Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Union, intersection and difference between JavaFX 3D objects

Is there any way to perform Boolean operations like union, intersections and difference between JavaFX 3D objects, let's say for example between a Sphere instance, a Cylinder instance, and a Box instance.

JavaFX 2D objects which inherit from Shape class already have union() and subtract() methods http://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/Shape.html

I was wondering if there is such a thing for Shape3D objects in JavaFX, or the F(X)yz library. If not I would love to know about the best way to implement these operations.

Kind regards,

like image 369
Jean-Baptiste-B Avatar asked Dec 20 '22 06:12

Jean-Baptiste-B


1 Answers

As @jdub1581 says, in JavaFX there's no straight way to get boolean operations with 3D primitive shapes.

That doesn't mean those operations can't be performed, given you know or you provide the mesh info.

While F(X)yz library has many complex 3D shapes, where the mesh info is fully provided, it doesn't perform boolean operations with them.

3D boolean operations are the basis for the Constructive Solid Geometry technique. A CSG solid is constructed from several primitives (cube, prism, sphere, cylinder, cone and torus) using boolean operations (union, intersection, difference).

There is a Java based implementation of this technique, JCSG. From Michael Hoffer, his author:

Java implementation of BSP based CSG (Constructive Solid Geometry). It is the only simple and free Java implementation I am aware of. This implementation uses an optimized CSG algorithm based on csg.js.

Based on that implementation, JFXScad is a JavaFX based project using JCSG for creating complex shapes ready to be 3D printed, or exported as STL/OBJ.

Using this project, you can type on the left panel and the 3D shape is generated on the right one. This is one of the available samples:

JFXcad

As you can see, several arms are created by extrusion, and combined with Cylinders using union, difference, ...

like image 98
José Pereda Avatar answered Dec 28 '22 09:12

José Pereda