Skip to content

Commit 865dc1d

Browse files
committed
~ Merge: fixed subtract bug with resulting frames array, added more logs
1 parent 84fd116 commit 865dc1d

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

source/W3MayaAnimUtil.cpp

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#define upn(val, start, end) for(int val = start; val <= end; ++val)
99
#define JRef QJsonValueRef
10-
#define VERSION "v2.0"
10+
#define VERSION "v2.1.1"
1111

1212
W3MayaAnimUtil::W3MayaAnimUtil(QWidget *parent)
1313
: QMainWindow(parent)
@@ -2633,7 +2633,7 @@ void W3MayaAnimUtil::onClicked_MergeProcess() {
26332633
rotArrF[frame - 1] = rotArrS[frame - mergeStart];
26342634
}
26352635
} else if (ui->comboMergeType->currentIndex() == 1 /* SUM */) {
2636-
// SUM
2636+
// SUM [1; framesS] doing stuff in F
26372637
for (int frame = 1; frame <= framesS; frame += 1) {
26382638
qDebug() << QString("SUM: bone %1, frame %2").arg(boneNameF).arg(frame);
26392639
/* pos */
@@ -2706,45 +2706,47 @@ void W3MayaAnimUtil::onClicked_MergeProcess() {
27062706
addLog(QString("\t[MERGE] Cropping option is disabled, leaving %1 frames.").arg(posArrF.count()));
27072707
}
27082708
} else if (ui->comboMergeType->currentIndex() == 2 /* SUBTRACT */) {
2709-
// SUBTRACT [mergeStart; mergeStart + mergeDuration - 1]
2709+
// SUBTRACT [1; framesS], doing stuff in S
27102710
for (int frame = 1; frame <= framesS; frame += 1) {
27112711
qDebug() << QString("SUBTRACT: bone %1, frame %2").arg(boneNameF).arg(frame);
27122712
/* pos */
2713-
objToXYZ(posArrS.at(frame - 1).toObject(), pX1, pY1, pZ1);
2714-
objToXYZ(posArrF.at(frame - 1).toObject(), pX2, pY2, pZ2);
2713+
objToXYZ(posArrF.at(frame - 1).toObject(), pX1, pY1, pZ1);
2714+
objToXYZ(posArrS.at(frame - 1).toObject(), pX2, pY2, pZ2);
27152715

27162716
if (ui->checkMergeSumInversePos->isChecked()) {
2717-
pX1 += pX2;
2718-
pY1 += pY2;
2719-
pZ1 += pZ2;
2717+
pX2 += pX1;
2718+
pY2 += pY1;
2719+
pZ2 += pZ1;
27202720
} else {
2721-
pX1 -= pX2;
2722-
pY1 -= pY2;
2723-
pZ1 -= pZ2;
2721+
pX2 -= pX1;
2722+
pY2 -= pY1;
2723+
pZ2 -= pZ1;
27242724
}
27252725

2726-
posArrF[frame - 1] = objXYZ(pX1, pY1, pZ1);
2726+
posArrS[frame - 1] = objXYZ(pX2, pY2, pZ2);
27272727

27282728
/* rot */
2729-
objToXYZW(rotArrS.at(frame - 1).toObject(), pX1, pY1, pZ1, pW1);
2730-
objToXYZW(rotArrF.at(frame - 1).toObject(), pX2, pY2, pZ2, pW2);
2729+
objToXYZW(rotArrF.at(frame - 1).toObject(), pX1, pY1, pZ1, pW1);
2730+
objToXYZW(rotArrS.at(frame - 1).toObject(), pX2, pY2, pZ2, pW2);
27312731

2732-
QVector3D eulerMerged = QQuaternion(pW1, pX1, pY1, pZ1).toEulerAngles();
2733-
QVector3D eulerPose = QQuaternion(pW2, pX2, pY2, pZ2).toEulerAngles();
2732+
QVector3D eulerMerged = QQuaternion(pW2, pX2, pY2, pZ2).toEulerAngles();
2733+
QVector3D eulerPose = QQuaternion(pW1, pX1, pY1, pZ1).toEulerAngles();
27342734

27352735
QQuaternion subQ;
27362736
if (ui->checkMergeSumInverseRot->isChecked())
27372737
subQ = QQuaternion::fromEulerAngles(eulerMerged + eulerPose);
27382738
else
27392739
subQ = QQuaternion::fromEulerAngles(eulerMerged - eulerPose);
27402740
subQ.normalize();
2741-
rotArrF[frame - 1] = objXYZW(subQ.x(), subQ.y(), subQ.z(), subQ.scalar());
2741+
rotArrS[frame - 1] = objXYZW(subQ.x(), subQ.y(), subQ.z(), subQ.scalar());
27422742
}
2743+
posArrF = posArrS;
2744+
rotArrF = rotArrS;
27432745
}
27442746
// else do nothing
27452747

2746-
if (framesTotal != posArrF.count()) {
2747-
qDebug() << QString("!!! Inconsistence! framesTotal = %1, posArr count = %2").arg(framesTotal).arg(posArrF.count());
2748+
if (framesTotal != posArrF.count() || framesTotal != rotArrF.count()) {
2749+
addLog(QString("!!! Inconsistence! bone = %1, framesTotal = %2, posArr = %3, rotArr = %4").arg(boneNameF).arg(framesTotal).arg(posArrF.count()).arg(rotArrF.count()), logError);
27482750
}
27492751
boneF["position_numFrames"] = framesTotal;
27502752
boneF["rotation_numFrames"] = framesTotal;
@@ -2782,7 +2784,12 @@ void W3MayaAnimUtil::onClicked_MergeProcess() {
27822784
}
27832785

27842786
if (ui->checkMergeEventsSort->isChecked()) {
2785-
editSortEvents(eventsArrayF);
2787+
if (isSubtract) {
2788+
editSortEvents(eventsArrayS);
2789+
eventsArrayF = eventsArrayS;
2790+
} else {
2791+
editSortEvents(eventsArrayF);
2792+
}
27862793
}
27872794

27882795
// save
@@ -2794,6 +2801,8 @@ void W3MayaAnimUtil::onClicked_MergeProcess() {
27942801
animObjF["duration"] = framesToSec(framesTotal - 1);
27952802
animObjF["animBuffer"] = animBuffF;
27962803

2804+
addLog(QString("\t[MERGE] Resulting anim: numFrames = %1, duration = %2 s, name = %3").arg(framesTotal).arg(framesToSec(framesTotal - 1)).arg(animObjF["name"].toString()));
2805+
27972806
/* optimize */
27982807
if (ui->checkMergeOptimize->isChecked()) {
27992808
editOptimizeBones(animObjF, true, true, true);

0 commit comments

Comments
 (0)