We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Snapping object to certain point on a geometry

Home Forums Puzzles Snapping object to certain point on a geometry

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1640
    Yaroslav
    Participant

    While being able to snap a mesh to another geometry’s certain vertex manually with three.js and a bunch of code, i think it would be great to be able to define, say, a vertex group in Blender under an ‘xyz’ name and then just have any object snapped to its centroid by calling “snap to object xxx” from Puzzles.

    I can imagine a ton of use cases for this simple action: basically, any complex product configurator which has resizable geometries in it needs an easy way to define “snap points” which can be used to attach objects to each other rather than writing code to detect collisions with raycasters or iterating around to find a vertex which is nearest to the border of a bounding mesh in certain direction – not too complex but annoying as hell.

    Is there any chance you guys could consider adding this in one of the following releases?

    #1642
    Will Welker
    Customer

    I have accomplished this by creating empties. The empties can be named, numbered and grouped in Blender for easy organization. Then you place the empty where you want it in the scene and it will be available in the Puzzles object picker. This also gives you the ability to place objects like your camera at a location where there is no mesh. In this example, my empties are named with integers so I can iterate through them with simple math in the Puzzles editor.
    Empties

    #1645
    Will Welker
    Customer

    Here is my Puzzle logic for navigating through these empties:

    Logic

    #1649
    Yaroslav
    Participant

    Will, thank you for a detailed explanation and examples. Your case of navigating around a pre-defined geometry makes perfect use of empties as locations, which, i believe, is the currently recommended solution.

    My case is slightly different, as i have a dynamically resized geometry in my scene. User has an ability to resize a ring, which is done with the following Puzzle:

    Resize function

    As the ring is resized, my target point would have to move around with the edge of the ring to allow proper snapping – so, in this case, i would have to add around 20 empties per ring model to snap the gemstone to a correct location for each possible size. In this particular scene, there are 8 ring types available to user, each having slightly different properties and surface geometries, and there are two ring objects – one for men and one for women. This setup gives us 20 x 8 x 2 = 320 empties to keep in the scene. While theoretically it shouldn’t be much of a problem, imagine spawning these in Blender file for each of 500+ ring models i have in my final product.

    Theoretically i can add a Blender python script to do the heavy lifting for me, but with complex geometries, where the final vertex position might be moved by user in any direction, even this would not suffice, and i’ll have to embed some custom JS function to locate vertexes.

    That’s why i thought it would be extremely convenient to be able to define a group of vertices in Blender and use it as a snapping point.

    Yuri, V3D team – do you think there is a smooth way to address this?

    #1652
    Will Welker
    Customer

    I have done some playing around with parenting empties and meshes to a ring. A hidden mesh will follow along with the size change of the ring but the snap-to function will only snap to the mesh’s location at load time. So one solution would be to make the snap-to function work on object that get their location changed by scaling of the parent object.

    In the meantime, there are two possible ways that could help you:
    1. Set the origin point of you ring to the location you want jewels to snap to.
    Or…
    2. Parent all of the jewels to the ring and hide all except the one you want shown.

    #1659
    Yaroslav
    Participant

    Will, thanks for your time on this issue.

    one solution would be to make the snap-to function work on object that get their location changed by scaling of the parent object

    I tried this myself as well and it seems more of a bug – theoretically, snap shouldn’t stop working if a geometry was modified. Fixing this would actually solve my whole case, as it would allow to move any object in accordance with the other object without making it a child of the latest.

    For now, i was able to work around this for my specific isolated case with the following solution. For anyone reading this who doesn’t have experience with JS – please note this solution is not universal and works only for my specific case where the object we are snapping to:

    – is not being dynamically rotated
    – aligned to be resized on Z-axis

    So what i did was making a simple function which gets a bounding box of my ring and finds the position of its surface after resize:

       v3dApp.ExternalInterface.snapObjectToBound = function(obj_name, obj_pos_name)
        {
    
          var Obj = v3dApp.scene.getObjectByName(obj_name);
          var ObjPosition = v3dApp.scene.getObjectByName(obj_pos_name);
    
          var BoundBox = new v3d.Box3().setFromObject(ObjPosition);
          var BoundDepth = BoundBox.getSize().z;
    
          var Pos = ObjPosition.position;
    
          Obj.position.z = BoundDepth/2;
        }

    Then, when a resize callback happens, all i have to do is to call snapObjectToBound with my gem as an object to get bounded and ring as a bounding target to make it fit:

    My resume for this case is: while being able to solving it with JS, snapping objects to pre-defined vertexes of another object (defined with either an Empty or with a Vertex Group, whatever works for developers best) is a vital function which should not be broken after modifying an object (at least with built-in Puzzle modifiers). All in all, fixing the behavior Will mentioned in his previous post seems important.

    #5535
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.