Search in sources :

Example 1 with PhysicsRigidBody

use of com.jme3.bullet.objects.PhysicsRigidBody 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 PhysicsRigidBody

use of com.jme3.bullet.objects.PhysicsRigidBody in project jmonkeyengine by jMonkeyEngine.

the class PhysicsRigidBody method getAngularVelocity.

/**
     * Get the current angular velocity of this PhysicsRigidBody
     * @return the current linear velocity
     */
public Vector3f getAngularVelocity() {
    Vector3f vec = new Vector3f();
    getAngularVelocity(objectId, vec);
    return vec;
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 3 with PhysicsRigidBody

use of com.jme3.bullet.objects.PhysicsRigidBody in project jmonkeyengine by jMonkeyEngine.

the class PhysicsRigidBody method getLinearVelocity.

/**
     * Get the current linear velocity of this PhysicsRigidBody
     * @return the current linear velocity
     */
public Vector3f getLinearVelocity() {
    Vector3f vec = new Vector3f();
    getLinearVelocity(objectId, vec);
    return vec;
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 4 with PhysicsRigidBody

use of com.jme3.bullet.objects.PhysicsRigidBody in project jmonkeyengine by jMonkeyEngine.

the class BetterCharacterControl method read.

@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule in = im.getCapsule(this);
    this.radius = in.readFloat("radius", 1);
    this.height = in.readFloat("height", 2);
    this.mass = in.readFloat("mass", 80);
    this.physicsDamping = in.readFloat("physicsDamping", 0.9f);
    this.jumpForce.set((Vector3f) in.readSavable("jumpForce", new Vector3f(0, mass * 5, 0)));
    rigidBody = new PhysicsRigidBody(getShape(), mass);
    jumpForce.set(new Vector3f(0, mass * 5, 0));
    rigidBody.setAngularFactor(0);
}
Also used : InputCapsule(com.jme3.export.InputCapsule) Vector3f(com.jme3.math.Vector3f) PhysicsRigidBody(com.jme3.bullet.objects.PhysicsRigidBody)

Example 5 with PhysicsRigidBody

use of com.jme3.bullet.objects.PhysicsRigidBody in project jmonkeyengine by jMonkeyEngine.

the class BulletDebugAppState method updateRigidBodies.

private void updateRigidBodies() {
    HashMap<PhysicsRigidBody, Spatial> oldObjects = bodies;
    bodies = new HashMap<PhysicsRigidBody, Spatial>();
    Collection<PhysicsRigidBody> current = space.getRigidBodyList();
    //create new map
    for (Iterator<PhysicsRigidBody> it = current.iterator(); it.hasNext(); ) {
        PhysicsRigidBody physicsObject = it.next();
        //copy existing spatials
        if (oldObjects.containsKey(physicsObject)) {
            Spatial spat = oldObjects.get(physicsObject);
            bodies.put(physicsObject, spat);
            oldObjects.remove(physicsObject);
        } else {
            if (filter == null || filter.displayObject(physicsObject)) {
                logger.log(Level.FINE, "Create new debug RigidBody");
                //create new spatial
                Node node = new Node(physicsObject.toString());
                node.addControl(new BulletRigidBodyDebugControl(this, physicsObject));
                bodies.put(physicsObject, node);
                physicsDebugRootNode.attachChild(node);
            }
        }
    }
    //remove leftover spatials
    for (Map.Entry<PhysicsRigidBody, Spatial> entry : oldObjects.entrySet()) {
        PhysicsRigidBody object = entry.getKey();
        Spatial spatial = entry.getValue();
        spatial.removeFromParent();
    }
}
Also used : Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) PhysicsRigidBody(com.jme3.bullet.objects.PhysicsRigidBody) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

PhysicsRigidBody (com.jme3.bullet.objects.PhysicsRigidBody)5 Vector3f (com.jme3.math.Vector3f)5 Bone (com.jme3.animation.Bone)1 PhysicsCollisionObject (com.jme3.bullet.collision.PhysicsCollisionObject)1 HullCollisionShape (com.jme3.bullet.collision.shapes.HullCollisionShape)1 SixDofJoint (com.jme3.bullet.joints.SixDofJoint)1 InputCapsule (com.jme3.export.InputCapsule)1 Node (com.jme3.scene.Node)1 Spatial (com.jme3.scene.Spatial)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1