Search in sources :

Example 16 with SkeletonJoint

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

the class LoaderMD5Mesh method buildMeshes.

private void buildMeshes() {
    for (int i = 0; i < mNumMeshes; ++i) {
        int boneIndex = 0;
        SkeletonMeshData mesh = mMeshes[i];
        mesh.vertices = new float[mesh.numVertices * 3];
        mesh.indices = new int[mesh.numWeights];
        mesh.weights = new float[mesh.numWeights];
        mesh.textureCoordinates = new float[mesh.numVertices * 2];
        int numVerts = mesh.numVertices;
        for (int j = 0; j < numVerts; ++j) {
            BoneVertex vert = mesh.boneVertices[j];
            Vector3 position = new Vector3();
            for (int k = 0; k < vert.numWeights; ++k) {
                BoneWeight weight = mesh.boneWeights[vert.weightIndex + k];
                SkeletonJoint joint = mJoints[weight.jointIndex];
                Vector3 rotPos = joint.getOrientation().multiply(weight.position);
                //We don't clone here because nothing will be able to use the quaternion scratch before we do
                Vector3 pos = Vector3.addAndCreate(joint.getPosition(), rotPos);
                pos.multiply(weight.weightValue);
                position.add(pos);
                mesh.indices[boneIndex] = weight.jointIndex;
                mesh.weights[boneIndex++] = weight.weightValue;
            }
            int vertIndex = j * 3;
            mesh.vertices[vertIndex] = (float) position.x;
            mesh.vertices[vertIndex + 1] = (float) position.y;
            mesh.vertices[vertIndex + 2] = (float) position.z;
            int uvIndex = j * 2;
            mesh.textureCoordinates[uvIndex] = (float) vert.textureCoordinate.getX();
            mesh.textureCoordinates[uvIndex + 1] = (float) vert.textureCoordinate.getY();
        }
    }
}
Also used : BoneWeight(org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D.BoneWeight) SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint) Vector3(org.rajawali3d.math.vector.Vector3) SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint) BoneVertex(org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D.BoneVertex)

Example 17 with SkeletonJoint

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

the class LoaderMD5Mesh method parseJoints.

private void parseJoints(BufferedReader buffer) {
    try {
        String line;
        int count = 0;
        while ((line = buffer.readLine()) != null) {
            SkeletonJoint joint = new SkeletonJoint();
            if (line.length() == 0)
                continue;
            if (line.indexOf('}') > -1) {
                return;
            }
            line = line.replace('\t', ' ');
            // -- Bone Name
            int offset = line.lastIndexOf('"');
            joint.setName(line.substring(line.indexOf('"') + 1, offset));
            // -- Parent Index
            offset += 2;
            joint.setParentIndex(Integer.parseInt(line.substring(offset, line.indexOf(' ', offset))));
            // -- position
            offset = line.indexOf(')');
            String[] p = line.substring(line.indexOf('(') + 2, offset).split(" ");
            joint.setPosition(Float.parseFloat(p[0]), Float.parseFloat(p[2]), Float.parseFloat(p[1]));
            // -- orientation
            p = line.substring(line.indexOf('(', offset) + 2, line.lastIndexOf(')')).split(" ");
            joint.setOrientation(Float.parseFloat(p[0]), Float.parseFloat(p[2]), Float.parseFloat(p[1]));
            joint.getOrientation().computeW();
            mJoints[count++] = joint;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint) SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint) TextureException(org.rajawali3d.materials.textures.ATexture.TextureException) ParsingException(org.rajawali3d.loader.ParsingException) FileNotFoundException(java.io.FileNotFoundException) SkeletalAnimationException(org.rajawali3d.animation.mesh.SkeletalAnimationObject3D.SkeletalAnimationException)

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