@Dunhou Thanks, I'm having a lot of fun making TP run like a train, I'm trying to optimize the code by vectorizing some functions and gain new FPS. I will keep this post updated on developments as much as possible
Posts made by Abetred
-
RE: Real-Time 3D flocking on GPU (Cinema 4D Thinking Particles)
-
Real-Time 3D flocking on GPU (Cinema 4D Thinking Particles)
Today I present my new frontier in the simulation of artificial creatures.
By revisiting classic script programming and expressions in Python for Cinema4D with external libraries, I've achieved real-time 3D flocking by combining Thinking Particles (TP) with the power of an NVIDIA GPU.
TP offers unprecedented control over every aspect of particle behavior through Python code. Completely flexible and unrestricted by predefined nodes, it allows for creating any desired behavior, from realistic physics to artificial intelligence. However, its performance largely depends on the programmer's ability to optimize the code.
The GPU drastically accelerates calculations compared to the CPU, allowing for real-time visualization of smooth and interactive particle behavior, providing immediate feedback to the animator. Managing a large number of particles simulating thousands of boids finally becomes possible on TP.
Parameters of the Flocking Simulation:
• Separation: Boids avoid collisions with each other, maintaining a minimum pre-set distance.
• Alignment: Boids tend to match the speed and direction of their neighbors.
• Cohesion: Boids cluster toward the center of mass of their group.
• Boundaries: Boids remain within the simulation domain with natural behavior.
• Speed Limits: Speed is limited within a preset range for realistic movement.
• Prey: Boids can follow moving targets relative to distance.
• Obstacles: Boids interact with obstacles realistically.
All parameters are controlled by response factors to recreate a smooth reaction.
Further implementations are possible, such as complex obstacle ray tracking, which predicts the most reliable escape route while avoiding collisions, direction of travel, which maintains a rotation axis in the direction of acceleration, and arc of vision, which limits interactions to only visible boids within a section of a circle, for greater simulation realism.
The simulation in question is in the experimental phase and has a good margin for performance improvement and code optimization, which will be published later on GitHub. The results obtained on a specific machine* are nevertheless remarkable: Simulation of 1000 boids in real-time with a stable frame rate of 45 FPS. Demonstration of the potential of TP and GPU for real-time 3D flocking.
On more powerful machines with faster BUS, a higher frame rate and the management of an even greater number of boids can be expected. Despite the clear performance increase, as evidenced by the attached graph, the significant advantage of using the GPU is felt with the increasing number of particles, but this is undermined by the update phase, which still must occur via the CPU and canonical c4dpython code.
In conclusion, the combination of Thinking Particles and GPU represents a powerful and versatile approach for simulating 3D flocking in Cinema 4D.
Thank you for your attention.
A short demo video is available at the link- Tests conducted on:
Intel(R) Xeon(R) CPU E5-4650 0 @ 2.70GHz
Processori fisici: 1
Cores: 8
Processori logici: 16
Memoria 32GB
SSD
GPU NVIDIA GeForce RTX 2070 Super
- Tests conducted on:
-
RE: PointObject.CalcVertexMap(self, modifier)
hi Maxime, thank you for your availability. Bacca's answer immediately cleared my mind on the subject, just as I was reading the other thread. I usually use the traditional method of calculating vertexmaps in the presence of obstacles. I thought CalcVertexMap did just that (the restriction tag is not mentioned in the SDK, so I couldn't figure out how to use it) but my curiosity is just didactic.
Ciao
Gianluca -
RE: PointObject.CalcVertexMap(self, modifier)
Ok, thanks for the help.
CalcVertexMap obtains an array of the product of the PointObject's vertexmap values (in the range [0.0,1.0],(I think) "normalizing" the result), using a modifier (BaseObject) with a Restriction tag (from this discussion https://plugincafe .maxon.net/topic/1125/453_calcvertexmap ) which is passed the vertexmap tags.I finally understood. It is specifically used to restrict the action of a plug-in modifier to passed vertex maps. I thought CalcVertexMap used the modifier as the object that produces the vertex map, obviously it's not like that...
-
PointObject.CalcVertexMap(self, modifier)
Hi everyone. I have a question about CalcVertexMap.
When and how is it used? I've used it on a spline (PointObject) and on a Plane (PoligonObject) but in each case the method returns only "None", no Array is generated.
The modifier parameter requires a BaseObject, again I passed different types here but it doesn't change anything. Could anyone give me some tips?