diff options
author | Mahmoud Badri <mahmoud.badri@qt.io> | 2019-08-23 12:15:25 +0300 |
---|---|---|
committer | Mahmoud Badri <mahmoud.badri@qt.io> | 2019-08-27 10:49:26 +0300 |
commit | 317766c96985aa2c772536bed3a0058d2a4534e8 (patch) | |
tree | 0b2c34076298f4ae6b1cc1bdec741eb7fa562cba | |
parent | 8e9cbd3e2384653ac41404e035b1422bfc8f83a0 (diff) |
Unify Editor timeline unit to millisecond
The studio has mixed timing units (seconds and milliseconds). This
commit unifies the timings to milliseconds. The values are however kept
saved in the UIP file in seconds for backward compatibility and also
cause it is more compact (ex: 1 vs 1000).
Change-Id: I906214dfbb4e666ee099b4055ef4c9aa98e91745
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
17 files changed, 129 insertions, 159 deletions
diff --git a/src/Authoring/Client/Code/Core/Commands/CmdDataModelChangeKeyframe.h b/src/Authoring/Client/Code/Core/Commands/CmdDataModelChangeKeyframe.h index 99b33509..08c28a79 100644 --- a/src/Authoring/Client/Code/Core/Commands/CmdDataModelChangeKeyframe.h +++ b/src/Authoring/Client/Code/Core/Commands/CmdDataModelChangeKeyframe.h @@ -43,16 +43,13 @@ #include "CmdDataModelBase.h" #include "Qt3DSDMStudioSystem.h" -class CCmdDataModelSetKeyframeTime : public CCmdDataModelBase<float> +class CCmdDataModelSetKeyframeTime : public CCmdDataModelBase<long> { -protected: // Members - qt3dsdm::Qt3DSDMKeyframeHandle m_Keyframe; -public: // Construction - //@param inTime is in secs - CCmdDataModelSetKeyframeTime(CDoc *inDoc, qt3dsdm::Qt3DSDMKeyframeHandle inKeyframe, float inTime) - : CCmdDataModelBase(inDoc, inTime) - , m_Keyframe(inKeyframe) +public: + CCmdDataModelSetKeyframeTime(CDoc *doc, qt3dsdm::Qt3DSDMKeyframeHandle keyframe, long time) + : CCmdDataModelBase(doc, time) + , m_Keyframe(keyframe) { } ~CCmdDataModelSetKeyframeTime() {} @@ -65,22 +62,21 @@ public: // Construction theAnimationCore->SetKeyframeData(m_Keyframe, theKeyframe); } - //====================================================================== - // ToString - //====================================================================== QString ToString() override { return QObject::tr("Set Keyframe Time"); } + +protected: + qt3dsdm::Qt3DSDMKeyframeHandle m_Keyframe; }; class CCmdDataModelSetKeyframeValue : public CCmdDataModelBase<float> { -protected: // Members +protected: qt3dsdm::Qt3DSDMKeyframeHandle m_Keyframe; -public: // Construction - //@param inTime is in secs +public: CCmdDataModelSetKeyframeValue(CDoc *inDoc, qt3dsdm::Qt3DSDMKeyframeHandle inKeyframe, float inValue) : CCmdDataModelBase(inDoc, inValue) @@ -97,9 +93,6 @@ public: // Construction theAnimationCore->SetKeyframeData(m_Keyframe, theKeyframe); } - //====================================================================== - // ToString - //====================================================================== QString ToString() override { return QObject::tr("Set Keyframe Value"); diff --git a/src/Authoring/Client/Code/Core/Commands/CmdDataModelInsertKeyframe.h b/src/Authoring/Client/Code/Core/Commands/CmdDataModelInsertKeyframe.h index f2ea635f..c07170c2 100644 --- a/src/Authoring/Client/Code/Core/Commands/CmdDataModelInsertKeyframe.h +++ b/src/Authoring/Client/Code/Core/Commands/CmdDataModelInsertKeyframe.h @@ -46,11 +46,11 @@ public: struct STimeKeyframeData { qt3dsdm::Qt3DSDMPropertyHandle m_Property; - float m_KeyframeTime; // seconds + long m_KeyframeTime; qt3dsdm::SGetOrSetKeyframeInfo m_Infos[4]; size_t m_ValidInfoCount; - STimeKeyframeData(qt3dsdm::Qt3DSDMPropertyHandle inProperty, float inKeyframeTime, + STimeKeyframeData(qt3dsdm::Qt3DSDMPropertyHandle inProperty, long inKeyframeTime, qt3dsdm::SGetOrSetKeyframeInfo *inInfos, size_t inInfoCount) : m_Property(inProperty) , m_KeyframeTime(inKeyframeTime) @@ -75,7 +75,7 @@ public: , m_Instance(inInstance) {} ~CCmdDataModelInsertKeyframe() {} - void AddKeyframeData(qt3dsdm::Qt3DSDMPropertyHandle inProperty, float inTime, + void AddKeyframeData(qt3dsdm::Qt3DSDMPropertyHandle inProperty, long inTime, qt3dsdm::SGetOrSetKeyframeInfo *inInfos, size_t inInfoCount) { m_KeyframeDataList.push_back(STimeKeyframeData(inProperty, inTime, inInfos, inInfoCount)); diff --git a/src/Authoring/Client/Code/Core/Doc/Doc.cpp b/src/Authoring/Client/Code/Core/Doc/Doc.cpp index 6be4c066..9ef2a930 100644 --- a/src/Authoring/Client/Code/Core/Doc/Doc.cpp +++ b/src/Authoring/Client/Code/Core/Doc/Doc.cpp @@ -623,7 +623,7 @@ void CDoc::NotifyActiveSlideChanged(qt3dsdm::Qt3DSDMSlideHandle inNewActiveSlide if (theLastActiveSlide != inNewActiveSlide) { SetActiveSlideChange(inNewActiveSlide); if (inIgnoreLastDisplayTime) - m_StudioSystem->GetSlideSystem()->SetComponentSeconds( + m_StudioSystem->GetSlideSystem()->SetComponentTime( m_StudioSystem->GetSlideSystem()->GetMasterSlide(inNewActiveSlide), 0); } @@ -1382,7 +1382,7 @@ bool CDoc::isPlayHeadAtEnd() return m_CurrentViewTime >= GetLatestEndTime(); } -void CDoc::OnComponentSeconds() +void CDoc::OnComponentTime() { long theTime = GetCurrentClientTime(); @@ -1421,8 +1421,8 @@ void CDoc::DoNotifyTimeChanged(long inNewTime) // Update DataModel qt3dsdm::Qt3DSDMSlideHandle theMasterSlide = m_StudioSystem->GetSlideSystem()->GetMasterSlide(GetActiveSlide()); - // TODO: fix precision issue from converting to/from float & long. choose 1 type - m_StudioSystem->GetSlideSystem()->SetComponentSeconds(theMasterSlide, (float)inNewTime / 1000); + + m_StudioSystem->GetSlideSystem()->SetComponentTime(theMasterSlide, inNewTime); } /** @@ -1488,7 +1488,7 @@ bool CDoc::IsPlaying() long CDoc::GetCurrentClientTime() { if (m_ActiveSlide.Valid()) - return m_StudioSystem->GetSlideSystem()->GetComponentSecondsLong(m_ActiveSlide); + return m_StudioSystem->GetSlideSystem()->GetComponentTime(m_ActiveSlide); return 0; } @@ -2244,11 +2244,11 @@ void CDoc::SetupDataCoreSignals() m_Connections.push_back(theSlideProvider->ConnectBeforeSlideDeleted( std::bind(&CDoc::OnSlideDeleted, this, std::placeholders::_1))); m_Connections.push_back( - m_StudioSystem->GetFullSystem()->GetSignalProvider()->ConnectComponentSeconds( - std::bind(&CDoc::OnComponentSeconds, this))); + m_StudioSystem->GetFullSystem()->GetSignalProvider()->ConnectComponentTime( + std::bind(&CDoc::OnComponentTime, this))); m_Connections.push_back( m_StudioSystem->GetFullSystem()->GetSignalProvider()->ConnectActiveSlide( - std::bind(&CDoc::OnComponentSeconds, this))); + std::bind(&CDoc::OnComponentTime, this))); // listener to keep track of datainput bindings m_Connections.push_back( diff --git a/src/Authoring/Client/Code/Core/Doc/Doc.h b/src/Authoring/Client/Code/Core/Doc/Doc.h index a12df7cb..af91c59e 100644 --- a/src/Authoring/Client/Code/Core/Doc/Doc.h +++ b/src/Authoring/Client/Code/Core/Doc/Doc.h @@ -301,7 +301,7 @@ public: // IDoc virtual qt3dsdm::Qt3DSDMInstanceHandle GetActiveRootInstance(); long GetCurrentViewTime() const override; - virtual void OnComponentSeconds(); + virtual void OnComponentTime(); // Notify time changed and set the playback clock to this time. void NotifyTimeChanged(long inNewTime) override; // Notify time changed. diff --git a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp index 7051a91d..af008129 100644 --- a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp +++ b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp @@ -243,7 +243,7 @@ public: Qt3DSDMSlideHandle theMaster = theSlideInfo.m_MasterSlide; Qt3DSDMSlideHandle theActiveSlide = theSlideInfo.m_ActiveSlide; if (theAssociatedSlide == theMaster || theAssociatedSlide == theActiveSlide) { - long theViewTime = theSlideInfo.m_ComponentMilliseconds; + long theViewTime = theSlideInfo.m_ComponentTime; return eyeballVal && theStart <= theViewTime && theEnd > 0 && theEnd >= theViewTime; } } @@ -2811,8 +2811,8 @@ public: } template <typename TKeyframeType> - void AddKeyframes(Qt3DSDMAnimationHandle animHandle, const float *keyframeValues, long numValues, - long inOffsetInSeconds) + void AddKeyframes(Qt3DSDMAnimationHandle animHandle, const float *keyframeValues, + long numValues, long timeOffset) { long numFloatsPerKeyframe = sizeof(TKeyframeType) / sizeof(float); if (numValues % numFloatsPerKeyframe) { @@ -2822,25 +2822,21 @@ public: long numKeyframes = numValues / numFloatsPerKeyframe; for (long idx = 0; idx < numKeyframes; ++idx) { TKeyframeType theData(keyframes[idx]); - theData.m_KeyframeSeconds += inOffsetInSeconds; + theData.m_time += timeOffset; m_AnimationCore.InsertKeyframe(animHandle, theData); } } - void SetKeyframeTime(TKeyframeHandle inKeyframe, long inTime) override + void SetKeyframeTime(TKeyframeHandle kfHandle, long time) override { - float timeInSecs = static_cast<float>(inTime) / 1000.f; - // round off to 4 decimal place to workaround precision issues - // TODO: fix this, either all talk float OR long. choose one. - timeInSecs = ceilf(timeInSecs * 10000.0f) / 10000.0f; - TKeyframe kfData = m_AnimationCore.GetKeyframeData(inKeyframe); + TKeyframe kfData = m_AnimationCore.GetKeyframeData(kfHandle); // offset control points for bezier keyframes - offsetBezier(kfData, timeInSecs - getKeyframeTime(kfData)); + offsetBezier(kfData, time - getKeyframeTime(kfData)); // Functional programming paradigm, returns new value instead of changing current value. - kfData = qt3dsdm::setKeyframeTime(kfData, timeInSecs); - m_AnimationCore.SetKeyframeData(inKeyframe, kfData); + kfData = qt3dsdm::setKeyframeTime(kfData, time); + m_AnimationCore.SetKeyframeData(kfHandle, kfData); } void setBezierKeyframeValue(TKeyframeHandle kfHandle, const TKeyframe &kfData) override @@ -2891,25 +2887,21 @@ public: m_AnimationCore.CreateAnimation(inSlide, instance, property, subIndex, animType, false); long theStartTime = GetTimeRange(instance).first; - long theTimeOffsetInSeconds = long(theStartTime / 1000.f); switch (animType) { case EAnimationTypeLinear: - AddKeyframes<SLinearKeyframe>(animHandle, keyframeValues, numValues, - theTimeOffsetInSeconds); + AddKeyframes<SLinearKeyframe>(animHandle, keyframeValues, numValues, theStartTime); break; case EAnimationTypeBezier: - AddKeyframes<SBezierKeyframe>(animHandle, keyframeValues, numValues, - theTimeOffsetInSeconds); + AddKeyframes<SBezierKeyframe>(animHandle, keyframeValues, numValues, theStartTime); break; case EAnimationTypeEaseInOut: AddKeyframes<SEaseInEaseOutKeyframe>(animHandle, keyframeValues, numValues, - theTimeOffsetInSeconds); + theStartTime); break; default: QT3DS_ASSERT(false); - AddKeyframes<SLinearKeyframe>(animHandle, keyframeValues, numValues, - theTimeOffsetInSeconds); + AddKeyframes<SLinearKeyframe>(animHandle, keyframeValues, numValues, theStartTime); break; } return animHandle; diff --git a/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp b/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp index 96ca4937..beff3192 100644 --- a/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp +++ b/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp @@ -120,47 +120,60 @@ using std::hash; template <typename TOperator> static void HandleKeyframe(SLinearKeyframe &inKeyframe, TOperator &inOperator) { - inOperator(inKeyframe.m_KeyframeSeconds); - inOperator(inKeyframe.m_KeyframeValue); + float kfTime = float(inKeyframe.m_time / 1000.f); + + inOperator(kfTime); + inOperator(inKeyframe.m_value); + + inKeyframe.m_time = long(kfTime * 1000.f); } template <typename TOperator> static void HandleKeyframe(SBezierKeyframe &inKeyframe, TOperator &inOperator) { - inOperator(inKeyframe.m_KeyframeSeconds); - inOperator(inKeyframe.m_KeyframeValue); - inOperator(inKeyframe.m_InTangentTime); + float kfTime = float(inKeyframe.m_time / 1000.f); + float tangentInTime = float(inKeyframe.m_InTangentTime / 1000.f); + float tangentOutTime = float(inKeyframe.m_OutTangentTime / 1000.f); + + inOperator(kfTime); + inOperator(inKeyframe.m_value); + inOperator(tangentInTime); inOperator(inKeyframe.m_InTangentValue); - inOperator(inKeyframe.m_OutTangentTime); + inOperator(tangentOutTime); inOperator(inKeyframe.m_OutTangentValue); + + inKeyframe.m_time = long(kfTime * 1000.f); + inKeyframe.m_InTangentTime = long(tangentInTime * 1000.f); + inKeyframe.m_OutTangentTime = long(tangentOutTime * 1000.f); } template <typename TOperator> static void HandleKeyframe(SEaseInEaseOutKeyframe &inKeyframe, TOperator &inOperator) { - inOperator(inKeyframe.m_KeyframeSeconds); - inOperator(inKeyframe.m_KeyframeValue); + float kfTime = float(inKeyframe.m_time / 1000.f); + inOperator(kfTime); + inOperator(inKeyframe.m_value); inOperator(inKeyframe.m_EaseIn); inOperator(inKeyframe.m_EaseOut); + + inKeyframe.m_time = long(kfTime * 1000.f); } -template <typename TItemType> -struct SVectorWriteOperator +struct KeyframeWriter { - vector<TItemType> &m_Vector; - SVectorWriteOperator(vector<TItemType> &vec) - : m_Vector(vec) + vector<float> &m_vector; + KeyframeWriter(vector<float> &vec) + : m_vector(vec) { } - void operator()(const TItemType &inValue) { m_Vector.push_back(inValue); } + void operator()(const float &inValue) { m_vector.push_back(inValue); } }; -template <typename TItemType> -struct SMemReadOperator +struct KeyframeReader { - const TItemType *m_Ptr; - const TItemType *m_End; - SMemReadOperator(const TItemType *s, const TItemType *e) + const float *m_Ptr; + const float *m_End; + KeyframeReader(const float *s, const float *e) : m_Ptr(s) , m_End(e) { @@ -168,7 +181,7 @@ struct SMemReadOperator bool IsDone() { return m_Ptr >= m_End; } - void operator()(TItemType &outValue) + void operator()(float &outValue) { if (m_Ptr < m_End) { outValue = *m_Ptr; @@ -183,7 +196,7 @@ template <typename TKeyframeType> static void WriteKeyframes(TKeyframeHandleList &inKeyframes, IAnimationCore &inCore, vector<float> &outValues) { - SVectorWriteOperator<float> theOperator(outValues); + KeyframeWriter theOperator(outValues); for (size_t idx = 0, end = inKeyframes.size(); idx < end; ++idx) { TKeyframe theKeyframeVariant(inCore.GetKeyframeData(inKeyframes[idx])); TKeyframeType theData(get<TKeyframeType>(theKeyframeVariant)); @@ -195,7 +208,7 @@ template <typename TKeyframeType> static void ReadKeyframes(Qt3DSDMAnimationHandle inAnimation, IAnimationCore &inCore, const float *inStart, const float *inEnd) { - SMemReadOperator<float> theOperator(inStart, inEnd); + KeyframeReader theOperator(inStart, inEnd); while (theOperator.IsDone() == false) { TKeyframeType theData; HandleKeyframe(theData, theOperator); diff --git a/src/Authoring/Client/Code/Core/Doc/IDocumentEditor.h b/src/Authoring/Client/Code/Core/Doc/IDocumentEditor.h index 71859311..da11238e 100644 --- a/src/Authoring/Client/Code/Core/Doc/IDocumentEditor.h +++ b/src/Authoring/Client/Code/Core/Doc/IDocumentEditor.h @@ -306,7 +306,7 @@ public: long numValues, bool inUserEdited = true) = 0; virtual bool RemoveAnimation(TSlideHandle inSlide, TInstanceHandle instance, const wchar_t *propName, long subIndex) = 0; - virtual void SetKeyframeTime(TKeyframeHandle inKeyframe, long inTimeInMilliseconds) = 0; + virtual void SetKeyframeTime(TKeyframeHandle inKeyframe, long inTime) = 0; virtual void setBezierKeyframeValue(TKeyframeHandle kfHandle, const qt3dsdm::TKeyframe &kfData) = 0; virtual void DeleteAllKeyframes(Qt3DSDMAnimationHandle inAnimation) = 0; diff --git a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/PasteKeyframesCommandHelper.h b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/PasteKeyframesCommandHelper.h index f6330cc0..44b585b1 100644 --- a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/PasteKeyframesCommandHelper.h +++ b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/PasteKeyframesCommandHelper.h @@ -48,7 +48,7 @@ public: ~CPasteKeyframeCommandHelper() {} // inTime should be relative to the earliest keyframe time in this list - void AddKeyframeData(qt3dsdm::Qt3DSDMPropertyHandle inProperty, float inKeyframeTime, + void AddKeyframeData(qt3dsdm::Qt3DSDMPropertyHandle inProperty, long inKeyframeTime, qt3dsdm::SGetOrSetKeyframeInfo *inInfos, size_t inInfoCount) { m_CopiedKeyframeList.push_back(CCmdDataModelInsertKeyframe::STimeKeyframeData( @@ -66,23 +66,23 @@ public: // but that is not an issue in the new data model. // // 2. The first pasted keyframe is at current view time and the rest are offset accordingly. - CCmdDataModelInsertKeyframe *GetCommand(CDoc *inDoc, long inTimeOffsetInMilliseconds, - qt3dsdm::Qt3DSDMInstanceHandle inTargetInstance) + CCmdDataModelInsertKeyframe *GetCommand(CDoc *doc, long timeOffset, + qt3dsdm::Qt3DSDMInstanceHandle targetInstance) { using namespace qt3dsdm; CCmdDataModelInsertKeyframe *insertKeyframesCmd = nullptr; - qt3dsdm::IPropertySystem *propSys = inDoc->GetStudioSystem()->GetPropertySystem(); - CClientDataModelBridge *bridge = inDoc->GetStudioSystem()->GetClientDataModelBridge(); + qt3dsdm::IPropertySystem *propSys = doc->GetStudioSystem()->GetPropertySystem(); + CClientDataModelBridge *bridge = doc->GetStudioSystem()->GetClientDataModelBridge(); for (auto &kfData : m_CopiedKeyframeList) { // check property exists on target - if (bridge->hasAggregateInstanceProperty(inTargetInstance, kfData.m_Property)) { + if (bridge->hasAggregateInstanceProperty(targetInstance, kfData.m_Property)) { if (!insertKeyframesCmd) - insertKeyframesCmd = new CCmdDataModelInsertKeyframe(inDoc, inTargetInstance); + insertKeyframesCmd = new CCmdDataModelInsertKeyframe(doc, targetInstance); - // Offset keyframe time by current view time (time in seconds) - float time = kfData.m_KeyframeTime + inTimeOffsetInMilliseconds / 1000.f; + // Offset keyframe time by current view time + long time = kfData.m_KeyframeTime + timeOffset; insertKeyframesCmd->AddKeyframeData(kfData.m_Property, time, kfData.m_Infos, kfData.m_ValidInfoCount); } diff --git a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemProperty.cpp b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemProperty.cpp index bc9cefe7..a5c49bfa 100644 --- a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemProperty.cpp +++ b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemProperty.cpp @@ -285,10 +285,8 @@ float Qt3DSDMTimelineItemProperty::GetChannelValueAtTime(size_t chIndex, long ti } IAnimationCore *animCore = m_TransMgr->GetStudioSystem()->GetAnimationCore(); - if (!m_AnimationHandles.empty() && chIndex < m_AnimationHandles.size()) { - return animCore->EvaluateAnimation(m_AnimationHandles[chIndex], - Qt3DSDMTimelineKeyframe::GetTimeInSecs(time)); - } + if (!m_AnimationHandles.empty() && chIndex < m_AnimationHandles.size()) + return animCore->EvaluateAnimation(m_AnimationHandles[chIndex], time); return 0.f; } diff --git a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.cpp b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.cpp index d447307c..acfbf4ac 100644 --- a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.cpp +++ b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.cpp @@ -56,58 +56,32 @@ bool Qt3DSDMTimelineKeyframe::IsSelected() const return m_Selected; } -float my_roundf(float r) -{ - return (r > 0.0f) ? floorf(r + 0.5f) : ceilf(r - 0.5f); -} - long Qt3DSDMTimelineKeyframe::GetTime() const { if (!m_KeyframeHandles.empty()) { IAnimationCore *animaCore = m_Doc->GetStudioSystem()->GetAnimationCore(); Qt3DSDMKeyframeHandle kfHandle = *m_KeyframeHandles.begin(); - if (animaCore->KeyframeValid(kfHandle)) { - float theTimeinSecs = getKeyframeTime(animaCore->GetKeyframeData(kfHandle)); - // We always convert back and forth between between long and float. - // This causes especially issues when we do comparisons - return (long)my_roundf(theTimeinSecs * 1000); - } + if (animaCore->KeyframeValid(kfHandle)) + return getKeyframeTime(animaCore->GetKeyframeData(kfHandle)); } - return -1; // keyframe was deleted, and data cannot be retrieved. -} -float Qt3DSDMTimelineKeyframe::GetTimeInSecs(long inTime) -{ - float theTimeinSecs = static_cast<float>(inTime) / 1000.f; - // round off to 4 decimal place to workaround precision issues - // TODO: fix this, either all talk float OR long. choose one. - theTimeinSecs = (float)(((theTimeinSecs + 0.00005) * 10000.0) / 10000.0f); - return theTimeinSecs; + return -1; // keyframe was deleted, and data cannot be retrieved. } void Qt3DSDMTimelineKeyframe::SetTime(const long inNewTime) { - float theTimeinSecs = GetTimeInSecs(inNewTime); CCmd *theCmd = nullptr; if (m_KeyframeHandles.size() == 1) { - theCmd = new CCmdDataModelSetKeyframeTime(m_Doc, m_KeyframeHandles.front(), theTimeinSecs); + theCmd = new CCmdDataModelSetKeyframeTime(m_Doc, m_KeyframeHandles.front(), inNewTime); } else { // more than 1 channel CCmdBatch *theBatch = new CCmdBatch(m_Doc); TKeyframeHandleList::iterator theIter = m_KeyframeHandles.begin(); for (; theIter != m_KeyframeHandles.end(); ++theIter) - theBatch->AddCommand(new CCmdDataModelSetKeyframeTime(m_Doc, *theIter, theTimeinSecs)); + theBatch->AddCommand(new CCmdDataModelSetKeyframeTime(m_Doc, *theIter, inNewTime)); theCmd = theBatch; } if (theCmd) m_Doc->GetCore()->ExecuteCommand(theCmd); - -#ifdef _DEBUG - // we have a precision issue from converting from long to float.. - IAnimationCore *theAnimationCore = m_Doc->GetStudioSystem()->GetAnimationCore(); - long theTest = static_cast<long>( - getKeyframeTime(theAnimationCore->GetKeyframeData(*m_KeyframeHandles.begin())) * 1000); - Q_ASSERT(inNewTime == theTest); -#endif } inline Qt3DSDMAnimationHandle GetAnimationHandle(qt3dsdm::IAnimationCore *inAnimationCore, diff --git a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.h b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.h index 63944764..3b73a3e7 100644 --- a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.h +++ b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.h @@ -63,8 +63,6 @@ public: void UpdateKeyframesTime(COffsetKeyframesCommandHelper *inCommandHelper, long inTime); void GetKeyframeHandles(TKeyframeHandleList &outList) const; - static float GetTimeInSecs(long inTime); - private: TKeyframeHandleList m_KeyframeHandles; // channels handles of the animated property CDoc *m_Doc = nullptr; diff --git a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/KeyframeManager.cpp b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/KeyframeManager.cpp index dcb1c5eb..4da0d376 100644 --- a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/KeyframeManager.cpp +++ b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/KeyframeManager.cpp @@ -334,7 +334,7 @@ void KeyframeManager::copySelectedKeyframes() break; } - float dt = Qt3DSDMTimelineKeyframe::GetTimeInSecs(kf->GetTime() - minTime); + long dt = kf->GetTime() - minTime; qt3dsdm::Qt3DSDMAnimationHandle animation = animationCore->GetAnimationForKeyframe(theKeyframeHandles[0]); m_pasteKeyframeCommandHelper->AddKeyframeData( @@ -361,10 +361,9 @@ void KeyframeManager::pasteKeyframes() if (m_pasteKeyframeCommandHelper && m_pasteKeyframeCommandHelper->HasCopiedKeyframes()) { qt3dsdm::Qt3DSDMInstanceHandle theSelectedInstance = theDoc->GetSelectedInstance(); if (theSelectedInstance.Valid()) { - long theCurrentViewTimeInMilliseconds = theDoc->GetCurrentViewTime(); - CCmdDataModelInsertKeyframe *theInsertKeyframesCommand = - m_pasteKeyframeCommandHelper->GetCommand(theDoc, theCurrentViewTimeInMilliseconds, - theSelectedInstance); + CCmdDataModelInsertKeyframe *theInsertKeyframesCommand + = m_pasteKeyframeCommandHelper->GetCommand(theDoc, theDoc->GetCurrentViewTime(), + theSelectedInstance); if (theInsertKeyframesCommand) g_StudioApp.GetCore()->ExecuteCommand(theInsertKeyframesCommand); } diff --git a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp index 8080f004..0078bc15 100644 --- a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp +++ b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp @@ -270,11 +270,11 @@ void RowTimelineContextMenu::onAnimTypeChange(QAction *action) QVector<SBezierKeyframe> keyframes; for (Qt3DSDMKeyframeHandle kfHandle : keyframeHandles) { TKeyframe kfData = animCore->GetKeyframeData(kfHandle); - float kfTime = getKeyframeTime(kfData); + long kfTime = getKeyframeTime(kfData); float kfValue = getKeyframeValue(kfData); keyframes.append(SBezierKeyframe(kfTime, kfValue, - kfTime - .5f, kfValue, - kfTime + .5f, kfValue)); + kfTime - 500, kfValue, + kfTime + 500, kfValue)); } long numFloatsPerKeyframe = sizeof(SBezierKeyframe) / sizeof(float); long numValues = long(keyframeHandles.size()) * numFloatsPerKeyframe; diff --git a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp index cdd38744..fbc92377 100644 --- a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp +++ b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp @@ -266,11 +266,11 @@ TimelineControlType RowTimelinePropertyGraph::getClickedBezierControl(const QPoi QPointF RowTimelinePropertyGraph::getBezierControlPosition(const SBezierKeyframe &kf, BezierControlType type) const { - float time = 0; // seconds + long time = 0; float value = 0; if (type == BezierControlType::None) { - time = kf.m_KeyframeSeconds; - value = kf.m_KeyframeValue; + time = kf.m_time; + value = kf.m_value; } else if (type == BezierControlType::In) { time = kf.m_InTangentTime; value = kf.m_InTangentValue; @@ -282,12 +282,11 @@ QPointF RowTimelinePropertyGraph::getBezierControlPosition(const SBezierKeyframe return getKeyframePosition(time, value); } -// time is in seconds -QPointF RowTimelinePropertyGraph::getKeyframePosition(float time, float value) const +QPointF RowTimelinePropertyGraph::getKeyframePosition(long time, float value) const { adjustColorProperty(value); - return QPointF(m_rowTimeline->rowTree()->m_scene->ruler()->timeToDistance(time * 1000), + return QPointF(m_rowTimeline->rowTree()->m_scene->ruler()->timeToDistance(time), m_graphY - value * m_valScale); } @@ -304,7 +303,7 @@ void RowTimelinePropertyGraph::updateBezierControlValue(TimelineControlType cont QPointF p = m_rowTimeline->mapFromScene(scenePos.x() - RULER_EDGE_OFFSET, scenePos.y()); // time and value at current mouse position - float time = m_rowTimeline->rowTree()->m_scene->ruler()->distanceToTime(p.x()) / 1000.f; // secs + long time = m_rowTimeline->rowTree()->m_scene->ruler()->distanceToTime(p.x()); float value = (m_graphY - p.y()) / m_valScale; adjustColorProperty(value, false); @@ -312,9 +311,9 @@ void RowTimelinePropertyGraph::updateBezierControlValue(TimelineControlType cont bool isBezierIn = controlType == TimelineControlType::BezierInHandle; // prevent handles from moving to the other side of the keyframe - if ((isBezierIn && time > kf.m_KeyframeSeconds) - || (!isBezierIn && time < kf.m_KeyframeSeconds)) { - time = kf.m_KeyframeSeconds; + if ((isBezierIn && time > kf.m_time) + || (!isBezierIn && time < kf.m_time)) { + time = kf.m_time; } // prevent handles from going beyond prev. and next keyframes @@ -323,11 +322,14 @@ void RowTimelinePropertyGraph::updateBezierControlValue(TimelineControlType cont m_animCore->GetKeyframes(anim, keyframeHandles); for (size_t i = 0; i < keyframeHandles.size(); ++i) { if (keyframeHandles[i] == m_currKeyframeData.first) { - float currKfTime = getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i])); - float prevKfTime = i > 0 - ? getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i - 1])) : -FLT_MAX; - float nextKfTime = i < keyframeHandles.size() - 1 - ? getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i + 1])) : FLT_MAX; + long currKfTime = getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i])); + long prevKfTime = i > 0 + ? getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i - 1])) + : LONG_MIN / 2; + long nextKfTime = i < keyframeHandles.size() - 1 + ? getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i + 1])) + : LONG_MAX / 2; + if (isBezierIn) { if (time < prevKfTime) time = prevKfTime; @@ -343,17 +345,17 @@ void RowTimelinePropertyGraph::updateBezierControlValue(TimelineControlType cont } } - float &currHandleTime = isBezierIn ? kf.m_InTangentTime : kf.m_OutTangentTime; + long &currHandleTime = isBezierIn ? kf.m_InTangentTime : kf.m_OutTangentTime; float &currHandleValue = isBezierIn ? kf.m_InTangentValue : kf.m_OutTangentValue; - float &otherHandleTime = isBezierIn ? kf.m_OutTangentTime : kf.m_InTangentTime; + long &otherHandleTime = isBezierIn ? kf.m_OutTangentTime : kf.m_InTangentTime; float &otherHandleValue = isBezierIn ? kf.m_OutTangentValue : kf.m_InTangentValue; currHandleTime = time; currHandleValue = value; if (!CHotKeys::isCtrlDown()) { - otherHandleTime = kf.m_KeyframeSeconds + (kf.m_KeyframeSeconds - time); - otherHandleValue = kf.m_KeyframeValue + (kf.m_KeyframeValue - currHandleValue); + otherHandleTime = kf.m_time + (kf.m_time - time); + otherHandleValue = kf.m_value + (kf.m_value - currHandleValue); } m_animCore->SetKeyframeData(m_currKeyframeData.first, kf); @@ -394,7 +396,8 @@ void RowTimelinePropertyGraph::fitGraph() // for bezier keyframes compare tangents in/out also if (keyframeData.getType() == qt3dsdm::EAnimationTypeBezier) { - float timeIn, valueIn, timeOut, valueOut; + long timeIn, timeOut; + float valueIn, valueOut; getBezierValues(keyframeData, timeIn, valueIn, timeOut, valueOut); if (!m_animCore->IsFirstKeyframe(kfHandle)) { // check tangent-in value diff --git a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h index 0607b8a2..b3ec82b1 100644 --- a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h +++ b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h @@ -71,7 +71,7 @@ private: QPointF getBezierControlPosition(const qt3dsdm::SBezierKeyframe &kf, BezierControlType type = BezierControlType::None) const; - QPointF getKeyframePosition(float time, float value) const; + QPointF getKeyframePosition(long time, float value) const; void checkValScaleLimits(); void adjustColorProperty(float &val, bool scaleUp = true) const; diff --git a/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.cpp b/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.cpp index 5312d2f8..06d6be76 100644 --- a/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.cpp +++ b/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.cpp @@ -1966,7 +1966,7 @@ STranslation::STranslation(IStudioRenderer &inRenderer, IQt3DSRenderContext &inC , m_DirtySet(inContext.GetAllocator(), "STranslation::m_DirtySet") , m_Scene(nullptr) , m_SignalConnections(inContext.GetAllocator(), "STranslation::m_SignalConnections") - , m_ComponentSecondsDepth(0) + , m_ComponentTimeDepth(0) , m_KeyRepeat(0) , m_EditCameraEnabled(false) , m_EditLightEnabled(false) @@ -2004,10 +2004,10 @@ STranslation::STranslation(IStudioRenderer &inRenderer, IQt3DSRenderContext &inC m_SignalConnections.push_back(m_AssetGraph.ConnectChildRemoved( std::bind(&STranslation::MarkGraphInstanceDirty, this, std::placeholders::_1, std::placeholders::_2))); - m_SignalConnections.push_back(theProvider->ConnectBeginComponentSeconds( - std::bind(&STranslation::MarkBeginComponentSeconds, this, std::placeholders::_1))); - m_SignalConnections.push_back(theProvider->ConnectComponentSeconds( - std::bind(&STranslation::MarkComponentSeconds, this, std::placeholders::_1))); + m_SignalConnections.push_back(theProvider->ConnectBeginComponentTime( + std::bind(&STranslation::MarkBeginComponentTime, this, std::placeholders::_1))); + m_SignalConnections.push_back(theProvider->ConnectComponentTime( + std::bind(&STranslation::MarkComponentTime, this, std::placeholders::_1))); ::CColor color = CStudioPreferences::rulerBackgroundColor(); // Rectangles under tick marks m_rectColor = QT3DSVec4(color.GetRed() / 255.f, diff --git a/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.h b/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.h index 5c2620b5..8f38d8e0 100644 --- a/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.h +++ b/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.h @@ -368,7 +368,7 @@ namespace studio { qt3ds::render::SScene *m_Scene; Q3DStudio::CGraphIterator m_GraphIterator; nvvector<TSignalConnection> m_SignalConnections; - QT3DSI32 m_ComponentSecondsDepth; + QT3DSI32 m_ComponentTimeDepth; SNode m_MouseDownNode; SCamera m_MouseDownCamera; Option<QT3DSMat44> m_MouseDownParentGlobalTransformInverse; @@ -418,12 +418,12 @@ namespace studio { QT3DSVec2 m_previewFboDimensions; STranslation(IStudioRenderer &inRenderer, IQt3DSRenderContext &inContext); - void MarkBeginComponentSeconds(qt3dsdm::Qt3DSDMSlideHandle) { ++m_ComponentSecondsDepth; } + void MarkBeginComponentTime(qt3dsdm::Qt3DSDMSlideHandle) { ++m_ComponentTimeDepth; } - void MarkComponentSeconds(qt3dsdm::Qt3DSDMSlideHandle) + void MarkComponentTime(qt3dsdm::Qt3DSDMSlideHandle) { - m_ComponentSecondsDepth = qMax(0, m_ComponentSecondsDepth - 1); - if (m_ComponentSecondsDepth == 0) + m_ComponentTimeDepth = qMax(0, m_ComponentTimeDepth - 1); + if (m_ComponentTimeDepth == 0) RequestRender(); } @@ -641,7 +641,7 @@ namespace studio { void RequestRender() { - if (m_ComponentSecondsDepth == 0) + if (m_ComponentTimeDepth == 0) m_Renderer.RequestRender(); } |