Search in sources :

Example 1 with SixDofJoint

use of com.jme3.bullet.joints.SixDofJoint in project jmonkeyengine by jMonkeyEngine.

the class KinematicRagdollControl method boneRecursion.

protected void boneRecursion(Spatial model, Bone bone, PhysicsRigidBody parent, int reccount, Map<Integer, List<Float>> pointsMap) {
    PhysicsRigidBody parentShape = parent;
    if (boneList.isEmpty() || boneList.contains(bone.getName())) {
        PhysicsBoneLink link = new PhysicsBoneLink();
        link.bone = bone;
        //creating the collision shape 
        HullCollisionShape shape = null;
        if (pointsMap != null) {
            //build a shape for the bone, using the vertices that are most influenced by this bone
            shape = RagdollUtils.makeShapeFromPointMap(pointsMap, RagdollUtils.getBoneIndices(link.bone, skeleton, boneList), initScale, link.bone.getModelSpacePosition());
        } else {
            //build a shape for the bone, using the vertices associated with this bone with a weight above the threshold
            shape = RagdollUtils.makeShapeFromVerticeWeights(model, RagdollUtils.getBoneIndices(link.bone, skeleton, boneList), initScale, link.bone.getModelSpacePosition(), weightThreshold);
        }
        PhysicsRigidBody shapeNode = new PhysicsRigidBody(shape, rootMass / (float) reccount);
        shapeNode.setKinematic(mode == Mode.Kinematic);
        totalMass += rootMass / (float) reccount;
        link.rigidBody = shapeNode;
        link.initalWorldRotation = bone.getModelSpaceRotation().clone();
        if (parent != null) {
            //get joint position for parent
            Vector3f posToParent = new Vector3f();
            if (bone.getParent() != null) {
                bone.getModelSpacePosition().subtract(bone.getParent().getModelSpacePosition(), posToParent).multLocal(initScale);
            }
            SixDofJoint joint = new SixDofJoint(parent, shapeNode, posToParent, new Vector3f(0, 0, 0f), true);
            preset.setupJointForBone(bone.getName(), joint);
            link.joint = joint;
            joint.setCollisionBetweenLinkedBodys(false);
        }
        boneLinks.put(bone.getName(), link);
        shapeNode.setUserObject(link);
        parentShape = shapeNode;
    }
    for (Iterator<Bone> it = bone.getChildren().iterator(); it.hasNext(); ) {
        Bone childBone = it.next();
        boneRecursion(model, childBone, parentShape, reccount + 1, pointsMap);
    }
}
Also used : SixDofJoint(com.jme3.bullet.joints.SixDofJoint) Vector3f(com.jme3.math.Vector3f) Bone(com.jme3.animation.Bone) PhysicsRigidBody(com.jme3.bullet.objects.PhysicsRigidBody) HullCollisionShape(com.jme3.bullet.collision.shapes.HullCollisionShape)

Example 2 with SixDofJoint

use of com.jme3.bullet.joints.SixDofJoint in project jmonkeyengine by jMonkeyEngine.

the class RagdollPreset method setupJointForBone.

public void setupJointForBone(String boneName, SixDofJoint joint) {
    if (boneMap.isEmpty()) {
        initBoneMap();
    }
    if (lexicon.isEmpty()) {
        initLexicon();
    }
    String resultName = "";
    int resultScore = 0;
    for (String key : lexicon.keySet()) {
        int score = lexicon.get(key).getScore(boneName);
        if (score > resultScore) {
            resultScore = score;
            resultName = key;
        }
    }
    JointPreset preset = boneMap.get(resultName);
    if (preset != null && resultScore >= 50) {
        logger.log(Level.FINE, "Found matching joint for bone {0} : {1} with score {2}", new Object[] { boneName, resultName, resultScore });
        preset.setupJoint(joint);
    } else {
        logger.log(Level.FINE, "No joint match found for bone {0}", boneName);
        if (resultScore > 0) {
            logger.log(Level.FINE, "Best match found is {0} with score {1}", new Object[] { resultName, resultScore });
        }
        new JointPreset().setupJoint(joint);
    }
}
Also used : SixDofJoint(com.jme3.bullet.joints.SixDofJoint)

Aggregations

SixDofJoint (com.jme3.bullet.joints.SixDofJoint)2 Bone (com.jme3.animation.Bone)1 HullCollisionShape (com.jme3.bullet.collision.shapes.HullCollisionShape)1 PhysicsRigidBody (com.jme3.bullet.objects.PhysicsRigidBody)1 Vector3f (com.jme3.math.Vector3f)1