Search in sources :

Example 16 with PointLight

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();
}
Also used : DirectionalLight(com.jme3.light.DirectionalLight) TempVars(com.jme3.util.TempVars) PointLight(com.jme3.light.PointLight) SpotLight(com.jme3.light.SpotLight)

Example 17 with PointLight

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();
}
Also used : Quaternion(com.jme3.math.Quaternion) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) PointLight(com.jme3.light.PointLight) SpotLight(com.jme3.light.SpotLight)

Example 18 with PointLight

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);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) VertexBuffer(com.jme3.scene.VertexBuffer) BoundingBox(com.jme3.bounding.BoundingBox) Vector3f(com.jme3.math.Vector3f) FloatBuffer(java.nio.FloatBuffer) Material(com.jme3.material.Material) IOException(java.io.IOException) PointLight(com.jme3.light.PointLight) Texture(com.jme3.texture.Texture)

Example 19 with PointLight

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);
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) FXAAFilter(com.jme3.post.filters.FXAAFilter) ColorRGBA(com.jme3.math.ColorRGBA) Vector3f(com.jme3.math.Vector3f) FilterPostProcessor(com.jme3.post.FilterPostProcessor) PointLight(com.jme3.light.PointLight) SpotLightShadowRenderer(com.jme3.shadow.SpotLightShadowRenderer) SpotLight(com.jme3.light.SpotLight) AmbientLight(com.jme3.light.AmbientLight)

Example 20 with PointLight

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;
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) DirectionalLight(com.jme3.light.DirectionalLight) SpotLight(com.jme3.light.SpotLight) Light(com.jme3.light.Light) PointLight(com.jme3.light.PointLight) DirectionalLight(com.jme3.light.DirectionalLight) BlenderFileException(com.jme3.scene.plugins.blender.file.BlenderFileException) PointLight(com.jme3.light.PointLight) SpotLight(com.jme3.light.SpotLight)

Aggregations

PointLight (com.jme3.light.PointLight)30 Vector3f (com.jme3.math.Vector3f)28 Geometry (com.jme3.scene.Geometry)22 DirectionalLight (com.jme3.light.DirectionalLight)21 Sphere (com.jme3.scene.shape.Sphere)18 SpotLight (com.jme3.light.SpotLight)14 Material (com.jme3.material.Material)12 ColorRGBA (com.jme3.math.ColorRGBA)12 Quaternion (com.jme3.math.Quaternion)9 AmbientLight (com.jme3.light.AmbientLight)8 Node (com.jme3.scene.Node)8 Light (com.jme3.light.Light)5 Spatial (com.jme3.scene.Spatial)5 TempVars (com.jme3.util.TempVars)5 FilterPostProcessor (com.jme3.post.FilterPostProcessor)4 Box (com.jme3.scene.shape.Box)4 SpotLightShadowRenderer (com.jme3.shadow.SpotLightShadowRenderer)4 ActionListener (com.jme3.input.controls.ActionListener)3 KeyTrigger (com.jme3.input.controls.KeyTrigger)3 Uniform (com.jme3.shader.Uniform)3