Java Code Examples for com.jme3.animation.Bone#getModelSpacePosition()

The following examples show how to use com.jme3.animation.Bone#getModelSpacePosition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SkeletonPoints.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * The method updates the geometry according to the positions of the bones.
 */
public void updateGeometry() {
    VertexBuffer vb = this.getBuffer(Type.Position);
    FloatBuffer posBuf = this.getFloatBuffer(Type.Position);
    posBuf.clear();
    for (int i = 0; i < skeleton.getBoneCount(); ++i) {
        Bone bone = skeleton.getBone(i);
        Vector3f head = bone.getModelSpacePosition();

        posBuf.put(head.getX()).put(head.getY()).put(head.getZ());
        if (boneLengths != null) {
            Vector3f tail = head.add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i))));
            posBuf.put(tail.getX()).put(tail.getY()).put(tail.getZ());
        }
    }
    posBuf.flip();
    vb.updateData(posBuf);

    this.updateBound();
}
 
Example 2
Source File: SkeletonInterBoneWire.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * The method updates the geometry according to the poitions of the bones.
 */
public void updateGeometry() {
    VertexBuffer vb = this.getBuffer(Type.Position);
    FloatBuffer posBuf = this.getFloatBuffer(Type.Position);
    posBuf.clear();
    for (int i = 0; i < skeleton.getBoneCount(); ++i) {
        Bone bone = skeleton.getBone(i);
        Vector3f parentTail = bone.getModelSpacePosition().add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i))));

        for (Bone child : bone.getChildren()) {
            Vector3f childHead = child.getModelSpacePosition();
            Vector3f v = childHead.subtract(parentTail);
            float pointDelta = v.length() / POINT_AMOUNT;
            v.normalizeLocal().multLocal(pointDelta);
            Vector3f pointPosition = parentTail.clone();
            for (int j = 0; j < POINT_AMOUNT; ++j) {
                posBuf.put(pointPosition.getX()).put(pointPosition.getY()).put(pointPosition.getZ());
                pointPosition.addLocal(v);
            }
        }
    }
    posBuf.flip();
    vb.updateData(posBuf);

    this.updateBound();
}
 
Example 3
Source File: SkeletonWire.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * The method updates the geometry according to the poitions of the bones.
 */
public void updateGeometry() {
    VertexBuffer vb = this.getBuffer(Type.Position);
    FloatBuffer posBuf = this.getFloatBuffer(Type.Position);
    posBuf.clear();
    for (int i = 0; i < skeleton.getBoneCount(); ++i) {
        Bone bone = skeleton.getBone(i);
        Vector3f head = bone.getModelSpacePosition();

        posBuf.put(head.getX()).put(head.getY()).put(head.getZ());
        if (boneLengths != null) {
            Vector3f tail = head.add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i))));
            posBuf.put(tail.getX()).put(tail.getY()).put(tail.getZ());
        }
    }
    posBuf.flip();
    vb.updateData(posBuf);

    this.updateBound();
}
 
Example 4
Source File: SkeletonPoints.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void updateGeometry(){
    VertexBuffer vb = getBuffer(Type.Position);
    FloatBuffer posBuf = getFloatBuffer(Type.Position);
    posBuf.clear();
    for (int i = 0; i < skeleton.getBoneCount(); i++){
        Bone bone = skeleton.getBone(i);
        Vector3f bonePos = bone.getModelSpacePosition();

        posBuf.put(bonePos.getX()).put(bonePos.getY()).put(bonePos.getZ());
    }
    posBuf.flip();
    vb.updateData(posBuf);

    updateBound();
}
 
Example 5
Source File: SkeletonWire.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void updateGeometry(){
    VertexBuffer vb = getBuffer(Type.Position);
    FloatBuffer posBuf = getFloatBuffer(Type.Position);
    posBuf.clear();
    for (int i = 0; i < skeleton.getBoneCount(); i++){
        Bone bone = skeleton.getBone(i);
        Vector3f bonePos = bone.getModelSpacePosition();

        posBuf.put(bonePos.getX()).put(bonePos.getY()).put(bonePos.getZ());
    }
    posBuf.flip();
    vb.updateData(posBuf);

    updateBound();
}
 
