Randomizing

   4585   11   1
User Avatar
Member
57 posts
Joined: July 2009
Offline
Hi all. I want to randomize the value of parameters in the DOP level such as intial velocity and mass. If you shatter a sphere and make it rigidbody it takes all groups ( usually piece0, piece1 and…) into autodopnetwork. If you set initial velocity, all of your pieces will take same value. how can I assign different initial velocity for each piece?
User Avatar
Member
1908 posts
Joined: Nov. 2006
Online
You can generate random values for DOP objects by randomizing based on their OBJID value, rand($OBJID). OBJID is unique for each object in the simulation so it is ideal for randomizing.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
319 posts
Joined:
Offline
Randomising velocity is quite a common need in an RBD simulation so there is also a toggle on the ‘initial state’ tab of the RBD DOP's named “Inherit velocity from point velocity”. This will take the velocity attribute present on your geometry from SOPs and apply it in the first frame of your simulation. Meaning you can use all the inherent functionality of the SOP context to generate the V attribute you want (and visualize it before simulating) and have it apply to your DOP geometry with one click of said toggle..
User Avatar
Member
57 posts
Joined: July 2009
Offline
thank you guys, but is there any python code which I can apply it in DOP level?
I tried to creating a loop through groups but I dont know how to use hou.PrimGroup class do you know how can I use it?
Also in SOP level I created attribute named Velocity and assign a value to it but when I turned inherent velocity on in initial section I saw no different
User Avatar
Member
1908 posts
Joined: Nov. 2006
Online
Here's an example of doing it 3 different ways.

The first way inherits the velocity from the points on the geometry. Way two doesn't inherit but uses the same method of randomizing as when point velocities were assigned in SOPs, but slightly tweaked for DOPs. The third method uses a Python DOP to do it. Really though it is basically the same as the other methods but in Python.

Personally I'd stick with probably the first method, perhaps the second. The Python method is overkill unless you have need of lots of calculations to decide on what velocity each group needs. Also, Python DOP objects have caching issues and they can get annoying.

If you really wanted to do something with primitive groups, hou.PrimGroup is pretty straightforward.

for prim_group in geo.primGroups():
for prim in prim_group.prims():
# Do something to this primitive.


If you needed to process actual geometry per piece you could just call hou.DopObject.geometry() to get the geometry for that object (group). Also you could use doptoolutils.getSourceObjectNode to look back to the original geometry container and then search for the primitive group named for the current object, but that's more work.

Attachments:
dop_rand_velocity.hip (188.2 KB)

Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
57 posts
Joined: July 2009
Offline
Thank you very much you are awesome
User Avatar
Member
57 posts
Joined: July 2009
Offline
Would you please re save and re upload your file? when I open it, I get fatal error for python
User Avatar
Member
1908 posts
Joined: Nov. 2006
Online
Sorry about that. There was a bug recently that was causing files saved in newer builds to crash instantly in older builds that I thought was fixed. Updating to a recent build should solve the problem. However, I copied and pasted the network to a new session in an older build so the file attached in this post should work fine in older builds now.
Edited by - Sept. 18, 2010 14:32:55

Attachments:
dop_rand_velocity.hip (188.1 KB)

Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
57 posts
Joined: July 2009
Offline
Thank you very very much. I have another question please ops:
in velocity changer node (with python icon) I found no codes and it says “ # Couldn't find Python code. Please check that
# oplibDop/velocity_changer?Dop/velocity_changer.py is in the proper location.”
would you please send me the codes???? tnxxxxxxxxxxxxxxx
User Avatar
Member
1908 posts
Joined: Nov. 2006
Online
Sorry. Copy/paste didn't transfer over the asset definition. I uploaded a newer version that should work fine.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
57 posts
Joined: July 2009
Offline
thank you very^10000 much graham. You are awesome…
User Avatar
Member
319 posts
Joined:
Offline
Cool stuff Graham. I never used any python outside of SOPs yet. Do you know any sources of other cool tricks with python in other contexts?
  • Quick Links