Bugfix: fixed a bug in skeleton animation constraints applying
procedure.
This commit is contained in:
parent
676ea17465
commit
5842613c2b
@ -258,7 +258,6 @@ public class SimulationNode {
|
|||||||
float maxTime = animationTimeBoundaries[1];
|
float maxTime = animationTimeBoundaries[1];
|
||||||
|
|
||||||
Map<Integer, VirtualTrack> tracks = new HashMap<Integer, VirtualTrack>();
|
Map<Integer, VirtualTrack> tracks = new HashMap<Integer, VirtualTrack>();
|
||||||
Map<Integer, Transform> previousTransforms = this.getInitialTransforms();
|
|
||||||
for (int frame = 0; frame < maxFrame; ++frame) {
|
for (int frame = 0; frame < maxFrame; ++frame) {
|
||||||
// this MUST be done here, otherwise setting next frame of animation will
|
// this MUST be done here, otherwise setting next frame of animation will
|
||||||
// lead to possible errors
|
// lead to possible errors
|
||||||
@ -291,26 +290,15 @@ public class SimulationNode {
|
|||||||
|
|
||||||
// ... and fill in another frame in the result track
|
// ... and fill in another frame in the result track
|
||||||
for (Entry<Integer, VirtualTrack> trackEntry : tracks.entrySet()) {
|
for (Entry<Integer, VirtualTrack> trackEntry : tracks.entrySet()) {
|
||||||
Integer boneIndex = trackEntry.getKey();
|
Bone bone = skeleton.getBone(trackEntry.getKey());
|
||||||
Bone bone = skeleton.getBone(boneIndex);
|
Transform startTransform = boneStartTransforms.get(bone);
|
||||||
|
|
||||||
// take the initial transform of a bone and its virtual track
|
// track contains differences between the frame position and bind positions of bones/spatials
|
||||||
Transform previousTransform = previousTransforms.get(boneIndex);
|
Vector3f bonePositionDifference = bone.getLocalPosition().subtract(startTransform.getTranslation());
|
||||||
VirtualTrack vTrack = trackEntry.getValue();
|
Quaternion boneRotationDifference = bone.getLocalRotation().mult(startTransform.getRotation().inverse()).normalizeLocal();
|
||||||
|
Vector3f boneScaleDifference = bone.getLocalScale().divide(startTransform.getScale());
|
||||||
|
|
||||||
Vector3f bonePositionDifference = bone.getLocalPosition().subtract(previousTransform.getTranslation());
|
trackEntry.getValue().setTransform(frame, new Transform(bonePositionDifference, boneRotationDifference, boneScaleDifference));
|
||||||
Quaternion boneRotationDifference = bone.getLocalRotation().mult(previousTransform.getRotation().inverse()).normalizeLocal();
|
|
||||||
Vector3f boneScaleDifference = bone.getLocalScale().divide(previousTransform.getScale());
|
|
||||||
if (frame > 0) {
|
|
||||||
bonePositionDifference = vTrack.translations.get(frame - 1).add(bonePositionDifference);
|
|
||||||
boneRotationDifference = vTrack.rotations.get(frame - 1).mult(boneRotationDifference);
|
|
||||||
boneScaleDifference = vTrack.scales.get(frame - 1).mult(boneScaleDifference);
|
|
||||||
}
|
|
||||||
vTrack.setTransform(frame, new Transform(bonePositionDifference, boneRotationDifference, boneScaleDifference));
|
|
||||||
|
|
||||||
previousTransform.setTranslation(bone.getLocalPosition());
|
|
||||||
previousTransform.setRotation(bone.getLocalRotation());
|
|
||||||
previousTransform.setScale(bone.getLocalScale());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,19 +415,6 @@ public class SimulationNode {
|
|||||||
return result.size() > 0 ? result : null;
|
return result.size() > 0 ? result : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the initial transforms for all bones in the skelketon.
|
|
||||||
* @return the map where the key is the bone index and the value us the bone's initial transformation
|
|
||||||
*/
|
|
||||||
private Map<Integer, Transform> getInitialTransforms() {
|
|
||||||
Map<Integer, Transform> result = new HashMap<Integer, Transform>();
|
|
||||||
for (int i = 0; i < skeleton.getBoneCount(); ++i) {
|
|
||||||
Bone bone = skeleton.getBone(i);
|
|
||||||
result.put(i, new Transform(bone.getLocalPosition(), bone.getLocalRotation(), bone.getLocalScale()));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user