Node — Aspose.3D FOSS for Java
Overview
The Node class represents a named element in the Aspose.3D scene graph. Each node can hold one Entity (such as a Mesh or Camera), maintains parent-child relationships with other nodes, and carries a local transform. Nodes are the primary way to organize 3D objects in a scene hierarchy.
import com.aspose.threed.Scene;
import com.aspose.threed.Node;
Scene scene = new Scene();
// Access the root node via getter
Node root = scene.getRootNode();
// Create a child node
Node child = root.createChildNode("my_node");
// Iterate child nodes via getter
for (Node node : root.getChildNodes()) {
System.out.println(node.getName());
}Constructor
The Node constructor initializes a node with an optional name.
| Parameter | Type | Description |
|---|---|---|
name | String | Optional name for the node |
Properties
All node attributes are accessed via getter/setter methods.
| Name | Type | Getter | Setter | Description |
|---|---|---|---|---|
name | String | getName() | setName(String) | Human-readable identifier for the node |
entity | Entity | getEntity() | setEntity(Entity) | The primary entity attached to this node (e.g., Mesh, Camera). Shortcut for the first element of getEntities(). |
entities | List<Entity> | getEntities() | – | All entities attached to this node (read-only) |
material | Material | getMaterial() | setMaterial(Material) | The primary material assigned to this node |
materials | List<Material> | getMaterials() | – | All materials assigned to this node (read-only) |
childNodes | List<Node> | getChildNodes() | – | List of child nodes |
parentNode | Node | getParentNode() | setParentNode(Node) | Immediate parent node in the scene hierarchy |
parentNodes | List<Node> | getParentNodes() | – | All parent nodes (inherited from Entity; supports instancing) |
visible | boolean | getVisible() | setVisible(boolean) | When false, the node and its subtree are hidden |
excluded | boolean | getExcluded() | setExcluded(boolean) | When true, this node is excluded from rendering |
transform | Transform | getTransform() | – | Local transform (translation, rotation, scale) |
globalTransform | GlobalTransform | getGlobalTransform() | – | World-space transformation matrix |
assetInfo | AssetInfo | getAssetInfo() | setAssetInfo(AssetInfo) | Asset metadata attached to this node, if any |
properties | PropertyCollection | getProperties() | – | Custom properties attached to this node |
Methods
| Method | Return Type | Description |
|---|---|---|
createChildNode(String name) | Node | Creates and attaches a new child node with the given name |
createChildNode(String name, Entity entity) | Node | Creates a child node and assigns an entity to it |
addChildNode(Node node) | void | Adds an existing node as a child of this node |
getChild(String name) | Node | Finds a direct child node by name |
addEntity(Entity entity) | void | Attaches an additional entity to this node |
merge(Node node) | void | Merges another node’s children and entities into this node |
evaluateGlobalTransform(boolean withGeometricTransform) | Matrix4 | Returns the world-space transform matrix; pass true to include geometric offsets |
getBoundingBox() | BoundingBox | Computes the axis-aligned bounding box of the node in world space |
getProperty(String name) | Object | Gets a property value by name |
findProperty(String name) | Property | Finds a property by name |
Example
Create a scene, attach a mesh to a node, and traverse the scene graph:
import com.aspose.threed.Scene;
import com.aspose.threed.Node;
import com.aspose.threed.*;
Scene scene = new Scene();
Mesh mesh = new Mesh();
mesh.getControlPoints().add(new Vector4(0, 0, 0, 1));
mesh.getControlPoints().add(new Vector4(1, 0, 0, 1));
mesh.getControlPoints().add(new Vector4(0.5, 1, 0, 1));
mesh.createPolygon(0, 1, 2);
// Attach mesh to a child node
Node node = scene.getRootNode().createChildNode("triangle", mesh);
// Traverse child nodes using getter
for (Node child : scene.getRootNode().getChildNodes()) {
Entity entity = child.getEntity();
if (entity != null) {
System.out.println("Node '" + child.getName() + "': " + entity.getClass().getSimpleName());
System.out.println(" Excluded: " + child.getExcluded());
}
}