use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.
the class TestCustomMesh method simpleInitApp.
@Override
public void simpleInitApp() {
Mesh m = new Mesh();
// Vertex positions in space
Vector3f[] vertices = new Vector3f[4];
vertices[0] = new Vector3f(0, 0, 0);
vertices[1] = new Vector3f(3, 0, 0);
vertices[2] = new Vector3f(0, 3, 0);
vertices[3] = new Vector3f(3, 3, 0);
// Texture coordinates
Vector2f[] texCoord = new Vector2f[4];
texCoord[0] = new Vector2f(0, 0);
texCoord[1] = new Vector2f(1, 0);
texCoord[2] = new Vector2f(0, 1);
texCoord[3] = new Vector2f(1, 1);
// Indexes. We define the order in which mesh should be constructed
short[] indexes = { 2, 0, 1, 1, 3, 2 };
// Setting buffers
m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
m.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
m.setBuffer(Type.Index, 1, BufferUtils.createShortBuffer(indexes));
m.updateBound();
// *************************************************************************
// First mesh uses one solid color
// *************************************************************************
// Creating a geometry, and apply a single color material to it
Geometry geom = new Geometry("OurMesh", m);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
// Attaching our geometry to the root node.
rootNode.attachChild(geom);
// *************************************************************************
// Second mesh uses vertex colors to color each vertex
// *************************************************************************
Mesh cMesh = m.clone();
Geometry coloredMesh = new Geometry("ColoredMesh", cMesh);
Material matVC = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matVC.setBoolean("VertexColor", true);
//We have 4 vertices and 4 color values for each of them.
//If you have more vertices, you need 'new float[yourVertexCount * 4]' here!
float[] colorArray = new float[4 * 4];
int colorIndex = 0;
//Set custom RGBA value for each Vertex. Values range from 0.0f to 1.0f
for (int i = 0; i < 4; i++) {
// Red value (is increased by .2 on each next vertex here)
colorArray[colorIndex++] = 0.1f + (.2f * i);
// Green value (is reduced by .2 on each next vertex)
colorArray[colorIndex++] = 0.9f - (0.2f * i);
// Blue value (remains the same in our case)
colorArray[colorIndex++] = 0.5f;
// Alpha value (no transparency set here)
colorArray[colorIndex++] = 1.0f;
}
// Set the color buffer
cMesh.setBuffer(Type.Color, 4, colorArray);
coloredMesh.setMaterial(matVC);
// move mesh a bit so that it doesn't intersect with the first one
coloredMesh.setLocalTranslation(4, 0, 0);
rootNode.attachChild(coloredMesh);
// /** Alternatively, you can show the mesh vertixes as points
// * instead of coloring the faces. */
// cMesh.setMode(Mesh.Mode.Points);
// cMesh.setPointSize(10f);
// cMesh.updateBound();
// cMesh.setStatic();
// Geometry points = new Geometry("Points", m);
// points.setMaterial(mat);
// rootNode.attachChild(points);
// *************************************************************************
// Third mesh will use a wireframe shader to show wireframe
// *************************************************************************
Mesh wfMesh = m.clone();
Geometry wfGeom = new Geometry("wireframeGeometry", wfMesh);
Material matWireframe = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matWireframe.setColor("Color", ColorRGBA.Green);
matWireframe.getAdditionalRenderState().setWireframe(true);
wfGeom.setMaterial(matWireframe);
wfGeom.setLocalTranslation(4, 4, 0);
rootNode.attachChild(wfGeom);
}
use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.
the class TestBloomAlphaThreshold method simpleInitApp.
@Override
public void simpleInitApp() {
// put the camera in a bad position
cam.setLocation(new Vector3f(-2.336393f, 11.91392f, -10));
cam.setRotation(new Quaternion(0.23602544f, 0.11321983f, -0.027698677f, 0.96473104f));
// cam.setFrustumFar(1000);
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat.setFloat("Shininess", 15f);
mat.setBoolean("UseMaterialColors", true);
mat.setColor("Ambient", ColorRGBA.Yellow.mult(0.2f));
mat.setColor("Diffuse", ColorRGBA.Yellow.mult(0.2f));
mat.setColor("Specular", ColorRGBA.Yellow.mult(0.8f));
mat.setColor("GlowColor", ColorRGBA.Green);
Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
matSoil.setFloat("Shininess", 15f);
matSoil.setBoolean("UseMaterialColors", true);
matSoil.setColor("Ambient", ColorRGBA.Gray);
matSoil.setColor("Diffuse", ColorRGBA.Black);
matSoil.setColor("Specular", ColorRGBA.Gray);
teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
teapot.setLocalTranslation(0, 0, 10);
teapot.setMaterial(mat);
teapot.setShadowMode(ShadowMode.CastAndReceive);
teapot.setLocalScale(10.0f);
rootNode.attachChild(teapot);
Geometry soil = new Geometry("soil", new Box(new Vector3f(0, -13, 550), 800, 10, 700));
soil.setMaterial(matSoil);
soil.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(soil);
Material matBox = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matBox.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
matBox.setFloat("AlphaDiscardThreshold", 0.5f);
Geometry box = new Geometry("box", new Box(new Vector3f(-3.5f, 10, -2), 2, 2, 2));
box.setMaterial(matBox);
box.setQueueBucket(RenderQueue.Bucket.Translucent);
// box.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(box);
DirectionalLight light = new DirectionalLight();
light.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
light.setColor(ColorRGBA.White.mult(1.5f));
rootNode.addLight(light);
// load sky
Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Bright/FullskiesBlueClear03.dds", false);
sky.setCullHint(Spatial.CullHint.Never);
rootNode.attachChild(sky);
fpp = new FilterPostProcessor(assetManager);
int numSamples = getContext().getSettings().getSamples();
if (numSamples > 0) {
fpp.setNumSamples(numSamples);
}
BloomFilter bloom = new BloomFilter(GlowMode.Objects);
bloom.setDownSamplingFactor(2);
bloom.setBlurScale(1.37f);
bloom.setExposurePower(3.30f);
bloom.setExposureCutOff(0.2f);
bloom.setBloomIntensity(2.45f);
BloomUI ui = new BloomUI(inputManager, bloom);
viewPort.addProcessor(fpp);
fpp.addFilter(bloom);
initInputs();
}
use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.
the class TestObjLoading method simpleInitApp.
public void simpleInitApp() {
// create the geometry and attach it
Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
// show normals as material
Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
teaGeom.setMaterial(mat);
rootNode.attachChild(teaGeom);
}
use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.
the class TestAnimBlendBug method simpleInitApp.
@Override
public void simpleInitApp() {
inputManager.addMapping("One", new KeyTrigger(KeyInput.KEY_1));
inputManager.addListener(this, "One");
flyCam.setMoveSpeed(100f);
cam.setLocation(new Vector3f(0f, 150f, -325f));
cam.lookAt(new Vector3f(0f, 100f, 0f), Vector3f.UNIT_Y);
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.1f, -0.7f, 1).normalizeLocal());
dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
rootNode.addLight(dl);
Node model1 = (Node) assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
Node model2 = (Node) assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
// Node model2 = model1.clone();
model1.setLocalTranslation(-60, 0, 0);
model2.setLocalTranslation(60, 0, 0);
AnimControl control1 = model1.getControl(AnimControl.class);
animNames = control1.getAnimationNames().toArray(new String[0]);
channel1 = control1.createChannel();
AnimControl control2 = model2.getControl(AnimControl.class);
channel2 = control2.createChannel();
SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton1", control1.getSkeleton());
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.getAdditionalRenderState().setWireframe(true);
mat.setColor("Color", ColorRGBA.Green);
mat.getAdditionalRenderState().setDepthTest(false);
skeletonDebug.setMaterial(mat);
model1.attachChild(skeletonDebug);
skeletonDebug = new SkeletonDebugger("skeleton2", control2.getSkeleton());
skeletonDebug.setMaterial(mat);
model2.attachChild(skeletonDebug);
rootNode.attachChild(model1);
rootNode.attachChild(model2);
}
use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.
the class TestCylinder method simpleInitApp.
@Override
public void simpleInitApp() {
Cylinder t = new Cylinder(20, 50, 1, 2, true);
Geometry geom = new Geometry("Cylinder", t);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
key.setGenerateMips(true);
Texture tex = assetManager.loadTexture(key);
tex.setMinFilter(Texture.MinFilter.Trilinear);
mat.setTexture("ColorMap", tex);
geom.setMaterial(mat);
rootNode.attachChild(geom);
}
Aggregations