|
|
|
@ -7,6 +7,7 @@ import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Map.Entry; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.Stack; |
|
|
|
|
import java.util.logging.Logger; |
|
|
|
|
|
|
|
|
|
import com.jme3.animation.AnimChannel; |
|
|
|
@ -209,7 +210,6 @@ public class SimulationNode { |
|
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
|
AnimChannel animChannel = animControl.createChannel(); |
|
|
|
|
|
|
|
|
|
// List<Bone> bonesWithConstraints = this.collectBonesWithConstraints(skeleton);
|
|
|
|
|
for (Animation animation : animations) { |
|
|
|
|
float[] animationTimeBoundaries = this.computeAnimationTimeBoundaries(animation); |
|
|
|
|
int maxFrame = (int) animationTimeBoundaries[0]; |
|
|
|
@ -233,7 +233,7 @@ public class SimulationNode { |
|
|
|
|
for (Bone rootBone : skeleton.getRoots()) { |
|
|
|
|
// ignore the 0-indexed bone
|
|
|
|
|
if (skeleton.getBoneIndex(rootBone) > 0) { |
|
|
|
|
this.applyConstraints(rootBone, alteredOmas, applied, frame); |
|
|
|
|
this.applyConstraints(rootBone, alteredOmas, applied, frame, new Stack<Bone>()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -294,18 +294,21 @@ public class SimulationNode { |
|
|
|
|
* the set of OMAS of the altered bones (is populated if necessary) |
|
|
|
|
* @param frame |
|
|
|
|
* the current frame of the animation |
|
|
|
|
* @param bonesStack |
|
|
|
|
* the stack of bones used to avoid infinite loops while applying constraints |
|
|
|
|
*/ |
|
|
|
|
private void applyConstraints(Bone bone, Set<Long> alteredOmas, Set<Long> applied, int frame) { |
|
|
|
|
private void applyConstraints(Bone bone, Set<Long> alteredOmas, Set<Long> applied, int frame, Stack<Bone> bonesStack) { |
|
|
|
|
if (!bonesStack.contains(bone)) { |
|
|
|
|
bonesStack.push(bone); |
|
|
|
|
BoneContext boneContext = blenderContext.getBoneContext(bone); |
|
|
|
|
if (!applied.contains(boneContext.getBoneOma())) { |
|
|
|
|
List<Constraint> constraints = this.findConstraints(boneContext.getBoneOma(), blenderContext); |
|
|
|
|
if (constraints != null && constraints.size() > 0) { |
|
|
|
|
// TODO: BEWARE OF INFINITE LOOPS !!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
for (Constraint constraint : constraints) { |
|
|
|
|
if (constraint.getTargetOMA() != null && constraint.getTargetOMA() > 0L) { |
|
|
|
|
// first apply constraints of the target bone
|
|
|
|
|
BoneContext targetBone = blenderContext.getBoneContext(constraint.getTargetOMA()); |
|
|
|
|
this.applyConstraints(targetBone.getBone(), alteredOmas, applied, frame); |
|
|
|
|
this.applyConstraints(targetBone.getBone(), alteredOmas, applied, frame, bonesStack); |
|
|
|
|
} |
|
|
|
|
constraint.apply(frame); |
|
|
|
|
if (constraint.getAlteredOmas() != null) { |
|
|
|
@ -320,9 +323,11 @@ public class SimulationNode { |
|
|
|
|
List<Bone> children = bone.getChildren(); |
|
|
|
|
if (children != null && children.size() > 0) { |
|
|
|
|
for (Bone child : bone.getChildren()) { |
|
|
|
|
this.applyConstraints(child, alteredOmas, applied, frame); |
|
|
|
|
this.applyConstraints(child, alteredOmas, applied, frame, bonesStack); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
bonesStack.pop(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|