* Octree/Octnode: construct method now takes arguments for max depth, max volume, and tris per node

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9489 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
Sha..rd 2012-06-14 00:17:03 +00:00
parent 613d519544
commit 37aa17302f
3 changed files with 10 additions and 19 deletions

View File

@ -75,8 +75,6 @@ public class TestOctree extends SimpleApplication implements SceneProcessor {
public void simpleInitApp() { public void simpleInitApp() {
// this.flyCam.setMoveSpeed(2000); // this.flyCam.setMoveSpeed(2000);
// this.cam.setFrustumFar(10000); // this.cam.setFrustumFar(10000);
MeshLoader.AUTO_INTERLEAVE = false;
// mat = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md"); // mat = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
// mat.setColor("Color", ColorRGBA.White); // mat.setColor("Color", ColorRGBA.White);
@ -102,8 +100,8 @@ public class TestOctree extends SimpleApplication implements SceneProcessor {
// generate octree // generate octree
// tree = new Octree(scene, 20000); // tree = new Octree(scene, 20000);
tree = new Octree(scene, 50); tree = new Octree(scene);
tree.construct(); tree.construct(50, 0.01f, 50);
ArrayList<Geometry> globalGeomList = new ArrayList<Geometry>(); ArrayList<Geometry> globalGeomList = new ArrayList<Geometry>();
tree.createFastOctnodes(globalGeomList); tree.createFastOctnodes(globalGeomList);

View File

@ -109,8 +109,8 @@ public class Octnode {
return false; return false;
} }
public void subdivide(int depth, int minTrisPerNode){ public void subdivide(int depth, int maxDepth, float maxVolume, int minTrisPerNode){
if (tris == null || depth > 50 || bbox.getVolume() < 0.01f || tris.size() < minTrisPerNode){ if (tris == null || depth > maxDepth || bbox.getVolume() < maxVolume || tris.size() < minTrisPerNode){
// no need to subdivide anymore // no need to subdivide anymore
leaf = true; leaf = true;
return; return;
@ -161,13 +161,13 @@ public class Octnode {
for (int i = 0; i < 8; i++){ for (int i = 0; i < 8; i++){
if (trisForChild[i].size() > 0){ if (trisForChild[i].size() > 0){
children[i] = new Octnode(boxForChild[i], trisForChild[i]); children[i] = new Octnode(boxForChild[i], trisForChild[i]);
children[i].subdivide(depth + 1, minTrisPerNode); children[i].subdivide(depth + 1, maxDepth, maxVolume, minTrisPerNode);
} }
} }
} }
public void subdivide(int minTrisPerNode){ public void subdivide(int maxDepth, float maxVolume, int minTrisPerNode){
subdivide(0, minTrisPerNode); subdivide(0, maxDepth, maxVolume, minTrisPerNode);
} }
public void createFastOctnode(List<Geometry> globalGeomList){ public void createFastOctnode(List<Geometry> globalGeomList){

View File

@ -55,7 +55,6 @@ public class Octree {
private final ArrayList<OCTTriangle> allTris = new ArrayList<OCTTriangle>(); private final ArrayList<OCTTriangle> allTris = new ArrayList<OCTTriangle>();
private final Geometry[] geoms; private final Geometry[] geoms;
private final BoundingBox bbox; private final BoundingBox bbox;
private final int minTrisPerNode;
private Octnode root; private Octnode root;
private CollisionResults boundResults = new CollisionResults(); private CollisionResults boundResults = new CollisionResults();
@ -77,7 +76,7 @@ public class Octree {
} }
} }
public Octree(Spatial scene, int minTrisPerNode){ public Octree(Spatial scene){
scene.updateGeometricState(); scene.updateGeometricState();
List<Geometry> geomsList = getGeometries(scene); List<Geometry> geomsList = getGeometries(scene);
@ -96,8 +95,6 @@ public class Octree {
bbox.setYExtent(extent); bbox.setYExtent(extent);
bbox.setZExtent(extent); bbox.setZExtent(extent);
this.minTrisPerNode = minTrisPerNode;
Triangle t = new Triangle(); Triangle t = new Triangle();
for (int g = 0; g < geoms.length; g++){ for (int g = 0; g < geoms.length; g++){
Mesh m = geoms[g].getMesh(); Mesh m = geoms[g].getMesh();
@ -113,13 +110,9 @@ public class Octree {
} }
} }
public Octree(Spatial scene){ public void construct(int maxDepth, float maxVolume, int minTrisPerNode){
this(scene,11);
}
public void construct(){
root = new Octnode(bbox, allTris); root = new Octnode(bbox, allTris);
root.subdivide(minTrisPerNode); root.subdivide(maxDepth, maxVolume, minTrisPerNode);
root.collectTriangles(geoms); root.collectTriangles(geoms);
} }