/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/EditorPlugins/Assets/EditorPluginAssets/AnimatedMeshAsset/AnimatedMeshAssetWindow.moc.cpp
241 строка
7 KB
Jan Krassnigg
Mesh asset improvements (camera mode, material picking, colmeshes with many materials (#1852)
08 мар 2026, 16:32
Не верифицирован
08 мар 2026, 16:32
b0c0266
Код
Авторство
О чём код?
#include <EditorPluginAssets/EditorPluginAssetsPCH.h> #include <EditorFramework/Assets/AssetStatusIndicator.moc.h> #include <EditorFramework/DocumentWindow/OrbitCamViewWidget.moc.h> #include <EditorFramework/InputContexts/CameraMoveContext.h> #include <EditorFramework/InputContexts/OrbitCameraContext.h> #include <EditorPluginAssets/AnimatedMeshAsset/AnimatedMeshAssetWindow.moc.h> #include <GuiFoundation/ActionViews/MenuBarActionMapView.moc.h> #include <GuiFoundation/ActionViews/ToolBarActionMapView.moc.h> #include <GuiFoundation/DockPanels/DocumentPanel.moc.h> #include <GuiFoundation/PropertyGrid/PropertyGridWidget.moc.h> #include <SharedPluginAssets/Common/Messages.h> ezQtAnimatedMeshAssetDocumentWindow::ezQtAnimatedMeshAssetDocumentWindow(ezAnimatedMeshAssetDocument* pDocument) : ezQtEngineDocumentWindow(pDocument) { GetDocument()->GetObjectManager()->m_PropertyEvents.AddEventHandler(ezMakeDelegate(&ezQtAnimatedMeshAssetDocumentWindow::PropertyEventHandler, this)); // Menu Bar { ezQtMenuBarActionMapView* pMenuBar = static_cast<ezQtMenuBarActionMapView*>(menuBar()); ezActionContext context; context.m_sMapping = "AnimatedMeshAssetMenuBar"; context.m_pDocument = pDocument; context.m_pWindow = this; pMenuBar->SetActionContext(context); } // Tool Bar { ezQtToolBarActionMapView* pToolBar = new ezQtToolBarActionMapView("Toolbar", this); ezActionContext context; context.m_sMapping = "AnimatedMeshAssetToolBar"; context.m_pDocument = pDocument; context.m_pWindow = this; pToolBar->SetActionContext(context); pToolBar->setObjectName("AnimatedMeshAssetWindowToolBar"); addToolBar(pToolBar); } // 3D View ezQtViewWidgetContainer* pContainer = nullptr; { SetTargetFramerate(25); m_ViewConfig.m_Camera.LookAt(ezVec3(-1.6f, 0, 0), ezVec3(0, 0, 0), ezVec3(0, 0, 1)); m_ViewConfig.ApplyPerspectiveSetting(90); m_pViewWidget = new ezQtOrbitCamViewWidget(this, &m_ViewConfig); m_pViewWidget->ConfigureRelative(ezVec3(0, 0, 1), ezVec3(10.0f), ezVec3(5, -2, 3), 2.0f); AddViewWidget(m_pViewWidget); m_pCameraFlyContext = EZ_DEFAULT_NEW(ezCameraMoveContext, this, m_pViewWidget); m_pCameraFlyContext->SetCamera(&m_ViewConfig.m_Camera); m_pCameraFlyContext->LoadState(); pContainer = new ezQtViewWidgetContainer(GetContainerWindow()->GetDockManager(), this, m_pViewWidget, "AnimatedMeshAssetViewToolBar"); m_pDockManager->setCentralWidget(pContainer); } // Property Grid { ezQtDocumentPanel* pPropertyPanel = new ezQtDocumentPanel(GetContainerWindow()->GetDockManager(), this, pDocument); pPropertyPanel->setObjectName("AnimatedMeshAssetDockWidget"); pPropertyPanel->setWindowTitle("Mesh Properties"); pPropertyPanel->show(); ezQtPropertyGridWidget* pPropertyGrid = new ezQtPropertyGridWidget(pPropertyPanel, pDocument); QWidget* pWidget = new QWidget(); pWidget->setObjectName("Group"); pWidget->setLayout(new QVBoxLayout()); pWidget->setContentsMargins(0, 0, 0, 0); pWidget->layout()->setContentsMargins(0, 0, 0, 0); pWidget->layout()->addWidget(new ezQtAssetStatusIndicator(GetDocument())); pWidget->layout()->addWidget(pPropertyGrid); pPropertyPanel->setWidget(pWidget, ads::CDockWidget::ForceNoScrollArea); m_pDockManager->addDockWidgetTab(ads::RightDockWidgetArea, pPropertyPanel); pDocument->GetSelectionManager()->SetSelection(pDocument->GetObjectManager()->GetRootObject()->GetChildren()[0]); } FinishWindowCreation(); UpdatePreview(); m_pHighlightTimer = new QTimer(); connect(m_pHighlightTimer, &QTimer::timeout, this, &ezQtAnimatedMeshAssetDocumentWindow::HighlightTimer); m_pHighlightTimer->setInterval(500); m_pHighlightTimer->start(); } ezQtAnimatedMeshAssetDocumentWindow::~ezQtAnimatedMeshAssetDocumentWindow() { m_pHighlightTimer->stop(); GetDocument()->GetObjectManager()->m_PropertyEvents.RemoveEventHandler(ezMakeDelegate(&ezQtAnimatedMeshAssetDocumentWindow::PropertyEventHandler, this)); } ezAnimatedMeshAssetDocument* ezQtAnimatedMeshAssetDocumentWindow::GetMeshDocument() { return static_cast<ezAnimatedMeshAssetDocument*>(GetDocument()); } void ezQtAnimatedMeshAssetDocumentWindow::SetCameraMode(int iMode) { if (m_iCameraMode == iMode) return; m_iCameraMode = iMode; m_pViewWidget->m_InputContexts.Clear(); if (iMode == 0) // Orbit m_pViewWidget->m_InputContexts.PushBack(m_pViewWidget->GetOrbitCamera()); else // Free fly m_pViewWidget->m_InputContexts.PushBack(m_pCameraFlyContext.Borrow()); } void ezQtAnimatedMeshAssetDocumentWindow::SendRedrawMsg() { // do not try to redraw while the process is crashed, it is obviously futile if (ezEditorEngineProcessConnection::GetSingleton()->IsProcessCrashed()) return; for (auto pView : m_ViewWidgets) { pView->SetEnablePicking(false); pView->UpdateCameraInterpolation(); pView->SyncToEngine(); } QueryObjectBBox(); } void ezQtAnimatedMeshAssetDocumentWindow::QueryObjectBBox(ezInt32 iPurpose /* = 0*/) { ezQuerySelectionBBoxMsgToEngine msg; msg.m_uiViewID = 0xFFFFFFFF; msg.m_iPurpose = iPurpose; GetDocument()->SendMessageToEngine(&msg); } void ezQtAnimatedMeshAssetDocumentWindow::PropertyEventHandler(const ezDocumentObjectPropertyEvent& e) { // if (e.m_sProperty == "Resource") // any material change { UpdatePreview(); } } bool ezQtAnimatedMeshAssetDocumentWindow::UpdatePreview() { if (ezEditorEngineProcessConnection::GetSingleton()->IsProcessCrashed()) return false; if (GetMeshDocument()->GetProperties() == nullptr) return false; const auto& materials = GetMeshDocument()->GetProperties()->m_Slots; ezEditorEngineSetMaterialsMsg msg; msg.m_Materials.SetCount(materials.GetCount()); ezUInt32 uiSlot = 0; bool bHighlighted = false; for (ezUInt32 i = 0; i < materials.GetCount(); ++i) { msg.m_Materials[i] = materials[i].m_sResource; if (materials[i].m_bHighlight) { if (uiSlot == m_uiHighlightSlots) { bHighlighted = true; msg.m_Materials[i] = "Editor/Materials/HighlightMesh.ezMaterial"; } ++uiSlot; } } GetEditorEngineConnection()->SendMessage(&msg); return bHighlighted; } void ezQtAnimatedMeshAssetDocumentWindow::InternalRedraw() { ezEditorInputContext::UpdateActiveInputContext(); SendRedrawMsg(); ezQtEngineDocumentWindow::InternalRedraw(); } void ezQtAnimatedMeshAssetDocumentWindow::ProcessMessageEventHandler(const ezEditorEngineDocumentMsg* pMsg) { if (pMsg->GetDynamicRTTI()->IsDerivedFrom<ezQuerySelectionBBoxResultMsgToEditor>()) { const ezQuerySelectionBBoxResultMsgToEditor* pMessage = static_cast<const ezQuerySelectionBBoxResultMsgToEditor*>(pMsg); if (pMessage->m_vCenter.IsValid() && pMessage->m_vHalfExtents.IsValid()) { m_pViewWidget->SetOrbitVolume(pMessage->m_vCenter, pMessage->m_vHalfExtents.CompMax(ezVec3(0.1f))); } else { // try again QueryObjectBBox(pMessage->m_iPurpose); } return; } ezQtEngineDocumentWindow::ProcessMessageEventHandler(pMsg); } void ezQtAnimatedMeshAssetDocumentWindow::HighlightTimer() { if (m_uiHighlightSlots & EZ_BIT(31)) m_uiHighlightSlots &= ~EZ_BIT(31); else m_uiHighlightSlots |= EZ_BIT(31); if (m_uiHighlightSlots & EZ_BIT(31)) { UpdatePreview(); } else { if (UpdatePreview()) { ++m_uiHighlightSlots; } else { m_uiHighlightSlots = EZ_BIT(31); } } }