use of jme3tools.optimize.LodGenerator in project jmonkeyengine by jMonkeyEngine.
the class TestLodGeneration method makeLod.
private void makeLod(final LodGenerator.TriangleReductionMethod method, final float value, final int ll) {
exec.execute(new Runnable() {
public void run() {
for (final Geometry geometry : listGeoms) {
LodGenerator lODGenerator = new LodGenerator(geometry);
final VertexBuffer[] lods = lODGenerator.computeLods(method, value);
enqueue(new Callable<Void>() {
public Void call() throws Exception {
geometry.getMesh().setLodLevels(lods);
lodLevel = 0;
if (geometry.getMesh().getNumLodLevels() > ll) {
lodLevel = ll;
}
geometry.setLodLevel(lodLevel);
hudText.setText(computeNbTri() + " tris");
return null;
}
});
}
}
});
}
use of jme3tools.optimize.LodGenerator in project jmonkeyengine by jMonkeyEngine.
the class TestLodGeneration method simpleInitApp.
public void simpleInitApp() {
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
rootNode.addLight(dl);
AmbientLight al = new AmbientLight();
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");
BoundingBox b = ((BoundingBox) model.getWorldBound());
model.setLocalScale(1.2f / (b.getYExtent() * 2));
// model.setLocalTranslation(0,-(b.getCenter().y - b.getYExtent())* model.getLocalScale().y, 0);
for (Spatial spatial : model.getChildren()) {
if (spatial instanceof Geometry) {
listGeoms.add((Geometry) spatial);
}
}
ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
model.addControl(chaseCam);
chaseCam.setLookAtOffset(b.getCenter());
chaseCam.setDefaultDistance(5);
chaseCam.setMinVerticalRotation(-FastMath.HALF_PI + 0.01f);
chaseCam.setZoomSensitivity(0.5f);
// ch = model.getControl(AnimControl.class).createChannel();
// ch.setAnim("Wave");
SkeletonControl c = model.getControl(SkeletonControl.class);
if (c != null) {
c.setEnabled(false);
}
reductionvalue = 0.80f;
lodLevel = 1;
for (final Geometry geometry : listGeoms) {
LodGenerator lodGenerator = new LodGenerator(geometry);
lodGenerator.bakeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue);
geometry.setLodLevel(lodLevel);
}
rootNode.attachChild(model);
flyCam.setEnabled(false);
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
hudText = new BitmapText(guiFont, false);
hudText.setSize(guiFont.getCharSet().getRenderedSize());
hudText.setText(computeNbTri() + " tris");
hudText.setLocalTranslation(cam.getWidth() / 2, hudText.getLineHeight(), 0);
guiNode.attachChild(hudText);
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (isPressed) {
if (name.equals("plus")) {
// lodLevel++;
// for (Geometry geometry : listGeoms) {
// if (geometry.getMesh().getNumLodLevels() <= lodLevel) {
// lodLevel = 0;
// }
// geometry.setLodLevel(lodLevel);
// }
// jaimeText.setText(computeNbTri() + " tris");
reductionvalue += 0.05f;
updateLod();
}
if (name.equals("minus")) {
// lodLevel--;
// for (Geometry geometry : listGeoms) {
// if (lodLevel < 0) {
// lodLevel = geometry.getMesh().getNumLodLevels() - 1;
// }
// geometry.setLodLevel(lodLevel);
// }
// jaimeText.setText(computeNbTri() + " tris");
reductionvalue -= 0.05f;
updateLod();
}
if (name.equals("wireFrame")) {
wireFrame = !wireFrame;
for (Geometry geometry : listGeoms) {
geometry.getMaterial().getAdditionalRenderState().setWireframe(wireFrame);
}
}
}
}
private void updateLod() {
reductionvalue = FastMath.clamp(reductionvalue, 0.0f, 1.0f);
makeLod(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue, 1);
}
}, "plus", "minus", "wireFrame");
inputManager.addMapping("plus", new KeyTrigger(KeyInput.KEY_ADD));
inputManager.addMapping("minus", new KeyTrigger(KeyInput.KEY_SUBTRACT));
inputManager.addMapping("wireFrame", new KeyTrigger(KeyInput.KEY_SPACE));
}
use of jme3tools.optimize.LodGenerator in project chordatlas by twak.
the class LineGen3d method calculate.
@Override
public void calculate() {
for (Spatial s : gNode.getChildren()) s.removeFromParent();
{
Geometry geom;
Mesh m = new Mesh();
m.setMode(Mesh.Mode.Lines);
List<Float> coords = new ArrayList();
List<Integer> inds = new ArrayList();
for (Line3d l : getLines()) {
inds.add(inds.size());
inds.add(inds.size());
coords.add((float) l.start.x);
coords.add((float) l.start.y);
coords.add((float) l.start.z);
coords.add((float) l.end.x);
coords.add((float) l.end.y);
coords.add((float) l.end.z);
}
m.setBuffer(VertexBuffer.Type.Position, 3, Arrayz.toFloatArray(coords));
m.setBuffer(VertexBuffer.Type.Index, 2, Arrayz.toIntArray(inds));
geom = new Geometry(filename, m);
geom.setCullHint(CullHint.Never);
Material lineMaterial = new Material(tweed.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
lineMaterial.setColor("Color", new ColorRGBA(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1f));
geom.setMaterial(lineMaterial);
geom.setLocalTranslation(0, 0, 0);
gNode.attachChild(geom);
}
// int c = 0;
VertexBuffer emptyVB = new VertexBuffer(Type.Index);
emptyVB.setupData(Usage.Static, 3, Format.UnsignedShort, BufferUtils.createShortBuffer(0));
{
Geometry geom;
Random randy = new Random();
for (Map.Entry<Loop<Point3d>, Integer> e : getFaces().entrySet()) {
Loop<Point3d> p = e.getKey();
final int callbackI = e.getValue();
Mesh m = Jme3z.fromLoop(p);
// m.setMode( Mesh.Mode.Triangles );
//
// List<Integer> inds = new ArrayList<>();
// List<Float> pos = new ArrayList<>();
// List<Float> norms = new ArrayList<>();
//
// Loopz.triangulate( p, true, inds, pos, norms );
//
// m.set setVe( Type.Index, Arrayz.toIntArray(inds));
geom = new Geometry(filename, m);
geom.setCullHint(CullHint.Never);
// ColorRGBA col = Jme3z.toJme( Rainbow.getColour( c++ ) );
ColorRGBA col = new ColorRGBA(color.getRed() * randy.nextFloat() / 500f + 0.1f, color.getGreen() * randy.nextFloat() / 500f + 0.1f, color.getBlue() * randy.nextFloat() / 500f + 0.1f, 1f);
Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
mat.setColor("Diffuse", col);
mat.setColor("Ambient", col);
mat.setBoolean("UseMaterialColors", true);
geom.setUserData(ClickMe.class.getSimpleName(), new Object[] { new ClickMe() {
@Override
public void clicked(Object data) {
polyClicked(callbackI);
}
} });
geom.setUserData(Gen.class.getSimpleName(), new Object[] { this });
geom.setMaterial(mat);
geom.setLocalTranslation(0, 0, 0);
if (TweedSettings.settings.LOD) {
LodGenerator lod = new LodGenerator(geom);
lod.bakeLods(LodGenerator.TriangleReductionMethod.COLLAPSE_COST, 10, 100);
GISLodControl lc = new GISLodControl();
lc.setTrisPerPixel(0.000001f);
geom.addControl(lc);
}
gNode.attachChild(geom);
}
}
gNode.updateModelBound();
super.calculate();
}
Aggregations