Search in sources :

Example 1 with SkeletalAnimationObject3D

use of org.rajawali3d.animation.mesh.SkeletalAnimationObject3D 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);
    }
}
Also used : SkeletalAnimationSequence(org.rajawali3d.animation.mesh.SkeletalAnimationSequence) SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint) SkeletalAnimationFrame(org.rajawali3d.animation.mesh.SkeletalAnimationFrame) SkeletalAnimationChildObject3D(org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D) SkeletalAnimationMaterialPlugin(org.rajawali3d.materials.plugins.SkeletalAnimationMaterialPlugin) SkeletalAnimationObject3D(org.rajawali3d.animation.mesh.SkeletalAnimationObject3D) SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint) Matrix4(org.rajawali3d.math.Matrix4)

Example 2 with SkeletalAnimationObject3D

use of org.rajawali3d.animation.mesh.SkeletalAnimationObject3D in project Rajawali by Rajawali.

the class BlockTriangleGeometry method getBaseObject3D.

@Override
public Object3D getBaseObject3D() {
    if (finalObject != null)
        return finalObject;
    if (mBaseObjects[0] instanceof SkeletalAnimationChildObject3D) {
        SkeletalAnimationObject3D container = new SkeletalAnimationObject3D();
        for (int i = 0; i < mBaseObjects.length; i++) {
            SkeletalAnimationChildObject3D child = (SkeletalAnimationChildObject3D) mBaseObjects[i];
            child.setSkeleton(container);
            container.addChild(child);
        }
        finalObject = container;
    } else if (mBaseObjects.length == 1)
        finalObject = mBaseObjects[0];
    else {
        final Object3D container = new Object3D(mLookupName);
        container.isContainer(true);
        for (int i = 0; i < mBaseObjects.length; i++) container.addChild(mBaseObjects[i]);
        finalObject = container;
    }
    return finalObject;
}
Also used : SkeletalAnimationChildObject3D(org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D) SkeletalAnimationObject3D(org.rajawali3d.animation.mesh.SkeletalAnimationObject3D) Object3D(org.rajawali3d.Object3D) SkeletalAnimationObject3D(org.rajawali3d.animation.mesh.SkeletalAnimationObject3D) SkeletalAnimationChildObject3D(org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D)

Example 3 with SkeletalAnimationObject3D

use of org.rajawali3d.animation.mesh.SkeletalAnimationObject3D 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;
    }
}
Also used : SkeletalAnimationChildObject3D(org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D) ParsingException(org.rajawali3d.loader.ParsingException) SkeletalAnimationMaterialPlugin(org.rajawali3d.materials.plugins.SkeletalAnimationMaterialPlugin) DiffuseMethod(org.rajawali3d.materials.methods.DiffuseMethod) SkeletalAnimationObject3D(org.rajawali3d.animation.mesh.SkeletalAnimationObject3D) Material(org.rajawali3d.materials.Material) Texture(org.rajawali3d.materials.textures.Texture) SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint)

Aggregations

SkeletalAnimationChildObject3D (org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D)3 SkeletalAnimationObject3D (org.rajawali3d.animation.mesh.SkeletalAnimationObject3D)3 SkeletonJoint (org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint)2 SkeletalAnimationMaterialPlugin (org.rajawali3d.materials.plugins.SkeletalAnimationMaterialPlugin)2 Object3D (org.rajawali3d.Object3D)1 SkeletalAnimationFrame (org.rajawali3d.animation.mesh.SkeletalAnimationFrame)1 SkeletalAnimationSequence (org.rajawali3d.animation.mesh.SkeletalAnimationSequence)1 ParsingException (org.rajawali3d.loader.ParsingException)1 Material (org.rajawali3d.materials.Material)1 DiffuseMethod (org.rajawali3d.materials.methods.DiffuseMethod)1 Texture (org.rajawali3d.materials.textures.Texture)1 Matrix4 (org.rajawali3d.math.Matrix4)1