Search in sources :

Example 76 with Light

use of com.jme3.light.Light in project jmonkeyengine by jMonkeyEngine.

the class LightControl method write.

@Override
public void write(JmeExporter ex) throws IOException {
    super.write(ex);
    OutputCapsule oc = ex.getCapsule(this);
    oc.write(controlDir, CONTROL_DIR_NAME, ControlDirection.SpatialToLight);
    oc.write(light, LIGHT_NAME, null);
}
Also used : OutputCapsule(com.jme3.export.OutputCapsule)

Example 77 with Light

use of com.jme3.light.Light in project jmonkeyengine by jMonkeyEngine.

the class LightControl method read.

@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);
    controlDir = ic.readEnum(CONTROL_DIR_NAME, ControlDirection.class, ControlDirection.SpatialToLight);
    light = (Light) ic.readSavable(LIGHT_NAME, null);
}
Also used : InputCapsule(com.jme3.export.InputCapsule)

Example 78 with Light

use of com.jme3.light.Light in project jmonkeyengine by jMonkeyEngine.

the class DirectionalLightShadowRenderer method write.

@Override
public void write(JmeExporter ex) throws IOException {
    super.write(ex);
    OutputCapsule oc = ex.getCapsule(this);
    oc.write(lambda, "lambda", 0.65f);
    oc.write(zFarOverride, "zFarOverride", 0);
    oc.write(light, "light", null);
    oc.write(fadeInfo, "fadeInfo", null);
    oc.write(fadeLength, "fadeLength", 0f);
}
Also used : OutputCapsule(com.jme3.export.OutputCapsule)

Example 79 with Light

use of com.jme3.light.Light in project jmonkeyengine by jMonkeyEngine.

the class OBJLoader method createGeometry.

protected Geometry createGeometry(ArrayList<Face> faceList, String matName) throws IOException {
    if (faceList.isEmpty())
        throw new IOException("No geometry data to generate mesh");
    // Create mesh from the faces
    Mesh mesh = constructMesh(faceList);
    Geometry geom = new Geometry(objName + "-geom-" + (geomIndex++), mesh);
    Material material = null;
    if (matName != null && matList != null) {
        // Get material from material list
        material = matList.get(matName);
    }
    if (material == null) {
        // create default material
        material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        material.setFloat("Shininess", 64);
    }
    geom.setMaterial(material);
    if (material.isTransparent())
        geom.setQueueBucket(Bucket.Transparent);
    else
        geom.setQueueBucket(Bucket.Opaque);
    if (material.getMaterialDef().getName().contains("Lighting") && mesh.getFloatBuffer(Type.Normal) == null) {
        logger.log(Level.WARNING, "OBJ mesh {0} doesn't contain normals! " + "It might not display correctly", geom.getName());
    }
    return geom;
}
Also used : Material(com.jme3.material.Material) IOException(java.io.IOException)

Example 80 with Light

use of com.jme3.light.Light in project jmonkeyengine by jMonkeyEngine.

the class LightFilterTest method testPointFiltering.

