Enum Class CollisionTreeManager
- All Implemented Interfaces:
Serializable
,Comparable<CollisionTreeManager>
,Constable
getCollisionTree
method. The cache is checked for the tree, and if it is
available, sent to the caller. If the tree is not in the cache, and generateTrees is true, a new CollisionTree is
generated on the fly and sent to the caller. When a new tree is created, the cache size is compared to the
maxElements value. If the cache is larger than maxElements, the cache is sent to the CollisionTreeController for
cleaning.
There are a number of settings that can be used to control how trees are generated. First, generateTrees denotes whether the manager should be creating trees at all. This is set to true by default. doSort defines if the CollisionTree primitive array should be sorted as it is built. This is false by default. Sorting is beneficial for model data that is not well ordered spatially. This occurrence is rare, and sorting slows creation time. It is, therefore, only to be used when model data requires it. maxPrimitivesPerLeaf defines the number of primitives a leaf node in the collision tree should maintain. The larger number of primitives maintained in a leaf node, the smaller the tree, but the larger the number of checks during a collision. By default, this value is set to 16. maxElements defines the maximum number of trees that will be maintained before clean-up is required. A collision tree is defined for each mesh that is being collided with. The user should determine the optimal number of trees to maintain (a memory/performance tradeoff), based on the number of meshes, their population density and their primitive size. By default, this value is set to 25. The type of trees that will be generated is defined by the treeType value, where valid options are define in CollisionTree as AABB_TREE, OBB_TREE and SPHERE_TREE. You can set the functionality of how trees are removed from the cache by providing the manager with a CollisionTreeController implementation. By default, the manager will use the UsageTreeController for removing trees, but any other CollisionTreeController is acceptable. You can create protected tree manually. These are collision trees that you request the manager to create and not allow them to be removed by the CollisionTreeController.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
defines the default maximum number of trees to maintain.static final int
defines the default maximum number of primitives in a tree leaf. -
Method Summary
Modifier and TypeMethodDescriptiongenerateCollisionTree
(CollisionTree.Type type, Mesh mesh, boolean protect) generates a new tree for the associated mesh.void
generateCollisionTree
(CollisionTree.Type type, Spatial object, boolean protect) creates a new collision tree for the provided spatial.protected void
generateCollisionTree
(CollisionTree tree, Mesh mesh, boolean protect) generates a new tree for the associated mesh.getCollisionTree
(Mesh mesh) getCollisionTree obtains a collision tree that is assigned to a supplied Mesh.static CollisionTreeManager
retrieves the singleton instance of the CollisionTreeManager.int
returns the maximum number of CollisionTree elements this manager will hold on to before starting to clear some.int
returns the maximum number of primitives a leaf of the collision tree may contain.boolean
isDoSort()
returns true if the manager is set to sort new generated trees.boolean
returns true if the manager will automatically generate new trees as needed, false otherwise.void
removeCollisionTree
(Mesh mesh) removes a collision tree from the manager based on the mesh supplied.void
removeCollisionTree
(Spatial object) removes all collision trees associated with a Spatial object.void
removeProtected
(Mesh mesh) Removes the supplied mesh from the "protected" list.void
setCollisionTreeController
(CollisionTreeController treeRemover) sets the CollisionTreeController used for cleaning the cache when the maximum number of elements is reached.void
setDoSort
(boolean doSort) set if this manager should have newly generated trees sort primitives.void
setGenerateTrees
(boolean generateTrees) set if this manager should generate new trees as needed.void
setMaxElements
(int maxElements) set the maximum number of CollisionTree elements this manager will hold on to before starting to clear some.void
setMaxPrimitivesPerLeaf
(int maxPrimitivesPerLeaf) set the maximum number of primitives a leaf of the collision tree may contain.void
setProtected
(Mesh meshToProtect) Add the given mesh to our "protected" list.void
setTreeType
(CollisionTree.Type treeType) void
updateCollisionTree
(Mesh mesh) updates the existing tree for a supplied mesh.void
updateCollisionTree
(Spatial object) updates the existing tree(s) for a supplied spatial.static CollisionTreeManager
Returns the enum constant of this class with the specified name.static CollisionTreeManager[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
INSTANCE
-
-
Field Details
-
DEFAULT_MAX_ELEMENTS
public static final int DEFAULT_MAX_ELEMENTSdefines the default maximum number of trees to maintain.- See Also:
-
DEFAULT_MAX_PRIMITIVES_PER_LEAF
public static final int DEFAULT_MAX_PRIMITIVES_PER_LEAFdefines the default maximum number of primitives in a tree leaf.- See Also:
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
getInstance
retrieves the singleton instance of the CollisionTreeManager.- Returns:
- the singleton instance of the manager.
-
setCollisionTreeController
sets the CollisionTreeController used for cleaning the cache when the maximum number of elements is reached.- Parameters:
treeRemover
- the controller used to clean the cache.
-
getCollisionTree
getCollisionTree obtains a collision tree that is assigned to a supplied Mesh. The cache is checked for a pre-existing tree, if none is available and generateTrees is true, a new tree is created and returned.- Parameters:
mesh
- the mesh to use as the key for the tree to obtain.- Returns:
- the tree associated with a given mesh
-
generateCollisionTree
creates a new collision tree for the provided spatial. If the spatial is a node, it recursively calls generateCollisionTree for each child. If it is a Mesh, a call to generateCollisionTree is made for each mesh. If this tree(s) is to be protected, i.e. not deleted by the CollisionTreeController, set protect to true.- Parameters:
type
- the type of collision tree to generate.object
- the Spatial to generate tree(s) for.protect
- true to keep these trees from being removed, false otherwise.
-
generateCollisionTree
generates a new tree for the associated mesh. The type is provided and a new tree is constructed of this type. The tree is placed in the cache. If the cache's size then becomes too large, the cache is sent to the CollisionTreeController for clean-up. If this tree is to be protected, i.e. protected from the CollisionTreeController, set protect to true.- Parameters:
type
- the type of collision tree to generate.mesh
- the mesh to generate the tree for.protect
- true if this tree is to be protected, false otherwise.- Returns:
- the new collision tree.
-
generateCollisionTree
generates a new tree for the associated mesh. It is provided with a pre-existing, non-null tree. The tree is placed in the cache. If the cache's size then becomes too large, the cache is sent to the CollisionTreeController for clean-up. If this tree is to be protected, i.e. protected from the CollisionTreeController, set protect to true.- Parameters:
tree
- the tree to use for generationmesh
- the mesh to generate the tree for.protect
- true if this tree is to be protected, false otherwise.
-
removeCollisionTree
removes a collision tree from the manager based on the mesh supplied.- Parameters:
mesh
- the mesh to remove the corresponding collision tree.
-
removeCollisionTree
removes all collision trees associated with a Spatial object.- Parameters:
object
- the spatial to remove all collision trees from.
-
updateCollisionTree
updates the existing tree for a supplied mesh. If this tree does not exist, the tree is not updated. If the tree is not in the cache, no further operations are handled.- Parameters:
mesh
- the mesh key for the tree to update.
-
updateCollisionTree
updates the existing tree(s) for a supplied spatial. If this tree does not exist, the tree is not updated. If the tree is not in the cache, no further operations are handled.- Parameters:
object
- the object on which to update the tree.
-
isDoSort
public boolean isDoSort()returns true if the manager is set to sort new generated trees. False otherwise.- Returns:
- true to sort tree, false otherwise.
-
setDoSort
public void setDoSort(boolean doSort) set if this manager should have newly generated trees sort primitives.- Parameters:
doSort
- true to sort trees, false otherwise.
-
isGenerateTrees
public boolean isGenerateTrees()returns true if the manager will automatically generate new trees as needed, false otherwise.- Returns:
- true if this manager is generating trees, false otherwise.
-
setGenerateTrees
public void setGenerateTrees(boolean generateTrees) set if this manager should generate new trees as needed.- Parameters:
generateTrees
- true to generate trees, false otherwise.
-
getTreeType
- Returns:
- the type of tree the manager will create.
- See Also:
-
setTreeType
- Parameters:
treeType
- the type of tree to create.- See Also:
-
getMaxPrimitivesPerLeaf
public int getMaxPrimitivesPerLeaf()returns the maximum number of primitives a leaf of the collision tree may contain.- Returns:
- the maximum number of primitives a leaf may contain.
-
setMaxPrimitivesPerLeaf
public void setMaxPrimitivesPerLeaf(int maxPrimitivesPerLeaf) set the maximum number of primitives a leaf of the collision tree may contain.- Parameters:
maxPrimitivesPerLeaf
- the maximum number of primitives a leaf may contain.
-
getMaxElements
public int getMaxElements()returns the maximum number of CollisionTree elements this manager will hold on to before starting to clear some.- Returns:
- the maximum number of CollisionTree elements.
-
setMaxElements
public void setMaxElements(int maxElements) set the maximum number of CollisionTree elements this manager will hold on to before starting to clear some.- Parameters:
maxElements
- the maximum number of CollisionTree elements.
-
setProtected
Add the given mesh to our "protected" list. This will signal to our cleanup operation that when deciding which trees to trim in an effort to keep our cache size to a certain desired size, do not trim the tree associated with this mesh.- Parameters:
meshToProtect
- the mesh whose CollisionTree we want to protect.
-
removeProtected
Removes the supplied mesh from the "protected" list.- Parameters:
mesh
- the mesh to remove from the "protected" list
-
getProtectedMeshes
- Returns:
- an immutable copy of the list of protected meshes.
-