Examples of BoneContext


Examples of com.jme3.scene.plugins.blender.animations.BoneContext

                }
            }

            if (!constraintUsed) {
                if (constraint instanceof BoneConstraint) {
                    BoneContext boneContext = blenderContext.getBoneContext(constraint.ownerOMA);
                    simulationRootNodes.add(new SimulationNode(boneContext.getArmatureObjectOMA(), blenderContext));
                } else if (constraint instanceof SpatialConstraint) {
                    Spatial spatial = (Spatial) blenderContext.getLoadedFeature(constraint.ownerOMA, LoadedFeatureDataType.LOADED_FEATURE);
                    while (spatial.getParent() != null) {
                        spatial = spatial.getParent();
                    }
View Full Code Here

Examples of com.jme3.scene.plugins.blender.animations.BoneContext

    public Transform getTransform(Long oma, String subtargetName, Space space) {
        Spatial feature = (Spatial) blenderContext.getLoadedFeature(oma, LoadedFeatureDataType.LOADED_FEATURE);
        boolean isArmature = blenderContext.getMarkerValue(ObjectHelper.ARMATURE_NODE_MARKER, feature) != null;
        if (isArmature) {
            blenderContext.getSkeleton(oma).updateWorldVectors();
            BoneContext targetBoneContext = blenderContext.getBoneByName(oma, subtargetName);
            Bone bone = targetBoneContext.getBone();

            if (bone.getParent() == null && (space == Space.CONSTRAINT_SPACE_LOCAL || space == Space.CONSTRAINT_SPACE_PARLOCAL)) {
                space = Space.CONSTRAINT_SPACE_POSE;
            }

            TempVars tempVars = TempVars.get();// use readable names of the matrices so that the code is more clear
            Transform result;
            switch (space) {
                case CONSTRAINT_SPACE_WORLD:
                    Spatial model = (Spatial) blenderContext.getLoadedFeature(targetBoneContext.getSkeletonOwnerOma(), LoadedFeatureDataType.LOADED_FEATURE);
                    Matrix4f boneModelMatrix = this.toMatrix(bone.getModelSpacePosition(), bone.getModelSpaceRotation(), bone.getModelSpaceScale(), tempVars.tempMat4);
                    Matrix4f modelWorldMatrix = this.toMatrix(model.getWorldTransform(), tempVars.tempMat42);
                    Matrix4f boneMatrixInWorldSpace = modelWorldMatrix.multLocal(boneModelMatrix);
                    result = new Transform(boneMatrixInWorldSpace.toTranslationVector(), boneMatrixInWorldSpace.toRotationQuat(), boneMatrixInWorldSpace.toScaleVector());
                    break;
                case CONSTRAINT_SPACE_LOCAL:
                    assert bone.getParent() != null : "CONSTRAINT_SPACE_LOCAL should be evaluated as CONSTRAINT_SPACE_POSE if the bone has no parent!";
                    result = new Transform(bone.getLocalPosition(), bone.getLocalRotation(), bone.getLocalScale());
                    break;
                case CONSTRAINT_SPACE_POSE: {
                    Matrix4f boneWorldMatrix = this.toMatrix(this.getTransform(oma, subtargetName, Space.CONSTRAINT_SPACE_WORLD), tempVars.tempMat4);
                    Matrix4f armatureInvertedWorldMatrix = this.toMatrix(feature.getWorldTransform(), tempVars.tempMat42).invertLocal();
                    Matrix4f bonePoseMatrix = armatureInvertedWorldMatrix.multLocal(boneWorldMatrix);
                    result = new Transform(bonePoseMatrix.toTranslationVector(), bonePoseMatrix.toRotationQuat(), bonePoseMatrix.toScaleVector());
                    break;
                }
                case CONSTRAINT_SPACE_PARLOCAL: {
                    Matrix4f boneWorldMatrix = this.toMatrix(this.getTransform(oma, subtargetName, Space.CONSTRAINT_SPACE_WORLD), tempVars.tempMat4);
                    Matrix4f armatureInvertedWorldMatrix = this.toMatrix(feature.getWorldTransform(), tempVars.tempMat42).invertLocal();
                    Matrix4f bonePoseMatrix = armatureInvertedWorldMatrix.multLocal(boneWorldMatrix);
                    result = new Transform(bonePoseMatrix.toTranslationVector(), bonePoseMatrix.toRotationQuat(), bonePoseMatrix.toScaleVector());
                    Bone parent = bone.getParent();
                    if(parent != null) {
                        BoneContext parentContext = blenderContext.getBoneContext(parent);
                        Vector3f head = parent.getModelSpacePosition();
                        Vector3f tail = head.add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(parentContext.getLength())));
                        result.getTranslation().subtractLocal(tail);
                       
                    }
                    break;
                }
View Full Code Here

Examples of com.jme3.scene.plugins.blender.animations.BoneContext

    public void applyTransform(Long oma, String subtargetName, Space space, Transform transform) {
        Spatial feature = (Spatial) blenderContext.getLoadedFeature(oma, LoadedFeatureDataType.LOADED_FEATURE);
        boolean isArmature = blenderContext.getMarkerValue(ObjectHelper.ARMATURE_NODE_MARKER, feature) != null;
        if (isArmature) {
            Skeleton skeleton = blenderContext.getSkeleton(oma);
            BoneContext targetBoneContext = blenderContext.getBoneByName(oma, subtargetName);
            Bone bone = targetBoneContext.getBone();

            if (bone.getParent() == null && (space == Space.CONSTRAINT_SPACE_LOCAL || space == Space.CONSTRAINT_SPACE_PARLOCAL)) {
                space = Space.CONSTRAINT_SPACE_POSE;
            }

            TempVars tempVars = TempVars.get();
            switch (space) {
                case CONSTRAINT_SPACE_LOCAL:
                    assert bone.getParent() != null : "CONSTRAINT_SPACE_LOCAL should be evaluated as CONSTRAINT_SPACE_POSE if the bone has no parent!";
                    bone.setBindTransforms(transform.getTranslation(), transform.getRotation(), transform.getScale());
                    break;
                case CONSTRAINT_SPACE_WORLD: {
                    Matrix4f boneMatrixInWorldSpace = this.toMatrix(transform, tempVars.tempMat4);
                    Matrix4f modelWorldMatrix = this.toMatrix(this.getTransform(targetBoneContext.getSkeletonOwnerOma(), null, Space.CONSTRAINT_SPACE_WORLD), tempVars.tempMat42);
                    Matrix4f boneMatrixInModelSpace = modelWorldMatrix.invertLocal().multLocal(boneMatrixInWorldSpace);
                    Bone parent = bone.getParent();
                    if (parent != null) {
                        Matrix4f parentMatrixInModelSpace = this.toMatrix(parent.getModelSpacePosition(), parent.getModelSpaceRotation(), parent.getModelSpaceScale(), tempVars.tempMat4);
                        boneMatrixInModelSpace = parentMatrixInModelSpace.invertLocal().multLocal(boneMatrixInModelSpace);
                    }
                    bone.setBindTransforms(boneMatrixInModelSpace.toTranslationVector(), boneMatrixInModelSpace.toRotationQuat(), boneMatrixInModelSpace.toScaleVector());
                    break;
                }
                case CONSTRAINT_SPACE_POSE: {
                    Matrix4f armatureWorldMatrix = this.toMatrix(feature.getWorldTransform(), tempVars.tempMat4);
                    Matrix4f boneMatrixInWorldSpace = armatureWorldMatrix.multLocal(this.toMatrix(transform, tempVars.tempMat42));
                    Matrix4f invertedModelMatrix = this.toMatrix(this.getTransform(targetBoneContext.getSkeletonOwnerOma(), null, Space.CONSTRAINT_SPACE_WORLD), tempVars.tempMat42).invertLocal();
                    Matrix4f boneMatrixInModelSpace = invertedModelMatrix.multLocal(boneMatrixInWorldSpace);
                    Bone parent = bone.getParent();
                    if (parent != null) {
                        Matrix4f parentMatrixInModelSpace = this.toMatrix(parent.getModelSpacePosition(), parent.getModelSpaceRotation(), parent.getModelSpaceScale(), tempVars.tempMat4);
                        boneMatrixInModelSpace = parentMatrixInModelSpace.invertLocal().multLocal(boneMatrixInModelSpace);
                    }
                    bone.setBindTransforms(boneMatrixInModelSpace.toTranslationVector(), boneMatrixInModelSpace.toRotationQuat(), boneMatrixInModelSpace.toScaleVector());
                    break;
                }
                case CONSTRAINT_SPACE_PARLOCAL:
                    Matrix4f armatureWorldMatrix = this.toMatrix(feature.getWorldTransform(), tempVars.tempMat4);
                    Matrix4f boneMatrixInWorldSpace = armatureWorldMatrix.multLocal(this.toMatrix(transform, tempVars.tempMat42));
                    Matrix4f invertedModelMatrix = this.toMatrix(this.getTransform(targetBoneContext.getSkeletonOwnerOma(), null, Space.CONSTRAINT_SPACE_WORLD), tempVars.tempMat42).invertLocal();
                    Matrix4f boneMatrixInModelSpace = invertedModelMatrix.multLocal(boneMatrixInWorldSpace);
                    Bone parent = bone.getParent();
                    if (parent != null) {
                        //first add the initial parent matrix to the bone's model matrix
                        BoneContext parentContext = blenderContext.getBoneContext(parent);

                        Matrix4f initialParentMatrixInModelSpace = parentContext.getBoneMatrixInModelSpace();
                        Matrix4f currentParentMatrixInModelSpace = this.toMatrix(parent.getModelSpacePosition(), parent.getModelSpaceRotation(), parent.getModelSpaceScale(), tempVars.tempMat4);
                        //the bone will now move with its parent in model space

                        //now we need to subtract the difference between current parent's model matrix and its initial model matrix
                        boneMatrixInModelSpace = initialParentMatrixInModelSpace.mult(boneMatrixInModelSpace);
View Full Code Here

Examples of com.jme3.scene.plugins.blender.animations.BoneContext

    private BoneContext[] getBones() {
        if (bones == null) {
            List<BoneContext> bones = new ArrayList<BoneContext>();
            Bone bone = (Bone) this.getOwner();
            while (bone != null) {
                BoneContext boneContext = blenderContext.getBoneContext(bone);
                bones.add(0, boneContext);
                chainLength += boneContext.getLength();
                if (bonesAffected != 0 && bones.size() >= bonesAffected) {
                    break;
                }
                bone = bone.getParent();
            }
View Full Code Here

Examples of com.jme3.scene.plugins.blender.animations.BoneContext

        // add children nodes
        if (skeleton != null) {
            // bone with index 0 is a root bone and should not be considered
            // here
            for (int i = 1; i < skeleton.getBoneCount(); ++i) {
                BoneContext boneContext = blenderContext.getBoneContext(skeleton.getBone(i));
                List<Constraint> boneConstraints = this.findConstraints(boneContext.getBoneOma(), blenderContext);
                if (boneConstraints != null) {
                    constraints.addAll(boneConstraints);
                }
            }
            Node node = blenderContext.getControlledNode(skeleton);
View Full Code Here

Examples of com.jme3.scene.plugins.blender.animations.BoneContext

                            }
                        }

                        // ... add virtual tracks if neccessary, for bones that were altered but had no tracks before ...
                        for (Long boneOMA : alteredOmas) {
                            BoneContext boneContext = blenderContext.getBoneContext(boneOMA);
                            int boneIndex = skeleton.getBoneIndex(boneContext.getBone());
                            if (!tracks.containsKey(boneIndex)) {
                                tracks.put(boneIndex, new VirtualTrack(maxFrame, maxTime));
                            }
                        }
                        alteredOmas.clear();
View Full Code Here

Examples of com.jme3.scene.plugins.blender.animations.BoneContext

     *            the set of OMAS of the altered bones (is populated if necessary)
     * @param frame
     *            the current frame of the animation
     */
    private void applyConstraints(Bone bone, Set<Long> alteredOmas, int frame) {
        BoneContext boneContext = blenderContext.getBoneContext(bone);
        List<Constraint> constraints = this.findConstraints(boneContext.getBoneOma(), blenderContext);
        if (constraints != null && constraints.size() > 0) {
            for (Constraint constraint : constraints) {
                constraint.apply(frame);
                if (constraint.getAlteredOmas() != null) {
                    alteredOmas.addAll(constraint.getAlteredOmas());
                }
                alteredOmas.add(boneContext.getBoneOma());
            }
        }
        for (Bone child : bone.getChildren()) {
            this.applyConstraints(child, alteredOmas, frame);
        }
View Full Code Here

Examples of com.jme3.scene.plugins.blender.animations.BoneContext

                    LOGGER.log(Level.WARNING, "No bone target specified for constraint: {0}.", name);
                    return false;
                }
                // if the target is not an object node then it is an Armature,
                // so make sure the bone is in the current skeleton
                BoneContext boneContext = blenderContext.getBoneContext(ownerOMA);
                if (targetOMA.longValue() != boneContext.getArmatureObjectOMA().longValue()) {
                    LOGGER.log(Level.WARNING, "Bone constraint {0} must target bone in the its own skeleton! Targeting bone in another skeleton is not supported!", name);
                    return false;
                }
            }
        }
View Full Code Here

Examples of com.jme3.scene.plugins.blender.animations.BoneContext

     *            the space in which the computed transformation is given
     * @return the constraint owner's transformation
     */
    protected Transform getOwnerTransform(Space ownerSpace) {
        if (this.getOwner() instanceof Bone) {
            BoneContext boneContext = blenderContext.getBoneContext(ownerOMA);
            return constraintHelper.getTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace);
        }
        return constraintHelper.getTransform(ownerOMA, null, ownerSpace);
    }
View Full Code Here

Examples of com.jme3.scene.plugins.blender.animations.BoneContext

     * @param ownerSpace
     *            the space that defines which owner's transformation (ie. global, local, etc. will be set)
     */
    protected void applyOwnerTransform(Transform ownerTransform, Space ownerSpace) {
        if (this.getOwner() instanceof Bone) {
            BoneContext boneContext = blenderContext.getBoneContext(ownerOMA);
            constraintHelper.applyTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace, ownerTransform);
        } else {
            constraintHelper.applyTransform(ownerOMA, null, ownerSpace, ownerTransform);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.