Refactoring to constraints. Implementation now not dependant on the animation type.

Removing deprecated animation classes.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8303 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 13 years ago
parent c773395ace
commit 6c341850d2
  1. 33
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/Constraint.java
  2. 5
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintAction.java
  3. 5
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintChildOf.java
  4. 5
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintClampTo.java
  5. 9
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintDistLimit.java
  6. 5
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintFollowPath.java
  7. 174
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintInverseKinematics.java
  8. 15
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLocLike.java
  9. 15
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLocLimit.java
  10. 5
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLockTrack.java
  11. 5
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintMinMax.java
  12. 5
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintNull.java
  13. 5
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintPython.java
  14. 5
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRigidBodyJoint.java
  15. 15
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRotLike.java
  16. 15
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRotLimit.java
  17. 17
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintShrinkWrap.java
  18. 15
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintSizeLike.java
  19. 15
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintSizeLimit.java
  20. 5
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintStretchTo.java
  21. 5
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintTransform.java
  22. 12
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java

@ -1,9 +1,7 @@
package com.jme3.scene.plugins.blender.constraints; package com.jme3.scene.plugins.blender.constraints;
import com.jme3.animation.Bone; import com.jme3.animation.Animation;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Track;
import com.jme3.animation.BoneTrack;
import com.jme3.animation.Skeleton;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.Node; import com.jme3.scene.Node;
@ -25,7 +23,7 @@ public abstract class Constraint {
/** The name of this constraint. */ /** The name of this constraint. */
protected final String name; protected final String name;
/** The old memory address of the constraint's owner. */ /** The old memory address of the constraint's owner. */
protected final Long boneOMA; protected Long boneOMA = -1L;
protected final Space ownerSpace; protected final Space ownerSpace;
protected final Space targetSpace; protected final Space targetSpace;
/** The structure with constraint's data. */ /** The structure with constraint's data. */
@ -101,16 +99,15 @@ public abstract class Constraint {
* the bone animation that affects the skeleton * the bone animation that affects the skeleton
* @return the bone track for the bone that is being affected by the constraint * @return the bone track for the bone that is being affected by the constraint
*/ */
protected BoneTrack getBoneTrack(Skeleton skeleton, BoneAnimation boneAnimation) { protected Track<?> getTrack(Animation animation, int targetIndex) {
Bone bone = (Bone) blenderContext.getLoadedFeature(boneOMA, LoadedFeatureDataType.LOADED_FEATURE); if(boneOMA >= 0) {//bone animation
int boneIndex = bone==null ? 0 : skeleton.getBoneIndex(bone);//bone==null may mean the object animation for(Track<?> track : animation.getTracks()) {
if (boneIndex != -1) { if(track.getTargetIndex() == targetIndex) {
//searching for track for this bone return track;
for (BoneTrack boneTrack : boneAnimation.getTracks()) {
if (boneTrack.getTargetBoneIndex() == boneIndex) {
return boneTrack;
} }
} }
} else {//spatial animation
return animation.getTracks()[0];
} }
return null; return null;
} }
@ -203,14 +200,12 @@ public abstract class Constraint {
/** /**
* This method affects the bone animation tracks for the given skeleton. * This method affects the bone animation tracks for the given skeleton.
* *
* @param skeleton * @param animation
* the skeleton containing the affected bones by constraint
* @param boneAnimation
* the bone animation baked traces * the bone animation baked traces
* @param constraint * @param targetIndex
* the constraint * the index of the constraint's target object
*/ */
public abstract void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation); public abstract void affectAnimation(Animation animation, int targetIndex);
/** /**
* The space of target or owner transformation. * The space of target or owner transformation.

@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
@ -38,7 +37,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
// TODO: implement 'Action' constraint // TODO: implement 'Action' constraint
LOGGER.log(Level.WARNING, "'Action' constraint NOT implemented!"); LOGGER.log(Level.WARNING, "'Action' constraint NOT implemented!");
} }

@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
@ -38,7 +37,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
// TODO: implement ChildOf constraint // TODO: implement ChildOf constraint
LOGGER.log(Level.WARNING, "ChildOf constraint NOT implemented!"); LOGGER.log(Level.WARNING, "ChildOf constraint NOT implemented!");
} }

@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
@ -39,7 +38,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
//TODO: implement when curves are implemented //TODO: implement when curves are implemented
LOGGER.log(Level.INFO, "'Clamp to' not yet implemented! Curves not yet implemented!", this.getName()); LOGGER.log(Level.INFO, "'Clamp to' not yet implemented! Curves not yet implemented!", this.getName());
} }

@ -1,8 +1,7 @@
package com.jme3.scene.plugins.blender.constraints; package com.jme3.scene.plugins.blender.constraints;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.BoneTrack; import com.jme3.animation.Track;
import com.jme3.animation.Skeleton;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
@ -39,9 +38,9 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
Vector3f targetLocation = this.getTargetLocation(); Vector3f targetLocation = this.getTargetLocation();
BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); Track<?> boneTrack = this.getTrack(animation, targetIndex);
if (boneTrack != null) { if (boneTrack != null) {
//TODO: target vertex group !!! //TODO: target vertex group !!!
float dist = ((Number) data.getFieldValue("dist")).floatValue(); float dist = ((Number) data.getFieldValue("dist")).floatValue();

@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
@ -38,7 +37,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
//TODO: implement when curves are implemented //TODO: implement when curves are implemented
LOGGER.log(Level.INFO, "'Follow path' not implemented! Curves not yet implemented!"); LOGGER.log(Level.INFO, "'Follow path' not implemented! Curves not yet implemented!");
} }

@ -1,24 +1,12 @@
package com.jme3.scene.plugins.blender.constraints; package com.jme3.scene.plugins.blender.constraints;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.animation.Bone; import com.jme3.animation.Animation;
import com.jme3.animation.BoneAnimation;
import com.jme3.animation.Skeleton;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Transform;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
import com.jme3.scene.plugins.blender.animations.CalculationBone;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
import com.jme3.scene.plugins.blender.objects.ObjectHelper;
/** /**
* This class represents 'Inverse kinematics' constraint type in blender. * This class represents 'Inverse kinematics' constraint type in blender.
@ -49,28 +37,28 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
try { // try {
// IK solver is only attached to bones // IK solver is only attached to bones
Bone ownerBone = (Bone) blenderContext.getLoadedFeature(boneOMA, LoadedFeatureDataType.LOADED_FEATURE); // Bone ownerBone = (Bone) blenderContext.getLoadedFeature(boneOMA, LoadedFeatureDataType.LOADED_FEATURE);
//
// get the target point // // get the target point
Object targetObject = this.getTarget(LoadedFeatureDataType.LOADED_FEATURE); // Object targetObject = this.getTarget(LoadedFeatureDataType.LOADED_FEATURE);
Vector3f pt = null;// Point Target // Vector3f pt = null;// Point Target
if (targetObject instanceof Bone) { // if (targetObject instanceof Bone) {
pt = ((Bone) targetObject).getModelSpacePosition(); // pt = ((Bone) targetObject).getModelSpacePosition();
} else if (targetObject instanceof Node) { // } else if (targetObject instanceof Node) {
pt = ((Node) targetObject).getWorldTranslation(); // pt = ((Node) targetObject).getWorldTranslation();
} else if (targetObject instanceof Skeleton) { // } else if (targetObject instanceof Skeleton) {
Structure armatureNodeStructure = (Structure) this.getTarget(LoadedFeatureDataType.LOADED_STRUCTURE); // Structure armatureNodeStructure = (Structure) this.getTarget(LoadedFeatureDataType.LOADED_STRUCTURE);
ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class); // ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
Transform transform = objectHelper.getTransformation(armatureNodeStructure, blenderContext); // Transform transform = objectHelper.getTransformation(armatureNodeStructure, blenderContext);
pt = transform.getTranslation(); // pt = transform.getTranslation();
} else { // } else {
throw new IllegalStateException( // throw new IllegalStateException(
"Unknown target object type! Should be Node, Bone or Skeleton and there is: " // "Unknown target object type! Should be Node, Bone or Skeleton and there is: "
+ targetObject.getClass().getName()); // + targetObject.getClass().getName());
} // }
//fetching the owner's bone track //fetching the owner's bone track
// BoneTrack ownerBoneTrack = null; // BoneTrack ownerBoneTrack = null;
@ -82,43 +70,43 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
// } // }
// } // }
// int ownerBoneFramesCount = ownerBoneTrack==null ? 0 : ownerBoneTrack.getTimes().length; // int ownerBoneFramesCount = ownerBoneTrack==null ? 0 : ownerBoneTrack.getTimes().length;
//
// preparing data // // preparing data
int maxIterations = ((Number) data.getFieldValue("iterations")).intValue(); // int maxIterations = ((Number) data.getFieldValue("iterations")).intValue();
CalculationBone[] bones = this.getBonesToCalculate(ownerBone, skeleton, boneAnimation); // CalculationBone[] bones = this.getBonesToCalculate(ownerBone, skeleton, boneAnimation);
// for (int i = 0; i < bones.length; ++i) { // for (int i = 0; i < bones.length; ++i) {
// System.out.println(Arrays.toString(bones[i].track.getTranslations())); // System.out.println(Arrays.toString(bones[i].track.getTranslations()));
// System.out.println(Arrays.toString(bones[i].track.getRotations())); // System.out.println(Arrays.toString(bones[i].track.getRotations()));
// System.out.println("==============================="); // System.out.println("===============================");
// } // }
Quaternion rotation = new Quaternion(); // Quaternion rotation = new Quaternion();
//all tracks should have the same amount of frames // //all tracks should have the same amount of frames
int framesCount = bones[0].getBoneFramesCount(); // int framesCount = bones[0].getBoneFramesCount();
assert framesCount >=1; // assert framesCount >=1;
for (int frame = 0; frame < framesCount; ++frame) { // for (int frame = 0; frame < framesCount; ++frame) {
float error = IK_SOLVER_ERROR; // float error = IK_SOLVER_ERROR;
int iteration = 0; // int iteration = 0;
while (error >= IK_SOLVER_ERROR && iteration <= maxIterations) { // while (error >= IK_SOLVER_ERROR && iteration <= maxIterations) {
// rotating the bones // // rotating the bones
for (int i = 0; i < bones.length - 1; ++i) { // for (int i = 0; i < bones.length - 1; ++i) {
Vector3f pe = bones[i].getEndPoint(); // Vector3f pe = bones[i].getEndPoint();
Vector3f pc = bones[i + 1].getWorldTranslation().clone(); // Vector3f pc = bones[i + 1].getWorldTranslation().clone();
//
Vector3f peSUBpc = pe.subtract(pc).normalizeLocal(); // Vector3f peSUBpc = pe.subtract(pc).normalizeLocal();
Vector3f ptSUBpc = pt.subtract(pc).normalizeLocal(); // Vector3f ptSUBpc = pt.subtract(pc).normalizeLocal();
//
float theta = FastMath.acos(peSUBpc.dot(ptSUBpc)); // float theta = FastMath.acos(peSUBpc.dot(ptSUBpc));
Vector3f direction = peSUBpc.cross(ptSUBpc).normalizeLocal(); // Vector3f direction = peSUBpc.cross(ptSUBpc).normalizeLocal();
bones[i].rotate(rotation.fromAngleAxis(theta, direction), frame); // bones[i].rotate(rotation.fromAngleAxis(theta, direction), frame);
} // }
error = pt.subtract(bones[0].getEndPoint()).length(); // error = pt.subtract(bones[0].getEndPoint()).length();
++iteration; // ++iteration;
} // }
} // }
//
for (CalculationBone bone : bones) { // for (CalculationBone bone : bones) {
bone.applyCalculatedTracks(); // bone.applyCalculatedTracks();
} // }
// System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"); // System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
// for (int i = 0; i < bones.length; ++i) { // for (int i = 0; i < bones.length; ++i) {
@ -126,26 +114,26 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
// System.out.println(Arrays.toString(bones[i].track.getRotations())); // System.out.println(Arrays.toString(bones[i].track.getRotations()));
// System.out.println("==============================="); // System.out.println("===============================");
// } // }
} catch(BlenderFileException e) { // } catch(BlenderFileException e) {
LOGGER.severe(e.getLocalizedMessage()); // LOGGER.severe(e.getLocalizedMessage());
} // }
} }
/** // /**
* This method returns bones used for rotation calculations. // * This method returns bones used for rotation calculations.
* @param bone // * @param bone
* the bone to which the constraint is applied // * the bone to which the constraint is applied
* @param skeleton // * @param skeleton
* the skeleton owning the bone and its ancestors // * the skeleton owning the bone and its ancestors
* @param boneAnimation // * @param boneAnimation
* the bone animation data that stores the traces for the skeleton's bones // * the bone animation data that stores the traces for the skeleton's bones
* @return a list of bones to imitate the bone's movement during IK solving // * @return a list of bones to imitate the bone's movement during IK solving
*/ // */
private CalculationBone[] getBonesToCalculate(Bone bone, Skeleton skeleton, BoneAnimation boneAnimation) { // private CalculationBone[] getBonesToCalculate(Bone bone, Skeleton skeleton, Animation boneAnimation) {
List<CalculationBone> bonesList = new ArrayList<CalculationBone>(); // List<CalculationBone> bonesList = new ArrayList<CalculationBone>();
Bone currentBone = bone; // Bone currentBone = bone;
do { // do {
bonesList.add(new CalculationBone(currentBone, 1)); // bonesList.add(new CalculationBone(currentBone, 1));
// int boneIndex = skeleton.getBoneIndex(currentBone); // int boneIndex = skeleton.getBoneIndex(currentBone);
// for (int i = 0; i < boneAnimation.getTracks().length; ++i) { // for (int i = 0; i < boneAnimation.getTracks().length; ++i) {
// if (boneAnimation.getTracks()[i].getTargetBoneIndex() == boneIndex) { // if (boneAnimation.getTracks()[i].getTargetBoneIndex() == boneIndex) {
@ -153,15 +141,15 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
// break; // break;
// } // }
// } // }
currentBone = currentBone.getParent(); // currentBone = currentBone.getParent();
} while (currentBone != null); // } while (currentBone != null);
//attaching children // //attaching children
CalculationBone[] result = bonesList.toArray(new CalculationBone[bonesList.size()]); // CalculationBone[] result = bonesList.toArray(new CalculationBone[bonesList.size()]);
for (int i = result.length - 1; i > 0; --i) { // for (int i = result.length - 1; i > 0; --i) {
result[i].attachChild(result[i - 1]); // result[i].attachChild(result[i - 1]);
} // }
return result; // return result;
} // }
@Override @Override
public ConstraintType getType() { public ConstraintType getType() {

@ -1,8 +1,7 @@
package com.jme3.scene.plugins.blender.constraints; package com.jme3.scene.plugins.blender.constraints;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.BoneTrack; import com.jme3.animation.Track;
import com.jme3.animation.Skeleton;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
@ -45,12 +44,12 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); Track<?> track = this.getTrack(animation, targetIndex);
if (boneTrack != null) { if (track != null) {
Vector3f targetLocation = this.getTargetLocation(); Vector3f targetLocation = this.getTargetLocation();
int flag = ((Number) data.getFieldValue("flag")).intValue(); int flag = ((Number) data.getFieldValue("flag")).intValue();
Vector3f[] translations = boneTrack.getTranslations(); Vector3f[] translations = track.getTranslations();
int maxFrames = translations.length; int maxFrames = translations.length;
for (int frame = 0; frame < maxFrames; ++frame) { for (int frame = 0; frame < maxFrames; ++frame) {
Vector3f offset = Vector3f.ZERO; Vector3f offset = Vector3f.ZERO;
@ -76,7 +75,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
translations[frame].addLocal(offset);//TODO: ipo influence translations[frame].addLocal(offset);//TODO: ipo influence
} }
boneTrack.setKeyframes(boneTrack.getTimes(), translations, boneTrack.getRotations(), boneTrack.getScales()); track.setKeyframes(track.getTimes(), translations, track.getRotations(), track.getScales());
} }
} }

