浏览代码

Bugfix: fixed artifacts that were caused by adding bones with no weight
to bone index buffer.

jmekaelthas 10 年之前
父节点
当前提交
05bdd7b1c9

+ 7 - 1
jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/TemporalMesh.java

@@ -518,9 +518,15 @@ public class TemporalMesh extends Geometry {
                         Map<String, Float> vertexGroupsForVertex = vertexGroups.get(vertIndex);
                         for (Entry<String, Integer> entry : boneIndexes.entrySet()) {
                             if (vertexGroupsForVertex.containsKey(entry.getKey())) {
-                                boneBuffersForVertex.put(vertexGroupsForVertex.get(entry.getKey()), entry.getValue());
+                                float weight = vertexGroupsForVertex.get(entry.getKey());
+                                if(weight > 0) {// no need to use such weights
+                                    boneBuffersForVertex.put(weight, entry.getValue());
+                                }
                             }
                         }
+                        if(boneBuffersForVertex.size() == 0) {// attach the vertex to zero-indexed bone so that it does not collapse to (0, 0, 0)
+                            boneBuffersForVertex.put(1.0f, 0);
+                        }
                         boneBuffers.add(boneBuffersForVertex);
                     }
                 }

+ 15 - 12
jme3-blender/src/main/java/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java

@@ -53,18 +53,21 @@ import com.jme3.scene.plugins.blender.meshes.TemporalMesh;
                 modifying = useBoneEnvelopes || useVertexGroups;
                 if (modifying) {// if neither option is used the modifier will not modify anything anyway
                     Structure armatureObject = pArmatureObject.fetchData().get(0);
-                    
-                    // load skeleton
-                    Structure armatureStructure = ((Pointer) armatureObject.getFieldValue("data")).fetchData().get(0);
-                    List<Structure> bonebase = ((Structure) armatureStructure.getFieldValue("bonebase")).evaluateListBase();
-                    List<Bone> bonesList = new ArrayList<Bone>();
-                    for (int i = 0; i < bonebase.size(); ++i) {
-                        this.buildBones(armatureObject.getOldMemoryAddress(), bonebase.get(i), null, bonesList, objectStructure.getOldMemoryAddress(), blenderContext);
-                    }
-                    bonesList.add(0, new Bone(""));
-                    Bone[] bones = bonesList.toArray(new Bone[bonesList.size()]);
-                    skeleton = new Skeleton(bones);
-                    blenderContext.setSkeleton(armatureObject.getOldMemoryAddress(), skeleton);
+                    if(blenderContext.getSkeleton(armatureObject.getOldMemoryAddress()) == null) {
+                        LOGGER.fine("Creating new skeleton for armature modifier.");
+                        Structure armatureStructure = ((Pointer) armatureObject.getFieldValue("data")).fetchData().get(0);
+                        List<Structure> bonebase = ((Structure) armatureStructure.getFieldValue("bonebase")).evaluateListBase();
+                        List<Bone> bonesList = new ArrayList<Bone>();
+                        for (int i = 0; i < bonebase.size(); ++i) {
+                            this.buildBones(armatureObject.getOldMemoryAddress(), bonebase.get(i), null, bonesList, objectStructure.getOldMemoryAddress(), blenderContext);
+                        }
+                        bonesList.add(0, new Bone(""));
+                        Bone[] bones = bonesList.toArray(new Bone[bonesList.size()]);
+                        skeleton = new Skeleton(bones);
+                        blenderContext.setSkeleton(armatureObject.getOldMemoryAddress(), skeleton);
+                    } else {
+                        skeleton = blenderContext.getSkeleton(armatureObject.getOldMemoryAddress());
+                    }                    
                 }
             } else {
                 modifying = false;