This is a Java3D graphics application demonstrating 3D rendering using the JOGL (Java OpenGL) implementation. The project uses Maven for build management and requires Java 11+.
mvn clean compile # Compile the project
mvn clean package # Package as JAR./run.sh # Run via wrapper script (recommended for Java 25+)
mvn exec:java # Run via Maven (requires MAVEN_OPTS for Java 25+)
java -jar target/java3d-project-1.0-SNAPSHOT.jar # Run compiled JAR directlyFor Java 25+, native access permissions are required:
export MAVEN_OPTS="--enable-native-access=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.desktop/sun.awt=ALL-UNNAMED --add-opens=java.desktop/sun.awt.X11=ALL-UNNAMED"
mvn exec:javamvn test # Run all tests (currently no tests in project)mvn clean # Remove target directory and build artifacts- Java3D 1.6.0 (SciJava implementation) - 3D graphics API
- JOGL 2.5.0 - Java OpenGL bindings for hardware-accelerated rendering
- GlueGen Runtime 2.5.0 - Required for JOGL native library loading
- Swing - UI framework for windowing
- Maven - Build and dependency management
- Java 11+ - Required (tested with Java 25)
The project follows a simple single-class architecture:
com.java3d.app.Java3DApp - Main application class that:
- Extends
JFrameto provide the application window - Creates a
SimpleUniversewhich manages the 3D viewing environment - Builds a scene graph in
createSceneGraph()containing:- BranchGroup (root): Top-level container for all scene elements
- TransformGroup nodes: Enable positioning and animation of objects
- Geometry objects: ColorCube and Sphere primitives
- Behavior nodes: RotationInterpolator for cube animation
- Lighting: DirectionalLight and AmbientLight for scene illumination
- BoundingSphere: Defines the active region for behaviors and lighting
Java3D uses a scene graph paradigm where objects are organized in a tree structure:
BranchGroup (root)
├── TransformGroup (cube) [writable transform capability]
│ ├── ColorCube
│ └── RotationInterpolator [animated rotation behavior]
├── TransformGroup (sphere) [static position]
│ └── Sphere [with Material/Appearance]
├── DirectionalLight
└── AmbientLight
Key concepts:
- Capabilities: Must be set before compiling the scene graph (e.g.,
ALLOW_TRANSFORM_WRITEfor animation) - Bounds: Define spatial regions where behaviors and lights are active
- Alpha: Timing mechanism for animations (4000ms rotation cycle, infinite loops with
-1) - Appearance/Material: Define object surface properties (color, specularity, shininess)
Linux Display Issues: If encountering graphics problems, software rendering can be forced:
export LIBGL_ALWAYS_SOFTWARE=1Native Libraries: JOGL requires platform-specific native libraries. Maven dependencies (jogl-all-main, gluegen-rt-main) automatically include natives for all platforms (Linux, Windows, macOS).
To add objects to the scene, modify the createSceneGraph() method:
- Create a
TransformGroupfor positioning/animation - Create the geometry (use
org.jogamp.java3d.utils.geometry.*utilities) - Optionally set
AppearanceandMaterialfor custom rendering - Add to the parent node before
root.compile()
Use Alpha (timing) + Interpolator (e.g., RotationInterpolator, PositionInterpolator) pattern:
- Alpha controls timing (duration, loop count)
- Interpolator modifies transform over time
- Must set
ALLOW_TRANSFORM_WRITEcapability on the TransformGroup - Set scheduling bounds to activate the behavior
Scene requires proper lighting to visualize materials:
AmbientLight: Provides base illumination (non-directional)DirectionalLight: Simulates distant light source (e.g., sun)- Both require
setInfluencingBounds()to define active region
The entry point is: com.java3d.app.Java3DApp
This is configured in pom.xml for both:
maven-jar-plugin(manifest main class)exec-maven-plugin(mvn exec:java)
