Bugfix: avoiding infinite loops while applying constraints.
This commit is contained in:
parent
2d9a1b8737
commit
b0e751c81a
@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Stack;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.jme3.animation.AnimChannel;
|
import com.jme3.animation.AnimChannel;
|
||||||
@ -209,7 +210,6 @@ public class SimulationNode {
|
|||||||
TempVars vars = TempVars.get();
|
TempVars vars = TempVars.get();
|
||||||
AnimChannel animChannel = animControl.createChannel();
|
AnimChannel animChannel = animControl.createChannel();
|
||||||
|
|
||||||
// List<Bone> bonesWithConstraints = this.collectBonesWithConstraints(skeleton);
|
|
||||||
for (Animation animation : animations) {
|
for (Animation animation : animations) {
|
||||||
float[] animationTimeBoundaries = this.computeAnimationTimeBoundaries(animation);
|
float[] animationTimeBoundaries = this.computeAnimationTimeBoundaries(animation);
|
||||||
int maxFrame = (int) animationTimeBoundaries[0];
|
int maxFrame = (int) animationTimeBoundaries[0];
|
||||||
@ -233,7 +233,7 @@ public class SimulationNode {
|
|||||||
for (Bone rootBone : skeleton.getRoots()) {
|
for (Bone rootBone : skeleton.getRoots()) {
|
||||||
// ignore the 0-indexed bone
|
// ignore the 0-indexed bone
|
||||||
if (skeleton.getBoneIndex(rootBone) > 0) {
|
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)
|
* the set of OMAS of the altered bones (is populated if necessary)
|
||||||
* @param frame
|
* @param frame
|
||||||
* the current frame of the animation
|
* 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);
|
BoneContext boneContext = blenderContext.getBoneContext(bone);
|
||||||
if (!applied.contains(boneContext.getBoneOma())) {
|
if (!applied.contains(boneContext.getBoneOma())) {
|
||||||
List<Constraint> constraints = this.findConstraints(boneContext.getBoneOma(), blenderContext);
|
List<Constraint> constraints = this.findConstraints(boneContext.getBoneOma(), blenderContext);
|
||||||
if (constraints != null && constraints.size() > 0) {
|
if (constraints != null && constraints.size() > 0) {
|
||||||
// TODO: BEWARE OF INFINITE LOOPS !!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
for (Constraint constraint : constraints) {
|
for (Constraint constraint : constraints) {
|
||||||
if (constraint.getTargetOMA() != null && constraint.getTargetOMA() > 0L) {
|
if (constraint.getTargetOMA() != null && constraint.getTargetOMA() > 0L) {
|
||||||
// first apply constraints of the target bone
|
// first apply constraints of the target bone
|
||||||
BoneContext targetBone = blenderContext.getBoneContext(constraint.getTargetOMA());
|
BoneContext targetBone = blenderContext.getBoneContext(constraint.getTargetOMA());
|
||||||
this.applyConstraints(targetBone.getBone(), alteredOmas, applied, frame);
|
this.applyConstraints(targetBone.getBone(), alteredOmas, applied, frame, bonesStack);
|
||||||
}
|
}
|
||||||
constraint.apply(frame);
|
constraint.apply(frame);
|
||||||
if (constraint.getAlteredOmas() != null) {
|
if (constraint.getAlteredOmas() != null) {
|
||||||
@ -320,9 +323,11 @@ public class SimulationNode {
|
|||||||
List<Bone> children = bone.getChildren();
|
List<Bone> children = bone.getChildren();
|
||||||
if (children != null && children.size() > 0) {
|
if (children != null && children.size() > 0) {
|
||||||
for (Bone child : bone.getChildren()) {
|
for (Bone child : bone.getChildren()) {
|
||||||
this.applyConstraints(child, alteredOmas, applied, frame);
|
this.applyConstraints(child, alteredOmas, applied, frame, bonesStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bonesStack.pop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user