Union, intersection and difference between JavaFX 3D objects
Asked Answered
P

1

5

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,

Paleobotany answered 24/2, 2015 at 14:4 Comment(1)
Using the default shapes, simple answer is NO. There is no access to the Mesh data. There is a project github.com/miho/JCSG that offers such features.Muscarine
F
12

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, ...

Factional answered 24/2, 2015 at 16:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.