diff --git a/engine/src/test/jme3test/tools/TestOctree.java b/engine/src/test/jme3test/tools/TestOctree.java index ead8508b2..573f5eaf8 100644 --- a/engine/src/test/jme3test/tools/TestOctree.java +++ b/engine/src/test/jme3test/tools/TestOctree.java @@ -75,8 +75,6 @@ public class TestOctree extends SimpleApplication implements SceneProcessor { public void simpleInitApp() { // this.flyCam.setMoveSpeed(2000); // this.cam.setFrustumFar(10000); - MeshLoader.AUTO_INTERLEAVE = false; - // mat = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md"); // mat.setColor("Color", ColorRGBA.White); @@ -102,8 +100,8 @@ public class TestOctree extends SimpleApplication implements SceneProcessor { // generate octree // tree = new Octree(scene, 20000); - tree = new Octree(scene, 50); - tree.construct(); + tree = new Octree(scene); + tree.construct(50, 0.01f, 50); ArrayList globalGeomList = new ArrayList(); tree.createFastOctnodes(globalGeomList); diff --git a/engine/src/tools/jme3tools/optimize/Octnode.java b/engine/src/tools/jme3tools/optimize/Octnode.java index e9a00802a..dbc15d240 100644 --- a/engine/src/tools/jme3tools/optimize/Octnode.java +++ b/engine/src/tools/jme3tools/optimize/Octnode.java @@ -109,8 +109,8 @@ public class Octnode { return false; } - public void subdivide(int depth, int minTrisPerNode){ - if (tris == null || depth > 50 || bbox.getVolume() < 0.01f || tris.size() < minTrisPerNode){ + public void subdivide(int depth, int maxDepth, float maxVolume, int minTrisPerNode){ + if (tris == null || depth > maxDepth || bbox.getVolume() < maxVolume || tris.size() < minTrisPerNode){ // no need to subdivide anymore leaf = true; return; @@ -161,13 +161,13 @@ public class Octnode { for (int i = 0; i < 8; i++){ if (trisForChild[i].size() > 0){ 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){ - subdivide(0, minTrisPerNode); + public void subdivide(int maxDepth, float maxVolume, int minTrisPerNode){ + subdivide(0, maxDepth, maxVolume, minTrisPerNode); } public void createFastOctnode(List globalGeomList){ diff --git a/engine/src/tools/jme3tools/optimize/Octree.java b/engine/src/tools/jme3tools/optimize/Octree.java index 880f98459..4dd582dc5 100644 --- a/engine/src/tools/jme3tools/optimize/Octree.java +++ b/engine/src/tools/jme3tools/optimize/Octree.java @@ -55,7 +55,6 @@ public class Octree { private final ArrayList allTris = new ArrayList(); private final Geometry[] geoms; private final BoundingBox bbox; - private final int minTrisPerNode; private Octnode root; private CollisionResults boundResults = new CollisionResults(); @@ -77,7 +76,7 @@ public class Octree { } } - public Octree(Spatial scene, int minTrisPerNode){ + public Octree(Spatial scene){ scene.updateGeometricState(); List geomsList = getGeometries(scene); @@ -96,8 +95,6 @@ public class Octree { bbox.setYExtent(extent); bbox.setZExtent(extent); - this.minTrisPerNode = minTrisPerNode; - Triangle t = new Triangle(); for (int g = 0; g < geoms.length; g++){ Mesh m = geoms[g].getMesh(); @@ -113,13 +110,9 @@ public class Octree { } } - public Octree(Spatial scene){ - this(scene,11); - } - - public void construct(){ + public void construct(int maxDepth, float maxVolume, int minTrisPerNode){ root = new Octnode(bbox, allTris); - root.subdivide(minTrisPerNode); + root.subdivide(maxDepth, maxVolume, minTrisPerNode); root.collectTriangles(geoms); }