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