diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/ConstraintHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/ConstraintHelper.java index b0c9755dc..e74447cca 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/ConstraintHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/ConstraintHelper.java @@ -1,9 +1,11 @@ package com.jme3.scene.plugins.blender.helpers.v249; +import java.nio.FloatBuffer; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.logging.Level; import com.jme3.animation.Bone; import com.jme3.animation.BoneAnimation; @@ -12,8 +14,11 @@ import com.jme3.animation.Skeleton; import com.jme3.math.FastMath; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.Mesh; import com.jme3.scene.Node; import com.jme3.scene.Spatial; +import com.jme3.scene.VertexBuffer.Type; import com.jme3.scene.plugins.blender.data.Structure; import com.jme3.scene.plugins.blender.exception.BlenderFileException; import com.jme3.scene.plugins.blender.structures.AbstractInfluenceFunction; @@ -23,8 +28,8 @@ import com.jme3.scene.plugins.blender.structures.ConstraintType; import com.jme3.scene.plugins.blender.structures.Ipo; import com.jme3.scene.plugins.blender.utils.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.utils.DataRepository; +import com.jme3.scene.plugins.blender.utils.DataRepository.LoadedFeatureDataType; import com.jme3.scene.plugins.blender.utils.Pointer; -import java.util.logging.Level; /** * This class should be used for constraint calculations. @@ -404,7 +409,6 @@ public class ConstraintHelper extends AbstractBlenderHelper { //ROTLIMIT constraint influenceFunctions[ConstraintType.CONSTRAINT_TYPE_ROTLIMIT.getConstraintId()] = new AbstractInfluenceFunction(ConstraintType.CONSTRAINT_TYPE_ROTLIMIT, dataRepository) { - @Override public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation, Constraint constraint) { Structure constraintStructure = constraint.getData(); @@ -459,11 +463,57 @@ public class ConstraintHelper extends AbstractBlenderHelper { //SHRINKWRAP constraint (TODO: to implement) influenceFunctions[ConstraintType.CONSTRAINT_TYPE_SHRINKWRAP.getConstraintId()] = new AbstractInfluenceFunction(ConstraintType.CONSTRAINT_TYPE_SHRINKWRAP, dataRepository) { + @Override + public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation, Constraint constraint) { + Structure constraintStructure = constraint.getData(); + this.validateConstraintType(constraintStructure); + + //loading mesh points (blender ensures that the target is a mesh-object) + List pts = new ArrayList(); + try { + Node node = (Node)this.getTarget(constraint, LoadedFeatureDataType.LOADED_FEATURE); + for(Spatial spatial : node.getChildren()) { + if(spatial instanceof Geometry) { + Mesh mesh = ((Geometry) spatial).getMesh(); + FloatBuffer floatBuffer = mesh.getFloatBuffer(Type.Position); + for(int i=0;i 0) { + protected Object getTarget(Constraint constraint, LoadedFeatureDataType loadedFeatureDataType) throws BlenderFileException { + //TODO: load the feature through objectHelper, this way we are certain the object loads and has + //his own constraints applied to traces + ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); + //subtarget goes first + Object subtarget = constraint.getData().getFieldValue("subtarget"); + String subtargetName = subtarget==null ? null : subtarget.toString(); + if (subtargetName!=null && subtargetName.length() > 0) { + //TODO: what if it is not yet loaded ??? return dataRepository.getLoadedFeature(subtargetName, loadedFeatureDataType); } - return targetObject; + //and now use the target + Long targetOMA = ((Pointer) constraint.getData().getFieldValue("target")).getOldMemoryAddress(); + Structure objectStructure = dataRepository.getFileBlock(targetOMA).getStructure(dataRepository); + return objectHelper.toObject(objectStructure, dataRepository); } /** diff --git a/engine/src/test-data/Blender/2.4x/constraints.blend b/engine/src/test-data/Blender/2.4x/constraints.blend index 7b54c2987..53976ad01 100644 Binary files a/engine/src/test-data/Blender/2.4x/constraints.blend and b/engine/src/test-data/Blender/2.4x/constraints.blend differ