@ -1,8 +1,7 @@
package com.jme3.scene.plugins.blender.constraints; package com.jme3.scene.plugins.blender.constraints;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.BoneTrack; import com.jme3.animation.Track;
import com.jme3.animation.Skeleton;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
@ -42,11 +41,11 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); Track<?> track = this.getTrack(animation, targetIndex);
if (boneTrack != null) { if (track != null) {
int flag = ((Number) data.getFieldValue("flag")).intValue(); int flag = ((Number) data.getFieldValue("flag")).intValue();
Vector3f[] translations = boneTrack.getTranslations(); Vector3f[] translations = track.getTranslations();
int maxFrames = translations.length; int maxFrames = translations.length;
for (int frame = 0; frame < maxFrames; ++frame) { for (int frame = 0; frame < maxFrames; ++frame) {
float influence = ipo.calculateValue(frame); float influence = ipo.calculateValue(frame);
@ -87,7 +86,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
}//TODO: consider constraint space !!! }//TODO: consider constraint space !!!
} }
boneTrack.setKeyframes(boneTrack.getTimes(), translations, boneTrack.getRotations(), boneTrack.getScales()); track.setKeyframes(track.getTimes(), translations, track.getRotations(), track.getScales());
} }
} }

@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
@ -39,7 +38,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
// TODO: implement 'Lock track' constraint // TODO: implement 'Lock track' constraint
LOGGER.log(Level.WARNING, "'Lock track' constraint NOT implemented!"); LOGGER.log(Level.WARNING, "'Lock track' constraint NOT implemented!");
} }

@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
@ -38,7 +37,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
// TODO: implement 'Min max' constraint // TODO: implement 'Min max' constraint
LOGGER.log(Level.WARNING, "'Min max' constraint NOT implemented!"); LOGGER.log(Level.WARNING, "'Min max' constraint NOT implemented!");
} }

@ -1,7 +1,6 @@
package com.jme3.scene.plugins.blender.constraints; package com.jme3.scene.plugins.blender.constraints;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
@ -35,7 +34,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) {} public void affectAnimation(Animation animation, int targetIndex) {}
@Override @Override
public ConstraintType getType() { public ConstraintType getType() {

@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
@ -38,7 +37,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
// TODO: implement 'Python' constraint // TODO: implement 'Python' constraint
LOGGER.log(Level.WARNING, "'Python' constraint NOT implemented!"); LOGGER.log(Level.WARNING, "'Python' constraint NOT implemented!");
} }

@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
@ -38,7 +37,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
// TODO: implement 'Rigid body joint' constraint // TODO: implement 'Rigid body joint' constraint
LOGGER.log(Level.WARNING, "'Rigid body joint' constraint NOT implemented!"); LOGGER.log(Level.WARNING, "'Rigid body joint' constraint NOT implemented!");
} }

@ -1,8 +1,7 @@
package com.jme3.scene.plugins.blender.constraints; package com.jme3.scene.plugins.blender.constraints;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.BoneTrack; import com.jme3.animation.Track;
import com.jme3.animation.Skeleton;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
@ -43,13 +42,13 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); Track<?> track = this.getTrack(animation, targetIndex);
if (boneTrack != null) { if (track != null) {
Quaternion targetRotation = this.getTargetRotation(); Quaternion targetRotation = this.getTargetRotation();
int flag = ((Number) data.getFieldValue("flag")).intValue(); int flag = ((Number) data.getFieldValue("flag")).intValue();
float[] targetAngles = targetRotation.toAngles(null); float[] targetAngles = targetRotation.toAngles(null);
Quaternion[] rotations = boneTrack.getRotations(); Quaternion[] rotations = track.getRotations();
int maxFrames = rotations.length; int maxFrames = rotations.length;
for (int frame = 0; frame < maxFrames; ++frame) { for (int frame = 0; frame < maxFrames; ++frame) {
float[] angles = rotations[frame].toAngles(null); float[] angles = rotations[frame].toAngles(null);
@ -77,7 +76,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
rotations[frame].fromAngles(angles).multLocal(offset);//TODO: ipo influence rotations[frame].fromAngles(angles).multLocal(offset);//TODO: ipo influence
} }
boneTrack.setKeyframes(boneTrack.getTimes(), boneTrack.getTranslations(), rotations, boneTrack.getScales()); track.setKeyframes(track.getTimes(), track.getTranslations(), rotations, track.getScales());
} }
} }

