Table of Contents

This page provides information on how scripting can be used with Chaos Phoenix.

Overview


During the simulation process you can directly access the simulator's content using some functions exported by the plugin. These functions can't be called at any arbitrary point; they will work properly only when the simulator is in the appropriate internal state. The moments of time when the content can be manipulated properly are signaled by calling several callback functions, and you can access the simulator's content only inside them.

Every Phoenix Simulator node has its own script file. When the simulation starts, the script is compiled and its callback function overrides the callback functions of any previous simulation. Python and MEL scripts are supported. Python has been noted to be the faster of the two. The Python module is built into the Phoenix plugin for Maya, and is called phxfd.

 

Callback Functions


There are four callback functions that must be named accordingly.

Function

Description
OnSimulationBegin(node, t, dt)Called after all the initialization of the simulator is done and before first execution.
OnSimulationStep(node, t, dt)Called before each simulation step, after the interaction with the scene.
OnSimulationEnd(node, t, dt)Called after the end of the simulation. The simulation core would be already destroyed during this callback so it should not be accessed.

OnNewFrame(node, t, dt)

Called after each frame export.

 

Callback Parameters


The following parameters are passed to each of the above callback functions in the same order:

Parameter Description
node <string>The simulator that calls the callback function - returns a string containing the name of the simulator node.
t <float>The simulator's internal time - the returned value is equal to the current frame / frames per second.
dt <float>The simulator's internal step - the returned value is equal to the current time / (frames per second * steps per frame).

 

Script File Example


The following example will print the name of the simulator (node) , the current time (t) and the current time step (dt). The if() statement is used to stop the simulation if the current frame is 2.

You can save the script below to a test.py file for Python or test.mel file for MEL and load it from Phoenix Simulator → Simulation → Scripting → Script File

 

PYTHON 3 (used for Maya 2022 and newer):

import maya.cmds as cmds
import phxfd

def OnNewFrame(node, t, dt):
    print (node)
    print (t)
    print (dt)

    if( cmds.currentTime(query = True) == 2 ):
        phxfd.stop()

PYTHON 2 (used for Maya 2020 and older):

import maya.cmds as cmds
import phxfd

def OnNewFrame(node, t, dt):
    print node
    print t
    print dt

    if( cmds.currentTime(query = True) == 2 ):
        phxfd.stop()

MEL:

global proc OnNewFrame(string $node, float $t, float $dt) {
    print $node;
    print $t;
    print $dt;

    $now = `currentTime -q`;

    if($now == 2){
        phxfdSim -n $node -a "stop";
    }
}

 

Function Declaration


Example MEL function declaration:

          global proc OnSimulationBegin(string $node, float $t, float $dt)
        

Example Python function declaration:

          def OnSimulationBegin(node, t, dt):
        

Simulation Core and Result Access Functions


Each of the simulation channels (temperature, velocity,smoke etc.) exists in two instances - in the simulation core and in the simulation result (i.e. cache). The functions in this section can access both the simulation core and result. If a node is passed to the access functions, the particular simulation result is accessed, otherwise the simulation core is accessed.

The simulation core exists only during the simulation and can be accessed only in the Callback functions.

 

 

MEL Functions

phxfdSystem [-q] [-node(-n) string] [ system  string]

Specify which coordinate system to be used when calling phxfdGetphxfdInject and phxfdParticle.

-q

query the current coordinate system.

-node

determine manually the simulator node.

system

the coordinate system to set:

"object" - Object space

"world" - World space

"grid","core" - Grid space

 

Return value:

none

phxfdInject [-node(-n) string] -position(-pos) float float float -discharge(-d) float [-temperature(-t) float] [-smoke(-sm) float] [-fuel(-fl) float] [-velocity(-vel) float float float] [-uvw float float float]

Inject fluid in a given point. Using this function you can create your own procedural sources. The result of the function CAN NOT be achieved by calling one or more phxfdSet functions, because they do not affect the quantity of the fluid, but only the parameters carried by the fluid. The injection of fluid in some point causes changes in the content only of the nearest 8 cells, but produces an outgoing flow in the entire grid. Nevertheless the function is not slower than the ordinary phfxSet function, because the outgoing flow appears later, when the simulation is executed. If phxfdGet function is executed immediately after phxfdInject in some near point, the velocity will be not changed.

-node

determine manually the simulator node.

-position

the position of the injection.

-discharge

the speed (not the quantity) of the discharged fluid.

-temperature

the temperature of the released fluid measured in K.

-smoke

the concentration of the "Smoke" channel.

-fuel

the concentration of the "Fuel" channel.

