diff --git a/src/animations.cpp b/src/animations.cpp index 03a8566..8498e2d 100644 --- a/src/animations.cpp +++ b/src/animations.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -134,7 +135,6 @@ void _Animations::applyAnimationsToMappedObjects() // this functions will be called later Recorder::get()->recordFace(timestamp, [object, weight, weightPlug](int frame) { - MFnBlendShapeDeformer faceFn(object); Recorder::get()->keyframeNumericAttribute(frame, weightPlug, weight); }); } @@ -209,6 +209,22 @@ void _Animations::applyAnimationsToMappedObjects() boneQuat *= referenceQuat; boneQuat.normalizeIt(); fnTr.setRotation(boneQuat, MSpace::kWorld); + + if(recordingEnabled) { + MVector recordLocation = fnTr.getTranslation(MSpace::kTransform); + MQuaternion recordRotation; + fnTr.getRotation(recordRotation); + Recorder::get()->recordBone(timestamp, [recordLocation, jointPath, recordRotation](int frame) { + Recorder::get()->keyframeNumericAttribute("tx", frame, jointPath, recordLocation.x); + Recorder::get()->keyframeNumericAttribute("ty", frame, jointPath, recordLocation.y); + Recorder::get()->keyframeNumericAttribute("tz", frame, jointPath, recordLocation.z); + + MEulerRotation euAngle = recordRotation.asEulerRotation(); + Recorder::get()->keyframeNumericAttribute("rx", frame, jointPath, euAngle.x); + Recorder::get()->keyframeNumericAttribute("ry", frame, jointPath, euAngle.y); + Recorder::get()->keyframeNumericAttribute("rz", frame, jointPath, euAngle.z); + }); + } } jIt.next(); @@ -274,8 +290,16 @@ void _Animations::animatePropOrTracker(QJsonObject obj, const MDagPath &dagPath) fn.set(finalTransform); if(recordingEnabled) { - // if timestamp value not in storage - record - Recorder::get()->recordPropOrTracker(timestamp, dagPath, mayaPosition, mayaRotation); + Recorder::get()->recordPropOrTracker(timestamp, [mayaPosition, mayaRotation, dagPath](int frame){ + Recorder::get()->keyframeNumericAttribute("tx", frame, dagPath, mayaPosition.x); + Recorder::get()->keyframeNumericAttribute("ty", frame, dagPath, mayaPosition.y); + Recorder::get()->keyframeNumericAttribute("tz", frame, dagPath, mayaPosition.z); + + MEulerRotation euAngle = mayaRotation.asEulerRotation(); + Recorder::get()->keyframeNumericAttribute("rx", frame, dagPath, euAngle.x); + Recorder::get()->keyframeNumericAttribute("ry", frame, dagPath, euAngle.y); + Recorder::get()->keyframeNumericAttribute("rz", frame, dagPath, euAngle.z); + }); } } diff --git a/src/recorder.cpp b/src/recorder.cpp index 86099ae..3d72572 100644 --- a/src/recorder.cpp +++ b/src/recorder.cpp @@ -25,27 +25,19 @@ _Recorder::_Recorder() } -void _Recorder::recordPropOrTracker(float timestamp, MDagPath path, MVector location, MQuaternion rotation) +void _Recorder::recordPropOrTracker(float timestamp, std::function foo) { - // create frame object if not exists - if(!recordedData.contains(timestamp)) { - recordedData[timestamp] = FrameData(); - } - - // put transform for objects - recordedData[timestamp].objects.insert(path.fullPathName().asChar(), { location, rotation }); - + recordedData[timestamp].append(foo); } void _Recorder::recordFace(float timestamp, std::function foo) { - // create frame object if not exists - if(!recordedData.contains(timestamp)) { - recordedData[timestamp] = FrameData(); - } + recordedData[timestamp].append(foo); +} - // put weight data for each blend shape node - recordedData[timestamp].setFaceKeyframDelegates.append(foo); +void _Recorder::recordBone(float timestamp, std::function foo) +{ + recordedData[timestamp].append(foo); } void _Recorder::finalizeRecording() @@ -60,64 +52,14 @@ void _Recorder::finalizeRecording() index++; int frame = index; - FrameData fData = recordedData[ts]; - - // bake props or trackers - if(fData.objects.count() > 0) - { - for(QString path : fData.objects.keys()) - { - MSelectionList ls; - ls.add(path.toStdString().c_str(), false); - MDagPath dagPath; - ls.getDagPath(0, dagPath); - - auto kfData = fData.objects[path]; - keyframeNumericAttribute("tx", frame, dagPath, kfData.first.x); - keyframeNumericAttribute("ty", frame, dagPath, kfData.first.y); - keyframeNumericAttribute("tz", frame, dagPath, kfData.first.z); - - MEulerRotation euRot = kfData.second.asEulerRotation(); - keyframeNumericAttribute("rx", frame, dagPath, euRot.x); - keyframeNumericAttribute("ry", frame, dagPath, euRot.y); - keyframeNumericAttribute("rz", frame, dagPath, euRot.z); - } - } - - // bake faces - for(auto foo : fData.setFaceKeyframDelegates) { - foo(frame); - } - } + auto delegates = recordedData[ts]; - recordedData.clear(); -} + // bake + for (auto foo : delegates) foo(frame); -int _Recorder::getFrame(const QList ×tamps, int frameNumber) -{ - return int(round((timestamps[frameNumber] - timestamps[0]) * RECEIVER_FPS)); -} - -int _Recorder::getCorrectedFrameNumber(const QList ×tamps, int frameIndex) -{ - int currFrame = getFrame(timestamps, frameIndex); - if (0 < frameIndex < timestamps.count() - 1) - { - int prev_frame = getFrame(timestamps, frameIndex - 1); - int next_frame = getFrame(timestamps, frameIndex + 1); - if (prev_frame == currFrame && next_frame == currFrame + 2) - currFrame += 1; - if (next_frame == currFrame && prev_frame == currFrame - 2) - currFrame -= 1; } - if (frameIndex == timestamps.count() - 1) - { - int prev_frame = getFrame(timestamps, frameIndex - 1); - if (prev_frame == currFrame) - currFrame += 1; - } - return currFrame; + recordedData.clear(); } void _Recorder::recordingToggled(bool enabled) diff --git a/src/recorder.h b/src/recorder.h index 5ba2cdc..b87ba36 100644 --- a/src/recorder.h +++ b/src/recorder.h @@ -16,36 +16,17 @@ #include - -class FrameData { - -public: - // objects - // object name - TR - QHash> objects; - - //faces - QList> setFaceKeyframDelegates; - - // characters - //... -}; - - class _Recorder { public: _Recorder(); - void recordPropOrTracker(float timestamp, MDagPath path, MVector location, MQuaternion rotation); + void recordPropOrTracker(float timestamp, std::function foo); void recordFace(float timestamp, std::function foo); + void recordBone(float timestamp, std::function foo); void finalizeRecording(); - static int getFrame(const QList ×tamps, int frameNumber); - - static int getCorrectedFrameNumber(const QList ×tamps, int frameIndex); - void recordingToggled(bool enabled); void keyframeNumericAttribute(MString attrName, int frame, MDagPath dagPath, double value); @@ -57,7 +38,8 @@ class _Recorder QList sortedTimeStamps(); private: - QHash recordedData; + // timestamp - set keyframe function + QHash>> recordedData; float mRecordingStartTime; bool isRecording = false; };