@ -1,8 +1,7 @@
package com.jme3.scene.plugins.blender.constraints; package com.jme3.scene.plugins.blender.constraints;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.BoneTrack; import com.jme3.animation.Track;
import com.jme3.animation.Skeleton;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
@ -40,11 +39,11 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); Track<?> track = this.getTrack(animation, targetIndex);
if (boneTrack != null) { if (track != null) {
int flag = ((Number) data.getFieldValue("flag")).intValue(); int flag = ((Number) data.getFieldValue("flag")).intValue();
Quaternion[] rotations = boneTrack.getRotations(); Quaternion[] rotations = track.getRotations();
int maxFrames = rotations.length; int maxFrames = rotations.length;
for (int frame = 0; frame < maxFrames; ++frame) { for (int frame = 0; frame < maxFrames; ++frame) {
float[] angles = rotations[frame].toAngles(null); float[] angles = rotations[frame].toAngles(null);
@ -84,7 +83,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
rotations[frame].fromAngles(angles);//TODO: consider constraint space !!! rotations[frame].fromAngles(angles);//TODO: consider constraint space !!!
} }
boneTrack.setKeyframes(boneTrack.getTimes(), boneTrack.getTranslations(), rotations, boneTrack.getScales()); track.setKeyframes(track.getTimes(), track.getTranslations(), rotations, track.getScales());
} }
} }

