Search in sources :

Example 16 with Bone

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

the class ArmatureModifier method apply.

@Override
public void apply(Node node, BlenderContext blenderContext) {
    if (invalid) {
        LOGGER.log(Level.WARNING, "Armature modifier is invalid! Cannot be applied to: {0}", node.getName());
    }
    if (modifying) {
        TemporalMesh temporalMesh = this.getTemporalMesh(node);
        if (temporalMesh != null) {
            LOGGER.log(Level.FINE, "Applying armature modifier to: {0}", temporalMesh);
            LOGGER.fine("Creating map between bone name and its index.");
            for (int i = 0; i < skeleton.getBoneCount(); ++i) {
                Bone bone = skeleton.getBone(i);
                temporalMesh.addBoneIndex(bone.getName(), i);
            }
            temporalMesh.applyAfterMeshCreate(this);
        } else {
            LOGGER.log(Level.WARNING, "Cannot find temporal mesh for node: {0}. The modifier will NOT be applied!", node);
        }
    }
}
Also used : TemporalMesh(com.jme3.scene.plugins.blender.meshes.TemporalMesh) Bone(com.jme3.animation.Bone)

Example 17 with Bone

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

the class KinematicRagdollControl method setIKTarget.

public Vector3f setIKTarget(Bone bone, Vector3f worldPos, int chainLength) {
    Vector3f target = worldPos.subtract(targetModel.getWorldTranslation());
    ikTargets.put(bone.getName(), target);
    ikChainDepth.put(bone.getName(), chainLength);
    int i = 0;
    while (i < chainLength + 2 && bone.getParent() != null) {
        if (!bone.hasUserControl()) {
            bone.setUserControl(true);
        }
        bone = bone.getParent();
        i++;
    }
    //        setIKMode();
    return target;
}
Also used : Vector3f(com.jme3.math.Vector3f) SixDofJoint(com.jme3.bullet.joints.SixDofJoint)

Example 18 with Bone

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

the class KinematicRagdollControl method ikUpdate.

private void ikUpdate(float tpf) {
    TempVars vars = TempVars.get();
    Quaternion tmpRot1 = vars.quat1;
    Quaternion[] tmpRot2 = new Quaternion[] { vars.quat2, new Quaternion() };
    Iterator<String> it = ikTargets.keySet().iterator();
    float distance;
    Bone bone;
    String boneName;
    while (it.hasNext()) {
        boneName = it.next();
        bone = (Bone) boneLinks.get(boneName).bone;
        if (!bone.hasUserControl()) {
            Logger.getLogger(KinematicRagdollControl.class.getSimpleName()).log(Level.FINE, "{0} doesn't have user control", boneName);
            continue;
        }
        distance = bone.getModelSpacePosition().distance(ikTargets.get(boneName));
        if (distance < IKThreshold) {
            Logger.getLogger(KinematicRagdollControl.class.getSimpleName()).log(Level.FINE, "Distance is close enough");
            continue;
        }
        int depth = 0;
        int maxDepth = ikChainDepth.get(bone.getName());
        updateBone(boneLinks.get(bone.getName()), tpf * (float) FastMath.sqrt(distance), vars, tmpRot1, tmpRot2, bone, ikTargets.get(boneName), depth, maxDepth);
        Vector3f position = vars.vect1;
        for (PhysicsBoneLink link : boneLinks.values()) {
            matchPhysicObjectToBone(link, position, tmpRot1);
        }
    }
    vars.release();
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars) Bone(com.jme3.animation.Bone) SixDofJoint(com.jme3.bullet.joints.SixDofJoint)

Example 19 with Bone

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

the class KinematicRagdollControl method removeIKTarget.

public void removeIKTarget(Bone bone) {
    int depth = ikChainDepth.remove(bone.getName());
    int i = 0;
    while (i < depth + 2 && bone.getParent() != null) {
        if (bone.hasUserControl()) {
            //                matchPhysicObjectToBone(boneLinks.get(bone.getName()), position, tmpRot1);
            bone.setUserControl(false);
        }
        bone = bone.getParent();
        i++;
    }
}
Also used : SixDofJoint(com.jme3.bullet.joints.SixDofJoint)

Example 20 with Bone

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

the class TestOgreComplexAnim method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    Bone b = control.getSkeleton().getBone("spinehigh");
    Bone b2 = control.getSkeleton().getBone("uparm.left");
    angle += tpf * rate;
    if (angle > FastMath.HALF_PI / 2f) {
        angle = FastMath.HALF_PI / 2f;
        rate = -1;
    } else if (angle < -FastMath.HALF_PI / 2f) {
        angle = -FastMath.HALF_PI / 2f;
        rate = 1;
    }
    Quaternion q = new Quaternion();
    q.fromAngles(0, angle, 0);
    b.setUserControl(true);
    b.setUserTransforms(Vector3f.ZERO, q, Vector3f.UNIT_XYZ);
    b2.setUserControl(true);
    b2.setUserTransforms(Vector3f.ZERO, Quaternion.IDENTITY, new Vector3f(1 + angle, 1 + angle, 1 + angle));
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) Bone(com.jme3.animation.Bone)

Aggregations

Bone (com.jme3.animation.Bone)35 Vector3f (com.jme3.math.Vector3f)25 Quaternion (com.jme3.math.Quaternion)17 TempVars (com.jme3.util.TempVars)13 SixDofJoint (com.jme3.bullet.joints.SixDofJoint)10 FloatBuffer (java.nio.FloatBuffer)10 VertexBuffer (com.jme3.scene.VertexBuffer)8 HashMap (java.util.HashMap)8 Skeleton (com.jme3.animation.Skeleton)7 Matrix4f (com.jme3.math.Matrix4f)7 Transform (com.jme3.math.Transform)7 BoneContext (com.jme3.scene.plugins.blender.animations.BoneContext)7 ByteBuffer (java.nio.ByteBuffer)7 BoneTrack (com.jme3.animation.BoneTrack)6 Structure (com.jme3.scene.plugins.blender.file.Structure)6 ArrayList (java.util.ArrayList)6 AnimControl (com.jme3.animation.AnimControl)5 Spatial (com.jme3.scene.Spatial)5 Map (java.util.Map)5 Animation (com.jme3.animation.Animation)4