Search in sources :

Example 21 with Filter

use of com.jme3.post.Filter in project jmonkeyengine by jMonkeyEngine.

the class BulletDebugAppState method updateJoints.

private void updateJoints() {
    HashMap<PhysicsJoint, Spatial> oldObjects = joints;
    joints = new HashMap<PhysicsJoint, Spatial>();
    Collection<PhysicsJoint> current = space.getJointList();
    //create new map
    for (Iterator<PhysicsJoint> it = current.iterator(); it.hasNext(); ) {
        PhysicsJoint physicsObject = it.next();
        //copy existing spatials
        if (oldObjects.containsKey(physicsObject)) {
            Spatial spat = oldObjects.get(physicsObject);
            joints.put(physicsObject, spat);
            oldObjects.remove(physicsObject);
        } else {
            if (filter == null || filter.displayObject(physicsObject)) {
                logger.log(Level.FINE, "Create new debug Joint");
                //create new spatial
                Node node = new Node(physicsObject.toString());
                node.addControl(new BulletJointDebugControl(this, physicsObject));
                joints.put(physicsObject, node);
                physicsDebugRootNode.attachChild(node);
            }
        }
    }
    //remove leftover spatials
    for (Map.Entry<PhysicsJoint, Spatial> entry : oldObjects.entrySet()) {
        PhysicsJoint object = entry.getKey();
        Spatial spatial = entry.getValue();
        spatial.removeFromParent();
    }
}
Also used : Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) PhysicsJoint(com.jme3.bullet.joints.PhysicsJoint) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with Filter

use of com.jme3.post.Filter in project jmonkeyengine by jMonkeyEngine.

the class BulletDebugAppState method updateVehicles.

private void updateVehicles() {
    HashMap<PhysicsVehicle, Spatial> oldObjects = vehicles;
    vehicles = new HashMap<PhysicsVehicle, Spatial>();
    Collection<PhysicsVehicle> current = space.getVehicleList();
    //create new map
    for (Iterator<PhysicsVehicle> it = current.iterator(); it.hasNext(); ) {
        PhysicsVehicle physicsObject = it.next();
        //copy existing spatials
        if (oldObjects.containsKey(physicsObject)) {
            Spatial spat = oldObjects.get(physicsObject);
            vehicles.put(physicsObject, spat);
            oldObjects.remove(physicsObject);
        } else {
            if (filter == null || filter.displayObject(physicsObject)) {
                logger.log(Level.FINE, "Create new debug Vehicle");
                //create new spatial
                Node node = new Node(physicsObject.toString());
                node.addControl(new BulletVehicleDebugControl(this, physicsObject));
                vehicles.put(physicsObject, node);
                physicsDebugRootNode.attachChild(node);
            }
        }
    }
    //remove leftover spatials
    for (Map.Entry<PhysicsVehicle, Spatial> entry : oldObjects.entrySet()) {
        PhysicsVehicle object = entry.getKey();
        Spatial spatial = entry.getValue();
        spatial.removeFromParent();
    }
}
Also used : PhysicsVehicle(com.jme3.bullet.objects.PhysicsVehicle) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with Filter

use of com.jme3.post.Filter in project jmonkeyengine by jMonkeyEngine.

the class BulletDebugAppState method updateRigidBodies.

private void updateRigidBodies() {
    HashMap<PhysicsRigidBody, Spatial> oldObjects = bodies;
    bodies = new HashMap<PhysicsRigidBody, Spatial>();
    Collection<PhysicsRigidBody> current = space.getRigidBodyList();
    //create new map
    for (Iterator<PhysicsRigidBody> it = current.iterator(); it.hasNext(); ) {
        PhysicsRigidBody physicsObject = it.next();
        //copy existing spatials
        if (oldObjects.containsKey(physicsObject)) {
            Spatial spat = oldObjects.get(physicsObject);
            bodies.put(physicsObject, spat);
            oldObjects.remove(physicsObject);
        } else {
            if (filter == null || filter.displayObject(physicsObject)) {
                logger.log(Level.FINE, "Create new debug RigidBody");
                //create new spatial
                Node node = new Node(physicsObject.toString());
                node.addControl(new BulletRigidBodyDebugControl(this, physicsObject));
                bodies.put(physicsObject, node);
                physicsDebugRootNode.attachChild(node);
            }
        }
    }
    //remove leftover spatials
    for (Map.Entry<PhysicsRigidBody, Spatial> entry : oldObjects.entrySet()) {
        PhysicsRigidBody object = entry.getKey();
        Spatial spatial = entry.getValue();
        spatial.removeFromParent();
    }
}
Also used : Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) PhysicsRigidBody(com.jme3.bullet.objects.PhysicsRigidBody) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with Filter

use of com.jme3.post.Filter in project jmonkeyengine by jMonkeyEngine.

