Search in sources :

Example 11 with SkeletonJoint

use of org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint in project Rajawali by Rajawali.

the class BlockSkeleton method parseBlock.

// extract the inverse-bind-pose matrices for each joint in the skeleton
public void parseBlock(AWDLittleEndianDataInputStream dis, BlockHeader blockHeader) throws Exception {
    // Lookup name
    mLookupName = dis.readVarString();
    // Number of skeleton joints
    mNumJoints = dis.readUnsignedShort();
    // Skeleton attribute list (unused)
    dis.readProperties(null);
    // Skeleton joint parsing
    mJoints = new SkeletonJoint[mNumJoints];
    for (int i = 0; i < mNumJoints; i++) {
        int jointID = dis.readUnsignedShort();
        int parentID = dis.readUnsignedShort() - 1;
        String lookupName = dis.readVarString();
        dis.readMatrix3D(transformMatrix, blockHeader.globalPrecisionMatrix, false);
        // skip joint & user properties
        dis.readProperties(null);
        dis.readProperties(null);
        // construct joint and add to list
        SkeletonJoint joint = new SkeletonJoint();
        joint.setParentIndex(parentID);
        joint.setName(lookupName);
        joint.setIndex(jointID);
        // this is the INVERSE bind-pose matrix, take note for BlockAnimator
        joint.setMatrix(transformMatrix.getDoubleValues());
        mJoints[i] = joint;
    }
    // skip User properties section
    dis.readProperties(null);
}
Also used : SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint) SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint)

Example 12 with SkeletonJoint

use of org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint in project Rajawali by Rajawali.

the class BlockSkeletonPose method parseBlock.

public void parseBlock(AWDLittleEndianDataInputStream dis, BlockHeader blockHeader) throws Exception {
    // Lookup name
    mLookupName = dis.readVarString();
    // Number of transforms
    mNumTransforms = dis.readUnsignedShort();
    // skip block properties
    dis.readProperties(null);
    SkeletonJoint[] poses = new SkeletonJoint[mNumTransforms];
    // parse transformations; same order as joints
    for (int i = 0; i < mNumTransforms; i++) {
        SkeletonJoint pose = new SkeletonJoint();
        if (dis.readBoolean()) {
            // keep raw matrix for poses, extract pos + quat later in BlockAnimator
            dis.readMatrix3D(transformMatrix, blockHeader.globalPrecisionMatrix, false);
            pose.setMatrix(transformMatrix.getDoubleValues());
        }
        pose.setIndex(i);
        poses[i] = pose;
    }
    // skip user properties
    dis.readProperties(null);
    mPose = new SkeletalAnimationFrame();
    mPose.getSkeleton().setJoints(poses);
    mPose.setName(mLookupName);
}
Also used : SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint) SkeletalAnimationFrame(org.rajawali3d.animation.mesh.SkeletalAnimationFrame) SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint)

Example 13 with SkeletonJoint

use of org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint in project Rajawali by Rajawali.

the class LoaderMD5Anim method parseFrame.

