use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.
the class SceneLoader method startElement.
@Override
public void startElement(String uri, String localName, String qName, Attributes attribs) throws SAXException {
if (qName.equals("scene")) {
if (elementStack.size() != 0) {
throw new SAXException("dotScene parse error: 'scene' element must be the root XML element");
}
String version = attribs.getValue("formatVersion");
if (version == null || (!version.equals("1.0.0") && !version.equals("1.0.1"))) {
logger.log(Level.WARNING, "Unrecognized version number" + " in dotScene file: {0}", version);
}
} else if (qName.equals("nodes")) {
if (root != null) {
throw new SAXException("dotScene parse error: nodes element was specified twice");
}
if (sceneName == null) {
root = new com.jme3.scene.Node("OgreDotScene" + (++sceneIdx));
} else {
root = new com.jme3.scene.Node(sceneName + "-scene_node");
}
node = root;
} else if (qName.equals("externals")) {
checkTopNode("scene");
} else if (qName.equals("item")) {
checkTopNode("externals");
} else if (qName.equals("file")) {
checkTopNode("item");
// NOTE: This part of the file is ignored, it is parsed
// by SceneMaterialLoader in the first pass.
} else if (qName.equals("node")) {
String curElement = elementStack.peek();
if (!curElement.equals("node") && !curElement.equals("nodes")) {
throw new SAXException("dotScene parse error: " + "node element can only appear under 'node' or 'nodes'");
}
parseNode(attribs);
} else if (qName.equals("property")) {
if (node != null) {
String type = attribs.getValue("type");
String name = attribs.getValue("name");
String data = attribs.getValue("data");
if (type.equals("BOOL")) {
node.setUserData(name, Boolean.parseBoolean(data) || data.equals("1"));
} else if (type.equals("FLOAT")) {
node.setUserData(name, Float.parseFloat(data));
} else if (type.equals("STRING")) {
node.setUserData(name, data);
} else if (type.equals("INT")) {
node.setUserData(name, Integer.parseInt(data));
}
}
} else if (qName.equals("entity")) {
checkTopNode("node");
parseEntity(attribs);
} else if (qName.equals("camera")) {
checkTopNode("node");
parseCamera(attribs);
} else if (qName.equals("clipping")) {
checkTopNode("camera");
parseCameraClipping(attribs);
} else if (qName.equals("position")) {
if (elementStack.peek().equals("node")) {
node.setLocalTranslation(SAXUtil.parseVector3(attribs));
} else if (elementStack.peek().equals("camera")) {
cameraNode.setLocalTranslation(SAXUtil.parseVector3(attribs));
}
} else if (qName.equals("quaternion") || qName.equals("rotation")) {
node.setLocalRotation(parseQuat(attribs));
} else if (qName.equals("scale")) {
node.setLocalScale(SAXUtil.parseVector3(attribs));
} else if (qName.equals("light")) {
parseLight(attribs);
} else if (qName.equals("colourDiffuse") || qName.equals("colorDiffuse")) {
if (elementStack.peek().equals("light")) {
if (light != null) {
light.setColor(parseColor(attribs));
}
} else {
checkTopNode("environment");
}
} else if (qName.equals("colourAmbient") || qName.equals("colorAmbient")) {
if (elementStack.peek().equals("environment")) {
ColorRGBA color = parseColor(attribs);
if (!color.equals(ColorRGBA.Black) && !color.equals(ColorRGBA.BlackNoAlpha)) {
// Lets add an ambient light to the scene.
AmbientLight al = new AmbientLight();
al.setColor(color);
root.addLight(al);
}
}
} else if (qName.equals("normal") || qName.equals("direction")) {
checkTopNode("light");
parseLightNormal(attribs);
} else if (qName.equals("lightAttenuation")) {
parseLightAttenuation(attribs);
} else if (qName.equals("spotLightRange") || qName.equals("lightRange")) {
parseLightSpotLightRange(attribs);
}
elementStack.push(qName);
}
use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.
the class TestReverb method simpleInitApp.
@Override
public void simpleInitApp() {
audioSource = new AudioNode(assetManager, "Sound/Effects/Bang.wav");
float[] eax = new float[] { 15, 38.0f, 0.300f, -1000, -3300, 0, 1.49f, 0.54f, 1.00f, -2560, 0.162f, 0.00f, 0.00f, 0.00f, -229, 0.088f, 0.00f, 0.00f, 0.00f, 0.125f, 1.000f, 0.250f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.00f, 0x3f };
audioRenderer.setEnvironment(new Environment(eax));
Environment env = Environment.Cavern;
audioRenderer.setEnvironment(env);
}
use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.
the class LightsDebugState method initialize.
@Override
protected void initialize(Application app) {
debugNode = new Node("Environment debug Node");
Sphere s = new Sphere(16, 16, 1);
debugGeom = new Geometry("debugEnvProbe", s);
debugMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/reflect.j3md");
debugGeom.setMaterial(debugMaterial);
debugBounds = BoundingSphereDebug.createDebugSphere(app.getAssetManager());
if (scene == null) {
scene = app.getViewPort().getScenes().get(0);
}
}
use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.
the class TestAmbient method simpleInitApp.
@Override
public void simpleInitApp() {
float[] eax = new float[] { 15, 38.0f, 0.300f, -1000, -3300, 0, 1.49f, 0.54f, 1.00f, -2560, 0.162f, 0.00f, 0.00f, 0.00f, -229, 0.088f, 0.00f, 0.00f, 0.00f, 0.125f, 1.000f, 0.250f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.00f, 0x3f };
Environment env = new Environment(eax);
audioRenderer.setEnvironment(env);
waves = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg", false);
waves.setPositional(true);
waves.setLocalTranslation(new Vector3f(0, 0, 0));
waves.setMaxDistance(100);
waves.setRefDistance(5);
nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", true);
nature.setPositional(false);
nature.setVolume(3);
waves.playInstance();
nature.play();
// just a blue box to mark the spot
Box box1 = new Box(.5f, .5f, .5f);
Geometry player = new Geometry("Player", box1);
Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Blue);
player.setMaterial(mat1);
rootNode.attachChild(player);
}
use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.
the class EnvMapUtils method getSphericalHarmonicsCoefficents.
/**
* Returns the Spherical Harmonics coefficients for this cube map.
*
* The method used is the one from this article :
* http://graphics.stanford.edu/papers/envmap/envmap.pdf
*
* Also good resources on spherical harmonics
* http://dickyjim.wordpress.com/2013/09/04/spherical-harmonics-for-beginners/
*
* @param cubeMap the environment cube map to compute SH for
* @param fixSeamsMethod method to fix seams when computing the SH
* coefficients
* @return an array of 9 vector3f representing thos coefficients for each
* r,g,b channnel
*/
public static Vector3f[] getSphericalHarmonicsCoefficents(TextureCubeMap cubeMap, FixSeamsMethod fixSeamsMethod) {
Vector3f[] shCoef = new Vector3f[NUM_SH_COEFFICIENT];
float[] shDir = new float[9];
float weightAccum = 0.0f;
float weight;
if (cubeMap.getImage().getData(0) == null) {
throw new IllegalStateException("The cube map must contain Efficient data, if you rendered the cube map on the GPU plase use renderer.readFrameBuffer, to create a CPU image");
}
int width = cubeMap.getImage().getWidth();
int height = cubeMap.getImage().getHeight();
Vector3f texelVect = new Vector3f();
ColorRGBA color = new ColorRGBA();
CubeMapWrapper envMapReader = new CubeMapWrapper(cubeMap);
for (int face = 0; face < 6; face++) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
weight = getSolidAngleAndVector(x, y, width, face, texelVect, fixSeamsMethod);
evalShBasis(texelVect, shDir);
envMapReader.getPixel(x, y, face, color);
for (int i = 0; i < NUM_SH_COEFFICIENT; i++) {
if (shCoef[i] == null) {
shCoef[i] = new Vector3f();
}
shCoef[i].setX(shCoef[i].x + color.r * shDir[i] * weight);
shCoef[i].setY(shCoef[i].y + color.g * shDir[i] * weight);
shCoef[i].setZ(shCoef[i].z + color.b * shDir[i] * weight);
}
weightAccum += weight;
}
}
}
/* Normalization - The sum of solid angle should be equal to the solid angle of the sphere (4 PI), so
* normalize in order our weightAccum exactly match 4 PI. */
for (int i = 0; i < NUM_SH_COEFFICIENT; ++i) {
shCoef[i].multLocal(4.0f * PI / weightAccum);
}
return shCoef;
}
Aggregations