use of com.jme3.light.PointLight in project jmonkeyengine by jMonkeyEngine.
the class LightControl method spatialTolight.
private void spatialTolight(Light light) {
if (light instanceof PointLight) {
((PointLight) light).setPosition(spatial.getWorldTranslation());
}
TempVars vars = TempVars.get();
if (light instanceof DirectionalLight) {
((DirectionalLight) light).setDirection(vars.vect1.set(spatial.getWorldTranslation()).multLocal(-1.0f));
}
if (light instanceof SpotLight) {
((SpotLight) light).setPosition(spatial.getWorldTranslation());
((SpotLight) light).setDirection(spatial.getWorldRotation().multLocal(vars.vect1.set(Vector3f.UNIT_Y).multLocal(-1)));
}
vars.release();
}
use of com.jme3.light.PointLight in project jmonkeyengine by jMonkeyEngine.
the class SceneLoader method endElement.
@Override
public void endElement(String uri, String name, String qName) throws SAXException {
if (qName.equals("node")) {
node = node.getParent();
} else if (qName.equals("nodes")) {
node = null;
} else if (qName.equals("entity")) {
node = entityNode.getParent();
entityNode = null;
} else if (qName.equals("camera")) {
node = cameraNode.getParent();
cameraNode = null;
} else if (qName.equals("light")) {
// apply the node's world transform on the light..
root.updateGeometricState();
if (light != null) {
if (light instanceof DirectionalLight) {
DirectionalLight dl = (DirectionalLight) light;
Quaternion q = node.getWorldRotation();
Vector3f dir = dl.getDirection();
q.multLocal(dir);
dl.setDirection(dir);
} else if (light instanceof PointLight) {
PointLight pl = (PointLight) light;
Vector3f pos = node.getWorldTranslation();
pl.setPosition(pos);
} else if (light instanceof SpotLight) {
SpotLight sl = (SpotLight) light;
Vector3f pos = node.getWorldTranslation();
sl.setPosition(pos);
Quaternion q = node.getWorldRotation();
Vector3f dir = sl.getDirection();
q.multLocal(dir);
sl.setDirection(dir);
}
}
light = null;
}
checkTopNode(qName);
elementStack.pop();
}
use of com.jme3.light.PointLight in project jmonkeyengine by jMonkeyEngine.
the class TestTexture3D method simpleInitApp.
@Override
public void simpleInitApp() {
//mouseInput.setCursorVisible(true);
flyCam.setMoveSpeed(10);
//creating a sphere
Sphere sphere = new Sphere(32, 32, 1);
//getting the boundingbox
sphere.updateBound();
BoundingBox bb = (BoundingBox) sphere.getBound();
Vector3f min = bb.getMin(null);
float[] ext = new float[] { bb.getXExtent() * 2, bb.getYExtent() * 2, bb.getZExtent() * 2 };
//we need to change the UV coordinates (the sphere is assumet to be inside the 3D image box)
sphere.clearBuffer(Type.TexCoord);
VertexBuffer vb = sphere.getBuffer(Type.Position);
FloatBuffer fb = (FloatBuffer) vb.getData();
float[] uvCoordinates = BufferUtils.getFloatArray(fb);
//now transform the coordinates so that they are in the range of <0; 1>
for (int i = 0; i < uvCoordinates.length; i += 3) {
uvCoordinates[i] = (uvCoordinates[i] - min.x) / ext[0];
uvCoordinates[i + 1] = (uvCoordinates[i + 1] - min.y) / ext[1];
uvCoordinates[i + 2] = (uvCoordinates[i + 2] - min.z) / ext[2];
}
//apply new texture coordinates
VertexBuffer uvCoordsBuffer = new VertexBuffer(Type.TexCoord);
uvCoordsBuffer.setupData(Usage.Static, 3, com.jme3.scene.VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(uvCoordinates));
sphere.setBuffer(uvCoordsBuffer);
//create geometry, and apply material and our 3D texture
Geometry g = new Geometry("sphere", sphere);
Material material = new Material(assetManager, "jme3test/texture/tex3D.j3md");
try {
Texture texture = this.getTexture();
material.setTexture("Texture", texture);
} catch (IOException e) {
e.printStackTrace();
}
g.setMaterial(material);
rootNode.attachChild(g);
//add some light so that it is visible
PointLight light = new PointLight();
light.setColor(ColorRGBA.White);
light.setPosition(new Vector3f(5, 5, 5));
light.setRadius(20);
rootNode.addLight(light);
light = new PointLight();
light.setColor(ColorRGBA.White);
light.setPosition(new Vector3f(-5, -5, -5));
light.setRadius(20);
rootNode.addLight(light);
}
use of com.jme3.light.PointLight in project jmonkeyengine by jMonkeyEngine.
the class TestJaime method setupLights.
public void setupLights() {
AmbientLight al = new AmbientLight();
al.setColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1));
rootNode.addLight(al);
SpotLight sl = new SpotLight();
sl.setColor(ColorRGBA.White.mult(1.0f));
sl.setPosition(new Vector3f(1.2074411f, 10.6868908f, 4.1489987f));
sl.setDirection(sl.getPosition().mult(-1));
sl.setSpotOuterAngle(0.1f);
sl.setSpotInnerAngle(0.004f);
rootNode.addLight(sl);
//pointlight to fake indirect light coming from the ground
PointLight pl = new PointLight();
pl.setColor(ColorRGBA.White.mult(1.5f));
pl.setPosition(new Vector3f(0, 0, 1));
pl.setRadius(2);
rootNode.addLight(pl);
SpotLightShadowRenderer shadows = new SpotLightShadowRenderer(assetManager, 1024);
shadows.setLight(sl);
shadows.setShadowIntensity(0.3f);
shadows.setEdgeFilteringMode(EdgeFilteringMode.PCF8);
viewPort.addProcessor(shadows);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
SSAOFilter filter = new SSAOFilter(0.10997847f, 0.440001f, 0.39999998f, -0.008000026f);
;
fpp.addFilter(filter);
fpp.addFilter(new FXAAFilter());
fpp.addFilter(new FXAAFilter());
viewPort.addProcessor(fpp);
}
use of com.jme3.light.PointLight in project jmonkeyengine by jMonkeyEngine.
the class LightHelper method toLight.
public Light toLight(Structure structure, BlenderContext blenderContext) throws BlenderFileException {
Light result = (Light) blenderContext.getLoadedFeature(structure.getOldMemoryAddress(), LoadedDataType.FEATURE);
if (result != null) {
return result;
}
Light light = null;
int type = ((Number) structure.getFieldValue("type")).intValue();
switch(type) {
case // Lamp
0:
light = new PointLight();
float distance = ((Number) structure.getFieldValue("dist")).floatValue();
((PointLight) light).setRadius(distance);
break;
case // Sun
1:
LOGGER.log(Level.WARNING, "'Sun' lamp is not supported in jMonkeyEngine. Using PointLight with radius = Float.MAX_VALUE.");
light = new PointLight();
((PointLight) light).setRadius(Float.MAX_VALUE);
break;
case // Spot
2:
light = new SpotLight();
// range
((SpotLight) light).setSpotRange(((Number) structure.getFieldValue("dist")).floatValue());
// outer angle
float outerAngle = ((Number) structure.getFieldValue("spotsize")).floatValue() * FastMath.DEG_TO_RAD * 0.5f;
((SpotLight) light).setSpotOuterAngle(outerAngle);
// inner angle
float spotblend = ((Number) structure.getFieldValue("spotblend")).floatValue();
spotblend = FastMath.clamp(spotblend, 0, 1);
float innerAngle = outerAngle * (1 - spotblend);
((SpotLight) light).setSpotInnerAngle(innerAngle);
break;
case // Hemi
3:
LOGGER.log(Level.WARNING, "'Hemi' lamp is not supported in jMonkeyEngine. Using DirectionalLight instead.");
case // Area
4:
light = new DirectionalLight();
break;
default:
throw new BlenderFileException("Unknown light source type: " + type);
}
float r = ((Number) structure.getFieldValue("r")).floatValue();
float g = ((Number) structure.getFieldValue("g")).floatValue();
float b = ((Number) structure.getFieldValue("b")).floatValue();
light.setColor(new ColorRGBA(r, g, b, 1.0f));
light.setName(structure.getName());
return light;
}
Aggregations