Rev 1815 | Rev 1817 | 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; |
||
| 1816 | chris | 27 | public com.badlogic.gdx.math.Matrix4[] mGdxBones = null; |
| 1779 | chris | 28 | |
| 1720 | chris | 29 | // Methods========================================================================================== |
| 30 | |||
| 31 | public ModelPart(String name, MeshGroup group, Material material) |
||
| 32 | { |
||
| 33 | mName = name; |
||
| 34 | |||
| 35 | mMeshGroup = group; |
||
| 36 | mMaterial = material; |
||
| 37 | } |
||
| 38 | |||
| 1788 | chris | 39 | public Matrix4[] calcBoneMatrices() |
| 40 | { |
||
| 1804 | chris | 41 | Matrix4[] matrices = new Matrix4[mBoneInfluences.length]; |
| 42 | for (int i = 0; i < matrices.length; i++) |
||
| 1800 | chris | 43 | { |
| 44 | ModelNode bone = mBoneInfluences[i]; |
||
| 1788 | chris | 45 | |
| 1804 | chris | 46 | //Quaternion q = new Quaternion(0.5f, -0.5f, 0.5f, 0.5f); |
| 1800 | chris | 47 | |
| 1804 | chris | 48 | matrices[i] = new Matrix4(); |
| 1816 | chris | 49 | /*matrices[i].identity(); |
| 1806 | chris | 50 | matrices[i].multiply(bone.getGlobalTransform()); |
| 1808 | chris | 51 | |
| 1812 | chris | 52 | |
| 1814 | chris | 53 | Matrix4 a = new Matrix4(); |
| 54 | bone.getGlobalTransform().copyTo(a); |
||
| 55 | |||
| 56 | Matrix4 b = new Matrix4(); |
||
| 57 | mBoneTransformMatrices[i].copyTo(b); |
||
| 58 | |||
| 1816 | chris | 59 | matrices[i].multiply(mBoneTransformMatrices[i].getInverse());*/ |
| 60 | |||
| 61 | //set(part.invBoneBindTransforms.keys[i].globalTransform).mul(part.invBoneBindTransforms.values[i]); |
||
| 62 | com.badlogic.gdx.math.Matrix4 invBone = new com.badlogic.gdx.math.Matrix4(mGdxBones[i]).inv(); |
||
| 63 | com.badlogic.gdx.math.Matrix4 resultMatrix = new com.badlogic.gdx.math.Matrix4(); |
||
| 64 | resultMatrix.set(bone.globalTransform).mul(invBone); |
||
| 65 | |||
| 66 | matrices[i].set(resultMatrix.getValues()); |
||
| 1800 | chris | 67 | } |
| 68 | |||
| 1804 | chris | 69 | return matrices; |
| 1788 | chris | 70 | } |
| 71 | |||
| 1720 | chris | 72 | // Getters/Setters================================================================================== |
| 1723 | chris | 73 | |
| 1777 | chris | 74 | public final Material getMaterial() { return mMaterial; } |
| 1723 | chris | 75 | |
| 1777 | chris | 76 | public final MeshGroup getMeshGroup() { return mMeshGroup; } |
| 77 | |||
| 1804 | chris | 78 | private final void setBoneInfluences(ModelNode[] influences) |
| 1780 | chris | 79 | { |
| 80 | mBoneInfluences = influences; |
||
| 1801 | chris | 81 | } |
| 1809 | chris | 82 | public final ModelNode[] getBoneInfluences() { return mBoneInfluences; } |
| 1780 | chris | 83 | |
| 1804 | chris | 84 | private final void setBoneTransforms(Transform[] transforms) |
| 1801 | chris | 85 | { |
| 86 | mBoneTransforms = transforms; |
||
| 1804 | chris | 87 | } |
| 1809 | chris | 88 | public final Transform[] getBoneTransforms() { return mBoneTransforms; } |
| 1801 | chris | 89 | |
| 1804 | chris | 90 | public final void setBones(ModelNode[] influences, Transform[] transforms) |
| 91 | { |
||
| 92 | setBoneInfluences(influences); |
||
| 93 | setBoneTransforms(transforms); |
||
| 1814 | chris | 94 | |
| 95 | mBoneTransformMatrices = new Matrix4[transforms.length]; |
||
| 1816 | chris | 96 | mGdxBones = new com.badlogic.gdx.math.Matrix4[transforms.length]; |
| 1814 | chris | 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)); |
||
| 1816 | chris | 103 | |
| 104 | com.badlogic.gdx.math.Quaternion tempQ = new com.badlogic.gdx.math.Quaternion(); |
||
| 105 | |||
| 106 | mGdxBones[i] = new com.badlogic.gdx.math.Matrix4(); |
||
| 107 | mGdxBones[i].translate(transforms[i].translation.x,transforms[i].translation.y, transforms[i].translation.z); |
||
| 108 | mGdxBones[i].rotate(tempQ.set(transforms[i].rotation.x, transforms[i].rotation.y, transforms[i].rotation.z, transforms[i].rotation.w)); |
||
| 109 | mGdxBones[i].scale(transforms[i].scale.x, transforms[i].scale.y, transforms[i].scale.z); |
||
| 1814 | chris | 110 | } |
| 1780 | chris | 111 | } |
| 1782 | chris | 112 | |
| 1804 | chris | 113 | public final boolean isSkinned() |
| 114 | { |
||
| 115 | return (mBoneInfluences != null); |
||
| 116 | } |
||
| 1782 | chris | 117 | |
| 1804 | chris | 118 | |
| 1720 | chris | 119 | } |