Example 6
Source File: ConstraintHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * The method retreives the transform from a feature in a given space.
 * 
 * @param oma
 *            the OMA of the feature (spatial or armature node)
 * @param subtargetName
 *            the feature's subtarget (bone in a case of armature's node)
 * @param space
 *            the space the transform is evaluated to
 * @return thensform of a feature in a given space
 */
public Transform getTransform(Long oma, String subtargetName, Space space) {
    Spatial feature = (Spatial) blenderContext.getLoadedFeature(oma, LoadedFeatureDataType.LOADED_FEATURE);
    boolean isArmature = blenderContext.getMarkerValue(ArmatureHelper.ARMATURE_NODE_MARKER, feature) != null;
    if (isArmature) {
        BoneContext targetBoneContext = blenderContext.getBoneByName(subtargetName);
        Bone bone = targetBoneContext.getBone();

        switch (space) {
            case CONSTRAINT_SPACE_WORLD:
                return new Transform(bone.getModelSpacePosition(), bone.getModelSpaceRotation(), bone.getModelSpaceScale());
            case CONSTRAINT_SPACE_LOCAL:
                Transform localTransform = new Transform(bone.getLocalPosition(), bone.getLocalRotation());
                localTransform.setScale(bone.getLocalScale());
                return localTransform;
            case CONSTRAINT_SPACE_POSE:
                Node nodeWithAnimationControl = blenderContext.getControlledNode(targetBoneContext.getSkeleton());
                Matrix4f m = this.toMatrix(nodeWithAnimationControl.getWorldTransform());
                Matrix4f boneAgainstModifiedNodeMatrix = this.toMatrix(bone.getLocalPosition(), bone.getLocalRotation(), bone.getLocalScale());
                Matrix4f boneWorldMatrix = m.multLocal(boneAgainstModifiedNodeMatrix);

                Matrix4f armatureWorldMatrix = this.toMatrix(feature.getWorldTransform()).invertLocal();
                Matrix4f r2 = armatureWorldMatrix.multLocal(boneWorldMatrix);

                Vector3f loc2 = r2.toTranslationVector();
                Quaternion rot2 = r2.toRotationQuat().normalizeLocal().multLocal(POS_POSE_SPACE_QUATERNION);
                Vector3f scl2 = r2.toScaleVector();

                return new Transform(loc2, rot2, scl2);
            case CONSTRAINT_SPACE_PARLOCAL:
                Matrix4f parentLocalMatrix = Matrix4f.IDENTITY;
                if (bone.getParent() != null) {
                    Bone parent = bone.getParent();
                    parentLocalMatrix = this.toMatrix(parent.getLocalPosition(), parent.getLocalRotation(), parent.getLocalScale());
                } else {
                    // we need to clone it because otherwise we could spoil
                    // the IDENTITY matrix
                    parentLocalMatrix = parentLocalMatrix.clone();
                }
                Matrix4f boneLocalMatrix = this.toMatrix(bone.getLocalPosition(), bone.getLocalRotation(), bone.getLocalScale());
                Matrix4f result = parentLocalMatrix.multLocal(boneLocalMatrix);

                Vector3f loc = result.toTranslationVector();
                Quaternion rot = result.toRotationQuat().normalizeLocal().multLocal(NEG_PARLOC_SPACE_QUATERNION);
                Vector3f scl = result.toScaleVector();
                return new Transform(loc, rot, scl);
            default:
                throw new IllegalStateException("Unknown space type: " + space);
        }
    } else {
        switch (space) {
            case CONSTRAINT_SPACE_LOCAL:
                return feature.getLocalTransform();
            case CONSTRAINT_SPACE_WORLD:
                return feature.getWorldTransform();
            case CONSTRAINT_SPACE_PARLOCAL:
            case CONSTRAINT_SPACE_POSE:
                throw new IllegalStateException("Nodes can have only Local and World spaces applied!");
            default:
                throw new IllegalStateException("Unknown space type: " + space);
        }
    }
}