Dynamics and Objects - Question?

Discussions about rigidbody simulation in Realflow 4
Posts: 4766
Joined: Sun Sep 10, 2006 8:04 am

Dynamics and Objects - Question?

Postby shaun_michael » Mon Aug 27, 2007 8:20 pm

OK, so I had time to sit down and write something that i think works (and believe me, I need loads of time even for something seemingly this simple). It may not be very elegant, but if someone would show me a tidier way of doing it that would be great - say calling up a GUI with all your objects in it for you to select so you dont have to hunt through the nodes.

Here's how to use it

Firstly cut and paste the script into the OnSimulationFrame section of the Event Script window (F11) ensuring that you overwrite the two lines of code that are already there

Code: Select all

def onSimulationFrame():

1) Add a limiter object to the scene that describes the height at which you want objects to be inactive. I used a null called Null01. If you dont use an object called Null01 either change the name in the script to match your object (between the quotes) or change the name of your limiter object in the nodes window to Null01
2) Select or multi-select the node(s) you want affected by script
3) Check the Active box in the script window
4) Hit simulate.

What it does
Each frame it checks the y-position of your objects compared to the y-position of the limiter object. If the limiter is equal to, or above the position of the object, the object will be inactivated.

It also turns all your selected nodes to active at the beginning of the sim - this gets around the fact that you might want to run the script more than once and all/many of the objects have already been set to "Inactive".

Ways to improve the script?
Evolve it so that objects can go past the limiter in one direction (ie with y increasing) and not be read as meeting the Inactive condition, but when they come down, they do.
Add a GUI that shows all objects in scene to make selecting objects easier
Any other suggestions?

Code: Select all

def onSimulationFrame():
   objects = scene.getSelectedNodes( )                  # Creates list of all nodes selected
   for object in objects:
      object.setParameter("Simulation", "Active" )      # Ensures that at the start of the sim all objects selected are Active
   limiter = scene.getObject( "Null01" )
   limiterpos = limiter.getParameter( "Position" )         # Calls limiter object's position,   x, y, z vectors returned

# Loop through object list each frame and compare to Null's position.
   for object in objects:
      objpos = object.getParameter( "Position" )
      if (limiterpos.y >= objpos.y):                        # Uses y vector for comparison
         object.setParameter ("Simulation", "Inactive" )   # Needs both equal and below comparison as this is only
                                                         # making the check once per frame, rather than per substep
                                                         # Sets state to Inactive if condidtion met

Let me know if it works, or is quirky or reliable for the purpose we've been discussing in this thread.


ps - I happened to notice that after a while, the keyword colour-coding in the RF scripting window started to fail. Anyone else notice that at all?

Posts: 124
Joined: Sun Sep 10, 2006 11:30 pm

Dynamics and Objects - Question?

Postby Spongebob » Tue Aug 28, 2007 3:03 pm

Cool! I really appreciate all the efforts, I know it requires some brain power and time! I will have to try it out. I ended up experimenting with a simple formula (similar to what you have in your script) where the Object would compare it's position to another Object's "Y" value and then once the object is outside camera sight it would set that objects mass to zero so it would stop having to be calculated. But the problem with that is again you have to do that for every object. But like you said about your script, adding a feature GUI to select Objects would be a lot easier.

I wish :) that they had a Volume_K_for_Objects. Where it would be a box or a simple ground plane that would instantly freeze those objects so that there would be no scripts or a whole lot of thought put into it.

In the long run I suppose there is always the simple solution of adding another ground plane, or box to a scene that would just catch any free object. Then in your 3d platform it would just not be rendered. That's the .99 cent solution...

But once I get some time I will mess around and let ya knowhow it works!

Posts: 334
Joined: Tue Jan 09, 2007 5:15 pm

Dynamics and Objects - Question?

Postby ranxerox » Tue Aug 28, 2007 3:20 pm

it would be cool to be able to test for objects names on collision (something like getParticlesColliding() but for objects). If you had this you could easily set up some planes just outside the view frustum to catch those objects. I'm pretty sure however this doesn't exist. Someone let me know if I am wrong.


Return to “RF4: Rigidbody simulation”

Who is online

Users browsing this forum: No registered users and 1 guest