From 3284164a25eea6db305247699771b4ea66c159ce Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Sat, 1 Feb 2014 12:39:29 +0000 Subject: [PATCH] Feature: added support for 'Copy transform' constraint. git-svn-id: https://jmonkeyengine.googlecode.com/svn/branches/gradle-restructure@11006 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../ConstraintDefinitionFactory.java | 2 +- .../ConstraintDefinitionTransLike.java | 73 +++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionTransLike.java diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionFactory.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionFactory.java index 080881ea1..fba5ef1e4 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionFactory.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionFactory.java @@ -51,6 +51,7 @@ public class ConstraintDefinitionFactory { CONSTRAINT_CLASSES.put("bSizeLikeConstraint", ConstraintDefinitionSizeLike.class); CONSTRAINT_CLASSES.put("bSizeLimitConstraint", ConstraintDefinitionSizeLimit.class); CONSTRAINT_CLASSES.put("bKinematicConstraint", ConstraintDefinitionIK.class); + CONSTRAINT_CLASSES.put("bTransLikeConstraint", ConstraintDefinitionTransLike.class);// since blender 2.51 } private static final Map UNSUPPORTED_CONSTRAINTS = new HashMap(); @@ -73,7 +74,6 @@ public class ConstraintDefinitionFactory { // Blender 2.56+ UNSUPPORTED_CONSTRAINTS.put("bTrackToConstraint", "Track to"); UNSUPPORTED_CONSTRAINTS.put("bSameVolumeConstraint", "Same volume"); - UNSUPPORTED_CONSTRAINTS.put("bTransLikeConstraint", "Trans like"); // Blender 2.62+ UNSUPPORTED_CONSTRAINTS.put("bCameraSolverConstraint", "Camera solver"); UNSUPPORTED_CONSTRAINTS.put("bObjectSolverConstraint", "Object solver"); diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionTransLike.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionTransLike.java new file mode 100644 index 000000000..826982ac5 --- /dev/null +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionTransLike.java @@ -0,0 +1,73 @@ +package com.jme3.scene.plugins.blender.constraints.definitions; + +import com.jme3.animation.Bone; +import com.jme3.animation.Skeleton; +import com.jme3.math.Matrix4f; +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.Pointer; +import com.jme3.scene.plugins.blender.file.Structure; +import com.jme3.scene.plugins.blender.objects.ObjectHelper; +import com.jme3.util.TempVars; + +/** + * This class represents 'Trans like' constraint type in blender. + * + * @author Marcin Roguski (Kaelthas) + */ +public class ConstraintDefinitionTransLike extends ConstraintDefinition { + private Long targetOMA; + private String subtargetName; + + public ConstraintDefinitionTransLike(Structure constraintData, Long ownerOMA, BlenderContext blenderContext) { + super(constraintData, ownerOMA, blenderContext); + Pointer pTarget = (Pointer) constraintData.getFieldValue("tar"); + targetOMA = pTarget.getOldMemoryAddress(); + Object subtarget = constraintData.getFieldValue("subtarget"); + if (subtarget != null) { + subtargetName = subtarget.toString(); + } + } + + @Override + public void bake(Space ownerSpace, Space targetSpace, Transform targetTransform, float influence) { + Object target = this.getTarget();// Bone or Node + Object owner = this.getOwner();// Bone or Node + if (!target.getClass().equals(owner.getClass())) { + ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class); + + TempVars tempVars = TempVars.get(); + Matrix4f m = constraintHelper.toMatrix(targetTransform, tempVars.tempMat4); + tempVars.tempMat42.set(BoneContext.BONE_ARMATURE_TRANSFORMATION_MATRIX); + if (target instanceof Bone) { + tempVars.tempMat42.invertLocal(); + } + m = m.multLocal(tempVars.tempMat42); + tempVars.release(); + + targetTransform = new Transform(m.toTranslationVector(), m.toRotationQuat(), m.toScaleVector()); + } + this.applyOwnerTransform(targetTransform, ownerSpace); + } + + /** + * @return the target feature; it is either Node or Bone (vertex group subtarger is not yet supported) + */ + private Object getTarget() { + Object target = blenderContext.getLoadedFeature(targetOMA, LoadedFeatureDataType.LOADED_FEATURE); + if (subtargetName != null && blenderContext.getMarkerValue(ObjectHelper.ARMATURE_NODE_MARKER, target) != null) { + Skeleton skeleton = blenderContext.getSkeleton(targetOMA); + target = skeleton.getBone(subtargetName); + } + return target; + } + + @Override + public String getConstraintTypeName() { + return "Copy transforms"; + } +}