diff --git a/engine/src/test/jme3test/light/TestTangentGenBadModels.java b/engine/src/test/jme3test/light/TestTangentGenBadModels.java index 30e9e7f39..91c4ffba0 100644 --- a/engine/src/test/jme3test/light/TestTangentGenBadModels.java +++ b/engine/src/test/jme3test/light/TestTangentGenBadModels.java @@ -1,8 +1,10 @@ package jme3test.light; import com.jme3.app.SimpleApplication; -import com.jme3.asset.plugins.UrlLocator; -import com.jme3.light.AmbientLight; +import com.jme3.font.BitmapText; +import com.jme3.input.KeyInput; +import com.jme3.input.controls.ActionListener; +import com.jme3.input.controls.KeyTrigger; import com.jme3.light.PointLight; import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; @@ -12,9 +14,11 @@ import com.jme3.scene.Geometry; import com.jme3.scene.Spatial; import com.jme3.scene.shape.Sphere; import com.jme3.light.DirectionalLight; -import com.jme3.math.Transform; +import com.jme3.renderer.queue.RenderQueue.Bucket; import com.jme3.scene.Mesh; +import com.jme3.scene.Node; import com.jme3.scene.SceneGraphVisitorAdapter; +import com.jme3.scene.Spatial.CullHint; import com.jme3.util.TangentBinormalGenerator; /** @@ -37,12 +41,12 @@ public class TestTangentGenBadModels extends SimpleApplication { // assetManager.registerLocator("http://jme-glsl-shaders.googlecode.com/hg/assets/Models/LightBlow/", UrlLocator.class); // assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/", UrlLocator.class); - Spatial badModel = assetManager.loadModel("Models/TangentBugs/test.blend"); + final Spatial badModel = assetManager.loadModel("Models/TangentBugs/test.blend"); // badModel.setLocalScale(1f); -// Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); -// mat.setTexture("NormalMap", assetManager.loadTexture("jme_lightblow_nor.png")); - Material mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m"); + Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); + mat.setTexture("NormalMap", assetManager.loadTexture("Models/TangentBugs/test_normal.png")); +// Material mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m"); badModel.setMaterial(mat); rootNode.attachChild(badModel); @@ -50,10 +54,14 @@ public class TestTangentGenBadModels extends SimpleApplication { // need to check it // Spatial model = assetManager.loadModel("test.blend"); // rootNode.attachChild(model); + + final Node debugTangents = new Node("debug tangents"); + debugTangents.setCullHint(CullHint.Always); + rootNode.attachChild(debugTangents); final Material debugMat = assetManager.loadMaterial("Common/Materials/VertexColor.j3m"); - rootNode.depthFirstTraversal(new SceneGraphVisitorAdapter(){ + badModel.depthFirstTraversal(new SceneGraphVisitorAdapter(){ @Override public void visit(Geometry g){ Mesh m = g.getMesh(); @@ -65,14 +73,14 @@ public class TestTangentGenBadModels extends SimpleApplication { TangentBinormalGenerator.generate(m); Geometry debug = new Geometry( - "Debug Teapot", + "debug tangents geom", TangentBinormalGenerator.genTbnLines(g.getMesh(), 0.2f) ); debug.getMesh().setLineWidth(1); debug.setMaterial(debugMat); debug.setCullHint(Spatial.CullHint.Never); - debug.setLocalTransform(debug.getLocalTransform()); - g.getParent().attachChild(debug); + debug.setLocalTransform(g.getWorldTransform()); + debugTangents.attachChild(debug); } }); @@ -89,6 +97,34 @@ public class TestTangentGenBadModels extends SimpleApplication { pl = new PointLight(); pl.setColor(ColorRGBA.White); // rootNode.addLight(pl); + + + BitmapText info = new BitmapText(guiFont); + info.setText("Press SPACE to switch between lighting and tangent display"); + info.setQueueBucket(Bucket.Gui); + info.move(0, settings.getHeight() - info.getLineHeight(), 0); + rootNode.attachChild(info); + + inputManager.addMapping("space", new KeyTrigger(KeyInput.KEY_SPACE)); + inputManager.addListener(new ActionListener() { + + private boolean isLit = true; + + public void onAction(String name, boolean isPressed, float tpf) { + if (isPressed) return; + Material mat; + if (isLit){ + mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m"); + debugTangents.setCullHint(CullHint.Inherit); + }else{ + mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); + mat.setTexture("NormalMap", assetManager.loadTexture("Models/TangentBugs/test_normal.png")); + debugTangents.setCullHint(CullHint.Always); + } + isLit = !isLit; + badModel.setMaterial(mat); + } + }, "space"); } @Override