Bugfix: fixed an issue with skeleton loading when the armature was not a parent of an object it should animate.
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10511 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
33ad135b28
commit
06f5cab5ba
@ -25,8 +25,6 @@ public class BoneContext {
|
|||||||
private Structure boneStructure;
|
private Structure boneStructure;
|
||||||
/** Bone's name. */
|
/** Bone's name. */
|
||||||
private String boneName;
|
private String boneName;
|
||||||
/** This variable indicates if the Y axis should be the UP axis. */
|
|
||||||
private boolean fixUpAxis;
|
|
||||||
/** The bone's armature matrix. */
|
/** The bone's armature matrix. */
|
||||||
private Matrix4f armatureMatrix;
|
private Matrix4f armatureMatrix;
|
||||||
/** The parent context. */
|
/** The parent context. */
|
||||||
@ -93,7 +91,6 @@ public class BoneContext {
|
|||||||
ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
|
ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
|
||||||
armatureMatrix = objectHelper.getMatrix(boneStructure, "arm_mat", true);
|
armatureMatrix = objectHelper.getMatrix(boneStructure, "arm_mat", true);
|
||||||
|
|
||||||
fixUpAxis = blenderContext.getBlenderKey().isFixUpAxis();
|
|
||||||
this.computeRestMatrix(objectToArmatureMatrix);
|
this.computeRestMatrix(objectToArmatureMatrix);
|
||||||
List<Structure> childbase = ((Structure) boneStructure.getFieldValue("childbase")).evaluateListBase(blenderContext);
|
List<Structure> childbase = ((Structure) boneStructure.getFieldValue("childbase")).evaluateListBase(blenderContext);
|
||||||
for (Structure child : childbase) {
|
for (Structure child : childbase) {
|
||||||
@ -112,10 +109,8 @@ public class BoneContext {
|
|||||||
private void computeRestMatrix(Matrix4f objectToArmatureMatrix) {
|
private void computeRestMatrix(Matrix4f objectToArmatureMatrix) {
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
inverseParentMatrix = parent.inverseTotalTransformation.clone();
|
inverseParentMatrix = parent.inverseTotalTransformation.clone();
|
||||||
} else if (fixUpAxis) {
|
|
||||||
inverseParentMatrix = objectToArmatureMatrix.clone();
|
|
||||||
} else {
|
} else {
|
||||||
inverseParentMatrix = Matrix4f.IDENTITY.clone();
|
inverseParentMatrix = objectToArmatureMatrix.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
restMatrix = armatureMatrix.clone();
|
restMatrix = armatureMatrix.clone();
|
||||||
|
@ -94,10 +94,14 @@ import com.jme3.util.BufferUtils;
|
|||||||
bonesPoseChannels.put(pBone.getOldMemoryAddress(), poseChannel);
|
bonesPoseChannels.put(pBone.getOldMemoryAddress(), poseChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Matrix4f objectToArmatureTransformation = Matrix4f.IDENTITY;
|
||||||
ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
|
ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
|
||||||
Matrix4f armatureObjectMatrix = objectHelper.getMatrix(armatureObject, "obmat", true);
|
|
||||||
|
if(objectHelper.isLineage(armatureObject, objectStructure, blenderContext)) {
|
||||||
|
Matrix4f armatureObjectMatrix = objectHelper.getMatrix(armatureObject, "obmat", blenderContext.getBlenderKey().isFixUpAxis());
|
||||||
Matrix4f inverseMeshObjectMatrix = objectHelper.getMatrix(objectStructure, "obmat", true).invertLocal();
|
Matrix4f inverseMeshObjectMatrix = objectHelper.getMatrix(objectStructure, "obmat", true).invertLocal();
|
||||||
Matrix4f objectToArmatureTransformation = armatureObjectMatrix.multLocal(inverseMeshObjectMatrix);
|
objectToArmatureTransformation = armatureObjectMatrix.multLocal(inverseMeshObjectMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
List<Structure> bonebase = ((Structure) armatureStructure.getFieldValue("bonebase")).evaluateListBase(blenderContext);
|
List<Structure> bonebase = ((Structure) armatureStructure.getFieldValue("bonebase")).evaluateListBase(blenderContext);
|
||||||
List<Bone> bonesList = new ArrayList<Bone>();
|
List<Bone> bonesList = new ArrayList<Bone>();
|
||||||
@ -202,11 +206,11 @@ import com.jme3.util.BufferUtils;
|
|||||||
mesh.setBuffer(buffers[0]);
|
mesh.setBuffer(buffers[0]);
|
||||||
mesh.setBuffer(buffers[1]);
|
mesh.setBuffer(buffers[1]);
|
||||||
|
|
||||||
VertexBuffer bindNormalBuffer = (meshContext.getBindNormalBuffer(materialIndex));
|
VertexBuffer bindNormalBuffer = meshContext.getBindNormalBuffer(materialIndex);
|
||||||
if (bindNormalBuffer != null) {
|
if (bindNormalBuffer != null) {
|
||||||
mesh.setBuffer(bindNormalBuffer);
|
mesh.setBuffer(bindNormalBuffer);
|
||||||
}
|
}
|
||||||
VertexBuffer bindPoseBuffer = (meshContext.getBindPoseBuffer(materialIndex));
|
VertexBuffer bindPoseBuffer = meshContext.getBindPoseBuffer(materialIndex);
|
||||||
if (bindPoseBuffer != null) {
|
if (bindPoseBuffer != null) {
|
||||||
mesh.setBuffer(bindPoseBuffer);
|
mesh.setBuffer(bindPoseBuffer);
|
||||||
}
|
}
|
||||||
|
@ -174,9 +174,9 @@ public class ObjectHelper extends AbstractBlenderHelper {
|
|||||||
List<Geometry> curves = curvesHelper.toCurve(curveData, blenderContext);
|
List<Geometry> curves = curvesHelper.toCurve(curveData, blenderContext);
|
||||||
result = new Node(name);
|
result = new Node(name);
|
||||||
for (Geometry curve : curves) {
|
for (Geometry curve : curves) {
|
||||||
((Node) result).attachChild(curve);
|
result.attachChild(curve);
|
||||||
}
|
}
|
||||||
((Node) result).setLocalTransform(t);
|
result.setLocalTransform(t);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OBJECT_TYPE_LAMP:
|
case OBJECT_TYPE_LAMP:
|
||||||
@ -244,13 +244,38 @@ public class ObjectHelper extends AbstractBlenderHelper {
|
|||||||
Properties properties = this.loadProperties(objectStructure, blenderContext);
|
Properties properties = this.loadProperties(objectStructure, blenderContext);
|
||||||
// the loaded property is a group property, so we need to get each value and set it to Spatial
|
// the loaded property is a group property, so we need to get each value and set it to Spatial
|
||||||
if (result instanceof Spatial && properties != null && properties.getValue() != null) {
|
if (result instanceof Spatial && properties != null && properties.getValue() != null) {
|
||||||
this.applyProperties((Spatial) result, properties);
|
this.applyProperties(result, properties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method tells if the structure1 is a lineage of structure2.
|
||||||
|
*
|
||||||
|
* @param structure1
|
||||||
|
* the first structure
|
||||||
|
* @param structure2
|
||||||
|
* the second structure
|
||||||
|
* @return <b>true</b> if the first structure is a lineage of the second
|
||||||
|
* structure and <b>false</b> otherwise
|
||||||
|
* @throws BlenderFileException
|
||||||
|
* thrown when problems with reading the blend file occur
|
||||||
|
*/
|
||||||
|
public boolean isLineage(Structure structure1, Structure structure2, BlenderContext blenderContext) throws BlenderFileException {
|
||||||
|
Pointer pParent = (Pointer) structure2.getFieldValue("parent");
|
||||||
|
while (pParent.isNotNull()) {
|
||||||
|
long oma = pParent.getOldMemoryAddress();
|
||||||
|
if (structure1.getOldMemoryAddress().longValue() == oma) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
structure2 = blenderContext.getFileBlock(oma).getStructure(blenderContext);
|
||||||
|
pParent = (Pointer) structure2.getFieldValue("parent");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method calculates local transformation for the object. Parentage is taken under consideration.
|
* This method calculates local transformation for the object. Parentage is taken under consideration.
|
||||||
* @param objectStructure
|
* @param objectStructure
|
||||||
|
Loading…
x
Reference in New Issue
Block a user