summaryrefslogtreecommitdiffstats
path: root/src/Viewer
diff options
context:
space:
mode:
Diffstat (limited to 'src/Viewer')
-rw-r--r--src/Viewer/qmlviewer/Qt3DSRenderer.cpp17
-rw-r--r--src/Viewer/qmlviewer/Qt3DSView.cpp2
-rw-r--r--src/Viewer/studio3d/q3dscommandqueue.cpp42
-rw-r--r--src/Viewer/studio3d/q3dscommandqueue_p.h13
-rw-r--r--src/Viewer/studio3d/q3dspresentation.cpp20
-rw-r--r--src/Viewer/studio3d/q3dspresentation.h2
6 files changed, 85 insertions, 11 deletions
diff --git a/src/Viewer/qmlviewer/Qt3DSRenderer.cpp b/src/Viewer/qmlviewer/Qt3DSRenderer.cpp
index 9b7d6e0b..35b3da71 100644
--- a/src/Viewer/qmlviewer/Qt3DSRenderer.cpp
+++ b/src/Viewer/qmlviewer/Qt3DSRenderer.cpp
@@ -138,7 +138,7 @@ void Q3DSRenderer::render()
m_initialized = initializeRuntime(this->framebufferObject());
m_initializationFailure = !m_initialized;
if (m_initializationFailure)
- m_commands.clear();
+ m_commands.clear(true);
}
// Don't render if the plugin is hidden; however, if hidden, but sure
@@ -249,7 +249,7 @@ void Q3DSRenderer::onUpdateHandler(void *userData)
void Q3DSRenderer::processCommands()
{
if (!m_runtime) {
- m_commands.clear();
+ m_commands.clear(true);
return;
}
@@ -279,7 +279,7 @@ void Q3DSRenderer::processCommands()
// Send scene graph changes over to Q3DS
for (int i = 0; i < m_commands.size(); i++) {
- const ElementCommand &cmd = m_commands.commandAt(i);
+ const ElementCommand &cmd = m_commands.constCommandAt(i);
switch (cmd.m_commandType) {
case CommandType_SetAttribute:
m_presentation->setAttribute(cmd.m_elementPath, cmd.m_stringValue, cmd.m_variantValue);
@@ -328,6 +328,15 @@ void Q3DSRenderer::processCommands()
m_runtime->SetDataInputValue(cmd.m_stringValue, cmd.m_variantValue,
static_cast<Q3DSDataInput::ValueRole>(cmd.m_intValues[0]));
break;
+ case CommandType_CreateElement: {
+ m_runtime->createElement(cmd.m_elementPath, cmd.m_stringValue,
+ *static_cast<QHash<QString, QVariant> *>(cmd.m_data));
+ // Runtime makes copy of the data in its own format, so we can delete it now
+ auto &command = m_commands.commandAt(i);
+ delete reinterpret_cast<QHash<QString, QVariant> *>(command.m_data);
+ command.m_data = nullptr;
+ break;
+ }
case CommandType_RequestSlideInfo: {
int current = 0;
int previous = 0;
@@ -368,7 +377,7 @@ void Q3DSRenderer::processCommands()
}
}
- m_commands.clear();
+ m_commands.clear(false);
}
QT_END_NAMESPACE
diff --git a/src/Viewer/qmlviewer/Qt3DSView.cpp b/src/Viewer/qmlviewer/Qt3DSView.cpp
index e7b90056..f5abb3e1 100644
--- a/src/Viewer/qmlviewer/Qt3DSView.cpp
+++ b/src/Viewer/qmlviewer/Qt3DSView.cpp
@@ -252,7 +252,7 @@ void Q3DSView::getCommands(bool emitInitialize, CommandQueue &renderQueue)
m_emitRunningChange = true;
renderQueue.copyCommands(m_pendingCommands);
- m_pendingCommands.clear();
+ m_pendingCommands.clear(false);
}
void Q3DSView::mousePressEvent(QMouseEvent *event)
diff --git a/src/Viewer/studio3d/q3dscommandqueue.cpp b/src/Viewer/studio3d/q3dscommandqueue.cpp
index 2bc540af..71220410 100644
--- a/src/Viewer/studio3d/q3dscommandqueue.cpp
+++ b/src/Viewer/studio3d/q3dscommandqueue.cpp
@@ -28,6 +28,7 @@
****************************************************************************/
#include "q3dscommandqueue_p.h"
+#include "q3dspresentation.h"
ElementCommand::ElementCommand()
: m_commandType(CommandType_Invalid)
@@ -146,6 +147,19 @@ ElementCommand &CommandQueue::queueCommand(const QString &elementPath,
return cmd;
}
+ElementCommand &CommandQueue::queueCommand(const QString &elementPath, CommandType commandType,
+ const QString &stringValue, void *commandData)
+{
+ ElementCommand &cmd = nextFreeCommand();
+
+ cmd.m_commandType = commandType;
+ cmd.m_elementPath = elementPath;
+ cmd.m_stringValue = stringValue;
+ cmd.m_data = commandData;
+
+ return cmd;
+}
+
ElementCommand &CommandQueue::queueRequest(const QString &elementPath, CommandType commandType)
{
ElementCommand &cmd = nextFreeCommand();
@@ -156,7 +170,7 @@ ElementCommand &CommandQueue::queueRequest(const QString &elementPath, CommandTy
return cmd;
}
-void CommandQueue::copyCommands(const CommandQueue &fromQueue)
+void CommandQueue::copyCommands(CommandQueue &fromQueue)
{
m_visibleChanged = m_visibleChanged || fromQueue.m_visibleChanged;
m_scaleModeChanged = m_scaleModeChanged || fromQueue.m_scaleModeChanged;
@@ -191,7 +205,7 @@ void CommandQueue::copyCommands(const CommandQueue &fromQueue)
// Pending queue may be synchronized multiple times between queue processing, so let's append
// to the existing queue rather than clearing it.
for (int i = 0; i < fromQueue.m_size; i++) {
- const ElementCommand &source = fromQueue.commandAt(i);
+ const ElementCommand &source = fromQueue.constCommandAt(i);
switch (source.m_commandType) {
case CommandType_SetDataInputValue:
queueCommand(source.m_elementPath, source.m_commandType, source.m_stringValue,
@@ -225,6 +239,11 @@ void CommandQueue::copyCommands(const CommandQueue &fromQueue)
source.m_intValues[0], source.m_intValues[1],
source.m_intValues[2], source.m_intValues[3]);
break;
+ case CommandType_CreateElement:
+ queueCommand(source.m_elementPath, source.m_commandType, source.m_stringValue,
+ source.m_data);
+ fromQueue.commandAt(i).m_data = nullptr; // This queue takes ownership of data
+ break;
case CommandType_RequestSlideInfo:
case CommandType_UnloadSlide:
case CommandType_PreloadSlide:
@@ -241,7 +260,7 @@ void CommandQueue::copyCommands(const CommandQueue &fromQueue)
}
// Clears changed states and empties the queue
-void CommandQueue::clear()
+void CommandQueue::clear(bool deleteCommandData)
{
m_visibleChanged = false;
m_scaleModeChanged = false;
@@ -253,6 +272,23 @@ void CommandQueue::clear()
m_globalAnimationTimeChanged = false;
m_delayedLoadingChanged = false;
+ if (deleteCommandData) {
+ for (int i = 0; i < m_size; ++i) {
+ ElementCommand &cmd = m_elementCommands[i];
+ if (cmd.m_data) {
+ switch (cmd.m_commandType) {
+ case CommandType_CreateElement:
+ delete static_cast<QHash<QString, QVariant> *>(cmd.m_data);
+ break;
+ default:
+ Q_ASSERT(false); // Should never come here
+ break;
+ }
+ cmd.m_data = nullptr;
+ }
+ }
+ }
+
// We do not clear the actual queued commands, those will be reused the next frame
// To avoid a lot of unnecessary reallocations.
m_size = 0;
diff --git a/src/Viewer/studio3d/q3dscommandqueue_p.h b/src/Viewer/studio3d/q3dscommandqueue_p.h
index 27612bfb..533f61ed 100644
--- a/src/Viewer/studio3d/q3dscommandqueue_p.h
+++ b/src/Viewer/studio3d/q3dscommandqueue_p.h
@@ -68,6 +68,9 @@ enum CommandType {
CommandType_KeyRelease,
CommandType_SetGlobalAnimationTime,
CommandType_SetDataInputValue,
+ CommandType_CreateElement,
+
+ // Requests
CommandType_RequestSlideInfo,
CommandType_RequestDataInputs,
CommandType_PreloadSlide,
@@ -83,6 +86,7 @@ public:
QString m_elementPath;
QString m_stringValue;
QVariant m_variantValue;
+ void *m_data = nullptr; // Data is owned by the queue and is deleted once command is handled
union {
bool m_boolValue;
float m_floatValue;
@@ -114,9 +118,11 @@ public:
ElementCommand &queueCommand(const QString &elementPath, CommandType commandType,
int value0, int value1 = 0,
int value2 = 0, int value3 = 0);
+ ElementCommand &queueCommand(const QString &elementPath, CommandType commandType,
+ const QString &stringValue, void *commandData);
ElementCommand &queueRequest(const QString &elementPath, CommandType commandType);
- void copyCommands(const CommandQueue &fromQueue);
+ void copyCommands(CommandQueue &fromQueue);
bool m_visibleChanged;
bool m_scaleModeChanged;
@@ -138,9 +144,10 @@ public:
qint64 m_globalAnimationTime;
bool m_delayedLoading;
- void clear();
+ void clear(bool deleteCommandData);
int size() const { return m_size; }
- const ElementCommand &commandAt(int index) const { return m_elementCommands.at(index); }
+ const ElementCommand &constCommandAt(int index) const { return m_elementCommands.at(index); }
+ ElementCommand &commandAt(int index) { return m_elementCommands[index]; }
private:
ElementCommand &nextFreeCommand();
diff --git a/src/Viewer/studio3d/q3dspresentation.cpp b/src/Viewer/studio3d/q3dspresentation.cpp
index f4235456..362c2803 100644
--- a/src/Viewer/studio3d/q3dspresentation.cpp
+++ b/src/Viewer/studio3d/q3dspresentation.cpp
@@ -274,6 +274,26 @@ void Q3DSPresentation::setDataInputValue(const QString &name, const QVariant &va
}
}
+/**
+ Adds a new child element for the element specified by parentElementPath to the slide specified with
+ slideName. Only model element creation is currently supported.
+ A referenced material element is also created for the new model element. The source material name
+ can be specified with custom "material" property in the properties hash.
+ The source material must exist in the material container of the presentation.
+*/
+void Q3DSPresentation::createElement(const QString &parentElementPath, const QString &slideName,
+ const QHash<QString, QVariant> &properties)
+{
+ if (d_ptr->m_viewerApp) {
+ d_ptr->m_viewerApp->createElement(parentElementPath, slideName, properties);
+ } else if (d_ptr->m_commandQueue) {
+ // We need to copy the properties map as queue takes ownership of it
+ QHash<QString, QVariant> *theProperties = new QHash<QString, QVariant>(properties);
+ d_ptr->m_commandQueue->queueCommand(parentElementPath, CommandType_CreateElement,
+ slideName, theProperties);
+ }
+}
+
void Q3DSPresentation::mousePressEvent(QMouseEvent *e)
{
if (d_ptr->m_viewerApp) {
diff --git a/src/Viewer/studio3d/q3dspresentation.h b/src/Viewer/studio3d/q3dspresentation.h
index 34809613..97f7b6fc 100644
--- a/src/Viewer/studio3d/q3dspresentation.h
+++ b/src/Viewer/studio3d/q3dspresentation.h
@@ -83,6 +83,8 @@ public:
void keyPressEvent(QKeyEvent *e);
void keyReleaseEvent(QKeyEvent *e);
+ void createElement(const QString &parentElementPath, const QString &slideName,
+ const QHash<QString, QVariant> &properties);
public Q_SLOTS:
void setSource(const QUrl &source);
void setVariantList(const QStringList &variantList);