use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.
the class HelloLoop method simpleInitApp.
@Override
public void simpleInitApp() {
/** this blue box is our player character */
Box b = new Box(1, 1, 1);
player = new Geometry("blue cube", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
player.setMaterial(mat);
rootNode.attachChild(player);
}
use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.
the class HelloMaterial method simpleInitApp.
@Override
public void simpleInitApp() {
/** A simple textured cube -- in good MIP map quality. */
Box cube1Mesh = new Box(1f, 1f, 1f);
Geometry cube1Geo = new Geometry("My Textured Box", cube1Mesh);
cube1Geo.setLocalTranslation(new Vector3f(-3f, 1.1f, 0f));
Material cube1Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture cube1Tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
cube1Mat.setTexture("ColorMap", cube1Tex);
cube1Geo.setMaterial(cube1Mat);
rootNode.attachChild(cube1Geo);
/** A translucent/transparent texture, similar to a window frame. */
Box cube2Mesh = new Box(1f, 1f, 0.01f);
Geometry cube2Geo = new Geometry("window frame", cube2Mesh);
Material cube2Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
cube2Mat.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
// activate transparency
cube2Mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
cube2Geo.setQueueBucket(Bucket.Transparent);
cube2Geo.setMaterial(cube2Mat);
rootNode.attachChild(cube2Geo);
/** A bumpy rock with a shiny light effect. To make bumpy objects you must create a NormalMap. */
Sphere sphereMesh = new Sphere(32, 32, 2f);
Geometry sphereGeo = new Geometry("Shiny rock", sphereMesh);
// better quality on spheres
sphereMesh.setTextureMode(Sphere.TextureMode.Projected);
// for lighting effect
TangentBinormalGenerator.generate(sphereMesh);
Material sphereMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
sphereMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
sphereMat.setTexture("NormalMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
sphereMat.setBoolean("UseMaterialColors", true);
sphereMat.setColor("Diffuse", ColorRGBA.White);
sphereMat.setColor("Specular", ColorRGBA.White);
// [0,128]
sphereMat.setFloat("Shininess", 64f);
sphereGeo.setMaterial(sphereMat);
//sphereGeo.setMaterial((Material) assetManager.loadMaterial("Materials/MyCustomMaterial.j3m"));
// Move it a bit
sphereGeo.setLocalTranslation(0, 2, -2);
// Rotate it a bit
sphereGeo.rotate(1.6f, 0, 0);
rootNode.attachChild(sphereGeo);
/** Must add a light to make the lit object visible! */
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(1, 0, -2).normalizeLocal());
sun.setColor(ColorRGBA.White);
rootNode.addLight(sun);
}
use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.
the class HelloPhysics method initFloor.
/** Make a solid floor and add it to the scene. */
public void initFloor() {
Geometry floor_geo = new Geometry("Floor", floor);
floor_geo.setMaterial(floor_mat);
floor_geo.setLocalTranslation(0, -0.1f, 0);
this.rootNode.attachChild(floor_geo);
/* Make the floor physical with mass 0.0f! */
floor_phy = new RigidBodyControl(0.0f);
floor_geo.addControl(floor_phy);
bulletAppState.getPhysicsSpace().add(floor_phy);
}
use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.
the class TestTangentGen method addMesh.
private void addMesh(String name, Mesh mesh, Vector3f translation) {
TangentBinormalGenerator.generate(mesh);
Geometry testGeom = new Geometry(name, mesh);
Material mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m");
testGeom.setMaterial(mat);
testGeom.getLocalTranslation().set(translation);
rootNode.attachChild(testGeom);
Geometry debug = new Geometry("Debug " + name, TangentBinormalGenerator.genTbnLines(mesh, 0.08f));
Material debugMat = assetManager.loadMaterial("Common/Materials/VertexColor.j3m");
debug.setMaterial(debugMat);
debug.setCullHint(Spatial.CullHint.Never);
debug.getLocalTranslation().set(translation);
rootNode.attachChild(debug);
}
use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.
the class TestTangentSpace method simpleInitApp.
@Override
public void simpleInitApp() {
renderManager.setSinglePassLightBatchSize(2);
renderManager.setPreferredLightMode(TechniqueDef.LightMode.SinglePass);
initView();
Spatial s = assetManager.loadModel("Models/Test/BasicCubeLow.obj");
rootNode.attachChild(s);
Material m = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
m.setTexture("NormalMap", assetManager.loadTexture("Models/Test/Normal_pixel.png"));
Geometry g = (Geometry) s;
Geometry g2 = (Geometry) g.deepClone();
g2.move(5, 0, 0);
g.getParent().attachChild(g2);
g.setMaterial(m);
g2.setMaterial(m);
//Regular tangent generation (left geom)
TangentBinormalGenerator.generate(g2.getMesh(), true);
//MikkTSPace Tangent generation (right geom)
MikktspaceTangentGenerator.generate(g);
createDebugTangents(g2);
createDebugTangents(g);
inputManager.addListener(new ActionListener() {
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("toggleDebug") && isPressed) {
if (debugNode.getParent() == null) {
rootNode.attachChild(debugNode);
} else {
debugNode.removeFromParent();
}
}
}
}, "toggleDebug");
inputManager.addMapping("toggleDebug", new KeyTrigger(KeyInput.KEY_SPACE));
DirectionalLight dl = new DirectionalLight(new Vector3f(-1, -1, -1).normalizeLocal());
rootNode.addLight(dl);
}
Aggregations