Simple PolygonMesh Collision Deformer

Hey guys,

Let's start this community and share some snippets of codes and graphs. I wanted to start here with a very (very!) basic PolygonMesh collision deformer.

This is using the vertex' normal to search for an odd number of backface hits using SpatialQuery.

See attached canvas graph

The collision code is in the MeshCollide node.

A neat feature of the line intersection method on the SpatialQuery is that it returns the hits in sorted manner from the start point to the end point. This is something the code is also relying on by simply iterating the hits until we find the first front-faced hit and ignore the rest (since those would be further front-faced hit positions.)

Let me know if you like it. If you use it, share back!
We'd all love to see what you build with it!



  • EricTEricT Administrator, Moderator, Fabric Employee Posts: 304 admin

    Just a suggestion, if we're sharing code, I think we should try to attach a picture of the effect as well if possible. Thanks for sharing! Will check it out tonight!

    Eric Thivierge
    Kraken Developer
    Kraken Rigging Framework

  • Roy NieterauRoy Nieterau Posts: 258 ✭✭✭
    edited November 2015

    I seem to be unable to edit and update the above post. (Apparently it locks after a given period?) I wanted to add in the image there so it's at the top. But here goes.

    What it does

    Basically the white sphere here acts as the collider and deforms the orange sphere's vertices (as such is the deformed) so it is outside of its collider pushing them along its normals. (Pushing to closest point on surface should be trivial to implement actually!)

    It should work with any arbitrary PolygonMesh shapes. (Though if the collider mesh is not a closed surface it's not accurate, see below)

    How it works

    From the white object's vertices it will raycast in the direction of its normals and use the hits to decide whether it's inside the collider. It assumes an odd amount of front faces hits (frontHits % 2 != 0) to be a collision if there's also at least one back face hit.

    This is similar to the even-odd-rule as described here on Wikipedia: Point in Polygon - Ray casting algorithm. But then of course using that as a raycast in 3D as opposed to a flat 2D polygon.

    For this to work accurately it is assumed that the collider object is a closed surface, otherwise raycasting against a "open hole" would make it hard to detect whether the vertex should be inside/outside. (One could use the Bullet extension to create a Convex Hole given any open mesh if one really needs to work with open meshes)

    Attached is the updated graph which I used to create the above preview image. It has a bit more elaborate debug drawing at the end of the graph. (Note that this also contains a small extra function that creates Lines from the difference between two meshes so I can draw those difference lines)

  • Roy NieterauRoy Nieterau Posts: 258 ✭✭✭

    Just to add a bit on how this could be used.

    Snow Collisions anyone?

    See example video here

    Here I'm combining this technique with something that keeps the "biggest delta" over time from the original mesh so we can quickly and easily create snow-like patterns at interactive rates.

  • malbrechtmalbrecht Fabric for Houdini Posts: 752 ✭✭✭

    Moin, Roy,

    very cool result - thanks a ton for sharing! Now all we need is to reproduce Houdini's "sand solver" and Christmas, Easter and Samhain can be celebrated all in one minute :dizzy:


    Marc Albrecht - - does things.

  • Roy NieterauRoy Nieterau Posts: 258 ✭✭✭
    edited December 2015

    @malbrecht Thanks!

    I'm using a (somewhat customized) version of this implementation in production right now. Once projects are released I'll drop a link here to show usage!

    The last graph I posted was lacking some optimizations, eg.:

    • Performing prepareForSpatialQueries on the Collider.
    • Performing a bounding box check before collisions.
    • Performing a bounding box check per vertex before raycast.

    Even faster! I hope to be able to share an improved version here soon!

    Any other features anyone is looking for?

  • Hyun S KimHyun S Kim Posts: 6

    additional Possible feature I wished for, we have ability to control the ray direction ( other than intersect point with normal ). I have been utilized on geometry line/mesh using as reflector to control the ray direction in maya plugin
    ( sourse postion --> closest point on reflector model --> finding vector and flip vector ---> check the ray hit ---> find the ray intersect point ---> final direction vector for deformation )
    just wishful thinking ^^ I might want to try it out on FE from now on!

  • Roy NieterauRoy Nieterau Posts: 258 ✭✭✭

    @Hyun S Kim sounds like it shouldn't be too much trouble. What's the expected result you're looking for? Not sure I'm understanding what you're saying.

    How I'm reading it:
    For each source point get closest point on collision mesh. From that closest point, shoot raycast to the source point and check the odd/even rule for collision. If any collision, move source point to that closest point.

    Ia that what you mean?

  • Hyun S KimHyun S Kim Posts: 6
    edited August 2016

    @Roy Nieterau Thanks for the reply and sorry for lack of explanation. I think your explanation is correct with one more thing. Finding closest point not on collision mesh but using other mesh using as reflection model. here is the quick drawing to explan better I guess..^^

  • knekkeknekke Posts: 12
    edited November 2016

    Noob Alert!!
    Hi, I pretty much need/want to do what you did in the snow example. Coming from Softimage/ICE I can figure out the collision part, but how do you "store the biggest delta over time"?
    Sorry if I'm missing the obvious....

Sign In or Register to comment.