material.setBoolean("LowQuality", true);
material.setTexture("DiffuseMap", texture);
} else {
- material = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setTexture("ColorMap", texture);
}
} else {
- material = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
+ material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setColor("Color", ColorRGBA.Red);
}
*/\r
public synchronized Material getDefaultMaterial() {\r
if(blenderKey.getDefaultMaterial() == null) {\r
- Material defaultMaterial = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");\r
+ Material defaultMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");\r
defaultMaterial.setColor("Color", ColorRGBA.DarkGray);\r
blenderKey.setDefaultMaterial(defaultMaterial);\r
}\r
* @param manager AssetManager to load the default wireframe material for the debug shape
*/
protected Spatial attachDebugShape(AssetManager manager) {
- debugMaterialBlue = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
+ debugMaterialBlue = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
+ debugMaterialBlue.getAdditionalRenderState().setWireframe(true);
debugMaterialBlue.setColor("Color", ColorRGBA.Blue);
- debugMaterialGreen = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
+ debugMaterialGreen = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
+ debugMaterialGreen.getAdditionalRenderState().setWireframe(true);
debugMaterialGreen.setColor("Color", ColorRGBA.Green);
- debugMaterialRed = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
+ debugMaterialRed = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
+ debugMaterialRed.getAdditionalRenderState().setWireframe(true);
debugMaterialRed.setColor("Color", ColorRGBA.Red);
- debugMaterialYellow = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
+ debugMaterialYellow = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
+ debugMaterialYellow.getAdditionalRenderState().setWireframe(true);
debugMaterialYellow.setColor("Color", ColorRGBA.Yellow);
debugArrow = new Arrow(Vector3f.UNIT_XYZ);
debugArrowGeom = new Geometry("DebugArrow", debugArrow);
\r
\r
void main(){\r
- \r
#ifdef HAS_GLOWMAP\r
#if defined(NEED_TEXCOORD1) \r
gl_FragColor = texture2D(m_GlowMap, texCoord1);\r
+Exception SimpleTextured.j3md has been marked as obsolete. Please use Unshaded.j3md instead.\r
+\r
MaterialDef Plain Texture {\r
\r
MaterialParameters {\r
+Exception SolidColor.j3md has been marked as obsolete. Please use Unshaded.j3md instead.\r
+\r
MaterialDef Solid Color {\r
\r
MaterialParameters {\r
+Exception VertexColor.j3md has been marked as obsolete. Please use Unshaded.j3md instead.\r
+\r
MaterialDef Vertex Color {\r
\r
Technique {\r
+Exception WireColor.j3md has been marked as obsolete. Please use Unshaded.j3md instead.\r
+\r
MaterialDef Wire Color {\r
\r
MaterialParameters {\r
import com.jme3.asset.AssetInfo;
import com.jme3.asset.AssetKey;
+import com.jme3.asset.AssetLoadException;
import com.jme3.material.*;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
extending = true;
}else if (word.equals("MaterialDef")){
extending = false;
+ }else if (word.equals("Exception")){
+ String exception = scan.nextLine();
+ throw new AssetLoadException(exception);
}else{
throw new IOException("Specified file is not a Material file");
}
private Geometry CreateLinearPath() {
- Material mat = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
+ Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
+ mat.getAdditionalRenderState().setWireframe(true);
mat.setColor("Color", ColorRGBA.Blue);
Geometry lineGeometry = new Geometry("line", new Curve(spline, 0));
lineGeometry.setMaterial(mat);
private Geometry CreateCatmullRomPath() {
- Material mat = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
+ Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
+ mat.getAdditionalRenderState().setWireframe(true);
mat.setColor("Color", ColorRGBA.Blue);
Geometry lineGeometry = new Geometry("line", new Curve(spline, 10));
lineGeometry.setMaterial(mat);
import com.jme3.export.OutputCapsule;\r
import com.jme3.export.Savable;\r
import com.jme3.material.Material;\r
-import com.jme3.shader.VarType;\r
-import com.jme3.texture.Texture;\r
\r
/**\r
* Represents a font within jME that is generated with the AngelCode Bitmap Font Generator\r
*
* Same as GL_SHININESS for OpenGL.
*/
- Shininess
+ MaterialShininess
}
--- /dev/null
+package com.jme3.material;
+
+import com.jme3.export.InputCapsule;
+import com.jme3.export.JmeExporter;
+import com.jme3.export.JmeImporter;
+import com.jme3.export.OutputCapsule;
+import com.jme3.renderer.Renderer;
+import com.jme3.shader.VarType;
+import com.jme3.texture.Texture;
+import java.io.IOException;
+
+public class MatParamTexture extends MatParam {
+
+ private Texture texture;
+ private int unit;
+
+ public MatParamTexture(VarType type, String name, Texture texture, int unit) {
+ super(type, name, texture, null);
+ this.texture = texture;
+ this.unit = unit;
+ }
+
+ public MatParamTexture() {
+ }
+
+ public Texture getTextureValue() {
+ return texture;
+ }
+
+ public void setTextureValue(Texture value) {
+ this.value = value;
+ this.texture = value;
+ }
+
+ public void setUnit(int unit) {
+ this.unit = unit;
+ }
+
+ public int getUnit() {
+ return unit;
+ }
+
+ @Override
+ public void apply(Renderer r, Technique technique) {
+ TechniqueDef techDef = technique.getDef();
+ r.setTexture(getUnit(), getTextureValue());
+ if (techDef.isUsingShaders()) {
+ technique.updateUniformParam(getName(), getVarType(), getUnit(), true);
+ }
+ }
+
+ @Override
+ public void write(JmeExporter ex) throws IOException {
+ super.write(ex);
+ OutputCapsule oc = ex.getCapsule(this);
+ oc.write(unit, "texture_unit", -1);
+ oc.write(texture, "texture", null);
+ }
+
+ @Override
+ public void read(JmeImporter im) throws IOException {
+ super.read(im);
+ InputCapsule ic = im.getCapsule(this);
+ unit = ic.readInt("texture_unit", -1);
+ texture = (Texture) ic.readSavable("texture", null);
+ }
+}
\ No newline at end of file
import com.jme3.renderer.Caps;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.Renderer;
+import com.jme3.renderer.queue.RenderQueue.Bucket;
+import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
+import com.jme3.scene.Spatial;
import com.jme3.shader.Shader;
import com.jme3.shader.Uniform;
import com.jme3.shader.VarType;
import java.util.logging.Level;
import java.util.logging.Logger;
+/**
+ * <code>Material</code> describes the rendering style for a given
+ * {@link Geometry}.
+ *
+ * <p>A material is essentially a list of {@link MatParam parameters}, those parameters
+ * map to uniforms which are defined in a shader.
+ * Setting the parameters can modify the behavior of a shader.
+ *
+ * @author Kirill Vainer
+ */
public class Material implements Cloneable, Savable, Comparable<Material> {
private static final Logger logger = Logger.getLogger(Material.class.getName());
private int sortingId = -1;
private transient ColorRGBA ambientLightColor = new ColorRGBA(0, 0, 0, 1);
- public static class MatParamTexture extends MatParam {
-
- private Texture texture;
- private int unit;
-// private transient TextureKey key;
-
- public MatParamTexture(VarType type, String name, Texture texture, int unit) {
- super(type, name, texture, null);
- this.texture = texture;
- this.unit = unit;
- }
-
- public MatParamTexture() {
- }
-
- public Texture getTextureValue() {
- return texture;
- }
-
- public void setTextureValue(Texture value) {
- this.value = value;
- this.texture = value;
- }
-
- public void setUnit(int unit) {
- this.unit = unit;
- }
-
- public int getUnit() {
- return unit;
- }
-
- @Override
- public void apply(Renderer r, Technique technique) {
- TechniqueDef techDef = technique.getDef();
- r.setTexture(getUnit(), getTextureValue());
- if (techDef.isUsingShaders()) {
- technique.updateUniformParam(getName(), getVarType(), getUnit(), true);
- }
- }
-
- @Override
- public void write(JmeExporter ex) throws IOException {
- super.write(ex);
- OutputCapsule oc = ex.getCapsule(this);
- oc.write(unit, "texture_unit", -1);
- oc.write(texture, "texture", null);
- }
-
- @Override
- public void read(JmeImporter im) throws IOException {
- super.read(im);
- InputCapsule ic = im.getCapsule(this);
- unit = ic.readInt("texture_unit", -1);
- texture = (Texture) ic.readSavable("texture", null);
-// key = texture.getTextureKey();
- }
- }
-
public Material(MaterialDef def) {
if (def == null) {
throw new NullPointerException("Material definition cannot be null");
}
-
this.def = def;
}
public Material() {
}
+ /**
+ * Returns the asset key name of the asset from which this material was loaded.
+ *
+ * <p>This value will be <code>null</code> unless this material was loaded
+ * from a .j3m file.
+ *
+ * @return Asset key name of the j3m file
+ */
public String getAssetName() {
return assetName;
}
+ /**
+ * Set the asset key name. This is used internally by the j3m material loader.
+ *
+ * @param assetName the asset key name
+ */
public void setAssetName(String assetName) {
this.assetName = assetName;
}
+ /**
+ * Returns the sorting ID or sorting index for this material.
+ *
+ * <p>The sorting ID is used internally by the system to sort rendering
+ * of geometries. It sorted to reduce shader switches, if the shaders
+ * are equal, then it is sorted by textures.
+ *
+ * @return The sorting ID used for sorting geometries for rendering.
+ */
public int getSortId() {
Technique t = getActiveTechnique();
if (sortingId == -1 && t != null && t.getShader() != null) {
return sortingId;
}
+ /**
+ * Uses the sorting ID for each material to compare them.
+ *
+ * @param m The other material to compare to.
+ *
+ * @return zero if the materials are equal, returns a negative value
+ * if <code>this</code> has a lower sorting ID than <code>m</code>,
+ * otherwise returns a positive value.
+ */
public int compareTo(Material m) {
return m.getSortId() - getSortId();
}
+ /**
+ * Clones this material. The result
+ * @return
+ */
@Override
public Material clone() {
try {
Material mat = (Material) super.clone();
+
if (additionalState != null) {
mat.additionalState = additionalState.clone();
}
return technique;
}
- /**
- * Should only be used in Technique.makeCurrent()
- * @param tech
- */
- public void setActiveTechnique(Technique tech) {
- technique = tech;
- }
-
public boolean isTransparent() {
return transparent;
}
+ /**
+ * Set the transparent value marker.
+ *
+ * <p>This value is merely a marker, by itself it does nothing.
+ * Generally model loaders will use this marker to indicate further
+ * up that the material is transparent and therefore any geometries
+ * using it should be put into the {@link Bucket#Transparent transparent
+ * bucket}.
+ *
+ * @param transparent the transparent value marker.
+ */
public void setTransparent(boolean transparent) {
this.transparent = transparent;
}
+ /**
+ * Check if the material should receive shadows or not.
+ *
+ * @return True if the material should receive shadows.
+ *
+ * @see Material#setReceivesShadows(boolean)
+ */
public boolean isReceivesShadows() {
return receivesShadows;
}
+ /**
+ * Set if the material should receive shadows or not.
+ *
+ * <p>This value is merely a marker, by itself it does nothing.
+ * Generally model loaders will use this marker to indicate
+ * the material should receive shadows and therefore any
+ * geometries using it should have the {@link ShadowMode#Receive} set
+ * on them.
+ *
+ * @param receivesShadows if the material should receive shadows or not.
+ */
public void setReceivesShadows(boolean receivesShadows) {
this.receivesShadows = receivesShadows;
}
+ /**
+ * Acquire the additional {@link RenderState render state} to apply
+ * for this material.
+ *
+ * <p>The first call to this method will create an additional render
+ * state which can be modified by the user to apply any render
+ * states in addition to the ones used by the renderer. Only render
+ * states which are modified in the additional render state will be applied.
+ *
+ * @return The additional render state.
+ */
public RenderState getAdditionalRenderState() {
if (additionalState == null) {
additionalState = RenderState.ADDITIONAL.clone();
return additionalState;
}
+ /**
+ * Get the material definition (j3md file info) that <code>this</code>
+ * material is implementing.
+ *
+ * @return the material definition this material implements.
+ */
public MaterialDef getMaterialDef() {
return def;
}
-// void updateUniformLinks(){
-// for (MatParam param : paramValues.values()){
-// param.uniform = technique.getShader().getUniform(param.name);
-// }
-// }
public MatParam getParam(String name) {
MatParam param = paramValues.get(name);
if (param instanceof MatParam) {
// the texture failed to load for this param
// do not add to param values
- if (texVal.texture == null || texVal.texture.getImage() == null) {
+ if (texVal.getTextureValue() == null || texVal.getTextureValue().getImage() == null) {
continue;
}
}
@Override
public String toString() {
- return "RenderState[" + "pointSprite=" + pointSprite + "applyPointSprite=" + applyPointSprite + "wireframe=" + wireframe + "applyWireFrame=" + applyWireFrame + "cullMode=" + cullMode + "applyCullMode=" + applyCullMode + "depthWrite=" + depthWrite + "applyDepthWrite=" + applyDepthWrite + "depthTest=" + depthTest + "applyDepthTest=" + applyDepthTest + "colorWrite=" + colorWrite + "applyColorWrite=" + applyColorWrite + "blendMode=" + blendMode + "applyBlendMode=" + applyBlendMode + "alphaTest=" + alphaTest + "applyAlphaTest=" + applyAlphaTest + "alphaFallOff=" + alphaFallOff + "applyAlphaFallOff=" + applyAlphaFallOff + "offsetEnabled=" + offsetEnabled + "applyPolyOffset=" + applyPolyOffset + "offsetFactor=" + offsetFactor + "offsetUnits=" + offsetUnits + ']';
+ return "RenderState[\n" + "pointSprite=" + pointSprite + "\napplyPointSprite=" + applyPointSprite + "\nwireframe=" + wireframe + "\napplyWireFrame=" + applyWireFrame + "\ncullMode=" + cullMode + "\napplyCullMode=" + applyCullMode + "\ndepthWrite=" + depthWrite + "\napplyDepthWrite=" + applyDepthWrite + "\ndepthTest=" + depthTest + "\napplyDepthTest=" + applyDepthTest + "\ncolorWrite=" + colorWrite + "\napplyColorWrite=" + applyColorWrite + "\nblendMode=" + blendMode + "\napplyBlendMode=" + applyBlendMode + "\nalphaTest=" + alphaTest + "\napplyAlphaTest=" + applyAlphaTest + "\nalphaFallOff=" + alphaFallOff + "\napplyAlphaFallOff=" + applyAlphaFallOff + "\noffsetEnabled=" + offsetEnabled + "\napplyPolyOffset=" + applyPolyOffset + "\noffsetFactor=" + offsetFactor + "\noffsetUnits=" + offsetUnits + "\n]";
}
}
Geometry frustumMdl = new Geometry("f", frustum);
frustumMdl.setCullHint(Spatial.CullHint.Never);
frustumMdl.setShadowMode(ShadowMode.Off);
- frustumMdl.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md"));
+ Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
+ mat.getAdditionalRenderState().setWireframe(true);
+ frustumMdl.setMaterial(mat);
switch (i) {
case 0:
frustumMdl.getMaterial().setColor("Color", ColorRGBA.Pink);
private float speed, coreTime,coreTime2;
private float camAngle = 0;
private BitmapText fpsScoreText, pressStart;
- private String boxSolid;
+ private boolean solidBox = true;
private Material playerMaterial;
private Material floorMaterial;
obstacleColors.add(ColorRGBA.Red);
obstacleColors.add(ColorRGBA.Yellow);
renderer.setBackgroundColor(ColorRGBA.White);
- boxSolid = "Common/MatDefs/Misc/SolidColor.j3md";
speed = lowCap / 400f;
coreTime = 20.0f;
coreTime2 = 10.0f;
// playerX+difficulty+30,playerX+difficulty+90
-
- Material mat = new Material(assetManager, boxSolid);
+ Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
+ if (!solidBox){
+ mat.getAdditionalRenderState().setWireframe(true);
+ }
mat.setColor("Color", obstacleColors.get(FastMath.nextRandomInt(0, obstacleColors.size() - 1)));
cube.setMaterial(mat);
Box b = new Box(loc, 1, 1, 1);
Geometry geom = new Geometry("Box", b);
- Material mat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
+ Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
Dome b = new Dome(Vector3f.ZERO, 10, 100, 1);
Geometry playerMesh = new Geometry("Box", b);
- playerMaterial = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
+ playerMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
playerMaterial.setColor("Color", ColorRGBA.Red);
playerMesh.setMaterial(playerMaterial);
playerMesh.setName("player");
playerMesh.getLocalTranslation().getY() - 1, 0), 100, 0, 100);
Geometry floorMesh = new Geometry("Box", floor);
- floorMaterial = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
+ floorMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
floorMaterial.setColor("Color", ColorRGBA.LightGray);
floorMesh.setMaterial(floorMaterial);
floorMesh.setName("floor");
switch (colorInt){
case 1:
obstacleColors.clear();
- boxSolid(false);
+ solidBox = false;
obstacleColors.add(ColorRGBA.Green);
renderer.setBackgroundColor(ColorRGBA.Black);
playerMaterial.setColor("Color", ColorRGBA.White);
break;
case 2:
obstacleColors.set(0, ColorRGBA.Black);
- boxSolid(true);
+ solidBox = true;
renderer.setBackgroundColor(ColorRGBA.White);
playerMaterial.setColor("Color", ColorRGBA.Gray);
floorMaterial.setColor("Color", ColorRGBA.LightGray);
case 5:
obstacleColors.remove(0);
renderer.setBackgroundColor(ColorRGBA.Pink);
- boxSolid(false);
+ solidBox = false;
playerMaterial.setColor("Color", ColorRGBA.White);
break;
case 6:
obstacleColors.set(0, ColorRGBA.White);
- boxSolid(true);
+ solidBox = true;
renderer.setBackgroundColor(ColorRGBA.Black);
playerMaterial.setColor("Color", ColorRGBA.Gray);
floorMaterial.setColor("Color", ColorRGBA.LightGray);
txt.setText(text);
guiNode.attachChild(txt);
}
-
- /**
- * Changes the boolean variable boxSolid
- * @param solid the boolean to determine if the boxes will be solid or wireFrame
- */
- private void boxSolid(boolean solid) {
- if (solid == false){
- boxSolid = "Common/MatDefs/Misc/WireColor.j3md";
- }else{
- boxSolid = "Common/MatDefs/Misc/SolidColor.j3md";
- }
- }
-
}
\ No newline at end of file
* @param manager AssetManager to load the default wireframe material for the debug shape
*/
protected Spatial attachDebugShape(AssetManager manager) {
- debugMaterialBlue = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
+ debugMaterialBlue = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
+ debugMaterialBlue.getAdditionalRenderState().setWireframe(true);
debugMaterialBlue.setColor("Color", ColorRGBA.Blue);
- debugMaterialGreen = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
+ debugMaterialGreen = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
+ debugMaterialGreen.getAdditionalRenderState().setWireframe(true);
debugMaterialGreen.setColor("Color", ColorRGBA.Green);
- debugMaterialRed = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
+ debugMaterialRed = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
+ debugMaterialRed.getAdditionalRenderState().setWireframe(true);
debugMaterialRed.setColor("Color", ColorRGBA.Red);
- debugMaterialYellow = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
+ debugMaterialYellow = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
+ debugMaterialYellow.getAdditionalRenderState().setWireframe(true);
debugMaterialYellow.setColor("Color", ColorRGBA.Yellow);
debugArrow = new Arrow(Vector3f.UNIT_XYZ);
debugArrowGeom = new Geometry("DebugArrow", debugArrow);
import java.util.EnumSet;
import java.util.logging.Logger;
import jme3tools.converters.MipMapGenerator;
+import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.GLContext;
import static org.lwjgl.opengl.GL11.*;
private int maxCubeTexSize;
private int maxVertCount;
private int maxTriCount;
+ private boolean gl12 = false;
private final Statistics statistics = new Statistics();
private int vpX, vpY, vpW, vpH;
private int clipX, clipY, clipW, clipH;
+ "support non-power-of-2 textures. "
+ "Some features might not work.");
}
+
+ if (GLContext.getCapabilities().OpenGL12){
+ gl12 = true;
+ }
}
public void invalidateState() {
glMaterial(GL_FRONT_AND_BACK, type, fb16);
}
+ private void setMaterialFloat(int type, float value){
+ if (!materialSet) {
+ materialSet = true;
+ glEnable(GL_COLOR_MATERIAL);
+ }
+
+ glMaterialf(GL_FRONT_AND_BACK, type, value);
+ }
+
public void setFixedFuncBinding(FixedFuncBinding ffBinding, Object val) {
switch (ffBinding) {
case Color:
ColorRGBA specular = (ColorRGBA) val;
setMaterialColor(GL_SPECULAR, specular);
break;
+ case MaterialShininess:
+ float shiny = (Float) val;
+ setMaterialFloat(GL_SPECULAR, shiny);
+ break;
+
}
}
return;
}
-// glEnable(GL_LIGHTING);
-
- //TODO: ...
+ //glEnable(GL_LIGHTING);
}
private int convertTextureType(Texture.Type type) {
switch (mode) {
case EdgeClamp:
case Clamp:
+ case BorderClamp:
return GL_CLAMP;
case Repeat:
return GL_REPEAT;
setupTextureParams(tex);
}
- private void checkTexturingUsed() {
+ private void clearTextureUnits() {
Image[] textures = context.boundTextures;
if (textures[0] != null) {
glDisable(GL_TEXTURE_2D);
} else {
glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
}
+
+ // TODO: Fix these to use IDList??
clearVertexAttribs();
- checkTexturingUsed();
+ clearTextureUnits();
clearSetFixedFuncBindings();
}
boolean dynamic = false;
if (mesh.getBuffer(Type.InterleavedData) != null) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("Interleaved meshes are not supported");
}
if (mesh.getNumLodLevels() == 0) {
-Material HDR Picture : Common/MatDefs/Misc/SimpleTextured.j3md {\r
+Material HDR Picture : Common/MatDefs/Misc/Unshaded.j3md {\r
MaterialParameters {\r
ColorMap : Flip Textures/HdrTest/Memorial.hdr\r
}\r
--- /dev/null
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package jme3test.audio;
+
+import com.jme3.asset.plugins.UrlLocator;
+import com.jme3.audio.AudioNode;
+
+public class TestMusicStreaming extends AudioApp {
+
+ public static void main(String[] args){
+ TestMusicStreaming test = new TestMusicStreaming();
+ test.start();
+ }
+
+ @Override
+ public void updateAudioApp(float tpf){
+ }
+
+ @Override
+ public void initAudioApp(){
+ assetManager.registerLocator("http://www.vorbis.com/music/", UrlLocator.class);
+ AudioNode src = new AudioNode(audioRenderer, assetManager, "Lumme-Badloop.ogg", true);
+ audioRenderer.playSource(src);
+ }
+}
\ No newline at end of file
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry geom = new Geometry("Box", b);
- Material mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
geom.setMaterial(mat);
rootNode.attachChild(geom);
}\r
\r
private void assignPoints(AssetManager assetManager) {\r
- Material defaultMaterial = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");\r
- defaultMaterial.setColor("m_Color", ColorRGBA.DarkGray);\r
+ Material defaultMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");\r
+ defaultMaterial.setColor("Color", ColorRGBA.DarkGray);\r
for(int i = -10; i <= 10; ++i) {\r
Geometry g = new Geometry("", new Sphere(3, 3, 0.05f));\r
g.setLocalTranslation(i, 0, 0);\r
\r
private Geometry getAxis(String name, Vector3f endPoint, ColorRGBA color, AssetManager assetManager) {\r
Line axis = new Line(new Vector3f(0, 0, 0), endPoint);\r
- Material mat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");\r
- mat.setColor("m_Color", color);\r
+ Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");\r
+ mat.setColor("Color", color);\r
Geometry geom = new Geometry(name, axis);\r
geom.setMaterial(mat);\r
return geom;\r
private Vector3f globalPosition;\r
\r
public VisibleBone(Bone bone, Vector3f parentLocation, Quaternion parentRotation, AssetManager assetManager) {\r
- Material redMat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");\r
- redMat.setColor("m_Color", ColorRGBA.Red);\r
+ Material redMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");\r
+ redMat.setColor("Color", ColorRGBA.Red);\r
\r
- Material whiteMat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");\r
- whiteMat.setColor("m_Color", ColorRGBA.White);\r
+ Material whiteMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");\r
+ whiteMat.setColor("Color", ColorRGBA.White);\r
\r
Geometry g = new Geometry(bone.getName(), new Sphere(9, 9, 0.01f));\r
globalPosition = bone.getLocalPosition().add(parentLocation);\r
light.setColor(ColorRGBA.LightGray);
rootNode.addLight(light);
- Material material = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
Box floorBox = new Box(140, 0.25f, 140);
* @return
*/
public static Geometry createPhysicsTestBox(AssetManager assetManager) {
- Material material = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
Box box = new Box(0.25f, 0.25f, 0.25f);
Geometry boxGeometry = new Geometry("Box", box);
* @return
*/
public static Geometry createPhysicsTestSphere(AssetManager assetManager) {
- Material material = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
Sphere sphere = new Sphere(8, 8, 0.25f);
Geometry boxGeometry = new Geometry("Sphere", sphere);
public void onAction(String name, boolean keyPressed, float tpf) {
Sphere bullet = new Sphere(32, 32, 0.4f, true, false);
bullet.setTextureMode(TextureMode.Projected);
- Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/SimpleTextured.j3md");
+ Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
key2.setGenerateMips(true);
Texture tex2 = app.getAssetManager().loadTexture(key2);
}
private void buildPlayer() {
- Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/WireColor.j3md");
+ Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
+ mat.getAdditionalRenderState().setWireframe(true);
mat.setColor("Color", ColorRGBA.Red);
//create a compound shape and attach the BoxCollisionShape for the car body at 0,1,0
}
public void setupJoint() {
-
- Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/WireColor.j3md");
- mat.setColor("Color", ColorRGBA.Gray);
-
Node holderNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.1f, .1f, .1f)), 0);
holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, 0, 0f));
rootNode.attachChild(holderNode);
//debug view
AnimControl control = model.getControl(AnimControl.class);
SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton", control.getSkeleton());
- Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
+ Material mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
+ mat2.getAdditionalRenderState().setWireframe(true);
mat2.setColor("Color", ColorRGBA.Green);
mat2.getAdditionalRenderState().setDepthTest(false);
skeletonDebug.setMaterial(mat2);
public void initMaterial() {
- matBullet = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ matBullet = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
key2.setGenerateMips(true);
Texture tex2 = assetManager.loadTexture(key2);
}
public void initMaterial() {
- mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
key.setGenerateMips(true);
Texture tex = assetManager.loadTexture(key);
mat.setTexture("ColorMap", tex);
- mat2 = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
key2.setGenerateMips(true);
Texture tex2 = assetManager.loadTexture(key2);
mat2.setTexture("ColorMap", tex2);
- mat3 = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.png");
key3.setGenerateMips(true);
Texture tex3 = assetManager.loadTexture(key3);
}\r
\r
public void initMaterial() {\r
- mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");\r
+ mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");\r
TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");\r
key.setGenerateMips(true);\r
Texture tex = assetManager.loadTexture(key);\r
mat.setTexture("ColorMap", tex);\r
\r
- mat2 = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");\r
+ mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");\r
TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");\r
key2.setGenerateMips(true);\r
Texture tex2 = assetManager.loadTexture(key2);\r
mat2.setTexture("ColorMap", tex2);\r
\r
- mat3 = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");\r
+ mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");\r
TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.png");\r
key3.setGenerateMips(true);\r
Texture tex3 = assetManager.loadTexture(key3);\r
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
*/\r
-\r
package jme3test.bullet;\r
\r
import com.jme3.bullet.BulletAppState;\r
*\r
* @author normenhansen\r
*/\r
-public class TestCcd extends SimpleApplication implements ActionListener{\r
+public class TestCcd extends SimpleApplication implements ActionListener {\r
\r
private Material mat;\r
private Material mat2;\r
bulletCollisionShape = new SphereCollisionShape(0.1f);\r
setupKeys();\r
\r
- mat = new Material(getAssetManager(), "Common/MatDefs/Misc/WireColor.j3md");\r
+ mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");\r
+ mat.getAdditionalRenderState().setWireframe(true);\r
mat.setColor("Color", ColorRGBA.Green);\r
\r
- mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/WireColor.j3md");\r
+ mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");\r
+ mat2.getAdditionalRenderState().setWireframe(true);\r
mat2.setColor("Color", ColorRGBA.Red);\r
\r
// An obstacle mesh, does not move (mass=0)\r
Node node2 = new Node();\r
node2.setName("mesh");\r
node2.setLocalTranslation(new Vector3f(2.5f, 0, 0f));\r
- node2.addControl(new RigidBodyControl(new MeshCollisionShape(new Box(Vector3f.ZERO,4,4,0.1f)), 0));\r
+ node2.addControl(new RigidBodyControl(new MeshCollisionShape(new Box(Vector3f.ZERO, 4, 4, 0.1f)), 0));\r
rootNode.attachChild(node2);\r
getPhysicsSpace().add(node2);\r
\r
\r
}\r
\r
- private PhysicsSpace getPhysicsSpace(){\r
+ private PhysicsSpace getPhysicsSpace() {\r
return bulletAppState.getPhysicsSpace();\r
}\r
\r
bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40));\r
rootNode.attachChild(bulletg);\r
getPhysicsSpace().add(bulletg);\r
- }\r
- else if(binding.equals("shoot2") && !value) {\r
+ } else if (binding.equals("shoot2") && !value) {\r
Geometry bulletg = new Geometry("bullet", bullet);\r
bulletg.setMaterial(mat2);\r
bulletg.setName("bullet");\r
getPhysicsSpace().add(bulletg);\r
}\r
}\r
-\r
}\r
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
- Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/WireColor.j3md");
- mat.setColor("Color", ColorRGBA.Red);
- Material mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/WireColor.j3md");
- mat2.setColor("Color", ColorRGBA.Magenta);
-
+
// Add a physics sphere to the world
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
public class TestCollisionListener extends SimpleApplication implements PhysicsCollisionListener {\r
\r
private BulletAppState bulletAppState;\r
- private Material mat;\r
private Sphere bullet;\r
private SphereCollisionShape bulletCollisionShape;\r
\r
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());\r
PhysicsTestHelper.createBallShooter(this, rootNode, bulletAppState.getPhysicsSpace());\r
\r
- mat = new Material(getAssetManager(), "Common/MatDefs/Misc/WireColor.j3md");\r
- mat.setColor("Color", ColorRGBA.Red);\r
-\r
// add ourselves as collision listener\r
getPhysicsSpace().addCollisionListener(this);\r
}\r
private void initGhostObject() {
Vector3f halfExtents = new Vector3f(3, 4.2f, 1);
- Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/WireColor.j3md");
- mat.setColor("Color", ColorRGBA.Red);
ghostControl = new GhostControl(new BoxCollisionShape(halfExtents));
Node node=new Node("Ghost Object");
node.addControl(ghostControl);
private Spatial spaceCraft;
TerrainQuad terrain;
Material matRock;
- Material matWire;
boolean wireframe = false;
protected BitmapText hintText;
PointLight pl;
matRock.setTexture("NormalMap_1", normalMap2);
matRock.setTexture("NormalMap_2", normalMap2);
- matWire = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
- matWire.setColor("Color", ColorRGBA.Green);
AbstractHeightMap heightmap = null;
try {
heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.25f);
}
private void buildPlayer() {
- Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/WireColor.j3md");
+ Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
+ mat.getAdditionalRenderState().setWireframe(true);
mat.setColor("Color", ColorRGBA.Red);
//create a compound shape and attach the BoxCollisionShape for the car body at 0,1,0
}
public void setupJoint() {
-
- Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/WireColor.j3md");
- mat.setColor("Color", ColorRGBA.Yellow);
-
Node holderNode=PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f( .1f, .1f, .1f)),0);
holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f,0,0f));
rootNode.attachChild(holderNode);
RigidBodyControl terrainPhysicsNode;
//Materials
Material matRock;
- Material matWire;
Material matBullet;
//animation
AnimChannel animationChannel;
bullet = new Sphere(32, 32, 0.4f, true, false);
bullet.setTextureMode(TextureMode.Projected);
bulletCollisionShape = new SphereCollisionShape(0.4f);
- matBullet = new Material(getAssetManager(), "Common/MatDefs/Misc/SolidColor.j3md");
+ matBullet = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
matBullet.setColor("Color", ColorRGBA.Green);
matBullet.setColor("m_GlowColor", ColorRGBA.Green);
getPhysicsSpace().addCollisionListener(this);
matRock.setTexture("NormalMap", normalMap0);
matRock.setTexture("NormalMap_1", normalMap2);
matRock.setTexture("NormalMap_2", normalMap2);
- matWire = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
- matWire.setColor("Color", ColorRGBA.Green);
AbstractHeightMap heightmap = null;
try {
protected Geometry makeCube(String name, float x, float y, float z) {
Box box = new Box(new Vector3f(x, y, z), 1, 1, 1);
Geometry cube = new Geometry(name, box);
- Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
+ Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.randomColor());
cube.setMaterial(mat1);
return cube;
protected Geometry makeFloor() {
Box box = new Box(new Vector3f(0, -4, -5), 15, .2f, 15);
Geometry floor = new Geometry("the Floor", box);
- Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
+ Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Gray);
floor.setMaterial(mat1);
return floor;
//Sphere sphere = new Sphere(30, 30, 0.2f);
mark = new Geometry("BOOM!", arrow);
//mark = new Geometry("BOOM!", sphere);
- Material mark_mat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
+ Material mark_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mark_mat.setColor("Color", ColorRGBA.Red);
mark.setMaterial(mark_mat);
}
Mesh mesh1 = new Box(0.5f, 0.5f, 0.5f);
geom1 = new Geometry("Box", mesh1);
geom1.move(2, 2, -.5f);
- Material m1 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
+ Material m1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
m1.setColor("Color", ColorRGBA.Blue);
geom1.setMaterial(m1);
rootNode.attachChild(geom1);
MipMapGenerator.generateMipMaps(imageCustomMip);
texCustomMip.setImage(imageCustomMip);
- Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat1.setTexture("ColorMap", tex);
- Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat2.setTexture("ColorMap", texCustomMip);
quad1.setMaterial(mat1);
/** Create a wall (Box with material and texture from test-data) */
Box box = new Box(Vector3f.ZERO, 2.5f,2.5f,1.0f);
Spatial wall = new Geometry("Box", box );
- Material mat_brick = new Material( assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ Material mat_brick = new Material( assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat_brick.setTexture("ColorMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
wall.setMaterial(mat_brick);
wall.setLocalTranslation(2.0f,-2.5f,0.0f);
/** just a blue box floating in space */
Box box1 = new Box(Vector3f.ZERO, 1, 1, 1);
player = new Geometry("Player", box1);
- Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
+ Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Blue);
player.setMaterial(mat1);
rootNode.attachChild(player);
public void simpleInitApp() {\r
Box b = new Box(Vector3f.ZERO, 1, 1, 1);\r
player = new Geometry("Player", b);\r
- Material mat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");\r
+ Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");\r
mat.setColor("Color", ColorRGBA.Blue);\r
player.setMaterial(mat);\r
rootNode.attachChild(player);\r
Box b = new Box(Vector3f.ZERO, 1, 1, 1); // create cube shape
Geometry geom = new Geometry("Box", b); // create cube geometry from the shape
Material mat = new Material(assetManager,
- "Common/MatDefs/Misc/SolidColor.j3md"); // create a simple material
+ "Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material
mat.setColor("Color", ColorRGBA.Blue); // set color of material to blue
geom.setMaterial(mat); // set the cube's material
rootNode.attachChild(geom); // make the cube appear in the scene
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
player = new Geometry("blue cube", b);
Material mat = new Material(assetManager,
- "Common/MatDefs/Misc/SolidColor.j3md");
+ "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
player.setMaterial(mat);
rootNode.attachChild(player);
/** A simple textured cube -- in good MIP map quality. */
Box boxshape1 = new Box(new Vector3f(-3f,1.1f,0f), 1f,1f,1f);
Geometry cube = new Geometry("My Textured Box", boxshape1);
- Material mat_stl = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ Material mat_stl = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture tex_ml = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
mat_stl.setTexture("ColorMap", tex_ml);
cube.setMaterial(mat_stl);
/** A translucent/transparent texture, similar to a window frame. */
Box boxshape3 = new Box(new Vector3f(0f,0f,0f), 1f,1f,0.01f);
Geometry window_frame = new Geometry("window frame", boxshape3);
- Material mat_tt = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ Material mat_tt = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat_tt.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
mat_tt.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); // activate transparency
window_frame.setQueueBucket(Bucket.Transparent);
/** create a blue box at coordinates (1,-1,1) */
Box box1 = new Box( new Vector3f(1,-1,1), 1,1,1);
Geometry blue = new Geometry("Box", box1);
- Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
+ Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Blue);
blue.setMaterial(mat1);
/** create a red box straight above the blue one at (1,3,1) */
Box box2 = new Box( new Vector3f(1,3,1), 1,1,1);
Geometry red = new Geometry("Box", box2);
- Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
+ Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat2.setColor("Color", ColorRGBA.Red);
red.setMaterial(mat2);
\r
/** Initialize the materials used in this scene. */\r
public void initMaterials() {\r
- wall_mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");\r
+ wall_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");\r
TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");\r
key.setGenerateMips(true);\r
Texture tex = assetManager.loadTexture(key);\r
wall_mat.setTexture("ColorMap", tex);\r
\r
- stone_mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");\r
+ stone_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");\r
TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");\r
key2.setGenerateMips(true);\r
Texture tex2 = assetManager.loadTexture(key2);\r
stone_mat.setTexture("ColorMap", tex2);\r
\r
- floor_mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");\r
+ floor_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");\r
TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.png");\r
key3.setGenerateMips(true);\r
Texture tex3 = assetManager.loadTexture(key3);\r
protected Geometry makeCube(String name, float x, float y, float z) {\r
Box box = new Box(new Vector3f(x, y, z), 1, 1, 1);\r
Geometry cube = new Geometry(name, box);\r
- Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");\r
+ Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");\r
mat1.setColor("Color", ColorRGBA.randomColor());\r
cube.setMaterial(mat1);\r
return cube;\r
protected Geometry makeFloor() {\r
Box box = new Box(new Vector3f(0, -4, -5), 15, .2f, 15);\r
Geometry floor = new Geometry("the Floor", box);\r
- Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");\r
+ Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");\r
mat1.setColor("Color", ColorRGBA.Gray);\r
floor.setMaterial(mat1);\r
return floor;\r
protected void initMark() {\r
Sphere sphere = new Sphere(30, 30, 0.2f);\r
mark = new Geometry("BOOM!", sphere);\r
- Material mark_mat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");\r
+ Material mark_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");\r
mark_mat.setColor("Color", ColorRGBA.Red);\r
mark.setMaterial(mark_mat);\r
}\r
Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
teaGeom.setMaterial(mat);
pivot.attachChild(teaGeom);
- mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
Geometry ground = new Geometry("ground", new Quad(50, 50));
ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
public void loadScene(){
Material mat = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
- Material matSoil = new Material(assetManager,"Common/MatDefs/Misc/SolidColor.j3md");
+ Material matSoil = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
matSoil.setColor("Color", ColorRGBA.Cyan);
teapot = new Geometry("sphere", new Sphere(30, 30, 2));
frustumMdl = new Geometry("f", frustum);
frustumMdl.setCullHint(Spatial.CullHint.Never);
frustumMdl.setShadowMode(ShadowMode.Off);
- frustumMdl.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md"));
+ frustumMdl.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
+ frustumMdl.getMaterial().getAdditionalRenderState().setWireframe(true);
frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
rootNode.attachChild(frustumMdl);
}
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
-import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Sphere;
public BoxEntity(AssetManager assetManager, ColorRGBA color){
super("Box", new Box(1,1,1));
- setMaterial(new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md"));
+ setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
getMaterial().setColor("Color", color);
}
private Vector3f lightDir = new Vector3f(-4.9236743f, -1.27054665f, 5.896916f);
TerrainQuad terrain;
Material matRock;
- Material matWire;
DepthOfFieldFilter dofFilter;
public static void main(String[] args) {
matRock.setTexture("NormalMap_1", normalMap2);
matRock.setTexture("NormalMap_2", normalMap2);
- matWire = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
- matWire.setColor("Color", ColorRGBA.Green);
AbstractHeightMap heightmap = null;
try {
heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.25f);
// Material mat = assetManager.loadMaterial("Textures/HdrTest/Memorial.j3m");
// box.setMaterial(mat);
- Material mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", assetManager.loadTexture("Textures/HdrTest/Memorial.hdr"));
box.setMaterial(mat);
// fpp.addFilter(ssaoFilter);
-// Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+// Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
// mat2.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
//
// Sphere lite=new Sphere(8, 8, 10.0f);
Texture offTex = setupOffscreenView();
- Material mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", offTex);
quad.setMaterial(mat);
rootNode.attachChild(quad);
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package jme3test.terrain;
import jme3tools.converters.ImageToAwt;
*/
public class TerrainTest extends SimpleApplication {
- private TerrainQuad terrain;
- Material matRock;
- Material matWire;
- boolean wireframe = false;
+ private TerrainQuad terrain;
+ Material matRock;
+ Material matWire;
+ boolean wireframe = false;
boolean triPlanar = false;
- protected BitmapText hintText;
- PointLight pl;
- Geometry lightMdl;
+ protected BitmapText hintText;
+ PointLight pl;
+ Geometry lightMdl;
private float grassScale = 64;
private float dirtScale = 16;
private float rockScale = 128;
- public static void main(String[] args) {
- TerrainTest app = new TerrainTest();
- app.start();
- }
+ public static void main(String[] args) {
+ TerrainTest app = new TerrainTest();
+ app.start();
+ }
- @Override
- public void initialize() {
- super.initialize();
+ @Override
+ public void initialize() {
+ super.initialize();
- loadHintText();
- }
+ loadHintText();
+ }
- @Override
- public void simpleInitApp() {
- setupKeys();
+ @Override
+ public void simpleInitApp() {
+ setupKeys();
// First, we load up our textures and the heightmap texture for the terrain
- // TERRAIN TEXTURE material
- matRock = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
+ // TERRAIN TEXTURE material
+ matRock = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
matRock.setBoolean("useTriPlanarMapping", false);
- // ALPHA map (for splat textures)
- matRock.setTexture("Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
-
- // HEIGHTMAP image (for the terrain heightmap)
- Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
-
- // GRASS texture
- Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
- grass.setWrap(WrapMode.Repeat);
- matRock.setTexture("Tex1", grass);
- matRock.setFloat("Tex1Scale", grassScale);
-
- // DIRT texture
- Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
- dirt.setWrap(WrapMode.Repeat);
- matRock.setTexture("Tex2", dirt);
- matRock.setFloat("Tex2Scale", dirtScale);
-
- // ROCK texture
- Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
- rock.setWrap(WrapMode.Repeat);
- matRock.setTexture("Tex3", rock);
- matRock.setFloat("Tex3Scale", rockScale);
-
- // WIREFRAME material
- matWire = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
+ // ALPHA map (for splat textures)
+ matRock.setTexture("Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
+
+ // HEIGHTMAP image (for the terrain heightmap)
+ Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
+
+ // GRASS texture
+ Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
+ grass.setWrap(WrapMode.Repeat);
+ matRock.setTexture("Tex1", grass);
+ matRock.setFloat("Tex1Scale", grassScale);
+
+ // DIRT texture
+ Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
+ dirt.setWrap(WrapMode.Repeat);
+ matRock.setTexture("Tex2", dirt);
+ matRock.setFloat("Tex2Scale", dirtScale);
+
+ // ROCK texture
+ Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
+ rock.setWrap(WrapMode.Repeat);
+ matRock.setTexture("Tex3", rock);
+ matRock.setFloat("Tex3Scale", rockScale);
+
+ // WIREFRAME material
+ matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
+ matWire.getAdditionalRenderState().setWireframe(true);
matWire.setColor("Color", ColorRGBA.Green);
+ // CREATE HEIGHTMAP
+ AbstractHeightMap heightmap = null;
+ try {
+ //heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3);
+
+ heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 1f);
+ heightmap.load();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ /*
+ * Here we create the actual terrain. The tiles will be 65x65, and the total size of the
+ * terrain will be 513x513. It uses the heightmap we created to generate the height values.
+ */
+ /**
+ * Optimal terrain patch size is 65 (64x64).
+ * The total size is up to you. At 1025 it ran fine for me (200+FPS), however at
+ * size=2049, it got really slow. But that is a jump from 2 million to 8 million triangles...
+ */
+ terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());//, new LodPerspectiveCalculatorFactory(getCamera(), 4)); // add this in to see it use entropy for LOD calculations
+ List<Camera> cameras = new ArrayList<Camera>();
+ cameras.add(getCamera());
+ TerrainLodControl control = new TerrainLodControl(terrain, cameras);
+ terrain.addControl(control);
+ terrain.setMaterial(matRock);
+ terrain.setModelBound(new BoundingBox());
+ terrain.updateModelBound();
+ terrain.setLocalTranslation(0, -100, 0);
+ terrain.setLocalScale(2f, 1f, 2f);
+ rootNode.attachChild(terrain);
- // CREATE HEIGHTMAP
- AbstractHeightMap heightmap = null;
- try {
- //heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3);
-
- heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 1f);
- heightmap.load();
-
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- /*
- * Here we create the actual terrain. The tiles will be 65x65, and the total size of the
- * terrain will be 513x513. It uses the heightmap we created to generate the height values.
- */
- /**
- * Optimal terrain patch size is 65 (64x64).
- * The total size is up to you. At 1025 it ran fine for me (200+FPS), however at
- * size=2049, it got really slow. But that is a jump from 2 million to 8 million triangles...
- */
- terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());//, new LodPerspectiveCalculatorFactory(getCamera(), 4)); // add this in to see it use entropy for LOD calculations
- List<Camera> cameras = new ArrayList<Camera>();
- cameras.add(getCamera());
- TerrainLodControl control = new TerrainLodControl(terrain, cameras);
- terrain.addControl(control);
- terrain.setMaterial(matRock);
- terrain.setModelBound(new BoundingBox());
- terrain.updateModelBound();
- terrain.setLocalTranslation(0, -100, 0);
- terrain.setLocalScale(2f, 1f, 2f);
- rootNode.attachChild(terrain);
-
DirectionalLight light = new DirectionalLight();
- light.setDirection((new Vector3f(-0.5f,-1f, -0.5f)).normalize());
+ light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
rootNode.addLight(light);
- getCamera().getLocation().y = 10;
- getCamera().setDirection(new Vector3f(0, -1.5f, -1));
- }
-
- public void loadHintText() {
- hintText = new BitmapText(guiFont, false);
- hintText.setSize(guiFont.getCharSet().getRenderedSize());
- hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
- hintText.setText("Hit T to switch to wireframe, P to switch to tri-planar texturing");
- guiNode.attachChild(hintText);
- }
-
- private void setupKeys() {
- flyCam.setMoveSpeed(50);
- inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
- inputManager.addListener(actionListener, "wireframe");
+ getCamera().getLocation().y = 10;
+ getCamera().setDirection(new Vector3f(0, -1.5f, -1));
+ }
+
+ public void loadHintText() {
+ hintText = new BitmapText(guiFont, false);
+ hintText.setSize(guiFont.getCharSet().getRenderedSize());
+ hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
+ hintText.setText("Hit T to switch to wireframe, P to switch to tri-planar texturing");
+ guiNode.attachChild(hintText);
+ }
+
+ private void setupKeys() {
+ flyCam.setMoveSpeed(50);
+ inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
+ inputManager.addListener(actionListener, "wireframe");
inputManager.addMapping("triPlanar", new KeyTrigger(KeyInput.KEY_P));
- inputManager.addListener(actionListener, "triPlanar");
- }
-
- private ActionListener actionListener = new ActionListener() {
-
- public void onAction(String name, boolean pressed, float tpf) {
- if (name.equals("wireframe") && !pressed) {
- wireframe = !wireframe;
- if (!wireframe) {
- terrain.setMaterial(matWire);
- } else {
- terrain.setMaterial(matRock);
- }
- } else if (name.equals("triPlanar") && !pressed) {
+ inputManager.addListener(actionListener, "triPlanar");
+ }
+ private ActionListener actionListener = new ActionListener() {
+
+ public void onAction(String name, boolean pressed, float tpf) {
+ if (name.equals("wireframe") && !pressed) {
+ wireframe = !wireframe;
+ if (!wireframe) {
+ terrain.setMaterial(matWire);
+ } else {
+ terrain.setMaterial(matRock);
+ }
+ } else if (name.equals("triPlanar") && !pressed) {
triPlanar = !triPlanar;
if (triPlanar) {
matRock.setBoolean("useTriPlanarMapping", true);
// planar textures don't use the mesh's texture coordinates but real world coordinates,
// so we need to convert these texture coordinate scales into real world scales so it looks
// the same when we switch to/from tr-planar mode
- matRock.setFloat("Tex1Scale", 1f/(float)(512f/grassScale));
- matRock.setFloat("Tex2Scale", 1f/(float)(512f/dirtScale));
- matRock.setFloat("Tex3Scale", 1f/(float)(512f/rockScale));
- } else {
+ matRock.setFloat("Tex1Scale", 1f / (float) (512f / grassScale));
+ matRock.setFloat("Tex2Scale", 1f / (float) (512f / dirtScale));
+ matRock.setFloat("Tex3Scale", 1f / (float) (512f / rockScale));
+ } else {
matRock.setBoolean("useTriPlanarMapping", false);
matRock.setFloat("Tex1Scale", grassScale);
matRock.setFloat("Tex2Scale", dirtScale);
matRock.setFloat("Tex3Scale", rockScale);
}
}
- }
- };
+ }
+ };
}
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package jme3test.terrain;
import jme3tools.converters.ImageToAwt;
*/
public class TerrainTestAdvanced extends SimpleApplication {
- private TerrainQuad terrain;
- Material matTerrain;
- Material matWire;
- boolean wireframe = false;
+ private TerrainQuad terrain;
+ Material matTerrain;
+ Material matWire;
+ boolean wireframe = false;
boolean triPlanar = false;
boolean wardiso = false;
boolean minnaert = false;
- protected BitmapText hintText;
- PointLight pl;
- Geometry lightMdl;
+ protected BitmapText hintText;
+ PointLight pl;
+ Geometry lightMdl;
private float grassScale = 64;
private float dirtScale = 16;
private float rockScale = 128;
- public static void main(String[] args) {
- TerrainTestAdvanced app = new TerrainTestAdvanced();
- app.start();
- }
+ public static void main(String[] args) {
+ TerrainTestAdvanced app = new TerrainTestAdvanced();
+ app.start();
+ }
- @Override
- public void initialize() {
- super.initialize();
+ @Override
+ public void initialize() {
+ super.initialize();
- loadHintText();
- }
+ loadHintText();
+ }
- @Override
- public void simpleInitApp() {
- setupKeys();
+ @Override
+ public void simpleInitApp() {
+ setupKeys();
// 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");
+ // TERRAIN TEXTURE material
+ matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
matTerrain.setBoolean("useTriPlanarMapping", false);
matTerrain.setBoolean("WardIso", true);
- // ALPHA map (for splat textures)
- matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
+ // ALPHA map (for splat textures)
+ matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
- // HEIGHTMAP image (for the terrain heightmap)
- Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
+ // HEIGHTMAP image (for the terrain heightmap)
+ Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.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);
-
+ // 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);
+ // 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);
+
-
Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.png");
normalMap0.setWrap(WrapMode.Repeat);
Texture normalMap1 = assetManager.loadTexture("Textures/Terrain/splat/dirt_normal.png");
matTerrain.setTexture("NormalMap_1", normalMap2);
matTerrain.setTexture("NormalMap_2", normalMap2);
- // WIREFRAME material
- matWire = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
+ // WIREFRAME material
+ matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
+ matWire.getAdditionalRenderState().setWireframe(true);
matWire.setColor("Color", ColorRGBA.Green);
createSky();
- // CREATE HEIGHTMAP
- AbstractHeightMap heightmap = null;
- try {
- //heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3);
-
- heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 1f);
- heightmap.load();
-
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- /*
- * Here we create the actual terrain. The tiles will be 65x65, and the total size of the
- * terrain will be 513x513. It uses the heightmap we created to generate the height values.
- */
- /**
- * Optimal terrain patch size is 65 (64x64).
- * The total size is up to you. At 1025 it ran fine for me (200+FPS), however at
- * size=2049, it got really slow. But that is a jump from 2 million to 8 million triangles...
- */
- terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());//, new LodPerspectiveCalculatorFactory(getCamera(), 4)); // add this in to see it use entropy for LOD calculations
- List<Camera> cameras = new ArrayList<Camera>();
- cameras.add(getCamera());
- TerrainLodControl control = new TerrainLodControl(terrain, cameras);
- terrain.addControl(control);
- terrain.setMaterial(matTerrain);
- terrain.setModelBound(new BoundingBox());
- terrain.updateModelBound();
- terrain.setLocalTranslation(0, -100, 0);
- terrain.setLocalScale(1f, 1f, 1f);
- rootNode.attachChild(terrain);
+ // CREATE HEIGHTMAP
+ AbstractHeightMap heightmap = null;
+ try {
+ //heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3);
+
+ heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 1f);
+ heightmap.load();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ /*
+ * Here we create the actual terrain. The tiles will be 65x65, and the total size of the
+ * terrain will be 513x513. It uses the heightmap we created to generate the height values.
+ */
+ /**
+ * Optimal terrain patch size is 65 (64x64).
+ * The total size is up to you. At 1025 it ran fine for me (200+FPS), however at
+ * size=2049, it got really slow. But that is a jump from 2 million to 8 million triangles...
+ */
+ terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());//, new LodPerspectiveCalculatorFactory(getCamera(), 4)); // add this in to see it use entropy for LOD calculations
+ List<Camera> cameras = new ArrayList<Camera>();
+ cameras.add(getCamera());
+ TerrainLodControl control = new TerrainLodControl(terrain, cameras);
+ terrain.addControl(control);
+ terrain.setMaterial(matTerrain);
+ terrain.setModelBound(new BoundingBox());
+ terrain.updateModelBound();
+ terrain.setLocalTranslation(0, -100, 0);
+ terrain.setLocalScale(1f, 1f, 1f);
+ rootNode.attachChild(terrain);
DirectionalLight light = new DirectionalLight();
- light.setDirection((new Vector3f(-0.5f,-1f, -0.5f)).normalize());
+ light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
rootNode.addLight(light);
AmbientLight ambLight = new AmbientLight();
ambLight.setColor(new ColorRGBA(1f, 1f, 0.8f, 0.2f));
rootNode.addLight(ambLight);
- getCamera().getLocation().y = 10;
- getCamera().setDirection(new Vector3f(0, -1.5f, -1));
- }
-
- public void loadHintText() {
- hintText = new BitmapText(guiFont, false);
- hintText.setSize(guiFont.getCharSet().getRenderedSize());
- hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
- hintText.setText("Hit T to switch to wireframe, P to switch to tri-planar texturing");
- guiNode.attachChild(hintText);
- }
-
- private void setupKeys() {
- flyCam.setMoveSpeed(50);
- inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
- inputManager.addListener(actionListener, "wireframe");
+ getCamera().getLocation().y = 10;
+ getCamera().setDirection(new Vector3f(0, -1.5f, -1));
+ }
+
+ public void loadHintText() {
+ hintText = new BitmapText(guiFont, false);
+ hintText.setSize(guiFont.getCharSet().getRenderedSize());
+ hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
+ hintText.setText("Hit T to switch to wireframe, P to switch to tri-planar texturing");
+ guiNode.attachChild(hintText);
+ }
+
+ private void setupKeys() {
+ flyCam.setMoveSpeed(50);
+ inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
+ inputManager.addListener(actionListener, "wireframe");
inputManager.addMapping("triPlanar", new KeyTrigger(KeyInput.KEY_P));
- inputManager.addListener(actionListener, "triPlanar");
+ inputManager.addListener(actionListener, "triPlanar");
inputManager.addMapping("WardIso", new KeyTrigger(KeyInput.KEY_9));
- inputManager.addListener(actionListener, "WardIso");
+ inputManager.addListener(actionListener, "WardIso");
inputManager.addMapping("Minnaert", new KeyTrigger(KeyInput.KEY_0));
- inputManager.addListener(actionListener, "Minnaert");
- }
-
- private ActionListener actionListener = new ActionListener() {
-
- public void onAction(String name, boolean pressed, float tpf) {
- if (name.equals("wireframe") && !pressed) {
- wireframe = !wireframe;
- if (!wireframe) {
- terrain.setMaterial(matWire);
- } else {
- terrain.setMaterial(matTerrain);
- }
- } else if (name.equals("triPlanar") && !pressed) {
+ inputManager.addListener(actionListener, "Minnaert");
+ }
+ private ActionListener actionListener = new ActionListener() {
+
+ public void onAction(String name, boolean pressed, float tpf) {
+ if (name.equals("wireframe") && !pressed) {
+ wireframe = !wireframe;
+ if (!wireframe) {
+ terrain.setMaterial(matWire);
+ } else {
+ terrain.setMaterial(matTerrain);
+ }
+ } else if (name.equals("triPlanar") && !pressed) {
triPlanar = !triPlanar;
if (triPlanar) {
matTerrain.setBoolean("useTriPlanarMapping", true);
// planar textures don't use the mesh's texture coordinates but real world coordinates,
// so we need to convert these texture coordinate scales into real world scales so it looks
// the same when we switch to/from tr-planar mode
- matTerrain.setFloat("DiffuseMap_0_scale", 1f/(float)(512f/grassScale));
- matTerrain.setFloat("DiffuseMap_1_scale", 1f/(float)(512f/dirtScale));
- matTerrain.setFloat("DiffuseMap_2_scale", 1f/(float)(512f/rockScale));
- } else {
+ matTerrain.setFloat("DiffuseMap_0_scale", 1f / (float) (512f / grassScale));
+ matTerrain.setFloat("DiffuseMap_1_scale", 1f / (float) (512f / dirtScale));
+ matTerrain.setFloat("DiffuseMap_2_scale", 1f / (float) (512f / rockScale));
+ } else {
matTerrain.setBoolean("useTriPlanarMapping", false);
matTerrain.setFloat("DiffuseMap_0_scale", grassScale);
matTerrain.setFloat("DiffuseMap_1_scale", dirtScale);
matTerrain.setFloat("DiffuseMap_2_scale", rockScale);
}
}
- }
- };
+ }
+ };
private void createSky() {
Texture west = assetManager.loadTexture("Textures/Sky/Lagoon/lagoon_west.jpg");
rock.setWrap(WrapMode.Repeat);
matRock.setTexture("Tex3", rock);
matRock.setFloat("Tex3Scale", 128f);
- matWire = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
+ matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
+ matWire.getAdditionalRenderState().setWireframe(true);
matWire.setColor("Color", ColorRGBA.Green);
AbstractHeightMap heightmap = null;
try {
heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.25f);
heightmap.load();
- } catch (Exception e) { }
+ } catch (Exception e) {
+ }
terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
List<Camera> cameras = new ArrayList<Camera>();
// let them drop from the sky
for (int i = 0; i < 5; i++) {
float r = (float) (8 * Math.random());
- Geometry sphere = new Geometry("cannonball",new Sphere(10, 10, r) );
+ Geometry sphere = new Geometry("cannonball", new Sphere(10, 10, r));
sphere.setMaterial(matWire);
float x = (float) (20 * Math.random()) - 40; // random position
float y = (float) (20 * Math.random()) - 40; // random position
float z = (float) (20 * Math.random()) - 40; // random position
sphere.setLocalTranslation(new Vector3f(x, 100 + y, z));
- sphere.addControl(new RigidBodyControl(new SphereCollisionShape(r),2));
+ sphere.addControl(new RigidBodyControl(new SphereCollisionShape(r), 2));
rootNode.attachChild(sphere);
bulletAppState.getPhysicsSpace().add(sphere);
}
- collisionBox = new Geometry("collisionBox",new Box(2, 2, 2));
+ collisionBox = new Geometry("collisionBox", new Box(2, 2, 2));
collisionBox.setModelBound(new BoundingBox());
collisionBox.setLocalTranslation(new Vector3f(20, 95, 30));
collisionBox.setMaterial(matWire);
Sphere s = new Sphere(6, 6, 1);
collisionMarker = new Geometry("collisionMarker");
collisionMarker.setMesh(s);
- Material mat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
+ Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Orange);
collisionMarker.setMaterial(mat);
rootNode.attachChild(collisionMarker);
}
Vector2f loc = new Vector2f(hit.getContactPoint().x, hit.getContactPoint().z);
float height = terrain.getHeight(loc);
- System.out.println("collide " + hit.getContactPoint() + ", height: " + height+", distance: "+hit.getDistance());
+ System.out.println("collide " + hit.getContactPoint() + ", height: " + height + ", distance: " + hit.getDistance());
collisionMarker.setLocalTranslation(new Vector3f(hit.getContactPoint().x, height, hit.getContactPoint().z));
}
} else if (binding.equals("cameraDown") && !keyPressed) {
- getCamera().setDirection(new Vector3f(0,-1,0));
- }
- else if (binding.equals("Lefts") && !keyPressed) {
+ getCamera().setDirection(new Vector3f(0, -1, 0));
+ } else if (binding.equals("Lefts") && !keyPressed) {
Vector3f oldLoc = selectedCollisionObject.getLocalTranslation().clone();
selectedCollisionObject.move(-0.5f, 0, 0);
testCollision(oldLoc);
- }
- else if (binding.equals("Rights") && !keyPressed) {
+ } else if (binding.equals("Rights") && !keyPressed) {
Vector3f oldLoc = selectedCollisionObject.getLocalTranslation().clone();
selectedCollisionObject.move(0.5f, 0, 0);
testCollision(oldLoc);
- }
- else if (binding.equals("Forwards") && !keyPressed) {
+ } else if (binding.equals("Forwards") && !keyPressed) {
Vector3f oldLoc = selectedCollisionObject.getLocalTranslation().clone();
selectedCollisionObject.move(0, 0, 0.5f);
testCollision(oldLoc);
- }
- else if (binding.equals("Backs") && !keyPressed) {
+ } else if (binding.equals("Backs") && !keyPressed) {
Vector3f oldLoc = selectedCollisionObject.getLocalTranslation().clone();
selectedCollisionObject.move(0, 0, -0.5f);
testCollision(oldLoc);
- }
- else if (binding.equals("Ups") && !keyPressed) {
+ } else if (binding.equals("Ups") && !keyPressed) {
Vector3f oldLoc = selectedCollisionObject.getLocalTranslation().clone();
selectedCollisionObject.move(0, 0.5f, 0);
testCollision(oldLoc);
- }
- else if (binding.equals("Downs") && !keyPressed) {
+ } else if (binding.equals("Downs") && !keyPressed) {
Vector3f oldLoc = selectedCollisionObject.getLocalTranslation().clone();
selectedCollisionObject.move(0, -0.5f, 0);
testCollision(oldLoc);
};
private void testCollision(Vector3f oldLoc) {
- if (terrain.collideWith(selectedCollisionObject.getWorldBound(), new CollisionResults()) > 0)
+ if (terrain.collideWith(selectedCollisionObject.getWorldBound(), new CollisionResults()) > 0) {
selectedCollisionObject.setLocalTranslation(oldLoc);
+ }
}
}
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package jme3test.terrain;
import com.jme3.app.SimpleApplication;
public class TerrainTestModifyHeight extends SimpleApplication {
private TerrainQuad terrain;
- Material matTerrain;
- Material matWire;
- boolean wireframe = false;
+ Material matTerrain;
+ Material matWire;
+ boolean wireframe = false;
boolean triPlanar = false;
boolean wardiso = false;
boolean minnaert = false;
- protected BitmapText hintText;
+ protected BitmapText hintText;
private float grassScale = 64;
private float dirtScale = 16;
private float rockScale = 128;
app.start();
}
-
@Override
- public void initialize() {
- super.initialize();
+ public void initialize() {
+ super.initialize();
- loadHintText();
+ loadHintText();
initCrossHairs();
- }
+ }
@Override
public void update() {
super.update();
-
+
updateHintText();
}
- @Override
- public void simpleInitApp() {
- setupKeys();
+ @Override
+ public void simpleInitApp() {
+ setupKeys();
// 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");
+ // TERRAIN TEXTURE material
+ matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
matTerrain.setBoolean("useTriPlanarMapping", false);
matTerrain.setBoolean("WardIso", true);
- // 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);
-
- // WIREFRAME material
- matWire = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
+ // 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);
+
+ // WIREFRAME material
+ matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
+ matWire.getAdditionalRenderState().setWireframe(true);
matWire.setColor("Color", ColorRGBA.Green);
// CREATE THE TERRAIN
- terrain = new TerrainQuad("terrain", 65, 513, null);
- List<Camera> cameras = new ArrayList<Camera>();
- cameras.add(getCamera());
- TerrainLodControl control = new TerrainLodControl(terrain, cameras);
- terrain.addControl(control);
- terrain.setMaterial(matTerrain);
- terrain.setModelBound(new BoundingBox());
- terrain.updateModelBound();
- terrain.setLocalTranslation(0, -100, 0);
- terrain.setLocalScale(2f, 1f, 2f);
- rootNode.attachChild(terrain);
+ terrain = new TerrainQuad("terrain", 65, 513, null);
+ List<Camera> cameras = new ArrayList<Camera>();
+ cameras.add(getCamera());
+ TerrainLodControl control = new TerrainLodControl(terrain, cameras);
+ terrain.addControl(control);
+ terrain.setMaterial(matTerrain);
+ terrain.setModelBound(new BoundingBox());
+ terrain.updateModelBound();
+ terrain.setLocalTranslation(0, -100, 0);
+ terrain.setLocalScale(2f, 1f, 2f);
+ rootNode.attachChild(terrain);
DirectionalLight light = new DirectionalLight();
- light.setDirection((new Vector3f(-0.5f,-1f, -0.5f)).normalize());
+ light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
rootNode.addLight(light);
AmbientLight ambLight = new AmbientLight();
ambLight.setColor(new ColorRGBA(1f, 1f, 0.8f, 0.2f));
rootNode.addLight(ambLight);
- getCamera().getLocation().y = 10;
- getCamera().setDirection(new Vector3f(0, -1.5f, -1));
- }
+ getCamera().getLocation().y = 10;
+ getCamera().setDirection(new Vector3f(0, -1.5f, -1));
+ }
- public void loadHintText() {
- hintText = new BitmapText(guiFont, false);
- hintText.setSize(guiFont.getCharSet().getRenderedSize());
- hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
- hintText.setText("Hit 1 to raise terrain, hit 2 to lower terrain");
- guiNode.attachChild(hintText);
- }
+ public void loadHintText() {
+ hintText = new BitmapText(guiFont, false);
+ hintText.setSize(guiFont.getCharSet().getRenderedSize());
+ hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
+ hintText.setText("Hit 1 to raise terrain, hit 2 to lower terrain");
+ guiNode.attachChild(hintText);
+ }
public void updateHintText() {
int x = (int) getCamera().getLocation().x;
int y = (int) getCamera().getLocation().y;
int z = (int) getCamera().getLocation().z;
- hintText.setText("Hit 1 to raise terrain, hit 2 to lower terrain. "+x+","+y+","+z);
+ hintText.setText("Hit 1 to raise terrain, hit 2 to lower terrain. " + x + "," + y + "," + z);
}
protected void initCrossHairs() {
guiNode.attachChild(ch);
}
- private void setupKeys() {
- flyCam.setMoveSpeed(100);
- inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
- inputManager.addListener(actionListener, "wireframe");
+ private void setupKeys() {
+ flyCam.setMoveSpeed(100);
+ inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
+ inputManager.addListener(actionListener, "wireframe");
inputManager.addMapping("Raise", new KeyTrigger(KeyInput.KEY_1));
inputManager.addListener(actionListener, "Raise");
inputManager.addMapping("Lower", new KeyTrigger(KeyInput.KEY_2));
inputManager.addListener(actionListener, "Lower");
- }
-
- private ActionListener actionListener = new ActionListener() {
-
- public void onAction(String name, boolean pressed, float tpf) {
- if (name.equals("wireframe") && !pressed) {
- wireframe = !wireframe;
- if (!wireframe) {
- terrain.setMaterial(matWire);
- } else {
- terrain.setMaterial(matTerrain);
- }
- } else if (name.equals("Raise")) {
+ }
+ private ActionListener actionListener = new ActionListener() {
+
+ public void onAction(String name, boolean pressed, float tpf) {
+ if (name.equals("wireframe") && !pressed) {
+ wireframe = !wireframe;
+ if (!wireframe) {
+ terrain.setMaterial(matWire);
+ } else {
+ terrain.setMaterial(matTerrain);
+ }
+ } else if (name.equals("Raise")) {
if (pressed) {
Vector3f intersection = getWorldIntersection();
if (intersection != null) {
}
}
}
-
- }
- };
+
+ }
+ };
private void adjustHeight(Vector3f loc, float radius, float height) {
-
+
// offset it by radius because in the loop we iterate through 2 radii
int radiusStepsX = (int) (radius / terrain.getLocalScale().x);
int radiusStepsZ = (int) (radius / terrain.getLocalScale().z);
float xStepAmount = terrain.getLocalScale().x;
float zStepAmount = terrain.getLocalScale().z;
-long start = System.currentTimeMillis();
- for (int z=-radiusStepsZ; z<radiusStepsZ; z++) {
- for (int x=-radiusStepsZ; x<radiusStepsX; x++) {
-
- float locX = loc.x + (x*xStepAmount);
- float locZ = loc.z + (z*zStepAmount);
-
- if (isInRadius(locX-loc.x,locZ-loc.z,radius)) {
+ long start = System.currentTimeMillis();
+ for (int z = -radiusStepsZ; z < radiusStepsZ; z++) {
+ for (int x = -radiusStepsZ; x < radiusStepsX; x++) {
+
+ float locX = loc.x + (x * xStepAmount);
+ float locZ = loc.z + (z * zStepAmount);
+
+ if (isInRadius(locX - loc.x, locZ - loc.z, radius)) {
// see if it is in the radius of the tool
- float h = calculateHeight(radius, height, locX-loc.x, locZ-loc.z);
-
- // increase the height
- terrain.adjustHeight(new Vector2f(locX, locZ), h);
- }
- }
- }
- System.out.println("took: "+(System.currentTimeMillis()-start));
+ float h = calculateHeight(radius, height, locX - loc.x, locZ - loc.z);
+
+ // increase the height
+ terrain.adjustHeight(new Vector2f(locX, locZ), h);
+ }
+ }
+ }
+ System.out.println("took: " + (System.currentTimeMillis() - start));
terrain.updateModelBound();
}
private boolean isInRadius(float x, float y, float radius) {
- Vector2f point = new Vector2f(x,y);
- // return true if the distance is less than equal to the radius
- return point.length() <= radius;
- }
+ Vector2f point = new Vector2f(x, y);
+ // return true if the distance is less than equal to the radius
+ return point.length() <= radius;
+ }
private float calculateHeight(float radius, float heightFactor, float x, float z) {
// find percentage for each 'unit' in radius
- Vector2f point = new Vector2f(x,z);
+ Vector2f point = new Vector2f(x, z);
float val = point.length() / radius;
val = 1 - val;
- if (val <= 0)
+ if (val <= 0) {
val = 0;
+ }
return heightFactor * val;
- }
+ }
private Vector3f getWorldIntersection() {
Vector3f origin = cam.getWorldCoordinates(new Vector2f(settings.getWidth() / 2, settings.getHeight() / 2), 0.0f);
matTerrain.setBoolean("useTriPlanarMapping", false);
matTerrain.setBoolean("WardIso", true);
- // ALPHA map (for splat textures)
- matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
+ // ALPHA map (for splat textures)
+ matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
- // HEIGHTMAP image (for the terrain heightmap)
- Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
+ // HEIGHTMAP image (for the terrain heightmap)
+ Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.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);
+ // 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);
+ // 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);
+ // 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);
Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.png");
matTerrain.setTexture("NormalMap_1", normalMap2);
matTerrain.setTexture("NormalMap_2", normalMap2);
- matWire = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
+ matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
+ matWire.getAdditionalRenderState().setWireframe(true);
matWire.setColor("Color", ColorRGBA.Green);
// CREATE HEIGHTMAP
- AbstractHeightMap heightmap = null;
- try {
- //heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3);
+ AbstractHeightMap heightmap = null;
+ try {
+ //heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3);
- heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 1f);
- heightmap.load();
+ heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 1f);
+ heightmap.load();
- } catch (Exception e) {
- e.printStackTrace();
- }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
if (new File("terrainsave.jme").exists()) {
loadTerrain();
terrain.setLocalScale(2f, 1f, 2f);
rootNode.attachChild(terrain);
}
-
+
DirectionalLight light = new DirectionalLight();
- light.setDirection((new Vector3f(-0.5f,-1f, -0.5f)).normalize());
+ light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
rootNode.addLight(light);
}
*/
private void createControls() {
flyCam.setMoveSpeed(50);
- cam.setLocation(new Vector3f(0,100,0));
+ cam.setLocation(new Vector3f(0, 100, 0));
inputManager.addMapping("save", new KeyTrigger(KeyInput.KEY_T));
inputManager.addListener(saveActionListener, "save");
}
}
}
-
private ActionListener loadActionListener = new ActionListener() {
public void onAction(String name, boolean pressed, float tpf) {
TextureKey key = new TextureKey(texName, true);
key.setGenerateMips(false);
Texture tex = assetManager.loadTexture(key);
- Material mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", tex);
// mat.setBoolean("Normalize", true);
if (latc)
private WaterFilter water;
TerrainQuad terrain;
Material matRock;
- Material matWire;
public static void main(String[] args) {
TestPostWater app = new TestPostWater();
matRock.setTexture("NormalMap_1", normalMap2);
matRock.setTexture("NormalMap_2", normalMap2);
- matWire = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
- matWire.setColor("Color", ColorRGBA.Green);
AbstractHeightMap heightmap = null;
try {
heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.25f);
sun.setColor(ColorRGBA.White.clone().multLocal(2));
scene.addLight(sun);
- Material mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
//add lightPos Geometry
Sphere lite=new Sphere(8, 8, 3.0f);
cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
//init scene
sceneNode = new Node("Scene");
- mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
+ mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
Box b = new Box(1, 1, 1);
Geometry geom = new Geometry("Box", b);