Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / script at render, frame value
  RSS 2.0 ATOM  

script at render, frame value
Rate this thread
 
41514
 
Permlink of this thread  
avatar
  • Total Posts: 15
  • Joined: 19 March 2008 05:50 PM

Hi, I’ve got a simple script that changes the substitute object according to slidertime. Unfortunately the slidertime doesn’t change while rendering. How can I implement the actual rendered frame number?



Replies: 0
avatar
  • thedour
  • Posted: 06 April 2010 09:01 AM

<del>Try using Maxscript Callbacks.  They have a callback for #preRenderFrame and #postRenderFrame that you might find useful.

This is in the MAXScript reference under Callbacks: General Event: Rendering Notifications</del>

EDIT: I take it all back!  Tested… giant crash.  *tear*



thedour.net
Render 3D @ ScriptSpot.com

Replies: 2
/img/forum/dark/default_avatar.png

Except that you can’t change certain things in those callbacks, and I suspect that changing a “substitute object” is one of them. I don’t know if it is for certain, but it’s worth pointing out because it may cause problems (like a crash).

Author: Steve_Curley

Replied: 06 April 2010 09:22 AM  
/userdata/avatar/k9ti0d4th_33dffc1.jpg

Good catch, <del>I’d perhaps look into #postRenderFrame then.  #PreRenderFrame says “The renderer has already called GetRenderMesh() on all the object instances, and the materials and lights are already updated.” So post may work (as long as he doesn’t need it to happen on the first frame)</del>

Author: thedour

Replied: 06 April 2010 09:50 AM  
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

Gotta love CTDs - especially self-inflicted ones ;)

A quick question for you (apologies to the OP, but it is “on topic”, if tangential to the stated question).

In a normal controller script, e.g. a “scale script” attached to the Scale track of a dummy object, is there any way to tell that max is “rendering” as opposed to “playing” or having the Slider bar scrubbed? A System Global (which I can’t find) maybe?
Reason being, you can do almost anything in one of those scripts, so if it “knew” it was being rendered…

An example might be this thread which clearly alters the topology of the objects and doesn’t crash (or at least I don’t think it does). Something along those lines combined with the Frame and an “isRendering” might do the job.



Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.

Replies: 3
/userdata/avatar/k9ti0d4th_33dffc1.jpg

I don’t know of anything. I know globals are evil and all that, but…

You could make a script, with pre/post render callbacks, where each toggles a boolean global.  isRendering = true/false.

This would have to be in your startup folder or something like that so that the callbacks get registered in each max session… otherwise your controller pointing to “isRendering” will freak out.

Author: thedour

Replied: 06 April 2010 03:09 PM  
/img/forum/dark/default_avatar.png

I’d considered that but was hoping there was a pre-defined means of obtaining the “Max Status” rather than having to do it manually. The overall idea may work though - any “gotcha’s” you can think of which would prevent this working reliably? Always assuming you can do the replacement in such a script - I tried (briefly) creating a new Box at a given time. It wouldn’t render the box, but it appeared as soon as the render ended. Needs more investigation, I think.

Author: Steve_Curley

Replied: 06 April 2010 10:46 PM  
/userdata/avatar/k9ti0d4th_33dffc1.jpg

I can’t think of gotchas with that.  In the SDK, .net under ManagedServices there is a “AnimationFrameChangeListener” class that may be useful (might work at both render time and slider changes).

It may be easier with something like this to simply create a custom “render frames” script… something that would actually stop render, advance slider time (and change mesh as necessary), render next frame, and then at the end combine them into a movie.  I kind of do that in my script: <font color=red>Render 3D v1.3</font>, but I’m not breaking render per say; though you can look at the code and see how I’m adding support for .MOV by combining bitmaps.

Author: thedour

Replied: 07 April 2010 06:04 AM  
avatar
  • Anubis
  • Posted: 07 April 2010 04:58 AM

Maybe the example from the help (How To ... Create a Quick Preview) will help?

macroScript QuickPreview category:"HowTo"
(
    preview_name 
(getDir #preview)+"/quickpreview.avi"
    
view_size getViewSize()
    anim_bmp 
bitmap view_size.x view_size.y filename:preview_name
    
for animationrange.start to animationrange.end do
    
(
        sliderTime 
t
        dib 
gw.getViewportDib()
        copy dib anim_bmp
        save anim_bmp
    )
    close anim_bmp
    gc()
    ramplayer preview_name 
""
)

[edit] Ok, their is a modification of mxs-help example.

(
    objs 
#(box, cone, sphere, teapot)
    
tmp1 (objs[random 1 4]())
    
    outFile 
(getDir #preview)+"/test.avi"
    
anim_bmp bitmap renderWidth renderHeight filename:outFile
    
    
for animationrange.start to animationrange.end do
    
(
        sliderTime 
t
        tmp2 
(objs[random 1 4]())
        instanceReplace tmp1 tmp2
        delete tmp2
        frame 
render()
        copy frame anim_bmp
        save anim_bmp
    )
    close anim_bmp
    freeSceneBitmaps()
    gc()
)


Max 9 through 2009, XP-Pro x64 SP2
ASUS EAH3450 Series (Driver 8.470).
Core 2 Duo E8400 3GHz, 4Gb Ram, DX9.0c.

Replies: 0