Scripting for Data Modifing or Construction


If you set "Post Process", the expression would be executed after reading each snapshot data.
Predefined commands to access internal data of Zindaiji 3 is registerd with a prfix "C", like other commands.

For example, command to set position of i-th particle is

C.SetDataPosition(i, x, y, z)

As an other example, command for set 1-dimensional parameter "type" is
C.SetDataType(i, type)

When you consturuct data or append additional particles to the data, you must allocate memory by following command at first.
C.SetParticleNumber(number)



Above sample is a script to make rotating particle disk. You can make a movie like this from the script.



The post process expression is enable to access only to the data just loaded.
It is not implemented to access data of other steps.
Thus, simulation-like data making, constructing data from data of previous frames according to its interactions and time difference dt, is impossible for now.

User Defined Functions (C++)

Lua script is relatively fast script, but not so fast as compiled code. You may want to use your original C or C++ functions to make data. There is a some tips to include your code to Zindaiji3 when compiling it.

If C.CallUserDefinedFunction(index, arg...) is called in lua script, user defined function UserDefinedFunction0x() would be called. (x = index (1 - 3)).

UserDefinedFunction0x is defined in source code SRC/PARTICLEDATA/clsUserDefinedFunctions.cpp. As default, function01 is a routine to make spherical particle distribution, and function02 is a routine to make chaos particle distribution. You can rewrite these functions and compile Zindaiji3 to use your own data make functions.

Programming UserDefinedFunction()

You must allocate memory for particles data at first.
Call Allocate(int particle number).
In Zindaiji3, some variables would not be allocated unless following variables are set TRUE beforehand, to reduce memory consumption.
mbUseRadius
mbUseID
mbUseValue1

When Allocate() is called, memory for particle data would be allocated. Then you can set particle data to data array.

Data Array

mpX[][3] : position (float)
mpV[][3] : velocity(float) (*)
mpRadius[] : radius (float)
mpID[] : ID (int)
mpValue1[] : value1 (float)

(*) Used for Hermite interpolation. If linear interpolation is selected, these values would be overwrited, and setting these values would be meaningless.

The time of the snapshot is mpCParentSnap->mTime (double).
When calculating position offset from velocity, Zindaiji3 use the value of time. If the time is not defined, time is set to be the index of the snapshot (0, 1, 2, ...)

return
inserted by FC2 system