private void createTerrain() { // First, we load up our textures and the heightmap texture for the terrain // TERRAIN TEXTURE material matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md"); matTerrain.setBoolean("useTriPlanarMapping", false); matTerrain.setBoolean("WardIso", true); matTerrain.setFloat("Shininess", 0); // ALPHA map (for splat textures) matTerrain.setTexture( "AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png")); // GRASS texture Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg"); grass.setWrap(WrapMode.Repeat); matTerrain.setTexture("DiffuseMap", grass); matTerrain.setFloat("DiffuseMap_0_scale", grassScale); // DIRT texture Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg"); dirt.setWrap(WrapMode.Repeat); matTerrain.setTexture("DiffuseMap_1", dirt); matTerrain.setFloat("DiffuseMap_1_scale", dirtScale); // ROCK texture Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg"); rock.setWrap(WrapMode.Repeat); matTerrain.setTexture("DiffuseMap_2", rock); matTerrain.setFloat("DiffuseMap_2_scale", rockScale); // HEIGHTMAP image (for the terrain heightmap) Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png"); AbstractHeightMap heightmap = null; try { heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.5f); heightmap.load(); heightmap.smooth(0.9f, 1); } catch (Exception e) { e.printStackTrace(); } // CREATE THE TERRAIN terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap()); TerrainLodControl control = new TerrainLodControl(terrain, getCamera()); control.setLodCalculator(new DistanceLodCalculator(65, 2.7f)); // patch size, and a multiplier terrain.addControl(control); terrain.setMaterial(matTerrain); terrain.setLocalTranslation(0, -100, 0); terrain.setLocalScale(2.5f, 0.5f, 2.5f); rootNode.attachChild(terrain); }
public RenderDeviceJme(NiftyJmeDisplay display) { this.display = display; quadColor = new VertexBuffer(Type.Color); quadColor.setNormalized(true); ByteBuffer bb = BufferUtils.createByteBuffer(4 * 4); quadColor.setupData(Usage.Stream, 4, Format.UnsignedByte, bb); quad.setBuffer(quadColor); quadModTC.setUsage(Usage.Stream); // Load the 3 material types separately to avoid // reloading the shader when the defines change. // Material with a single color (no texture or vertex color) colorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); // Material with a texture and a color (no vertex color) textureColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); // Material with vertex color, used for gradients (no texture) vertexColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); vertexColorMaterial.setBoolean("VertexColor", true); // Shared render state for all materials renderState.setDepthTest(false); renderState.setDepthWrite(false); }
public void makeToonish(Spatial spatial) { if (spatial instanceof Node) { Node n = (Node) spatial; for (Spatial child : n.getChildren()) makeToonish(child); } else if (spatial instanceof Geometry) { Geometry g = (Geometry) spatial; Material m = g.getMaterial(); if (m.getMaterialDef().getName().equals("Phong Lighting")) { Texture t = assetManager.loadTexture("Textures/ColorRamp/toon.png"); // t.setMinFilter(Texture.MinFilter.NearestNoMipMaps); // t.setMagFilter(Texture.MagFilter.Nearest); m.setTexture("ColorRamp", t); m.setBoolean("UseMaterialColors", true); m.setColor("Specular", ColorRGBA.Black); m.setColor("Diffuse", ColorRGBA.White); m.setBoolean("VertexLighting", true); } } }
private Material getMaterial(ColorRGBA color) { Material mat = new Material(main.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md"); mat.setColor("Diffuse", color); ColorRGBA clone = color.clone(); clone.multLocal(0.8f); clone.a = 1f; mat.setColor("Ambient", clone); mat.setBoolean("UseMaterialColors", true); return mat; }
@Override public void simpleInitApp() { Sphere sphereMesh = new Sphere(32, 32, 1f); Geometry spherePlainGeo = new Geometry("rough sphere", sphereMesh); Material spherePlainMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); spherePlainMat.setFloat("Shininess", 0f); // [1,128] spherePlainMat.setBoolean("UseMaterialColors", true); spherePlainMat.setColor("Ambient", ColorRGBA.Black); spherePlainMat.setColor("Diffuse", ColorRGBA.Cyan); spherePlainMat.setColor("Specular", ColorRGBA.White); spherePlainGeo.setMaterial(spherePlainMat); spherePlainGeo.move(-2.5f, 0, 0); rootNode.attachChild(spherePlainGeo); Geometry sphereShinyGeo = new Geometry("normal sphere", sphereMesh); Material sphereShinyMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); sphereShinyMat.setBoolean("UseMaterialColors", true); sphereShinyMat.setColor("Ambient", ColorRGBA.Black); sphereShinyMat.setColor("Diffuse", ColorRGBA.Cyan); sphereShinyMat.setColor("Specular", ColorRGBA.White); sphereShinyMat.setFloat("Shininess", 4f); // [1,128] sphereShinyGeo.setMaterial(sphereShinyMat); rootNode.attachChild(sphereShinyGeo); Geometry sphereVeryShinyGeo = new Geometry("Smooth sphere", sphereMesh); Material sphereVeryShinyMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); sphereVeryShinyMat.setBoolean("UseMaterialColors", true); sphereVeryShinyMat.setColor("Ambient", ColorRGBA.Black); sphereVeryShinyMat.setColor("Diffuse", ColorRGBA.Cyan); sphereVeryShinyMat.setColor("Specular", ColorRGBA.White); sphereVeryShinyMat.setFloat("Shininess", 100f); // [1,128] sphereVeryShinyGeo.setMaterial(sphereVeryShinyMat); sphereVeryShinyGeo.move(2.5f, 0, 0); rootNode.attachChild(sphereVeryShinyGeo); /** Must add a light to make the lit object visible! */ DirectionalLight sun = new DirectionalLight(); sun.setDirection(new Vector3f(1, 0, -2)); sun.setColor(ColorRGBA.White); rootNode.addLight(sun); }
/** * Generates a new, basic material for use in the jME3 app. * * @param color The color of the material. * @return A jME3 Material using Lighting.j3md. */ public Material createLitMaterial(ColorRGBA color) { Material material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); material.setBoolean("UseMaterialColors", true); material.setColor("Diffuse", color); material.setFloat("Shininess", 12f); material.setColor("Specular", ColorRGBA.White); material.setColor("Ambient", ColorRGBA.LightGray); material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); return material; }
public static Material getLightingColor(ColorRGBA color) { // We first check if the requested color exist in the map if (colorsMap.containsKey(color)) { return colorsMap.get(color); } // At this point, we know that the color doesn't exist. // We must create a new material, add it to the map and return it. Material res = new Material(am, "Common/MatDefs/Light/Lighting.j3md"); res.setColor("Diffuse", color); res.setFloat("Shininess", 10f); res.setBoolean("UseMaterialColors", true); colorsMap.put(color, res); return res; }
private void setMatParams() { GeometryList l = viewPort.getQueue().getShadowQueueContent(ShadowMode.Receive); // iteration throught all the geometries of the list to gather the materials matCache.clear(); for (int i = 0; i < l.size(); i++) { Material mat = l.get(i).getMaterial(); // checking if the material has the post technique and adding it to the material cache if (mat.getMaterialDef().getTechniqueDef(postTechniqueName) != null) { if (!matCache.contains(mat)) { matCache.add(mat); } } else { needsfallBackMaterial = true; } } // iterating through the mat cache and setting the parameters for (Material mat : matCache) { mat.setFloat("ShadowMapSize", shadowMapSize); for (int j = 0; j < nbShadowMaps; j++) { mat.setMatrix4("LightViewProjectionMatrix" + j, lightViewProjectionsMatrices[j]); } for (int j = 0; j < nbShadowMaps; j++) { mat.setTexture("ShadowMap" + j, shadowMaps[j]); } mat.setBoolean("HardwareShadows", shadowCompareMode == CompareMode.Hardware); mat.setInt("FilterMode", edgeFilteringMode.getMaterialParamValue()); mat.setFloat("PCFEdge", edgesThickness); mat.setFloat("ShadowIntensity", shadowIntensity); setMaterialParameters(mat); } // At least one material of the receiving geoms does not support the post shadow techniques // so we fall back to the forced material solution (transparent shadows won't be supported for // these objects) if (needsfallBackMaterial) { setPostShadowParams(); } }
protected void createMaterial() { Material material; if (alpha < 1f && transparent) { diffuse.a = alpha; } if (shadeless) { material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); material.setColor("Color", diffuse.clone()); material.setTexture("ColorMap", diffuseMap); // TODO: Add handling for alpha map? } else { material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); material.setBoolean("UseMaterialColors", true); material.setColor("Ambient", ambient.clone()); material.setColor("Diffuse", diffuse.clone()); material.setColor("Specular", specular.clone()); material.setFloat("Shininess", shininess); // prevents "premature culling" bug if (diffuseMap != null) material.setTexture("DiffuseMap", diffuseMap); if (specularMap != null) material.setTexture("SpecularMap", specularMap); if (normalMap != null) material.setTexture("NormalMap", normalMap); if (alphaMap != null) material.setTexture("AlphaMap", alphaMap); } if (transparent) { material.setTransparent(true); material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); material.getAdditionalRenderState().setAlphaTest(true); material.getAdditionalRenderState().setAlphaFallOff(0.01f); } material.setName(matName); matList.put(matName, material); }
/** * sets the shadow compare mode see {@link CompareMode} for more info * * @param compareMode */ public final void setShadowCompareMode(CompareMode compareMode) { if (compareMode == null) { throw new IllegalArgumentException("Shadow compare mode cannot be null"); } this.shadowCompareMode = compareMode; for (Texture2D shadowMap : shadowMaps) { if (compareMode == CompareMode.Hardware) { shadowMap.setShadowCompareMode(ShadowCompareMode.LessOrEqual); if (edgeFilteringMode == EdgeFilteringMode.Bilinear) { shadowMap.setMagFilter(MagFilter.Bilinear); shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps); } else { shadowMap.setMagFilter(MagFilter.Nearest); shadowMap.setMinFilter(MinFilter.NearestNoMipMaps); } } else { shadowMap.setShadowCompareMode(ShadowCompareMode.Off); shadowMap.setMagFilter(MagFilter.Nearest); shadowMap.setMinFilter(MinFilter.NearestNoMipMaps); } } postshadowMat.setBoolean("HardwareShadows", compareMode == CompareMode.Hardware); }
private static void initBaseMaterials() { ColorRGBA lotColorBase = new ColorRGBA(200f / 255f, 200f / 255f, 200f / 255f, 255f / 255f); ColorRGBA concreteColor = new ColorRGBA(90f / 255f, 100f / 255f, 255f / 255f, 255f / 255f); ColorRGBA redConcreteColor = ColorRGBA.Red; ColorRGBA blueConcreteColor = ColorRGBA.Blue; ColorRGBA yellowConcreteColor = ColorRGBA.Yellow; ColorRGBA cyanConcreteColor = new ColorRGBA(0, 1, 1, 0.4f); ColorRGBA blackConcreteColor = ColorRGBA.Black; ColorRGBA greenConcreteColor = ColorRGBA.Green; ColorRGBA floorColor = ColorRGBA.Gray; ColorRGBA windowsColor = ColorRGBA.White; ColorRGBA itemColor = ColorRGBA.LightGray; ColorRGBA roadsColor = ColorRGBA.LightGray; ColorRGBA terrainColor = new ColorRGBA(0f / 255f, 50f / 255f, 14f / 255f, 255f / 255f); am.registerLocator("assets/", FileLocator.class.getName()); contourMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); contourMaterial.setColor("Color", blackConcreteColor); blockContourMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); blockContourMaterial.setColor("Color", redConcreteColor); lotContourMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); lotContourMaterial.setColor("Color", blueConcreteColor); lotMaterial1 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); lotMaterial1.setColor("Color", lotColorBase); lotMaterial2 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); lotMaterial2.setColor("Color", lotColorBase); lotMaterial3 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); lotMaterial3.setColor("Color", lotColorBase); // debug material debugMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); debugMaterial.setColor("Color", redConcreteColor); // debug texture material // debugTextureMaterial = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md"); // debugTextureMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); // debugTextureMaterial.setTexture("DiffuseMap", // assetManager.loadTexture("Textures/UVTest.jpg")); // debugTextureMaterial.setFloat("Shininess", 128f); // [0,128] // Red Material redMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); redMaterial.setColor("Color", redConcreteColor); redMaterial.setColor("GlowColor", redConcreteColor); // Concrete Material yellowMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); yellowMaterial.setColor("Color", yellowConcreteColor); // Concrete Material cyanMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); cyanMaterial.setColor("Color", cyanConcreteColor); cyanMaterial.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); // Concrete Material blackMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); blackMaterial.setColor("Color", blackConcreteColor); // Concrete Material greenMaterial = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); greenMaterial.setColor("Color", greenConcreteColor); greenMaterial.setColor("GlowColor", greenConcreteColor); // Item Material itemMaterial = new Material(am, "Common/MatDefs/Light/Lighting.j3md"); itemMaterial.setColor("Diffuse", itemColor); itemMaterial.setBoolean("UseMaterialColors", true); // gradient blue for (int i = 0; i < 4; i++) { gradientMaterial.add(new Material(am, "Common/MatDefs/Misc/Unshaded.j3md")); gradientMaterial .get(i) .setColor("Color", new ColorRGBA(i * 30 / 255f, i * 30 / 255f, i * 85 / 255f, 1)); } }
@Override public void simpleInitApp() { viewPort.setBackgroundColor(ColorRGBA.White); flyCam.setMoveSpeed(50); /** A simple textured sphere */ Sphere sphereMesh = new Sphere(16, 16, 1); Geometry sphereGeo = new Geometry("lit textured sphere", sphereMesh); Material sphereMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); sphereMat.setTexture("DiffuseMap", assetManager.loadTexture("Interface/Monkey.png")); sphereMat.setBoolean("UseMaterialColors", true); sphereMat.setColor("Diffuse", ColorRGBA.Gray); sphereMat.setColor("Ambient", ColorRGBA.Gray); // alpha test start sphereMat.getAdditionalRenderState().setAlphaTest(true); sphereMat.getAdditionalRenderState().setAlphaFallOff(.5f); sphereGeo.setQueueBucket(Bucket.Transparent); // alpha test end sphereGeo.setMaterial(sphereMat); sphereGeo.move(-2f, 0f, 0f); sphereGeo.rotate(FastMath.DEG_TO_RAD * -90, FastMath.DEG_TO_RAD * 120, 0f); rootNode.attachChild(sphereGeo); /** * This material turns the box into a stained glass window. The texture has an alpha channel and * is partially transparent. */ Box windowMesh = new Box(new Vector3f(0f, 0f, 0f), 1f, 1.4f, 0.01f); Geometry windowGeo = new Geometry("stained glass window", windowMesh); Material windowMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); windowMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/mucha-window.png")); windowMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); windowGeo.setMaterial(windowMat); windowGeo.setQueueBucket(Bucket.Transparent); windowGeo.setMaterial(windowMat); windowGeo.move(1, 0, 0); rootNode.attachChild(windowGeo); /** * A box with its material color "bleeding" through. The texture has an alpha channel and is * partially transparent. */ Cylinder logMesh = new Cylinder(32, 32, 1, 8, true); TangentBinormalGenerator.generate(logMesh); Geometry logGeo = new Geometry("Bleed-through color", logMesh); Material logMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); logMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Bark/bark_diffuse.png")); logMat.setTexture("NormalMap", assetManager.loadTexture("Textures/Bark/bark_normal.png")); logMat.setBoolean("UseMaterialColors", true); logMat.setColor("Diffuse", ColorRGBA.Orange); logMat.setColor("Ambient", ColorRGBA.Gray); logMat.setBoolean("UseAlpha", true); logGeo.setMaterial(logMat); logGeo.move(0f, 0f, -2f); logGeo.rotate(0f, FastMath.DEG_TO_RAD * 90, 0f); rootNode.attachChild(logGeo); /** 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); AmbientLight ambient = new AmbientLight(); ambient.setColor(ColorRGBA.White); rootNode.addLight(ambient); }
@Override public void simpleInitApp() { setDisplayFps(false); setDisplayStatView(false); bap = new BulletAppState(); stateManager.attach(bap); bap.getPhysicsSpace().setGravity(Vector3f.ZERO); bap.getPhysicsSpace().addCollisionListener(this); guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt"); showText = new BitmapText(guiFont, false); showText.setSize(50); showText.setColor(ColorRGBA.Red); showText.setLocalTranslation((settings.getWidth() / 2) - 200, settings.getHeight() / 2, 0); score = 0; scoreText = new BitmapText(guiFont, false); scoreText.setSize(guiFont.getCharSet().getRenderedSize()); scoreText.setColor(ColorRGBA.White); scoreText.setText("Score: " + score); scoreText.setLocalTranslation(settings.getWidth() - 200, settings.getHeight() - 30, 0); guiNode.attachChild(scoreText); lives = 3; /* livespic = new Picture[lives]; for(int i=0; i < lives; i++){ livespic[i] = new Picture("Live "+i); livespic[i].setImage(assetManager, "Textures/LifeLogo.png", true); livespic[i].setWidth(50); livespic[i].setHeight(50); livespic[i].setPosition(i*50, settings.getHeight()-50); guiNode.attachChild(livespic[i]); } * */ planets = new Planet[9]; Material mat10 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat10.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Sun.jpg")); mat10.setTexture("GlowMap", assetManager.loadTexture("Textures/Sun.jpg")); mat10.setColor("Specular", ColorRGBA.White); mat10.setBoolean("UseAlpha", true); sun = new Planet("Sun", 5f, mat10); sun.registerPhysics(bap.getPhysicsSpace()); rootNode.attachChild(sun); Material mat1 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat1.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Mercury.jpg")); mat1.setColor("Specular", ColorRGBA.White); mercury = new Planet("Mercury", 2f, mat1); mercury.setInitLocation(new Vector3f(16.0f, 0f, -6.0f)); mercury.setRotationSpeed((float) Math.random()); mercury.setTranslationSpeed(0.76f); mercury.registerPhysics(bap.getPhysicsSpace()); planets[0] = mercury; rootNode.attachChild(mercury); Material mat2 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat2.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Venus.jpg")); mat2.setColor("Specular", ColorRGBA.White); venus = new Planet("Venus", 2.6f, mat2); venus.setInitLocation(new Vector3f(23.0f, 0f, -6.0f)); venus.setRotationSpeed((float) Math.random()); venus.setTranslationSpeed(0.65f); venus.registerPhysics(bap.getPhysicsSpace()); planets[1] = venus; rootNode.attachChild(venus); Material mat3 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat3.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Earth/Color.jpg")); mat3.setTexture("ParallaxMap", assetManager.loadTexture("Textures/Earth/Bump.jpg")); mat3.setTexture("SpecularMap", assetManager.loadTexture("Textures/Earth/Specular.jpg")); earth = new Planet("Earth", 2.7f, mat3); earth.setInitLocation(new Vector3f(31.0f, 0f, -6.0f)); earth.setRotationSpeed((float) Math.random()); earth.setTranslationSpeed(0.6f); earth.registerPhysics(bap.getPhysicsSpace()); planets[2] = earth; rootNode.attachChild(earth); Material mat4 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat4.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Mars.jpg")); mat4.setColor("Specular", ColorRGBA.White); mars = new Planet("Mars", 2.5f, mat4); mars.setInitLocation(new Vector3f(40.0f, 0f, -6.0f)); mars.setRotationSpeed((float) Math.random()); mars.setTranslationSpeed(0.56f); mars.registerPhysics(bap.getPhysicsSpace()); planets[3] = mars; rootNode.attachChild(mars); Material mat5 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat5.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Jupiter.jpg")); mat5.setColor("Specular", ColorRGBA.White); jupiter = new Planet("Jupiter", 3.1f, mat5); jupiter.setInitLocation(new Vector3f(49.0f, 0f, -6.0f)); jupiter.setRotationSpeed((float) Math.random()); jupiter.setTranslationSpeed(0.5f); jupiter.registerPhysics(bap.getPhysicsSpace()); planets[4] = jupiter; rootNode.attachChild(jupiter); Material mat6 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat6.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Saturn.jpg")); mat6.setColor("Specular", ColorRGBA.White); saturn = new Planet("Saturn", 2.9f, mat6); saturn.setInitLocation(new Vector3f(57.0f, 0f, -6.0f)); saturn.setRotationSpeed((float) Math.random()); saturn.setTranslationSpeed(0.44f); saturn.registerPhysics(bap.getPhysicsSpace()); planets[5] = saturn; rootNode.attachChild(saturn); Material mat7 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat7.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Uranus.jpg")); mat7.setColor("Specular", ColorRGBA.White); uranus = new Planet("Uranus", 2.8f, mat7); uranus.setInitLocation(new Vector3f(65.0f, 0f, -6.0f)); uranus.setRotationSpeed((float) Math.random()); uranus.setTranslationSpeed(0.4f); uranus.registerPhysics(bap.getPhysicsSpace()); planets[6] = uranus; rootNode.attachChild(uranus); Material mat8 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat8.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Neptune.jpg")); mat8.setColor("Specular", ColorRGBA.White); neptune = new Planet("Neptune", 2.65f, mat8); neptune.setInitLocation(new Vector3f(75.0f, 0f, -6.0f)); neptune.setRotationSpeed((float) Math.random()); neptune.setTranslationSpeed(0.34f); neptune.registerPhysics(bap.getPhysicsSpace()); planets[7] = neptune; rootNode.attachChild(neptune); Material mat9 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat9.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Pluto.jpg")); mat9.setColor("Specular", ColorRGBA.White); pluto = new Planet("Pluto", 1.5f, mat9); pluto.setInitLocation(new Vector3f(82.0f, 0f, -6.0f)); pluto.setRotationSpeed((float) Math.random()); pluto.setTranslationSpeed(0.2f); pluto.registerPhysics(bap.getPhysicsSpace()); planets[8] = pluto; rootNode.attachChild(pluto); spaceship = new Spaceship("Spaceship", assetManager.loadModel("Models/X-WING/X-WING.j3o")); spaceship.addTurbines( new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"), assetManager.loadTexture("Effects/Explosion/flame.png")); spaceship.setLocalTranslation(0, 20, 40); spaceship.getModel().scale(0.1f); spaceship.registerPhysics(bap.getPhysicsSpace()); rootNode.attachChild(spaceship); Material laserMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); laserMaterial.setColor("GlowColor", ColorRGBA.Green); laserMaterial.setColor("Ambient", ColorRGBA.Green); laserMaterial.setColor("Diffuse", ColorRGBA.Green); laserMaterial.setBoolean("UseMaterialColors", true); spaceship.setLaserMaterial(laserMaterial); lasers = new Node("Lasers"); rootNode.attachChild(lasers); flyCam.setEnabled(false); cam.setLocation(spaceship.getRear().getWorldTranslation()); cam.lookAt(spaceship.getFront().getWorldTranslation(), Vector3f.UNIT_Y); PointLight sunLight = new PointLight(); sunLight.setColor(ColorRGBA.White); sunLight.setPosition(new Vector3f(0f, 0f, 0f)); sunLight.setRadius(100f); rootNode.addLight(sunLight); AmbientLight ambient = new AmbientLight(); rootNode.addLight(ambient); fpp = new FilterPostProcessor(assetManager); bloom = new BloomFilter(BloomFilter.GlowMode.Objects); bloom.setExposurePower(30f); bloom.setBloomIntensity(1f); fpp.addFilter(bloom); viewPort.addProcessor(fpp); rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Stars5.jpeg", true)); bloomDirection = 1; noComet = 1; moving = up = down = left = right = leftSide = rightSide = false; asteroids = new Node("Asteroids"); rootNode.attachChild(asteroids); explosions = new Node("Explosions"); rootNode.attachChild(explosions); initKeys(); initAudio(); }
public void read(JmeImporter im) throws IOException { InputCapsule ic = im.getCapsule(this); additionalState = (RenderState) ic.readSavable("render_state", null); transparent = ic.readBoolean("is_transparent", false); // Load the material def String defName = ic.readString("material_def", null); HashMap<String, MatParam> params = (HashMap<String, MatParam>) ic.readStringSavableMap("parameters", null); boolean enableVcolor = false; boolean separateTexCoord = false; boolean applyDefaultValues = false; boolean guessRenderStateApply = false; int ver = ic.getSavableVersion(Material.class); if (ver < 1) { applyDefaultValues = true; } if (ver < 2) { guessRenderStateApply = true; } if (im.getFormatVersion() == 0) { // Enable compatibility with old models if (defName.equalsIgnoreCase("Common/MatDefs/Misc/VertexColor.j3md")) { // Using VertexColor, switch to Unshaded and set VertexColor=true enableVcolor = true; defName = "Common/MatDefs/Misc/Unshaded.j3md"; } else if (defName.equalsIgnoreCase("Common/MatDefs/Misc/SimpleTextured.j3md") || defName.equalsIgnoreCase("Common/MatDefs/Misc/SolidColor.j3md")) { // Using SimpleTextured/SolidColor, just switch to Unshaded defName = "Common/MatDefs/Misc/Unshaded.j3md"; } else if (defName.equalsIgnoreCase("Common/MatDefs/Misc/WireColor.j3md")) { // Using WireColor, set wireframe renderstate = true and use Unshaded getAdditionalRenderState().setWireframe(true); defName = "Common/MatDefs/Misc/Unshaded.j3md"; } else if (defName.equalsIgnoreCase("Common/MatDefs/Misc/Unshaded.j3md")) { // Uses unshaded, ensure that the proper param is set MatParam value = params.get("SeperateTexCoord"); if (value != null && ((Boolean) value.getValue()) == true) { params.remove("SeperateTexCoord"); separateTexCoord = true; } } assert applyDefaultValues && guessRenderStateApply; } def = (MaterialDef) im.getAssetManager().loadAsset(new AssetKey(defName)); paramValues = new ListMap<String, MatParam>(); // load the textures and update nextTexUnit for (Map.Entry<String, MatParam> entry : params.entrySet()) { MatParam param = entry.getValue(); if (param instanceof MatParamTexture) { MatParamTexture texVal = (MatParamTexture) param; if (nextTexUnit < texVal.getUnit() + 1) { nextTexUnit = texVal.getUnit() + 1; } // the texture failed to load for this param // do not add to param values if (texVal.getTextureValue() == null || texVal.getTextureValue().getImage() == null) { continue; } } if (im.getFormatVersion() == 0 && param.getName().startsWith("m_")) { // Ancient version of jME3 ... param.setName(param.getName().substring(2)); } checkSetParam(param.getVarType(), param.getName()); paramValues.put(param.getName(), param); } if (applyDefaultValues) { // compatability with old versions where default vars were // not available for (MatParam param : def.getMaterialParams()) { if (param.getValue() != null && paramValues.get(param.getName()) == null) { setParam(param.getName(), param.getVarType(), param.getValue()); } } } if (guessRenderStateApply && additionalState != null) { // Try to guess values of "apply" render state based on defaults // if value != default then set apply to true additionalState.applyPolyOffset = additionalState.offsetEnabled; additionalState.applyAlphaFallOff = additionalState.alphaTest; additionalState.applyAlphaTest = additionalState.alphaTest; additionalState.applyBlendMode = additionalState.blendMode != BlendMode.Off; additionalState.applyColorWrite = !additionalState.colorWrite; additionalState.applyCullMode = additionalState.cullMode != FaceCullMode.Back; additionalState.applyDepthTest = !additionalState.depthTest; additionalState.applyDepthWrite = !additionalState.depthWrite; additionalState.applyPointSprite = additionalState.pointSprite; additionalState.applyStencilTest = additionalState.stencilTest; additionalState.applyWireFrame = additionalState.wireframe; } if (enableVcolor) { setBoolean("VertexColor", true); } if (separateTexCoord) { setBoolean("SeparateTexCoord", true); } }