diff options
author | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2020-06-29 10:09:05 +0300 |
---|---|---|
committer | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2020-06-29 10:10:02 +0300 |
commit | c08ef9bc1772d98f675a5a51b3105af123b187cd (patch) | |
tree | 8dce7fd9c74c93be322909c5318ecca1d8e2184b | |
parent | 8065d16d4b63d428aa712e8d83848898e3054184 (diff) | |
parent | 99a88653cd29f95cb2e3f770bf0599e758a03c05 (diff) |
Merge remote-tracking branch 'origin/2.7'
Change-Id: I86e5766624fecb436157f6f44393bea36cd99c82
22 files changed, 375 insertions, 54 deletions
diff --git a/doc/src/07-file-formats/custom-materials-effects.qdoc b/doc/src/07-file-formats/custom-materials-effects.qdoc index 646245ca..66f5d8e7 100644 --- a/doc/src/07-file-formats/custom-materials-effects.qdoc +++ b/doc/src/07-file-formats/custom-materials-effects.qdoc @@ -170,6 +170,13 @@ A \c{property} element can have the following attributes: \li Text \li - \li Creates UI dropdown list. +\row + \li category + \li Text + \li + \li Use to group material properties into separate categories. \note Required field for + materials. If this is not added, the property will not be displayed in the Inspector palette. + Adding category with empty string will not suffice. \endtable The only required attribute in the \c{<property>} element is \c{name}. @@ -340,4 +347,71 @@ The element attributes are: \li Specifies if depth is written or not. With "true" depth is written, with "false" it's not. \endtable +\section1 Things to Note + +\section2 Materials +When creating a custom material with several properties, it is a good practice to use categories +to separate them. If there is a need to be able to change the material for the mesh, at least one +property needs to be added to \b Materials category. This will pull in \b {Material Type} and +\b Shader properties into the Inspector palette. + +Consider a custom material with the following metadata: +\badcode + <MetaData > + <Property category="ExampleMaterial" formalName="Environment Map" name="uEnvironmentTexture" description="Environment texture for the material" type="Texture" filter="linear" minfilter="linearMipmapLinear" clamp="repeat" usage="environment" default="./maps/materials/spherical_checker.png"/> + <Property category="ExampleMaterial" formalName="Enable Environment" name="uEnvironmentMappingEnabled" description="Enable environment mapping" type="Boolean" default="True"/> + <Property category="ExampleMaterial" formalName="Baked Shadow Map" name="uBakedShadowTexture" description="Baked shadow texture for the material" type="Texture" filter="linear" minfilter="linearMipmapLinear" clamp="repeat" usage="shadow" default="./maps/materials/shadow.png"/> + <Property category="ExampleMaterial" formalName="Shadow Mapping" name="uShadowMappingEnabled" description="Enable shadow mapping" type="Boolean" default="False"/> + <Property category="ExampleMaterial" formalName="Roughness" name="roughness" type="Float" min="0.0" max="1.0" default="0.3" description="Roughness of the material.\n0 = fully specular\n1 = fully diffuse"/> + <Property category="ExampleMaterial" formalName="Base color" name="base_color" type="Color" default="0.7 0.7 0.7" description="Color of the material"/> + </MetaData> +\endcode +and the same material with sensible categories defined, including \b {Material}: +\badcode + <MetaData > + <Property category="Environment" formalName="Environment Map" name="uEnvironmentTexture" description="Environment texture for the material" type="Texture" filter="linear" minfilter="linearMipmapLinear" clamp="repeat" usage="environment" default="./maps/materials/spherical_checker.png"/> + <Property category="Environment" formalName="Enable Environment" name="uEnvironmentMappingEnabled" description="Enable environment mapping" type="Boolean" default="True"/> + <Property category="Shadow" formalName="Baked Shadow Map" name="uBakedShadowTexture" description="Baked shadow texture for the material" type="Texture" filter="linear" minfilter="linearMipmapLinear" clamp="repeat" usage="shadow" default="./maps/materials/shadow.png"/> + <Property category="Shadow" formalName="Shadow Mapping" name="uShadowMappingEnabled" description="Enable shadow mapping" type="Boolean" default="False"/> + <Property category="Material" formalName="Roughness" name="roughness" type="Float" min="0.0" max="1.0" default="0.3" description="Roughness of the material.\n0 = fully specular\n1 = fully diffuse"/> + <Property category="Material" formalName="Base color" name="base_color" type="Color" default="0.7 0.7 0.7" description="Color of the material"/> + </MetaData> +\endcode + +The first option results in +\image materials-category-dummy.png +and the seconds one results in +\image materials-category-several.png + +\section2 Controlling Custom Properties +When some of the properties in custom materials or effects need to be adjusted during run-time, +the \c setAttribute API is required. The usage may differ slightly from normal usage, depending on +the property being controlled, as all of the properties in custom materials and effects are handled +as dynamic properties. +For example, a texture is not handled as an image like it is when controlling it in standard +material. +\section3 Controlling a texture in standard material +\badcode +<presentation id>.setAttribute("<element path to texture>", "sourcepath", "<path to image>"); +\endcode +For example: +\badcode +myPresentation.setAttribute("Scene.Layer.Sphere.Default_animatable.diffusemap", "sourcepath", "../maps/myTexture.png"); +\endcode +\section3 Controlling a texture in a custom material +\badcode +<presentation id>.setAttribute("<element path to material>", "<texture property name>", "<path to image>"); +\endcode +With a material that has a metadata entry as follows: +\badcode +<MetaData > + ... + <Property name="diffuseTexture" type="Texture" category="Material" formalName="Diffuse texture"/> + ... +</MetaData> +\endcode +This is the way to control it: +\badcode +myPresentation.setAttribute("Scene.Layer.Sphere.MyMaterial_animatable", "diffuseTexture", "../maps/myTexture.png"); +\endcode */ diff --git a/doc/Src/10-best-practices/exporting-from-3dsmax.qdoc b/doc/src/10-best-practices/exporting-from-3dsmax.qdoc index 79754adc..79754adc 100644 --- a/doc/Src/10-best-practices/exporting-from-3dsmax.qdoc +++ b/doc/src/10-best-practices/exporting-from-3dsmax.qdoc diff --git a/doc/Src/10-best-practices/exporting-from-blender.qdoc b/doc/src/10-best-practices/exporting-from-blender.qdoc index 528dcbad..528dcbad 100644 --- a/doc/Src/10-best-practices/exporting-from-blender.qdoc +++ b/doc/src/10-best-practices/exporting-from-blender.qdoc diff --git a/doc/Src/10-best-practices/exporting-from-maya.qdoc b/doc/src/10-best-practices/exporting-from-maya.qdoc index 10d1525b..10d1525b 100644 --- a/doc/Src/10-best-practices/exporting-from-maya.qdoc +++ b/doc/src/10-best-practices/exporting-from-maya.qdoc diff --git a/doc/Src/10-best-practices/exporting-from-modo.qdoc b/doc/src/10-best-practices/exporting-from-modo.qdoc index b8c34f77..b8c34f77 100644 --- a/doc/Src/10-best-practices/exporting-from-modo.qdoc +++ b/doc/src/10-best-practices/exporting-from-modo.qdoc diff --git a/doc/src/images/materials-category-dummy.png b/doc/src/images/materials-category-dummy.png Binary files differnew file mode 100644 index 00000000..5e66e737 --- /dev/null +++ b/doc/src/images/materials-category-dummy.png diff --git a/doc/src/images/materials-category-several.png b/doc/src/images/materials-category-several.png Binary files differnew file mode 100644 index 00000000..5ef32fb3 --- /dev/null +++ b/doc/src/images/materials-category-several.png diff --git a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp index 9ef85efd..202736d8 100644 --- a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp +++ b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp @@ -2156,7 +2156,8 @@ public: } const QFileInfo fileInfo(file); - writeProperty(file, QStringLiteral("path"), fileInfo.absoluteFilePath()); + writeProperty(file, QStringLiteral("path"), + projDir.relativeFilePath(fileInfo.absoluteFilePath())); QMapIterator<QString, Qt3DSDMInstanceHandle> i(textureHandles); while (i.hasNext()) { @@ -4265,6 +4266,15 @@ public: m_DataCore.SetInstancePropertyValue(inDynamic, theInfo.m_Property, theRef); } } + } else if (theInfo.m_CompleteType == CompleteMetaDataType::Texture + && GetValueType(theInfo.m_DefaultValue) == DataModelDataType::String) { + SValue value; + m_DataCore.GetInstancePropertyValue(inDynamic, theInfo.m_Property, value); + // Set default value to the instance + if (!value.empty()) { + m_DataCore.SetInstancePropertyValue(inDynamicInstance, theInfo.m_Property, + value); + } } } } @@ -4568,6 +4578,8 @@ public: theParentInstance, inParent, inSlide, m_DataCore, m_SlideSystem, m_Bridge.GetObjectDefinitions(), m_AssetGraph, m_MetaData, inTargetId)); + ApplyDynamicMetaData(retval, theParentInstance); + if (inStartTime != -1) SetStartTime(retval, inStartTime); diff --git a/src/Authoring/Client/Code/Core/Utility/StudioPreferences.cpp b/src/Authoring/Client/Code/Core/Utility/StudioPreferences.cpp index 4402c916..f4157e7c 100644 --- a/src/Authoring/Client/Code/Core/Utility/StudioPreferences.cpp +++ b/src/Authoring/Client/Code/Core/Utility/StudioPreferences.cpp @@ -450,6 +450,19 @@ void CStudioPreferences::setHelperGridOn(bool showGrid) s_preferences.setValue(QStringLiteral("VisualAids/ShowHelperGrid"), showGrid); } +bool CStudioPreferences::isAxisHelperOn() +{ + return false; + // Disable axis helper (QT3DS-4122). To be re-enabled (QT3DS-4124), thoroughly tested + // and bugs fixed after 2.7 is released. + //return s_preferences.value(QStringLiteral("VisualAids/ShowAxisHelper"), true).toBool(); +} + +void CStudioPreferences::setAxisHelperOn(bool showAxisHelper) +{ + s_preferences.setValue(QStringLiteral("VisualAids/ShowAxisHelper"), showAxisHelper); +} + int CStudioPreferences::helperGridLines() { return s_preferences.value(QStringLiteral("VisualAids/HelperGridLines"), 10).toInt(); diff --git a/src/Authoring/Client/Code/Core/Utility/StudioPreferences.h b/src/Authoring/Client/Code/Core/Utility/StudioPreferences.h index 9ae55568..92a5787a 100644 --- a/src/Authoring/Client/Code/Core/Utility/StudioPreferences.h +++ b/src/Authoring/Client/Code/Core/Utility/StudioPreferences.h @@ -135,6 +135,9 @@ public: static int helperGridLines(); static void setHelperGridLines(int lines); + static void setAxisHelperOn(bool showAxisHelper); + static bool isAxisHelperOn(); + static int helperGridSpacing(); static void setHelperGridSpacing(int spacing); diff --git a/src/Authoring/Qt3DStudio/MainFrm.cpp b/src/Authoring/Qt3DStudio/MainFrm.cpp index 4fd0414d..377260c1 100644 --- a/src/Authoring/Qt3DStudio/MainFrm.cpp +++ b/src/Authoring/Qt3DStudio/MainFrm.cpp @@ -177,6 +177,7 @@ CMainFrame::CMainFrame() connect(m_ui->actionTooltips, &QAction::triggered, this, &CMainFrame::OnViewTooltips); connect(m_ui->actionHelper_Grid, &QAction::triggered, this, &CMainFrame::onHelperGrid); + connect(m_ui->actionAxis_Helper, &QAction::triggered, this, &CMainFrame::onAxisHelper); m_ui->actionHelper_Grid->setToolTip( m_ui->actionHelper_Grid->toolTip().arg( m_ui->actionHelper_Grid->shortcut().toString(QKeySequence::NativeText))); @@ -251,6 +252,10 @@ CMainFrame::CMainFrame() m_ui->actionToggle_hide_unhide_unselected->setVisible(false); m_ui->actionFind->setVisible(false); + // Hide axis helper (QT3DS-4122). To be re-enabled (QT3DS-4124), thoroughly tested and bugs + // fixed after 2.7 is released. + m_ui->actionAxis_Helper->setVisible(false); + // TODO: better solution? m_updateUITimer->start(500); connect(m_updateUITimer.data(), &QTimer::timeout, [&]() { @@ -272,6 +277,7 @@ CMainFrame::CMainFrame() OnUpdateViewWireframe(); OnUpdateViewTooltips(); onUpdateHelperGrid(); + onUpdateAxisHelper(); OnUpdateViewTimeline(); onUpdateViewSceneCamera(); OnUpdateViewInspector(); @@ -897,6 +903,7 @@ void CMainFrame::EditPreferences(short inPageIndex) CStudioPreferences::setWireframeModeOn(true); CStudioPreferences::setTooltipsOn(true); CStudioPreferences::setHelperGridOn(true); + CStudioPreferences::setAxisHelperOn(true); CStudioPreferences::setHelperGridLines(10); CStudioPreferences::setHelperGridSpacing(100); CStudioPreferences::setSelectorLineWidth( @@ -1676,11 +1683,21 @@ void CMainFrame::onUpdateHelperGrid() } } +void CMainFrame::onUpdateAxisHelper() +{ + m_ui->actionAxis_Helper->setChecked(CStudioPreferences::isAxisHelperOn()); +} + void CMainFrame::onHelperGrid() { CStudioPreferences::setHelperGridOn(!CStudioPreferences::isHelperGridOn()); } +void CMainFrame::onAxisHelper() +{ + CStudioPreferences::setAxisHelperOn(!CStudioPreferences::isAxisHelperOn()); +} + //============================================================================== /** * Called when the update message occurs for the Help->Help Topics menu item. diff --git a/src/Authoring/Qt3DStudio/MainFrm.h b/src/Authoring/Qt3DStudio/MainFrm.h index f25540ec..f1d2fdeb 100644 --- a/src/Authoring/Qt3DStudio/MainFrm.h +++ b/src/Authoring/Qt3DStudio/MainFrm.h @@ -174,6 +174,8 @@ public: void OnHelpIndex(); void OnHelpVisitQt(); void OnHelpOpenTutorial(); + void onUpdateAxisHelper(); + void onAxisHelper(); void onViewResetLayout(); void OnViewAction(); diff --git a/src/Authoring/Qt3DStudio/MainFrm.ui b/src/Authoring/Qt3DStudio/MainFrm.ui index 553659dc..9473052f 100644 --- a/src/Authoring/Qt3DStudio/MainFrm.ui +++ b/src/Authoring/Qt3DStudio/MainFrm.ui @@ -132,6 +132,7 @@ Project palette using Import functionality.</string> <addaction name="actionTooltips"/> <addaction name="actionFind"/> <addaction name="actionHelper_Grid"/> + <addaction name="actionAxis_Helper"/> <addaction name="actionRulers_Guides"/> <addaction name="actionLock_Guides"/> <addaction name="actionClear_Guides"/> @@ -1104,6 +1105,20 @@ Project palette using Import functionality.</string> <bool>false</bool> </property> </action> + <action name="actionAxis_Helper"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="checked"> + <bool>false</bool> + </property> + <property name="text"> + <string>Axis Helper</string> + </property> + <property name="toolTip"> + <string>Show world axis helper</string> + </property> + </action> </widget> <customwidgets> <customwidget> diff --git a/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.cpp b/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.cpp index aaeb7a89..5f72bdf0 100644 --- a/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.cpp +++ b/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.cpp @@ -447,6 +447,7 @@ void InspectorControlModel::setMatDatas(const std::vector<Q3DStudio::CFilePath> m_matDatas.clear(); const auto doc = g_StudioApp.GetCore()->GetDoc(); + bool forceModified = false; bool isDocModified = doc->isModified(); const auto sceneEditor = doc->getSceneEditor(); if (!sceneEditor) @@ -465,6 +466,8 @@ void InspectorControlModel::setMatDatas(const std::vector<Q3DStudio::CFilePath> const QString relativePath = path.toQString(); const Q3DStudio::CFilePath absolutePath = Q3DStudio::CFilePath::CombineBaseAndRelative(doc->GetDocumentDirectory(), path); + const QDir projDir = QDir(g_StudioApp.GetCore()->getProjectFile().getProjectPath()); + const QString projRelativePath = projDir.relativeFilePath(absolutePath.toQString()); QString name; QMap<QString, QString> values; @@ -477,19 +480,21 @@ void InspectorControlModel::setMatDatas(const std::vector<Q3DStudio::CFilePath> bool needRewrite = false; if (values.contains(QStringLiteral("path"))) { const QString oldPath = values[QStringLiteral("path")]; - needRewrite = oldPath != absolutePath.toQString(); - if (!QFileInfo(oldPath).exists()) { + needRewrite = oldPath != projRelativePath; + const QString oldAbsolutePath = projDir.absoluteFilePath(oldPath); + if (!QFileInfo(oldAbsolutePath).exists()) { const auto instance = sceneEditor->getMaterial(oldPath); if (instance.Valid()) { const QString oldName = sceneEditor->GetName(instance).toQString(); const QString newName = sceneEditor - ->getMaterialNameFromFilePath(relativePath); + ->getMaterialNameFromFilePath(projRelativePath); const QString actualPath = sceneEditor ->getFilePathFromMaterialName(oldName); - if (actualPath == oldPath) { + if (projDir.relativeFilePath(actualPath) == oldPath) { doc->queueMaterialRename(oldName, newName); Q3DStudio::SCOPED_DOCUMENT_EDITOR(*doc, tr("Set Name")) - ->setMaterialNameByPath(instance, relativePath); + ->setMaterialNameByPath(instance, projRelativePath); + forceModified = true; } } } @@ -526,7 +531,10 @@ void InspectorControlModel::setMatDatas(const std::vector<Q3DStudio::CFilePath> sceneEditor->removeDeletedFromMaterialContainer(); // Modified flag has to be restored because of the hidden transaction - doc->SetModifiedFlag(isDocModified); + if (!forceModified) + doc->SetModifiedFlag(isDocModified); + else + doc->SetModifiedFlag(true); m_cachedMatDatas = matDatas; } diff --git a/src/Authoring/Qt3DStudio/Render/StudioRenderer.cpp b/src/Authoring/Qt3DStudio/Render/StudioRenderer.cpp index 4ec63e19..92c660a1 100644 --- a/src/Authoring/Qt3DStudio/Render/StudioRenderer.cpp +++ b/src/Authoring/Qt3DStudio/Render/StudioRenderer.cpp @@ -93,7 +93,7 @@ struct SRendererImpl : public IStudioRenderer, public CToolbarChangeListener, public IOffscreenRenderer::IOffscreenRendererCallback { - typedef eastl::vector<Option<SEditCameraPersistentInformation>> TEditCameraInfoList; + typedef eastl::vector<Option<SEditorCameraInformation>> TEditCameraInfoList; std::shared_ptr<CWGLRenderContext> m_RenderContext; NVScopedRefCounted<IQt3DSRenderContext> m_Context; QRect m_Rect; @@ -109,7 +109,7 @@ struct SRendererImpl : public IStudioRenderer, bool m_MaybeDragStart; TEditCameraInfoList m_EditCameraInformation; QT3DSI32 m_EditCameraIndex; - SEditCameraPersistentInformation m_MouseDownCameraInformation; + SEditorCameraInformation m_MouseDownCameraInformation; SStudioPickValue m_PickResult; bool m_RenderRequested; int m_LastToolMode; @@ -378,12 +378,7 @@ struct SRendererImpl : public IStudioRenderer, m_Rect = inRect; if (IsInitialized()) { m_pixelRatio = StudioUtils::devicePixelRatio(); - m_RenderContext->BeginRender(); - NVRenderContext &theContext = m_RenderContext->GetRenderContext(); - theContext.SetViewport(qt3ds::render::NVRenderRect(0, 0, inRect.width(), - inRect.height())); SetTranslationViewport(); - m_RenderContext->EndRender(); } } @@ -695,11 +690,11 @@ struct SRendererImpl : public IStudioRenderer, while ((size_t)m_EditCameraIndex >= m_EditCameraInformation.size()) m_EditCameraInformation.push_back(Empty()); - Option<SEditCameraPersistentInformation> &theCameraInfo = + Option<SEditorCameraInformation> &theCameraInfo = m_EditCameraInformation[m_EditCameraIndex]; if (!theCameraInfo.hasValue()) { - theCameraInfo = SEditCameraPersistentInformation(); + theCameraInfo = SEditorCameraInformation(); // TODO - consider resizing clip planes to scene so we use the depth buffer more // accurately // or consider requesting a larger depth buffer from the windowing system. diff --git a/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.cpp b/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.cpp index e52d4011..590439f3 100644 --- a/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.cpp +++ b/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.cpp @@ -1966,6 +1966,11 @@ void STranslation::updateHelperGridFromSettings() } } +void STranslation::updateAxisHelperFromSettings() +{ + m_axisHelperEnabled = CStudioPreferences::isAxisHelperOn(); +} + qt3dsdm::Qt3DSDMInstanceHandle STranslation::GetAnchorPoint(SPathPick &inPick) { return GetAnchorPoint(inPick.m_AnchorIndex); @@ -1973,9 +1978,9 @@ qt3dsdm::Qt3DSDMInstanceHandle STranslation::GetAnchorPoint(SPathPick &inPick) namespace qt3ds { namespace studio { - struct SEditCameraLayerTranslator : public SLayerTranslator + struct SEditorLayerTranslator : public SLayerTranslator { - SEditCameraLayerTranslator(qt3dsdm::Qt3DSDMInstanceHandle inInstance, + SEditorLayerTranslator(qt3dsdm::Qt3DSDMInstanceHandle inInstance, qt3ds::NVAllocatorCallback &inAlloc) : SLayerTranslator(inInstance, inAlloc) { @@ -2016,6 +2021,7 @@ STranslation::STranslation(IStudioRenderer &inRenderer, IQt3DSRenderContext &inC , m_EditLightEnabled(false) , m_Viewport(0, 0) , m_EditCameraLayerTranslator(nullptr) + , m_AxisHelperLayerTranslator(nullptr) , m_PixelBuffer(inContext.GetAllocator(), "STranslation::m_PixelBuffer") , m_editModeCamerasAndLights(inContext.GetAllocator(), "STranslation::m_editModeCamerasAndLights") @@ -2090,6 +2096,51 @@ void STranslation::BuildRenderGraph(SGraphObjectTranslator &inParent, bool scene { SGraphObjectTranslator &theParentTranslator(inParent); theParentTranslator.ClearChildren(); + + updateAxisHelperFromSettings(); + if (theParentTranslator.GetGraphObject().m_Type == GraphObjectTypes::Scene && + m_axisHelperEnabled && !scenePreviewPass) { + if (m_AxisHelperLayerTranslator && m_AxisHelperLayerTranslator->GetInstanceHandle() + != inParent.GetInstanceHandle()) { + QT3DS_FREE(m_Allocator, m_AxisHelperLayerTranslator); + m_AxisHelperLayerTranslator = nullptr; + } + if (!m_AxisHelperLayerTranslator) { + m_AxisHelperLayerTranslator = + QT3DS_NEW(m_Allocator, SEditorLayerTranslator)(inParent.GetInstanceHandle(), m_Allocator); + SLayer &layer = static_cast<SLayer &>(m_AxisHelperLayerTranslator->GetGraphObject()); + layer.m_Background = LayerBackground::Color; + static const QT3DSVec4 matteColor(CStudioPreferences::matteColor().redF(), + CStudioPreferences::matteColor().greenF(), + CStudioPreferences::matteColor().blueF(), 0.5f); + layer.m_ClearColor = m_EditCameraEnabled ? QT3DSVec4(0, 0, 0, 0.5) : matteColor; + layer.m_LeftUnits = LayerUnitTypes::Pixels; + layer.m_RightUnits = LayerUnitTypes::Pixels; + layer.m_HeightUnits = LayerUnitTypes::Pixels; + layer.m_WidthUnits = LayerUnitTypes::Pixels; + layer.m_TopUnits = LayerUnitTypes::Pixels; + layer.m_BottomUnits = LayerUnitTypes::Pixels; + layer.m_HorizontalFieldValues = HorizontalFieldValues::LeftWidth; + layer.m_VerticalFieldValues = VerticalFieldValues::HeightBottom; + float pixelRatio = float(StudioUtils::devicePixelRatio()); + layer.m_Top = 10 * pixelRatio; + layer.m_Left = 10 * pixelRatio; + layer.m_Right = 10 * pixelRatio; + layer.m_Bottom = 10 * pixelRatio; + layer.m_Width = 120 * pixelRatio; + layer.m_Height = 120 * pixelRatio; + layer.m_Flags.SetDirty(true); + m_AxisCamera.m_Id = m_Context.GetStringTable().RegisterStr("AxisCamera"); + } + theParentTranslator.AppendChild(m_AxisHelperLayerTranslator->GetGraphObject()); + BuildRenderGraph(*m_AxisHelperLayerTranslator, scenePreviewPass); + SLayer &layer = static_cast<SLayer &>(m_AxisHelperLayerTranslator->GetGraphObject()); + layer.m_NextSibling = layer.m_PreviousSibling = nullptr; + m_AxisHelperLayerTranslator->SetActive(true); + m_AxisHelperLayerTranslator->AppendChild(m_AxisCamera); + m_AxisCamera.m_Flags.SetActive(true); + } + if (m_EditCameraEnabled && !scenePreviewPass) { const auto objectType = theParentTranslator.GetGraphObject().m_Type; if (objectType == GraphObjectTypes::Layer) { @@ -2132,7 +2183,7 @@ void STranslation::BuildRenderGraph(SGraphObjectTranslator &inParent, bool scene } if (!m_EditCameraLayerTranslator) { m_EditCameraLayerTranslator = - QT3DS_NEW(m_Allocator, SEditCameraLayerTranslator)(theChild, + QT3DS_NEW(m_Allocator, SEditorLayerTranslator)(theChild, m_Allocator); } theTranslator = m_EditCameraLayerTranslator; @@ -2267,6 +2318,26 @@ void STranslation::PreRender(bool scenePreviewPass) m_EditLight.MarkDirty(qt3ds::render::NodeTransformDirtyFlag::TransformIsDirty); updateHelperGridFromSettings(); } + if (m_axisHelperEnabled && !scenePreviewPass) { + if (m_EditCameraEnabled) { + m_EditCameraInfo.ApplyToCamera(m_AxisCamera, theViewportDims, true); + } else { + // Get scene camera + SLayerTranslator *layerTranslator = static_cast<SLayerTranslator *>(GetOrCreateTranslator(m_Doc.GetActiveLayer())); + SNode *layerNode = static_cast<SNode *>(layerTranslator->m_GraphObject); + for (SNode *child = layerNode->m_FirstChild; child; child = child->m_NextSibling) { + if (child->m_Type == GraphObjectTypes::Enum::Camera) { + m_AxisCamera = *(SCamera *)child; + m_AxisCamera.m_Parent = (SNode *)&m_AxisHelperLayerTranslator->GetGraphObject(); + m_AxisCamera.m_NextSibling = nullptr; + m_AxisCamera.m_PreviousSibling = nullptr; + m_AxisCamera.m_FirstChild = nullptr; + m_AxisCamera.m_PreviousSibling = nullptr; + break; + } + } + } + } if (m_Scene) { CStudioProjectSettings *theSettings = m_Doc.GetCore()->GetStudioProjectSettings(); @@ -2742,14 +2813,28 @@ void STranslation::Render(int inWidgetId, bool inDrawGuides, bool scenePreviewPa } } } - Option<NVRenderRect> viewport = m_Context.GetRenderContext().GetViewport(); + + if (!m_AxisHelperWidget ) { + m_AxisHelperWidget + = qt3ds::widgets::IStudioWidget::CreateTranslationWidget( + m_Context.GetAllocator()); + m_AxisHelperWidget->setAsAxisHelper(true); + } + + auto layer = GetAxisHelperLayer(); + if (layer != nullptr) { + updateAxisHelperFromSettings(); + m_AxisHelperWidget->SetNode(*layer); + if (m_axisHelperEnabled) + m_Context.GetRenderer().AddRenderWidget(*m_AxisHelperWidget); + } + if (scenePreviewPass) { m_Context.GetRenderContext().SetViewport(GetPreviewViewport()); m_Context.SetSceneColor(Option<QT3DSVec4>()); } - m_Scene->PrepareForRender(scenePreviewPass ? GetPreviewViewportDimensions() - : GetViewportDimensions(), m_Context); + m_Scene->PrepareForRender(m_Context); m_Context.RunRenderTasks(); @@ -2895,14 +2980,6 @@ void STranslation::Render(int inWidgetId, bool inDrawGuides, bool scenePreviewPa m_Context.GetRenderContext().SetRenderTarget(nullptr); m_Context.EndFrame(); - m_Context.GetRenderContext().SetViewport(viewport); - QT3DSVec2 theViewportDims(GetViewportDimensions()); - m_Context.SetWindowDimensions(QSize((QT3DSU32)theViewportDims.x, - (QT3DSU32)theViewportDims.y)); - CStudioProjectSettings *theSettings = m_Doc.GetCore()->GetStudioProjectSettings(); - QSize thePresSize = theSettings->getPresentationSize(); - m_Presentation.m_PresentationDimensions = - QT3DSVec2((QT3DSF32)thePresSize.width(), (QT3DSF32)thePresSize.height()); if (m_ZoomRender.hasValue()) { RenderZoomRender(*m_ZoomRender); @@ -4177,6 +4254,13 @@ SNode *STranslation::GetEditCameraLayer() return nullptr; } +SNode *STranslation::GetAxisHelperLayer() +{ + if (m_AxisHelperLayerTranslator) + return static_cast<SNode *>(&m_AxisHelperLayerTranslator->GetGraphObject()); + return nullptr; +} + PickTargetAreas::Enum STranslation::GetPickArea(CPt inPoint) { qt3ds::render::NVRenderRectF displayViewport = m_Context.GetDisplayViewport(); diff --git a/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.h b/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.h index f615664a..ed7ea70d 100644 --- a/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.h +++ b/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.h @@ -153,7 +153,7 @@ namespace studio { const QT3DSF32 g_EditCameraFOV = 45.0f; const QT3DSF32 g_RotationScaleFactor = 2.0f * QT3DSF32(M_PI) / 180.0f; - struct SEditCameraPersistentInformation + struct SEditorCameraInformation { QT3DSVec3 m_Position; QT3DSVec3 m_Direction; @@ -161,7 +161,7 @@ namespace studio { EditCameraTypes::Enum m_CameraType; NVReal m_xRotation = 0.0f; NVReal m_yRotation = 0.0f; - SEditCameraPersistentInformation() + SEditorCameraInformation() : m_Position(0, 0, 0) , m_Direction(0, 0, 0) , m_ViewRadius(600) @@ -169,7 +169,7 @@ namespace studio { { } - void ApplyToCamera(SCamera &inCamera, QT3DSVec2 inViewport) + void ApplyToCamera(SCamera &inCamera, QT3DSVec2 inViewport, bool noScale = false) { // Setup shared default values. inCamera.m_ClipFar = 2000000.0f; @@ -212,6 +212,7 @@ namespace studio { if (m_CameraType != EditCameraTypes::Directional) { theRotationTransform.rotate(-m_xRotation, QT3DSVec3(0.0f, 1.0f, 0.0f)); theRotationTransform.rotate(m_yRotation, QT3DSVec3(1.0f, 0.0f, 0.0f)); + inCamera.m_Rotation = inCamera.GetRotationVectorFromRotationMatrix(theRotationTransform.getUpper3x3()); } // The view radius dictates the zoom. @@ -230,7 +231,8 @@ namespace studio { thePositionMatrix.column3.y = m_Position.y; thePositionMatrix.column3.z = m_Position.z + 600; theGlobalTransform = theGlobalTransform * theRotationTransform; - theGlobalTransform = theGlobalTransform * theScaleMatrix; + if (!noScale) + theGlobalTransform = theGlobalTransform * theScaleMatrix; theGlobalTransform = theGlobalTransform * thePivotMatrix.getInverse(); theGlobalTransform = theGlobalTransform * thePositionMatrix; // This works because the camera has no hierarchy. @@ -256,7 +258,7 @@ namespace studio { }; }; - struct SEditCameraLayerTranslator; + struct SEditorLayerTranslator; struct SZoomRender { CPt m_Point; @@ -387,13 +389,17 @@ namespace studio { bool m_EditCameraEnabled; bool m_EditLightEnabled; bool m_helperGridEnabled = true; - SEditCameraPersistentInformation m_EditCameraInfo; + bool m_axisHelperEnabled = true; + SEditorCameraInformation m_EditCameraInfo; SCamera m_EditCamera; + SCamera m_AxisCamera; SLight m_EditLight; QT3DSVec2 m_Viewport; - SEditCameraLayerTranslator *m_EditCameraLayerTranslator; + SEditorLayerTranslator *m_EditCameraLayerTranslator; + SEditorLayerTranslator *m_AxisHelperLayerTranslator; Option<SZoomRender> m_ZoomRender; NVScopedRefCounted<qt3ds::widgets::IStudioWidget> m_TranslationWidget; + NVScopedRefCounted<qt3ds::widgets::IStudioWidget> m_AxisHelperWidget; NVScopedRefCounted<qt3ds::widgets::IStudioWidget> m_RotationWidget; NVScopedRefCounted<qt3ds::widgets::IStudioWidget> m_ScaleWidget; NVScopedRefCounted<qt3ds::widgets::IStudioWidget> m_LastRenderedWidget; @@ -662,6 +668,7 @@ namespace studio { PickTargetAreas::Enum GetPickArea(CPt inPoint); SNode *GetEditCameraLayer(); + SNode *GetAxisHelperLayer(); void ReleaseEffect(qt3dsdm::Qt3DSDMInstanceHandle inInstance); void releaseMaterial(qt3dsdm::Qt3DSDMInstanceHandle inInstance); @@ -679,6 +686,7 @@ namespace studio { qt3dsdm::Qt3DSDMInstanceHandle GetAnchorPoint(QT3DSU32 inAnchorIndex); void updateHelperGridFromSettings(); + void updateAxisHelperFromSettings(); }; struct SDisableUseClearColor diff --git a/src/Authoring/Qt3DStudio/Render/StudioTranslationWidget.cpp b/src/Authoring/Qt3DStudio/Render/StudioTranslationWidget.cpp index 8f426b3c..47206714 100644 --- a/src/Authoring/Qt3DStudio/Render/StudioTranslationWidget.cpp +++ b/src/Authoring/Qt3DStudio/Render/StudioTranslationWidget.cpp @@ -46,7 +46,9 @@ struct STranslationWidget : public SStudioWidgetImpl<StudioWidgetTypes::Translat NVRenderInputAssembler *m_XAxis; NVRenderInputAssembler *m_YAxis; NVRenderInputAssembler *m_ZAxis; - + NVRenderInputAssembler *m_wideXAxis; + NVRenderInputAssembler *m_wideYAxis; + NVRenderInputAssembler *m_wideZAxis; NVRenderInputAssembler *m_XPlane; NVRenderInputAssembler *m_YPlane; NVRenderInputAssembler *m_ZPlane; @@ -58,6 +60,9 @@ struct STranslationWidget : public SStudioWidgetImpl<StudioWidgetTypes::Translat , m_XAxis(nullptr) , m_YAxis(nullptr) , m_ZAxis(nullptr) + , m_wideXAxis(nullptr) + , m_wideYAxis(nullptr) + , m_wideZAxis(nullptr) , m_XPlane(nullptr) , m_YPlane(nullptr) , m_ZPlane(nullptr) @@ -108,7 +113,71 @@ struct STranslationWidget : public SStudioWidgetImpl<StudioWidgetTypes::Translat QT3DSVec3(axisPos, axisPos, 0), axisDiscRadius, axisRingRadius, 0.0f, 1.0f, "TranslationWidgetZPlane"); } - QT3DSMat44 theMVP = TBase::SetupMVP(inWidgetContext); + + QT3DSMat44 theMVP; + + if (m_isAxisHelper) { + auto helpWidgetInfo + = inWidgetContext.GetWidgetRenderInformation(*m_Node, + QT3DSVec3(0, 0, 0), + RenderWidgetModes::Global); + auto viewport = inRenderContext.GetViewport(); + SCamera theTempCamera; + + QT3DSMat44 theViewProjection; + theTempCamera.m_Flags.SetOrthographic(true); + + // Move the camera back far enough that we can see everything + static QT3DSF32 theCameraSetback(600); + + // Move the camera to position axis helper to the lower left. + theTempCamera.m_Position.z = -theCameraSetback; + theTempCamera.m_Position.x = 0; + theTempCamera.m_Position.y = 0; + theTempCamera.m_ClipFar = 2.0f * theCameraSetback; + + // Use entire viewport + theTempCamera.CalculateGlobalVariables( + viewport, + QT3DSVec2((QT3DSF32)viewport.m_Width, (QT3DSF32)viewport.m_Height)); + theTempCamera.CalculateViewProjectionMatrix(theViewProjection); + + // Get the rotation for the scene view camera (the actual direction of world axes) + // and rotate the widget axes to match world axes. Scale the widget to be smaller + // and less intrusive than actual translation widget. + auto rot = QT3DSMat44::createIdentity(); + if (helpWidgetInfo.m_Camera->m_Flags.IsOrthographic()) { + rot = helpWidgetInfo.m_Camera->m_LocalTransform; + rot.setPosition({}); + rot = rot.getInverse().getTranspose(); + } else { + helpWidgetInfo.m_Camera->CalculateRotationMatrix(rot); + } + + helpWidgetInfo.m_Camera->FlipCoordinateSystem(rot); + rot.scale(QT3DSVec4(0.6, 0.6, 0.6, 1)); + theMVP = theViewProjection * rot.getTranspose(); + + if (m_wideXAxis == nullptr) { + float pixelRatio = float(StudioUtils::devicePixelRatio()); + QT3DSF32 axisWidth = pixelRatio * 6; + QT3DSF32 triWidth = axisWidth * 3; + QT3DSF32 axisStart = 0; + QT3DSF32 axisLength = axisWidth * 10; + QT3DSF32 triLength = axisWidth * 5; + m_wideXAxis = CreateAxis(m_Allocator, inWidgetContext, inRenderContext, + QT3DSVec3(1, 0, 0), axisStart, axisLength, triLength, + axisWidth, triWidth, "TranslationWidgetWideXAxis"); + m_wideYAxis = CreateAxis(m_Allocator, inWidgetContext, inRenderContext, + QT3DSVec3(0, 1, 0), axisStart, axisLength, triLength, + axisWidth, triWidth, "TranslationWidgetWideYAxis"); + m_wideZAxis = CreateAxis(m_Allocator, inWidgetContext, inRenderContext, + QT3DSVec3(0, 0, -1), axisStart, axisLength, triLength, + axisWidth, triWidth, "TranslationWidgetWideZAxis"); + } + } else { + theMVP = TBase::SetupMVP(inWidgetContext); + } if (isNodeBehindCamera()) return; @@ -127,18 +196,27 @@ struct STranslationWidget : public SStudioWidgetImpl<StudioWidgetTypes::Translat QT3DSVec3 theZColor(GetZAxisColor()); QT3DSVec3 theRingColor(QT3DSVec3(.8f, .8f, .8f)); - RenderSingleToneGeometry(StudioWidgetComponentIds::XAxis, theXColor, inRenderContext, - m_XAxis); - RenderSingleToneGeometry(StudioWidgetComponentIds::YAxis, theYColor, inRenderContext, - m_YAxis); - RenderSingleToneGeometry(StudioWidgetComponentIds::ZAxis, theZColor, inRenderContext, - m_ZAxis); - RenderTwoToneGeometry(StudioWidgetComponentIds::XPlane, theXColor, theRingColor, - inRenderContext, m_XPlane); - RenderTwoToneGeometry(StudioWidgetComponentIds::YPlane, theYColor, theRingColor, - inRenderContext, m_YPlane); - RenderTwoToneGeometry(StudioWidgetComponentIds::ZPlane, theZColor, theRingColor, - inRenderContext, m_ZPlane); + if (!m_isAxisHelper) { + RenderSingleToneGeometry(StudioWidgetComponentIds::XAxis, theXColor, inRenderContext, + m_XAxis); + RenderSingleToneGeometry(StudioWidgetComponentIds::YAxis, theYColor, inRenderContext, + m_YAxis); + RenderSingleToneGeometry(StudioWidgetComponentIds::ZAxis, theZColor, inRenderContext, + m_ZAxis); + RenderTwoToneGeometry(StudioWidgetComponentIds::XPlane, theXColor, theRingColor, + inRenderContext, m_XPlane); + RenderTwoToneGeometry(StudioWidgetComponentIds::YPlane, theYColor, theRingColor, + inRenderContext, m_YPlane); + RenderTwoToneGeometry(StudioWidgetComponentIds::ZPlane, theZColor, theRingColor, + inRenderContext, m_ZPlane); + } else { + RenderSingleToneGeometry(StudioWidgetComponentIds::XAxis, theXColor, inRenderContext, + m_wideXAxis); + RenderSingleToneGeometry(StudioWidgetComponentIds::YAxis, theYColor, inRenderContext, + m_wideYAxis); + RenderSingleToneGeometry(StudioWidgetComponentIds::ZAxis, theZColor, inRenderContext, + m_wideZAxis); + } m_Highlight = StudioWidgetComponentIds::NoId; } @@ -168,6 +246,11 @@ struct STranslationWidget : public SStudioWidgetImpl<StudioWidgetTypes::Translat RenderPickBuffer(StudioWidgetComponentIds::ZPlane, m_ZPlane, inRenderContext); } } + + void setAsAxisHelper(bool isAxisHelper) override + { + m_isAxisHelper = isAxisHelper; + } }; } diff --git a/src/Authoring/Qt3DStudio/Render/StudioWidget.h b/src/Authoring/Qt3DStudio/Render/StudioWidget.h index 897c71cf..1287612e 100644 --- a/src/Authoring/Qt3DStudio/Render/StudioWidget.h +++ b/src/Authoring/Qt3DStudio/Render/StudioWidget.h @@ -115,6 +115,8 @@ namespace widgets { QT3DSF32 inColorIndex, TResultVecType &outResult); void SetNode(SNode &inNode) override = 0; + virtual void setAsAxisHelper(bool isAxisWidget) = 0; + virtual StudioWidgetTypes::Enum GetWidgetType() const = 0; virtual void SetSubComponentId(int inSubComponentId) = 0; virtual void SetRenderWidgetMode(RenderWidgetModes::Enum inSpace) = 0; diff --git a/src/Authoring/Qt3DStudio/Render/StudioWidgetImpl.h b/src/Authoring/Qt3DStudio/Render/StudioWidgetImpl.h index d963bee1..9205fc5d 100644 --- a/src/Authoring/Qt3DStudio/Render/StudioWidgetImpl.h +++ b/src/Authoring/Qt3DStudio/Render/StudioWidgetImpl.h @@ -92,6 +92,7 @@ namespace widgets { NVRenderVertexBuffer *m_ImmediateVertexBuffer; NVRenderInputAssembler *m_ImmediateInputAssembler; NVRenderShaderProgram *m_ImmediateShader; + bool m_isAxisHelper; SStudioWidgetImpl(NVAllocatorCallback &inAlloc) : m_Allocator(inAlloc) @@ -104,6 +105,7 @@ namespace widgets { , m_ImmediateVertexBuffer(NULL) , m_ImmediateInputAssembler(NULL) , m_ImmediateShader(NULL) + , m_isAxisHelper(false) { } @@ -319,6 +321,8 @@ namespace widgets { void SetAxisScale(const QT3DSVec3 &inAxisScale) override { m_AxisScale = inAxisScale; } + void setAsAxisHelper(bool isAxisHelper) override { m_isAxisHelper = isAxisHelper; } + void SetRotationEdges(const QT3DSVec3 &inStartDirection, const QT3DSVec3 &inRotationAxis, QT3DSF32 inAngleRad, QT3DSF32 inEndLineLen) override { diff --git a/src/Authoring/Qt3DStudio/UI/SceneView.cpp b/src/Authoring/Qt3DStudio/UI/SceneView.cpp index 46b8ccac..653fcd9b 100644 --- a/src/Authoring/Qt3DStudio/UI/SceneView.cpp +++ b/src/Authoring/Qt3DStudio/UI/SceneView.cpp @@ -338,6 +338,10 @@ void CSceneView::setToolMode(long inMode) */ void CSceneView::onEditCameraChanged() { + // Update the view mode accordingly + setViewMode(g_StudioApp.getRenderer().GetEditCamera() >= 0 ? CPlayerContainerWnd::VIEW_EDIT + : CPlayerContainerWnd::VIEW_SCENE); + // Reset any scrolling and recalculate the window position. if (m_playerContainerWnd) { m_playerContainerWnd->SetScrollRanges(); @@ -345,9 +349,6 @@ void CSceneView::onEditCameraChanged() setPlayerWndPosition(); } - // Update the view mode accordingly - setViewMode(g_StudioApp.getRenderer().GetEditCamera() >= 0 ? CPlayerContainerWnd::VIEW_EDIT - : CPlayerContainerWnd::VIEW_SCENE); m_playerWnd->update(); } diff --git a/src/Runtime/ogl-runtime b/src/Runtime/ogl-runtime -Subproject d9986892bf0cccc60c53d42dfc556d37226cf5d +Subproject b9b52349d0df29e2eaa30dd13644b9f42d9e4f3 |