From da421b7056eeeaeb1869d3c22c5acf5c6bcd3096 Mon Sep 17 00:00:00 2001 From: Roman <69218254+amzn-rhhong@users.noreply.github.com> Date: Mon, 14 Feb 2022 13:27:37 -0800 Subject: [PATCH] Change actorRenderFlag to use AZ ENUM CLASS instead of azstd::bitset (#7542) * Fixes the problem with using actor render flags in actor component Signed-off-by: rhhong * In progress work for actor render flag rework Signed-off-by: rhhong * add an utlity function to check bit Signed-off-by: rhhong * code cleanup Signed-off-by: rhhong * More CR cleanup Signed-off-by: rhhong * build fix Signed-off-by: rhhong * CR feedback Signed-off-by: rhhong --- .../Code/Source/AtomActorDebugDraw.cpp | 30 ++--- .../Code/Source/AtomActorDebugDraw.h | 2 +- .../Code/Source/AtomActorInstance.cpp | 2 +- .../Code/Source/AtomActorInstance.h | 2 +- .../Tools/EMStudio/AnimViewportRenderer.cpp | 2 +- .../Tools/EMStudio/AnimViewportRenderer.h | 2 +- .../Tools/EMStudio/AnimViewportRequestBus.h | 2 +- .../Tools/EMStudio/AnimViewportToolBar.cpp | 46 ++++---- .../Code/Tools/EMStudio/AnimViewportToolBar.h | 4 +- .../Tools/EMStudio/AnimViewportWidget.cpp | 2 +- .../Code/Tools/EMStudio/AnimViewportWidget.h | 2 +- .../Code/Tools/EMStudio/AtomRenderPlugin.cpp | 2 +- .../Code/Tools/EMStudio/AtomRenderPlugin.h | 2 +- .../EMStudioSDK/Source/EMStudioPlugin.h | 2 +- .../Source/RenderPlugin/RenderOptions.cpp | 25 ++--- .../Source/RenderPlugin/RenderOptions.h | 8 +- .../Cloth/ClothJointInspectorPlugin.cpp | 5 +- .../Plugins/Cloth/ClothJointInspectorPlugin.h | 2 +- .../HitDetectionJointInspectorPlugin.cpp | 5 +- .../HitDetectionJointInspectorPlugin.h | 2 +- .../Ragdoll/RagdollNodeInspectorPlugin.cpp | 6 +- .../Ragdoll/RagdollNodeInspectorPlugin.h | 2 +- .../SimulatedObject/SimulatedObjectWidget.cpp | 8 +- .../SimulatedObject/SimulatedObjectWidget.h | 2 +- .../Integration/Components/ActorComponent.cpp | 50 +++++---- .../Integration/Components/ActorComponent.h | 7 +- .../Components/EditorActorComponent.cpp | 45 +++++--- .../Editor/Components/EditorActorComponent.h | 7 +- .../Rendering/RenderActorInstance.h | 2 +- .../Source/Integration/Rendering/RenderFlag.h | 105 +++++++++++++----- .../Code/Tests/RenderBackendManagerTests.cpp | 2 +- 31 files changed, 217 insertions(+), 168 deletions(-) diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorDebugDraw.cpp b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorDebugDraw.cpp index deb668d12a..24134b2d17 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorDebugDraw.cpp +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorDebugDraw.cpp @@ -33,7 +33,7 @@ namespace AZ::Render m_auxGeomFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity(entityId); } - void AtomActorDebugDraw::DebugDraw(const EMotionFX::ActorRenderFlagBitset& renderFlags, EMotionFX::ActorInstance* instance) + void AtomActorDebugDraw::DebugDraw(const EMotionFX::ActorRenderFlags& renderFlags, EMotionFX::ActorInstance* instance) { if (!m_auxGeomFeatureProcessor || !instance) { @@ -46,10 +46,12 @@ namespace AZ::Render return; } + using AZ::RHI::CheckBitsAny; + // Update the mesh deformers (perform cpu skinning and morphing) when needed. - if (renderFlags[EMotionFX::ActorRenderFlag::RENDER_AABB] || renderFlags[EMotionFX::ActorRenderFlag::RENDER_FACENORMALS] || - renderFlags[EMotionFX::ActorRenderFlag::RENDER_TANGENTS] || renderFlags[EMotionFX::ActorRenderFlag::RENDER_VERTEXNORMALS] || - renderFlags[EMotionFX::ActorRenderFlag::RENDER_WIREFRAME]) + if (CheckBitsAny(renderFlags, + EMotionFX::ActorRenderFlags::AABB | EMotionFX::ActorRenderFlags::FaceNormals | EMotionFX::ActorRenderFlags::Tangents | + EMotionFX::ActorRenderFlags::VertexNormals | EMotionFX::ActorRenderFlags::Wireframe)) { instance->UpdateMeshDeformers(0.0f, true); } @@ -61,7 +63,7 @@ namespace AZ::Render const float scaleMultiplier = CalculateScaleMultiplier(instance); // Render aabb - if (renderFlags[EMotionFX::ActorRenderFlag::RENDER_AABB]) + if (CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::AABB)) { RenderAABB(instance, renderActorSettings.m_enabledNodeBasedAabb, renderActorSettings.m_nodeAABBColor, @@ -70,39 +72,39 @@ namespace AZ::Render } // Render simple line skeleton - if (renderFlags[EMotionFX::ActorRenderFlag::RENDER_LINESKELETON]) + if (CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::LineSkeleton)) { RenderLineSkeleton(instance, renderActorSettings.m_lineSkeletonColor); } // Render advanced skeleton - if (renderFlags[EMotionFX::ActorRenderFlag::RENDER_SKELETON]) + if (CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::Skeleton)) { RenderSkeleton(instance, renderActorSettings.m_skeletonColor); } - if (renderFlags[EMotionFX::ActorRenderFlag::RENDER_NODENAMES]) + if (CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::NodeNames)) { RenderJointNames(instance, viewport, renderActorSettings.m_jointNameColor); } // Render internal EMFX debug lines. - if (renderFlags[EMotionFX::ActorRenderFlag::RENDER_EMFX_DEBUG]) + if (CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::EmfxDebug)) { RenderEMFXDebugDraw(instance); } // Render - if (renderFlags[EMotionFX::ActorRenderFlag::RENDER_NODEORIENTATION]) + if (CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::NodeOrientation)) { RenderNodeOrientations(instance, debugDisplay, renderActorSettings.m_nodeOrientationScale * scaleMultiplier); } // Render vertex normal, face normal, tagent and wireframe. - const bool renderVertexNormals = renderFlags[EMotionFX::ActorRenderFlag::RENDER_VERTEXNORMALS]; - const bool renderFaceNormals = renderFlags[EMotionFX::ActorRenderFlag::RENDER_FACENORMALS]; - const bool renderTangents = renderFlags[EMotionFX::ActorRenderFlag::RENDER_TANGENTS]; - const bool renderWireframe = renderFlags[EMotionFX::ActorRenderFlag::RENDER_WIREFRAME]; + const bool renderVertexNormals = CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::VertexNormals); + const bool renderFaceNormals = CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::FaceNormals); + const bool renderTangents = CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::Tangents); + const bool renderWireframe = CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::Wireframe); if (renderVertexNormals || renderFaceNormals || renderTangents || renderWireframe) { diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorDebugDraw.h b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorDebugDraw.h index 8e985fdbc6..53086801c7 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorDebugDraw.h +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorDebugDraw.h @@ -40,7 +40,7 @@ namespace AZ::Render public: AtomActorDebugDraw(AZ::EntityId entityId); - void DebugDraw(const EMotionFX::ActorRenderFlagBitset& renderFlags, EMotionFX::ActorInstance* instance); + void DebugDraw(const EMotionFX::ActorRenderFlags& renderFlags, EMotionFX::ActorInstance* instance); private: diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.cpp b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.cpp index 35aea57702..f0b46255fe 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.cpp +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.cpp @@ -79,7 +79,7 @@ namespace AZ::Render UpdateBounds(); } - void AtomActorInstance::DebugDraw(const EMotionFX::ActorRenderFlagBitset& renderFlags) + void AtomActorInstance::DebugDraw(const EMotionFX::ActorRenderFlags& renderFlags) { m_atomActorDebugDraw->DebugDraw(renderFlags, m_actorInstance); } diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.h b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.h index 73d428216c..2eeb61c812 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.h +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.h @@ -86,7 +86,7 @@ namespace AZ // RenderActorInstance overrides ... void OnTick(float timeDelta) override; - void DebugDraw(const EMotionFX::ActorRenderFlagBitset& renderFlags); + void DebugDraw(const EMotionFX::ActorRenderFlags& renderFlags); void UpdateBounds() override; void SetMaterials(const EMotionFX::Integration::ActorAsset::MaterialList& materialPerLOD) override { AZ_UNUSED(materialPerLOD); }; void SetSkinningMethod(EMotionFX::Integration::SkinningMethod emfxSkinningMethod) override; diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.cpp b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.cpp index 6ac2a66261..63a0554e37 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.cpp +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.cpp @@ -191,7 +191,7 @@ namespace EMStudio return result; } - void AnimViewportRenderer::UpdateActorRenderFlag(EMotionFX::ActorRenderFlagBitset renderFlags) + void AnimViewportRenderer::UpdateActorRenderFlag(EMotionFX::ActorRenderFlags renderFlags) { for (AZ::Entity* entity : m_actorEntities) { diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.h b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.h index 0066c222db..3f34d2f26e 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.h +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.h @@ -54,7 +54,7 @@ namespace EMStudio //! Return the center position of the existing objects. AZ::Vector3 GetCharacterCenter() const; - void UpdateActorRenderFlag(EMotionFX::ActorRenderFlagBitset renderFlags); + void UpdateActorRenderFlag(EMotionFX::ActorRenderFlags renderFlags); AZStd::shared_ptr GetFrameworkScene() const; AZ::EntityId GetEntityId() const; AzFramework::EntityContextId GetEntityContextId() const; diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRequestBus.h b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRequestBus.h index 9b2fc0b212..91de0882bc 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRequestBus.h +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRequestBus.h @@ -26,7 +26,7 @@ namespace EMStudio virtual void UpdateCameraFollowUp(bool followUp) = 0; //! Update render flags - virtual void UpdateRenderFlags(EMotionFX::ActorRenderFlagBitset renderFlags) = 0; + virtual void UpdateRenderFlags(EMotionFX::ActorRenderFlags renderFlags) = 0; }; using AnimViewportRequestBus = AZ::EBus; diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportToolBar.cpp b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportToolBar.cpp index d9de41f54b..e2c011fcde 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportToolBar.cpp +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportToolBar.cpp @@ -61,35 +61,35 @@ namespace EMStudio renderOptionsButton->setIcon(QIcon(":/EMotionFXAtom/Visualization.svg")); addWidget(renderOptionsButton); - CreateViewOptionEntry(contextMenu, "Solid", EMotionFX::ActorRenderFlag::RENDER_SOLID); - CreateViewOptionEntry(contextMenu, "Wireframe", EMotionFX::ActorRenderFlag::RENDER_WIREFRAME); + CreateViewOptionEntry(contextMenu, "Solid", EMotionFX::ActorRenderFlagIndex::SOLID); + CreateViewOptionEntry(contextMenu, "Wireframe", EMotionFX::ActorRenderFlagIndex::WIREFRAME); // [EMFX-TODO] Add those option once implemented. - // CreateViewOptionEntry(contextMenu, "Lighting", EMotionFX::ActorRenderFlag::RENDER_LIGHTING); - // CreateViewOptionEntry(contextMenu, "Backface Culling", EMotionFX::ActorRenderFlag::RENDER_BACKFACECULLING); + // CreateViewOptionEntry(contextMenu, "Lighting", EMotionFX::ActorRenderFlagIndex::RENDER_LIGHTING); + // CreateViewOptionEntry(contextMenu, "Backface Culling", EMotionFX::ActorRenderFlagIndex::RENDER_BACKFACECULLING); contextMenu->addSeparator(); - CreateViewOptionEntry(contextMenu, "Vertex Normals", EMotionFX::ActorRenderFlag::RENDER_VERTEXNORMALS); - CreateViewOptionEntry(contextMenu, "Face Normals", EMotionFX::ActorRenderFlag::RENDER_FACENORMALS); - CreateViewOptionEntry(contextMenu, "Tangents", EMotionFX::ActorRenderFlag::RENDER_TANGENTS); - CreateViewOptionEntry(contextMenu, "Actor Bounding Boxes", EMotionFX::ActorRenderFlag::RENDER_AABB); + CreateViewOptionEntry(contextMenu, "Vertex Normals", EMotionFX::ActorRenderFlagIndex::VERTEXNORMALS); + CreateViewOptionEntry(contextMenu, "Face Normals", EMotionFX::ActorRenderFlagIndex::FACENORMALS); + CreateViewOptionEntry(contextMenu, "Tangents", EMotionFX::ActorRenderFlagIndex::TANGENTS); + CreateViewOptionEntry(contextMenu, "Actor Bounding Boxes", EMotionFX::ActorRenderFlagIndex::AABB); contextMenu->addSeparator(); - CreateViewOptionEntry(contextMenu, "Line Skeleton", EMotionFX::ActorRenderFlag::RENDER_LINESKELETON); - CreateViewOptionEntry(contextMenu, "Solid Skeleton", EMotionFX::ActorRenderFlag::RENDER_SKELETON); - CreateViewOptionEntry(contextMenu, "Joint Names", EMotionFX::ActorRenderFlag::RENDER_NODENAMES); - CreateViewOptionEntry(contextMenu, "Joint Orientations", EMotionFX::ActorRenderFlag::RENDER_NODEORIENTATION); + CreateViewOptionEntry(contextMenu, "Line Skeleton", EMotionFX::ActorRenderFlagIndex::LINESKELETON); + CreateViewOptionEntry(contextMenu, "Solid Skeleton", EMotionFX::ActorRenderFlagIndex::SKELETON); + CreateViewOptionEntry(contextMenu, "Joint Names", EMotionFX::ActorRenderFlagIndex::NODENAMES); + CreateViewOptionEntry(contextMenu, "Joint Orientations", EMotionFX::ActorRenderFlagIndex::NODEORIENTATION); // [EMFX-TODO] Add those option once implemented. - // CreateViewOptionEntry(contextMenu, "Actor Bind Pose", EMotionFX::ActorRenderFlag::RENDER_ACTORBINDPOSE); + // CreateViewOptionEntry(contextMenu, "Actor Bind Pose", EMotionFX::ActorRenderFlagIndex::RENDER_ACTORBINDPOSE); contextMenu->addSeparator(); - CreateViewOptionEntry(contextMenu, "Hit Detection Colliders", EMotionFX::ActorRenderFlag::RENDER_HITDETECTION_COLLIDERS, true, + CreateViewOptionEntry(contextMenu, "Hit Detection Colliders", EMotionFX::ActorRenderFlagIndex::HITDETECTION_COLLIDERS, true, ":/EMotionFXAtom/HitDetection.svg"); - CreateViewOptionEntry(contextMenu, "Ragdoll Colliders", EMotionFX::ActorRenderFlag::RENDER_RAGDOLL_COLLIDERS, true, + CreateViewOptionEntry(contextMenu, "Ragdoll Colliders", EMotionFX::ActorRenderFlagIndex::RAGDOLL_COLLIDERS, true, ":/EMotionFXAtom/RagdollCollider.svg"); - CreateViewOptionEntry(contextMenu, "Ragdoll Joint Limits", EMotionFX::ActorRenderFlag::RENDER_RAGDOLL_JOINTLIMITS, true, + CreateViewOptionEntry(contextMenu, "Ragdoll Joint Limits", EMotionFX::ActorRenderFlagIndex::RAGDOLL_JOINTLIMITS, true, ":/EMotionFXAtom/RagdollJointLimit.svg"); - CreateViewOptionEntry(contextMenu, "Cloth Colliders", EMotionFX::ActorRenderFlag::RENDER_CLOTH_COLLIDERS, true, + CreateViewOptionEntry(contextMenu, "Cloth Colliders", EMotionFX::ActorRenderFlagIndex::CLOTH_COLLIDERS, true, ":/EMotionFXAtom/Cloth.svg"); - CreateViewOptionEntry(contextMenu, "Simulated Object Colliders", EMotionFX::ActorRenderFlag::RENDER_SIMULATEDOBJECT_COLLIDERS, true, + CreateViewOptionEntry(contextMenu, "Simulated Object Colliders", EMotionFX::ActorRenderFlagIndex::SIMULATEDOBJECT_COLLIDERS, true, ":/EMotionFXAtom/SimulatedObjectCollider.svg"); - CreateViewOptionEntry(contextMenu, "Simulated Joints", EMotionFX::ActorRenderFlag::RENDER_SIMULATEJOINTS); + CreateViewOptionEntry(contextMenu, "Simulated Joints", EMotionFX::ActorRenderFlagIndex::SIMULATEJOINTS); } // Add the camera button @@ -158,7 +158,7 @@ namespace EMStudio } void AnimViewportToolBar::CreateViewOptionEntry( - QMenu* menu, const char* menuEntryName, uint32_t actionIndex, bool visible, const char* iconFileName) + QMenu* menu, const char* menuEntryName, AZ::u8 actionIndex, bool visible, const char* iconFileName) { QAction* action = menu->addAction( menuEntryName, @@ -194,13 +194,13 @@ namespace EMStudio m_manipulatorActions[mode]->setChecked(true); } - const EMotionFX::ActorRenderFlagBitset renderFlags = renderOptions->GetRenderFlags(); - for (size_t i = 0; i < renderFlags.size(); ++i) + const EMotionFX::ActorRenderFlags renderFlags = renderOptions->GetRenderFlags(); + for (uint8 i = 0; i < EMotionFX::ActorRenderFlagIndex::NUM_RENDERFLAGINDEXES; ++i) { QAction* action = m_renderActions[i]; if (action) { - action->setChecked(renderFlags[i]); + action->setChecked(EMotionFX::ActorRenderFlagUtil::CheckBit(renderFlags, i)); } } } diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportToolBar.h b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportToolBar.h index f516b9df28..08c32429e9 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportToolBar.h +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportToolBar.h @@ -30,11 +30,11 @@ namespace EMStudio private: void CreateViewOptionEntry( - QMenu* menu, const char* menuEntryName, uint32_t actionIndex, bool visible = true, const char* iconFileName = nullptr); + QMenu* menu, const char* menuEntryName, AZ::u8 actionIndex, bool visible = true, const char* iconFileName = nullptr); AtomRenderPlugin* m_plugin = nullptr; QAction* m_manipulatorActions[RenderOptions::ManipulatorMode::NUM_MODES] = { nullptr }; - QAction* m_renderActions[EMotionFX::ActorRenderFlag::NUM_RENDERFLAGS] = { nullptr }; + QAction* m_renderActions[EMotionFX::ActorRenderFlagIndex::NUM_RENDERFLAGINDEXES] = { nullptr }; QAction* m_followCharacterAction = nullptr; }; } diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.cpp b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.cpp index 90fbb81e47..c1c891ad97 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.cpp +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.cpp @@ -229,7 +229,7 @@ namespace EMStudio } } - void AnimViewportWidget::UpdateRenderFlags(EMotionFX::ActorRenderFlagBitset renderFlags) + void AnimViewportWidget::UpdateRenderFlags(EMotionFX::ActorRenderFlags renderFlags) { m_renderer->UpdateActorRenderFlag(renderFlags); } diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.h b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.h index 9e4a7c5fa7..261c78c755 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.h +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.h @@ -45,7 +45,7 @@ namespace EMStudio // AnimViewportRequestBus::Handler overrides void UpdateCameraViewMode(RenderOptions::CameraViewMode mode); void UpdateCameraFollowUp(bool follow); - void UpdateRenderFlags(EMotionFX::ActorRenderFlagBitset renderFlags); + void UpdateRenderFlags(EMotionFX::ActorRenderFlags renderFlags); // ViewportPluginRequestBus::Handler overrides AZ::s32 GetViewportId() const; diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AtomRenderPlugin.cpp b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AtomRenderPlugin.cpp index 5b3f305cd0..32298d740f 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AtomRenderPlugin.cpp +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AtomRenderPlugin.cpp @@ -300,7 +300,7 @@ namespace EMStudio return &m_renderOptions; } - void AtomRenderPlugin::Render([[maybe_unused]]EMotionFX::ActorRenderFlagBitset renderFlags) + void AtomRenderPlugin::Render([[maybe_unused]]EMotionFX::ActorRenderFlags renderFlags) { if (!m_animViewportWidget) { diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AtomRenderPlugin.h b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AtomRenderPlugin.h index 2207690628..66e89dfc45 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AtomRenderPlugin.h +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AtomRenderPlugin.h @@ -61,7 +61,7 @@ namespace EMStudio void SaveRenderOptions(); RenderOptions* GetRenderOptions(); - void Render(EMotionFX::ActorRenderFlagBitset renderFlags) override; + void Render(EMotionFX::ActorRenderFlags renderFlags) override; void SetManipulatorMode(RenderOptions::ManipulatorMode mode); private: diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/EMStudioPlugin.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/EMStudioPlugin.h index 2dc86ba01b..1d6bd55290 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/EMStudioPlugin.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/EMStudioPlugin.h @@ -96,7 +96,7 @@ namespace EMStudio virtual void LegacyRender(RenderPlugin* renderPlugin, RenderInfo* renderInfo) { MCORE_UNUSED(renderPlugin); MCORE_UNUSED(renderInfo); } //! Render function will call atom auxGeom internally to render. This is the replacement for LegacyRender function. - virtual void Render(EMotionFX::ActorRenderFlagBitset renderFlags) + virtual void Render(EMotionFX::ActorRenderFlags renderFlags) { AZ_UNUSED(renderFlags); }; diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderOptions.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderOptions.cpp index 7adea15a99..4c3b9d1a93 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderOptions.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderOptions.cpp @@ -255,12 +255,7 @@ namespace EMStudio settings->setValue("cameraFollowUp", m_cameraFollowUp); // Save render flags - settings->beginGroup("renderFlags"); - for (uint32 i = 0; i < EMotionFX::ActorRenderFlag::NUM_RENDERFLAGS; ++i) - { - settings->setValue(QString(i), (bool)m_renderFlags[i]); - } - settings->endGroup(); + settings->setValue("renderFlags", static_cast(m_renderFlags)); } RenderOptions RenderOptions::Load(QSettings* settings) @@ -333,14 +328,8 @@ namespace EMStudio options.m_cameraFollowUp = settings->value("CameraFollowUp", options.m_cameraFollowUp).toBool(); // Read render flags - settings->beginGroup("renderFlags"); - for (uint32 i = 0; i < EMotionFX::ActorRenderFlag::NUM_RENDERFLAGS; ++i) - { - const bool defaultValue = (i == EMotionFX::ActorRenderFlag::RENDER_SOLID); - const bool isEnabled = settings->value(QString(i), defaultValue).toBool(); - options.m_renderFlags[i] = isEnabled; - } - settings->endGroup(); + options.m_renderFlags = + EMotionFX::ActorRenderFlags(settings->value("RenderFlags", static_cast(EMotionFX::ActorRenderFlags::Default)).toInt()); options.CopyToRenderActorSettings(EMotionFX::GetRenderActorSettings()); @@ -1104,17 +1093,17 @@ namespace EMStudio return m_cameraFollowUp; } - void RenderOptions::ToggerRenderFlag(int index) + void RenderOptions::ToggerRenderFlag(uint8 index) { - m_renderFlags[index] = !m_renderFlags[index]; + m_renderFlags ^= EMotionFX::ActorRenderFlags(AZ_BIT(index)); } - void RenderOptions::SetRenderFlags(EMotionFX::ActorRenderFlagBitset renderFlags) + void RenderOptions::SetRenderFlags(EMotionFX::ActorRenderFlags renderFlags) { m_renderFlags = renderFlags; } - EMotionFX::ActorRenderFlagBitset RenderOptions::GetRenderFlags() const + EMotionFX::ActorRenderFlags RenderOptions::GetRenderFlags() const { return m_renderFlags; } diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderOptions.h b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderOptions.h index 3c5dbcaba1..09b23cab08 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderOptions.h +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderOptions.h @@ -284,9 +284,9 @@ namespace EMStudio void SetCameraFollowUp(bool followUp); bool GetCameraFollowUp() const; - void ToggerRenderFlag(int index); - void SetRenderFlags(EMotionFX::ActorRenderFlagBitset renderFlags); - EMotionFX::ActorRenderFlagBitset GetRenderFlags() const; + void ToggerRenderFlag(uint8 index); + void SetRenderFlags(EMotionFX::ActorRenderFlags renderFlags); + EMotionFX::ActorRenderFlags GetRenderFlags() const; private: void OnGridUnitSizeChangedCallback() const; @@ -406,7 +406,7 @@ namespace EMStudio ManipulatorMode m_manipulatorMode = ManipulatorMode::SELECT; CameraViewMode m_cameraViewMode = CameraViewMode::DEFAULT; bool m_cameraFollowUp = false; - EMotionFX::ActorRenderFlagBitset m_renderFlags; + EMotionFX::ActorRenderFlags m_renderFlags; }; } // namespace EMStudio diff --git a/Gems/EMotionFX/Code/Source/Editor/Plugins/Cloth/ClothJointInspectorPlugin.cpp b/Gems/EMotionFX/Code/Source/Editor/Plugins/Cloth/ClothJointInspectorPlugin.cpp index 161cc2ac95..a89f9fdb85 100644 --- a/Gems/EMotionFX/Code/Source/Editor/Plugins/Cloth/ClothJointInspectorPlugin.cpp +++ b/Gems/EMotionFX/Code/Source/Editor/Plugins/Cloth/ClothJointInspectorPlugin.cpp @@ -196,10 +196,9 @@ namespace EMotionFX renderInfo); } - void ClothJointInspectorPlugin::Render(EMotionFX::ActorRenderFlagBitset renderFlags) + void ClothJointInspectorPlugin::Render(EMotionFX::ActorRenderFlags renderFlags) { - const bool renderColliders = renderFlags[RENDER_CLOTH_COLLIDERS]; - if (!renderColliders) + if (!AZ::RHI::CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::ClothColliders)) { return; } diff --git a/Gems/EMotionFX/Code/Source/Editor/Plugins/Cloth/ClothJointInspectorPlugin.h b/Gems/EMotionFX/Code/Source/Editor/Plugins/Cloth/ClothJointInspectorPlugin.h index c1b3e9ad13..d220d4ca44 100644 --- a/Gems/EMotionFX/Code/Source/Editor/Plugins/Cloth/ClothJointInspectorPlugin.h +++ b/Gems/EMotionFX/Code/Source/Editor/Plugins/Cloth/ClothJointInspectorPlugin.h @@ -48,7 +48,7 @@ namespace EMotionFX void OnContextMenu(QMenu* menu, const QModelIndexList& selectedRowIndices) override; void LegacyRender(EMStudio::RenderPlugin* renderPlugin, RenderInfo* renderInfo) override; - void Render(EMotionFX::ActorRenderFlagBitset renderFlags) override; + void Render(EMotionFX::ActorRenderFlags renderFlags) override; static bool IsJointInCloth(const QModelIndex& index); public slots: diff --git a/Gems/EMotionFX/Code/Source/Editor/Plugins/HitDetection/HitDetectionJointInspectorPlugin.cpp b/Gems/EMotionFX/Code/Source/Editor/Plugins/HitDetection/HitDetectionJointInspectorPlugin.cpp index 0f0eb89bfc..74534927c3 100644 --- a/Gems/EMotionFX/Code/Source/Editor/Plugins/HitDetection/HitDetectionJointInspectorPlugin.cpp +++ b/Gems/EMotionFX/Code/Source/Editor/Plugins/HitDetection/HitDetectionJointInspectorPlugin.cpp @@ -181,10 +181,9 @@ namespace EMotionFX renderInfo); } - void HitDetectionJointInspectorPlugin::Render(EMotionFX::ActorRenderFlagBitset renderFlags) + void HitDetectionJointInspectorPlugin::Render(EMotionFX::ActorRenderFlags renderFlags) { - const bool renderColliders = renderFlags[EMotionFX::ActorRenderFlag::RENDER_HITDETECTION_COLLIDERS]; - if (!renderColliders) + if (!AZ::RHI::CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::HitDetectionColliders)) { return; } diff --git a/Gems/EMotionFX/Code/Source/Editor/Plugins/HitDetection/HitDetectionJointInspectorPlugin.h b/Gems/EMotionFX/Code/Source/Editor/Plugins/HitDetection/HitDetectionJointInspectorPlugin.h index 4dc61f9b9e..2b3daeb7db 100644 --- a/Gems/EMotionFX/Code/Source/Editor/Plugins/HitDetection/HitDetectionJointInspectorPlugin.h +++ b/Gems/EMotionFX/Code/Source/Editor/Plugins/HitDetection/HitDetectionJointInspectorPlugin.h @@ -44,7 +44,7 @@ namespace EMotionFX void OnContextMenu(QMenu* menu, const QModelIndexList& selectedRowIndices) override; void LegacyRender(EMStudio::RenderPlugin* renderPlugin, RenderInfo* renderInfo) override; - void Render(EMotionFX::ActorRenderFlagBitset renderFlags) override; + void Render(EMotionFX::ActorRenderFlags renderFlags) override; public slots: void OnAddCollider(); diff --git a/Gems/EMotionFX/Code/Source/Editor/Plugins/Ragdoll/RagdollNodeInspectorPlugin.cpp b/Gems/EMotionFX/Code/Source/Editor/Plugins/Ragdoll/RagdollNodeInspectorPlugin.cpp index e76cf42c44..eb8a22021b 100644 --- a/Gems/EMotionFX/Code/Source/Editor/Plugins/Ragdoll/RagdollNodeInspectorPlugin.cpp +++ b/Gems/EMotionFX/Code/Source/Editor/Plugins/Ragdoll/RagdollNodeInspectorPlugin.cpp @@ -595,10 +595,10 @@ namespace EMotionFX renderInfo->m_renderUtil->RenderArrow(0.1f, jointChildWorldSpaceTransformNoScale.m_position, MCore::GetRight(jointChildWorldSpaceTransformNoScale.ToAZTransform()), color); } - void RagdollNodeInspectorPlugin::Render(EMotionFX::ActorRenderFlagBitset renderFlags) + void RagdollNodeInspectorPlugin::Render(EMotionFX::ActorRenderFlags renderFlags) { - const bool renderColliders = renderFlags[RENDER_RAGDOLL_COLLIDERS]; - const bool renderJointLimits = renderFlags[RENDER_RAGDOLL_JOINTLIMITS]; + const bool renderColliders = AZ::RHI::CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::RagdollColliders); + const bool renderJointLimits = AZ::RHI::CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::RagdollJointLimits); if (!renderColliders && !renderJointLimits) { return; diff --git a/Gems/EMotionFX/Code/Source/Editor/Plugins/Ragdoll/RagdollNodeInspectorPlugin.h b/Gems/EMotionFX/Code/Source/Editor/Plugins/Ragdoll/RagdollNodeInspectorPlugin.h index d3b27da5ce..4742bfb889 100644 --- a/Gems/EMotionFX/Code/Source/Editor/Plugins/Ragdoll/RagdollNodeInspectorPlugin.h +++ b/Gems/EMotionFX/Code/Source/Editor/Plugins/Ragdoll/RagdollNodeInspectorPlugin.h @@ -74,7 +74,7 @@ namespace EMotionFX const MCore::RGBAColor& color); //! Those function replaces legacyRender function and calls atom auxGeom render internally. - void Render(EMotionFX::ActorRenderFlagBitset renderFlags) override; + void Render(EMotionFX::ActorRenderFlags renderFlags) override; void RenderRagdoll( ActorInstance* actorInstance, bool renderColliders, diff --git a/Gems/EMotionFX/Code/Source/Editor/Plugins/SimulatedObject/SimulatedObjectWidget.cpp b/Gems/EMotionFX/Code/Source/Editor/Plugins/SimulatedObject/SimulatedObjectWidget.cpp index 695603cecb..7a11402611 100644 --- a/Gems/EMotionFX/Code/Source/Editor/Plugins/SimulatedObject/SimulatedObjectWidget.cpp +++ b/Gems/EMotionFX/Code/Source/Editor/Plugins/SimulatedObject/SimulatedObjectWidget.cpp @@ -570,7 +570,7 @@ namespace EMotionFX drawData->Unlock(); } - void SimulatedObjectWidget::Render(EMotionFX::ActorRenderFlagBitset renderFlags) + void SimulatedObjectWidget::Render(EMotionFX::ActorRenderFlags renderFlags) { if (!m_actor || !m_actorInstance) { @@ -578,9 +578,8 @@ namespace EMotionFX } const AZ::Render::RenderActorSettings& settings = EMotionFX::GetRenderActorSettings(); - const bool renderSimulatedJoints = renderFlags[RENDER_SIMULATEJOINTS]; const AZStd::unordered_set& selectedJointIndices = EMStudio::GetManager()->GetSelectedJointIndices(); - if (renderSimulatedJoints && !selectedJointIndices.empty()) + if (AZ::RHI::CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::SimulatedJoints) && !selectedJointIndices.empty()) { // Render the joint radius. const size_t actorInstanceCount = GetActorManager().GetNumActorInstances(); @@ -613,8 +612,7 @@ namespace EMotionFX } } - const bool renderColliders = renderFlags[RENDER_SIMULATEDOBJECT_COLLIDERS]; - if (renderColliders) + if (AZ::RHI::CheckBitsAny(renderFlags, EMotionFX::ActorRenderFlags::SimulatedObjectColliders)) { ColliderContainerWidget::RenderColliders(PhysicsSetup::SimulatedObjectCollider, settings.m_simulatedObjectColliderColor, settings.m_selectedSimulatedObjectColliderColor); diff --git a/Gems/EMotionFX/Code/Source/Editor/Plugins/SimulatedObject/SimulatedObjectWidget.h b/Gems/EMotionFX/Code/Source/Editor/Plugins/SimulatedObject/SimulatedObjectWidget.h index 9662fbc150..a3a6344a09 100644 --- a/Gems/EMotionFX/Code/Source/Editor/Plugins/SimulatedObject/SimulatedObjectWidget.h +++ b/Gems/EMotionFX/Code/Source/Editor/Plugins/SimulatedObject/SimulatedObjectWidget.h @@ -61,7 +61,7 @@ namespace EMotionFX void LegacyRender(EMStudio::RenderPlugin* renderPlugin, RenderInfo* renderInfo) override; void LegacyRenderJointRadius(const SimulatedJoint* joint, ActorInstance* actorInstance, const AZ::Color& color); - void Render(EMotionFX::ActorRenderFlagBitset renderFlags) override; + void Render(EMotionFX::ActorRenderFlags renderFlags) override; void RenderJointRadius(const SimulatedJoint* joint, ActorInstance* actorInstance, const AZ::Color& color); SimulatedObjectModel* GetSimulatedObjectModel() const; diff --git a/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.cpp b/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.cpp index e38e15d124..a44882694f 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -131,7 +132,10 @@ namespace EMotionFX return AZ::Edit::PropertyVisibility::Show; } + ////////////////////////////////////////////////////////////////////////// + AZ_ENUM_DEFINE_REFLECT_UTILITIES(ActorRenderFlags); + void ActorComponent::Configuration::Reflect(AZ::ReflectContext* context) { BoundingBoxConfiguration::Reflect(context); @@ -139,19 +143,19 @@ namespace EMotionFX auto* serializeContext = azrtti_cast(context); if (serializeContext) { + ActorRenderFlagsReflect(*serializeContext); + serializeContext->Class() - ->Version(4) + ->Version(5) ->Field("ActorAsset", &Configuration::m_actorAsset) ->Field("MaterialPerLOD", &Configuration::m_materialPerLOD) - ->Field("RenderSkeleton", &Configuration::m_renderSkeleton) - ->Field("RenderCharacter", &Configuration::m_renderCharacter) - ->Field("RenderBounds", &Configuration::m_renderBounds) ->Field("AttachmentType", &Configuration::m_attachmentType) ->Field("AttachmentTarget", &Configuration::m_attachmentTarget) ->Field("SkinningMethod", &Configuration::m_skinningMethod) ->Field("LODLevel", &Configuration::m_lodLevel) ->Field("BoundingBoxConfig", &Configuration::m_bboxConfig) ->Field("ForceJointsUpdateOOV", &Configuration::m_forceUpdateJointsOOV) + ->Field("RenderFlags", &Configuration::m_renderFlags) ; } } @@ -250,8 +254,6 @@ namespace EMotionFX { m_configuration = *configuration; } - - m_debugRenderFlags[RENDER_SOLID] = true; } ////////////////////////////////////////////////////////////////////////// @@ -344,20 +346,24 @@ namespace EMotionFX ////////////////////////////////////////////////////////////////////////// bool ActorComponent::GetRenderCharacter() const { - return m_configuration.m_renderCharacter; + return AZ::RHI::CheckBitsAny(m_configuration.m_renderFlags, ActorRenderFlags::Solid); } ////////////////////////////////////////////////////////////////////////// void ActorComponent::SetRenderCharacter(bool enable) { - if (m_configuration.m_renderCharacter != enable) + if (enable) + { + m_configuration.m_renderFlags |= ActorRenderFlags::Solid; + } + else { - m_configuration.m_renderCharacter = enable; + m_configuration.m_renderFlags &= ~ActorRenderFlags::Solid; + } - if (m_renderActorInstance) - { - m_renderActorInstance->SetIsVisible(m_configuration.m_renderCharacter); - } + if (m_renderActorInstance) + { + m_renderActorInstance->SetIsVisible(enable); } } @@ -394,9 +400,9 @@ namespace EMotionFX return m_sceneFinishSimHandler.IsConnected(); } - void ActorComponent::SetRenderFlag(ActorRenderFlagBitset renderFlags) + void ActorComponent::SetRenderFlag(ActorRenderFlags renderFlags) { - m_debugRenderFlags = renderFlags; + m_configuration.m_renderFlags = renderFlags; } void ActorComponent::CheckActorCreation() @@ -456,7 +462,7 @@ namespace EMotionFX if (m_renderActorInstance) { - m_renderActorInstance->SetIsVisible(m_configuration.m_renderCharacter); + m_renderActorInstance->SetIsVisible(AZ::RHI::CheckBitsAny(m_configuration.m_renderFlags, ActorRenderFlags::Solid)); } } @@ -563,22 +569,18 @@ namespace EMotionFX m_renderActorInstance->OnTick(deltaTime); m_renderActorInstance->UpdateBounds(); AZ::Interface::Get()->RefreshEntityLocalBoundsUnion(GetEntityId()); + const bool renderActorSolid = AZ::RHI::CheckBitsAny(m_configuration.m_renderFlags, ActorRenderFlags::Solid); // Optimization: Set the actor instance invisible when character is out of camera view. This will stop the joint transforms update, except the root joint. // Calling it after the bounds on the render actor updated. if (!m_configuration.m_forceUpdateJointsOOV) { const bool isInCameraFrustum = m_renderActorInstance->IsInCameraFrustum(); - m_actorInstance->SetIsVisible(isInCameraFrustum && m_configuration.m_renderCharacter); + m_actorInstance->SetIsVisible(isInCameraFrustum && renderActorSolid); } - m_renderActorInstance->SetIsVisible(m_debugRenderFlags[RENDER_SOLID]); - - // The configuration stores some debug option. When that is enabled, we override it on top of the render flags. - m_debugRenderFlags[RENDER_AABB] = m_debugRenderFlags[RENDER_AABB] || m_configuration.m_renderBounds; - m_debugRenderFlags[RENDER_LINESKELETON] = m_debugRenderFlags[RENDER_LINESKELETON] || m_configuration.m_renderSkeleton; - m_debugRenderFlags[RENDER_EMFX_DEBUG] = true; - m_renderActorInstance->DebugDraw(m_debugRenderFlags); + m_renderActorInstance->SetIsVisible(renderActorSolid); + m_renderActorInstance->DebugDraw(m_configuration.m_renderFlags); } } diff --git a/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.h b/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.h index 9eecea2f54..9bf2b88325 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.h +++ b/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.h @@ -82,11 +82,9 @@ namespace EMotionFX AZ::EntityId m_attachmentTarget{}; ///< Target entity this actor should attach to. size_t m_attachmentJointIndex = InvalidIndex; ///< Index of joint on target skeleton for actor attachments. AttachmentType m_attachmentType = AttachmentType::None; ///< Type of attachment. - bool m_renderSkeleton = false; ///< Toggles debug rendering of the skeleton. - bool m_renderCharacter = true; ///< Toggles rendering of the character. - bool m_renderBounds = false; ///< Toggles rendering of the character bounds used for visibility testing. SkinningMethod m_skinningMethod = SkinningMethod::DualQuat; ///< The skinning method for this actor size_t m_lodLevel = 0; + ActorRenderFlags m_renderFlags = ActorRenderFlags::Default; ///< Actor render flag // Force updating the joints when it is out of camera view. By // default, joints level update (beside the root joint) on @@ -180,7 +178,7 @@ namespace EMotionFX bool IsPhysicsSceneSimulationFinishEventConnected() const; AZ::Data::Asset GetActorAsset() const { return m_configuration.m_actorAsset; } - void SetRenderFlag(ActorRenderFlagBitset renderFlags); + void SetRenderFlag(ActorRenderFlags renderFlags); private: // AZ::TransformNotificationBus::MultiHandler @@ -202,7 +200,6 @@ namespace EMotionFX AZStd::vector m_attachments; AZStd::unique_ptr m_renderActorInstance; - ActorRenderFlagBitset m_debugRenderFlags; ///< Actor debug render flag AzPhysics::SceneEvents::OnSceneSimulationFinishHandler m_sceneFinishSimHandler; }; diff --git a/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.cpp b/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.cpp index 4292f04a08..3139e97b16 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.cpp @@ -124,12 +124,12 @@ namespace EMotionFX ->Attribute(AZ::Edit::Attributes::AutoExpand, true) ->DataElement(0, &EditorActorComponent::m_renderCharacter, "Draw character", "Toggles rendering of character mesh.") - ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorActorComponent::OnDebugDrawFlagChanged) + ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorActorComponent::OnRenderFlagChanged) ->DataElement(0, &EditorActorComponent::m_renderSkeleton, "Draw skeleton", "Toggles rendering of skeleton.") - ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorActorComponent::OnDebugDrawFlagChanged) + ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorActorComponent::OnRenderFlagChanged) ->DataElement(0, &EditorActorComponent::m_renderBounds, "Draw bounds", "Toggles rendering of world space bounding boxes.") - ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorActorComponent::OnDebugDrawFlagChanged) + ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorActorComponent::OnRenderFlagChanged) ->DataElement(AZ::Edit::UIHandlers::ComboBox, &EditorActorComponent::m_skinningMethod, "Skinning method", "Choose the skinning method this actor is using") ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorActorComponent::OnSkinningMethodChanged) @@ -180,7 +180,6 @@ namespace EMotionFX , m_lodLevel(0) , m_actorAsset(AZ::Data::AssetLoadBehavior::NoLoad) { - m_debugRenderFlags[RENDER_SOLID] = true; } ////////////////////////////////////////////////////////////////////////// @@ -198,6 +197,7 @@ namespace EMotionFX { AzToolsFramework::Components::EditorComponentBase::Activate(); + UpdateRenderFlags(); LoadActorAsset(); const AZ::EntityId entityId = GetEntityId(); @@ -363,8 +363,9 @@ namespace EMotionFX } ////////////////////////////////////////////////////////////////////////// - void EditorActorComponent::OnDebugDrawFlagChanged() + void EditorActorComponent::OnRenderFlagChanged() { + UpdateRenderFlags(); if (m_renderSkeleton || m_renderBounds || m_renderCharacter) { AZ::TickBus::Handler::BusConnect(); @@ -573,6 +574,23 @@ namespace EMotionFX ToolsApplicationEvents::Bus::Broadcast(&ToolsApplicationEvents::InvalidatePropertyDisplay, Refresh_EntireTree); } + void EditorActorComponent::UpdateRenderFlags() + { + m_renderFlags = ActorRenderFlags::None; + if (m_renderCharacter) + { + m_renderFlags |= ActorRenderFlags::Solid; + } + if (m_renderBounds) + { + m_renderFlags |= ActorRenderFlags::AABB; + } + if (m_renderSkeleton) + { + m_renderFlags |= ActorRenderFlags::LineSkeleton; + } + } + ////////////////////////////////////////////////////////////////////////// void EditorActorComponent::OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) { @@ -616,22 +634,16 @@ namespace EMotionFX { m_renderActorInstance->OnTick(deltaTime); m_renderActorInstance->UpdateBounds(); - - m_debugRenderFlags[RENDER_AABB] = m_renderBounds; - m_debugRenderFlags[RENDER_LINESKELETON] = m_renderSkeleton; - m_debugRenderFlags[RENDER_EMFX_DEBUG] = true; - m_renderActorInstance->DebugDraw(m_debugRenderFlags); + m_renderActorInstance->DebugDraw(m_renderFlags); } } void EditorActorComponent::BuildGameEntity(AZ::Entity* gameEntity) { + UpdateRenderFlags(); ActorComponent::Configuration cfg; cfg.m_actorAsset = m_actorAsset; cfg.m_materialPerLOD = m_materialPerLOD; - cfg.m_renderSkeleton = m_renderSkeleton; - cfg.m_renderCharacter = m_renderCharacter; - cfg.m_renderBounds = m_renderBounds; cfg.m_attachmentType = m_attachmentType; cfg.m_attachmentTarget = m_attachmentTarget; cfg.m_attachmentJointIndex = m_attachmentJointIndex; @@ -639,6 +651,7 @@ namespace EMotionFX cfg.m_skinningMethod = m_skinningMethod; cfg.m_bboxConfig = m_bboxConfig; cfg.m_forceUpdateJointsOOV = m_forceUpdateJointsOOV; + cfg.m_renderFlags = m_renderFlags; gameEntity->AddComponent(aznew ActorComponent(&cfg)); } @@ -861,7 +874,7 @@ namespace EMotionFX void EditorActorComponent::CheckActorCreation() { // Enable/disable debug drawing. - OnDebugDrawFlagChanged(); + OnRenderFlagChanged(); // Create actor instance. auto* actorAsset = m_actorAsset.GetAs(); @@ -964,9 +977,9 @@ namespace EMotionFX } } - void EditorActorComponent::SetRenderFlag(ActorRenderFlagBitset renderFlags) + void EditorActorComponent::SetRenderFlag(ActorRenderFlags renderFlags) { - m_debugRenderFlags = renderFlags; + m_renderFlags = renderFlags; } } //namespace Integration } // namespace EMotionFX diff --git a/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.h b/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.h index f4c663a92f..0336a0844d 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.h +++ b/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorActorComponent.h @@ -104,7 +104,7 @@ namespace EMotionFX ActorComponent::GetRequiredServices(required); } - void SetRenderFlag(ActorRenderFlagBitset renderFlags); + void SetRenderFlag(ActorRenderFlags renderFlags); static void Reflect(AZ::ReflectContext* context); @@ -114,7 +114,7 @@ namespace EMotionFX void OnMaterialChanged(); void OnMaterialPerActorChanged(); void OnLODLevelChanged(); - void OnDebugDrawFlagChanged(); + void OnRenderFlagChanged(); void OnSkinningMethodChanged(); AZ::Crc32 OnAttachmentTypeChanged(); AZ::Crc32 OnAttachmentTargetChanged(); @@ -124,6 +124,7 @@ namespace EMotionFX bool AttachmentTargetJointVisibility(); AZStd::string AttachmentJointButtonText(); void InitializeMaterial(ActorAsset& actorAsset); + void UpdateRenderFlags(); void LaunchAnimationEditor(const AZ::Data::AssetId& assetId, const AZ::Data::AssetType&); @@ -164,7 +165,7 @@ namespace EMotionFX size_t m_lodLevel; ActorComponent::BoundingBoxConfiguration m_bboxConfig; bool m_forceUpdateJointsOOV = false; - ActorRenderFlagBitset m_debugRenderFlags; ///< Actor debug render flag + ActorRenderFlags m_renderFlags; ///< Actor render flag // \todo attachmentTarget node nr // Note: LOD work in progress. For now we use one material instead of a list of material, because we don't have the support for LOD with multiple scene files. diff --git a/Gems/EMotionFX/Code/Source/Integration/Rendering/RenderActorInstance.h b/Gems/EMotionFX/Code/Source/Integration/Rendering/RenderActorInstance.h index 8afb2a2f9a..f124f352c6 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Rendering/RenderActorInstance.h +++ b/Gems/EMotionFX/Code/Source/Integration/Rendering/RenderActorInstance.h @@ -34,7 +34,7 @@ namespace EMotionFX virtual ~RenderActorInstance() = default; virtual void OnTick(float timeDelta) = 0; - virtual void DebugDraw(const EMotionFX::ActorRenderFlagBitset& renderFlags) = 0; + virtual void DebugDraw(const EMotionFX::ActorRenderFlags& renderFlags) = 0; SkinningMethod GetSkinningMethod() const; virtual void SetSkinningMethod(SkinningMethod skinningMethod); diff --git a/Gems/EMotionFX/Code/Source/Integration/Rendering/RenderFlag.h b/Gems/EMotionFX/Code/Source/Integration/Rendering/RenderFlag.h index e053eae6d5..4640fdfcb1 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Rendering/RenderFlag.h +++ b/Gems/EMotionFX/Code/Source/Integration/Rendering/RenderFlag.h @@ -7,38 +7,87 @@ */ #pragma once -#include +#include +#include namespace EMotionFX { - enum ActorRenderFlag + // The index of the render flag which is 0, 1, 2, 3.. based. + // Do not confuse this with the actual ActorRenderFlags::Type which is 1, 2, 4, 8.. based. + enum ActorRenderFlagIndex : AZ::u8 { - RENDER_SOLID = 0, - RENDER_WIREFRAME = 1, - RENDER_LIGHTING = 2, - RENDER_SHADOWS = 3, - RENDER_FACENORMALS = 4, - RENDER_VERTEXNORMALS = 5, - RENDER_TANGENTS = 6, - RENDER_AABB = 7, - RENDER_SKELETON = 8, - RENDER_LINESKELETON = 9, - RENDER_NODEORIENTATION = 10, - RENDER_NODENAMES = 11, - RENDER_GRID = 12, - RENDER_BACKFACECULLING = 13, - RENDER_ACTORBINDPOSE = 14, - RENDER_RAGDOLL_COLLIDERS = 15, - RENDER_RAGDOLL_JOINTLIMITS = 16, - RENDER_HITDETECTION_COLLIDERS = 17, - RENDER_USE_GRADIENTBACKGROUND = 18, - RENDER_MOTIONEXTRACTION = 19, - RENDER_CLOTH_COLLIDERS = 20, - RENDER_SIMULATEDOBJECT_COLLIDERS = 21, - RENDER_SIMULATEJOINTS = 22, - RENDER_EMFX_DEBUG = 23, - NUM_RENDERFLAGS = 24 + SOLID = 0, + WIREFRAME = 1, + LIGHTING = 2, + SHADOWS = 3, + FACENORMALS = 4, + VERTEXNORMALS = 5, + TANGENTS = 6, + AABB = 7, + SKELETON = 8, + LINESKELETON = 9, + NODEORIENTATION = 10, + NODENAMES = 11, + GRID = 12, + BACKFACECULLING = 13, + ACTORBINDPOSE = 14, + RAGDOLL_COLLIDERS = 15, + RAGDOLL_JOINTLIMITS = 16, + HITDETECTION_COLLIDERS = 17, + USE_GRADIENTBACKGROUND = 18, + MOTIONEXTRACTION = 19, + CLOTH_COLLIDERS = 20, + SIMULATEDOBJECT_COLLIDERS = 21, + SIMULATEJOINTS = 22, + EMFX_DEBUG = 23, + NUM_RENDERFLAGINDEXES = 24 }; - using ActorRenderFlagBitset = AZStd::bitset; + //! A set of combinable flags which indicate which render option in turned on for the actor. + AZ_ENUM_CLASS_WITH_UNDERLYING_TYPE(ActorRenderFlags, AZ::u32, + (None, 0), + (Solid, AZ_BIT(ActorRenderFlagIndex::SOLID)), + (Wireframe, AZ_BIT(ActorRenderFlagIndex::WIREFRAME)), + (Lighting, AZ_BIT(ActorRenderFlagIndex::LIGHTING)), + (Default, Solid | Lighting), + (Shadows, AZ_BIT(ActorRenderFlagIndex::SHADOWS)), + (FaceNormals, AZ_BIT(ActorRenderFlagIndex::FACENORMALS)), + (VertexNormals, AZ_BIT(ActorRenderFlagIndex::VERTEXNORMALS)), + (Tangents, AZ_BIT(ActorRenderFlagIndex::TANGENTS)), + (AABB, AZ_BIT(ActorRenderFlagIndex::AABB)), + (Skeleton, AZ_BIT(ActorRenderFlagIndex::SKELETON)), + (LineSkeleton, AZ_BIT(ActorRenderFlagIndex::LINESKELETON)), + (NodeOrientation, AZ_BIT(ActorRenderFlagIndex::NODEORIENTATION)), + (NodeNames, AZ_BIT(ActorRenderFlagIndex::NODENAMES)), + (Grid, AZ_BIT(ActorRenderFlagIndex::GRID)), + (BackfaceCulling, AZ_BIT(ActorRenderFlagIndex::BACKFACECULLING)), + (ActorBindPose, AZ_BIT(ActorRenderFlagIndex::ACTORBINDPOSE)), + (RagdollColliders, AZ_BIT(ActorRenderFlagIndex::RAGDOLL_COLLIDERS)), + (RagdollJointLimits, AZ_BIT(ActorRenderFlagIndex::RAGDOLL_JOINTLIMITS)), + (HitDetectionColliders, AZ_BIT(ActorRenderFlagIndex::HITDETECTION_COLLIDERS)), + (UseGradientBackground, AZ_BIT(ActorRenderFlagIndex::USE_GRADIENTBACKGROUND)), + (MotionExtraction, AZ_BIT(ActorRenderFlagIndex::MOTIONEXTRACTION)), + (ClothColliders, AZ_BIT(ActorRenderFlagIndex::CLOTH_COLLIDERS)), + (SimulatedObjectColliders, AZ_BIT(ActorRenderFlagIndex::SIMULATEDOBJECT_COLLIDERS)), + (SimulatedJoints, AZ_BIT(ActorRenderFlagIndex::SIMULATEJOINTS)), + (EmfxDebug, AZ_BIT(ActorRenderFlagIndex::EMFX_DEBUG)) + ); + + AZ_DEFINE_ENUM_BITWISE_OPERATORS(ActorRenderFlags); + + class ActorRenderFlagUtil + { + public: + // Check the bit value with the offset start at 0 from the right. + // CheckBit(flags, 0) means check the last digit of the flags, CheckBit(flags, 1) means the second digit from right, etc. + static bool CheckBit(ActorRenderFlags flags, AZ::u8 offset) + { + return (flags & ActorRenderFlags(AZ_BIT(offset))) != ActorRenderFlags(0); + } + }; +} + +namespace AZ +{ + AZ_TYPE_INFO_SPECIALIZE(EMotionFX::ActorRenderFlags, "{2D2187FA-2C1A-4485-AF7C-AD34C0514105}"); } diff --git a/Gems/EMotionFX/Code/Tests/RenderBackendManagerTests.cpp b/Gems/EMotionFX/Code/Tests/RenderBackendManagerTests.cpp index be990f444c..e1e092cf3d 100644 --- a/Gems/EMotionFX/Code/Tests/RenderBackendManagerTests.cpp +++ b/Gems/EMotionFX/Code/Tests/RenderBackendManagerTests.cpp @@ -65,7 +65,7 @@ namespace EMotionFX } MOCK_METHOD1(OnTick, void(float)); - MOCK_METHOD1(DebugDraw, void(const EMotionFX::ActorRenderFlagBitset&)); + MOCK_METHOD1(DebugDraw, void(const EMotionFX::ActorRenderFlags&)); MOCK_CONST_METHOD0(IsVisible, bool()); MOCK_METHOD1(SetIsVisible, void(bool)); MOCK_METHOD1(SetMaterials, void(const ActorAsset::MaterialList&));