📄 collisiontreemanager.java
字号:
* the type of collision tree to generate.
* @param mesh
* the mesh to generate the tree for.
* @param protect
* true if this tree is to be protected, false otherwise.
* @return the new collision tree.
*/
public CollisionTree generateCollisionTree(CollisionTree.Type type,
TriMesh mesh, boolean protect) {
if (mesh == null) {
return null;
}
CollisionTree tree = new CollisionTree(type);
return generateCollisionTree(tree, mesh, protect);
}
/**
* 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.
*
* @param tree
* the tree to use for generation
* @param mesh
* the mesh to generate the tree for.
* @param protect
* true if this tree is to be protected, false otherwise.
* @return the new collision tree.
*/
public CollisionTree generateCollisionTree(CollisionTree tree,
TriMesh mesh, boolean protect) {
if (tree != null) {
if (mesh instanceof SharedMesh) {
// we might already have the appropriate tree
if (!cache.containsKey(((SharedMesh) mesh).getTarget())) {
tree.construct(((SharedMesh) mesh).getTarget(), doSort);
cache.put(((SharedMesh) mesh).getTarget(), tree);
// This mesh has been added by outside sources and labeled
// as protected. Therefore, put it in the protected list
// so it is not removed by a controller.
if (protect) {
if (protectedList == null) {
protectedList = Collections.synchronizedList(new ArrayList<TriMesh>(1));
}
protectedList.add(((SharedMesh) mesh).getTarget());
}
}
} else {
tree.construct(mesh, doSort);
cache.put(mesh, tree);
// This mesh has been added by outside sources and labeled
// as protected. Therefore, put it in the protected list
// so it is not removed by a controller.
if (protect) {
if (protectedList == null) {
protectedList = Collections.synchronizedList(new ArrayList<TriMesh>(1));
}
protectedList.add(mesh);
}
}
// Are we over our max? Test
if (cache.size() > maxElements && treeRemover != null) {
treeRemover.clean(cache, protectedList, maxElements);
}
}
return tree;
}
/**
* removes a collision tree from the manager based on the mesh supplied.
*
* @param mesh
* the mesh to remove the corresponding collision tree.
*/
public void removeCollisionTree(TriMesh mesh) {
cache.remove(mesh);
}
/**
* removes all collision trees associated with a Spatial object.
*
* @param object
* the spatial to remove all collision trees from.
*/
public void removeCollisionTree(Spatial object) {
if (object instanceof Node) {
Node n = (Node) object;
for (int i = n.getQuantity() - 1; i >= 0; i--) {
removeCollisionTree(n.getChild(i));
}
} else if (object instanceof TriMesh) {
removeCollisionTree((TriMesh) object);
}
}
/**
* 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.
*
* @param mesh
* the mesh key for the tree to update.
*/
public void updateCollisionTree(TriMesh mesh) {
CollisionTree ct = cache.get(mesh);
if (ct != null) {
generateCollisionTree(ct, mesh, protectedList != null
&& protectedList.contains(mesh));
}
}
/**
* 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.
*
* @param object
* the object on which to update the tree.
*/
public void updateCollisionTree(Spatial object) {
if (object instanceof Node) {
Node n = (Node) object;
for (int i = n.getQuantity() - 1; i >= 0; i--) {
updateCollisionTree(n.getChild(i));
}
} else if (object instanceof TriMesh) {
updateCollisionTree((TriMesh) object);
}
}
/**
* returns true if the manager is set to sort new generated trees. False
* otherwise.
*
* @return true to sort tree, false otherwise.
*/
public boolean isDoSort() {
return doSort;
}
/**
* set if this manager should have newly generated trees sort triangles.
*
* @param doSort
* true to sort trees, false otherwise.
*/
public void setDoSort(boolean doSort) {
this.doSort = doSort;
}
/**
* returns true if the manager will automatically generate new trees as
* needed, false otherwise.
*
* @return true if this manager is generating trees, false otherwise.
*/
public boolean isGenerateTrees() {
return generateTrees;
}
/**
* set if this manager should generate new trees as needed.
*
* @param generateTrees
* true to generate trees, false otherwise.
*/
public void setGenerateTrees(boolean generateTrees) {
this.generateTrees = generateTrees;
}
/**
* @return the type of tree the manager will create.
* @see CollisionTree.Type
*/
public CollisionTree.Type getTreeType() {
return treeType;
}
/**
* @param treeType
* the type of tree to create.
* @see CollisionTree.Type
*/
public void setTreeType(CollisionTree.Type treeType) {
this.treeType = treeType;
}
/**
* returns the maximum number of triangles a leaf of the collision tree will
* contain.
*
* @return the maximum number of triangles a leaf will contain.
*/
public int getMaxTrisPerLeaf() {
return maxTrisPerLeaf;
}
/**
* set the maximum number of triangles a leaf of the collision tree will
* contain.
*
* @param maxTrisPerLeaf
* the maximum number of triangles a leaf will contain.
*/
public void setMaxTrisPerLeaf(int maxTrisPerLeaf) {
this.maxTrisPerLeaf = maxTrisPerLeaf;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -