Search in sources :

Example 51 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class SpatialTrack method setTime.

/**
     * 
     * Modify the spatial which this track modifies.
     * 
     * @param time
     *            the current time of the animation
     */
public void setTime(float time, float weight, AnimControl control, AnimChannel channel, TempVars vars) {
    Spatial spatial = control.getSpatial();
    Vector3f tempV = vars.vect1;
    Vector3f tempS = vars.vect2;
    Quaternion tempQ = vars.quat1;
    Vector3f tempV2 = vars.vect3;
    Vector3f tempS2 = vars.vect4;
    Quaternion tempQ2 = vars.quat2;
    int lastFrame = times.length - 1;
    if (time < 0 || lastFrame == 0) {
        if (rotations != null)
            rotations.get(0, tempQ);
        if (translations != null)
            translations.get(0, tempV);
        if (scales != null) {
            scales.get(0, tempS);
        }
    } else if (time >= times[lastFrame]) {
        if (rotations != null)
            rotations.get(lastFrame, tempQ);
        if (translations != null)
            translations.get(lastFrame, tempV);
        if (scales != null) {
            scales.get(lastFrame, tempS);
        }
    } else {
        int startFrame = 0;
        int endFrame = 1;
        // use lastFrame so we never overflow the array
        for (int i = 0; i < lastFrame && times[i] < time; ++i) {
            startFrame = i;
            endFrame = i + 1;
        }
        float blend = (time - times[startFrame]) / (times[endFrame] - times[startFrame]);
        if (rotations != null)
            rotations.get(startFrame, tempQ);
        if (translations != null)
            translations.get(startFrame, tempV);
        if (scales != null) {
            scales.get(startFrame, tempS);
        }
        if (rotations != null)
            rotations.get(endFrame, tempQ2);
        if (translations != null)
            translations.get(endFrame, tempV2);
        if (scales != null) {
            scales.get(endFrame, tempS2);
        }
        tempQ.nlerp(tempQ2, blend);
        tempV.interpolateLocal(tempV2, blend);
        tempS.interpolateLocal(tempS2, blend);
    }
    if (translations != null)
        spatial.setLocalTranslation(tempV);
    if (rotations != null)
        spatial.setLocalRotation(tempQ);
    if (scales != null) {
        spatial.setLocalScale(tempS);
    }
}
Also used : Spatial(com.jme3.scene.Spatial) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f)

Example 52 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class EffectTrack method read.

/**
     * Internal use only serialization
     *
     * @param im importer
     * @throws IOException Exception
     */
public void read(JmeImporter im) throws IOException {
    InputCapsule in = im.getCapsule(this);
    this.particlesPerSeconds = in.readFloat("particlesPerSeconds", 0);
    //reading the emitter even if the track will then reference its cloned counter part if it's loaded with the assetManager.
    //This also avoid null pointer exception if the model is not loaded via the AssetManager.
    emitter = (ParticleEmitter) in.readSavable("emitter", null);
    emitter.setParticlesPerSec(0);
    //if the emitter was saved with a KillParticleControl we remove it.
    //        Control c = emitter.getControl(KillParticleControl.class);
    //        if(c!=null){
    //            emitter.removeControl(c);
    //        }
    //emitter.removeControl(KillParticleControl.class);
    length = in.readFloat("length", length);
    startOffset = in.readFloat("startOffset", 0);
}
Also used : InputCapsule(com.jme3.export.InputCapsule)

Example 53 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class Cinematic method bindCamera.

/**
     * Binds a camera to this cinematic, tagged by a unique name. This methods
     * creates and returns a CameraNode for the cam and attach it to the scene.
     * The control direction is set to SpatialToCamera. This camera Node can
     * then be used in other events to handle the camera movements during the
     * playback
     *
     * @param cameraName the unique tag the camera should have
     * @param cam the scene camera.
     * @return the created CameraNode.
     */