-velocity

the concentration of the "Velocity" channel.

-uvw

the concentration of the "UVW" channel.

Return value:

true if the operation was completed successfully, and false otherwise.

phxfdSet [-node(-n) string] -position(-pos) int int int [-temperature(-t) float] [-smoke(-sm) float] [-fuel(-fl) float] [-velocity(-vel) float float float] [-uvw float float float]

Directly set the content of a particular cell inside the grid. Note that this function works only in grid space and phxfdSystem do not have effect on it.

-node

determine manually the simulator node.

-position

the position of the cell.

-temperature

the temperature value in K.

-smoke

the value for the "Smoke" channel.

-fuel

the value for the "Fuel" channel.

-velocity

the value for the "Velocity" channel.

-uvw

the value for the "UVW" channel.

Return value:

true if the operation was completed successfully, and false otherwise.

phxfdGet [-node(-n) string] -position(-pos) float float float [-temperature(-t)] [-smoke(-sm)] [-fuel(-fl)] [-velocity(-vel)] [-uvw]

Get the content of the grid at a given point. Note that the point is in the coordinate system specified by phxfdSystem.

-node

determine manually the simulator node.

-position

the position of the content that must be accessed.

-temperature

get the temperature in K.

-smoke

get the value of the "Smoke" channel.

-fuel

get the value of the "Fuel" channel.

-velocity

get the value of the "Velocity" channel.

-uvw

get the value of the "UVW" channel.

Return value:

float[] An array of floats with the content of the grid at that point. The queued channels are return in a fixed order - temperature, smoke, fuel, velocity, uvw.

phxfdFreeze -position(-pos) int int int [ freeze  bool] [ source  bool]

Freeze a cell during the simulation. The cell can be made optionally a source.

-position

the position of the cell to freeze.

freeze

if 1, the cell will be frozen, if 0 - unfrozen, default 1.

source

if 1, the cell will be marked as a source, if 0 - unmarked, default 0.

Return value:

true if the operation was completed successfully, and false otherwise.

phxfdParticle [-node(-n) string] -position(-pos) float float float -partgroup(-pg) string [-velocity(-vel) float float float] [-radius(-rad) float]

Create particle in given position with given properties.

-node

determine manually the simulator node.

-position

the position of the new particle.

-partgroup

determine to which particle group to assign the new particle.

-velocity

set the initial velocity of the particle.

-radius

set the radius of the particle (only for foam and splashes).

Return value:

true if the operation was completed successfully, and false otherwise.

phxfdSaveCache  filename string  node string

Save the current content of the grid to an AUR or VDB cache file.

filename

the cache file name.

node

the simulator node name.

Return value:

true if the operation was completed successfully, and false otherwise.

 

 

Python Functions

setsystem  system  string [ node  string]

Specify which coordinate system to be used when calling getinject and particle.

Return value:

true if the operation was completed successfully, and false otherwise.

getsystem [ node  string]

Return the current coordinate system.

Return value:

string The current coordinate system.

inject (x float, y float z float) disch float [temp float] [smoke float] [(vx float, vy float, vz float)] [(ufloat, v float, w float)]

Inject fluid in given point. Using this function you can create your own procedural sources. The result of the function CAN NOT be achieved by calling one or more set functions, because they do not affect the quantity of the fluid, but only the parameters carried by the fluid. The injection of fluid in some point causes changes in the content only of the nearest 8 cells, but produces an outgoing flow in the entire grid. Nevertheless the function is not slower than the ordinary phfxSet function, because the outgoing flow appears later, when the simulation is executed. If get function is executed immediately after inject in some near point, the velocity will be not changed.

Return value:

true if the operation was completed successfully, and false otherwise.

set (cx int, cy int cz int) [temp float] [smoke float] [(vx float, vy float, vz float)] [(u float, v float, wfloat)] [ node  string]

Directly set the content of a particular cell inside the grid. Note that this function works only in grid space and setsystem do not have effect on it.

Return value:

true if the operation was completed successfully, and false otherwise.

setT (cx int, cy int cz int) temp float [ node  string]

Directly set the temperature in K of a particular cell inside the grid. Note that this function works only in grid space and setsystem do not have effect on it.

Return value:

true if the operation was completed successfully, and false otherwise.

setSm (cx int, cy int cz int) temp float [ node  string]

Directly set the value of the "Smoke" channel of a particular cell inside the grid. Note that this function works only in grid space and setsystem do not have effect on it.

Return value:

true if the operation was completed successfully, and false otherwise.

setFl (cx int, cy int cz int) temp float [ node  string]

