Jump to content

newbie help scripting a collision/deformer sop


Kenshin_desu

Recommended Posts

Hello,

I'm a total newb to Houdini and its scripting langauge and I am having diffuclty writing a script that will detect collisions and deform objects that participate in the collision.

For example, say I have a box that is key framed to come crashing down onto a grid. When the box comes in contact with the grid I want to deform the grid such that when the box leaves the grid, there will be an imprint of the box on the grid. So far I've tried scripting an SOP that goes inside the grid geometry and takes the grid's points and the box's channel name as inputs. Then using the grid's points and the box's channel name I tried to test positions like this:

if ch("/obj/grid/tx") <= grid.y then collision has occured but I keep recieving a segmentation fault which causes Houdini to crash.

I'm pretty sure that my approach is incorrect but with my current knowledge of the scripting langauge I'm kind of lost. Can anyone offer me any advice on how I should approach this problem? Should I be trying to script an SOP or should I be scripting a CHOP? Can I even do this using VEX? Or do I need to try the HDK? Any Input would be greatly appreciated.

Thanks.

Mike

Link to comment
Share on other sites

Hi Steven,

thanks for your quick reply. However, for this task my professor requires me to script this as opposed to using the built in operators.

I've kind of got an algorithm worked out: I want to group a subset of all the points on the grid and then use those points and test them against the vertices of the box. If the grid point is inside the box then a collision is found and I want to apply a transformation to the grid point and possibly to the neighboring points to get a more interesting effect. The problem I have right now is that I don't know how to access the points in the box within the grid SOP network. Does Houdini have a vertex or point list global that I can use in a for loop (ie: for i = 0; i < numPoints; i++ {accessGridPoint(i) do something)?

Thanks,

Mike

Link to comment
Share on other sites

tell ur professor that maya is the tool for scripting :-)

houdini just does what u want with little boxes fulled with magic  :)

16990[/snapback]

:P I wish I could say that to my prof, but he won't let us use maya or xsi. We have to use houdini to do it.

Anyways I was able to make a script that does the deformation now, although its done in a really hacked way. What I did was make the center of the sphere and the radius of the sphere function paramters into my SOP function. Then I just used those values to do the collision detection, this got rid of all the nasty sementation faults. The problem i'm having now though is how do I make the imprint in the grid stay when I render out the animation? Is there a way to make houdini keep the deformations on the grid?

Mike

Link to comment
Share on other sites

The easiest way to do this is using the SoftBody POP. No scripting necessary. SoftBody -> Collision (Slide) -> Drag will do it all.

I have a hipfile that I put together to prove it. I'll post it if you need it.

Good luck!

Jason

Link to comment
Share on other sites

Thanks Jason for your reply. Unfortunately I have to do this through my own scripted operation.

My problem now is making the changes that my script applies to the grid to remain there once the sphere is removed from the collision point on the grid.

I'm pretty sure the reason why the grid returns to its normal form is becuase inside the grid's sop network the grid primitive is at the top of the network and hence everytime the scene is refreshed the grid points are reset to their original positions which removes the deformations.

To see what I mean I've attached the hip file i'm currently working on to this post. My script is contained inside the SnowDeform1 node located inside the snow SOP. The SnowDeform basically takes three parameters.

-max_displace: not used

-collision_radius: the radius of the collision sphere

-collision_zone_center: the center of the collision sphere (the center of the ball in world coordinates for this case)

Thanks,

Mike

snow_deform_test2.zip

Link to comment
Share on other sites

I really think you need to be in POPs one way or another ...

17032[/snapback]

Another technique is to perform "simulations" by reading and writing the same file - with a reset frame chosen by a SwitchSOP.

The collisons can be fudged with a RaySOP.

In psuedocode:

- If frame one, Input the rest grid, else Read sim.`$F-1`bgeo

- Project grid vertically down against the geo input. (If the geo input is above the grid then nothing will happen)

- Write the sim.$F.bgeo

There are some subtleties that you'll figure out on the way :)

This still avoids scripting - as do can do almost anything you want to in Houdini as is. If you REALLY HAVE TO SCRIPT, then perform the opsave of the geo and opcook -F the FileSOP to refresh contents and such.

Houdini is basically equivalent to visual scripting. You could merely opscript out the network, simpiify it and there you have your script. All done in 20 lines of code which all it does it create these operations.

As an aside:

This has always been a RFE for Side Effects to create a SOP system which would allow cyclic links - like Feedback or a Loop SOP Subnet. This mechanism for feedback is the shared file in this case - and not geometry stored in RAM.

Link to comment
Share on other sites

Okay I've setup the network like Jason suggested, however I can't seem to figure out where to call the opsave and opcook other than in the textport which doesn't update things in a loop.

Do you put them inside a .cmd file and use it in conjunction with #pragma callback? Or am I totally off?

Thanks,

Mike

Link to comment
Share on other sites

Do you put them inside a .cmd file and use it in conjunction with #pragma callback? Or am I totally off?

17083[/snapback]

Ok, I'm talking about using Hscript for the scripting process to save the file out and read the file in, not VEX at all. VEX could only solve for the collision aspect if you didn't way to use the RaySOP - see the VEX intersect() function.

If you wanted to manually script the collision, use VEX; to code the simulation loop (progressively modifying the geometry) then use hscript. Again, all these things are possible without using a single line of hscript OR vex - just the simplest of expressions in the FileSOP to read the geometry back in.

Any clearer? :)

Link to comment
Share on other sites

Ah okay now I understand what you mean. So those hscript commands would belong in a postframe script which i can use in the mantra renderer.

I think I'm almost done. I've got something thats really close to what i was hoping for. Only problem now is that after consecutive iterations, the depth of the deformation on the grid is kind of averaged out. But i think its just a matter of tweaking some of the paramters.

Thanks again everyone, especially Jason for your help and advice :D

Mike

Link to comment
Share on other sites

Ah okay now I understand what you mean. So those hscript commands would belong in a postframe script which i can use in the mantra renderer.

Yeah, depends what your output should be... i.e. do you want an animated geometry sequence or do you want to render them?

You could put the script in a GeometryROP driver - or a scripted loop of your own from which you use opsave to write out the geometry.

You could make this as compilcated as you want! ;)

Link to comment
Share on other sites

Hello

Thanks Edward for that extra link for the for loop, that could come in handy later :D

I just have a few general questions about scripting in Houdini.

1. How do you import attributes (such as rotation rx,ry,rz) into a custom VEX function?

2. What's the best way to manipulate translation & rotation within VEX, sops or chops?

3. How do you read/modify point values from multiple input nodes in VEX?

4. Is there a way to pass the center of a sphere in world coordinates that exists in an sop network A into sop network B?

Thanks again for your help,

Mike

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...