Subversion Repositories AndroidProjects

Rev

Rev 1809 | Rev 1814 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.gebauz.bauzoid2.graphics.model;

import com.gebauz.bauzoid2.graphics.util.Transform;
import com.gebauz.bauzoid2.math.Matrix4;
import com.gebauz.bauzoid2.math.Quaternion;
import com.gebauz.bauzoid2.math.Vector3;

/**
 * Created by chris on 14.12.2014.
 */

public class ModelPart
{
    // Constants========================================================================================



    // Fields===========================================================================================

    private String mName = null;

    private MeshGroup mMeshGroup = null;
    private Material mMaterial = null;

        private ModelNode[] mBoneInfluences = null;
        private Transform[] mBoneTransforms = null;
        //private Matrix4[] mMatrices = null;

    // Methods==========================================================================================

    public ModelPart(String name, MeshGroup group, Material material)
    {
        mName = name;

        mMeshGroup = group;
        mMaterial = material;
    }

    public Matrix4[] calcBoneMatrices()
    {
        Matrix4[] matrices = new Matrix4[mBoneInfluences.length];
        for (int i = 0; i < matrices.length; i++)
        {
            ModelNode bone = mBoneInfluences[i];

            //Quaternion q = new Quaternion(0.5f, -0.5f, 0.5f, 0.5f);

                        matrices[i] = new Matrix4();
                        matrices[i].identity();
            matrices[i].multiply(bone.getGlobalTransform());

                        //matrices[i].multiply(mBoneTransforms[i].calcMatrix().getInverse());
                        //matrices[i].multiply(mBoneTransforms[i].rotation.toMatrix());
                        //matrices[i].multiply(bone.getGlobalBindPose().getInverse());

                        //matrices[i].multiply(bone.bindPose.calcMatrix().getInverse());
                        //matrices[i].multiply(mBoneTransforms[i].rotation.toMatrix().getInverse());
                        matrices[i].multiply(bone.getGlobalBindPose().getInverse());

        }

        return matrices;
    }

    // Getters/Setters==================================================================================

        public final Material getMaterial() { return mMaterial; }

        public final MeshGroup getMeshGroup() { return mMeshGroup; }

        private final void setBoneInfluences(ModelNode[] influences)
        {
                mBoneInfluences = influences;
        }
        public final ModelNode[] getBoneInfluences() { return mBoneInfluences; }

        private final void setBoneTransforms(Transform[] transforms)
        {
                mBoneTransforms = transforms;
        }
        public final Transform[] getBoneTransforms() { return mBoneTransforms; }

        public final void setBones(ModelNode[] influences, Transform[] transforms)
        {
                setBoneInfluences(influences);
                setBoneTransforms(transforms);
        }


        //public final Matrix4[] getBoneMatrices() { return mMatrices; }

        public final boolean isSkinned()
        {
                return (mBoneInfluences != null);
        }


}