|
@@ -1,7 +1,6 @@
|
|
package com.jme3.scene.plugins.blender.constraints;
|
|
package com.jme3.scene.plugins.blender.constraints;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
-import java.util.Arrays;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -40,26 +39,16 @@ public class ConstraintHelper extends AbstractBlenderHelper {
|
|
private static final Quaternion POS_PARLOC_SPACE_QUATERNION = new Quaternion(new float[] { FastMath.HALF_PI, 0, 0 });
|
|
private static final Quaternion POS_PARLOC_SPACE_QUATERNION = new Quaternion(new float[] { FastMath.HALF_PI, 0, 0 });
|
|
private static final Quaternion NEG_PARLOC_SPACE_QUATERNION = new Quaternion(new float[] { -FastMath.HALF_PI, 0, 0 });
|
|
private static final Quaternion NEG_PARLOC_SPACE_QUATERNION = new Quaternion(new float[] { -FastMath.HALF_PI, 0, 0 });
|
|
|
|
|
|
- private BlenderContext blenderContext;
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
- * Helper constructor. It's main task is to generate the affection
|
|
|
|
- * functions. These functions are common to all ConstraintHelper instances.
|
|
|
|
- * Unfortunately this constructor might grow large. If it becomes too large
|
|
|
|
- * - I shall consider refactoring. The constructor parses the given blender
|
|
|
|
- * version and stores the result. Some functionalities may differ in
|
|
|
|
- * different blender versions.
|
|
|
|
|
|
+ * Helper constructor.
|
|
*
|
|
*
|
|
* @param blenderVersion
|
|
* @param blenderVersion
|
|
* the version read from the blend file
|
|
* the version read from the blend file
|
|
* @param blenderContext
|
|
* @param blenderContext
|
|
* the blender context
|
|
* the blender context
|
|
- * @param fixUpAxis
|
|
|
|
- * a variable that indicates if the Y asxis is the UP axis or not
|
|
|
|
*/
|
|
*/
|
|
- public ConstraintHelper(String blenderVersion, BlenderContext blenderContext, boolean fixUpAxis) {
|
|
|
|
- super(blenderVersion, fixUpAxis);
|
|
|
|
- this.blenderContext = blenderContext;
|
|
|
|
|
|
+ public ConstraintHelper(String blenderVersion, BlenderContext blenderContext) {
|
|
|
|
+ super(blenderVersion, blenderContext);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -231,16 +220,14 @@ public class ConstraintHelper extends AbstractBlenderHelper {
|
|
*/
|
|
*/
|
|
public Transform getTransform(Long oma, String subtargetName, Space space) {
|
|
public Transform getTransform(Long oma, String subtargetName, Space space) {
|
|
Spatial feature = (Spatial) blenderContext.getLoadedFeature(oma, LoadedFeatureDataType.LOADED_FEATURE);
|
|
Spatial feature = (Spatial) blenderContext.getLoadedFeature(oma, LoadedFeatureDataType.LOADED_FEATURE);
|
|
- boolean isArmature = feature.getUserData(ArmatureHelper.ARMETURE_NODE_MARKER) != null;
|
|
|
|
|
|
+ boolean isArmature = feature.getUserData(ArmatureHelper.ARMATURE_NODE_MARKER) != null;
|
|
if (isArmature) {
|
|
if (isArmature) {
|
|
BoneContext targetBoneContext = blenderContext.getBoneByName(subtargetName);
|
|
BoneContext targetBoneContext = blenderContext.getBoneByName(subtargetName);
|
|
Bone bone = targetBoneContext.getBone();
|
|
Bone bone = targetBoneContext.getBone();
|
|
|
|
|
|
switch (space) {
|
|
switch (space) {
|
|
case CONSTRAINT_SPACE_WORLD:
|
|
case CONSTRAINT_SPACE_WORLD:
|
|
- Transform t = new Transform(bone.getModelSpacePosition(), bone.getModelSpaceRotation(), bone.getModelSpaceScale());
|
|
|
|
- System.out.println("A: " + Arrays.toString(t.getRotation().toAngles(null)));
|
|
|
|
- return t;
|
|
|
|
|
|
+ return new Transform(bone.getModelSpacePosition(), bone.getModelSpaceRotation(), bone.getModelSpaceScale());
|
|
case CONSTRAINT_SPACE_LOCAL:
|
|
case CONSTRAINT_SPACE_LOCAL:
|
|
Transform localTransform = new Transform(bone.getLocalPosition(), bone.getLocalRotation());
|
|
Transform localTransform = new Transform(bone.getLocalPosition(), bone.getLocalRotation());
|
|
localTransform.setScale(bone.getLocalScale());
|
|
localTransform.setScale(bone.getLocalScale());
|
|
@@ -264,8 +251,9 @@ public class ConstraintHelper extends AbstractBlenderHelper {
|
|
if (bone.getParent() != null) {
|
|
if (bone.getParent() != null) {
|
|
Bone parent = bone.getParent();
|
|
Bone parent = bone.getParent();
|
|
parentLocalMatrix = this.toMatrix(parent.getLocalPosition(), parent.getLocalRotation(), parent.getLocalScale());
|
|
parentLocalMatrix = this.toMatrix(parent.getLocalPosition(), parent.getLocalRotation(), parent.getLocalScale());
|
|
- } else {// we need to clone it because otherwise we could
|
|
|
|
- // spoil the IDENTITY matrix
|
|
|
|
|
|
+ } else {
|
|
|
|
+ // we need to clone it because otherwise we could spoil
|
|
|
|
+ // the IDENTITY matrix
|
|
parentLocalMatrix = parentLocalMatrix.clone();
|
|
parentLocalMatrix = parentLocalMatrix.clone();
|
|
}
|
|
}
|
|
Matrix4f boneLocalMatrix = this.toMatrix(bone.getLocalPosition(), bone.getLocalRotation(), bone.getLocalScale());
|
|
Matrix4f boneLocalMatrix = this.toMatrix(bone.getLocalPosition(), bone.getLocalRotation(), bone.getLocalScale());
|
|
@@ -309,7 +297,7 @@ public class ConstraintHelper extends AbstractBlenderHelper {
|
|
*/
|
|
*/
|
|
public void applyTransform(Long oma, String subtargetName, Space space, Transform transform) {
|
|
public void applyTransform(Long oma, String subtargetName, Space space, Transform transform) {
|
|
Spatial feature = (Spatial) blenderContext.getLoadedFeature(oma, LoadedFeatureDataType.LOADED_FEATURE);
|
|
Spatial feature = (Spatial) blenderContext.getLoadedFeature(oma, LoadedFeatureDataType.LOADED_FEATURE);
|
|
- boolean isArmature = feature.getUserData(ArmatureHelper.ARMETURE_NODE_MARKER) != null;
|
|
|
|
|
|
+ boolean isArmature = feature.getUserData(ArmatureHelper.ARMATURE_NODE_MARKER) != null;
|
|
if (isArmature) {
|
|
if (isArmature) {
|
|
Skeleton skeleton = blenderContext.getSkeleton(oma);
|
|
Skeleton skeleton = blenderContext.getSkeleton(oma);
|
|
BoneContext targetBoneContext = blenderContext.getBoneByName(subtargetName);
|
|
BoneContext targetBoneContext = blenderContext.getBoneByName(subtargetName);
|
|
@@ -324,7 +312,6 @@ public class ConstraintHelper extends AbstractBlenderHelper {
|
|
bone.setBindTransforms(transform.getTranslation(), transform.getRotation(), transform.getScale());
|
|
bone.setBindTransforms(transform.getTranslation(), transform.getRotation(), transform.getScale());
|
|
break;
|
|
break;
|
|
case CONSTRAINT_SPACE_WORLD:
|
|
case CONSTRAINT_SPACE_WORLD:
|
|
- System.out.println("B: " + Arrays.toString(transform.getRotation().toAngles(null)));
|
|
|
|
Matrix4f boneMatrix = this.toMatrix(transform);
|
|
Matrix4f boneMatrix = this.toMatrix(transform);
|
|
Bone parent = bone.getParent();
|
|
Bone parent = bone.getParent();
|
|
if (parent != null) {
|
|
if (parent != null) {
|
|
@@ -352,8 +339,9 @@ public class ConstraintHelper extends AbstractBlenderHelper {
|
|
if (bone.getParent() != null) {
|
|
if (bone.getParent() != null) {
|
|
parentLocalMatrix = this.toMatrix(bone.getParent().getLocalPosition(), bone.getParent().getLocalRotation(), bone.getParent().getLocalScale());
|
|
parentLocalMatrix = this.toMatrix(bone.getParent().getLocalPosition(), bone.getParent().getLocalRotation(), bone.getParent().getLocalScale());
|
|
parentLocalMatrix.invertLocal();
|
|
parentLocalMatrix.invertLocal();
|
|
- } else {// we need to clone it because otherwise we could
|
|
|
|
- // spoil the IDENTITY matrix
|
|
|
|
|
|
+ } else {
|
|
|
|
+ // we need to clone it because otherwise we could
|
|
|
|
+ // spoil the IDENTITY matrix
|
|
parentLocalMatrix = parentLocalMatrix.clone();
|
|
parentLocalMatrix = parentLocalMatrix.clone();
|
|
}
|
|
}
|
|
Matrix4f m = this.toMatrix(transform.getTranslation(), transform.getRotation(), transform.getScale());
|
|
Matrix4f m = this.toMatrix(transform.getTranslation(), transform.getRotation(), transform.getScale());
|