View Full Version : Threading the render function...
09-03-2009, 08:01 PM
local renderThread = dotnetobject "CSharpUtilities.SynchronizingBackgroundWorker"
renderThread.WorkerSupportsCancellation = true
renderThread.WorkerReportsProgress = true
fn doTheRenderBaby =
render outputWidth:800 outputHeight:600 vfb:true
dotNet.addEventHandler renderThread "DoWork" doTheRenderBaby
It kinda of hangs max when the render is done for a while... and the viewport is frozen, but I have to say I had to try it. On the plus side I can keep coding maxscript while the render is processing. =P
09-03-2009, 09:15 PM
Wow, if that effectively works, it's great... is there a possibility to enhace this to do the render completly threaded?
Cheers and take my greetings for this! :)
09-03-2009, 11:15 PM
It works but it's really nothing to call home about. I just thought it would be interesting to try. It's still better to just open two instances of max.
09-04-2009, 11:06 AM
At first is not working for me, i'm going to try again, but that can be great, because i have an script that helps with the rendering and if the render launched from my script does not hangs out max, can be really great.
Is there a way to get rid of this little hangs you talk about? and the viewport problem?
09-04-2009, 11:09 AM
Deffinitely i can't do anything, no coding, no max at all, max stays as not responding, but it's worse than with a normal render because i cannot see anything :p and when the render ends out max stays hanged.
EDIT1:I saw that you use CSharpUtilities, i don't have it installed, maybe this is the problem?
09-04-2009, 11:30 AM
I tried also this script from lonerobot.
I changed the nonsense calculation by a render, and it does the render, but after that, max is hanged, non responding at all, if i do the normal calculation (that comes with the script) it's ok, but with the render i need to kill max and reopen it.
09-04-2009, 11:48 AM
Maybe is not working for 64 bit?
Edit1: LoneRobot some ideas?
09-04-2009, 12:29 PM
I've found that if i display the vfb or display the bitmap then max hangs, but if i don't do that, then max stays stable.
Another thing i found is that threaded proccess is not working fine with Mental Ray, it does fine and fast with scan line, with mental it throws an Unespected Exception, and the next time you try to render then mental is completly blocked.
09-04-2009, 02:52 PM
I really doubt you are gonna be able to make it work properly. In any case, I tried it with finalRender and it freezes max when it's done, but after a while (like 15 min) it comes back to life...
Like I said, it was just a test...
09-04-2009, 03:00 PM
If you don't display the vfb and don't show any bitmap within the threaded funcion it won't hang max,also save the render to a temporal file, after the render is ended, inside a non threaded function you can load the temporal picture and display it.
It works fine with the scanline render, but with mental ray it gives an error, a BIG error hehe.
If that works is much better than 3dsmaxcmd because you don't have to load any instance of max, and wait until max loads the file, it will render directly.
09-06-2009, 06:52 PM
Great to see someone doing some more research into this stuff, I only ever scratched the surface and gave up as I pretty much encountered the same limitations over non dotnet based functions. MultiThreading is something that my brain just gives up on after a while. I looked into it for my VB programming, and you should in theory be able to use the system.threading class in max but the background worker is just a simpler alternative that takes all of the nasty delegate handling out of the equation. My only bit i'd add is you have to be careful about what stuff gets passed between threads, nothing can be referenced from another thread that was created on a different thread without passing it via the correct delegate method. So with that primitve understanding of it i'd say that's what is probably happening with the stuff errroring and hanging. Mental Ray must be pretty well threaded process already, so your guess is as good as mine as the what is actually happening at various points in the render process.
Sorry if thats a bit vague guys but thats about as far as I got with it too!
09-06-2009, 09:38 PM
So...no threading for mental ray render...i thought that because thread a process that it's going to be threaded also...it's a bit weird, but i don't understand why autodesk cannot let us continue working at the same time that mental is rendering, once you have exported the scene max can be free i think, all the work is done by mental wich is an external renderer well integrated, i'm only guessing, with that in mind progressive rendering can be a real thing even without the progressive rendering option of mental ray 3.7+ activate inside max...what a pitty hehe.
Cheers and thanks for the answer LoneRobot!
09-06-2009, 11:50 PM
Great to see someone doing some more research into this stuff, I only ever scratched the surface and gave up as I pretty much encountered the same limitations over non dotnet based functions.
Well I only found about it after reading your article, so thanks for that!. Right now I'm working on a script that adds controls to a flowLayoutPanel depending on some data, and being able to thread the control creation, so that the user does not have to wait for the whole process to finish has been extremely practical, and makes the script feel a lot more "professional". I can see myself using this threading stuff a lot more in the future.
09-06-2009, 11:50 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.