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();
}
}
}
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();
}
}
Aggregations