the class ALAudioRenderer method updateSourceParam.

public void updateSourceParam(AudioSource src, AudioParam param) {
    checkDead();
    synchronized (threadLock) {
        if (audioDisabled) {
            return;
        }
        // it should be safe to just ignore the update
        if (src.getChannel() < 0) {
            return;
        }
        assert src.getChannel() >= 0;
        int id = channels[src.getChannel()];
        switch(param) {
            case Position:
                if (!src.isPositional()) {
                    return;
                }
                Vector3f pos = src.getPosition();
                al.alSource3f(id, AL_POSITION, pos.x, pos.y, pos.z);
                break;
            case Velocity:
                if (!src.isPositional()) {
                    return;
                }
                Vector3f vel = src.getVelocity();
                al.alSource3f(id, AL_VELOCITY, vel.x, vel.y, vel.z);
                break;
            case MaxDistance:
                if (!src.isPositional()) {
                    return;
                }
                al.alSourcef(id, AL_MAX_DISTANCE, src.getMaxDistance());
                break;
            case RefDistance:
                if (!src.isPositional()) {
                    return;
                }
                al.alSourcef(id, AL_REFERENCE_DISTANCE, src.getRefDistance());
                break;
            case ReverbFilter:
                if (!supportEfx || !src.isPositional() || !src.isReverbEnabled()) {
                    return;
                }
                int filter = EFX.AL_FILTER_NULL;
                if (src.getReverbFilter() != null) {
                    Filter f = src.getReverbFilter();
                    if (f.isUpdateNeeded()) {
                        updateFilter(f);
                    }
                    filter = f.getId();
                }
                al.alSource3i(id, EFX.AL_AUXILIARY_SEND_FILTER, reverbFxSlot, 0, filter);
                break;
            case ReverbEnabled:
                if (!supportEfx || !src.isPositional()) {
                    return;
                }
                if (src.isReverbEnabled()) {
                    updateSourceParam(src, AudioParam.ReverbFilter);
                } else {
                    al.alSource3i(id, EFX.AL_AUXILIARY_SEND_FILTER, 0, 0, EFX.AL_FILTER_NULL);
                }
                break;
            case IsPositional:
                if (!src.isPositional()) {
                    // Play in headspace
                    al.alSourcei(id, AL_SOURCE_RELATIVE, AL_TRUE);
                    al.alSource3f(id, AL_POSITION, 0, 0, 0);
                    al.alSource3f(id, AL_VELOCITY, 0, 0, 0);
                    // Disable reverb
                    al.alSource3i(id, EFX.AL_AUXILIARY_SEND_FILTER, 0, 0, EFX.AL_FILTER_NULL);
                } else {
                    al.alSourcei(id, AL_SOURCE_RELATIVE, AL_FALSE);
                    updateSourceParam(src, AudioParam.Position);
                    updateSourceParam(src, AudioParam.Velocity);
                    updateSourceParam(src, AudioParam.MaxDistance);
                    updateSourceParam(src, AudioParam.RefDistance);
                    updateSourceParam(src, AudioParam.ReverbEnabled);
                }
                break;
            case Direction:
                if (!src.isDirectional()) {
                    return;
                }
                Vector3f dir = src.getDirection();
                al.alSource3f(id, AL_DIRECTION, dir.x, dir.y, dir.z);
                break;
            case InnerAngle:
                if (!src.isDirectional()) {
                    return;
                }
                al.alSourcef(id, AL_CONE_INNER_ANGLE, src.getInnerAngle());
                break;
            case OuterAngle:
                if (!src.isDirectional()) {
                    return;
                }
                al.alSourcef(id, AL_CONE_OUTER_ANGLE, src.getOuterAngle());
                break;
            case IsDirectional:
                if (src.isDirectional()) {
                    updateSourceParam(src, AudioParam.Direction);
                    updateSourceParam(src, AudioParam.InnerAngle);
                    updateSourceParam(src, AudioParam.OuterAngle);
                    al.alSourcef(id, AL_CONE_OUTER_GAIN, 0);
                } else {
                    al.alSourcef(id, AL_CONE_INNER_ANGLE, 360);
                    al.alSourcef(id, AL_CONE_OUTER_ANGLE, 360);
                    al.alSourcef(id, AL_CONE_OUTER_GAIN, 1f);
                }
                break;
            case DryFilter:
                if (!supportEfx) {
                    return;
                }
                if (src.getDryFilter() != null) {
                    Filter f = src.getDryFilter();
                    if (f.isUpdateNeeded()) {
                        updateFilter(f);
                        // NOTE: must re-attach filter for changes to apply.
                        al.alSourcei(id, EFX.AL_DIRECT_FILTER, f.getId());
                    }
                } else {
                    al.alSourcei(id, EFX.AL_DIRECT_FILTER, EFX.AL_FILTER_NULL);
                }
                break;
            case Looping:
                if (src.isLooping() && !(src.getAudioData() instanceof AudioStream)) {
                    al.alSourcei(id, AL_LOOPING, AL_TRUE);
                } else {
                    al.alSourcei(id, AL_LOOPING, AL_FALSE);
                }
                break;
            case Volume:
                al.alSourcef(id, AL_GAIN, src.getVolume());
                break;
            case Pitch:
                al.alSourcef(id, AL_PITCH, src.getPitch());
                break;
        }
    }
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 25 with Filter

use of com.jme3.post.Filter in project jmonkeyengine by jMonkeyEngine.

the class ALAudioRenderer method setSourceParams.

private void setSourceParams(int id, AudioSource src, boolean forceNonLoop) {
    if (src.isPositional()) {
        Vector3f pos = src.getPosition();
        Vector3f vel = src.getVelocity();
        al.alSource3f(id, AL_POSITION, pos.x, pos.y, pos.z);
        al.alSource3f(id, AL_VELOCITY, vel.x, vel.y, vel.z);
        al.alSourcef(id, AL_MAX_DISTANCE, src.getMaxDistance());
        al.alSourcef(id, AL_REFERENCE_DISTANCE, src.getRefDistance());
        al.alSourcei(id, AL_SOURCE_RELATIVE, AL_FALSE);
        if (src.isReverbEnabled() && supportEfx) {
            int filter = EFX.AL_FILTER_NULL;
            if (src.getReverbFilter() != null) {
                Filter f = src.getReverbFilter();
                if (f.isUpdateNeeded()) {
                    updateFilter(f);
                }
                filter = f.getId();
            }
            al.alSource3i(id, EFX.AL_AUXILIARY_SEND_FILTER, reverbFxSlot, 0, filter);
        }
    } else {
        // play in headspace
        al.alSourcei(id, AL_SOURCE_RELATIVE, AL_TRUE);
        al.alSource3f(id, AL_POSITION, 0, 0, 0);
        al.alSource3f(id, AL_VELOCITY, 0, 0, 0);
    }
    if (src.getDryFilter() != null && supportEfx) {
        Filter f = src.getDryFilter();
        if (f.isUpdateNeeded()) {
            updateFilter(f);
            // NOTE: must re-attach filter for changes to apply.
            al.alSourcei(id, EFX.AL_DIRECT_FILTER, f.getId());
        }
    }
    if (forceNonLoop || src.getAudioData() instanceof AudioStream) {
        al.alSourcei(id, AL_LOOPING, AL_FALSE);
    } else {
        al.alSourcei(id, AL_LOOPING, src.isLooping() ? AL_TRUE : AL_FALSE);
    }
    al.alSourcef(id, AL_GAIN, src.getVolume());
    al.alSourcef(id, AL_PITCH, src.getPitch());
    al.alSourcef(id, AL_SEC_OFFSET, src.getTimeOffset());
    if (src.isDirectional()) {
        Vector3f dir = src.getDirection();
        al.alSource3f(id, AL_DIRECTION, dir.x, dir.y, dir.z);
        al.alSourcef(id, AL_CONE_INNER_ANGLE, src.getInnerAngle());
        al.alSourcef(id, AL_CONE_OUTER_ANGLE, src.getOuterAngle());
        al.alSourcef(id, AL_CONE_OUTER_GAIN, 0);
    } else {
        al.alSourcef(id, AL_CONE_INNER_ANGLE, 360);
        al.alSourcef(id, AL_CONE_OUTER_ANGLE, 360);
        al.alSourcef(id, AL_CONE_OUTER_GAIN, 1f);
    }
}
Also used : Vector3f(com.jme3.math.Vector3f)

Aggregations

Node (com.jme3.scene.Node)10 Vector3f (com.jme3.math.Vector3f)7 FilterPostProcessor (com.jme3.post.FilterPostProcessor)7 Spatial (com.jme3.scene.Spatial)7 Texture2D (com.jme3.texture.Texture2D)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 SSAOFilter (com.jme3.post.ssao.SSAOFilter)5 DirectionalLight (com.jme3.light.DirectionalLight)4 Material (com.jme3.material.Material)4 Quaternion (com.jme3.math.Quaternion)4 Filter (com.jme3.post.Filter)4 AudioNode (com.jme3.audio.AudioNode)3 KeyTrigger (com.jme3.input.controls.KeyTrigger)3 ColorRGBA (com.jme3.math.ColorRGBA)3 FogFilter (com.jme3.post.filters.FogFilter)3 DirectionalLightShadowFilter (com.jme3.shadow.DirectionalLightShadowFilter)3 Texture (com.jme3.texture.Texture)3 TextureKey (com.jme3.asset.TextureKey)2 LowPassFilter (com.jme3.audio.LowPassFilter)2