Rigid body creation ?

Discussion about scripting with Python
hardin
Posts: 6
Joined: Thu Nov 17, 2011 11:40 pm

Rigid body creation ?

Postby hardin » Thu Dec 08, 2011 7:41 pm

I've been using Realflow for several years. I'm just getting into Rigid Bodies.
To make a long question short, Can I use Python to create one or more Rigid Bodies with initial velocity vectors?

More detail:
Right now, I can stack up a couple thousand 'lumps of coal' (rigid bodies) and drop them down a chute. It looks and works great! I'm impressed. But, I really need to launch these lumps of coal off the end of a conveyor belt into some chute work. So, I'm thinking I can use Python (once I learn it) to create lumps of coal with velocity vectors to simulate coal flying off the end of a conveyor belt. Basically, I want to create my own emitter that emits rigid bodies.

Can this be done or is there an easier way by using existing RealFlow features?

Lyle.


hardin
Posts: 6
Joined: Thu Nov 17, 2011 11:40 pm

Rigid body creation ?

Postby hardin » Fri Dec 16, 2011 9:38 pm

With my scripting, I'm able to create objects in the realflow scene. I can change them to Active rigid bodies. But, in the RealFlow 2012 manual, on page 318, it says I can't use the setVelocity on Objects. I take it, that setVelocity is only for particles. So, am I able to set these object in motion with some other means? I feel like I'm so close!....

User avatar
bolek
Posts: 121
Joined: Thu Nov 27, 2008 10:24 am
Contact:

Rigid body creation ?

Postby bolek » Sat Dec 17, 2011 2:39 am

Welcome hardin.

So... answering to your first question.

Can I use Python to create one or more Rigid Bodies with initial velocity vectors? - yes you can.

But I suppose you are not very familiar with python (... So, I'm thinking I can use Python (once I learn it) ... ) so you should do it other way.

Anyway it's not good example to start study python... in my opinion writting simple scripts at the very beginning of learning is better because it gives you more self-confidence.

My way of thinking - If you can not swim do not jump into deep water.

Anyhow HERE is simple scene with script(Events). - rbd_forum.rar

It will give you an idea.

PREVIEW

Good luck. :)
____________________________________________
http://vimeo.com/bolekcg
http://bolekcg.blogspot.com/

hardin
Posts: 6
Joined: Thu Nov 17, 2011 11:40 pm

Rigid body creation ?

Postby hardin » Tue Dec 20, 2011 3:12 pm

Thanks for the reply.
I'm familiar with programming, in general, but new to Python.
I've gone through the Scripting chapter in the Realflow 2012 manual and havel learned quite a bit.
I'm now able to create an object, make a rigid body out of it and give it a vector and velocity.
I just need to figure out how to run the script with each frame of the simulation within RealFlow. Actually, I will just run the script for about 100 frames in a 1000 frame simulation.
I downloaded your .rar file and opened the .flw file and ran simulate, but I don't see the script. Is it coded into the Simulation Events? Guess that's another thing to learn, then....
Your script generates a bunch of cubes in one spot, but I get errors showing "@Velocity" not found. I pick on the cube(s) and they are not listed as being dynamic.
Am I missing something?
Thanks again.
Lyle

hardin
Posts: 6
Joined: Thu Nov 17, 2011 11:40 pm

Rigid body creation ?

Postby hardin » Tue Dec 20, 2011 3:34 pm

I tried another look at your preview. (My first try didn't show anything.) That is exactly what I am looking to do! But as I said in my previous post, the file I downloaded from you doesn't work. It creates several non dynamic cubes in one spot. I'm trying to place my script into the Events now, but I don't really know what I'm doing in that respect... yet.
Thanks again. You've given me hope!

hardin
Posts: 6
Joined: Thu Nov 17, 2011 11:40 pm

Rigid body creation ?

Postby hardin » Tue Dec 20, 2011 4:51 pm

Making headway.
I found that your script and 2012 must be a bit different.
Here's what works for me, but my exported sd file that I bring into 3DSMax, does not contain the cubes... why? Also, after my simulation, when I scroll my simulation frame slider back and forth, nothing happens, no animation. So, I now need to figure out how to stop my emitter at a set number of frames and let the simulation continue so I can Export the simulation to MAX. I commented out the keyframes, thinking that had something to do with the animation not working...

#--------------------------------------------------
# Function: onSimulationFrame
#--------------------------------------------------

def onSimulationFrame():
# velVector = Vector.new(5.0,5.0,5.0)
# nullPosition = scene.getObject("Null01").getParameter("Position")
curFrame = scene.getCurrentFrame()
if((curFrame%5) == 0):
cube = scene.addCube()
# cube.setParameter("Position", 1.0, 0.0, 0.0)
cube.setParameter("Position.X", 0.0)
cube.setParameter("Position.Y", 1.0)
cube.setParameter("Position.Z", 0.0)
cube.setParameter("Dynamics", "Active rigid body")
cube.setParameter("@ Velocity", Vector.new( 0.0, 8.0, 8.0 ))
# posXCurve = cube.getParameterCurve("Position.X")
# newKey = Key.new()
# curTime = scene.getCurrentTime()
# newKey.time = curTime
# curPos = cube.getParameter("Position.X")
# newKey.value = curPos
# posXCurve.addKey( newKey )

User avatar
bolek
Posts: 121
Joined: Thu Nov 27, 2008 10:24 am
Contact:

Rigid body creation ?

Postby bolek » Wed Dec 21, 2011 1:48 pm

Hi again. : )

I just need to figure out how to run the script with each frame of the simulation within RealFlow.
-"simulation events" window and onSimulationFrame() section


http://lesterbanks.com/2010/08/intro-to-scripting-in-realflow-tutorial/

http://thevault.realflow.com/simulation_events-68.html

http://thevault.realflow.com/simulation_events-325.html


Your script generates a bunch of cubes in one spot, but I get errors showing "@Velocity" not found.
- a little different attribute name maybe (my scene is in RF5)

Also, after my simulation, when I scroll my simulation frame slider back and forth, nothing happens, no animation.
- you need to put key(transformation,rotation) at every frame at simulation time (event script) .... or...

You can overcome that broblem by creating objects before simulation, and then give them initialPosition and velocity

PREVIEW and SIMPLE_SCENE (rbd_forum_02.rar) - again RF5
____________________________________________
http://vimeo.com/bolekcg
http://bolekcg.blogspot.com/

hardin
Posts: 6
Joined: Thu Nov 17, 2011 11:40 pm

Rigid body creation ?

Postby hardin » Wed Dec 21, 2011 7:32 pm

Clever. It took a while, but I get it. The objects have to be non-rigid bodies in a Group to begin with. The script reads each object from the group, turns them into rigid bodies, and throws them from a specified point then takes the object out of the group one at a time.
I like this much better than building and storing the key frames. Though, if I tackle the key frame recording / baking, I may change my mind.
Thank you very much for you help and especially the samples. I've learned a lot. Particularly by having to edit the scripts to work with 2012 vs 5.
Thanks again, I appreciate it.


Return to “Python-Scripting”

Who is online

Users browsing this forum: No registered users and 4 guests