Feature: added support for 'Copy transform' constraint.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/branches/gradle-restructure@11006 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
experimental
Kae..pl 11 years ago
parent 595dc4cd8a
commit 3284164a25
  1. 2
      jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionFactory.java
  2. 73
      jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionTransLike.java

@ -51,6 +51,7 @@ public class ConstraintDefinitionFactory {
CONSTRAINT_CLASSES.put("bSizeLikeConstraint", ConstraintDefinitionSizeLike.class); CONSTRAINT_CLASSES.put("bSizeLikeConstraint", ConstraintDefinitionSizeLike.class);
CONSTRAINT_CLASSES.put("bSizeLimitConstraint", ConstraintDefinitionSizeLimit.class); CONSTRAINT_CLASSES.put("bSizeLimitConstraint", ConstraintDefinitionSizeLimit.class);
CONSTRAINT_CLASSES.put("bKinematicConstraint", ConstraintDefinitionIK.class); CONSTRAINT_CLASSES.put("bKinematicConstraint", ConstraintDefinitionIK.class);
CONSTRAINT_CLASSES.put("bTransLikeConstraint", ConstraintDefinitionTransLike.class);// since blender 2.51
} }
private static final Map<String, String> UNSUPPORTED_CONSTRAINTS = new HashMap<String, String>(); private static final Map<String, String> UNSUPPORTED_CONSTRAINTS = new HashMap<String, String>();
@ -73,7 +74,6 @@ public class ConstraintDefinitionFactory {
// Blender 2.56+ // Blender 2.56+
UNSUPPORTED_CONSTRAINTS.put("bTrackToConstraint", "Track to"); UNSUPPORTED_CONSTRAINTS.put("bTrackToConstraint", "Track to");
UNSUPPORTED_CONSTRAINTS.put("bSameVolumeConstraint", "Same volume"); UNSUPPORTED_CONSTRAINTS.put("bSameVolumeConstraint", "Same volume");
UNSUPPORTED_CONSTRAINTS.put("bTransLikeConstraint", "Trans like");
// Blender 2.62+ // Blender 2.62+
UNSUPPORTED_CONSTRAINTS.put("bCameraSolverConstraint", "Camera solver"); UNSUPPORTED_CONSTRAINTS.put("bCameraSolverConstraint", "Camera solver");
UNSUPPORTED_CONSTRAINTS.put("bObjectSolverConstraint", "Object solver"); UNSUPPORTED_CONSTRAINTS.put("bObjectSolverConstraint", "Object solver");

@ -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";
}
}
Loading…
Cancel
Save