How To > Create a Quick Preview |
The following macroScript will implement a highly simplified version of the Preview Animation feature of 3ds Max. We will access the content of the viewport directly and build an AVI file which will be then automatically loaded in the RAM player.
Accessing Active Viewport Info, Type, and Transforms
Device_Independent_Bitmap_access
The macroScript will be called QuickPreview . To use the script, you can go to Customize... and drag the script from the category "HowTo" to a toolbar, a menu, a quad menu or assign to a keyboard shortcut.
Now we define the output path for the preview AVI file. Using the getDir function we access the current preview path specified in 3ds Max’ Customize>Configure Paths. We add the file name to the path separated with a slash. (we could also use double-backslash "\\" as directory delimiter). The resulting path will be stored in a user variable called preview_name.
Next we check the size of the currently active viewport. The result of the getViewSize function is a Point2 value containing the width and height of the viewport in pixels. We will store this value in another user variable called view_size .
Accessing Active Viewport Info, Type, and Transforms
Using these two user variables, we can define a bitmap to store the preview. We supply the x and y component of the viewport size as the width and height parameters of the bitmap constructor, and set the filename to the already defined preview path.
A for loop will iterate through all frames in the current animation segment. The variable t will contain the frame number of each frame, starting with the start value of the animation range interval and ending with the end value.
Using the t variable, we move the time slider from frame to frame.
On each frame, we capture the viewport bitmap (Device Independent Bitmap, DIB) in a temporary variable.
Device_Independent_Bitmap_access
Then we copy the content of the dib variable (which is the bitmap showing the viewport’s content) into the preview bitmap we created. This adds a new frame to the AVI preview animation.
Before repeating the same on the next frame, we save the current content of the bitmap to disk.
When all frames have been stored, we can close the animation file and manually force garbage collection to ensure the memory used while copying bitmaps around has been released.
In 3ds Max 5, you can use gc light:true to free up memory.
Finally, we call the RAM Player and provide the path of the preview animation as first parameter, and an empty string as the second. The two parameters tell the RAM player which two files to load. The empty string is a place holder for a non-existing animation – we want to preview just one file.
Evaluate the script. To use it, you can use Customize... to drag the script from the category "HowTo" to a toolbar, a menu, a quad menu or to assign to a keyboard shortcut.
Select the viewport you want to preview (you can drag the viewport division to make it smaller for faster results) and start the script. The animation will be played once, then the RAM Player should open and load the preview animation.