Drag & Drop Spatial in / into (running) Scene

i have a running scene and by clicking on a Spatial i want to move its position with my mouse and after clicking one more time it should be set at the new position.

I know it is difficult to position something in a 3D-Scene only with the mouse, but to get the complete right position i want to set up the cam in the middle on top (like its 2D from Top) and set the height-position of the spatial by a second cam-view or something else. The first thing to get a solution for my problem would be, just to move the spatial with dragging by the mouse.

Any ideas how to do this?

Thanks for your help,

Fire a ray in an actionlistener when the mouse is pressed, save the spatial that was hit. Then in an analoglistener, listen for mouse move events, and move the spatial (if one is selected). When u let go of the mouse, set the selected spatial variable to null.

thanks for your answer. Getting the hitted Spatial runs. But then I have the problem, that I need to identify it. I have a list with all my Spatials and i want to know which of it was hitted. I can move the Spatial and change its size e.g., but the parameter tmpSpatial.getName() doesn´t give me the right “key”. If I use a Geometry instead, the getName() parameter gives the setted Name.

The code:

[java]Spatial tmpKugel = assetManager.loadModel(“Models/GelbeKugel/Kugel.mesh.j3o”);
sensors.put(id, tmpKugel);

[java]Geometry markedGeometry = results.getClosestCollision().getGeometry();
Spatial tmpKugel = markedGeometry;
System.out.println("Name: " + tmpKugel.getName());[/java]

How can i identify which Spatial of my list was hitted?

Thanks for your help,

You’ll have to traverse up the hierarchy until the parent is null or in your list

1 Like

Yes you are right, thanks! I also just found it^^

[java]markedGeometry = results.getCollision(i).getGeometry();
String id = markedGeometry.getParent().getName());[/java]