Search in sources :

Example 41 with Animation

use of com.jme3.animation.Animation in project jmonkeyengine by jMonkeyEngine.

the class SkeletonLoader method endElement.

public void endElement(String uri, String name, String qName) {
    if (qName.equals("translate") || qName.equals("position") || qName.equals("scale")) {
    } else if (qName.equals("axis")) {
    } else if (qName.equals("rotate") || qName.equals("rotation")) {
        rotation = new Quaternion();
        axis.normalizeLocal();
        rotation.fromAngleNormalAxis(angle, axis);
        angle = 0;
        axis = null;
    } else if (qName.equals("bone")) {
        bone.setBindTransforms(position, rotation, scale);
        bone = null;
        position = null;
        rotation = null;
        scale = null;
    } else if (qName.equals("bonehierarchy")) {
        Bone[] bones = new Bone[indexToBone.size()];
        // also assign the bones to the bonelist
        for (Map.Entry<Integer, Bone> entry : indexToBone.entrySet()) {
            Bone bone = entry.getValue();
            bones[entry.getKey()] = bone;
        }
        indexToBone.clear();
        skeleton = new Skeleton(bones);
    } else if (qName.equals("animation")) {
        animations.add(animation);
        animation = null;
    } else if (qName.equals("track")) {
        if (track != null) {
            // if track has keyframes
            tracks.add(track);
            track = null;
        }
    } else if (qName.equals("tracks")) {
        BoneTrack[] trackList = tracks.toArray(new BoneTrack[tracks.size()]);
        animation.setTracks(trackList);
        tracks.clear();
    } else if (qName.equals("keyframe")) {
        assert time >= 0;
        assert position != null;
        assert rotation != null;
        times.add(time);
        translations.add(position);
        rotations.add(rotation);
        if (scale != null) {
            scales.add(scale);
        } else {
            scales.add(new Vector3f(1, 1, 1));
        }
        time = -1;
        position = null;
        rotation = null;
        scale = null;
    } else if (qName.equals("keyframes")) {
        if (times.size() > 0) {
            float[] timesArray = new float[times.size()];
            for (int i = 0; i < timesArray.length; i++) {
                timesArray[i] = times.get(i);
            }
            Vector3f[] transArray = translations.toArray(new Vector3f[translations.size()]);
            Quaternion[] rotArray = rotations.toArray(new Quaternion[rotations.size()]);
            Vector3f[] scalesArray = scales.toArray(new Vector3f[scales.size()]);
            track.setKeyframes(timesArray, transArray, rotArray, scalesArray);
        //track.setKeyframes(timesArray, transArray, rotArray);
        } else {
            track = null;
        }
        times.clear();
        translations.clear();
        rotations.clear();
        scales.clear();
    } else if (qName.equals("skeleton")) {
        nameToBone.clear();
    }
    assert elementStack.peek().equals(qName);
    elementStack.pop();
}
Also used : BoneTrack(com.jme3.animation.BoneTrack) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) Skeleton(com.jme3.animation.Skeleton) Bone(com.jme3.animation.Bone) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Vector3f (com.jme3.math.Vector3f)18 Animation (com.jme3.animation.Animation)12 Quaternion (com.jme3.math.Quaternion)12 AnimControl (com.jme3.animation.AnimControl)11 BoneTrack (com.jme3.animation.BoneTrack)10 HashMap (java.util.HashMap)9 Bone (com.jme3.animation.Bone)8 SpatialTrack (com.jme3.animation.SpatialTrack)7 TempVars (com.jme3.util.TempVars)6 Material (com.jme3.material.Material)5 Track (com.jme3.animation.Track)4 ParticleEmitter (com.jme3.effect.ParticleEmitter)4 DirectionalLight (com.jme3.light.DirectionalLight)4 Geometry (com.jme3.scene.Geometry)4 Node (com.jme3.scene.Node)4 ArrayList (java.util.ArrayList)4 AmbientLight (com.jme3.light.AmbientLight)3 ColorRGBA (com.jme3.math.ColorRGBA)3 Transform (com.jme3.math.Transform)3 Spatial (com.jme3.scene.Spatial)3