APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.graphics.g3d.model

public Class Node

extends Object
Class Inheritance
Imports
com.badlogic.gdx.graphics.g3d.Material, .Model, com.badlogic.gdx.math.Matrix4, .Quaternion, .Vector3, com.badlogic.gdx.math.collision.BoundingBox, com.badlogic.gdx.utils.Array, .GdxRuntimeException

A node is part of a hierarchy of Nodes in a Model. A Node encodes a transform relative to its parents. A Node can have child nodes. Optionally a node can specify a MeshPart and a Material to be applied to the mesh part.
Author
badlogic

Field Summary

Modifier and TypeField and Description
private final Array<Node>
public final Matrix4
globalTransform

the global transform, product of local transform and transform of the parent node, calculated via calculateWorldTransform()

public String
id

the id, may be null, FIXME is this unique?

public boolean
inheritTransform

Whether this node should inherit the transformation of its parent node, defaults to true.

public boolean
isAnimated

Whether this node is currently being animated, if so the translation, rotation and scale values are not used.

public final Matrix4
localTransform

the local transform, based on translation/rotation/scale (calculateLocalTransform()) or any applied animation

protected Node
public Array<NodePart>
public final Quaternion
rotation

the rotation, relative to the parent, not modified by animations

public final Vector3
scale

the scale, relative to the parent, not modified by animations

public final Vector3
translation

the translation, relative to the parent, not modified by animations

Constructor Summary

AccessConstructor and Description
public
Node()

Method Summary

Modifier and TypeMethod and Description
public <T extends Node> int

Returns:

the zero-based index of the child
addChild
(final T
The Node to add as child of this Node
child
)

Adds the specified node as the currently last child of this node.

public <T extends Node> int

Returns:

the zero-based index of the first added child
addChildren
(final Iterable<T>
The Node to add as child of this Node
nodes
)

Adds the specified nodes as the currently last child of this node.

public <T extends Node> void
attachTo(T
The Node to attach this Node to.
parent
)

Adds this node as child to specified parent Node, synonym for: parent.addChild(this)

public void
calculateBoneTransforms(boolean recursive)

public BoundingBox
calculateBoundingBox(final BoundingBox out)

Calculate the bounding box of this Node.

public BoundingBox
calculateBoundingBox(final BoundingBox out, boolean transform)

Calculate the bounding box of this Node.

public Matrix4

Returns:

the local transform
calculateLocalTransform
()

Calculates the local transform based on the translation, scale and rotation

public void
calculateTransforms(boolean
whether to calculate the local/world transforms for children.
recursive
)

Calculates the local and world transform of this node and optionally all its children.

public Matrix4

Returns:

the world transform
calculateWorldTransform
()

Calculates the world transform; the product of local transform and the parent's world transform.

public Node
copy()

Creates a nested copy of this Node, any child nodes are copied using this method as well.

public void
detach()

Removes this node from its current parent, if any.

public BoundingBox
extendBoundingBox(final BoundingBox out)

Extends the bounding box with the bounds of this Node.

public BoundingBox
extendBoundingBox(final BoundingBox out, boolean transform)

Extends the bounding box with the bounds of this Node.

public Node
getChild(final int
The zero-based index of the child node to get, must be: 0 <= index < getChildCount().
index
)

Returns: The child node at the specified index

public Node
getChild(final String id, boolean
false to fetch a root child only, true to search the entire node tree for the specified node.
recursive
,
boolean ignoreCase)

Returns: The node with the specified id, or null if not found.

public int
getChildCount()

Returns: The number of child nodes that this Node current contains.

public Iterable<Node>
getChildren()

Returns: An Iterable to all child nodes that this node contains.

public static Node

Returns:

The node with the specified id, or null if not found.
getNode
(final Array<Node> nodes, final String id, boolean
false to fetch a root node only, true to search the entire node tree for the specified node.
recursive
,
boolean ignoreCase)

Helper method to recursive fetch a node from an array

public Node
getParent()

Returns: The parent node that holds this node as child node, may be null.

