I’m having some issues regarding imported blender models and the handling of physics.
This has already been described here.
Basically, the object is rotated by the importer to fix the up axis, but for physics purposes this is not the case. For me the result is that my car is launched over my bridge.
To fix this I’ve made the changes below to the mesh helper and the object helper.
In effect, instead of rotating the model, it rotates the meshes within the model.
The changes to MeshHelper had been submitted by Nehon previously, but on their own they caused problems with rotations of the objects within the model. This was already discussed here
My models were created with blender 2.5
[patch]
Index: src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java
===================================================================
— src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java (revision 8366)
+++ src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java (working copy)
@@ -498,7 +498,11 @@
List<Structure> mVerts = pMVert.fetchData(blenderContext.getInputStream());
for (int i = 0; i < verticesAmount; ++i) {
DynamicArray<Number> coordinates = (DynamicArray<Number>) mVerts.get(i).getFieldValue(“co”);
-
vertices<i> = new Vector3f(coordinates.get(0).floatValue(), coordinates.get(1).floatValue(), coordinates.get(2).floatValue());<br />
+ if (blenderContext.getBlenderKey().isFixUpAxis()) {
+ vertices = new Vector3f(coordinates.get(0).floatValue(), coordinates.get(2).floatValue(), -coordinates.get(1).floatValue());
+ } else {
+ vertices = new Vector3f(coordinates.get(0).floatValue(), coordinates.get(1).floatValue(), coordinates.get(2).floatValue());
+ }
}
return vertices;
}
[/patch]
[patch]
Index: src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java
===================================================================
--- src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java (revision 8366)
+++ src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java (working copy)
@@ -309,13 +309,11 @@
size.get(1).floatValue() * scaleY,
size.get(2).floatValue() * scaleZ);
- //the root object is transformed if the Y axis is UP
- if(fixUpAxis && (pParent.isNull() || (parent!=null && !this.shouldBeLoaded(parent, blenderContext)))) {
- float y = translation.y;
- translation.y = translation.z;
- translation.z = -y;
- rotation = this.upAxisRotationQuaternion.mult(rotation);
- }
+ if (fixUpAxis) {
+ float y = translation.y;
+ translation.y = translation.z;
+ translation.z = -y;
+ }
//create the result
Transform t = new Transform(translation, rotation);
[/patch]