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 b3d185ab7..1e1bf2f4b 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,9 +1,7 @@ package com.jme3.scene.plugins.blender.constraints; -import com.jme3.animation.Bone; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.BoneTrack; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; +import com.jme3.animation.Track; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.scene.Node; @@ -25,7 +23,7 @@ public abstract class Constraint { /** The name of this constraint. */ protected final String name; /** The old memory address of the constraint's owner. */ - protected final Long boneOMA; + protected Long boneOMA = -1L; protected final Space ownerSpace; protected final Space targetSpace; /** The structure with constraint's data. */ @@ -101,20 +99,19 @@ public abstract class Constraint { * the bone animation that affects the skeleton * @return the bone track for the bone that is being affected by the constraint */ - protected BoneTrack getBoneTrack(Skeleton skeleton, BoneAnimation boneAnimation) { - Bone bone = (Bone) blenderContext.getLoadedFeature(boneOMA, LoadedFeatureDataType.LOADED_FEATURE); - int boneIndex = bone==null ? 0 : skeleton.getBoneIndex(bone);//bone==null may mean the object animation - if (boneIndex != -1) { - //searching for track for this bone - for (BoneTrack boneTrack : boneAnimation.getTracks()) { - if (boneTrack.getTargetBoneIndex() == boneIndex) { - return boneTrack; - } - } - } - return null; + protected Track getTrack(Animation animation, int targetIndex) { + if(boneOMA >= 0) {//bone animation + for(Track track : animation.getTracks()) { + if(track.getTargetIndex() == targetIndex) { + return track; + } + } + } else {//spatial animation + return animation.getTracks()[0]; + } + return null; } - + /** * This method returns the target or subtarget object (if specified). * @param loadedFeatureDataType @@ -203,14 +200,12 @@ public abstract class Constraint { /** * This method affects the bone animation tracks for the given skeleton. * - * @param skeleton - * the skeleton containing the affected bones by constraint - * @param boneAnimation + * @param animation * the bone animation baked traces - * @param constraint - * the constraint + * @param targetIndex + * 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. diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintAction.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintAction.java index ad1f7163c..351b5af45 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintAction.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintAction.java @@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints; import java.util.logging.Level; import java.util.logging.Logger; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; @@ -38,7 +37,7 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { + public void affectAnimation(Animation animation, int targetIndex) { // TODO: implement 'Action' constraint LOGGER.log(Level.WARNING, "'Action' constraint NOT implemented!"); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintChildOf.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintChildOf.java index ea66a01b9..213778eb4 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintChildOf.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintChildOf.java @@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints; import java.util.logging.Level; import java.util.logging.Logger; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; @@ -38,7 +37,7 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { + public void affectAnimation(Animation animation, int targetIndex) { // TODO: implement ChildOf constraint LOGGER.log(Level.WARNING, "ChildOf constraint NOT implemented!"); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintClampTo.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintClampTo.java index 1a3723ce0..b48d4348c 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintClampTo.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintClampTo.java @@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints; import java.util.logging.Level; import java.util.logging.Logger; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; @@ -39,7 +38,7 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { + public void affectAnimation(Animation animation, int targetIndex) { //TODO: implement when curves are implemented LOGGER.log(Level.INFO, "'Clamp to' not yet implemented! Curves not yet implemented!", this.getName()); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintDistLimit.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintDistLimit.java index 9f6620b2b..820a729cb 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintDistLimit.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintDistLimit.java @@ -1,8 +1,7 @@ package com.jme3.scene.plugins.blender.constraints; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.BoneTrack; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; +import com.jme3.animation.Track; import com.jme3.math.Vector3f; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; @@ -39,9 +38,9 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { + public void affectAnimation(Animation animation, int targetIndex) { Vector3f targetLocation = this.getTargetLocation(); - BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); + Track boneTrack = this.getTrack(animation, targetIndex); if (boneTrack != null) { //TODO: target vertex group !!! float dist = ((Number) data.getFieldValue("dist")).floatValue(); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintFollowPath.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintFollowPath.java index 94d1ae4fc..63e018a2a 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintFollowPath.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintFollowPath.java @@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints; import java.util.logging.Level; import java.util.logging.Logger; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; @@ -38,7 +37,7 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { + public void affectAnimation(Animation animation, int targetIndex) { //TODO: implement when curves are implemented LOGGER.log(Level.INFO, "'Follow path' not implemented! Curves not yet implemented!"); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintInverseKinematics.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintInverseKinematics.java index 69ac7abce..c2cfc7471 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintInverseKinematics.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintInverseKinematics.java @@ -1,24 +1,12 @@ package com.jme3.scene.plugins.blender.constraints; -import java.util.ArrayList; -import java.util.List; import java.util.logging.Logger; -import com.jme3.animation.Bone; -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.animation.Animation; 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.exceptions.BlenderFileException; 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. @@ -49,28 +37,28 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { - try { + public void affectAnimation(Animation animation, int targetIndex) { +// try { // IK solver is only attached to bones - Bone ownerBone = (Bone) blenderContext.getLoadedFeature(boneOMA, LoadedFeatureDataType.LOADED_FEATURE); - - // get the target point - Object targetObject = this.getTarget(LoadedFeatureDataType.LOADED_FEATURE); - Vector3f pt = null;// Point Target - if (targetObject instanceof Bone) { - pt = ((Bone) targetObject).getModelSpacePosition(); - } else if (targetObject instanceof Node) { - pt = ((Node) targetObject).getWorldTranslation(); - } else if (targetObject instanceof Skeleton) { - Structure armatureNodeStructure = (Structure) this.getTarget(LoadedFeatureDataType.LOADED_STRUCTURE); - ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class); - Transform transform = objectHelper.getTransformation(armatureNodeStructure, blenderContext); - pt = transform.getTranslation(); - } else { - throw new IllegalStateException( - "Unknown target object type! Should be Node, Bone or Skeleton and there is: " - + targetObject.getClass().getName()); - } +// Bone ownerBone = (Bone) blenderContext.getLoadedFeature(boneOMA, LoadedFeatureDataType.LOADED_FEATURE); +// +// // get the target point +// Object targetObject = this.getTarget(LoadedFeatureDataType.LOADED_FEATURE); +// Vector3f pt = null;// Point Target +// if (targetObject instanceof Bone) { +// pt = ((Bone) targetObject).getModelSpacePosition(); +// } else if (targetObject instanceof Node) { +// pt = ((Node) targetObject).getWorldTranslation(); +// } else if (targetObject instanceof Skeleton) { +// Structure armatureNodeStructure = (Structure) this.getTarget(LoadedFeatureDataType.LOADED_STRUCTURE); +// ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class); +// Transform transform = objectHelper.getTransformation(armatureNodeStructure, blenderContext); +// pt = transform.getTranslation(); +// } else { +// throw new IllegalStateException( +// "Unknown target object type! Should be Node, Bone or Skeleton and there is: " +// + targetObject.getClass().getName()); +// } //fetching the owner's bone track // BoneTrack ownerBoneTrack = null; @@ -82,43 +70,43 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper; // } // } // int ownerBoneFramesCount = ownerBoneTrack==null ? 0 : ownerBoneTrack.getTimes().length; - - // preparing data - int maxIterations = ((Number) data.getFieldValue("iterations")).intValue(); - CalculationBone[] bones = this.getBonesToCalculate(ownerBone, skeleton, boneAnimation); +// +// // preparing data +// int maxIterations = ((Number) data.getFieldValue("iterations")).intValue(); +// CalculationBone[] bones = this.getBonesToCalculate(ownerBone, skeleton, boneAnimation); // 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.getRotations())); // System.out.println("==============================="); // } - Quaternion rotation = new Quaternion(); - //all tracks should have the same amount of frames - int framesCount = bones[0].getBoneFramesCount(); - assert framesCount >=1; - for (int frame = 0; frame < framesCount; ++frame) { - float error = IK_SOLVER_ERROR; - int iteration = 0; - while (error >= IK_SOLVER_ERROR && iteration <= maxIterations) { - // rotating the bones - for (int i = 0; i < bones.length - 1; ++i) { - Vector3f pe = bones[i].getEndPoint(); - Vector3f pc = bones[i + 1].getWorldTranslation().clone(); - - Vector3f peSUBpc = pe.subtract(pc).normalizeLocal(); - Vector3f ptSUBpc = pt.subtract(pc).normalizeLocal(); - - float theta = FastMath.acos(peSUBpc.dot(ptSUBpc)); - Vector3f direction = peSUBpc.cross(ptSUBpc).normalizeLocal(); - bones[i].rotate(rotation.fromAngleAxis(theta, direction), frame); - } - error = pt.subtract(bones[0].getEndPoint()).length(); - ++iteration; - } - } - - for (CalculationBone bone : bones) { - bone.applyCalculatedTracks(); - } +// Quaternion rotation = new Quaternion(); +// //all tracks should have the same amount of frames +// int framesCount = bones[0].getBoneFramesCount(); +// assert framesCount >=1; +// for (int frame = 0; frame < framesCount; ++frame) { +// float error = IK_SOLVER_ERROR; +// int iteration = 0; +// while (error >= IK_SOLVER_ERROR && iteration <= maxIterations) { +// // rotating the bones +// for (int i = 0; i < bones.length - 1; ++i) { +// Vector3f pe = bones[i].getEndPoint(); +// Vector3f pc = bones[i + 1].getWorldTranslation().clone(); +// +// Vector3f peSUBpc = pe.subtract(pc).normalizeLocal(); +// Vector3f ptSUBpc = pt.subtract(pc).normalizeLocal(); +// +// float theta = FastMath.acos(peSUBpc.dot(ptSUBpc)); +// Vector3f direction = peSUBpc.cross(ptSUBpc).normalizeLocal(); +// bones[i].rotate(rotation.fromAngleAxis(theta, direction), frame); +// } +// error = pt.subtract(bones[0].getEndPoint()).length(); +// ++iteration; +// } +// } +// +// for (CalculationBone bone : bones) { +// bone.applyCalculatedTracks(); +// } // System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"); // 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("==============================="); // } - } catch(BlenderFileException e) { - LOGGER.severe(e.getLocalizedMessage()); - } +// } catch(BlenderFileException e) { +// LOGGER.severe(e.getLocalizedMessage()); +// } } - /** - * This method returns bones used for rotation calculations. - * @param bone - * the bone to which the constraint is applied - * @param skeleton - * the skeleton owning the bone and its ancestors - * @param boneAnimation - * 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 - */ - private CalculationBone[] getBonesToCalculate(Bone bone, Skeleton skeleton, BoneAnimation boneAnimation) { - List bonesList = new ArrayList(); - Bone currentBone = bone; - do { - bonesList.add(new CalculationBone(currentBone, 1)); +// /** +// * This method returns bones used for rotation calculations. +// * @param bone +// * the bone to which the constraint is applied +// * @param skeleton +// * the skeleton owning the bone and its ancestors +// * @param boneAnimation +// * 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 +// */ +// private CalculationBone[] getBonesToCalculate(Bone bone, Skeleton skeleton, Animation boneAnimation) { +// List bonesList = new ArrayList(); +// Bone currentBone = bone; +// do { +// bonesList.add(new CalculationBone(currentBone, 1)); // int boneIndex = skeleton.getBoneIndex(currentBone); // for (int i = 0; i < boneAnimation.getTracks().length; ++i) { // if (boneAnimation.getTracks()[i].getTargetBoneIndex() == boneIndex) { @@ -153,15 +141,15 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper; // break; // } // } - currentBone = currentBone.getParent(); - } while (currentBone != null); - //attaching children - CalculationBone[] result = bonesList.toArray(new CalculationBone[bonesList.size()]); - for (int i = result.length - 1; i > 0; --i) { - result[i].attachChild(result[i - 1]); - } - return result; - } +// currentBone = currentBone.getParent(); +// } while (currentBone != null); +// //attaching children +// CalculationBone[] result = bonesList.toArray(new CalculationBone[bonesList.size()]); +// for (int i = result.length - 1; i > 0; --i) { +// result[i].attachChild(result[i - 1]); +// } +// return result; +// } @Override public ConstraintType getType() { diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLocLike.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLocLike.java index a956bb7a0..380299c12 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLocLike.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLocLike.java @@ -1,8 +1,7 @@ package com.jme3.scene.plugins.blender.constraints; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.BoneTrack; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; +import com.jme3.animation.Track; import com.jme3.math.Vector3f; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; @@ -45,12 +44,12 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { - BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); - if (boneTrack != null) { + public void affectAnimation(Animation animation, int targetIndex) { + Track track = this.getTrack(animation, targetIndex); + if (track != null) { Vector3f targetLocation = this.getTargetLocation(); int flag = ((Number) data.getFieldValue("flag")).intValue(); - Vector3f[] translations = boneTrack.getTranslations(); + Vector3f[] translations = track.getTranslations(); int maxFrames = translations.length; for (int frame = 0; frame < maxFrames; ++frame) { Vector3f offset = Vector3f.ZERO; @@ -76,7 +75,7 @@ import com.jme3.scene.plugins.blender.file.Structure; } 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()); } } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLocLimit.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLocLimit.java index 45a1bd665..4bb9a9a49 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLocLimit.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLocLimit.java @@ -1,8 +1,7 @@ package com.jme3.scene.plugins.blender.constraints; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.BoneTrack; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; +import com.jme3.animation.Track; import com.jme3.math.Vector3f; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; @@ -42,11 +41,11 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { - BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); - if (boneTrack != null) { + public void affectAnimation(Animation animation, int targetIndex) { + Track track = this.getTrack(animation, targetIndex); + if (track != null) { int flag = ((Number) data.getFieldValue("flag")).intValue(); - Vector3f[] translations = boneTrack.getTranslations(); + Vector3f[] translations = track.getTranslations(); int maxFrames = translations.length; for (int frame = 0; frame < maxFrames; ++frame) { float influence = ipo.calculateValue(frame); @@ -87,7 +86,7 @@ import com.jme3.scene.plugins.blender.file.Structure; } }//TODO: consider constraint space !!! } - boneTrack.setKeyframes(boneTrack.getTimes(), translations, boneTrack.getRotations(), boneTrack.getScales()); + track.setKeyframes(track.getTimes(), translations, track.getRotations(), track.getScales()); } } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLockTrack.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLockTrack.java index 3bc91c2a5..07422adc4 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLockTrack.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLockTrack.java @@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints; import java.util.logging.Level; import java.util.logging.Logger; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; @@ -39,7 +38,7 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { + public void affectAnimation(Animation animation, int targetIndex) { // TODO: implement 'Lock track' constraint LOGGER.log(Level.WARNING, "'Lock track' constraint NOT implemented!"); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintMinMax.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintMinMax.java index 6013366cf..95eb11e4d 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintMinMax.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintMinMax.java @@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints; import java.util.logging.Level; import java.util.logging.Logger; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; @@ -38,7 +37,7 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { + public void affectAnimation(Animation animation, int targetIndex) { // TODO: implement 'Min max' constraint LOGGER.log(Level.WARNING, "'Min max' constraint NOT implemented!"); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintNull.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintNull.java index 275b0d03d..62459cd87 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintNull.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintNull.java @@ -1,7 +1,6 @@ package com.jme3.scene.plugins.blender.constraints; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; @@ -35,7 +34,7 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) {} + public void affectAnimation(Animation animation, int targetIndex) {} @Override public ConstraintType getType() { diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintPython.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintPython.java index 5d3861867..89e664376 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintPython.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintPython.java @@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints; import java.util.logging.Level; import java.util.logging.Logger; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; @@ -38,7 +37,7 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { + public void affectAnimation(Animation animation, int targetIndex) { // TODO: implement 'Python' constraint LOGGER.log(Level.WARNING, "'Python' constraint NOT implemented!"); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRigidBodyJoint.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRigidBodyJoint.java index fdd329c41..a8949a199 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRigidBodyJoint.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRigidBodyJoint.java @@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints; import java.util.logging.Level; import java.util.logging.Logger; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; @@ -38,7 +37,7 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { + public void affectAnimation(Animation animation, int targetIndex) { // TODO: implement 'Rigid body joint' constraint LOGGER.log(Level.WARNING, "'Rigid body joint' constraint NOT implemented!"); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRotLike.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRotLike.java index b91f1fe67..30b4dc0a9 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRotLike.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRotLike.java @@ -1,8 +1,7 @@ package com.jme3.scene.plugins.blender.constraints; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.BoneTrack; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; +import com.jme3.animation.Track; import com.jme3.math.Quaternion; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; @@ -43,13 +42,13 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { - BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); - if (boneTrack != null) { + public void affectAnimation(Animation animation, int targetIndex) { + Track track = this.getTrack(animation, targetIndex); + if (track != null) { Quaternion targetRotation = this.getTargetRotation(); int flag = ((Number) data.getFieldValue("flag")).intValue(); float[] targetAngles = targetRotation.toAngles(null); - Quaternion[] rotations = boneTrack.getRotations(); + Quaternion[] rotations = track.getRotations(); int maxFrames = rotations.length; for (int frame = 0; frame < maxFrames; ++frame) { 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 } - boneTrack.setKeyframes(boneTrack.getTimes(), boneTrack.getTranslations(), rotations, boneTrack.getScales()); + track.setKeyframes(track.getTimes(), track.getTranslations(), rotations, track.getScales()); } } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRotLimit.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRotLimit.java index b1f102a4a..d251d2e64 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRotLimit.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRotLimit.java @@ -1,8 +1,7 @@ package com.jme3.scene.plugins.blender.constraints; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.BoneTrack; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; +import com.jme3.animation.Track; import com.jme3.math.FastMath; import com.jme3.math.Quaternion; import com.jme3.scene.plugins.blender.BlenderContext; @@ -40,11 +39,11 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { - BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); - if (boneTrack != null) { + public void affectAnimation(Animation animation, int targetIndex) { + Track track = this.getTrack(animation, targetIndex); + if (track != null) { int flag = ((Number) data.getFieldValue("flag")).intValue(); - Quaternion[] rotations = boneTrack.getRotations(); + Quaternion[] rotations = track.getRotations(); int maxFrames = rotations.length; for (int frame = 0; frame < maxFrames; ++frame) { 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 !!! } - boneTrack.setKeyframes(boneTrack.getTimes(), boneTrack.getTranslations(), rotations, boneTrack.getScales()); + track.setKeyframes(track.getTimes(), track.getTranslations(), rotations, track.getScales()); } } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintShrinkWrap.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintShrinkWrap.java index 551b32e8d..1e245e32d 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintShrinkWrap.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintShrinkWrap.java @@ -5,9 +5,8 @@ import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.BoneTrack; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; +import com.jme3.animation.Track; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; @@ -49,7 +48,7 @@ import com.jme3.scene.plugins.blender.file.Structure; } @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) List pts = new ArrayList(); try { @@ -65,10 +64,10 @@ import com.jme3.scene.plugins.blender.file.Structure; } //modifying traces - BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); - if (boneTrack != null) { - Vector3f[] translations = boneTrack.getTranslations(); - Quaternion[] rotations = boneTrack.getRotations(); + Track track = this.getTrack(animation, targetIndex); + if (track != null) { + Vector3f[] translations = track.getTranslations(); + Quaternion[] rotations = track.getRotations(); int maxFrames = translations.length; for (int frame = 0; frame < maxFrames; ++frame) { Vector3f currentTranslation = translations[frame]; @@ -86,7 +85,7 @@ import com.jme3.scene.plugins.blender.file.Structure; translations[frame] = minDistancePoint.clone(); } - boneTrack.setKeyframes(boneTrack.getTimes(), translations, rotations, boneTrack.getScales()); + track.setKeyframes(track.getTimes(), translations, rotations, track.getScales()); } } catch (BlenderFileException e) { LOGGER.severe(e.getLocalizedMessage()); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintSizeLike.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintSizeLike.java index 32d1952e5..35cc71b05 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintSizeLike.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintSizeLike.java @@ -1,8 +1,7 @@ package com.jme3.scene.plugins.blender.constraints; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.BoneTrack; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; +import com.jme3.animation.Track; import com.jme3.math.Vector3f; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; @@ -40,12 +39,12 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { + public void affectAnimation(Animation animation, int targetIndex) { Vector3f targetScale = this.getTargetLocation(); - BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); - if (boneTrack != null) { + Track track = this.getTrack(animation, targetIndex); + if (track != null) { int flag = ((Number) data.getFieldValue("flag")).intValue(); - Vector3f[] scales = boneTrack.getScales(); + Vector3f[] scales = track.getScales(); int maxFrames = scales.length; for (int frame = 0; frame < maxFrames; ++frame) { Vector3f offset = Vector3f.ZERO; @@ -63,7 +62,7 @@ import com.jme3.scene.plugins.blender.file.Structure; scales[frame].addLocal(offset);//TODO: ipo influence //TODO: add or multiply??? } - boneTrack.setKeyframes(boneTrack.getTimes(), boneTrack.getTranslations(), boneTrack.getRotations(), scales); + track.setKeyframes(track.getTimes(), track.getTranslations(), track.getRotations(), scales); } } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintSizeLimit.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintSizeLimit.java index ed6e9631d..8ebb9d401 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintSizeLimit.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintSizeLimit.java @@ -1,8 +1,7 @@ package com.jme3.scene.plugins.blender.constraints; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.BoneTrack; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; +import com.jme3.animation.Track; import com.jme3.math.Vector3f; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; @@ -42,11 +41,11 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { - BoneTrack boneTrack = this.getBoneTrack(skeleton, boneAnimation); - if (boneTrack != null) { + public void affectAnimation(Animation animation, int targetIndex) { + Track track = this.getTrack(animation, targetIndex); + if (track != null) { int flag = ((Number) data.getFieldValue("flag")).intValue(); - Vector3f[] scales = boneTrack.getScales(); + Vector3f[] scales = track.getScales(); int maxFrames = scales.length; for (int frame = 0; frame < maxFrames; ++frame) { float influence = ipo.calculateValue(frame); @@ -87,7 +86,7 @@ import com.jme3.scene.plugins.blender.file.Structure; } }//TODO: consider constraint space !!! } - boneTrack.setKeyframes(boneTrack.getTimes(), boneTrack.getTranslations(), boneTrack.getRotations(), scales); + track.setKeyframes(track.getTimes(), track.getTranslations(), track.getRotations(), scales); } } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintStretchTo.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintStretchTo.java index 7d8d738d2..2349637f7 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintStretchTo.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintStretchTo.java @@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints; import java.util.logging.Level; import java.util.logging.Logger; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; @@ -39,7 +38,7 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { + public void affectAnimation(Animation animation, int targetIndex) { // TODO: implement 'Stretch to' constraint LOGGER.log(Level.WARNING, "'Stretch to' constraint NOT implemented!"); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintTransform.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintTransform.java index 9c8b18f0d..da001fb04 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintTransform.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintTransform.java @@ -3,8 +3,7 @@ package com.jme3.scene.plugins.blender.constraints; import java.util.logging.Level; import java.util.logging.Logger; -import com.jme3.animation.BoneAnimation; -import com.jme3.animation.Skeleton; +import com.jme3.animation.Animation; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; @@ -38,7 +37,7 @@ import com.jme3.scene.plugins.blender.file.Structure; } @Override - public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { + public void affectAnimation(Animation animation, int targetIndex) { // TODO: implement 'Transform' constraint LOGGER.log(Level.WARNING, "'Transform' constraint NOT implemented!"); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java index e8a3b58a0..241e9b62c 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java @@ -13,7 +13,6 @@ import java.util.logging.Logger; import com.jme3.animation.AnimControl; import com.jme3.animation.Animation; import com.jme3.animation.Bone; -import com.jme3.animation.BoneAnimation; import com.jme3.animation.Skeleton; import com.jme3.animation.SkeletonControl; import com.jme3.math.Matrix4f; @@ -131,7 +130,7 @@ import com.jme3.util.BufferUtils; int fps = blenderContext.getBlenderKey().getFps(); float start = (float) animationFrames[0] / (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)); animations.add(boneAnimation); @@ -169,16 +168,19 @@ import com.jme3.util.BufferUtils; List constraints = blenderContext.getConstraints(this.armatureObjectOMA); HashMap anims = new HashMap(); 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 if (constraints != null && constraints.size() > 0) { 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