Search in sources :

Example 31 with Skeleton

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

the class MeshLoader method compileModel.

private Node compileModel() {
    Node model = new Node(meshName + "-ogremesh");
    for (int i = 0; i < geoms.size(); i++) {
        Geometry g = geoms.get(i);
        Mesh m = g.getMesh();
        // New code for buffer extract
        if (sharedMesh != null && usesSharedMesh.get(i)) {
            m.extractVertexData(sharedMesh);
        }
        model.attachChild(geoms.get(i));
    }
    if (animData != null) {
        for (int i = 0; i < geoms.size(); i++) {
            Geometry g = geoms.get(i);
            Mesh m = geoms.get(i).getMesh();
            //FIXME the parameter is now useless.
            //It was !HADWARE_SKINNING before, but since toggleing 
            //HW skinning does not happen at load time it was always true.
            //We should use something similar as for the HWBoneIndex and 
            //HWBoneWeight : create the vertex buffers empty so that they 
            //are put in the cache, and really populate them the first time 
            //software skinning is used on the mesh.
            m.generateBindPose(true);
        }
        // Put the animations in the AnimControl
        HashMap<String, Animation> anims = new HashMap<String, Animation>();
        ArrayList<Animation> animList = animData.anims;
        for (int i = 0; i < animList.size(); i++) {
            Animation anim = animList.get(i);
            anims.put(anim.getName(), anim);
        }
        AnimControl ctrl = new AnimControl(animData.skeleton);
        ctrl.setAnimations(anims);
        model.addControl(ctrl);
        // Put the skeleton in the skeleton control
        SkeletonControl skeletonControl = new SkeletonControl(animData.skeleton);
        // This will acquire the targets from the node
        model.addControl(skeletonControl);
    }
    return model;
}
Also used : HashMap(java.util.HashMap) Animation(com.jme3.animation.Animation) SkeletonControl(com.jme3.animation.SkeletonControl) AnimControl(com.jme3.animation.AnimControl)

Example 32 with Skeleton

use of com.jme3.animation.Skeleton 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

Quaternion (com.jme3.math.Quaternion)13 Vector3f (com.jme3.math.Vector3f)13 Bone (com.jme3.animation.Bone)11 Animation (com.jme3.animation.Animation)7 Skeleton (com.jme3.animation.Skeleton)7 AnimControl (com.jme3.animation.AnimControl)6 BoneTrack (com.jme3.animation.BoneTrack)6 TempVars (com.jme3.util.TempVars)6 HashMap (java.util.HashMap)6 SkeletonControl (com.jme3.animation.SkeletonControl)5 Material (com.jme3.material.Material)3 Transform (com.jme3.math.Transform)3 Node (com.jme3.scene.Node)3 Spatial (com.jme3.scene.Spatial)3 AnimChannel (com.jme3.animation.AnimChannel)2 Track (com.jme3.animation.Track)2 SixDofJoint (com.jme3.bullet.joints.SixDofJoint)2 DirectionalLight (com.jme3.light.DirectionalLight)2 Matrix4f (com.jme3.math.Matrix4f)2 Geometry (com.jme3.scene.Geometry)2