Rev 1814 |
Rev 1816 |
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; // bind pose?
private Matrix4
[] mBoneTransformMatrices =
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());
Matrix4 a =
new Matrix4
();
bone.
getGlobalTransform().
copyTo(a
);
Matrix4 b =
new Matrix4
();
mBoneTransformMatrices
[i
].
copyTo(b
);
matrices
[i
].
multiply(mBoneTransformMatrices
[i
].
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
);
mBoneTransformMatrices =
new Matrix4
[transforms.
length];
for (int i =
0; i
< transforms.
length; i++
)
{
mBoneTransformMatrices
[i
] = Matrix4.
createIdentity();
mBoneTransformMatrices
[i
].
multiply(Matrix4.
createTranslation(transforms
[i
].
translation));
mBoneTransformMatrices
[i
].
multiply(transforms
[i
].
rotation.
toMatrix());
mBoneTransformMatrices
[i
].
multiply(Matrix4.
createScale(transforms
[i
].
scale));
}
}
public final boolean isSkinned
()
{
return (mBoneInfluences
!=
null);
}
}