use of com.jme3.math.ColorRGBA in project jmonkeyengine by jMonkeyEngine.
the class TestTangentGenBadModels method simpleInitApp.
@Override
public void simpleInitApp() {
// assetManager.registerLocator("http://jme-glsl-shaders.googlecode.com/hg/assets/Models/LightBlow/", UrlLocator.class);
// assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/", UrlLocator.class);
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("Models/TangentBugs/test_normal.png"));
// Material mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m");
badModel.setMaterial(mat);
rootNode.attachChild(badModel);
// TODO: For some reason blender loader fails to load this.
// 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");
badModel.depthFirstTraversal(new SceneGraphVisitorAdapter() {
@Override
public void visit(Geometry g) {
Mesh m = g.getMesh();
Material mat = g.getMaterial();
// if (mat.getParam("DiffuseMap") != null){
// mat.setTexture("DiffuseMap", null);
// }
TangentBinormalGenerator.generate(m);
Geometry debug = new Geometry("debug tangents geom", TangentBinormalGenerator.genTbnLines(g.getMesh(), 0.2f));
debug.setMaterial(debugMat);
debug.setCullHint(Spatial.CullHint.Never);
debug.setLocalTransform(g.getWorldTransform());
debugTangents.attachChild(debug);
}
});
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.8f, -0.6f, -0.08f).normalizeLocal());
dl.setColor(new ColorRGBA(1, 1, 1, 1));
rootNode.addLight(dl);
lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
lightMdl.getMesh().setStatic();
rootNode.attachChild(lightMdl);
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");
}
use of com.jme3.math.ColorRGBA in project jmonkeyengine by jMonkeyEngine.
the class TestTransparentShadow method simpleInitApp.
public void simpleInitApp() {
cam.setLocation(new Vector3f(5.700248f, 6.161693f, 5.1404157f));
cam.setRotation(new Quaternion(-0.09441641f, 0.8993388f, -0.24089815f, -0.35248178f));
viewPort.setBackgroundColor(ColorRGBA.DarkGray);
Quad q = new Quad(20, 20);
q.scaleTextureCoordinates(Vector2f.UNIT_XY.mult(10));
TangentBinormalGenerator.generate(q);
Geometry geom = new Geometry("floor", q);
Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
geom.setMaterial(mat);
geom.rotate(-FastMath.HALF_PI, 0, 0);
geom.center();
geom.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(geom);
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(0.7f));
rootNode.addLight(al);
DirectionalLight dl1 = new DirectionalLight();
dl1.setDirection(new Vector3f(0, -1, 0.5f).normalizeLocal());
dl1.setColor(ColorRGBA.White.mult(1.5f));
rootNode.addLight(dl1);
// create the geometry and attach it
Spatial tree = assetManager.loadModel("Models/Tree/Tree.mesh.j3o");
tree.setQueueBucket(Bucket.Transparent);
tree.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(tree);
// Uses Texture from jme3-test-data library!
ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30);
Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
fire.setShadowMode(ShadowMode.Cast);
fire.setMaterial(mat_red);
fire.setImagesX(2);
// 2x2 texture animation
fire.setImagesY(2);
// red
fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f));
// yellow
fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f));
fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 2, 0));
fire.setStartSize(0.6f);
fire.setEndSize(0.1f);
fire.setGravity(0, 0, 0);
fire.setLowLife(0.5f);
fire.setHighLife(1.5f);
fire.getParticleInfluencer().setVelocityVariation(0.3f);
fire.setLocalTranslation(5.0f, 0, 1.0f);
fire.setLocalScale(0.3f);
fire.setQueueBucket(Bucket.Translucent);
rootNode.attachChild(fire);
Material mat2 = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
Geometry ball = new Geometry("sphere", new Sphere(16, 16, 0.5f));
ball.setMaterial(mat2);
ball.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(ball);
ball.setLocalTranslation(-1.0f, 1.5f, 1.0f);
final DirectionalLightShadowRenderer dlsRenderer = new DirectionalLightShadowRenderer(assetManager, 1024, 1);
dlsRenderer.setLight(dl1);
dlsRenderer.setLambda(0.55f);
dlsRenderer.setShadowIntensity(0.8f);
dlsRenderer.setShadowCompareMode(CompareMode.Software);
dlsRenderer.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
dlsRenderer.displayDebug();
viewPort.addProcessor(dlsRenderer);
inputManager.addMapping("stabilize", new KeyTrigger(KeyInput.KEY_B));
inputManager.addListener(new ActionListener() {
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("stabilize") && isPressed) {
dlsRenderer.setEnabledStabilization(!dlsRenderer.isEnabledStabilization());
}
}
}, "stabilize");
}
use of com.jme3.math.ColorRGBA in project jmonkeyengine by jMonkeyEngine.
the class TestColoredTexture method simpleUpdate.
@Override
public void simpleUpdate(float tpf) {
time += tpf;
if (time > 1f) {
time -= 1f;
prevColor = nextColor;
nextColor = ColorRGBA.randomColor();
}
ColorRGBA currentColor = new ColorRGBA();
currentColor.interpolateLocal(prevColor, nextColor, time);
mat.setColor("Color", currentColor);
}
use of com.jme3.math.ColorRGBA in project jmonkeyengine by jMonkeyEngine.
the class TestNormalMapping method simpleInitApp.
@Override
public void simpleInitApp() {
Sphere sphMesh = new Sphere(32, 32, 1);
sphMesh.setTextureMode(Sphere.TextureMode.Projected);
sphMesh.updateGeometry(32, 32, 1, false, false);
TangentBinormalGenerator.generate(sphMesh);
Geometry sphere = new Geometry("Rock Ball", sphMesh);
Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
sphere.setMaterial(mat);
rootNode.attachChild(sphere);
lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
rootNode.attachChild(lightMdl);
pl = new PointLight();
pl.setColor(ColorRGBA.White);
pl.setPosition(new Vector3f(0f, 0f, 4f));
rootNode.addLight(pl);
// DirectionalLight dl = new DirectionalLight();
// dl.setDirection(new Vector3f(1,-1,1).normalizeLocal());
// dl.setColor(new ColorRGBA(0.22f, 0.15f, 0.1f, 1.0f));
// rootNode.addLight(dl);
}
use of com.jme3.math.ColorRGBA in project jmonkeyengine by jMonkeyEngine.
the class TestWalkingChar method prepareEffect.
private void prepareEffect() {
int COUNT_FACTOR = 1;
float COUNT_FACTOR_F = 1f;
effect = new ParticleEmitter("Flame", Type.Triangle, 32 * COUNT_FACTOR);
effect.setSelectRandomImage(true);
effect.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (float) (1f / COUNT_FACTOR_F)));
effect.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
effect.setStartSize(1.3f);
effect.setEndSize(2f);
effect.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
effect.setParticlesPerSec(0);
effect.setGravity(0, -5, 0);
effect.setLowLife(.4f);
effect.setHighLife(.5f);
effect.setInitialVelocity(new Vector3f(0, 7, 0));
effect.setVelocityVariation(1f);
effect.setImagesX(2);
effect.setImagesY(2);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
effect.setMaterial(mat);
// effect.setLocalScale(100);
rootNode.attachChild(effect);
}
Aggregations