Implementing a 3D transform gizmo using JavaFX

516 views Asked by At

My goal is to create a simple translation and rotation gizmo in JavaFX.

There are plenty of examples of how this can be implemented in C++ (e.g. https://nelari.us/post/gizmos/). But I am having trouble translating this code into JavaFX. Mainly because the underlying Math is not easily accessible using JavaFX (e.g. getting a camera matrix from the PerspectiveCamera). I am having a hard time figuring out how to get the right ingredients from the available JavaFX components.

My plan is to implement MouseEvent handlers for pressing and dragging, and then project the drag motion in the respective transform space (translation, rotation). But I am really clueless on where to start.

I tried searching online for any implementations of this in JavaFX and I couldn't find anything.

I am hoping someone in this community can either help me out translating the C++ tutorial I linked at the beginning of this post or help me add the right drag handlers for the Gizmo components in the code linked below.

Below follows a gist containing a test application of a simple 3D scene containing the gizmo and with a simple camera implementation (thanks to the https://github.com/FXyz/FXyzLib library for this). It's a lot of lines but most are due to the classes used to create the visual elements, the really important class is the Gizmo class.

https://gist.github.com/dosier/f075259da0d87f431a361fd300b7e133 (code is too long to include in here)

Edit #1 - 8th of October:

I have tried setting a drag detected handler for each of the drag cones, and then set a drag handler in the scene. I don't want the returned coordinates of the drag event be dependent on whether a node has been intersected. I tried the code linked below, but it's not giving the correct results. I think if I have this figured out I can get the translate part of the gizmo functional, then only rotation is left:

final PickResult currentPickResult = me.getPickResult();
final Node currentNode = currentPickResult.getIntersectedNode();
final Point3D currentPoint;
if(currentNode != null)
    currentPoint = currentNode.localToParent(currentPickResult.getIntersectedPoint());
else
    currentPoint = currentPickResult.getIntersectedPoint();

Edit #2 - 8th of October:

So I made some strives towards porting the code in the tutorial I linked to JavaFX, I managed to find some (experimental) code in the com.sun.javafx package that seems to provide all the ingredients I need to work out the math. But I don't quite understand all parts of the math in the tutorial. Anyways, here is a gist with my current progress: https://gist.github.com/dosier/3481e18dfaaf38a36f4e91b525917642

0

There are 0 answers