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;
|
||||
/** Bone's name. */
|
||||
private String boneName;
|
||||
/** This variable indicates if the Y axis should be the UP axis. */
|
||||
private boolean fixUpAxis;
|
||||
/** The bone's armature matrix. */
|
||||
private Matrix4f armatureMatrix;
|
||||
/** The parent context. */
|
||||
@ -93,7 +91,6 @@ public class BoneContext {
|
||||
ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
|
||||
armatureMatrix = objectHelper.getMatrix(boneStructure, "arm_mat", true);
|
||||
|
||||
fixUpAxis = blenderContext.getBlenderKey().isFixUpAxis();
|
||||
this.computeRestMatrix(objectToArmatureMatrix);
|
||||
List<Structure> childbase = ((Structure) boneStructure.getFieldValue("childbase")).evaluateListBase(blenderContext);
|
||||
for (Structure child : childbase) {
|
||||
@ -112,10 +109,8 @@ public class BoneContext {
|
||||
private void computeRestMatrix(Matrix4f objectToArmatureMatrix) {
|
||||
if (parent != null) {
|
||||
inverseParentMatrix = parent.inverseTotalTransformation.clone();
|
||||
} else if (fixUpAxis) {
|
||||
inverseParentMatrix = objectToArmatureMatrix.clone();
|
||||
} else {
|
||||
inverseParentMatrix = Matrix4f.IDENTITY.clone();
|
||||
inverseParentMatrix = objectToArmatureMatrix.clone();
|
||||
}
|
||||
|
||||
restMatrix = armatureMatrix.clone();
|
||||
|
@ -94,10 +94,14 @@ import com.jme3.util.BufferUtils;
|
||||
bonesPoseChannels.put(pBone.getOldMemoryAddress(), poseChannel);
|
||||
}
|
||||
|
||||
Matrix4f objectToArmatureTransformation = Matrix4f.IDENTITY;
|
||||
ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
|
||||
Matrix4f armatureObjectMatrix = objectHelper.getMatrix(armatureObject, "obmat", true);
|
||||
Matrix4f inverseMeshObjectMatrix = objectHelper.getMatrix(objectStructure, "obmat", true).invertLocal();
|
||||
Matrix4f objectToArmatureTransformation = armatureObjectMatrix.multLocal(inverseMeshObjectMatrix);
|
||||
|
||||
if(objectHelper.isLineage(armatureObject, objectStructure, blenderContext)) {
|
||||
Matrix4f armatureObjectMatrix = objectHelper.getMatrix(armatureObject, "obmat", blenderContext.getBlenderKey().isFixUpAxis());
|
||||
Matrix4f inverseMeshObjectMatrix = objectHelper.getMatrix(objectStructure, "obmat", true).invertLocal();
|
||||
objectToArmatureTransformation = armatureObjectMatrix.multLocal(inverseMeshObjectMatrix);
|
||||
}
|
||||
|
||||
List<Structure> bonebase = ((Structure) armatureStructure.getFieldValue("bonebase")).evaluateListBase(blenderContext);
|
||||
List<Bone> bonesList = new ArrayList<Bone>();
|
||||
@ -202,11 +206,11 @@ import com.jme3.util.BufferUtils;
|
||||
mesh.setBuffer(buffers[0]);
|
||||
mesh.setBuffer(buffers[1]);
|
||||
|
||||
VertexBuffer bindNormalBuffer = (meshContext.getBindNormalBuffer(materialIndex));
|
||||
VertexBuffer bindNormalBuffer = meshContext.getBindNormalBuffer(materialIndex);
|
||||
if (bindNormalBuffer != null) {
|
||||
mesh.setBuffer(bindNormalBuffer);
|
||||
}
|
||||
VertexBuffer bindPoseBuffer = (meshContext.getBindPoseBuffer(materialIndex));
|
||||
VertexBuffer bindPoseBuffer = meshContext.getBindPoseBuffer(materialIndex);
|
||||
if (bindPoseBuffer != null) {
|
||||
mesh.setBuffer(bindPoseBuffer);
|
||||
}
|
||||
|
@ -174,9 +174,9 @@ public class ObjectHelper extends AbstractBlenderHelper {
|
||||
List<Geometry> curves = curvesHelper.toCurve(curveData, blenderContext);
|
||||
result = new Node(name);
|
||||
for (Geometry curve : curves) {
|
||||
((Node) result).attachChild(curve);
|
||||
result.attachChild(curve);
|
||||
}
|
||||
((Node) result).setLocalTransform(t);
|
||||
result.setLocalTransform(t);
|
||||
}
|
||||
break;
|
||||
case OBJECT_TYPE_LAMP:
|
||||
@ -244,13 +244,38 @@ public class ObjectHelper extends AbstractBlenderHelper {
|
||||
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
|
||||
if (result instanceof Spatial && properties != null && properties.getValue() != null) {
|
||||
this.applyProperties((Spatial) result, properties);
|
||||
this.applyProperties(result, properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
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.
|
||||
* @param objectStructure
|
||||
|
Loading…
x
Reference in New Issue
Block a user