JCSG
Java implementation of BSP based CSG (Constructive Solid Geometry)
Install / Use
/learn @miho/JCSGREADME
JCSG
<a href="https://foojay.io/today/works-with-openjdk">
<img align="right"
src="https://github.com/foojayio/badges/raw/main/works_with_openjdk/Works-with-OpenJDK.png"
width="100">
</a>
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 (see CSG and Node classes). Thanks to the author for creating the csg.js library.
There's also the related VCSG library, a plugin for VRL-Studio and two extension libraries: JCSG-MeshExtension and JCSG-PathExtension.
In addition to CSG this library provides the following features:
- optimized
difference()andunion()operations (many thanks to Sebastian Reiter) - extrusion of concave, non-intersecting polygons (uses Poly2Tri for triangulation)
- convex hull (uses QuickHull3D)
- weighted transformations (Scale, Rotation, Translation and Mirror)
- STL import and export (STLLoader from Fiji)
- OBJ export including material information (see screenshot below)
- supports conversion of CSG's to
JavaFX 3Dnodes - 3d text support (using FXyz)
JCSG on stackoverflow.

To see what's possible with JCSG try JFXScad.

How to Build JCSG
Requirements
- Java >= 11
- Internet connection (dependencies are downloaded automatically)
- IDE: Gradle Plugin (not necessary for command line usage)
IDE
Open the JCSG Gradle project in your favourite IDE (tested with NetBeans 7.4) and build it
by calling the assemble task.
Command Line
Navigate to the Gradle project (e.g., path/to/JCSG) and enter the following command
Bash (Linux/OS X/Cygwin/other Unix-like shell)
bash gradlew assemble
Windows (CMD)
gradlew assemble
Code Sample:
// we use cube and sphere as base geometries
CSG cube = new Cube(2).toCSG();
CSG sphere = new Sphere(1.25).toCSG();
// perform union, difference and intersection
CSG cubePlusSphere = cube.union(sphere);
CSG cubeMinusSphere = cube.difference(sphere);
CSG cubeIntersectSphere = cube.intersect(sphere);
// translate geometries to prevent overlapping
CSG union = cube.
union(sphere.transformed(Transform.unity().translateX(3))).
union(cubePlusSphere.transformed(Transform.unity().translateX(6))).
union(cubeMinusSphere.transformed(Transform.unity().translateX(9))).
union(cubeIntersectSphere.transformed(Transform.unity().translateX(12)));
// save union as stl
try {
FileUtil.write(
Paths.get("sample.stl"),
union.toStlString()
);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
Thanks to
-
JetBrains for their IntelliJ IDEA license(s)
-
Evan Wallace for creating the JavaScript library csg.js
Related Skills
node-connect
345.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
106.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
