/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/EditorPlugins/Scene/EditorPluginScene/EditTools/GreyBoxEditTool.cpp
241 строка
7 KB
Jan Krassnigg
Migrate code to use Make* functions (#1022)
03 авг 2023, 08:07
Не верифицирован
03 авг 2023, 08:07
c42cf1d
Код
Авторство
О чём код?
#include <EditorPluginScene/EditorPluginScenePCH.h> #include <EditorFramework/Assets/AssetCurator.h> #include <EditorFramework/DocumentWindow/EngineViewWidget.moc.h> #include <EditorFramework/DocumentWindow/GameObjectDocumentWindow.moc.h> #include <EditorFramework/Gizmos/SnapProvider.h> #include <EditorFramework/Panels/AssetBrowserPanel/AssetBrowserPanel.moc.h> #include <EditorFramework/Preferences/ScenePreferences.h> #include <EditorPluginScene/EditTools/GreyBoxEditTool.h> #include <GuiFoundation/PropertyGrid/ManipulatorManager.h> #include <ToolsFoundation/Command/TreeCommands.h> EZ_BEGIN_DYNAMIC_REFLECTED_TYPE(ezGreyBoxEditTool, 1, ezRTTIDefaultAllocator<ezGreyBoxEditTool>) EZ_END_DYNAMIC_REFLECTED_TYPE; ezGreyBoxEditTool::ezGreyBoxEditTool() { m_DrawBoxGizmo.m_GizmoEvents.AddEventHandler(ezMakeDelegate(&ezGreyBoxEditTool::GizmoEventHandler, this)); } ezGreyBoxEditTool::~ezGreyBoxEditTool() { m_DrawBoxGizmo.m_GizmoEvents.RemoveEventHandler(ezMakeDelegate(&ezGreyBoxEditTool::GizmoEventHandler, this)); } ezEditorInputContext* ezGreyBoxEditTool::GetEditorInputContextOverride() { if (IsActive()) return &m_DrawBoxGizmo; return nullptr; } ezEditToolSupportedSpaces ezGreyBoxEditTool::GetSupportedSpaces() const { return ezEditToolSupportedSpaces::WorldSpaceOnly; } bool ezGreyBoxEditTool::GetSupportsMoveParentOnly() const { return false; } void ezGreyBoxEditTool::GetGridSettings(ezGridSettingsMsgToEngine& ref_msg) { ezScenePreferencesUser* pPreferences = ezPreferences::QueryPreferences<ezScenePreferencesUser>(GetDocument()); ref_msg.m_fGridDensity = ezSnapProvider::GetTranslationSnapValue(); // negative density = local space ref_msg.m_vGridTangent1.SetZero(); ref_msg.m_vGridTangent2.SetZero(); if (pPreferences->GetShowGrid()) { if (m_DrawBoxGizmo.GetCurrentMode() == ezDrawBoxGizmo::ManipulateMode::DrawBase) { ref_msg.m_vGridCenter = m_DrawBoxGizmo.GetStartPosition(); ref_msg.m_vGridTangent1 = ezVec3(1, 0, 0); ref_msg.m_vGridTangent2 = ezVec3(0, 1, 0); } else if (m_DrawBoxGizmo.GetCurrentMode() == ezDrawBoxGizmo::ManipulateMode::DrawHeight) { const ezVec3 vCamDir = GetWindow()->GetFocusedViewWidget()->m_pViewConfig->m_Camera.GetDirForwards(); ref_msg.m_vGridCenter = m_DrawBoxGizmo.GetStartPosition(); if (ezMath::Abs(ezVec3(1, 0, 0).Dot(vCamDir)) < ezMath::Abs(ezVec3(0, 1, 0).Dot(vCamDir))) { ref_msg.m_vGridTangent1 = ezVec3(1, 0, 0); ref_msg.m_vGridTangent2 = ezVec3(0, 0, 1); } else { ref_msg.m_vGridTangent1 = ezVec3(0, 1, 0); ref_msg.m_vGridTangent2 = ezVec3(0, 0, 1); } } else if (m_DrawBoxGizmo.GetCurrentMode() == ezDrawBoxGizmo::ManipulateMode::None) { if (m_DrawBoxGizmo.GetDisplayGrid()) { ref_msg.m_vGridCenter = m_DrawBoxGizmo.GetStartPosition(); ref_msg.m_vGridTangent1 = ezVec3(1, 0, 0); ref_msg.m_vGridTangent2 = ezVec3(0, 1, 0); } } } } void ezGreyBoxEditTool::UpdateGizmoState() { ezManipulatorManager::GetSingleton()->HideActiveManipulator(GetDocument(), GetDocument()->GetActiveEditTool() != nullptr); m_DrawBoxGizmo.SetVisible(IsActive()); m_DrawBoxGizmo.SetTransformation(ezTransform::MakeIdentity()); } void ezGreyBoxEditTool::GameObjectEventHandler(const ezGameObjectEvent& e) { switch (e.m_Type) { case ezGameObjectEvent::Type::ActiveEditToolChanged: UpdateGizmoState(); break; default: break; } } void ezGreyBoxEditTool::ManipulatorManagerEventHandler(const ezManipulatorManagerEvent& e) { if (!IsActive()) return; // make sure the gizmo is deactivated when a manipulator becomes active if (e.m_pDocument == GetDocument() && e.m_pManipulator != nullptr && e.m_pSelection != nullptr && !e.m_pSelection->IsEmpty() && !e.m_bHideManipulators) { GetDocument()->SetActiveEditTool(nullptr); } } void ezGreyBoxEditTool::OnConfigured() { GetDocument()->m_GameObjectEvents.AddEventHandler(ezMakeDelegate(&ezGreyBoxEditTool::GameObjectEventHandler, this)); ezManipulatorManager::GetSingleton()->m_Events.AddEventHandler(ezMakeDelegate(&ezGreyBoxEditTool::ManipulatorManagerEventHandler, this)); m_DrawBoxGizmo.SetOwner(GetWindow(), nullptr); } void ezGreyBoxEditTool::OnActiveChanged(bool bIsActive) { if (bIsActive) { m_DrawBoxGizmo.UpdateStatusBarText(GetWindow()); } } void ezGreyBoxEditTool::GizmoEventHandler(const ezGizmoEvent& e) { if (e.m_Type == ezGizmoEvent::Type::EndInteractions) { ezVec3 vCenter; float negx, posx, negy, posy, negz, posz; m_DrawBoxGizmo.GetResult(vCenter, negx, posx, negy, posy, negz, posz); auto* pDoc = GetDocument(); auto* pHistory = pDoc->GetCommandHistory(); ezUuid materialGuid; // check if there is a material asset currently selected in the asset browser // if so, assign that material to the greybox component { const ezUuid lastSelected = ezQtAssetBrowserPanel::GetSingleton()->GetLastSelectedAsset(); if (lastSelected.IsValid()) { const auto pSubAsset = ezAssetCurator::GetSingleton()->GetSubAsset(lastSelected); if (pSubAsset && ezStringUtils::IsEqual(pSubAsset->m_pAssetInfo->m_Info->GetAssetsDocumentTypeName(), "Material")) { materialGuid = lastSelected; } } } pHistory->StartTransaction("Add Grey-Box"); ezUuid objGuid, compGuid; objGuid = ezUuid::MakeUuid(); compGuid = ezUuid::MakeUuid(); { ezAddObjectCommand cmdAdd; cmdAdd.m_NewObjectGuid = objGuid; cmdAdd.m_pType = ezGetStaticRTTI<ezGameObject>(); cmdAdd.m_sParentProperty = "Children"; pHistory->AddCommand(cmdAdd).AssertSuccess(); } { ezSetObjectPropertyCommand cmdPos; cmdPos.m_NewValue = vCenter; cmdPos.m_Object = objGuid; cmdPos.m_sProperty = "LocalPosition"; pHistory->AddCommand(cmdPos).AssertSuccess(); } { ezAddObjectCommand cmdComp; cmdComp.m_NewObjectGuid = compGuid; cmdComp.m_pType = ezRTTI::FindTypeByName("ezGreyBoxComponent"); cmdComp.m_sParentProperty = "Components"; cmdComp.m_Parent = objGuid; cmdComp.m_Index = -1; pHistory->AddCommand(cmdComp).AssertSuccess(); } if (materialGuid.IsValid()) { ezStringBuilder tmp; ezSetObjectPropertyCommand cmdMat; cmdMat.m_NewValue = ezConversionUtils::ToString(materialGuid, tmp).GetData(); cmdMat.m_Object = compGuid; cmdMat.m_sProperty = "Material"; pHistory->AddCommand(cmdMat).AssertSuccess(); } { ezSetObjectPropertyCommand cmdSize; cmdSize.m_Object = compGuid; cmdSize.m_NewValue = negx; cmdSize.m_sProperty = "SizeNegX"; pHistory->AddCommand(cmdSize).AssertSuccess(); cmdSize.m_NewValue = posx; cmdSize.m_sProperty = "SizePosX"; pHistory->AddCommand(cmdSize).AssertSuccess(); cmdSize.m_NewValue = negy; cmdSize.m_sProperty = "SizeNegY"; pHistory->AddCommand(cmdSize).AssertSuccess(); cmdSize.m_NewValue = posy; cmdSize.m_sProperty = "SizePosY"; pHistory->AddCommand(cmdSize).AssertSuccess(); cmdSize.m_NewValue = negz; cmdSize.m_sProperty = "SizeNegZ"; pHistory->AddCommand(cmdSize).AssertSuccess(); cmdSize.m_NewValue = posz; cmdSize.m_sProperty = "SizePosZ"; pHistory->AddCommand(cmdSize).AssertSuccess(); } pHistory->FinishTransaction(); pDoc->GetSelectionManager()->SetSelection(pDoc->GetObjectManager()->GetObject(objGuid)); } }