Gizmo on arm with custom handle without the utility layer?

Hi, I was trying to implement a method to rotate and object around another point.
But cant get it to work…so i made you an minimal example so maybe you can show me how to do it.
So by dragging the red handle the “arm” should rotate. The parent transform node should remain as it is. Thanks.

Uncaught When setting a custom mesh on a gizmo, the custom meshes scene must be the same as the gizmos (eg. gizmo.gizmoLayer.utilityLayerScene)

Playground: https://www.babylonjs-playground.com/#4M8ANG#3

Added an animation to demonstrate the motion: https://www.babylonjs-playground.com/#4M8ANG#4
Update 2: https://www.babylonjs-playground.com/#4M8ANG#6 attachedMesh was missing

I’m taking a look …

1 Like

Sorry, I forgot a part in PG. Please refer to this example:
https://www.babylonjs-playground.com/#4M8ANG#6

Is it possible to remove a mesh from a scene and attach it to the gizmo utility layer scene @Evgeni_Popov ?
I could easily add a new cylinder mesh at the position of MESH_handle and it works fine.

1 Like

I tried cloning the mesh but didn’t find a way to move to to utility layer.

In my case it would actually work better in the main scene, because that way it can be occluded and feel more natural. The utility layer, if I understand correctly, is always shown on top of the scene. In the project I have different levers and those should be occluded by other meshes. Think about a room with levers on the walls. I dont want to show levers thought the walls.

You can call scene.removeMesh(mesh) to remove the mesh from the source scene and utilityLayerScene.addMesh(mesh) to add it to the utility layer scene. At least that’s what the asset container is doing to move assets from one scene to another.

Just tried: https://www.babylonjs-playground.com/#4M8ANG#7
seems to not be working for me… and yes, this way the handle will appear on top of other objects.

scene.removeMesh(MESH_handle);
gizmo.gizmoLayer.utilityLayerScene.addMesh(MESH_handle);
gizmo.setCustomMesh(MESH_handle);

When a mesh is added in a scene, its _scene property is not updated. I don’t know if it’s expected (@Deltakosh ?). You can try:

MESH_handle._scene = gizmo.gizmoLayer.utilityLayerScene;.

Also, your mesh is parented to a mesh that is still in the original scene, I’m not sure it’s something supported by the engine…

Unfortunately doesn’t seem to work neigher. Probably mesh moving is not supported yet.

scene.removeMesh(MESH_handle);
MESH_handle.setParent(null);
MESH_handle._scene = gizmo.gizmoLayer.utilityLayerScene;
gizmo.gizmoLayer.utilityLayerScene.addMesh(MESH_handle);
gizmo.setCustomMesh(MESH_handle);

I’m thinking about using new BABYLON.PointerDragBehavior() to allow dragging of both pieces.
Then find a way to calculate the right angle between the two and use that angle to rotate the arm.
Maybe you do know a function that will help me align two objects in 3D space? Some kind of vector difference between starting position between the two handles. Oh yeah, parenting doesnt work well with pointer drag behavior… this gonna be a tough one!

It seems it is setCustomMesh that does not work, but moving the mesh into the utility layer scene does work:

http://localhost:1338/Playground/index-local.html#4M8ANG#15

If you uncomment the setCustomMesh call, you will see that the handle is there but out of the camera view (rotate to see it).

Note it’s easier to debug things by showing the inspector for the utility layer scene: you can do ss.debugLayer.show() in the console (I have set window.ss with the utility layer scene).