Create 3D scenes in Java with the help of the 3D document control Aspose.3D

A 3D scene is a way of displaying 3D shapes on a computer. In this guide, we'll learn how to create 3D scenes using Java without the need for any special 3D software. Afterwards, we will save the 3D scene in the FBX file format, which is a common way of sharing 3D content. So, let's get started.

Aspose.3D  is a feature-rich game software and computer-aided design (CAD) API that can manipulate documents without relying on any 3D modeling and rendering software . API supports Discreet3DS, WavefrontOBJ, FBX (ASCII, Binary), STL (ASCII, Binary), Universal3D, Collada, glTF, GLB, PLY, DirectX, Google Draco file formats, etc. Developers can easily create, read, convert, modify and control the essence of 3D file formats.

Aspose.3D latest download (qun: 666790229)icon-default.png?t=N7T8https://www.evget.com/product/3915/download

Java 3D API for creating 3D scenes - free download

We will useAspose.3D for Java API to create and read 3D scenes. It is a powerful API that allows you to create, edit and save 3D scenes in a variety offormats. It allows the creation and editing of 3D meshes, materials and textures. The API also supports adding and configuring lights, cameras, and animations.

Pleasedownload the JAR of the APIor add the followingpom in your Maven based Java application. xml configuration.

<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 these steps:

  1. Create an instance of the Scene class.
  2. CallcreateChildNode() method to add some geometry or shapes to be displayed on the screen, such as a cylinder.
  3. Set child node attributes, for exampleMaterial.
  4. First beginningLightThe first instance.
  5. tuningcreateChildNode()method additionLightbody.
  6. Finally, use the save() method to save the scene as FBX. It takes the output file path and FileFormat.FBX7500ASCII as arguments.

The following code example showshow to create a simple 3D scene using Java.

// This code example demonstrates how to create a simple 3D scene and save in FBX file.
// Initialize 3D scene
Scene scene = new Scene();

// Initialize Cylinder object
Cylinder cylinder = new Cylinder();
cylinder.setName("Cylinder");

// Create a child node and add Cylinder object
Node node = scene.getRootNode().createChildNode(cylinder);

// Set child node properties
LambertMaterial material = new LambertMaterial();
material.setDiffuseColor(null);
material.setName("Lambert");
node.setMaterial(material);

// Add Light entity
Light light = new Light();
light.setLightType(LightType.POINT);
light.setName("Light");
scene.getRootNode().createChildNode(light).getTransform().setTranslation(new Vector3(10, 0, 10));

// Output file path
String output = "C:\\Files\\document.fbx";

// Save 3D scene document
scene.save(output, FileFormat.FBX7500ASCII);

Create a simple 3D scene using Java

Reading 3D scenes using Java

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

  1. Create an instance of the Scene class.
  2. Use the open() method to load an existing 3D document.
  3. Cycling World ChildNodes Attributes
  4. Finally, the property values ​​are displayed.

The following code example demonstrateshow to load and read a 3D scene using Java.

// This code example demonstrates how to read a 3D scene from FBX file
// Initialize a Scene class object
Scene scene = new Scene();

// Load an existing 3D document
scene.open("C:\\Files\\document.fbx");

for(Node node : scene.getRootNode().getChildNodes())
{
Entity entity = node.getEntity();
System.out.println("Entity Name: " + entity.getName());

if (node.getMaterial() != null)
{
Material material = node.getMaterial();
System.out.println("Material Name: " + material.getName());

PropertyCollection props = material.getProperties();

// List all properties using foreach
for(Property prop : props)
{
System.out.println(prop.getName() + " : " + prop.getValue());
}
}
}

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

In this article, we learned how to create a 3D scene in Java. We also saw how to render a 3D scene in FBX format and read its subannotations and properties programmatically using Java. By leveraging Aspose.3D for Java, you can simplify 3D graphics programming in Java applications. If you have any questions, please feel free to contact me~

Guess you like

Origin blog.csdn.net/m0_67129275/article/details/134965892