Create 3D Scene in Java

A 3D scene is a way to show 3D shapes on a computer. In this guide, we’ll learn how to create a 3D scene using Java without needing any special 3D software. After that, we’ll save the 3D scene in an FBX file format, which is a common way to share 3D stuff. So, let’s begin.

The following topics shall be covered in this article:

  1. Java 3D API to create 3D scene — free download
  2. Create a simple 3D scene in Java
  3. Read a 3D scene using Java
  4. Free learning resources

Java 3D API to Create 3D Scene - Free Download

We will use the Aspose.3D for Java API to create and read a 3D scene. It is a powerful API that allows you to create, edit, and save 3D scenes in a variety of formats. It allows creating and editing 3D meshes, materials, and textures. The API also enables adding and configuring lights, cameras, and animations.

Please download the JAR of the API or add the following pom.xml configuration in a Maven-based Java application.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository> 
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-3d</artifactId>
    <version>23.9.0</version>
</dependency>   

Create a Simple 3D Scene using Java

We can create a simple 3D scene by following the steps below:

  1. Create an instance of the Scene class.
  2. Call the createChildNode() method to add some geometry or a shape to show on screen, e.g., a cylinder.
  3. Set child node properties such as Material.
  4. Initialize a Light class object.
  5. Call the createChildNode() method to add a Light entity.
  6. Finally, save the scene as FBX using the save() method. It takes the output file path and FileFormat.FBX7500ASCII as arguments.

The following code sample shows how to create a simple 3D scene using Java.

Create a Simple 3D Scene using Java

Create a Simple 3D Scene using Java.

Read 3D Scene using Java

We can also load an FBX document and read a 3D scene by following the steps below:

  1. Create an instance of the Scene class.
  2. Load an existing 3D document using the open() method.
  3. Loop through ChildNodes properties
  4. Finally, display property values.

The following code sample shows how to load and read a 3D scene using Java.

Entity Name: Cylinder
Material Name: Lambert
Emissive : (0 0 0)
Diffuse : (1 1 1)
Ambient : (0 0 0)
Entity Name: Light

Get a Free License

You can get a free temporary license to try Aspose.3D for Java without evaluation limitations.

Free Learning Resources

Besides creating or reading a simple 3D scene, learn more about the library and explore various other features using the resources below:

Conclusion

In this article, we have learned how to create a 3D scene in Java. We have also seen how to render a 3D scene in FBX format and read its child notes and properties programmatically in Java. By leveraging Aspose.3D for Java, you can simplify 3D graphics programming in Java applications. In case of any ambiguity, please feel free to contact us on our free support forum.

See Also