private void initCam() { // Camera Setup flyCam.setEnabled(false); cameraFixpoint = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj"); // cameraFixpoint.setMaterial(new Material(assetManager, // "Common/MatDefs/Misc/ShowNormals.j3md")); rootNode.attachChild(cameraFixpoint); chaseCam = new ChaseCamera(getCam(), cameraFixpoint, inputManager); chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE)); chaseCam.setMinVerticalRotation((float) (-Math.PI / 2)); }
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"); Spatial s = assetManager.loadModel(MODEL); if (s instanceof Node) { model = (Node) s; } else { model = new Node(); model.attachChild(s); } 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) { Geometry geom = (Geometry) spatial; Material mat = geom.getMaterial(); mat.setTransparent(true); mat.getAdditionalRenderState().setAlphaTest(true); mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha); geom.setQueueBucket(RenderQueue.Bucket.Transparent); listGeoms.add(geom); } } 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)); }