Placing Particles
The result from the previous script is a kind of “voxelized” representation of the objects in your scene, but the basic script has some annoying limitations regarding names. So here is an idea: what if it was possible to attach particles to the vertices instead of objects? These particles could then be meshed with the “Clone obj” method. This workflow would directly solve our problems without complex name checks.
Name | Particles2Vertices.rfs |
---|---|
Type | Batch script |
Description | This script reads out the vertices of all objects in the scene and writes them into a list. The position data are then used to add and place particles at the object’s vertex location. |
What the script should do:
- Detect all objects inside the current scene
- Loop through the objects, collect the vertices and store them inside a list
- Get the position data
- Add the particles
- Transfer the vertex positions to the particles
First of all an empty emitter is needed. It makes no difference which type of emitter you are going to use, but maybe a container serves best here. To prevent other emitter types from generating particles, both “Speed” and “Volume” have to be set to 0.0. To create a particle RealFlow offers a certain instruction:
addParticle(position_vector, velocity_vector)
As you can see this statement needs two arguments. Here you have to determine a particle’s position and velocity. This is necessary information for a complete definition of a particle; without these values it is not possible to properly add a particle. The position is again derived from the vertices of the objects, but speed seems to be a problem. In fact, it is not really, because you can define a new velocity vector any time. Since the particles should not move at all, it would be nice to make them all stationary:
null_velocity = Vector.new(0, 0, 0)
This script draws particles to all vertices in your scene:
nullVelocity = Vector.new(0, 0, 0) emitter = scene.get_PB_Emitter("Container01") objectList = scene.getObjects() for singleObject in objectList: vertexList = singleObject.getVertices() for singleVertex in vertexList: vertexPos = singleVertex.getPosition() emitter.addParticle(vertexPos, nullVelocity)
The particles here behave like particles from any other emitter. They can be affected by daemons, interact with objects and collide with other particles. Of course, they can be exported to a BIN file. To make this work, the emitter has to be active under "Export Central". Now you can store the particles into a single BIN file without simulating the scene. Just add a final statement at the end of the script without any leading tabs or spaces:
emitter.export()