@Test
public void testPointFiltering() {
    PointLight pl = new PointLight(Vector3f.ZERO);
    geom.addLight(pl);
    // Infinite point lights must never be filtered
    checkFilteredLights(1);
    // Light at origin does not intersect geom which is at Z=10
    pl.setRadius(1);
    checkFilteredLights(0);
    // Put it closer to geom, the very edge of the sphere touches the box.
    // Still not considered an intersection though.
    pl.setPosition(new Vector3f(0, 0, 8f));
    checkFilteredLights(0);
    // And more close - now its an intersection.
    pl.setPosition(new Vector3f(0, 0, 8f + FastMath.ZERO_TOLERANCE));
    checkFilteredLights(1);
    // Move the geometry away
    geom.move(0, 0, FastMath.ZERO_TOLERANCE);
    checkFilteredLights(0);
    // Test if the algorithm converts the sphere 
    // to a box before testing the collision (incorrect)
    float sqrt3 = FastMath.sqrt(3);
    pl.setPosition(new Vector3f(2, 2, 8));
    pl.setRadius(sqrt3);
    checkFilteredLights(0);
    // Make it a wee bit larger.
    pl.setRadius(sqrt3 + FastMath.ZERO_TOLERANCE);
    checkFilteredLights(1);
    // Rotate the camera so it is up, light is outside frustum.
    cam.lookAtDirection(Vector3f.UNIT_Y, Vector3f.UNIT_Y);
    checkFilteredLights(0);
    // ==================================
    // Tests for bounding Sphere
    geom.setModelBound(new BoundingSphere(1f, Vector3f.ZERO));
    geom.setLocalTranslation(0, 0, 2);
    pl.setPosition(new Vector3f(0, 0, 2f));
    // Infinite point lights must never be filtered
    pl.setRadius(0);
    checkFilteredLights(1);
    pl.setRadius(1f);
    // Put the light at the very close to the geom,
    // the very edge of the sphere touches the other bounding sphere
    // Still not considered an intersection though.
    pl.setPosition(new Vector3f(0, 0, 0));
    checkFilteredLights(0);
    // And more close - now its an intersection.
    pl.setPosition(new Vector3f(0, 0, 0f + FastMath.ZERO_TOLERANCE));
    checkFilteredLights(1);
    geom.setLocalTranslation(0, 0, 0);
    // In this case its an intersection for pointLight v. box
    // But not for pointLight v. sphere
    // Vector3f(0, 0.5f, 0.5f).normalize().mult(2) ~ >= (0.0, 1.4142135, 1.4142135)
    //pl.setPosition(new Vector3f(0, 0.5f, 0.5f).normalizeLocal().multLocal(2 + FastMath.ZERO_TOLERANCE));
    pl.setPosition(new Vector3f(0f, 1.4142135f, 1.4142135f).multLocal(1 + FastMath.ZERO_TOLERANCE));
    checkFilteredLights(0);
    // Make the distance a wee bit closer, now its an intersection
    //pl.setPosition(new Vector3f(0, 0.5f, 0.5f).normalizeLocal().multLocal(2 - FastMath.ZERO_TOLERANCE));
    pl.setPosition(new Vector3f(0f, 1.4142135f, 1.4142135f).multLocal(1 - FastMath.ZERO_TOLERANCE));
    checkFilteredLights(1);
    // it's a point light, also test for the other corner
    pl.setPosition(new Vector3f(0f, -1.4142135f, -1.4142135f).multLocal(1 - FastMath.ZERO_TOLERANCE));
    checkFilteredLights(0);
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) Vector3f(com.jme3.math.Vector3f) Test(org.junit.Test)

Aggregations

Vector3f (com.jme3.math.Vector3f)64 Material (com.jme3.material.Material)61 DirectionalLight (com.jme3.light.DirectionalLight)55 Geometry (com.jme3.scene.Geometry)52 PointLight (com.jme3.light.PointLight)27 Spatial (com.jme3.scene.Spatial)27 Box (com.jme3.scene.shape.Box)26 Sphere (com.jme3.scene.shape.Sphere)26 ColorRGBA (com.jme3.math.ColorRGBA)24 Quaternion (com.jme3.math.Quaternion)21 Node (com.jme3.scene.Node)21 AmbientLight (com.jme3.light.AmbientLight)20 Texture (com.jme3.texture.Texture)18 SpotLight (com.jme3.light.SpotLight)16 FilterPostProcessor (com.jme3.post.FilterPostProcessor)15 KeyTrigger (com.jme3.input.controls.KeyTrigger)11 Test (org.junit.Test)11 TempVars (com.jme3.util.TempVars)10 Light (com.jme3.light.Light)9 Camera (com.jme3.renderer.Camera)9