use of org.rajawali3d.materials.plugins.SkeletalAnimationMaterialPlugin in project Rajawali by Rajawali.
the class BlockAnimator method buildSkeleton.
// apply joint hierarchy to joint pose frames
private void buildSkeleton(BlockHeader blockHeader, long skelAddr) throws ParsingException {
SkeletonJoint[] joints = lookupSkeleton(blockHeader, skelAddr);
SkeletalAnimationSequence[] skelAnims = new SkeletalAnimationSequence[mAnimSet.length];
for (int i = 0; i < mAnimSet.length; i++) skelAnims[i] = (SkeletalAnimationSequence) mAnimSet[i];
Matrix4 scratch1 = new Matrix4();
Matrix4 scratch2 = new Matrix4();
for (SkeletalAnimationSequence skelSeq : skelAnims) {
for (SkeletalAnimationFrame frame : skelSeq.getFrames()) {
SkeletonJoint[] poses = frame.getSkeleton().getJoints();
// apply parent transforms
for (int i = 0; i < poses.length; i++) {
// matrix and index already set, need parent & other attribs
poses[i].setParentIndex(joints[i].getParentIndex());
if (// has parent joint
poses[i].getParentIndex() >= 0) {
SkeletonJoint parentPose = poses[poses[i].getParentIndex()];
scratch1.setAll(parentPose.getMatrix()).multiply(scratch2.setAll(poses[i].getMatrix()));
poses[i].setMatrix(scratch1.getDoubleValues());
} else
scratch1.setAll(poses[i].getMatrix());
// assign pos + rot from final matrix
scratch1.getTranslation(poses[i].getPosition());
poses[i].getOrientation().fromMatrix(scratch1);
poses[i].getOrientation().computeW();
}
}
}
for (int i = 0; i < mTargets.length; i++) {
SkeletalAnimationObject3D obj = (SkeletalAnimationObject3D) mTargets[i];
// assigns INVBP, builds BP, sets joints
obj.setJointsWithInverseBindPoseMatrices(joints);
for (int j = 0; j < obj.getNumChildren(); j++) {
SkeletalAnimationChildObject3D child = (SkeletalAnimationChildObject3D) obj.getChildAt(j);
SkeletalAnimationMaterialPlugin plugin = new SkeletalAnimationMaterialPlugin(child.getNumJoints(), child.getMaxBoneWeightsPerVertex());
child.getMaterial().addPlugin(plugin);
}
obj.setAnimationSequences(skelAnims);
obj.setAnimationSequence(mActive);
if (mAutoPlay)
obj.play(true);
}
}
use of org.rajawali3d.materials.plugins.SkeletalAnimationMaterialPlugin in project Rajawali by Rajawali.
the class LoaderMD5Mesh method createObjects.
private void createObjects() throws TextureException, ParsingException, SkeletalAnimationException {
SkeletalAnimationObject3D root = new SkeletalAnimationObject3D();
root.uBoneMatrix = mBindPoseMatrix;
root.mInverseBindPoseMatrix = mInverseBindPoseMatrix;
root.setJoints(mJoints);
mRootObject = root;
for (int i = 0; i < mNumMeshes; ++i) {
SkeletonMeshData mesh = mMeshes[i];
SkeletalAnimationChildObject3D o = new SkeletalAnimationChildObject3D();
o.setData(mesh.vertices, GLES20.GL_STREAM_DRAW, mesh.normals, GLES20.GL_STREAM_DRAW, mesh.textureCoordinates, GLES20.GL_STATIC_DRAW, null, GLES20.GL_STATIC_DRAW, mesh.indices, GLES20.GL_STATIC_DRAW, false);
o.setMaxBoneWeightsPerVertex(mesh.maxBoneWeightsPerVertex);
o.setSkeletonMeshData(mesh.numVertices, mesh.boneVertices, mesh.numWeights, mesh.boneWeights);
o.setName("MD5Mesh_" + i);
o.setSkeleton(mRootObject);
o.setInverseZScale(true);
boolean hasTexture = mesh.textureName != null && mesh.textureName.length() > 0;
Material mat = new Material();
mat.addPlugin(new SkeletalAnimationMaterialPlugin(mNumJoints, mesh.maxBoneWeightsPerVertex));
mat.enableLighting(true);
mat.setDiffuseMethod(new DiffuseMethod.Lambert());
o.setMaterial(mat);
if (!hasTexture) {
o.setColor(0xff000000 + (int) (Math.random() * 0xffffff));
} else {
int identifier = mResources.getIdentifier(mesh.textureName, "drawable", mResources.getResourcePackageName(mResourceId));
if (identifier == 0) {
throw new ParsingException("Couldn't find texture " + mesh.textureName);
}
mat.setColorInfluence(0);
mat.addTexture(new Texture("md5tex" + i, identifier));
}
mRootObject.addChild(o);
mesh.destroy();
mesh = null;
}
}
Aggregations