public boolean
hasChildren()

Returns: whether this Node has one or more children (true) or not (false)

public boolean
hasParent()

Returns: Whether (true) is this Node is a child node of another node or not (false).

public <T extends Node> int

Returns:

the zero-based index of the child
insertChild
(int
The zero-based index at which to add the child
index
,
final T
The Node to add as child of this Node
child
)

Insert the specified node as child of this node at the specified index.

public <T extends Node> int

Returns:

the zero-based index of the first inserted child
insertChildren
(int
The zero-based index at which to add the child
index
,
final Iterable<T>
The nodes to add as child of this Node
nodes
)

Insert the specified nodes as children of this node at the specified index.

public <T extends Node> boolean

Returns:

Whether the removal was successful.
removeChild
(final T
The child node to remove.
child
)

Removes the specified node as child of this node.

protected Node

Returns:

This Node for chaining
set
(Node other)

Creates a nested copy of this Node, any child nodes are copied using the copy() method.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

childrenback to summary
private final Array<Node> children
globalTransformback to summary
public final Matrix4 globalTransform

the global transform, product of local transform and transform of the parent node, calculated via calculateWorldTransform()

idback to summary
public String id

the id, may be null, FIXME is this unique?

inheritTransformback to summary
public boolean inheritTransform

Whether this node should inherit the transformation of its parent node, defaults to true. When this flag is false the value of globalTransform will be the same as the value of localTransform causing the transform to be independent of its parent transform.

isAnimatedback to summary
public boolean isAnimated

Whether this node is currently being animated, if so the translation, rotation and scale values are not used.

localTransformback to summary
public final Matrix4 localTransform

the local transform, based on translation/rotation/scale (calculateLocalTransform()) or any applied animation

parentback to summary
protected Node parent
partsback to summary
public Array<NodePart> parts
rotationback to summary
public final Quaternion rotation

the rotation, relative to the parent, not modified by animations

scaleback to summary
public final Vector3 scale

the scale, relative to the parent, not modified by animations

translationback to summary
public final Vector3 translation

the translation, relative to the parent, not modified by animations

Constructor Detail

Nodeback to summary
public Node()

Method Detail

addChildback to summary
public <T extends Node> int addChild(final T child)

Adds the specified node as the currently last child of this node. If the node is already a child of another node, then it is removed from its current parent.

Parameters
child:T

The Node to add as child of this Node

Returns:int

the zero-based index of the child

addChildrenback to summary
public <T extends Node> int addChildren(final Iterable<T> nodes)

Adds the specified nodes as the currently last child of this node. If the node is already a child of another node, then it is removed from its current parent.

Parameters
nodes:Iterable<T>

The Node to add as child of this Node

Returns:int

the zero-based index of the first added child

attachToback to summary
public <T extends Node> void attachTo(T parent)

Adds this node as child to specified parent Node, synonym for: parent.addChild(this)

Parameters
parent:T

The Node to attach this Node to.

calculateBoneTransformsback to summary
public void calculateBoneTransforms(boolean recursive)
calculateBoundingBoxback to summary
public BoundingBox calculateBoundingBox(final BoundingBox out)

Calculate the bounding box of this Node. This is a potential slow operation, it is advised to cache the result.

calculateBoundingBoxback to summary
public BoundingBox calculateBoundingBox(final BoundingBox out, boolean transform)

Calculate the bounding box of this Node. This is a potential slow operation, it is advised to cache the result.

calculateLocalTransformback to summary
public Matrix4 calculateLocalTransform()

Calculates the local transform based on the translation, scale and rotation

Returns:Matrix4

the local transform

calculateTransformsback to summary
public void calculateTransforms(boolean recursive)

Calculates the local and world transform of this node and optionally all its children.

Parameters
recursive:boolean

whether to calculate the local/world transforms for children.

calculateWorldTransformback to summary
public Matrix4 calculateWorldTransform()

Calculates the world transform; the product of local transform and the parent's world transform.

Returns:Matrix4

the world transform

copyback to summary
public Node copy()