@ -5,9 +5,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.BoneTrack; import com.jme3.animation.Track;
import com.jme3.animation.Skeleton;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
@ -49,7 +48,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
//loading mesh points (blender ensures that the target is a mesh-object) //loading mesh points (blender ensures that the target is a mesh-object)
List<Vector3f> pts = new ArrayList<Vector3f>(); List<Vector3f> pts = new ArrayList<Vector3f>();
try { try {
@ -65,10 +64,10 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
//modifying traces //modifying traces
BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); Track<?> track = this.getTrack(animation, targetIndex);
if (boneTrack != null) { if (track != null) {
Vector3f[] translations = boneTrack.getTranslations(); Vector3f[] translations = track.getTranslations();
Quaternion[] rotations = boneTrack.getRotations(); Quaternion[] rotations = track.getRotations();
int maxFrames = translations.length; int maxFrames = translations.length;
for (int frame = 0; frame < maxFrames; ++frame) { for (int frame = 0; frame < maxFrames; ++frame) {
Vector3f currentTranslation = translations[frame]; Vector3f currentTranslation = translations[frame];
@ -86,7 +85,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
translations[frame] = minDistancePoint.clone(); translations[frame] = minDistancePoint.clone();
} }
boneTrack.setKeyframes(boneTrack.getTimes(), translations, rotations, boneTrack.getScales()); track.setKeyframes(track.getTimes(), translations, rotations, track.getScales());
} }
} catch (BlenderFileException e) { } catch (BlenderFileException e) {
LOGGER.severe(e.getLocalizedMessage()); LOGGER.severe(e.getLocalizedMessage());

@ -1,8 +1,7 @@
package com.jme3.scene.plugins.blender.constraints; package com.jme3.scene.plugins.blender.constraints;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.BoneTrack; import com.jme3.animation.Track;
import com.jme3.animation.Skeleton;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
@ -40,12 +39,12 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
Vector3f targetScale = this.getTargetLocation(); Vector3f targetScale = this.getTargetLocation();
BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); Track<?> track = this.getTrack(animation, targetIndex);
if (boneTrack != null) { if (track != null) {
int flag = ((Number) data.getFieldValue("flag")).intValue(); int flag = ((Number) data.getFieldValue("flag")).intValue();
Vector3f[] scales = boneTrack.getScales(); Vector3f[] scales = track.getScales();
int maxFrames = scales.length; int maxFrames = scales.length;
for (int frame = 0; frame < maxFrames; ++frame) { for (int frame = 0; frame < maxFrames; ++frame) {
Vector3f offset = Vector3f.ZERO; Vector3f offset = Vector3f.ZERO;
@ -63,7 +62,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
scales[frame].addLocal(offset);//TODO: ipo influence scales[frame].addLocal(offset);//TODO: ipo influence
//TODO: add or multiply??? //TODO: add or multiply???
} }
boneTrack.setKeyframes(boneTrack.getTimes(), boneTrack.getTranslations(), boneTrack.getRotations(), scales); track.setKeyframes(track.getTimes(), track.getTranslations(), track.getRotations(), scales);
} }
} }

