Skip to content

Commit

Permalink
SelectedTrack: adapt translateForSupport() to new animation system
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Nov 19, 2023
1 parent ad0ec1c commit e24f526
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/main/java/maud/model/cgm/SelectedTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ public void insertKeyframe() {
*/
public boolean isBoneTrack() {
boolean result = selected instanceof BoneTrack;
if (!result && (selected instanceof TransformTrack)) {
TransformTrack transformTrack = (TransformTrack) selected;
HasLocalTransform target = transformTrack.getTarget();
result = target instanceof Joint;
}
return result;
}

Expand Down Expand Up @@ -960,7 +965,8 @@ public int targetBoneIndex() {
* Y-coordinate as it is for bind pose.
*/
public void translateForSupport() {
assert selected instanceof BoneTrack;
assert selected instanceof BoneTrack
|| selected instanceof TransformTrack;

SelectedSkeleton selectedSkeleton = cgm.getSkeleton();
Object skeleton = selectedSkeleton.find();
Expand Down Expand Up @@ -1260,9 +1266,6 @@ private List<String> listDescriptions() {
* @return true if successful, otherwise false
*/
private boolean translateForSupport(float cgmY) {
BoneTrack boneTrack = (BoneTrack) selected;
int boneIndex = boneTrack.getTargetBoneIndex();

SelectedSkeleton selectedSkeleton = cgm.getSkeleton();
Object skeleton = selectedSkeleton.find();
assert skeleton != null;
Expand All @@ -1282,9 +1285,11 @@ private boolean translateForSupport(float cgmY) {
Matrix3f sensMat = new Matrix3f();

// Calculate a new bone translation for each keyframe.
float[] times = boneTrack.getKeyFrameTimes();
Vector3f[] translations = boneTrack.getTranslations();
float[] times = MaudUtil.getTrackTimes(selected);
Vector3f[] translations = MaudUtil.getTrackTranslations(selected);
TweenTransforms techniques = Maud.getModel().getTweenTransforms();
int boneIndex = targetBoneIndex();

int numKeyframes = times.length;
for (int frameIndex = 0; frameIndex < numKeyframes; frameIndex++) {
float trackTime = times[frameIndex];
Expand Down Expand Up @@ -1325,11 +1330,11 @@ private boolean translateForSupport(float cgmY) {
Object[] oldTracks = cgm.getAnimation().getTracks();
for (Object oldTrack : oldTracks) {
Object newTrack;
if (oldTrack == boneTrack) {
Quaternion[] rotations = boneTrack.getRotations();
Vector3f[] scales = boneTrack.getScales();
newTrack = MyAnimation.newBoneTrack(
boneIndex, times, translations, rotations, scales);
if (oldTrack == selected) {
Quaternion[] rotations = MaudUtil.getTrackRotations(selected);
Vector3f[] scales = MaudUtil.getTrackScales(selected);
newTrack = MaudUtil.newTrack(
oldTrack, times, translations, rotations, scales);
newSelected = newTrack;
} else {
newTrack = TrackEdit.cloneTrack(oldTrack);
Expand Down

0 comments on commit e24f526

Please sign in to comment.