Directly set the value of the "Fuel" channel of a particular cell inside the grid. Note that this function works only in grid space and setsystem do not have effect on it.

Return value:

true if the operation was completed successfully, and false otherwise.

setV (cx int, cy int cz int) temp float [ node  string]

Directly set the velocity of a particular cell inside the grid. Note that this function works only in grid space and setsystem do not have effect on it.

Return value:

true if the operation was completed successfully, and false otherwise.

setUVW (cx int, cy int cz int) temp float [ node  string]

Directly set the value of the "UVW" channel of a particular cell inside the grid. Note that this function works only in grid space and setsystem do not have effect on it.

Return value:

true if the operation was completed successfully, and false otherwise.

get (x float, y float z float) [ node  string]

Get the content of the grid at a given point. Note that the point is in the coordinate system specified by setsystem.

Return value:

[float float float tuple tuple] array with the content in this order - temperature, smoke, fuel, velocity, uvw.

getT (x float, y float z float) [ node  string]

Get the temperature in K of the grid at a given point. Note that the point is in the coordinate system specified by setsystem.

Return value:

float the temperature in K.

getSm (x float, y float z float) [ node  string]

Get the value of the "Smoke" channel at a given point. Note that the point is in the coordinate system specified by setsystem.

Return value:

float the smoke.

getFl (x float, y float z float) [ node  string]

Get the value of the "Fuel" channel at a given point. Note that the point is in the coordinate system specified by setsystem.

Return value:

float the fuel.

getV (x float, y float z float) [ node  string]

Get the velocity of the grid at a given point. Note that the point is in the coordinate system specified by setsystem.

Return value:

tuple the velocity.

getUVW (x float, y float z float) [ node  string]

Get the value of the "UVW" channel at a given point. Note that the point is in the coordinate system specified by setsystem.

Return value:

tuple the uvw.

freeze (cx int, cy int cz int) [ freeze  bool] [ source  bool]

Freeze/Unfreeze the cell at a given point during the simulation, and optionally mark it as a source.

Return value:

true if the operation was completed successfully, and false otherwise.

particle  group  string (x float, y float z float) [(vx float, vy float, vz float)] [ radius  float] [ node  string]

Create a particle in a given position with given properties.

Return value:

true if the operation was completed successfully, and false otherwise.

saveCache  filename  string [ node  string]

Save the current content of the grid to a cache file.

Return value:

true if the operation was completed successfully, and false otherwise.

 

Utility Script Functions


These functions are not part of the simulation process, but can be used to script the functionality which is normally accessed via the GUI.

MEL Functions

phxfdSim [-q] [-node(-n) string] [ -action(-a) string] [-flags(-f) int] [-fname(-fn) string] [-debug(-d) int]

This is the main command to control the simulator node.

-q

query a property:

no flags current state of the simulation. Can be one of the following: "none" - no simulation is running, "paused" - the simulation is paused, "running" - the simulation is running.

-node the node of the simulation that is currently running.

-debug the current debug flags.

-node

determine manually the simulator node.

-action

the action to execute:

"start" - start the simulation of the specified node.

"stop" - stop the current simulation.

"pause" - pause the current simulation.

"restore" - restore the simulation from the current time slider position or the Custom Start Frame under the Simulation rollout. Use -fname if you want to Load the initial state of the simulation, instead of Restoring.

"batch" - start the simulation in batch mode.

"batchr" - restore the simulation in batch mode from the last simulated cache file or the Custom Start Frame under the Simulation rollout. Use -fname if you want to Load the initial state of the simulation, instead of Restoring.

"clearcache" - clear the output cache. Use -flags 1 to clear the resimulation cache.

"loadtempl" - load a preset. Use -fname to specify the preset file name.

"savetempl" - save a preset. Use -fname to specify the preset file name.

-flags

specify flags, used by clearcacheloadtempl and savepreview actions.

-fname

specify a file name, used by restoreloadtemplsavetempl and savepreview actions.

-debug

replace the smoke channel with debug information during the simulation:

0 - disabled, normal smoke channel

1 - frozen cells

2 - previous divergence

3, 4 - current divergence

Return value:

none

phxfdGetRoot

Return the Phoenix installation root path. If "." is returned, the Phoenix environment variable was not found. getPhoenixFDRoot will return also the fallback location.

phxfdSort  camera  string  nodes  string[]

Sort the nodes passed as the second argument based on a particular camera. This command can be used for example to determine the rendering order.

Return value:

string[] The sorted array of nodes.

phxfdSaveFramePreview  nodes  string[]  merge  int  filename  string  cameras  string[]