@ -1,8 +1,7 @@
package com.jme3.scene.plugins.blender.constraints; package com.jme3.scene.plugins.blender.constraints;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.BoneTrack; import com.jme3.animation.Track;
import com.jme3.animation.Skeleton;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
@ -42,11 +41,11 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); Track<?> track = this.getTrack(animation, targetIndex);
if (boneTrack != null) { if (track != null) {
int flag = ((Number) data.getFieldValue("flag")).intValue(); int flag = ((Number) data.getFieldValue("flag")).intValue();
Vector3f[] scales = boneTrack.getScales(); Vector3f[] scales = track.getScales();
int maxFrames = scales.length; int maxFrames = scales.length;
for (int frame = 0; frame < maxFrames; ++frame) { for (int frame = 0; frame < maxFrames; ++frame) {
float influence = ipo.calculateValue(frame); float influence = ipo.calculateValue(frame);
@ -87,7 +86,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
}//TODO: consider constraint space !!! }//TODO: consider constraint space !!!
} }
boneTrack.setKeyframes(boneTrack.getTimes(), boneTrack.getTranslations(), boneTrack.getRotations(), scales); track.setKeyframes(track.getTimes(), track.getTranslations(), track.getRotations(), scales);
} }
} }

@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
@ -39,7 +38,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
// TODO: implement 'Stretch to' constraint // TODO: implement 'Stretch to' constraint
LOGGER.log(Level.WARNING, "'Stretch to' constraint NOT implemented!"); LOGGER.log(Level.WARNING, "'Stretch to' constraint NOT implemented!");
} }

