Package jme3utilities
Class MySpatial
java.lang.Object
jme3utilities.MySpatial
Utility methods for manipulating scene graphs, nodes, and geometries.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends com.jme3.scene.control.Control>
intcountControls(com.jme3.scene.Spatial subtree, Class<T> controlType) Count all controls of the specified type in the specified subtree of a scene graph.static intcountMeshBones(com.jme3.scene.Spatial subtree) Estimate the number of bones in the specified subtree by reading its mesh index buffers.static <T extends com.jme3.scene.Spatial>
intcountSpatials(com.jme3.scene.Spatial subtree, Class<T> spatialType) Count all spatials of the specified type in the specified subtree of a scene graph.static intcountUserData(com.jme3.scene.Spatial subtree) Count all user data in the specified subtree of a scene graph.static intcountUses(com.jme3.scene.Spatial subtree, com.jme3.material.Material material) Count all uses of the specified Material in the specified subtree of a scene graph.static intcountVertices(com.jme3.scene.Spatial subtree) Count how many mesh vertices are contained in the specified subtree of a scene graph.static chardescribeType(com.jme3.scene.Spatial spatial) Generate a single-character description of a Spatial.static com.jme3.scene.GeometryfindAnimatedGeometry(com.jme3.scene.Spatial subtree) Find an animated geometry in the specified subtree of a scene graph.static <T extends com.jme3.scene.Spatial>
TFind the first child of the specified Node that's assignable from the specified class.static com.jme3.scene.SpatialFind the first child of the specified Node with the specified name.static com.jme3.scene.SpatialfindControlledSpatial(com.jme3.scene.control.Control sgc, com.jme3.scene.Spatial subtree) Find a Spatial controlled by the specified S-G control in the specified subtree of a scene graph.static intfindIndex(com.jme3.scene.Spatial spatial, com.jme3.scene.control.Control sgc) Deprecated.static <T extends com.jme3.light.Light>
TFind the first local light of the specified Spatial that is assignable from the specified class.static com.jme3.light.LightFind the first local light of the specified Spatial with the specified name.static com.jme3.math.Vector3f[]findMinMaxCoords(com.jme3.scene.Geometry geometry, boolean useWorld) Find the minimum and maximum coordinates of a Geometry.static com.jme3.math.Vector3f[]findMinMaxCoords(com.jme3.scene.Spatial subtree) Find the minimum and maximum coordinates in a subtree of a scene graph.static com.jme3.scene.SpatialFind the named Spatial in the specified subtree of a scene graph.static com.jme3.material.MatParamOverridefindOverride(com.jme3.scene.Spatial spatial, String parameterName) Find a named M-P override in the specified Spatial.static booleanhasLight(com.jme3.scene.Spatial spatial, com.jme3.light.Light light) Test whether the specified Spatial has the specified Light in its local list.static com.jme3.math.QuaternioninverseOrientation(com.jme3.scene.Spatial spatial) Construct the inverse of a spatial's world orientation, the Quaternion that undoes all its rotations.static booleanisIgnoringTransforms(com.jme3.scene.Spatial spatial) Test whether a Spatial is a Geometry with ignoreTransform=true.static booleanisOrphan(com.jme3.scene.Spatial spatial) Test whether a Spatial is an orphan or root (has no parent node).static List<com.jme3.scene.Mesh>listAnimatedMeshes(com.jme3.scene.Spatial subtree, List<com.jme3.scene.Mesh> addResults) Enumerate all animated meshes in the specified subtree of a scene graph.static List<com.jme3.scene.Spatial>listAnimationSpatials(com.jme3.scene.Spatial subtree, List<com.jme3.scene.Spatial> addResults) Enumerate all spatials with a SkeletonControl or SkinningControl in the specified subtree.static <T extends com.jme3.scene.control.Control>
List<T>listControls(com.jme3.scene.Spatial subtree, Class<T> controlType, List<T> addResults) Enumerate all controls of the specified type in the specified subtree of a scene graph.static List<com.jme3.scene.Geometry>listGeometries(com.jme3.scene.Spatial subtree) Enumerate all geometries in the specified subtree of a scene graph.static List<com.jme3.material.Material>listMaterials(com.jme3.scene.Spatial subtree, List<com.jme3.material.Material> addResults) Enumerate all materials in the specified subtree of a scene graph.static List<com.jme3.scene.Geometry>listMaterialUsers(com.jme3.scene.Spatial subtree, com.jme3.material.Material material, List<com.jme3.scene.Geometry> addResult) Enumerate all geometries using the specified Material in the specified subtree of a scene graph.static List<com.jme3.scene.Geometry>listMeshUsers(com.jme3.scene.Spatial subtree, com.jme3.scene.Mesh mesh, List<com.jme3.scene.Geometry> addResult) Enumerate all geometries using the specified Mesh in the specified subtree of a scene graph.static List<com.jme3.scene.Spatial>listSpatials(com.jme3.scene.Spatial subtree) Enumerate all spatials in the specified subtree of a scene graph.static <T extends com.jme3.scene.Spatial>
List<T>listSpatials(com.jme3.scene.Spatial subtree, Class<T> spatialType, List<T> addResult) Enumerate all spatials of the specified type in the specified subtree of a scene graph.static List<com.jme3.texture.Texture>listTextures(com.jme3.scene.Spatial subtree, List<com.jme3.texture.Texture> addResult) Enumerate all non-null texture instances in the specified subtree of a scene graph.static voidprepareForCollide(com.jme3.scene.Spatial subtree) Clear all cached collision data from the specified subtree of the scene graph and force a bound refresh.static voidremoveAllControls(com.jme3.scene.Spatial subtree) Remove all controls from the specified subtree of a scene graph.static voidsetWorldLocation(com.jme3.scene.Spatial spatial, com.jme3.math.Vector3f worldLocation) Alter the world location of a spatial's center.static voidsetWorldOrientation(com.jme3.scene.Spatial spatial, com.jme3.math.Quaternion worldOrientation) Alter the world orientation of the specified Spatial.static voidsetWorldScale(com.jme3.scene.Spatial spatial, float worldScale) Alter the (uniform) world scaling of the specified Spatial.static voidsetWorldTransform(com.jme3.scene.Spatial spatial, com.jme3.math.Transform worldTransform) Alter the world transform of the specified Spatial.static booleansubtreeContainsAny(com.jme3.scene.Spatial subtree, Collection<com.jme3.scene.Spatial> collection) Test whether the specified subtree of a scene graph contains any of the collected spatials.static floatuniformScale(com.jme3.scene.Spatial spatial) Determine the world scale factor of a uniformly scaled spatial.static voidvisualizeBoneWeights(com.jme3.scene.Spatial subtree, com.jme3.math.ColorRGBA[] boneIndexToColor, com.jme3.asset.AssetManager assetManager) Apply new materials to all animated meshes in the specified subtree in order to visualize their bone weights.static com.jme3.math.Vector3fworldLocation(com.jme3.scene.Spatial spatial, com.jme3.math.Vector3f storeResult) Determine the world location of a spatial's center.static com.jme3.math.QuaternionworldOrientation(com.jme3.scene.Spatial spatial, com.jme3.math.Quaternion storeResult) Determine the world orientation of the specified Spatial.static com.jme3.math.Vector3fworldScale(com.jme3.scene.Spatial spatial, com.jme3.math.Vector3f storeResult) Determine the world scale of the specified Spatial.static com.jme3.math.TransformworldTransform(com.jme3.scene.Spatial spatial, com.jme3.math.Transform storeResult) Determine the world transform of the specified Spatial.
-
Method Details
-
countControls
public static <T extends com.jme3.scene.control.Control> int countControls(com.jme3.scene.Spatial subtree, Class<T> controlType) Count all controls of the specified type in the specified subtree of a scene graph. Note: recursive!- Type Parameters:
T- subclass of Control- Parameters:
subtree- the subtree to analyze (may be null, unaffected)controlType- the subclass of Control to search for- Returns:
- the count (≥0)
-
countMeshBones
public static int countMeshBones(com.jme3.scene.Spatial subtree) Estimate the number of bones in the specified subtree by reading its mesh index buffers.- Parameters:
subtree- the subtree to analyze (may be null)- Returns:
- the estimated count (≥0)
-
countSpatials
public static <T extends com.jme3.scene.Spatial> int countSpatials(com.jme3.scene.Spatial subtree, Class<T> spatialType) Count all spatials of the specified type in the specified subtree of a scene graph. Note: recursive!- Type Parameters:
T- subclass of Spatial- Parameters:
subtree- the subtree to analyze (may be null, unaffected)spatialType- the subclass of Spatial to search for- Returns:
- the count (≥0)
-
countUserData
public static int countUserData(com.jme3.scene.Spatial subtree) Count all user data in the specified subtree of a scene graph. Note: recursive!- Parameters:
subtree- the subtree to analyze (may be null, unaffected)- Returns:
- the count (≥0)
-
countUses
public static int countUses(com.jme3.scene.Spatial subtree, com.jme3.material.Material material) Count all uses of the specified Material in the specified subtree of a scene graph. Note: recursive!- Parameters:
subtree- the subtree to analyze (may be null, unaffected)material- (unaffected)- Returns:
- the use count (≥0)
-
countVertices
public static int countVertices(com.jme3.scene.Spatial subtree) Count how many mesh vertices are contained in the specified subtree of a scene graph. Note: recursive!- Parameters:
subtree- the subtree to analyze (may be null, unaffected)- Returns:
- the number of vertices (≥0)
-
describeType
public static char describeType(com.jme3.scene.Spatial spatial) Generate a single-character description of a Spatial.- Parameters:
spatial- the Spatial to describe (unaffected, may be null)- Returns:
- a mnemonic character
-
findAnimatedGeometry
public static com.jme3.scene.Geometry findAnimatedGeometry(com.jme3.scene.Spatial subtree) Find an animated geometry in the specified subtree of a scene graph. Note: recursive!- Parameters:
subtree- the subtree to search (not null, unaffected)- Returns:
- a pre-existing Geometry, or null if none
-
findChild
public static <T extends com.jme3.scene.Spatial> T findChild(com.jme3.scene.Node node, Class<T> spatialType) Find the first child of the specified Node that's assignable from the specified class.- Type Parameters:
T- subtype ofSpatial- Parameters:
node- the Node to search (not null)spatialType- type of Spatial to search for (not null)- Returns:
- a pre-existing instance, or null if none found
-
findChild
Find the first child of the specified Node with the specified name. The search is case-sensitive and looks only at the node's immediate children, not all its descendants.- Parameters:
node- the Node to search (not null)childName- the name to search for (not null)- Returns:
- a pre-existing Spatial, or null if none found
- See Also:
-
Node.getChild(java.lang.String)
-
findControlledSpatial
public static com.jme3.scene.Spatial findControlledSpatial(com.jme3.scene.control.Control sgc, com.jme3.scene.Spatial subtree) Find a Spatial controlled by the specified S-G control in the specified subtree of a scene graph. Note: recursive!- Parameters:
sgc- which scene-graph control (not null, unaffected)subtree- the subtree to search (not null, unaffected)- Returns:
- a pre-existing Spatial, or null if none found
-
findIndex
@Deprecated public static int findIndex(com.jme3.scene.Spatial spatial, com.jme3.scene.control.Control sgc) Find the index of the specified scene-graph control in the specified Spatial.- Parameters:
spatial- the Spatial to search (not null, unaffected)sgc- the Control to search for (not null, unaffected)- Returns:
- the index (≥0) or -1 if not found
-
findLight
public static <T extends com.jme3.light.Light> T findLight(com.jme3.scene.Spatial spatial, Class<T> lightClass) Find the first local light of the specified Spatial that is assignable from the specified class.- Type Parameters:
T- subtype ofLight- Parameters:
spatial- the Spatial to search (not null)lightClass- type of Light to search for (not null)- Returns:
- a pre-existing instance, or null if none found
-
findLight
Find the first local light of the specified Spatial with the specified name.- Parameters:
spatial- the Spatial to search (not null, unaffected)lightName- the name to search for (not null)- Returns:
- a pre-existing Light, or null if none found
-
findMinMaxCoords
public static com.jme3.math.Vector3f[] findMinMaxCoords(com.jme3.scene.Geometry geometry, boolean useWorld) Find the minimum and maximum coordinates of a Geometry.- Parameters:
geometry- the Geometry to measure (not null)useWorld- true → use world coordinates, false → use mesh coordinates- Returns:
- a new array consisting of array[0]: the lowest coordinate for each axis and array[1]: the highest coordinate for each axis
-
findMinMaxCoords
public static com.jme3.math.Vector3f[] findMinMaxCoords(com.jme3.scene.Spatial subtree) Find the minimum and maximum coordinates in a subtree of a scene graph. Note: recursive!- Parameters:
subtree- subtree to measure (not null)- Returns:
- a new array consisting of array[0]: the lowest coordinate for each world axis and array[1]: the highest coordinate for each world axis (not null)
-
findNamed
Find the named Spatial in the specified subtree of a scene graph. Note: recursive!- Parameters:
subtree- the subtree to search in (not null, unaffected)name- the name to search for (not null)- Returns:
- a pre-existing Spatial, or null if none
-
findOverride
public static com.jme3.material.MatParamOverride findOverride(com.jme3.scene.Spatial spatial, String parameterName) Find a named M-P override in the specified Spatial.- Parameters:
spatial- the Spatial to search in (not null)parameterName- the name of the M-P override (not null, not empty)- Returns:
- a pre-existing instance, or null if not found
-
hasLight
public static boolean hasLight(com.jme3.scene.Spatial spatial, com.jme3.light.Light light) Test whether the specified Spatial has the specified Light in its local list.- Parameters:
spatial- the Spatial to analyze (not null, unaffected)light- the Light to search for (not null, unaffected)- Returns:
- true if found, false if not found
-
inverseOrientation
public static com.jme3.math.Quaternion inverseOrientation(com.jme3.scene.Spatial spatial) Construct the inverse of a spatial's world orientation, the Quaternion that undoes all its rotations.- Parameters:
spatial- the Spatial to analyze (not null, unaffected)- Returns:
- new instance
- Throws:
IllegalArgumentException- if the spatial's world orientation is not invertible
-
isIgnoringTransforms
public static boolean isIgnoringTransforms(com.jme3.scene.Spatial spatial) Test whether a Spatial is a Geometry with ignoreTransform=true.- Parameters:
spatial- the Spatial to test (may be null, unaffected)- Returns:
- true if the Spatial ignores transforms, otherwise false
-
isOrphan
public static boolean isOrphan(com.jme3.scene.Spatial spatial) Test whether a Spatial is an orphan or root (has no parent node).- Parameters:
spatial- the Spatial to test (not null, unaffected)- Returns:
- true if the Spatial is an orphan, otherwise false
-
listAnimatedMeshes
public static List<com.jme3.scene.Mesh> listAnimatedMeshes(com.jme3.scene.Spatial subtree, List<com.jme3.scene.Mesh> addResults) Enumerate all animated meshes in the specified subtree of a scene graph. Note: recursive!- Parameters:
subtree- the subtree to analyze (may be null, aliases created)addResults- storage for results (added to if not null)- Returns:
- an expanded List (either
addResultsor a new List)
-
listAnimationSpatials
public static List<com.jme3.scene.Spatial> listAnimationSpatials(com.jme3.scene.Spatial subtree, List<com.jme3.scene.Spatial> addResults) Enumerate all spatials with a SkeletonControl or SkinningControl in the specified subtree. Useful when adding a DynamicAnimControl to a model whose structure is complex or unknown. Note: recursive!- Parameters:
subtree- the subtree to analyze (may be null, aliases created)addResults- storage for results (added to if not null)- Returns:
- an expanded List (either addResults or a new List)
-
listControls
public static <T extends com.jme3.scene.control.Control> List<T> listControls(com.jme3.scene.Spatial subtree, Class<T> controlType, List<T> addResults) Enumerate all controls of the specified type in the specified subtree of a scene graph. Note: recursive!- Type Parameters:
T- subclass of Control- Parameters:
subtree- the subtree to analyze (not null, aliases created)controlType- the subclass of Control to search foraddResults- storage for results (added to if not null)- Returns:
- an expanded List (either
addResultsor a new List)
-
listGeometries
Enumerate all geometries in the specified subtree of a scene graph.- Parameters:
subtree- (not null, aliases created)- Returns:
- a new List of pre-existing instances (not null, not empty)
- See Also:
-
Node.descendantMatches(java.lang.Class)
-
listMaterials
public static List<com.jme3.material.Material> listMaterials(com.jme3.scene.Spatial subtree, List<com.jme3.material.Material> addResults) Enumerate all materials in the specified subtree of a scene graph. Note: recursive!- Parameters:
subtree- the subtree to analyze (may be null, aliases created)addResults- storage for results (added to if not null)- Returns:
- an expanded List (either
addResultsor a new List) - See Also:
-
listMaterialUsers
public static List<com.jme3.scene.Geometry> listMaterialUsers(com.jme3.scene.Spatial subtree, com.jme3.material.Material material, List<com.jme3.scene.Geometry> addResult) Enumerate all geometries using the specified Material in the specified subtree of a scene graph. Note: recursive!- Parameters:
subtree- the subtree to analyze (may be null, aliases created)material- the Material to search for (may be null, unaffected)addResult- storage for results (added to if not null)- Returns:
- an expanded List (either
addResultor a new List)
-
listMeshUsers
public static List<com.jme3.scene.Geometry> listMeshUsers(com.jme3.scene.Spatial subtree, com.jme3.scene.Mesh mesh, List<com.jme3.scene.Geometry> addResult) Enumerate all geometries using the specified Mesh in the specified subtree of a scene graph. Note: recursive!- Parameters:
subtree- (may be null, aliases created)mesh- the Mesh to search for (may be null, unaffected)addResult- storage for results (added to if not null)- Returns:
- an expanded List (either
addResultor a new List)
-
listSpatials
Enumerate all spatials in the specified subtree of a scene graph.- Parameters:
subtree- (not null, aliases created)- Returns:
- a new List of pre-existing instances (not null, not empty)
- See Also:
-
Node.descendantMatches(java.lang.Class)
-
listSpatials
public static <T extends com.jme3.scene.Spatial> List<T> listSpatials(com.jme3.scene.Spatial subtree, Class<T> spatialType, List<T> addResult) Enumerate all spatials of the specified type in the specified subtree of a scene graph. Note: recursive!- Type Parameters:
T- subclass of Spatial- Parameters:
subtree- (not null, aliases created)spatialType- the subclass of Spatial to search foraddResult- storage for results (added to if not null)- Returns:
- an expanded List (either
addResultor a new List) - See Also:
-
Node.descendantMatches(java.lang.Class)
-
listTextures
public static List<com.jme3.texture.Texture> listTextures(com.jme3.scene.Spatial subtree, List<com.jme3.texture.Texture> addResult) Enumerate all non-null texture instances in the specified subtree of a scene graph. Note that JME may consider 2 textures to be "equal" even when their asset keys differ.- Parameters:
subtree- the subtree to analyze (may be null)addResult- storage for results (added to if not null)- Returns:
- an expanded List (either
addResultor a new List)
-
prepareForCollide
public static void prepareForCollide(com.jme3.scene.Spatial subtree) Clear all cached collision data from the specified subtree of the scene graph and force a bound refresh. Note: recursive!- Parameters:
subtree- where to search (may be null)
-
removeAllControls
public static void removeAllControls(com.jme3.scene.Spatial subtree) Remove all controls from the specified subtree of a scene graph. Note: recursive!- Parameters:
subtree- (not null)
-
setWorldLocation
public static void setWorldLocation(com.jme3.scene.Spatial spatial, com.jme3.math.Vector3f worldLocation) Alter the world location of a spatial's center.- Parameters:
spatial- spatial to relocate (not null)worldLocation- desired world location (not null, unaffected)- Throws:
IllegalArgumentException- if the Spatial is a Geometry with ignoreTransform=true
-
setWorldOrientation
public static void setWorldOrientation(com.jme3.scene.Spatial spatial, com.jme3.math.Quaternion worldOrientation) Alter the world orientation of the specified Spatial.- Parameters:
spatial- spatial to reorient (not null)worldOrientation- desired world orientation (not null, unaffected)- Throws:
IllegalArgumentException- if the Spatial is a Geometry with ignoreTransform=true OR the parent's world orientation is not invertible
-
setWorldScale
public static void setWorldScale(com.jme3.scene.Spatial spatial, float worldScale) Alter the (uniform) world scaling of the specified Spatial.- Parameters:
spatial- spatial to rescale (not null)worldScale- desired world scale (>0)- Throws:
IllegalArgumentException- if the Spatial is a Geometry with ignoreTransform=true OR the spatial's parent has a zero in its world scale
-
setWorldTransform
public static void setWorldTransform(com.jme3.scene.Spatial spatial, com.jme3.math.Transform worldTransform) Alter the world transform of the specified Spatial.- Parameters:
spatial- spatial to alter (not null)worldTransform- desired world transform (not null, unaffected)- Throws:
IllegalArgumentException- if the Spatial is a Geometry with ignoreTransform=true OR the spatial's parent has a zero in its world scale OR the parent's world orientation is not invertible
-
subtreeContainsAny
public static boolean subtreeContainsAny(com.jme3.scene.Spatial subtree, Collection<com.jme3.scene.Spatial> collection) Test whether the specified subtree of a scene graph contains any of the collected spatials.- Parameters:
subtree- subtree to traverse (may be null, unaffected)collection- spatials to find (not null, unaffected)- Returns:
- true if one of the collected spatials was found, otherwise false
-
uniformScale
public static float uniformScale(com.jme3.scene.Spatial spatial) Determine the world scale factor of a uniformly scaled spatial.- Parameters:
spatial- the Spatial to analyze (not null, unaffected)- Returns:
- the scale factor
- Throws:
IllegalArgumentException- if the Spatial is scaled non-uniformly
-
visualizeBoneWeights
public static void visualizeBoneWeights(com.jme3.scene.Spatial subtree, com.jme3.math.ColorRGBA[] boneIndexToColor, com.jme3.asset.AssetManager assetManager) Apply new materials to all animated meshes in the specified subtree in order to visualize their bone weights.- Parameters:
subtree- the subtree to modify (may be null)boneIndexToColor- map bone indices to colors (not null, unaffected)assetManager- (not null)
-
worldLocation
public static com.jme3.math.Vector3f worldLocation(com.jme3.scene.Spatial spatial, com.jme3.math.Vector3f storeResult) Determine the world location of a spatial's center.- Parameters:
spatial- spatial to locate (not null)storeResult- storage for the result (modified if not null)- Returns:
- the location vector (in world coordinates, either storeResult or a new instance)
-
worldOrientation
public static com.jme3.math.Quaternion worldOrientation(com.jme3.scene.Spatial spatial, com.jme3.math.Quaternion storeResult) Determine the world orientation of the specified Spatial.- Parameters:
spatial- the Spatial to analyze (not null)storeResult- storage for the result (modified if not null)- Returns:
- the orientation (in world coordinates, either storeResult or a new instance)
-
worldScale
public static com.jme3.math.Vector3f worldScale(com.jme3.scene.Spatial spatial, com.jme3.math.Vector3f storeResult) Determine the world scale of the specified Spatial.- Parameters:
spatial- the Spatial to analyze (not null)storeResult- storage for the result (modified if not null)- Returns:
- the scale vector (in world coordinates, either storeResult or a new instance)
-
worldTransform
public static com.jme3.math.Transform worldTransform(com.jme3.scene.Spatial spatial, com.jme3.math.Transform storeResult) Determine the world transform of the specified Spatial.- Parameters:
spatial- the Spatial to analyze (not null)storeResult- storage for the result (modified if not null)- Returns:
- the Transform (in world coordinates, either storeResult or a new instance)
-
MyControl.findIndex(com.jme3.scene.control.Control, com.jme3.scene.Spatial)