Search in sources :

Example 11 with SkeletonControl

use of com.jme3.animation.SkeletonControl 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 12 with SkeletonControl

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

SkeletonControl (com.jme3.animation.SkeletonControl)7 DirectionalLight (com.jme3.light.DirectionalLight)5 Vector3f (com.jme3.math.Vector3f)5 Spatial (com.jme3.scene.Spatial)5 AnimControl (com.jme3.animation.AnimControl)4 KeyTrigger (com.jme3.input.controls.KeyTrigger)4 Quaternion (com.jme3.math.Quaternion)4 Node (com.jme3.scene.Node)4 Material (com.jme3.material.Material)3 ColorRGBA (com.jme3.math.ColorRGBA)3 Geometry (com.jme3.scene.Geometry)3 Animation (com.jme3.animation.Animation)2 Bone (com.jme3.animation.Bone)2 Skeleton (com.jme3.animation.Skeleton)2 AmbientLight (com.jme3.light.AmbientLight)2 Box (com.jme3.scene.shape.Box)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 BoneTrack (com.jme3.animation.BoneTrack)1 TextureKey (com.jme3.asset.TextureKey)1