Bugfix: fixed a bug (that occured during work on IK) that caused NPE to be raised when constraint other than IK was applied to bone.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10851 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
experimental
Kae..pl 11 years ago
parent 1df0a0a17b
commit 2ccadb7a7a
  1. 32
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinition.java
  2. 8
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionDistLimit.java
  3. 6
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionLocLike.java
  4. 6
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionLocLimit.java
  5. 6
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionRotLike.java
  6. 6
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionRotLimit.java
  7. 6
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionSizeLike.java
  8. 6
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionSizeLimit.java

@ -2,9 +2,11 @@ package com.jme3.scene.plugins.blender.constraints.definitions;
import java.util.Set;
import com.jme3.animation.Bone;
import com.jme3.math.Transform;
import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
import com.jme3.scene.plugins.blender.animations.BoneContext;
import com.jme3.scene.plugins.blender.constraints.ConstraintHelper;
import com.jme3.scene.plugins.blender.constraints.ConstraintHelper.Space;
import com.jme3.scene.plugins.blender.file.Structure;
@ -67,6 +69,36 @@ public abstract class ConstraintDefinition {
return owner;
}
/**
* The method gets the owner's transformation. The owner can be either bone or spatial.
* @param ownerSpace
* the space in which the computed transformation is given
* @return the constraint owner's transformation
*/
protected Transform getOwnerTransform(Space ownerSpace) {
if (this.getOwner() instanceof Bone) {
BoneContext boneContext = blenderContext.getBoneContext(ownerOMA);
return constraintHelper.getTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace);
}
return constraintHelper.getTransform(ownerOMA, null, ownerSpace);
}
/**
* The method applies the given transformation to the owner.
* @param ownerTransform
* the transformation to apply to the owner
* @param ownerSpace
* the space that defines which owner's transformation (ie. global, local, etc. will be set)
*/
protected void applyOwnerTransform(Transform ownerTransform, Space ownerSpace) {
if (this.getOwner() instanceof Bone) {
BoneContext boneContext = blenderContext.getBoneContext(ownerOMA);
constraintHelper.applyTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace, ownerTransform);
} else {
constraintHelper.applyTransform(ownerOMA, null, ownerSpace, ownerTransform);
}
}
/**
* @return <b>true</b> if the definition is implemented and <b>false</b>
* otherwise

@ -4,7 +4,6 @@ import com.jme3.animation.Bone;
import com.jme3.math.Transform;
import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.BoneContext;
import com.jme3.scene.plugins.blender.constraints.ConstraintHelper.Space;
import com.jme3.scene.plugins.blender.file.Structure;
@ -34,8 +33,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
return;
}
BoneContext boneContext = blenderContext.getBoneContext(ownerOMA);
Transform ownerTransform = constraintHelper.getTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace);
Transform ownerTransform = this.getOwnerTransform(ownerSpace);
Vector3f v = ownerTransform.getTranslation().subtract(targetTransform.getTranslation());
float currentDistance = v.length();
@ -66,8 +64,8 @@ import com.jme3.scene.plugins.blender.file.Structure;
default:
throw new IllegalStateException("Unknown distance limit constraint mode: " + mode);
}
constraintHelper.applyTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace, ownerTransform);
this.applyOwnerTransform(ownerTransform, ownerSpace);
}
@Override

@ -4,7 +4,6 @@ import com.jme3.animation.Bone;
import com.jme3.math.Transform;
import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.BoneContext;
import com.jme3.scene.plugins.blender.constraints.ConstraintHelper.Space;
import com.jme3.scene.plugins.blender.file.Structure;
@ -51,8 +50,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
return;
}
BoneContext boneContext = blenderContext.getBoneContext(ownerOMA);
Transform ownerTransform = constraintHelper.getTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace);
Transform ownerTransform = this.getOwnerTransform(ownerSpace);
Vector3f ownerLocation = ownerTransform.getTranslation();
Vector3f targetLocation = targetTransform.getTranslation();
@ -89,7 +87,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
ownerLocation.addLocal(startLocation);
}
constraintHelper.applyTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace, ownerTransform);
this.applyOwnerTransform(ownerTransform, ownerSpace);
}
@Override

@ -4,7 +4,6 @@ import com.jme3.animation.Bone;
import com.jme3.math.Transform;
import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.BoneContext;
import com.jme3.scene.plugins.blender.constraints.ConstraintHelper.Space;
import com.jme3.scene.plugins.blender.file.Structure;
@ -61,8 +60,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
return;
}
BoneContext boneContext = blenderContext.getBoneContext(ownerOMA);
Transform ownerTransform = constraintHelper.getTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace);
Transform ownerTransform = this.getOwnerTransform(ownerSpace);
Vector3f translation = ownerTransform.getTranslation();
@ -85,7 +83,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
translation.z -= (translation.z - limits[2][1]) * influence;
}
constraintHelper.applyTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace, ownerTransform);
this.applyOwnerTransform(ownerTransform, ownerSpace);
}
@Override

@ -3,7 +3,6 @@ package com.jme3.scene.plugins.blender.constraints.definitions;
import com.jme3.math.Quaternion;
import com.jme3.math.Transform;
import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.BoneContext;
import com.jme3.scene.plugins.blender.constraints.ConstraintHelper.Space;
import com.jme3.scene.plugins.blender.file.Structure;
@ -30,8 +29,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
@Override
public void bake(Space ownerSpace, Space targetSpace, Transform targetTransform, float influence) {
BoneContext boneContext = blenderContext.getBoneContext(ownerOMA);
Transform ownerTransform = constraintHelper.getTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace);
Transform ownerTransform = this.getOwnerTransform(ownerSpace);
Quaternion ownerRotation = ownerTransform.getRotation();
ownerAngles = ownerRotation.toAngles(ownerAngles);
@ -70,7 +68,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
// TODO
}
constraintHelper.applyTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace, ownerTransform);
this.applyOwnerTransform(ownerTransform, ownerSpace);
}
@Override

@ -3,7 +3,6 @@ package com.jme3.scene.plugins.blender.constraints.definitions;
import com.jme3.math.FastMath;
import com.jme3.math.Transform;
import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.BoneContext;
import com.jme3.scene.plugins.blender.constraints.ConstraintHelper.Space;
import com.jme3.scene.plugins.blender.file.Structure;
@ -70,8 +69,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
@Override
public void bake(Space ownerSpace, Space targetSpace, Transform targetTransform, float influence) {
BoneContext boneContext = blenderContext.getBoneContext(ownerOMA);
Transform ownerTransform = constraintHelper.getTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace);
Transform ownerTransform = this.getOwnerTransform(ownerSpace);
ownerTransform.getRotation().toAngles(angles);
// make sure that the rotations are always in range [0, 2PI)
@ -111,7 +109,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
}
ownerTransform.getRotation().fromAngles(angles);
constraintHelper.applyTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace, ownerTransform);
this.applyOwnerTransform(ownerTransform, ownerSpace);
}
@Override

@ -3,7 +3,6 @@ package com.jme3.scene.plugins.blender.constraints.definitions;
import com.jme3.math.Transform;
import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.BoneContext;
import com.jme3.scene.plugins.blender.constraints.ConstraintHelper.Space;
import com.jme3.scene.plugins.blender.file.Structure;
@ -33,8 +32,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
@Override
public void bake(Space ownerSpace, Space targetSpace, Transform targetTransform, float influence) {
BoneContext boneContext = blenderContext.getBoneContext(ownerOMA);
Transform ownerTransform = constraintHelper.getTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace);
Transform ownerTransform = this.getOwnerTransform(ownerSpace);
Vector3f ownerScale = ownerTransform.getScale();
Vector3f targetScale = targetTransform.getScale();
@ -56,7 +54,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
}
ownerScale.addLocal(offset);
constraintHelper.applyTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace, ownerTransform);
this.applyOwnerTransform(ownerTransform, ownerSpace);
}
@Override

@ -3,7 +3,6 @@ package com.jme3.scene.plugins.blender.constraints.definitions;
import com.jme3.math.Transform;
import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.BoneContext;
import com.jme3.scene.plugins.blender.constraints.ConstraintHelper.Space;
import com.jme3.scene.plugins.blender.file.Structure;
@ -55,8 +54,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
@Override
public void bake(Space ownerSpace, Space targetSpace, Transform targetTransform, float influence) {
BoneContext boneContext = blenderContext.getBoneContext(ownerOMA);
Transform ownerTransform = constraintHelper.getTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace);
Transform ownerTransform = this.getOwnerTransform(ownerSpace);
Vector3f scale = ownerTransform.getScale();
if ((flag & LIMIT_XMIN) != 0 && scale.x < limits[0][0]) {
@ -78,7 +76,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
scale.z -= (scale.z - limits[2][1]) * influence;
}
constraintHelper.applyTransform(boneContext.getArmatureObjectOMA(), boneContext.getBone().getName(), ownerSpace, ownerTransform);
this.applyOwnerTransform(ownerTransform, ownerSpace);
}
@Override

Loading…
Cancel
Save