diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/BoneConstraint.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/BoneConstraint.java
index 386242ed5..a207c4f22 100644
--- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/BoneConstraint.java
+++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/BoneConstraint.java
@@ -1,6 +1,5 @@
package com.jme3.scene.plugins.blender.constraints;
-import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -8,9 +7,7 @@ import com.jme3.animation.Animation;
import com.jme3.animation.Bone;
import com.jme3.animation.BoneTrack;
import com.jme3.animation.Track;
-import com.jme3.math.Quaternion;
import com.jme3.math.Transform;
-import com.jme3.math.Vector3f;
import com.jme3.scene.Spatial;
import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
@@ -181,38 +178,4 @@ import com.jme3.scene.plugins.ogre.AnimData;
}
return false;
}
-
- /**
- * The method applies bone's current position to all of the traces of the
- * given animations.
- *
- * @param boneContext
- * the bone context
- * @param space
- * the bone's evaluation space
- * @param referenceAnimData
- * the object containing the animations
- */
- protected void applyAnimData(BoneContext boneContext, Space space, AnimData referenceAnimData) {
- ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class);
- Transform transform = constraintHelper.getBoneTransform(space, boneContext.getBone());
-
- AnimData animData = blenderContext.getAnimData(boneContext.getBoneOma());
-
- for (Animation animation : referenceAnimData.anims) {
- BoneTrack parentTrack = (BoneTrack) animation.getTracks()[0];
-
- float[] times = parentTrack.getTimes();
- Vector3f[] translations = new Vector3f[times.length];
- Quaternion[] rotations = new Quaternion[times.length];
- Vector3f[] scales = new Vector3f[times.length];
- Arrays.fill(translations, transform.getTranslation());
- Arrays.fill(rotations, transform.getRotation());
- Arrays.fill(scales, transform.getScale());
- for (Animation anim : animData.anims) {
- anim.addTrack(new BoneTrack(animData.skeleton.getBoneIndex(boneContext.getBone()), times, translations, rotations, scales));
- }
- }
- blenderContext.setAnimData(boneContext.getBoneOma(), animData);
- }
}
diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/Constraint.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/Constraint.java
index 7a883c8d0..3a92e6b59 100644
--- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/Constraint.java
+++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/Constraint.java
@@ -1,10 +1,17 @@
package com.jme3.scene.plugins.blender.constraints;
+import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
+import com.jme3.animation.Animation;
+import com.jme3.animation.BoneTrack;
+import com.jme3.math.Quaternion;
+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.animations.Ipo;
import com.jme3.scene.plugins.blender.constraints.ConstraintHelper.Space;
import com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefinition;
@@ -12,6 +19,7 @@ import com.jme3.scene.plugins.blender.constraints.definitions.ConstraintDefiniti
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Pointer;
import com.jme3.scene.plugins.blender.file.Structure;
+import com.jme3.scene.plugins.ogre.AnimData;
/**
* The implementation of a constraint.
@@ -124,4 +132,38 @@ public abstract class Constraint {
* that will have non modifying values for translation, rotation and scale and will have the same amount of frames as its parent has.
*/
protected abstract void prepareTracksForApplyingConstraints();
+
+ /**
+ * The method applies bone's current position to all of the traces of the
+ * given animations.
+ *
+ * @param boneContext
+ * the bone context
+ * @param space
+ * the bone's evaluation space
+ * @param referenceAnimData
+ * the object containing the animations
+ */
+ protected void applyAnimData(BoneContext boneContext, Space space, AnimData referenceAnimData) {
+ ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class);
+ Transform transform = constraintHelper.getBoneTransform(space, boneContext.getBone());
+
+ AnimData animData = blenderContext.getAnimData(boneContext.getBoneOma());
+
+ for (Animation animation : referenceAnimData.anims) {
+ BoneTrack parentTrack = (BoneTrack) animation.getTracks()[0];
+
+ float[] times = parentTrack.getTimes();
+ Vector3f[] translations = new Vector3f[times.length];
+ Quaternion[] rotations = new Quaternion[times.length];
+ Vector3f[] scales = new Vector3f[times.length];
+ Arrays.fill(translations, transform.getTranslation());
+ Arrays.fill(rotations, transform.getRotation());
+ Arrays.fill(scales, transform.getScale());
+ for (Animation anim : animData.anims) {
+ anim.addTrack(new BoneTrack(animData.skeleton.getBoneIndex(boneContext.getBone()), times, translations, rotations, scales));
+ }
+ }
+ blenderContext.setAnimData(boneContext.getBoneOma(), animData);
+ }
}
\ No newline at end of file
diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/SpatialConstraint.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/SpatialConstraint.java
index 20ec82aa5..b8179ac93 100644
--- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/SpatialConstraint.java
+++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/SpatialConstraint.java
@@ -8,7 +8,9 @@ import java.util.logging.Logger;
import com.jme3.animation.AnimControl;
import com.jme3.animation.Animation;
import com.jme3.animation.Bone;
+import com.jme3.animation.BoneTrack;
import com.jme3.animation.SpatialTrack;
+import com.jme3.animation.Track;
import com.jme3.math.Quaternion;
import com.jme3.math.Transform;
import com.jme3.math.Vector3f;
@@ -28,7 +30,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
* This includes: nodes, cameras nodes and light nodes.
* @author Marcin Roguski (Kaelthas)
*/
-/* package */class SpatialConstraint extends BoneConstraint {
+/* package */class SpatialConstraint extends Constraint {
private static final Logger LOGGER = Logger.getLogger(SpatialConstraint.class.getName());
/** The owner of the constraint. */
@@ -40,6 +42,14 @@ import com.jme3.scene.plugins.ogre.AnimData;
super(constraintStructure, ownerOMA, influenceIpo, blenderContext);
}
+ @Override
+ protected boolean validate() {
+ if (targetOMA != null) {
+ return blenderContext.getLoadedFeature(targetOMA, LoadedFeatureDataType.LOADED_FEATURE) != null;
+ }
+ return true;
+ }
+
@Override
public void performBakingOperation() {
this.owner = (Spatial) blenderContext.getLoadedFeature(ownerOMA, LoadedFeatureDataType.LOADED_FEATURE);
@@ -130,6 +140,29 @@ import com.jme3.scene.plugins.ogre.AnimData;
}
}
+ /**
+ * The method determines if the bone has animations.
+ *
+ * @param boneOMA
+ * OMA of the animation's owner
+ * @return true if the target has animations and false otherwise
+ */
+ protected boolean hasAnimation(Long boneOMA) {
+ AnimData animData = blenderContext.getAnimData(boneOMA);
+ if (animData != null) {
+ Bone bone = blenderContext.getBoneContext(boneOMA).getBone();
+ int boneIndex = animData.skeleton.getBoneIndex(bone);
+ for (Animation animation : animData.anims) {
+ for (Track track : animation.getTracks()) {
+ if (track instanceof BoneTrack && ((BoneTrack) track).getTargetBoneIndex() == boneIndex) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
/**
* This method applies spatial transform on each frame of the given
* animations.