Rev 1812 | Rev 1815 | 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 | |||
| 58 | //matrices[i].multiply(mBoneTransforms[i].calcMatrix()); |
||
| 59 | matrices[i].multiply(bone.getGlobalBindPose().getInverse()); |
||
| 60 | |||
| 1812 | chris | 61 | //matrices[i].multiply(bone.bindPose.calcMatrix().getInverse()); |
| 62 | //matrices[i].multiply(mBoneTransforms[i].rotation.toMatrix().getInverse()); |
||
| 1814 | chris | 63 | //matrices[i].multiply(bone.getGlobalBindPose().getInverse()); |
| 1800 | chris | 64 | |
| 1814 | chris | 65 | //matrices[i].multiply(mBoneTransforms[i].calcMatrix().getInverse()); |
| 66 | //matrices[i].multiply(mBoneTransformMatrices[i].getInverse()); |
||
| 67 | |||
| 1800 | chris | 68 | } |
| 69 | |||
| 1804 | chris | 70 | return matrices; |
| 1788 | chris | 71 | } |
| 72 | |||
| 1720 | chris | 73 | // Getters/Setters================================================================================== |
| 1723 | chris | 74 | |
| 1777 | chris | 75 | public final Material getMaterial() { return mMaterial; } |
| 1723 | chris | 76 | |
| 1777 | chris | 77 | public final MeshGroup getMeshGroup() { return mMeshGroup; } |
| 78 | |||
| 1804 | chris | 79 | private final void setBoneInfluences(ModelNode[] influences) |
| 1780 | chris | 80 | { |
| 81 | mBoneInfluences = influences; |
||
| 1801 | chris | 82 | } |
| 1809 | chris | 83 | public final ModelNode[] getBoneInfluences() { return mBoneInfluences; } |
| 1780 | chris | 84 | |
| 1804 | chris | 85 | private final void setBoneTransforms(Transform[] transforms) |
| 1801 | chris | 86 | { |
| 87 | mBoneTransforms = transforms; |
||
| 1804 | chris | 88 | } |
| 1809 | chris | 89 | public final Transform[] getBoneTransforms() { return mBoneTransforms; } |
| 1801 | chris | 90 | |
| 1804 | chris | 91 | public final void setBones(ModelNode[] influences, Transform[] transforms) |
| 92 | { |
||
| 93 | setBoneInfluences(influences); |
||
| 94 | setBoneTransforms(transforms); |
||
| 1814 | chris | 95 | |
| 96 | mBoneTransformMatrices = new Matrix4[transforms.length]; |
||
| 97 | for (int i = 0; i < transforms.length; i++) |
||
| 98 | { |
||
| 99 | mBoneTransformMatrices[i] = Matrix4.createIdentity(); |
||
| 100 | mBoneTransformMatrices[i].multiply(Matrix4.createTranslation(transforms[i].translation)); |
||
| 101 | mBoneTransformMatrices[i].multiply(transforms[i].rotation.toMatrix()); |
||
| 102 | mBoneTransformMatrices[i].multiply(Matrix4.createScale(transforms[i].scale)); |
||
| 103 | } |
||
| 1780 | chris | 104 | } |
| 1782 | chris | 105 | |
| 1804 | chris | 106 | public final boolean isSkinned() |
| 107 | { |
||
| 108 | return (mBoneInfluences != null); |
||
| 109 | } |
||
| 1782 | chris | 110 | |
| 1804 | chris | 111 | |
| 1720 | chris | 112 | } |