LodGenerator used squared length of en edge as parameter for its collapse cost instead of the length. It gives better results

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10639 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 12 years ago
parent b918c707b8
commit f0b44c0704
  1. 18
      engine/src/test/jme3test/stress/TestLodGeneration.java
  2. 4
      engine/src/tools/jme3tools/optimize/LodGenerator.java

@ -32,6 +32,7 @@
package jme3test.stress; package jme3test.stress;
import com.jme3.animation.AnimChannel; import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.SkeletonControl; import com.jme3.animation.SkeletonControl;
import com.jme3.app.SimpleApplication; import com.jme3.app.SimpleApplication;
import com.jme3.bounding.BoundingBox; import com.jme3.bounding.BoundingBox;
@ -79,8 +80,8 @@ public class TestLodGeneration extends SimpleApplication {
al.setColor(ColorRGBA.White.mult(0.6f)); al.setColor(ColorRGBA.White.mult(0.6f));
rootNode.addLight(al); rootNode.addLight(al);
model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml"); // model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
//model = (Node) assetManager.loadModel("Models/Jaime/Jaime.j3o"); model = (Node) assetManager.loadModel("Models/Jaime/Jaime.j3o");
BoundingBox b = ((BoundingBox) model.getWorldBound()); BoundingBox b = ((BoundingBox) model.getWorldBound());
model.setLocalScale(1.2f / (b.getYExtent() * 2)); model.setLocalScale(1.2f / (b.getYExtent() * 2));
// model.setLocalTranslation(0,-(b.getCenter().y - b.getYExtent())* model.getLocalScale().y, 0); // model.setLocalTranslation(0,-(b.getCenter().y - b.getYExtent())* model.getLocalScale().y, 0);
@ -98,24 +99,21 @@ public class TestLodGeneration extends SimpleApplication {
// ch = model.getControl(AnimControl.class).createChannel(); // ch = model.getControl(AnimControl.class).createChannel();
// ch.setAnim("Wave"); // ch.setAnim("Wave");
SkeletonControl c = model.getControl(SkeletonControl.class); SkeletonControl c = model.getControl(SkeletonControl.class);
if (c != null) { if (c != null) {
c.setEnabled(false); c.setEnabled(false);
} }
reductionvalue = 0.001f; reductionvalue = 0.80f;
// makeLod(LodGenerator.VertexReductionMethod.PROPORTIONAL, reductionvalue, 1);
lodLevel = 1; lodLevel = 1;
for (final Geometry geometry : listGeoms) { for (final Geometry geometry : listGeoms) {
LodGenerator lODGenerator = new LodGenerator(geometry); LodGenerator lodGenerator = new LodGenerator(geometry);
lODGenerator.bakeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue); lodGenerator.bakeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue);
geometry.setLodLevel(lodLevel); geometry.setLodLevel(lodLevel);
} }
rootNode.attachChild(model); rootNode.attachChild(model);

@ -500,8 +500,8 @@ public class LodGenerator {
} }
assert (cost >= 0); assert (cost >= 0);
// TODO: use squared distance.
return cost * src.position.distance(dest.position); return cost * src.position.distanceSquared(dest.position);
} }
int nbCollapsedTri = 0; int nbCollapsedTri = 0;

Loading…
Cancel
Save