public class Node extends SceneObject
name, properties| Constructor and Description |
|---|
Node()
Initializes a new instance of the
Node class. |
Node(java.lang.String name)
Initializes a new instance of the
Node class. |
Node(java.lang.String name,
Entity entity)
Initializes a new instance of the
Node class. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
accept(NodeVisitor visitor)
Walks through all descendant nodes(including the current node) and call the visitor with the node.
|
void |
addChildNode(Node node)
Add a child node to this node
|
void |
addEntity(Entity entity)
Add an entity to the node.
|
Node |
createChildNode()
Creates a child node
|
Node |
createChildNode(Entity entity)
Create a new child node with given entity attached
|
Node |
createChildNode(java.lang.String nodeName)
Create a new child node with given node name
|
Node |
createChildNode(java.lang.String nodeName,
Entity entity)
Create a new child node with given node name
|
Node |
createChildNode(java.lang.String nodeName,
Entity entity,
Material material)
Create a new child node with given node name, and attach specified entity and a material
|
Matrix4 |
evaluateGlobalTransform(boolean withGeometricTransform)
Evaluate the global transform, include the geometric transform or not.
|
AssetInfo |
getAssetInfo()
Per-node asset info
|
BoundingBox |
getBoundingBox()
Calculate the bounding box of the node
|
Node |
getChild(int index)
Gets the child node at specified index.
|
Node |
getChild(java.lang.String nodeName)
Gets the child node with the specified name
|
java.util.List<Node> |
getChildNodes()
Gets the children nodes.
|
java.util.List<Entity> |
getEntities()
Gets all node entities.
|
Entity |
getEntity()
Gets the first entity attached to this node, if sets, will clear other entities.
|
boolean |
getExcluded()
Gets whether to exclude this node and all child nodes/entities during exporting.
|
GlobalTransform |
getGlobalTransform()
Gets the global transform.
|
Material |
getMaterial()
Gets the first material associated with this node, if sets, will clear other materials
|
java.util.List<Material> |
getMaterials()
Gets the materials associated with this node.
|
java.util.List<CustomObject> |
getMetaDatas()
Gets the meta data defined in this node.
|
Node |
getParentNode()
Gets the parent node.
|
Transform |
getTransform()
Gets the local transform.
|
boolean |
getVisible()
Gets to show the node
|
void |
merge(Node node)
Detach everything under the node and attach them to current node.
|
java.util.ArrayList<java.lang.Object> |
selectObjects(java.lang.String path)
Select multiple objects under current node using XPath-like query syntax.
|
java.lang.Object |
selectSingleObject(java.lang.String path)
Select single object under current node using XPath-like query syntax.
|
void |
setAssetInfo(AssetInfo value)
Per-node asset info
|
void |
setEntity(Entity value)
Sets the first entity attached to this node, if sets, will clear other entities.
|
void |
setExcluded(boolean value)
Sets whether to exclude this node and all child nodes/entities during exporting.
|
void |
setMaterial(Material value)
Sets the first material associated with this node, if sets, will clear other materials
|
void |
setParentNode(Node value)
Sets the parent node.
|
void |
setVisible(boolean value)
Sets to show the node
|
java.lang.String |
toString()
Gets the string representation of this node.
|
getScenefindProperty, getName, getProperties, getProperty, removeProperty, removeProperty, setName, setPropertypublic Node()
Node class.public Node(java.lang.String name,
Entity entity)
Node class.name - Name.entity - Default entity.public Node(java.lang.String name)
Node class.name - Name.public AssetInfo getAssetInfo()
public void setAssetInfo(AssetInfo value)
value - New valuepublic boolean getVisible()
Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("test-node", new Box());
node.setVisible(false);
scene.save("output.fbx");
public void setVisible(boolean value)
value - New value
Example:
The following code shows how to create a invisible node
Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("test-node", new Box());
node.setVisible(false);
scene.save("output.fbx");
public java.util.List<Node> getChildNodes()
Scene scene = Scene.fromFile("test.fbx");
for(var child : scene.getRootNode().getChildNodes())
{
//do your business
}
public Node createChildNode()
Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode();
node.setEntity(new Box());
scene.save("output.fbx");
public void merge(Node node)
Scene scene1 = Scene.fromFile("scene1.fbx");
Scene scene2 = Scene.fromFile("scene2.fbx");
scene1.getRootNode().merge(scene2.getRootNode());
scene1.save("merged.fbx");
public Node createChildNode(java.lang.String nodeName)
nodeName - The new child node's name
Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("new node");
node.setEntity(new Box());
scene.save("output.fbx");
public Node createChildNode(Entity entity)
entity - Default entity attached to the node
Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode(new Box());
scene.save("output.fbx");
public Node createChildNode(java.lang.String nodeName, Entity entity)
nodeName - The new child node's nameentity - Default entity attached to the nodepublic Node createChildNode(java.lang.String nodeName, Entity entity, Material material)
nodeName - The new child node's nameentity - Default entity attached to the nodematerial - The material attached to the nodepublic Entity getEntity()
Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("new node");
node.setEntity(new Box());
scene.save("output.fbx");
public void setEntity(Entity value)
value - New value
Example:
The following code shows how to create a new child node under root node
Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("new node");
node.setEntity(new Box());
scene.save("output.fbx");
public boolean getExcluded()
Scene scene = new Scene();
scene.getRootNode().createChildNode("excluded", new Box()).setExcluded(true);
scene.getRootNode().createChildNode("not excluded", new Box());
scene.save("output.usdz");
public void setExcluded(boolean value)
value - New value
Example:
The following code shows how to exclude specified node from exporting
Scene scene = new Scene();
scene.getRootNode().createChildNode("excluded", new Box()).setExcluded(true);
scene.getRootNode().createChildNode("not excluded", new Box());
scene.save("output.usdz");
public java.util.List<Entity> getEntities()
public java.util.List<CustomObject> getMetaDatas()
public java.util.List<Material> getMaterials()
public Material getMaterial()
Scene scene = new Scene();
var node = scene.getRootNode().createChildNode(new Box());
node.setMaterial(new LambertMaterial());
public void setMaterial(Material value)
value - New value
Example:
Scene scene = new Scene();
var node = scene.getRootNode().createChildNode(new Box());
node.setMaterial(new LambertMaterial());
public Node getParentNode()
public void setParentNode(Node value)
value - New valuepublic Transform getTransform()
Scene scene = new Scene();
var boxNode = scene.getRootNode().createChildNode(new Box());
//place the box at (10, 0, 0)
boxNode.getTransform().setTranslation(new Vector3(10, 0, 0));
public Matrix4 evaluateGlobalTransform(boolean withGeometricTransform)
withGeometricTransform - Whether the geometric transform is needed.
Scene scene = new Scene();
var boxNode = scene.getRootNode().createChildNode(new Box());
//place the box at (10, 0, 0)
boxNode.getTransform().setTranslation(new Vector3(10, 0, 0));
Matrix4 mat = boxNode.evaluateGlobalTransform(true);
System.out.printf("The box's global transform matrix is %s", mat);
public GlobalTransform getGlobalTransform()
Scene scene = new Scene();
var boxNode = scene.getRootNode().createChildNode(new Box());
//place the box at (10, 0, 0)
boxNode.getTransform().setTranslation(new Vector3(10, 0, 0));
var global = boxNode.getGlobalTransform();
System.out.printf("The box's position in world coordinate is %s", global.getTranslation());
public Node getChild(int index)
index - Index.
Scene scene = Scene.fromFile("input.fbx");
var node = scene.getRootNode().getChild(0);
System.out.printf("The first node of the file is %s", node.getName());
public Node getChild(java.lang.String nodeName)
nodeName - The child name to find.
Scene scene = Scene.fromFile("input.fbx");
var node = scene.getRootNode().getChild("box");
System.out.printf("The box node's translation is %s", node.getTransform().getTranslation());
public boolean accept(NodeVisitor visitor)
visitor - Visitor callback to visit the node
Scene scene = Scene.fromFile("input.fbx");
List<Mesh> meshes = new ArrayList<Mesh>();
scene.getRootNode().accept(new NodeVisitor() {
@Override
public boolean call(Node node) {
if(node.Entity instanceof Mesh)
meshes.add(((Mesh)node).getEntity());
//continue searching
return true;
}
});
public java.lang.String toString()
toString in class java.lang.Objectpublic BoundingBox getBoundingBox()
public void addEntity(Entity entity)
entity - The entity to be attached to the nodepublic void addChildNode(Node node)
node - The child node to be attached
Example:
The following code shows how to get all meshes from a scene
Scene scene = Scene.fromFile("input.fbx");
var newNode = new Node();
//add a new node manually
scene.getRootNode().addChildNode(newNode);
public java.lang.Object selectSingleObject(java.lang.String path)
throws ParseException
path - The XPath-like queryParseException - ParseException will be thrown if the path contains malformed query.
Example:
Select a single node using XPath-like expression
//Create a scene for testing
Scene s = new Scene();
var a = s.getRootNode().createChildNode("a");
a.createChildNode("a1");
a.createChildNode("a2");
s.getRootNode().createChildNode("b");
var c = s.getRootNode().createChildNode("c");
c.createChildNode("c1").addEntity(new Camera("cam"));
c.createChildNode("c2").addEntity(new Light("light"));
//Select single camera object under the child nodes of node named 'c' under the root node
var c1 = s.getRootNode().selectSingleObject("/c/*/<Camera>");
// Select node named 'a1' under the root node, even if the 'a1' is not a directly child node of the
var obj = s.getRootNode().selectSingleObject("a1");
//Select the node itself, since the '/' is selected directly on the root node, so the root node is selected.
obj = s.getRootNode().selectSingleObject("/");
public java.util.ArrayList<java.lang.Object> selectObjects(java.lang.String path)
throws ParseException
path - The XPath-like queryParseException - ParseException will be thrown if the path contains malformed query.
Example:
Select a single node using XPath-like expression
//Create a scene for testing
Scene s = new Scene();
var a = s.getRootNode().createChildNode("a");
a.createChildNode("a1");
a.createChildNode("a2");
s.getRootNode().createChildNode("b");
var c = s.getRootNode().createChildNode("c");
c.createChildNode("c1").addEntity(new Camera("cam"));
c.createChildNode("c2").addEntity(new Light("light"));
//select objects that has type Camera or name is 'light' whatever it's located.
var objects = s.getRootNode().selectObjects("//*[(@Type = 'Camera') or (@Name = 'light')]");