Subversion Repositories AndroidProjects

Rev

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

Rev Author Line No. Line
1720 chris 1
package com.gebauz.bauzoid2.graphics.model;
2
 
1801 chris 3
import com.gebauz.bauzoid2.graphics.util.Transform;
1782 chris 4
import com.gebauz.bauzoid2.math.Matrix4;
1778 chris 5
import com.gebauz.bauzoid2.math.Quaternion;
6
import com.gebauz.bauzoid2.math.Vector3;
7
 
1720 chris 8
/**
9
 * Created by chris on 14.12.2014.
10
 */
11
public class ModelPart
12
{
13
    // Constants========================================================================================
14
 
15
 
1778 chris 16
 
1720 chris 17
    // Fields===========================================================================================
18
 
19
    private String mName = null;
20
 
21
    private MeshGroup mMeshGroup = null;
22
    private Material mMaterial = null;
23
 
1779 chris 24
        private ModelNode[] mBoneInfluences = null;
1814 chris 25
        private Transform[] mBoneTransforms = null; // bind pose?
26
        private Matrix4[] mBoneTransformMatrices = null;
1779 chris 27
 
1720 chris 28
    // Methods==========================================================================================
29
 
30
    public ModelPart(String name, MeshGroup group, Material material)
31
    {
32
        mName = name;
33
 
34
        mMeshGroup = group;
35
        mMaterial = material;
36
    }
37
 
1788 chris 38
    public Matrix4[] calcBoneMatrices()
39
    {
1804 chris 40
        Matrix4[] matrices = new Matrix4[mBoneInfluences.length];
41
        for (int i = 0; i < matrices.length; i++)
1800 chris 42
        {
43
            ModelNode bone = mBoneInfluences[i];
1788 chris 44
 
1804 chris 45
            //Quaternion q = new Quaternion(0.5f, -0.5f, 0.5f, 0.5f);
1800 chris 46
 
1804 chris 47
                        matrices[i] = new Matrix4();
48
                        matrices[i].identity();
1806 chris 49
            matrices[i].multiply(bone.getGlobalTransform());
1808 chris 50
 
1812 chris 51
 
1814 chris 52
            Matrix4 a = new Matrix4();
53
            bone.getGlobalTransform().copyTo(a);
54
 
55
            Matrix4 b = new Matrix4();
56
            mBoneTransformMatrices[i].copyTo(b);
57
 
1815 chris 58
                        matrices[i].multiply(mBoneTransformMatrices[i].getInverse());
1800 chris 59
        }
60
 
1804 chris 61
        return matrices;
1788 chris 62
    }
63
 
1720 chris 64
    // Getters/Setters==================================================================================
1723 chris 65
 
1777 chris 66
        public final Material getMaterial() { return mMaterial; }
1723 chris 67
 
1777 chris 68
        public final MeshGroup getMeshGroup() { return mMeshGroup; }
69
 
1804 chris 70
        private final void setBoneInfluences(ModelNode[] influences)
1780 chris 71
        {
72
                mBoneInfluences = influences;
1801 chris 73
        }
1809 chris 74
        public final ModelNode[] getBoneInfluences() { return mBoneInfluences; }
1780 chris 75
 
1804 chris 76
        private final void setBoneTransforms(Transform[] transforms)
1801 chris 77
        {
78
                mBoneTransforms = transforms;
1804 chris 79
        }
1809 chris 80
        public final Transform[] getBoneTransforms() { return mBoneTransforms; }
1801 chris 81
 
1804 chris 82
        public final void setBones(ModelNode[] influences, Transform[] transforms)
83
        {
84
                setBoneInfluences(influences);
85
                setBoneTransforms(transforms);
1814 chris 86
 
87
        mBoneTransformMatrices = new Matrix4[transforms.length];
88
        for (int i = 0; i < transforms.length; i++)
89
        {
90
            mBoneTransformMatrices[i] = Matrix4.createIdentity();
91
            mBoneTransformMatrices[i].multiply(Matrix4.createTranslation(transforms[i].translation));
92
            mBoneTransformMatrices[i].multiply(transforms[i].rotation.toMatrix());
93
            mBoneTransformMatrices[i].multiply(Matrix4.createScale(transforms[i].scale));
94
        }
1780 chris 95
        }
1782 chris 96
 
1804 chris 97
        public final boolean isSkinned()
98
        {
99
                return (mBoneInfluences != null);
100
        }
1782 chris 101
 
1804 chris 102
 
1720 chris 103
}