Save a GPU preview for the current frame. The first argument specifies a list of nodes to render. If merge is 1, the preview of all nodes will be merged to a single image, otherwise - each node will be rendered to a separate image. If filename is not empty, it allows overriding the default file name. An image will be rendered for each camera in the cameras list.

phxfdSaveAnimPreview  nodes  string[]  startFrame  int  endFrame  int  merge  int  filename  string cameras  string[]

The same as phxfdSaveFramePreview, but allows you to specify a range of frames to render instead using the default one.

phxfdConnectRenderGizmo

With two nodes selected, this command will assign the shape node as render gizmo for the simulator/foam node.

phxfdConnectGlassGizmo

With two nodes selected, this command will assign the shape node as glass geometry for the foam node.

phxfdConnectLiqGeometry

With two nodes selected, this command will assign the shape node as liquid geometry for the foam node.

phxfdSetPreviewLights

Assign the selected lights to the preview lights of the selected simulator node.

phxQuickSetup -preset(-p) int

Set up a Quick Simulation with the selected object. The available options are as follows:

0 - fire
1 - fuel fire
2 - explosion
3 - gasoline explosion
4 - large smoke
5 - cold smoke
6 - cigarette smoke
7 - candle
8 - clouds

9 - tap water
10 - milk
11 - beer
12 - coffee
13 - honey
14 - liquid chocolate
15 - blood
16 - paints
17 - ink in water
18 - waterfall
19 - ocean

phxfdAbout

Returns a string with the exact Phoenix version installed.

phxfdCopyrights

Returns a string with all credits and copyrights for Phoenix and all 3rd party software used.

 

 

Python Functions

start  node  string

Start the simulation of the specified node.

restore  node  string [ filename  string]

Restore the simulation from the current time slider position. A file can be specified to load the simulation state from.

batch  node  string

Start the simulation of the specified node in batch mode.

batchr  node  string  frame int

Restore the simulation from a specified frame in batch mode.

pause

Pause the simulation.

stop

Stop the simulation.

clearcache  node  string [ flag  int]

Clear the output cache of the simulator node. If flag is 1, the resimulation cache will be cleared.

resetE

Reset the emission graph in render settings.

resetD

Reset the diffuse graph in render settings.

resetT

Reset the transparency graph in render settings.

 

Batch Scripting


Phoenix can do simulation in batch mode. Like inside the GUI, only one simulation can be run at a time. The batch commands are blocking, i.e. they will return the execution to the script after finishing. This can be used to script more complicated setups, like one simulator depending on the result of another. These commands can also be run inside the GUI, but will effectively block it for interaction. Once started, they can't be stopped. However, the simulation can run slightly faster.

Batch Functions

phxfdBatchSim  node  string

Start simulating the specified node. The command will return when the simulation is over.

phxfdStartBatch  node  string startFrame  int  endFrame  int

The same as phxfdBatchSim, but the second and third arguments override the default start/stop frame for the simulation.

phxfdBatchRestore  node  string  startFrame  int 

Restore the simulation in batch mode. The second argument specifies the frame from which the simulation must be restored. This is analogue to moving the time slider and clicking the "Restore" button.

phxfdBatchRestoreStop  node  string  startFrame int endFrame int

Restore the simulation in batch mode. The second argument specifies the frame from which the simulation must be restored. The third argument specifies the end frame of the Restore.

phxfdBatchResim  node  string  waiting  bool

Start simulating in resimulation mode. If  waiting  is true, the Cache Waiting is turned on.

phxfdBatchResimRestore  node  string  startFrame  int  waiting  bool

Restore the resimulation in batch mode. The second argument specifies the frame from which the simulation must be restored. This is analogue to moving the time slider and clicking the "Restore" button. If waiting is true, the Cache Waiting is turned on.

 

Example command line to launch Maya batch:

render -r vray -preRender "phxfdBatchSim(\"PhoenixFDSimulator1\")" -noRender phx_simple.ma

Example command line calls to initialize Maya Batch and start a Phoenix simulation:
cd "C:\Program Files\Autodesk\Maya2017\bin"

mayabatch.exe -file "D:\PHOENIX_QA\batchSimScene.ma" -command "phxfdBatchSim(\"PhoenixFDSimulator1\")"


Option Vars


Maya Option Vars

optionVar -sv "PhoenixFD_cachePath" string

Set the current cache path that will be used with the template path names.

optionVar -iv "PhoenixFD_safemode" number

Run Phoenix in safe mode. This will turn off the shading preview when loading new scenes to prevent display problems.