@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.Animation;
import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
@ -38,7 +37,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Animation animation, int targetIndex) {
// TODO: implement 'Transform' constraint // TODO: implement 'Transform' constraint
LOGGER.log(Level.WARNING, "'Transform' constraint NOT implemented!"); LOGGER.log(Level.WARNING, "'Transform' constraint NOT implemented!");
} }

@ -13,7 +13,6 @@ import java.util.logging.Logger;
import com.jme3.animation.AnimControl; import com.jme3.animation.AnimControl;
import com.jme3.animation.Animation; import com.jme3.animation.Animation;
import com.jme3.animation.Bone; import com.jme3.animation.Bone;
import com.jme3.animation.BoneAnimation;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.animation.SkeletonControl; import com.jme3.animation.SkeletonControl;
import com.jme3.math.Matrix4f; import com.jme3.math.Matrix4f;
@ -131,7 +130,7 @@ import com.jme3.util.BufferUtils;
int fps = blenderContext.getBlenderKey().getFps(); int fps = blenderContext.getBlenderKey().getFps();
float start = (float) animationFrames[0] / (float) fps; float start = (float) animationFrames[0] / (float) fps;
float stop = (float) animationFrames[1] / (float) fps; float stop = (float) animationFrames[1] / (float) fps;
BoneAnimation boneAnimation = new BoneAnimation(actionName, stop - start); Animation boneAnimation = new Animation(actionName, stop - start);
boneAnimation.setTracks(armatureHelper.getTracks(actionStructure, blenderContext, objectName, actionName)); boneAnimation.setTracks(armatureHelper.getTracks(actionStructure, blenderContext, objectName, actionName));
animations.add(boneAnimation); animations.add(boneAnimation);
@ -169,16 +168,19 @@ import com.jme3.util.BufferUtils;
List<Constraint> constraints = blenderContext.getConstraints(this.armatureObjectOMA); List<Constraint> constraints = blenderContext.getConstraints(this.armatureObjectOMA);
HashMap<String, Animation> anims = new HashMap<String, Animation>(); HashMap<String, Animation> anims = new HashMap<String, Animation>();
for (int i = 0; i < animList.size(); ++i) { for (int i = 0; i < animList.size(); ++i) {
BoneAnimation boneAnimation = (BoneAnimation) animList.get(i).clone(); Animation animation = (Animation) animList.get(i).clone();
// baking constraints into animations // baking constraints into animations
if (constraints != null && constraints.size() > 0) { if (constraints != null && constraints.size() > 0) {
for (Constraint constraint : constraints) { for (Constraint constraint : constraints) {
constraint.affectAnimation(animData.skeleton, boneAnimation); Long boneOMA = constraint.getBoneOMA();
Bone bone = (Bone) blenderContext.getLoadedFeature(boneOMA, LoadedFeatureDataType.LOADED_FEATURE);
int targetIndex = bone==null ? 0 : animData.skeleton.getBoneIndex(bone);//bone==null may mean the object animation
constraint.affectAnimation(animation, targetIndex);
} }
} }
anims.put(boneAnimation.getName(), boneAnimation); anims.put(animation.getName(), animation);
} }
// applying the control to the node // applying the control to the node

Loading…
Cancel
Save