Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

At the time the simulations starts there has to be a global definition of the lists for both position and time data. It is not possible to do this at another time, for example during the simulation, because in this case the contents would be overwritten with each frame and the result would be a single value.

 

Code Block
themeEclipse
languagepython
linenumberstrue
# Simulation Pre

 
object = scene.getObject("Sphere01")
name   = object.getName()

scene.setGlobalVariableValue("objName", name)
scene.setGlobalVariableValue("posList", [])
scene.setGlobalVariableValue("timeList", [])

...

All keys will be written after the simulation, because this has some advantages: imagine you have to write out the position data to a file. This could slow down RealFlow, since the script has to open the output file, write the data and close the file for every single frame! With the method outlined here, everything is written in one pass after the last simulated frame. In the last part you can find the functions for setting the keys and assigning the information from the different lists. Everything has to be done for each component of the position vectors: X, Y and Z. The code snippet here shows the process for a single axis. A counter is needed to read out the stored time information by the list’s index: 

Code Block
themeEclipse
languagepython
linenumberstrue
# SimulationPost   

index     = 0 
posList   = scene.getGlobalVariableValue("posList") 
timeList  = scene.getGlobalVariableValue("timeList")
objName   = scene.getGlobalVariableValue("objName")
object    = scene.getObject(objName)
curvePosX = object.getParameterCurve("Position.X") 

for posVector in posList:   
    newKeyX = Key.new() 
    simTime = timeList[index] 
    index  += 1
 
     newKeyX.time  = simTime
    newKeyX.value = posVector.getX()
    newKeyX.type  = KEY_TYPE_BEZIER
    curvePosX.addKey(newKeyX) 

...