Search in sources :

Example 1 with BoundingSphere

use of com.jme3.bounding.BoundingSphere in project jmonkeyengine by jMonkeyEngine.

the class LightsDebugState method update.

@Override
public void update(float tpf) {
    for (Light light : scene.getWorldLightList()) {
        switch(light.getType()) {
            case Probe:
                LightProbe probe = (LightProbe) light;
                probes.add(probe);
                Node n = probeMapping.get(probe);
                if (n == null) {
                    n = new Node("DebugProbe");
                    n.attachChild(debugGeom.clone(true));
                    n.attachChild(debugBounds.clone(false));
                    debugNode.attachChild(n);
                    probeMapping.put(probe, n);
                }
                Geometry probeGeom = ((Geometry) n.getChild(0));
                Material m = probeGeom.getMaterial();
                probeGeom.setLocalScale(probeScale);
                if (probe.isReady()) {
                    if (debugMode == DebugMode.IrradianceMap) {
                        m.setTexture("CubeMap", probe.getIrradianceMap());
                    } else {
                        m.setTexture("CubeMap", probe.getPrefilteredEnvMap());
                    }
                }
                n.setLocalTranslation(probe.getPosition());
                n.getChild(1).setLocalScale(((BoundingSphere) probe.getBounds()).getRadius());
                break;
            default:
                break;
        }
    }
    debugNode.updateLogicalState(tpf);
    debugNode.updateGeometricState();
    cleanProbes();
}
Also used : Geometry(com.jme3.scene.Geometry) LightProbe(com.jme3.light.LightProbe) Light(com.jme3.light.Light) Node(com.jme3.scene.Node) Material(com.jme3.material.Material)

Example 2 with BoundingSphere

use of com.jme3.bounding.BoundingSphere in project jmonkeyengine by jMonkeyEngine.

the class SpotLight method intersectsSphere.

@Override
public boolean intersectsSphere(BoundingSphere sphere, TempVars vars) {
    if (this.spotRange > 0f) {
        // Sphere v. sphere collision
        if (!Intersection.intersect(sphere, position, spotRange)) {
            return false;
        }
    }
    float otherRadiusSquared = FastMath.sqr(sphere.getRadius());
    float otherRadius = sphere.getRadius();
    // Check if sphere is within spot angle.
    // Cone v. sphere collision.
    Vector3f E = direction.mult(otherRadius * outerAngleSinRcp, vars.vect1);
    Vector3f U = position.subtract(E, vars.vect2);
    Vector3f D = sphere.getCenter().subtract(U, vars.vect3);
    float dsqr = D.dot(D);
    float e = direction.dot(D);
    if (e > 0f && e * e >= dsqr * outerAngleCosSqr) {
        D = sphere.getCenter().subtract(position, vars.vect3);
        dsqr = D.dot(D);
        e = -direction.dot(D);
        if (e > 0f && e * e >= dsqr * outerAngleSinSqr) {
            return dsqr <= otherRadiusSquared;
        } else {
            return true;
        }
    }
    return false;
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 3 with BoundingSphere

use of com.jme3.bounding.BoundingSphere in project jmonkeyengine by jMonkeyEngine.

the class DefaultLightFilter method filterLights.

@Override
public void filterLights(Geometry geometry, LightList filteredLightList) {
    TempVars vars = TempVars.get();
    try {
        LightList worldLights = geometry.getWorldLightList();
        for (int i = 0; i < worldLights.size(); i++) {
            Light light = worldLights.get(i);
            // If this light is not enabled it will be ignored.
            if (!light.isEnabled()) {
                continue;
            }
            if (light.frustumCheckNeeded) {
                processedLights.add(light);
                light.frustumCheckNeeded = false;
                light.intersectsFrustum = light.intersectsFrustum(camera, vars);
            }
            if (!light.intersectsFrustum) {
                continue;
            }
            BoundingVolume bv = geometry.getWorldBound();
            if (bv instanceof BoundingBox) {
                if (!light.intersectsBox((BoundingBox) bv, vars)) {
                    continue;
                }
            } else if (bv instanceof BoundingSphere) {
                if (!Float.isInfinite(((BoundingSphere) bv).getRadius())) {
                    if (!light.intersectsSphere((BoundingSphere) bv, vars)) {
                        continue;
                    }
                }
            }
            if (light.getType() == Light.Type.Probe) {
                probeBlendStrat.registerProbe((LightProbe) light);
            } else {
                filteredLightList.add(light);
            }
        }
        probeBlendStrat.populateProbes(geometry, filteredLightList);
    } finally {
        vars.release();
    }
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) BoundingBox(com.jme3.bounding.BoundingBox) BoundingVolume(com.jme3.bounding.BoundingVolume) TempVars(com.jme3.util.TempVars)

Example 4 with BoundingSphere

use of com.jme3.bounding.BoundingSphere in project jmonkeyengine by jMonkeyEngine.

the class LightProbe method write.

@Override
public void write(JmeExporter ex) throws IOException {
    super.write(ex);
    OutputCapsule oc = ex.getCapsule(this);
    oc.write(irradianceMap, "irradianceMap", null);
    oc.write(prefilteredEnvMap, "prefilteredEnvMap", null);
    oc.write(position, "position", null);
    oc.write(bounds, "bounds", new BoundingSphere(1.0f, Vector3f.ZERO));
    oc.write(ready, "ready", false);
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) OutputCapsule(com.jme3.export.OutputCapsule)

Example 5 with BoundingSphere

use of com.jme3.bounding.BoundingSphere in project jmonkeyengine by jMonkeyEngine.

the class LightProbe method read.

@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);
    irradianceMap = (TextureCubeMap) ic.readSavable("irradianceMap", null);
    prefilteredEnvMap = (TextureCubeMap) ic.readSavable("prefilteredEnvMap", null);
    position = (Vector3f) ic.readSavable("position", this);
    bounds = (BoundingVolume) ic.readSavable("bounds", new BoundingSphere(1.0f, Vector3f.ZERO));
    ready = ic.readBoolean("ready", false);
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) InputCapsule(com.jme3.export.InputCapsule)

Aggregations

BoundingSphere (com.jme3.bounding.BoundingSphere)24 Vector3f (com.jme3.math.Vector3f)9 BoundingBox (com.jme3.bounding.BoundingBox)8 TempVars (com.jme3.util.TempVars)7 Test (org.junit.Test)7 BoundingVolume (com.jme3.bounding.BoundingVolume)5 Geometry (com.jme3.scene.Geometry)5 LightProbe (com.jme3.light.LightProbe)4 EnvironmentCamera (com.jme3.environment.EnvironmentCamera)3 Material (com.jme3.material.Material)3 Node (com.jme3.scene.Node)2 ArrayList (java.util.ArrayList)2 UnsupportedCollisionException (com.jme3.collision.UnsupportedCollisionException)1 InputCapsule (com.jme3.export.InputCapsule)1 OutputCapsule (com.jme3.export.OutputCapsule)1 Light (com.jme3.light.Light)1 Triangle (com.jme3.math.Triangle)1 Vector2f (com.jme3.math.Vector2f)1 Mesh (com.jme3.scene.Mesh)1 Spatial (com.jme3.scene.Spatial)1