private void parseFrame(SkeletalAnimationFrame[] frames, int frameIndex, BufferedReader buffer) {
    try {
        String line;
        SkeletalAnimationFrame frame = frames[frameIndex];
        frame.setFrameIndex(frameIndex);
        Skeleton skeleton = frame.getSkeleton();
        SkeletonJoint[] joints = new SkeletonJoint[mNumJoints];
        float[] frameData = new float[mNumAnimatedComponents];
        int index = 0;
        while ((line = buffer.readLine()) != null) {
            line = line.replace("\t", " ");
            StringTokenizer parts = new StringTokenizer(line, " ");
            if (line.indexOf('}') > -1) {
                skeleton.setJoints(joints);
                buildFrameSkeleton(frameData, skeleton);
                return;
            }
            while (parts.hasMoreTokens()) {
                frameData[index++] = Float.parseFloat(parts.nextToken());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint) SkeletalAnimationFrame(org.rajawali3d.animation.mesh.SkeletalAnimationFrame) Skeleton(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.Skeleton) SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint) ParsingException(org.rajawali3d.loader.ParsingException) FileNotFoundException(java.io.FileNotFoundException)

Example 14 with SkeletonJoint

use of org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint in project Rajawali by Rajawali.

the class LoaderMD5Anim method parseBaseFrame.

private void parseBaseFrame(BufferedReader buffer) {
    try {
        String line;
        int index = 0;
        while ((line = buffer.readLine()) != null) {
            line = line.replace("\t", " ");
            StringTokenizer parts = new StringTokenizer(line, " ");
            int numTokens = parts.countTokens();
            if (line.indexOf('}') > -1)
                return;
            if (numTokens == 0)
                continue;
            SkeletonJoint joint = new SkeletonJoint();
            mBaseFrame[index++] = joint;
            // ignore "("
            parts.nextToken();
            float x = Float.parseFloat(parts.nextToken());
            float y = Float.parseFloat(parts.nextToken());
            float z = Float.parseFloat(parts.nextToken());
            joint.setPosition(x, z, y);
            // ignore ")"
            parts.nextToken();
            // ignore "("
            parts.nextToken();
            x = Float.parseFloat(parts.nextToken());
            y = Float.parseFloat(parts.nextToken());
            z = Float.parseFloat(parts.nextToken());
            joint.setOrientation(x, z, y);
            joint.getOrientation().computeW();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint) SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint) ParsingException(org.rajawali3d.loader.ParsingException) FileNotFoundException(java.io.FileNotFoundException)

Example 15 with SkeletonJoint

use of org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint in project Rajawali by Rajawali.

the class LoaderMD5Mesh method buildBindPose.

private void buildBindPose() {
    mBindPoseMatrix = new double[mNumJoints * 16];
    mInverseBindPoseMatrix = new double[mNumJoints][];
    for (int i = 0; i < mNumJoints; ++i) {
        SkeletonJoint joint = mJoints[i];
        double[] boneTranslation = new double[16];
        double[] boneRotation = new double[16];
        double[] boneMatrix = new double[16];
        double[] inverseBoneMatrix = new double[16];
        Matrix.setIdentityM(boneTranslation, 0);
        Matrix.setIdentityM(boneRotation, 0);
        Vector3 jointPos = joint.getPosition();
        Matrix.translateM(boneTranslation, 0, jointPos.x, jointPos.y, jointPos.z);
        joint.getOrientation().toRotationMatrix(boneRotation);
        Matrix.multiplyMM(boneMatrix, 0, boneTranslation, 0, boneRotation, 0);
        Matrix.invertM(inverseBoneMatrix, 0, boneMatrix, 0);
        for (int j = 0; j < 16; j++) {
            mBindPoseMatrix[i + j] = boneMatrix[j];
        }
        mInverseBindPoseMatrix[i] = inverseBoneMatrix;
    }
}
Also used : SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint) Vector3(org.rajawali3d.math.vector.Vector3) SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint)

Aggregations

SkeletonJoint (org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint)17 FileNotFoundException (java.io.FileNotFoundException)6 ParsingException (org.rajawali3d.loader.ParsingException)6 StringTokenizer (java.util.StringTokenizer)5 Vector3 (org.rajawali3d.math.vector.Vector3)5 SkeletalAnimationFrame (org.rajawali3d.animation.mesh.SkeletalAnimationFrame)4 SkeletalAnimationException (org.rajawali3d.animation.mesh.SkeletalAnimationObject3D.SkeletalAnimationException)3 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 BoneVertex (org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D.BoneVertex)2 BoneWeight (org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D.BoneWeight)2 SkeletalAnimationSequence (org.rajawali3d.animation.mesh.SkeletalAnimationSequence)2 TextureException (org.rajawali3d.materials.textures.ATexture.TextureException)2 ArrayList (java.util.ArrayList)1 SkeletalAnimationChildObject3D (org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D)1 Skeleton (org.rajawali3d.animation.mesh.SkeletalAnimationFrame.Skeleton)1 SkeletalAnimationObject3D (org.rajawali3d.animation.mesh.SkeletalAnimationObject3D)1 SkeletalAnimationMaterialPlugin (org.rajawali3d.materials.plugins.SkeletalAnimationMaterialPlugin)1