Search in sources :

Example 21 with AnimControl

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

the class FbxNode method createScene.

public static Spatial createScene(FbxNode fbxNode) {
    Spatial jmeSpatial = fbxNode.getJmeObject();
    if (jmeSpatial instanceof Node) {
        // Attach children to Node
        Node jmeNode = (Node) jmeSpatial;
        for (FbxNode fbxChild : fbxNode.children) {
            if (!(fbxChild instanceof FbxLimbNode)) {
                createScene(fbxChild);
                FbxNode preferredParent = fbxChild.getPreferredParent();
                Spatial jmeChild = fbxChild.getJmeObject();
                if (preferredParent != null) {
                    System.out.println("Preferred parent for " + fbxChild + " is " + preferredParent);
                    Node jmePreferredParent = (Node) preferredParent.getJmeObject();
                    relocateSpatial(jmeChild, fbxChild.jmeWorldNodeTransform, preferredParent.jmeWorldNodeTransform);
                    jmePreferredParent.attachChild(jmeChild);
                } else {
                    jmeNode.attachChild(jmeChild);
                }
            }
        }
    }
    if (fbxNode.skeleton != null) {
        jmeSpatial.addControl(new AnimControl(fbxNode.skeleton));
        jmeSpatial.addControl(new SkeletonControl(fbxNode.skeleton));
        SkeletonDebugger sd = new SkeletonDebugger("debug", fbxNode.skeleton);
        Material mat = new Material(fbxNode.assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.getAdditionalRenderState().setWireframe(true);
        mat.getAdditionalRenderState().setDepthTest(false);
        mat.setColor("Color", ColorRGBA.Green);
        sd.setMaterial(mat);
        ((Node) jmeSpatial).attachChild(sd);
    }
    return jmeSpatial;
}
Also used : SkeletonDebugger(com.jme3.scene.debug.SkeletonDebugger) Spatial(com.jme3.scene.Spatial) FbxLimbNode(com.jme3.scene.plugins.fbx.anim.FbxLimbNode) Node(com.jme3.scene.Node) FbxAnimCurveNode(com.jme3.scene.plugins.fbx.anim.FbxAnimCurveNode) SkeletonControl(com.jme3.animation.SkeletonControl) Material(com.jme3.material.Material) FbxMaterial(com.jme3.scene.plugins.fbx.material.FbxMaterial) FbxLimbNode(com.jme3.scene.plugins.fbx.anim.FbxLimbNode) AnimControl(com.jme3.animation.AnimControl)

Example 22 with AnimControl

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

Aggregations

AnimControl (com.jme3.animation.AnimControl)17 Vector3f (com.jme3.math.Vector3f)13 Quaternion (com.jme3.math.Quaternion)8 Animation (com.jme3.animation.Animation)7 Bone (com.jme3.animation.Bone)6 Node (com.jme3.scene.Node)6 HashMap (java.util.HashMap)6 DirectionalLight (com.jme3.light.DirectionalLight)5 Spatial (com.jme3.scene.Spatial)5 SkeletonControl (com.jme3.animation.SkeletonControl)4 AnimChannel (com.jme3.animation.AnimChannel)3 BoneTrack (com.jme3.animation.BoneTrack)3 SpatialTrack (com.jme3.animation.SpatialTrack)3 Material (com.jme3.material.Material)3 Geometry (com.jme3.scene.Geometry)3 SkeletonDebugger (com.jme3.scene.debug.SkeletonDebugger)3 TempVars (com.jme3.util.TempVars)3 AnimationFactory (com.jme3.animation.AnimationFactory)2 Skeleton (com.jme3.animation.Skeleton)2 BulletAppState (com.jme3.bullet.BulletAppState)2