public class Node extends Spatial
Node
defines an internal node of a scene graph. The internal
node maintains a collection of children and handles merging said children
into a single bound to allow for very fast culling of multiple nodes. Node
allows for any number of children to be attached.Spatial.BatchHint, Spatial.CullHint, Spatial.DFSMode
Modifier and Type | Field and Description |
---|---|
protected SafeArrayList<Spatial> |
children
This node's children.
|
batchHint, controls, cullHint, frustrumIntersects, key, localLights, localOverrides, localTransform, name, parent, queueBucket, queueDistance, refreshFlags, RF_BOUND, RF_CHILD_LIGHTLIST, RF_LIGHTLIST, RF_MATPARAM_OVERRIDE, RF_TRANSFORM, shadowMode, userData, worldBound, worldLights, worldOverrides, worldTransform
Constructor and Description |
---|
Node()
Instantiate a
Node with no name, no parent, and no children. |
Node(java.lang.String name)
Constructor instantiates a new
Node with a default empty
list for containing children. |
Modifier and Type | Method and Description |
---|---|
int |
attachChild(Spatial child)
attachChild attaches a child to this node. |
int |
attachChildAt(Spatial child,
int index)
attachChildAt attaches a child to this node at an index. |
protected void |
breadthFirstTraversal(SceneGraphVisitor visitor,
java.util.Queue<Spatial> queue) |
Node |
clone(boolean cloneMaterials) |
void |
cloneFields(Cloner cloner,
java.lang.Object original)
Called internally by com.jme3.util.clone.Cloner.
|
int |
collideWith(Collidable other,
CollisionResults results)
Check collision with another Collidable.
|
Spatial |
deepClone() |
void |
depthFirstTraversal(SceneGraphVisitor visitor,
Spatial.DFSMode mode)
Visit each scene graph element ordered by DFS.
|
<T extends Spatial> |
descendantMatches(java.lang.Class<T> spatialSubclass)
Convenience wrapper.
|
<T extends Spatial> |
descendantMatches(java.lang.Class<T> spatialSubclass,
java.lang.String nameRegex)
Returns flat list of Spatials implementing the specified class AND
with name matching the specified pattern.
|
<T extends Spatial> |
descendantMatches(java.lang.String nameRegex)
Convenience wrapper.
|
void |
detachAllChildren()
detachAllChildren removes all children attached to this
node. |
int |
detachChild(Spatial child)
detachChild removes a given child from the node's list. |
Spatial |
detachChildAt(int index)
detachChildAt removes a child at a given index. |
int |
detachChildNamed(java.lang.String childName)
detachChild removes a given child from the node's list. |
Spatial |
getChild(int i)
getChild returns a child at a given index. |
Spatial |
getChild(java.lang.String name)
getChild returns the first child found with exactly the
given name (case sensitive.) This method does a depth first recursive
search of all descendants of this node, it will return the first spatial
found with a matching name. |
int |
getChildIndex(Spatial sp)
getChildIndex returns the index of the given spatial
in this node's list of children. |
java.util.List<Spatial> |
getChildren()
Returns all children to this node.
|
int |
getQuantity()
getQuantity returns the number of children this node
maintains. |
int |
getTriangleCount()
getTriangleCount returns the number of triangles contained
in all sub-branches of this node that contain geometry. |
int |
getVertexCount()
getVertexCount returns the number of vertices contained
in all sub-branches of this node that contain geometry. |
boolean |
hasChild(Spatial spat)
determines if the provided Spatial is contained in the children list of
this node.
|
Spatial |
oldDeepClone() |
void |
read(JmeImporter e) |
protected void |
setLightListRefresh() |
void |
setLodLevel(int lod)
Sets the level of detail to use when rendering this Spatial,
this call propagates to all geometries under this Spatial.
|
void |
setMaterial(Material mat)
Applies the given material to the Spatial, this will propagate the
material down to the geometries in the scene graph.
|
protected void |
setMatParamOverrideRefresh() |
void |
setModelBound(BoundingVolume modelBound)
setModelBound sets the bounding object for this Spatial. |
protected void |
setParent(Node parent)
Called by
attachChild(Spatial) and
detachChild(Spatial) - don't call directly. |
protected void |
setTransformRefresh()
Indicate that the transform of this spatial has changed and that
a refresh is required.
|
void |
swapChildren(int index1,
int index2)
More efficient than e.g detaching and attaching as no updates are needed.
|
void |
updateGeometricState()
updateGeometricState updates the lightlist,
computes the world transforms, and computes the world bounds
for this Spatial. |
void |
updateLogicalState(float tpf)
updateLogicalState calls the update() method
for all controls attached to this Spatial. |
void |
updateModelBound()
updateModelBound recalculates the bounding object for this
Spatial. |
protected void |
updateWorldBound()
Should be overridden by Node and Geometry.
|
void |
write(JmeExporter e) |
addControl, addLight, addMatParamOverride, breadthFirstTraversal, center, checkCulling, clearMatParamOverrides, clone, depthFirstTraversal, forceRefresh, getBatchHint, getControl, getControl, getCullHint, getKey, getLastFrustumIntersection, getLocalBatchHint, getLocalCullHint, getLocalLightList, getLocalMatParamOverrides, getLocalQueueBucket, getLocalRotation, getLocalScale, getLocalShadowMode, getLocalToWorldMatrix, getLocalTransform, getLocalTranslation, getName, getNumControls, getParent, getQueueBucket, getShadowMode, getUserData, getUserDataKeys, getWorldBound, getWorldLightList, getWorldMatParamOverrides, getWorldRotation, getWorldScale, getWorldTransform, getWorldTranslation, hasAncestor, jmeClone, localToWorld, lookAt, matches, move, move, oldClone, removeControl, removeControl, removeFromParent, removeLight, removeMatParamOverride, rotate, rotate, rotateUpTo, runControlRender, scale, scale, setBatchHint, setBoundRefresh, setCullHint, setKey, setLastFrustumIntersection, setLocalRotation, setLocalRotation, setLocalScale, setLocalScale, setLocalScale, setLocalTransform, setLocalTranslation, setLocalTranslation, setName, setQueueBucket, setRequiresUpdates, setShadowMode, setUserData, toString, updateMatParamOverrides, updateWorldLightList, updateWorldTransforms, worldToLocal
protected SafeArrayList<Spatial> children
public Node()
Node
with no name, no parent, and no children.public Node(java.lang.String name)
Node
with a default empty
list for containing children.name
- the name of the scene elementpublic int getQuantity()
getQuantity
returns the number of children this node
maintains.protected void setTransformRefresh()
Spatial
setTransformRefresh
in class Spatial
protected void setLightListRefresh()
setLightListRefresh
in class Spatial
protected void setMatParamOverrideRefresh()
setMatParamOverrideRefresh
in class Spatial
protected void updateWorldBound()
Spatial
updateWorldBound
in class Spatial
protected void setParent(Node parent)
Spatial
attachChild(Spatial)
and
detachChild(Spatial)
- don't call directly.
setParent
sets the parent of this node.public void updateLogicalState(float tpf)
Spatial
updateLogicalState
calls the update()
method
for all controls attached to this Spatial.updateLogicalState
in class Spatial
tpf
- Time per frame.Spatial.addControl(com.jme3.scene.control.Control)
public void updateGeometricState()
Spatial
updateGeometricState
updates the lightlist,
computes the world transforms, and computes the world bounds
for this Spatial.
Calling this when the Spatial is attached to a node
will cause undefined results. User code should only call this
method on Spatials having no parent.updateGeometricState
in class Spatial
Spatial.getWorldLightList()
,
Spatial.getWorldTransform()
,
Spatial.getWorldBound()
public int getTriangleCount()
getTriangleCount
returns the number of triangles contained
in all sub-branches of this node that contain geometry.getTriangleCount
in class Spatial
public int getVertexCount()
getVertexCount
returns the number of vertices contained
in all sub-branches of this node that contain geometry.getVertexCount
in class Spatial
public int attachChild(Spatial child)
attachChild
attaches a child to this node. This node
becomes the child's parent. The current number of children maintained is
returned.
child
- the child to attach to this node.java.lang.IllegalArgumentException
- if child is null.public int attachChildAt(Spatial child, int index)
attachChildAt
attaches a child to this node at an index. This node
becomes the child's parent. The current number of children maintained is
returned.
child
- the child to attach to this node.java.lang.IllegalArgumentException
- if child is null or thispublic int detachChild(Spatial child)
detachChild
removes a given child from the node's list.
This child will no longer be maintained.child
- the child to remove (not null)public int detachChildNamed(java.lang.String childName)
detachChild
removes a given child from the node's list.
This child will no longer be maintained. Only the first child with a
matching name is removed.childName
- the child to remove (not null)public Spatial detachChildAt(int index)
detachChildAt
removes a child at a given index. That child
is returned for saving purposes.index
- the index of the child to be removed.public void detachAllChildren()
detachAllChildren
removes all children attached to this
node.public int getChildIndex(Spatial sp)
getChildIndex
returns the index of the given spatial
in this node's list of children.sp
- The spatial to look uppublic void swapChildren(int index1, int index2)
index1
- The index of the first child to swapindex2
- The index of the second child to swappublic Spatial getChild(int i)
getChild
returns a child at a given index.i
- the index to retrieve the child from.public Spatial getChild(java.lang.String name)
getChild
returns the first child found with exactly the
given name (case sensitive.) This method does a depth first recursive
search of all descendants of this node, it will return the first spatial
found with a matching name.name
- the name of the child to retrieve. If null, we'll return null.public boolean hasChild(Spatial spat)
spat
- the child object to look for.public java.util.List<Spatial> getChildren()
public void setMaterial(Material mat)
Spatial
setMaterial
in class Spatial
mat
- The material to set.public void setLodLevel(int lod)
Spatial
setLodLevel
in class Spatial
lod
- The lod level to set.public int collideWith(Collidable other, CollisionResults results)
Collidable
other
- The object to check collision againstresults
- Will contain the list of CollisionResult
s.public <T extends Spatial> java.util.List<T> descendantMatches(java.lang.Class<T> spatialSubclass, java.lang.String nameRegex)
Note that we are matching the pattern, therefore the pattern must match the entire pattern (i.e. it behaves as if it is sandwiched between "^" and "$"). You can set regex modes, like case insensitivity, by using the (?X) or (?X:Y) constructs.
By design, it is always safe to code loops like:
for (Spatial spatial : node.descendantMatches(AClass.class, "regex"))
"Descendants" does not include self, per the definition of the word.
To test for descendants AND self, you must do a
node.matches(aClass, aRegex)
+
node.descendantMatches(aClass, aRegex)
.
spatialSubclass
- Subclass which matching Spatials must implement.
Null causes all Spatials to qualify.nameRegex
- Regular expression to match Spatial name against.
Null causes all Names to qualify.Pattern
,
Spatial.matches(java.lang.Class, java.lang.String)
public <T extends Spatial> java.util.List<T> descendantMatches(java.lang.Class<T> spatialSubclass)
public <T extends Spatial> java.util.List<T> descendantMatches(java.lang.String nameRegex)
public Node clone(boolean cloneMaterials)
clone
in class Spatial
Mesh.cloneForAnim()
public Spatial deepClone()
deepClone
in class Spatial
Spatial.clone()
public Spatial oldDeepClone()
public void cloneFields(Cloner cloner, java.lang.Object original)
cloneFields
in interface JmeCloneable
cloneFields
in class Spatial
cloner
- The cloner that is performing the cloning operation. The
cloneFields method can call back into the cloner to make
clones of its subordinate fields.original
- The original object from which this object was cloned.
This is provided for the very rare case that this object needs
to refer to its original for some reason. In general, all of
the relevant values should have been transferred during the
shallow clone and this object need merely clone what it wants.public void write(JmeExporter e) throws java.io.IOException
public void read(JmeImporter e) throws java.io.IOException
public void setModelBound(BoundingVolume modelBound)
Spatial
setModelBound
sets the bounding object for this Spatial.setModelBound
in class Spatial
modelBound
- the bounding object for this spatial.public void updateModelBound()
Spatial
updateModelBound
recalculates the bounding object for this
Spatial.updateModelBound
in class Spatial
public void depthFirstTraversal(SceneGraphVisitor visitor, Spatial.DFSMode mode)
Spatial
depthFirstTraversal
in class Spatial
mode
- the traversal mode: pre order or post orderprotected void breadthFirstTraversal(SceneGraphVisitor visitor, java.util.Queue<Spatial> queue)
breadthFirstTraversal
in class Spatial