public CameraNode bindCamera(String cameraName, Camera cam) {
    if (cameras.containsKey(cameraName)) {
        throw new IllegalArgumentException("Camera " + cameraName + " is already binded to this cinematic");
    }
    CameraNode node = new CameraNode(cameraName, cam);
    node.setControlDir(ControlDirection.SpatialToCamera);
    node.getControl(CameraControl.class).setEnabled(false);
    cameras.put(cameraName, node);
    scene.attachChild(node);
    return node;
}
Also used : CameraNode(com.jme3.scene.CameraNode) CameraControl(com.jme3.scene.control.CameraControl)

Example 54 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class Spatial method read.

public void read(JmeImporter im) throws IOException {
    InputCapsule ic = im.getCapsule(this);
    name = ic.readString("name", null);
    worldBound = (BoundingVolume) ic.readSavable("world_bound", null);
    cullHint = ic.readEnum("cull_mode", CullHint.class, CullHint.Inherit);
    batchHint = ic.readEnum("batch_hint", BatchHint.class, BatchHint.Inherit);
    queueBucket = ic.readEnum("queue", RenderQueue.Bucket.class, RenderQueue.Bucket.Inherit);
    shadowMode = ic.readEnum("shadow_mode", ShadowMode.class, ShadowMode.Inherit);
    localTransform = (Transform) ic.readSavable("transform", Transform.IDENTITY);
    localLights = (LightList) ic.readSavable("lights", null);
    localLights.setOwner(this);
    ArrayList<MatParamOverride> localOverridesList = ic.readSavableArrayList("overrides", null);
    if (localOverridesList == null) {
        localOverrides = new SafeArrayList<>(MatParamOverride.class);
    } else {
        localOverrides = new SafeArrayList(MatParamOverride.class, localOverridesList);
    }
    worldOverrides = new SafeArrayList<>(MatParamOverride.class);
    //changed for backward compatibility with j3o files generated before the AnimControl/SkeletonControl split
    //the AnimControl creates the SkeletonControl for old files and add it to the spatial.
    //The SkeletonControl must be the last in the stack so we add the list of all other control before it.
    //When backward compatibility won't be needed anymore this can be replaced by :
    //controls = ic.readSavableArrayList("controlsList", null));
    controls.addAll(0, ic.readSavableArrayList("controlsList", null));
    userData = (HashMap<String, Savable>) ic.readStringSavableMap("user_data", null);
}
Also used : Bucket(com.jme3.renderer.queue.RenderQueue.Bucket) SafeArrayList(com.jme3.util.SafeArrayList) ShadowMode(com.jme3.renderer.queue.RenderQueue.ShadowMode) MatParamOverride(com.jme3.material.MatParamOverride)

Example 55 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class Spatial method removeControl.

/**
     * Removes the first control that is an instance of the given class.
     *
     * @see Spatial#addControl(com.jme3.scene.control.Control)
     */
public void removeControl(Class<? extends Control> controlType) {
    boolean before = requiresUpdates();
    for (int i = 0; i < controls.size(); i++) {
        if (controlType.isAssignableFrom(controls.get(i).getClass())) {
            Control control = controls.remove(i);
            control.setSpatial(null);
            // added to match the javadoc  -pspeed
            break;
        }
    }
    boolean after = requiresUpdates();
    // can rebuild its update list.
    if (parent != null && before != after) {
        parent.invalidateUpdateList();
    }
}
Also used : Control(com.jme3.scene.control.Control)

Aggregations

Vector3f (com.jme3.math.Vector3f)51 DirectionalLight (com.jme3.light.DirectionalLight)24 Material (com.jme3.material.Material)23 Quaternion (com.jme3.math.Quaternion)21 Node (com.jme3.scene.Node)19 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)18 Texture (com.jme3.texture.Texture)16 AnimControl (com.jme3.animation.AnimControl)15 ColorRGBA (com.jme3.math.ColorRGBA)15 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)15 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)14 Geometry (com.jme3.scene.Geometry)14 Spatial (com.jme3.scene.Spatial)13 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)13 BulletAppState (com.jme3.bullet.BulletAppState)12 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)11 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)11 ArrayList (java.util.ArrayList)10 Box (com.jme3.scene.shape.Box)7 Animation (com.jme3.animation.Animation)5