소스 검색

Improvement: Inverse Kinematics now breaks the iteration if the computed
angle change drops below some minimal level.

jmekaelthas 10 년 전
부모
커밋
483156f2ba
1개의 변경된 파일13개의 추가작업 그리고 10개의 파일을 삭제
  1. 13 10
      jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionIK.java

+ 13 - 10
jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionIK.java

@@ -25,19 +25,20 @@ import com.jme3.scene.plugins.blender.math.Vector3d;
  * @author Marcin Roguski (Kaelthas)
  */
 public class ConstraintDefinitionIK extends ConstraintDefinition {
-    private static final float MIN_DISTANCE  = 0.001f;
-    private static final int   FLAG_USE_TAIL = 0x01;
-    private static final int   FLAG_POSITION = 0x20;
+    private static final float MIN_DISTANCE     = 0.001f;
+    private static final float MIN_ANGLE_CHANGE = 0.001f;
+    private static final int   FLAG_USE_TAIL    = 0x01;
+    private static final int   FLAG_POSITION    = 0x20;
 
-    private BonesChain         bones;
+    private BonesChain bones;
     /** The number of affected bones. Zero means that all parent bones of the current bone should take part in baking. */
-    private int                bonesAffected;
+    private int        bonesAffected;
     /** Indicates if the tail of the bone should be used or not. */
-    private boolean            useTail;
+    private boolean    useTail;
     /** The amount of iterations of the algorithm. */
-    private int                iterations;
+    private int        iterations;
     /** The count of bones' chain. */
-    private int                bonesCount    = -1;
+    private int        bonesCount = -1;
 
     public ConstraintDefinitionIK(Structure constraintData, Long ownerOMA, BlenderContext blenderContext) {
         super(constraintData, ownerOMA, blenderContext);
@@ -117,7 +118,9 @@ public class ConstraintDefinitionIK extends ConstraintDefinition {
             Matrix J_1 = J.pseudoinverse();
 
             SimpleMatrix deltaThetas = J_1.mult(deltaP);
-
+            if (deltaThetas.elementMaxAbs() < MIN_ANGLE_CHANGE) {
+                break;
+            }
             for (int j = 0; j < deltaThetas.numRows(); ++j) {
                 double angle = deltaThetas.get(j, 0);
                 Vector3d rotationVector = rotationVectors[j];
@@ -171,7 +174,7 @@ public class ConstraintDefinitionIK extends ConstraintDefinition {
     private static class BonesChain extends ArrayList<BoneContext> {
         private static final long serialVersionUID = -1850524345643600718L;
 
-        private List<Matrix>      bonesMatrices    = new ArrayList<Matrix>();
+        private List<Matrix> bonesMatrices = new ArrayList<Matrix>();
 
         public BonesChain(Bone bone, boolean useTail, int bonesAffected, Collection<Long> alteredOmas, BlenderContext blenderContext) {
             if (bone != null) {