Misfit Model scripts provide a way to quickly manipulate several models in a uniform manner. Scripts can apply matrix transformations, create new primitives, apply textures, and create or manipulate animations.
Misfit Model 3D uses a lua-based scripting system. For general lua programming information, go to http://www.lua.org/docs.html. For functions specifically added to lua for model manipulation, see the Scripting Reference page.
The lua language for Misfit Model is restricted to the standard control structures, the math library, and the model manipulation functions.
A the time of this writing, the scripting system was tested against Lua 5.0.3. Other 5.x versions should work fine.
Script files are text files with functions that perform operations on models. The open script dialog box will look for files with a .lua extension by default, so you will probably want to use .lua as the script extension. A script run from the Misfit Model 3D UI is run on a single model at a time.
Scripts work similarly to the UI in that some operations work on the base model
and some work on the current animation (if you are in animation mode). Functions
like selectedRotate
and selectedTranslate
will work on the model itself or
on animation frames if you have used setAnimByIndex
and animSetFrame
.
A simple example script is included below. Lines beginning with
"--
" are comments. They are marked in blue below for the
sake of clarity. This script is included in the Misfit Model 3D
distribution in the scripts directory. There are a few other scripts
that are also included for reference.
x1 = -1.0 y1 = -1.0 z1 = -1.0 x2 = 1.0 y2 = 1.0 z2 = 1.0 -- front modelCreateMeshRectangle( x2, y1, z2, x1, y1, z2, x1, y2, z2, x2, y2, z2 ) -- back modelCreateMeshRectangle( x1, y1, z1, x2, y1, z1, x2, y2, z1, x1, y2, z1 ) -- right modelCreateMeshRectangle( x2, y1, z1, x2, y1, z2, x2, y2, z2, x2, y2, z1 ) -- left modelCreateMeshRectangle( x1, y1, z2, x1, y1, z1, x1, y2, z1, x1, y2, z2 ) -- top modelCreateMeshRectangle( x1, y2, z2, x1, y2, z1, x2, y2, z1, x2, y2, z2 ) -- bottom modelCreateMeshRectangle( x1, y1, z1, x1, y1, z2, x2, y1, z2, x2, y1, z1 ) modelSelectAllVertices() selectedWeldVertices()
To run a script in the graphical user interface, select "Run Script..." from the "File" menu. This will allow you to chose a script file to run on the current model. The result of the script will be displayed in the status bar.
If there was an error running the script the error will be displayed in the status bar. Long errors may be truncated. In these cases the entire error may be visible by hovering the mouse over the status bar to see a tool tip.
Once you have run a script, you can run it again by selecting the script name from the "Recent scripts" submenu in the "File" menu.
To run a script from the command line, use the --script
option.
The --script
option requires a script filename as an argument.
The script will run on every model file specified on the command line. If no model files are specified, a new model will be created. After the script has been run on every model file, Misfit Model 3D will continue processing as usual. If no other command line options are specified, the modified model files will each be opened in a view window.
If you wish to do command-line processing only without opening a view window
in the User Interface, see the --save
and --batch
options in the Command Line documentation.
There may be other options that are useful in batch processing as well.