* Added ability to switch between lit model and tangent display
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8644 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
5440deeaeb
commit
4ba21821a3
@ -1,8 +1,10 @@
|
|||||||
package jme3test.light;
|
package jme3test.light;
|
||||||
|
|
||||||
import com.jme3.app.SimpleApplication;
|
import com.jme3.app.SimpleApplication;
|
||||||
import com.jme3.asset.plugins.UrlLocator;
|
import com.jme3.font.BitmapText;
|
||||||
import com.jme3.light.AmbientLight;
|
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.light.PointLight;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.FastMath;
|
import com.jme3.math.FastMath;
|
||||||
@ -12,9 +14,11 @@ import com.jme3.scene.Geometry;
|
|||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
import com.jme3.scene.shape.Sphere;
|
import com.jme3.scene.shape.Sphere;
|
||||||
import com.jme3.light.DirectionalLight;
|
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.Mesh;
|
||||||
|
import com.jme3.scene.Node;
|
||||||
import com.jme3.scene.SceneGraphVisitorAdapter;
|
import com.jme3.scene.SceneGraphVisitorAdapter;
|
||||||
|
import com.jme3.scene.Spatial.CullHint;
|
||||||
import com.jme3.util.TangentBinormalGenerator;
|
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://jme-glsl-shaders.googlecode.com/hg/assets/Models/LightBlow/", UrlLocator.class);
|
||||||
// assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/", 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);
|
// badModel.setLocalScale(1f);
|
||||||
|
|
||||||
// Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
|
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
|
||||||
// mat.setTexture("NormalMap", assetManager.loadTexture("jme_lightblow_nor.png"));
|
mat.setTexture("NormalMap", assetManager.loadTexture("Models/TangentBugs/test_normal.png"));
|
||||||
Material mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m");
|
// Material mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m");
|
||||||
badModel.setMaterial(mat);
|
badModel.setMaterial(mat);
|
||||||
rootNode.attachChild(badModel);
|
rootNode.attachChild(badModel);
|
||||||
|
|
||||||
@ -51,9 +55,13 @@ public class TestTangentGenBadModels extends SimpleApplication {
|
|||||||
// Spatial model = assetManager.loadModel("test.blend");
|
// Spatial model = assetManager.loadModel("test.blend");
|
||||||
// rootNode.attachChild(model);
|
// 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");
|
final Material debugMat = assetManager.loadMaterial("Common/Materials/VertexColor.j3m");
|
||||||
|
|
||||||
rootNode.depthFirstTraversal(new SceneGraphVisitorAdapter(){
|
badModel.depthFirstTraversal(new SceneGraphVisitorAdapter(){
|
||||||
@Override
|
@Override
|
||||||
public void visit(Geometry g){
|
public void visit(Geometry g){
|
||||||
Mesh m = g.getMesh();
|
Mesh m = g.getMesh();
|
||||||
@ -65,14 +73,14 @@ public class TestTangentGenBadModels extends SimpleApplication {
|
|||||||
TangentBinormalGenerator.generate(m);
|
TangentBinormalGenerator.generate(m);
|
||||||
|
|
||||||
Geometry debug = new Geometry(
|
Geometry debug = new Geometry(
|
||||||
"Debug Teapot",
|
"debug tangents geom",
|
||||||
TangentBinormalGenerator.genTbnLines(g.getMesh(), 0.2f)
|
TangentBinormalGenerator.genTbnLines(g.getMesh(), 0.2f)
|
||||||
);
|
);
|
||||||
debug.getMesh().setLineWidth(1);
|
debug.getMesh().setLineWidth(1);
|
||||||
debug.setMaterial(debugMat);
|
debug.setMaterial(debugMat);
|
||||||
debug.setCullHint(Spatial.CullHint.Never);
|
debug.setCullHint(Spatial.CullHint.Never);
|
||||||
debug.setLocalTransform(debug.getLocalTransform());
|
debug.setLocalTransform(g.getWorldTransform());
|
||||||
g.getParent().attachChild(debug);
|
debugTangents.attachChild(debug);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -89,6 +97,34 @@ public class TestTangentGenBadModels extends SimpleApplication {
|
|||||||
pl = new PointLight();
|
pl = new PointLight();
|
||||||
pl.setColor(ColorRGBA.White);
|
pl.setColor(ColorRGBA.White);
|
||||||
// rootNode.addLight(pl);
|
// 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
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user