Main repository of MikuMikuStudio
Revisión | 5e9256a3c607a8a942ba6893ff6d514022e65671 (tree) |
---|---|
Tiempo | 2013-04-05 04:00:21 |
Autor | Kaelthas_Spellsinger@o2.pl <Kaelthas_Spellsinger@o2.p...> |
Commiter | Kaelthas_Spellsinger@o2.pl |
Bugfix: fixed an issue with skeleton loading when the armature was not a parent of an object it should animate.
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@10511 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
@@ -25,8 +25,6 @@ public class BoneContext { | ||
25 | 25 | private Structure boneStructure; |
26 | 26 | /** Bone's name. */ |
27 | 27 | private String boneName; |
28 | - /** This variable indicates if the Y axis should be the UP axis. */ | |
29 | - private boolean fixUpAxis; | |
30 | 28 | /** The bone's armature matrix. */ |
31 | 29 | private Matrix4f armatureMatrix; |
32 | 30 | /** The parent context. */ |
@@ -93,7 +91,6 @@ public class BoneContext { | ||
93 | 91 | ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class); |
94 | 92 | armatureMatrix = objectHelper.getMatrix(boneStructure, "arm_mat", true); |
95 | 93 | |
96 | - fixUpAxis = blenderContext.getBlenderKey().isFixUpAxis(); | |
97 | 94 | this.computeRestMatrix(objectToArmatureMatrix); |
98 | 95 | List<Structure> childbase = ((Structure) boneStructure.getFieldValue("childbase")).evaluateListBase(blenderContext); |
99 | 96 | for (Structure child : childbase) { |
@@ -112,10 +109,8 @@ public class BoneContext { | ||
112 | 109 | private void computeRestMatrix(Matrix4f objectToArmatureMatrix) { |
113 | 110 | if (parent != null) { |
114 | 111 | inverseParentMatrix = parent.inverseTotalTransformation.clone(); |
115 | - } else if (fixUpAxis) { | |
116 | - inverseParentMatrix = objectToArmatureMatrix.clone(); | |
117 | 112 | } else { |
118 | - inverseParentMatrix = Matrix4f.IDENTITY.clone(); | |
113 | + inverseParentMatrix = objectToArmatureMatrix.clone(); | |
119 | 114 | } |
120 | 115 | |
121 | 116 | restMatrix = armatureMatrix.clone(); |
@@ -94,10 +94,14 @@ import com.jme3.util.BufferUtils; | ||
94 | 94 | bonesPoseChannels.put(pBone.getOldMemoryAddress(), poseChannel); |
95 | 95 | } |
96 | 96 | |
97 | + Matrix4f objectToArmatureTransformation = Matrix4f.IDENTITY; | |
97 | 98 | ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class); |
98 | - Matrix4f armatureObjectMatrix = objectHelper.getMatrix(armatureObject, "obmat", true); | |
99 | - Matrix4f inverseMeshObjectMatrix = objectHelper.getMatrix(objectStructure, "obmat", true).invertLocal(); | |
100 | - Matrix4f objectToArmatureTransformation = armatureObjectMatrix.multLocal(inverseMeshObjectMatrix); | |
99 | + | |
100 | + if(objectHelper.isLineage(armatureObject, objectStructure, blenderContext)) { | |
101 | + Matrix4f armatureObjectMatrix = objectHelper.getMatrix(armatureObject, "obmat", blenderContext.getBlenderKey().isFixUpAxis()); | |
102 | + Matrix4f inverseMeshObjectMatrix = objectHelper.getMatrix(objectStructure, "obmat", true).invertLocal(); | |
103 | + objectToArmatureTransformation = armatureObjectMatrix.multLocal(inverseMeshObjectMatrix); | |
104 | + } | |
101 | 105 | |
102 | 106 | List<Structure> bonebase = ((Structure) armatureStructure.getFieldValue("bonebase")).evaluateListBase(blenderContext); |
103 | 107 | List<Bone> bonesList = new ArrayList<Bone>(); |
@@ -202,11 +206,11 @@ import com.jme3.util.BufferUtils; | ||
202 | 206 | mesh.setBuffer(buffers[0]); |
203 | 207 | mesh.setBuffer(buffers[1]); |
204 | 208 | |
205 | - VertexBuffer bindNormalBuffer = (meshContext.getBindNormalBuffer(materialIndex)); | |
209 | + VertexBuffer bindNormalBuffer = meshContext.getBindNormalBuffer(materialIndex); | |
206 | 210 | if (bindNormalBuffer != null) { |
207 | 211 | mesh.setBuffer(bindNormalBuffer); |
208 | 212 | } |
209 | - VertexBuffer bindPoseBuffer = (meshContext.getBindPoseBuffer(materialIndex)); | |
213 | + VertexBuffer bindPoseBuffer = meshContext.getBindPoseBuffer(materialIndex); | |
210 | 214 | if (bindPoseBuffer != null) { |
211 | 215 | mesh.setBuffer(bindPoseBuffer); |
212 | 216 | } |
@@ -174,9 +174,9 @@ public class ObjectHelper extends AbstractBlenderHelper { | ||
174 | 174 | List<Geometry> curves = curvesHelper.toCurve(curveData, blenderContext); |
175 | 175 | result = new Node(name); |
176 | 176 | for (Geometry curve : curves) { |
177 | - ((Node) result).attachChild(curve); | |
177 | + result.attachChild(curve); | |
178 | 178 | } |
179 | - ((Node) result).setLocalTransform(t); | |
179 | + result.setLocalTransform(t); | |
180 | 180 | } |
181 | 181 | break; |
182 | 182 | case OBJECT_TYPE_LAMP: |
@@ -244,7 +244,7 @@ public class ObjectHelper extends AbstractBlenderHelper { | ||
244 | 244 | Properties properties = this.loadProperties(objectStructure, blenderContext); |
245 | 245 | // the loaded property is a group property, so we need to get each value and set it to Spatial |
246 | 246 | if (result instanceof Spatial && properties != null && properties.getValue() != null) { |
247 | - this.applyProperties((Spatial) result, properties); | |
247 | + this.applyProperties(result, properties); | |
248 | 248 | } |
249 | 249 | } |
250 | 250 | } |
@@ -252,6 +252,31 @@ public class ObjectHelper extends AbstractBlenderHelper { | ||
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
255 | + * Method tells if the structure1 is a lineage of structure2. | |
256 | + * | |
257 | + * @param structure1 | |
258 | + * the first structure | |
259 | + * @param structure2 | |
260 | + * the second structure | |
261 | + * @return <b>true</b> if the first structure is a lineage of the second | |
262 | + * structure and <b>false</b> otherwise | |
263 | + * @throws BlenderFileException | |
264 | + * thrown when problems with reading the blend file occur | |
265 | + */ | |
266 | + public boolean isLineage(Structure structure1, Structure structure2, BlenderContext blenderContext) throws BlenderFileException { | |
267 | + Pointer pParent = (Pointer) structure2.getFieldValue("parent"); | |
268 | + while (pParent.isNotNull()) { | |
269 | + long oma = pParent.getOldMemoryAddress(); | |
270 | + if (structure1.getOldMemoryAddress().longValue() == oma) { | |
271 | + return true; | |
272 | + } | |
273 | + structure2 = blenderContext.getFileBlock(oma).getStructure(blenderContext); | |
274 | + pParent = (Pointer) structure2.getFieldValue("parent"); | |
275 | + } | |
276 | + return false; | |
277 | + } | |
278 | + | |
279 | + /** | |
255 | 280 | * This method calculates local transformation for the object. Parentage is taken under consideration. |
256 | 281 | * @param objectStructure |
257 | 282 | * the object's structure |