Search in sources :

Example 21 with Skeleton

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

the class KinematicRagdollControl method createSpatialData.

@Override
protected void createSpatialData(Spatial model) {
    targetModel = model;
    Node parent = model.getParent();
    Vector3f initPosition = model.getLocalTranslation().clone();
    Quaternion initRotation = model.getLocalRotation().clone();
    initScale = model.getLocalScale().clone();
    model.removeFromParent();
    model.setLocalTranslation(Vector3f.ZERO);
    model.setLocalRotation(Quaternion.IDENTITY);
    model.setLocalScale(1);
    //HACK ALERT change this
    //I remove the skeletonControl and readd it to the spatial to make sure it's after the ragdollControl in the stack
    //Find a proper way to order the controls.
    SkeletonControl sc = model.getControl(SkeletonControl.class);
    if (sc == null) {
        throw new IllegalArgumentException("The root node of the model should have a SkeletonControl. Make sure the control is there and that it's not on a sub node.");
    }
    model.removeControl(sc);
    model.addControl(sc);
    // put into bind pose and compute bone transforms in model space
    // maybe dont reset to ragdoll out of animations?
    scanSpatial(model);
    if (parent != null) {
        parent.attachChild(model);
    }
    model.setLocalTranslation(initPosition);
    model.setLocalRotation(initRotation);
    model.setLocalScale(initScale);
    if (added) {
        addPhysics(space);
    }
    logger.log(Level.FINE, "Created physics ragdoll for skeleton {0}", skeleton);
}
Also used : Quaternion(com.jme3.math.Quaternion) Node(com.jme3.scene.Node) Vector3f(com.jme3.math.Vector3f) SkeletonControl(com.jme3.animation.SkeletonControl)

Example 22 with Skeleton

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

the class KinematicRagdollControl method scanSpatial.

protected void scanSpatial(Spatial model) {
    AnimControl animControl = model.getControl(AnimControl.class);
    Map<Integer, List<Float>> pointsMap = null;
    if (weightThreshold == -1.0f) {
        pointsMap = RagdollUtils.buildPointMap(model);
    }
    skeleton = animControl.getSkeleton();
    skeleton.resetAndUpdate();
    for (int i = 0; i < skeleton.getRoots().length; i++) {
        Bone childBone = skeleton.getRoots()[i];
        if (childBone.getParent() == null) {
            logger.log(Level.FINE, "Found root bone in skeleton {0}", skeleton);
            boneRecursion(model, childBone, baseRigidBody, 1, pointsMap);
        }
    }
}
Also used : Bone(com.jme3.animation.Bone) AnimControl(com.jme3.animation.AnimControl) SixDofJoint(com.jme3.bullet.joints.SixDofJoint)

Example 23 with Skeleton

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

the class Skeleton method computeSkinningMatrices.

/**
     * Compute the skining matrices for each bone of the skeleton that would be used to transform vertices of associated meshes
     * @return 
     */
public Matrix4f[] computeSkinningMatrices() {
    TempVars vars = TempVars.get();
    for (int i = 0; i < boneList.length; i++) {
        boneList[i].getOffsetTransform(skinningMatrixes[i], vars.quat1, vars.vect1, vars.vect2, vars.tempMat3);
    }
    vars.release();
    return skinningMatrixes;
}
Also used : TempVars(com.jme3.util.TempVars)

Example 24 with Skeleton

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

the class TestCustomAnim method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    // Rotate around X axis
    Quaternion rotate = new Quaternion();
    rotate.fromAngleAxis(tpf, Vector3f.UNIT_X);
    // Combine rotation with previous
    rotation.multLocal(rotate);
    // Set new rotation into bone
    bone.setUserTransforms(Vector3f.ZERO, rotation, Vector3f.UNIT_XYZ);
    // After changing skeleton transforms, must update world data
    skeleton.updateWorldVectors();
}
Also used : Quaternion(com.jme3.math.Quaternion)

Example 25 with Skeleton

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

the class FbxLoader method load.

@Override
public Object load(AssetInfo assetInfo) throws IOException {
    this.assetManager = assetInfo.getManager();
    AssetKey<?> assetKey = assetInfo.getKey();
    if (!(assetKey instanceof ModelKey)) {
        throw new AssetLoadException("Invalid asset key");
    }
    InputStream stream = assetInfo.openStream();
    try {
        sceneFilename = assetKey.getName();
        sceneFolderName = assetKey.getFolder();
        String ext = assetKey.getExtension();
        sceneName = sceneFilename.substring(0, sceneFilename.length() - ext.length() - 1);
        if (sceneFolderName != null && sceneFolderName.length() > 0) {
            sceneName = sceneName.substring(sceneFolderName.length());
        }
        reset();
        // Load the data from the stream.
        loadData(stream);
        // Bind poses are needed to compute world transforms.
        applyBindPoses();
        // Need world transforms for skeleton creation.
        updateWorldTransforms();
        // Need skeletons for meshs to be created in scene graph construction.
        // Mesh bone indices require skeletons to determine bone index.
        constructSkeletons();
        // Create the jME3 scene graph from the FBX scene graph.
        // Also creates SkeletonControls based on the constructed skeletons.
        Spatial scene = constructSceneGraph();
        // Load animations into AnimControls
        constructAnimations();
        return scene;
    } finally {
        releaseObjects();
        if (stream != null) {
            stream.close();
        }
    }
}
Also used : ModelKey(com.jme3.asset.ModelKey) Spatial(com.jme3.scene.Spatial) InputStream(java.io.InputStream) AssetLoadException(com.jme3.asset.AssetLoadException)

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