Creates a nested copy of this Node, any child nodes are copied using this method as well. The parts are copied using the NodePart#copy() method. Note that that method copies the material and nodes (bones) by reference. If you intend to use the copy in a different node tree (e.g. a different Model or ModelInstance) then you will need to update these references afterwards. Override this method in your custom Node class to instantiate that class, in that case you should override the set(Node) method as well.

detachback to summary
public void detach()

Removes this node from its current parent, if any. Short for: this.getParent().removeChild(this)

extendBoundingBoxback to summary
public BoundingBox extendBoundingBox(final BoundingBox out)

Extends the bounding box with the bounds of this Node. This is a potential slow operation, it is advised to cache the result.

extendBoundingBoxback to summary
public BoundingBox extendBoundingBox(final BoundingBox out, boolean transform)

Extends the bounding box with the bounds of this Node. This is a potential slow operation, it is advised to cache the result.

getChildback to summary
public Node getChild(final int index)
Parameters
index:int

The zero-based index of the child node to get, must be: 0 <= index < getChildCount().

Returns:Node

The child node at the specified index

getChildback to summary
public Node getChild(final String id, boolean recursive, boolean ignoreCase)
Parameters
recursive:boolean

false to fetch a root child only, true to search the entire node tree for the specified node.

Returns:Node

The node with the specified id, or null if not found.

getChildCountback to summary
public int getChildCount()
Returns:int

The number of child nodes that this Node current contains.

See Also
getChild(int)
getChildrenback to summary
public Iterable<Node> getChildren()
Returns:Iterable<Node>

An Iterable to all child nodes that this node contains.

getNodeback to summary
public static Node getNode(final Array<Node> nodes, final String id, boolean recursive, boolean ignoreCase)

Helper method to recursive fetch a node from an array

Parameters
recursive:boolean

false to fetch a root node only, true to search the entire node tree for the specified node.

Returns:Node

The node with the specified id, or null if not found.

getParentback to summary
public Node getParent()
Returns:Node

The parent node that holds this node as child node, may be null.

hasChildrenback to summary
public boolean hasChildren()
Returns:boolean

whether this Node has one or more children (true) or not (false)

hasParentback to summary
public boolean hasParent()
Returns:boolean

Whether (true) is this Node is a child node of another node or not (false).

insertChildback to summary
public <T extends Node> int insertChild(int index, final T child)

Insert the specified node as child of this node at the specified index. If the node is already a child of another node, then it is removed from its current parent. If the specified index is less than zero or equal or greater than getChildCount() then the Node is added as the currently last child.

Parameters
index:int

The zero-based index at which to add the child

child:T

The Node to add as child of this Node

Returns:int

the zero-based index of the child

insertChildrenback to summary
public <T extends Node> int insertChildren(int index, final Iterable<T> nodes)

Insert the specified nodes as children of this node at the specified index. If the node is already a child of another node, then it is removed from its current parent. If the specified index is less than zero or equal or greater than getChildCount() then the Node is added as the currently last child.

Parameters
index:int

The zero-based index at which to add the child

nodes:Iterable<T>

The nodes to add as child of this Node

Returns:int

the zero-based index of the first inserted child

removeChildback to summary
public <T extends Node> boolean removeChild(final T child)

Removes the specified node as child of this node. On success, the child node will be not attached to any parent node (its getParent() method will return null). If the specified node currently isn't a child of this node then the removal is considered to be unsuccessful and the method will return false.

Parameters
child:T

The child node to remove.

Returns:boolean

Whether the removal was successful.

setback to summary
protected Node set(Node other)

Creates a nested copy of this Node, any child nodes are copied using the copy() method. This will detach this node from its parent, but does not attach it to the parent of node being copied. The parts are copied using the NodePart#copy() method. Note that that method copies the material and nodes (bones) by reference. If you intend to use this node in a different node tree (e.g. a different Model or ModelInstance) then you will need to update these references afterwards. Override this method in your custom Node class to copy any additional fields you've added.

Returns:Node

This Node for chaining