From 05bdd7b1c901e85c6a99b68b8d6c2e1ad3102b59 Mon Sep 17 00:00:00 2001 From: jmekaelthas Date: Tue, 25 Nov 2014 18:55:40 +0100 Subject: [PATCH] Bugfix: fixed artifacts that were caused by adding bones with no weight to bone index buffer. --- .../plugins/blender/meshes/TemporalMesh.java | 8 +++++- .../blender/modifiers/ArmatureModifier.java | 27 ++++++++++--------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/TemporalMesh.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/TemporalMesh.java index c359f6219..e11ee706a 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/TemporalMesh.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/TemporalMesh.java @@ -518,9 +518,15 @@ public class TemporalMesh extends Geometry { Map vertexGroupsForVertex = vertexGroups.get(vertIndex); for (Entry 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); } } diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java index 8e1051150..b59f3d05c 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java +++ b/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 bonebase = ((Structure) armatureStructure.getFieldValue("bonebase")).evaluateListBase(); - List bonesList = new ArrayList(); - 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 bonebase = ((Structure) armatureStructure.getFieldValue("bonebase")).evaluateListBase(); + List bonesList = new ArrayList(); + 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;