From f0b44c0704e7a10422a4ab586fc13cbec4fcebcf Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Sun, 2 Jun 2013 21:12:59 +0000 Subject: [PATCH] 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 --- .../jme3test/stress/TestLodGeneration.java | 18 ++++++++---------- .../tools/jme3tools/optimize/LodGenerator.java | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/engine/src/test/jme3test/stress/TestLodGeneration.java b/engine/src/test/jme3test/stress/TestLodGeneration.java index 07de66058..cf8dbb64b 100644 --- a/engine/src/test/jme3test/stress/TestLodGeneration.java +++ b/engine/src/test/jme3test/stress/TestLodGeneration.java @@ -32,6 +32,7 @@ package jme3test.stress; import com.jme3.animation.AnimChannel; +import com.jme3.animation.AnimControl; import com.jme3.animation.SkeletonControl; import com.jme3.app.SimpleApplication; import com.jme3.bounding.BoundingBox; @@ -79,8 +80,8 @@ public class TestLodGeneration extends SimpleApplication { al.setColor(ColorRGBA.White.mult(0.6f)); rootNode.addLight(al); - model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml"); - //model = (Node) assetManager.loadModel("Models/Jaime/Jaime.j3o"); + // model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml"); + model = (Node) assetManager.loadModel("Models/Jaime/Jaime.j3o"); BoundingBox b = ((BoundingBox) model.getWorldBound()); model.setLocalScale(1.2f / (b.getYExtent() * 2)); // 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.setAnim("Wave"); +// ch = model.getControl(AnimControl.class).createChannel(); +// ch.setAnim("Wave"); SkeletonControl c = model.getControl(SkeletonControl.class); if (c != null) { c.setEnabled(false); } - reductionvalue = 0.001f; - // makeLod(LodGenerator.VertexReductionMethod.PROPORTIONAL, reductionvalue, 1); - + reductionvalue = 0.80f; lodLevel = 1; for (final Geometry geometry : listGeoms) { - LodGenerator lODGenerator = new LodGenerator(geometry); - lODGenerator.bakeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue); + LodGenerator lodGenerator = new LodGenerator(geometry); + lodGenerator.bakeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue); geometry.setLodLevel(lodLevel); - } rootNode.attachChild(model); diff --git a/engine/src/tools/jme3tools/optimize/LodGenerator.java b/engine/src/tools/jme3tools/optimize/LodGenerator.java index d24b9e64c..308a79886 100644 --- a/engine/src/tools/jme3tools/optimize/LodGenerator.java +++ b/engine/src/tools/jme3tools/optimize/LodGenerator.java @@ -500,8 +500,8 @@ public class LodGenerator { } assert (cost >= 0); - // TODO: use squared distance. - return cost * src.position.distance(dest.position); + + return cost * src.position.distanceSquared(dest.position); } int nbCollapsedTri = 0;