* 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
3.0
Sha..rd 13 years ago
parent 613d519544
commit 37aa17302f
  1. 6
      engine/src/test/jme3test/tools/TestOctree.java
  2. 10
      engine/src/tools/jme3tools/optimize/Octnode.java
  3. 13
      engine/src/tools/jme3tools/optimize/Octree.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<Geometry> globalGeomList = new ArrayList<Geometry>();
tree.createFastOctnodes(globalGeomList);

@ -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<Geometry> globalGeomList){

@ -55,7 +55,6 @@ public class Octree {
private final ArrayList<OCTTriangle> allTris = new ArrayList<OCTTriangle>();
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<Geometry> 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);
}

Loading…
Cancel
Save