@@ -20,6 +20,7 @@ W3MayaAnimUtil::W3MayaAnimUtil(QWidget *parent)
2020 connect (ui->buttonSave , SIGNAL (clicked (bool )), this , SLOT (onClicked_Save ()));
2121 connect (ui->buttonApplyMotionToBone , SIGNAL (clicked (bool )), this , SLOT (onClicked_applyMotionToBone ()));
2222 connect (ui->buttonExtractMotionFromBone , SIGNAL (clicked (bool )), this , SLOT (onClicked_extractMotionFromBone ()));
23+ connect (ui->buttonExtractMotionFromBoneBatch , SIGNAL (clicked (bool )), this , SLOT (onClicked_extractMotionFromBoneBatch ()));
2324}
2425
2526void W3MayaAnimUtil::addLog (QString text, LogType type) {
@@ -35,32 +36,22 @@ void W3MayaAnimUtil::addLog(QString text, LogType type) {
3536 ui->textLog ->verticalScrollBar ()->setValue ( ui->textLog ->verticalScrollBar ()->maximum () );
3637}
3738
38- void W3MayaAnimUtil::onClicked_Load () {
39- if (hasChanges && QMessageBox::Yes != QMessageBox::question (this , " Attention!" , " Currently loaded .json has some unsaved changes. Do you want to discard them and load new file?" )) {
40- return ;
41- }
42- hasChanges = false ;
43-
44- QString filePath = QFileDialog::getOpenFileName (this , " Open animation json" , " " , " JSON Files (*.json)" );
45- if (filePath.isEmpty ()) {
46- addLog (" Loading file canceled by user" , logWarning);
47- return ;
48- }
39+ bool W3MayaAnimUtil::loadJsonFile (QString filePath) {
4940 jsonFile.setFileName (filePath);
5041 if ( !jsonFile.open (QIODevice::ReadOnly | QIODevice::Text) ) {
5142 addLog (" Can't open file in read-only text mode: " + filePath, logError);
52- return ;
43+ return false ;
5344 }
5445
5546 QByteArray bArray = jsonFile.readAll ();
5647 QJsonParseError* jsonError = new QJsonParseError;
5748 jsonDoc = QJsonDocument::fromJson (bArray, jsonError);
5849 if ( jsonDoc.isNull () ) {
5950 addLog ( QString (" Can't load json document correctly, parse error = %1" ).arg (jsonError->errorString ()), logError );
60- return ;
51+ return false ;
6152 } else if ( !jsonDoc.isObject () ) {
6253 addLog ( " Json root is not an object, can't load info." , logError );
63- return ;
54+ return false ;
6455 }
6556
6657 if ( QFile::exists (filePath + " .bak" ) ) {
@@ -73,11 +64,27 @@ void W3MayaAnimUtil::onClicked_Load() {
7364 if ( loadW3Data () ) {
7465 addLog ( QString (" [OK] Loaded %1, original file saved as: %1.bak" ).arg (QFileInfo (filePath).fileName ()) );
7566 ui->linePath ->setText (filePath);
67+ return true ;
7668 } else {
7769 addLog ( QString (" Failed to detect data format: %1" ).arg (QFileInfo (filePath).fileName ()), logError );
7870 ui->linePath ->setText (" NO CORRECT .JSON LOADED!" );
71+ return false ;
7972 }
8073}
74+
75+ void W3MayaAnimUtil::onClicked_Load () {
76+ if (hasChanges && QMessageBox::Yes != QMessageBox::question (this , " Attention!" , " Currently loaded .json has some unsaved changes. Do you want to discard them and load new file?" )) {
77+ return ;
78+ }
79+ hasChanges = false ;
80+
81+ QString filePath = QFileDialog::getOpenFileName (this , " Open animation json" , " " , " JSON Files (*.json)" );
82+ if (filePath.isEmpty ()) {
83+ addLog (" Loading file canceled by user" , logWarning);
84+ return ;
85+ }
86+ loadJsonFile (filePath);
87+ }
8188bool W3MayaAnimUtil::loadW3Data () {
8289 if ( jsonRoot.contains (" animations" ) ) {
8390 animSet = true ; // exported from wkit
@@ -485,10 +492,14 @@ bool W3MayaAnimUtil::extractMotionFromBone(QJsonValueRef ref) {
485492 }
486493 }
487494 if (mBoneIdx == -1 ) {
488- addLog (QString (" Anim doesn't contain [%2] bone, removing motionExtraction!" ).arg (mBoneName ), logError );
489- // END
490- ref = animObj;
491- return true ;
495+ if (ui->checkIgnoreEmptyRootMotion ->isChecked ()) {
496+ addLog (QString (" Anim doesn't contain [%2] bone, ignoring." ).arg (mBoneName ), logError );
497+ return false ;
498+ } else {
499+ addLog (QString (" Anim doesn't contain [%2] bone, removing motionExtraction!" ).arg (mBoneName ), logError );
500+ ref = animObj;
501+ return true ;
502+ }
492503 }
493504
494505 QJsonObject motionObj = bonesArray[mBoneIdx ].toObject ();
@@ -707,12 +718,34 @@ void W3MayaAnimUtil::onClicked_extractMotionFromBone() {
707718 } else {
708719 if ( extractMotionFromBone (jsonRoot[" animation" ]) ) {
709720 hasChanges = true ;
710-
711721 }
712722 addLog (QString (" [Finished in %1s] Processed 1 animation.<br>" ).arg (eTimer.elapsed () / 1000.0 ));
713723 ui->progressBar ->setValue (100 );
714724 }
715725}
726+ void W3MayaAnimUtil::onClicked_extractMotionFromBoneBatch () {
727+ QString dirName = QFileDialog::getExistingDirectory (this , tr (" Choose directory" ),
728+ QDir::currentPath ());
729+ if (dirName.isEmpty ()) {
730+ addLog (" User canceled operation." , logWarning);
731+ return ;
732+ }
733+ QStringList jsonList = QDir (dirName).entryList ({" *.json" }, QDir::Files, QDir::Name);
734+ for (const QString jsonPath : jsonList) {
735+ addLog (" [BATCH] Processing file: " + jsonPath);
736+ if (loadJsonFile (dirName + " /" + jsonPath)) {
737+ onClicked_extractMotionFromBone ();
738+ // YES it's dirty crutch
739+ QApplication::processEvents ();
740+ if (hasChanges) {
741+ onClicked_Save ();
742+ }
743+ }
744+ // YES it's dirty crutch
745+ QApplication::processEvents ();
746+ }
747+ addLog (QString (" [BATCH] Completed processing %1 files." ).arg (jsonList.size ()));
748+ }
716749
717750W3MayaAnimUtil::~W3MayaAnimUtil ()
718751{
0 commit comments