summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMahmoud Badri <mahmoud.badri@qt.io>2019-09-04 14:23:42 +0300
committerMahmoud Badri <mahmoud.badri@qt.io>2019-09-09 12:46:26 +0300
commit2206a31c2f6a98abe54527000a5b389f8f9980bc (patch)
tree221246d95c6b83ab0986cad927ebaa8871b2b022
parent0e8d9f8133fe1a3cf86457faa332de3180d8d17a (diff)
Fix imported assets animations not appearing bug
Imported keyframes times have to be convered from seconds to milliseconds to work correctly. Task-number: QT3DS-3921 Change-Id: I4a01ce548560bf35adae9e525bbe7d3aba9f8064 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r--src/Authoring/Client/Code/Core/Doc/ComposerEditorInterface.cpp28
-rw-r--r--src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp33
2 files changed, 37 insertions, 24 deletions
diff --git a/src/Authoring/Client/Code/Core/Doc/ComposerEditorInterface.cpp b/src/Authoring/Client/Code/Core/Doc/ComposerEditorInterface.cpp
index 9d477e0c..7efcc82f 100644
--- a/src/Authoring/Client/Code/Core/Doc/ComposerEditorInterface.cpp
+++ b/src/Authoring/Client/Code/Core/Doc/ComposerEditorInterface.cpp
@@ -38,8 +38,16 @@ using namespace Q3DStudio::ComposerImport;
using namespace qt3ds::foundation;
namespace {
-// base class between performing refresh and performing
-// imports
+// base class between performing refresh and performing imports
+
+// convert imported keyframes times from seconds to millis to be compatible with the animation
+// system. The assumption is that keyframes are imported as EaseInOut type which has 4 values per
+// keyframe
+inline void convertSecondsToMillis(const float *animData, QT3DSU32 numFloats)
+{
+ for (int i = 0; i < numFloats; i += 4)
+ const_cast<float *>(animData)[i] *= 1000.f;
+}
struct STCharPtrHash
{
@@ -112,13 +120,13 @@ struct SComposerImportInterface : public SComposerImportBase, public IComposerEd
, m_Root(root)
, m_Slide(slide)
, m_StartTime(inStartTime)
- , m_ImportObj(NULL)
+ , m_ImportObj(nullptr)
{
m_Editor.BeginAggregateOperation();
}
// Fires the 'do' notifications
- ~SComposerImportInterface() { m_Editor.EndAggregateOperation(); }
+ ~SComposerImportInterface() override { m_Editor.EndAggregateOperation(); }
// IComposerEditorInterface
@@ -154,7 +162,7 @@ struct SComposerImportInterface : public SComposerImportBase, public IComposerEd
void AddInstanceMap(Qt3DSDMInstanceHandle instanceHandle, TImportId inImportId) override
{
- if (inImportId == NULL || *inImportId == 0) {
+ if (inImportId == nullptr || *inImportId == 0) {
assert(0);
return;
}
@@ -397,6 +405,7 @@ struct SComposerImportInterface : public SComposerImportBase, public IComposerEd
Qt3DSDMInstanceHandle hdl(FindInstance(inInstance));
if (hdl.Valid()) {
if (m_Editor.IsAnimationArtistEdited(m_Slide, hdl, propName, propSubIndex) == false) {
+ convertSecondsToMillis(animData, numFloats);
Qt3DSDMAnimationHandle anim = m_Editor.CreateOrSetAnimation(
m_Slide, hdl, propName, propSubIndex, animType, animData, numFloats, false);
m_Editor.SetIsArtistEdited(anim, false);
@@ -429,7 +438,7 @@ struct SComposerRefreshInterface : public SComposerImportBase, public IComposerE
SSlideInstanceIdMapIterator(TImportId inImportId, TIdMultiMap &inItems,
qt3dsdm::IStringTable &inStringTable)
- : m_CurrentItems(NULL)
+ : m_CurrentItems(nullptr)
, m_CurrentTreeIdx(0)
, m_CurrentTreeEnd(0)
, m_Id(inStringTable.RegisterStr(inImportId))
@@ -440,7 +449,7 @@ struct SComposerRefreshInterface : public SComposerImportBase, public IComposerE
{
m_CurrentTreeIdx = 0;
m_CurrentTreeEnd = 0;
- m_CurrentItems = NULL;
+ m_CurrentItems = nullptr;
TIdMultiMap::const_iterator theFind = inItems.find(m_Id);
if (theFind != inItems.end()) {
m_CurrentItems = &theFind->second;
@@ -774,8 +783,8 @@ struct SComposerRefreshInterface : public SComposerImportBase, public IComposerE
theIterator.GetCurrentInstance(), propName, propSubIndex)
&& m_Editor.IsAnimationArtistEdited(theIterator.GetCurrentSlide(),
theIterator.GetCurrentInstance(), propName,
- propSubIndex)
- == false) {
+ propSubIndex) == false) {
+ convertSecondsToMillis(animData, numFloats);
Qt3DSDMAnimationHandle anim = m_Editor.CreateOrSetAnimation(
theIterator.GetCurrentSlide(), theIterator.GetCurrentInstance(), propName,
propSubIndex, animType, animData, numFloats, false);
@@ -793,6 +802,7 @@ struct SComposerRefreshInterface : public SComposerImportBase, public IComposerE
if (!m_Editor.AnimationExists(theIterator.GetCurrentSlide(),
theIterator.GetCurrentInstance(), propName,
propSubIndex)) {
+ convertSecondsToMillis(animData, numFloats);
Qt3DSDMAnimationHandle anim = m_Editor.CreateOrSetAnimation(
theIterator.GetCurrentSlide(), theIterator.GetCurrentInstance(), propName,
propSubIndex, animType, animData, numFloats, false);
diff --git a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp
index b21b80a6..215c4d64 100644
--- a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp
+++ b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp
@@ -117,7 +117,7 @@ void RowTimelinePropertyGraph::paintGraphs(QPainter *painter, const QRectF &rect
// draw channel curves
painter->setPen(CStudioPreferences::studioColor3()); // default to locked color
- for (size_t i = 0; i < m_activeChannels.size(); ++i) {
+ for (int i = 0; i < m_activeChannels.size(); ++i) {
QPainterPath path;
int start_j = qMax(rect.x(), edgeOffset.x());
for (int j = start_j; j < rect.right(); j += 5) { // 5 = sampling step in pixels
@@ -308,7 +308,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
- long time = m_rowTimeline->rowTree()->m_scene->ruler()->distanceToTime(p.x());
+ float time = float(m_rowTimeline->rowTree()->m_scene->ruler()->distanceToTime(p.x()));
float value = (m_graphY - p.y()) / m_valScale;
adjustColorProperty(value, false);
@@ -347,32 +347,35 @@ void RowTimelinePropertyGraph::updateBezierControlValue(TimelineControlType cont
m_animCore->GetKeyframes(anim, keyframeHandles);
for (size_t i = 0; i < keyframeHandles.size(); ++i) {
if (keyframeHandles[i] == m_pressedKeyframeHandle) {
- 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;
+ float currKfTime = float(getKeyframeTime(m_animCore->GetKeyframeData(
+ keyframeHandles[i])));
+ // FLT_MAX is divided by 2 so that it doesn't cause an overflow in the calculations
+ // below
+ float prevKfTime = i > 0
+ ? float(getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i - 1])))
+ : -FLT_MAX / 2.f;
+ float nextKfTime = i < keyframeHandles.size() - 1.f
+ ? float(getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i + 1])))
+ : FLT_MAX / 2.f;
if (isBezierIn) {
if (time < prevKfTime)
time = prevKfTime;
- if (!CHotKeys::isCtrlDown() && time < currKfTime * 2 - nextKfTime)
- time = currKfTime * 2 - nextKfTime;
+ if (!CHotKeys::isCtrlDown() && time < currKfTime * 2.f - nextKfTime)
+ time = currKfTime * 2.f - nextKfTime;
} else { // bezier out
if (time > nextKfTime)
time = nextKfTime;
- if (!CHotKeys::isCtrlDown() && time > currKfTime * 2 - prevKfTime)
- time = currKfTime * 2 - prevKfTime;
+ if (!CHotKeys::isCtrlDown() && time > currKfTime * 2.f - prevKfTime)
+ time = currKfTime * 2.f - prevKfTime;
}
break;
}
}
- long &currHandleTime = isBezierIn ? kf.m_InTangentTime : kf.m_OutTangentTime;
+ float &currHandleTime = isBezierIn ? kf.m_InTangentTime : kf.m_OutTangentTime;
float &currHandleValue = isBezierIn ? kf.m_InTangentValue : kf.m_OutTangentValue;
- long &otherHandleTime = isBezierIn ? kf.m_OutTangentTime : kf.m_InTangentTime;
+ float &otherHandleTime = isBezierIn ? kf.m_OutTangentTime : kf.m_InTangentTime;
float &otherHandleValue = isBezierIn ? kf.m_OutTangentValue : kf.m_InTangentValue;
currHandleTime = time;