From 3888036176b335ccc38fae3d8378654dfd6e7942 Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Tue, 5 Mar 2013 09:35:35 +0000 Subject: [PATCH] Bugfix: fixed an error that could create wrogn vertex to bone group assignment. This caused animation to be played badly because some vertices remained in their places instead of moving with the proper bone. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10463 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../plugins/blender/animations/ArmatureHelper.java | 14 +++++++------- .../blender/modifiers/ArmatureModifier.java | 9 +++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/animations/ArmatureHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/animations/ArmatureHelper.java index a0112aba6..2775fb21a 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/animations/ArmatureHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/animations/ArmatureHelper.java @@ -31,23 +31,23 @@ */ package com.jme3.scene.plugins.blender.animations; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + import com.jme3.animation.Bone; import com.jme3.animation.BoneTrack; import com.jme3.animation.Skeleton; import com.jme3.math.Matrix4f; -import com.jme3.scene.Spatial; import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.curves.BezierCurve; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Structure; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; /** * This class defines the methods to calculate certain aspects of animation and diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java index c6c8f1e1e..a69103f6b 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java @@ -314,9 +314,10 @@ import com.jme3.util.BufferUtils; List dw = pDW.fetchData(blenderContext.getInputStream()); for (Structure deformWeight : dw) { Integer boneIndex = groupToBoneIndexMap.get(((Number) deformWeight.getFieldValue("def_nr")).intValue()); - // null here means that we came accross group that has no bone attached to - if (boneIndex != null) { - float weight = ((Number) deformWeight.getFieldValue("weight")).floatValue(); + float weight = ((Number) deformWeight.getFieldValue("weight")).floatValue(); + // boneIndex == null: it here means that we came accross group that has no bone attached to, so simply ignore it + // if weight == 0 and weightIndex == 0 then ignore the weight (do not set weight = 0 as a first weight) + if (boneIndex != null && (weight > 0.0f || weightIndex > 0)) { if (weightIndex < MAXIMUM_WEIGHTS_PER_VERTEX) { if (weight == 0.0f) { boneIndex = Integer.valueOf(0); @@ -341,8 +342,8 @@ import com.jme3.util.BufferUtils; weightToIndexMap.put(weight, lowestWeightAndIndex.getValue()); } } + ++weightIndex; } - ++weightIndex; } } else { // 0.0 weight indicates, do not transform this vertex, but keep it in bind pose.