diff options
4 files changed, 26 insertions, 5 deletions
diff --git a/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.cpp b/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.cpp index 611daef1..c07922cb 100644 --- a/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.cpp +++ b/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.cpp @@ -763,13 +763,19 @@ void Q3DSPresentation::setDataInputValue(const QString &name, const QVariant &va element. The property names are the same the setAttribute() recognizes. A referenced material element is also created for the new model element. The source material - name can be specified with custom "material" attribute in the \a attributes hash. + name can be specified with custom "material" attribute in the \a properties hash. The source material must exist in the same presentation where the element is created. The mesh for a model is specified with the \c sourcepath property. This can be a local file path to \c .mesh file, a studio mesh primitive (e.g. \c{#Cube}), or the name of a mesh created dynamically with createMesh(). + A property/properties of the element can be bound to be controlled by an existing datainput. + Control bindings can be indicated with custom "controlledproperty" attribute in the + \a properties hash. The format for attribute value is "$<datainputname> <attributename>", i.e. + "$Datainput_1 rotation $Datainput_2 diffusecolor". If datainput name does not match with + any of the datainputs defined in UIA file, binding has no impact. + The element is ready for use once elementsCreated() signal is received for it. \sa createElements @@ -777,6 +783,7 @@ void Q3DSPresentation::setDataInputValue(const QString &name, const QVariant &va \sa createMesh \sa elementsCreated \sa setAttribute + \sa dataInputs */ void Q3DSPresentation::createElement(const QString &parentElementPath, const QString &slideName, const QHash<QString, QVariant> &properties) diff --git a/src/Runtime/ogl-runtime/src/runtime/Qt3DSQmlEngine.cpp b/src/Runtime/ogl-runtime/src/runtime/Qt3DSQmlEngine.cpp index 3e741b39..ac958ea7 100644 --- a/src/Runtime/ogl-runtime/src/runtime/Qt3DSQmlEngine.cpp +++ b/src/Runtime/ogl-runtime/src/runtime/Qt3DSQmlEngine.cpp @@ -473,7 +473,8 @@ private: void createComponent(QQmlComponent *component, TElement *element); TElement *getTarget(const char *component); void listAllElements(TElement *root, QList<TElement *> &elements); - void initializeDataInputsInPresentation(CPresentation &presentation, bool isPrimary); + void initializeDataInputsInPresentation(CPresentation &presentation, bool isPrimary, + QList<TElement *> inElements = QList<TElement *>()); void initializeDataOutputsInPresentation(CPresentation &presentation, bool isPrimary); // Splits down vector attributes to components as Runtime does not really // handle vectors at this level anymore @@ -1234,6 +1235,9 @@ void CQmlEngineImpl::createElements(const QString &parentElementPath, const QStr createdElements << &newElem; } + bool isPrimary = presentation == m_Application->GetPrimaryPresentation() ? true : false; + initializeDataInputsInPresentation(*presentation, isPrimary, createdElements.toList()); + renderer->ChildrenUpdated(parentObject); handleError(); @@ -2023,12 +2027,19 @@ void CQmlEngineImpl::listAllElements(TElement *root, QList<TElement *> &elements } } +// Initializes datainput bindings in the presentation starting by default from the root element. +// If inElements is specified, only parses the specified elements. void CQmlEngineImpl::initializeDataInputsInPresentation(CPresentation &presentation, - bool isPrimary) + bool isPrimary, + QList<TElement *> inElements) { - TElement *parent = presentation.GetRoot(); QList<TElement *> elements; - listAllElements(parent, elements); + if (!inElements.empty()) { + elements = inElements; + } else { + TElement *parent = presentation.GetRoot(); + listAllElements(parent, elements); + } qt3ds::runtime::DataInputMap &diMap = m_Application->dataInputMap(); // #TODO: Remove below once QT3DS-3510 has been implemented in the editor diff --git a/tests/auto/viewer/tst_qt3dsviewer.cpp b/tests/auto/viewer/tst_qt3dsviewer.cpp index d38e0207..c9787fdb 100644 --- a/tests/auto/viewer/tst_qt3dsviewer.cpp +++ b/tests/auto/viewer/tst_qt3dsviewer.cpp @@ -226,6 +226,7 @@ void tst_qt3dsviewer::testCreateElement() data.insert(QStringLiteral("position"), QVariant::fromValue<QVector3D>(QVector3D(200, 300, 200))); data.insert(QStringLiteral("opacity"), 20.0); + data.insert(QStringLiteral("controlledproperty"), QStringLiteral("@newDataInput opacity")); createElement(QStringLiteral("Scene.Layer"), QStringLiteral("Slide1"), data); @@ -247,6 +248,7 @@ void tst_qt3dsviewer::testCreateElement() newCylinder2.setAttribute(QStringLiteral("position.y"), animValue * 3); newSphere.setAttribute(QStringLiteral("position.x"), 50 + animValue * 2); newGroup.setAttribute(QStringLiteral("opacity"), qAbs(animValue)); + m_presentation->setDataInputValue(QStringLiteral("newDataInput"), qAbs(animValue / 2)); }); // Create objects to slides 1 & 2 while slide 1 is executing diff --git a/tests/scenes/simple_cube_animation/simple_cube_animation.uia b/tests/scenes/simple_cube_animation/simple_cube_animation.uia index 46dbf70e..ca2d770f 100644 --- a/tests/scenes/simple_cube_animation/simple_cube_animation.uia +++ b/tests/scenes/simple_cube_animation/simple_cube_animation.uia @@ -2,6 +2,7 @@ <application xmlns="http://qt.io/qt3dstudio/uia"> <assets initial="simple_cube_animation"> <presentation id="simple_cube_animation" src="presentations/simple_cube_animation.uip"/> + <dataInput metadata="" name="newDataInput" type="Float"/> </assets> <statemachine ref="#logic"> <visual-states> |