From 74416a6b600b9f941c620a17a515fb9b54cd676c Mon Sep 17 00:00:00 2001 From: Rowland <975945824@qq.com> Date: Mon, 22 Jun 2026 16:06:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BD=91=E6=A0=BC=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 68 ++++ SandboxProject/Assets/Models/Cube.glb.mcasset | Bin 3966 -> 3966 bytes .../Private/MetaCoreEditorApp.cpp | 57 +-- .../MetaCoreRender/Private/Materials/grid.mat | 20 + .../MetaCoreEditorViewportRenderer.cpp | 4 + .../Private/MetaCoreFilamentSceneBridge.cpp | 370 ++++++++++++++++++ .../MetaCoreEditorViewportRenderer.h | 1 + .../MetaCoreFilamentSceneBridge.h | 2 + 8 files changed, 468 insertions(+), 54 deletions(-) create mode 100644 Source/MetaCoreRender/Private/Materials/grid.mat diff --git a/CMakeLists.txt b/CMakeLists.txt index 82e8e6e..dd5b68d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,18 @@ if(NOT METACORE_BUILD_CORE_ONLY) else() set(METACORE_FILAMENT_MATC "${METACORE_FILAMENT_ROOT}/bin/matc") endif() + set(METACORE_FILAMENT_MATC_RUNNABLE OFF) + if(EXISTS "${METACORE_FILAMENT_MATC}") + execute_process( + COMMAND "${METACORE_FILAMENT_MATC}" --help + RESULT_VARIABLE METACORE_FILAMENT_MATC_HELP_RESULT + OUTPUT_QUIET + ERROR_QUIET + ) + if(METACORE_FILAMENT_MATC_HELP_RESULT EQUAL 0) + set(METACORE_FILAMENT_MATC_RUNNABLE ON) + endif() + endif() set(METACORE_UI_BLIT_MATERIAL_PREBUILT "") foreach(candidate IN ITEMS @@ -151,6 +163,61 @@ if(NOT METACORE_BUILD_CORE_ONLY) VERBATIM ) endfunction() + + set(METACORE_EDITOR_GRID_MATERIAL_SOURCE "${CMAKE_SOURCE_DIR}/Source/MetaCoreRender/Private/Materials/grid.mat") + set(METACORE_EDITOR_GRID_MATERIAL_OUTPUT "${CMAKE_BINARY_DIR}/grid.filamat") + set(METACORE_EDITOR_GRID_MATERIAL_PREBUILT "") + foreach(candidate IN ITEMS + "${CMAKE_SOURCE_DIR}/Source/MetaCoreRender/Private/Materials/grid.filamat" + "${CMAKE_SOURCE_DIR}/build_filament/libs/filamentapp/generated/material/transparentColor.filamat" + ) + if(EXISTS "${candidate}") + set(METACORE_EDITOR_GRID_MATERIAL_PREBUILT "${candidate}") + break() + endif() + endforeach() + + if(METACORE_FILAMENT_MATC_RUNNABLE AND EXISTS "${METACORE_EDITOR_GRID_MATERIAL_SOURCE}") + add_custom_command( + OUTPUT "${METACORE_EDITOR_GRID_MATERIAL_OUTPUT}" + COMMAND "${METACORE_FILAMENT_MATC}" + --platform desktop + --api opengl + --output "${METACORE_EDITOR_GRID_MATERIAL_OUTPUT}" + "${METACORE_EDITOR_GRID_MATERIAL_SOURCE}" + DEPENDS + "${METACORE_EDITOR_GRID_MATERIAL_SOURCE}" + "${METACORE_FILAMENT_MATC}" + VERBATIM + ) + add_custom_target(MetaCoreEditorGridMaterial + DEPENDS "${METACORE_EDITOR_GRID_MATERIAL_OUTPUT}" + ) + elseif(METACORE_EDITOR_GRID_MATERIAL_PREBUILT) + add_custom_command( + OUTPUT "${METACORE_EDITOR_GRID_MATERIAL_OUTPUT}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${METACORE_EDITOR_GRID_MATERIAL_PREBUILT}" + "${METACORE_EDITOR_GRID_MATERIAL_OUTPUT}" + DEPENDS "${METACORE_EDITOR_GRID_MATERIAL_PREBUILT}" + VERBATIM + ) + add_custom_target(MetaCoreEditorGridMaterial + DEPENDS "${METACORE_EDITOR_GRID_MATERIAL_OUTPUT}" + ) + endif() + + function(metacore_stage_editor_grid_material target_name) + if(TARGET MetaCoreEditorGridMaterial) + add_dependencies(${target_name} MetaCoreEditorGridMaterial) + add_custom_command(TARGET ${target_name} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${METACORE_EDITOR_GRID_MATERIAL_OUTPUT}" + "$/grid.filamat" + VERBATIM + ) + endif() + endfunction() endif() add_executable(MetaCoreHeaderTool @@ -546,6 +613,7 @@ target_link_libraries(MetaCoreEditorApp MetaCoreEditor ) metacore_stage_ui_blit_material(MetaCoreEditorApp) +metacore_stage_editor_grid_material(MetaCoreEditorApp) set(METACORE_LAUNCHER_SOURCES diff --git a/SandboxProject/Assets/Models/Cube.glb.mcasset b/SandboxProject/Assets/Models/Cube.glb.mcasset index 83c4a93c1be0ae913269f69e0ebd450cb66dc450..a8d84fdc1542b3dbbbef79dc8d45311ea96b4096 100644 GIT binary patch delta 20 ccmew-_fKxa2X6N1)5Po-E>PI~ox7bG0B2JP4FCWD delta 20 ccmew-_fKxa2X6M>9v=Hk7Xvqc=Wb^P0BQ~if&c&j diff --git a/Source/MetaCoreEditor/Private/MetaCoreEditorApp.cpp b/Source/MetaCoreEditor/Private/MetaCoreEditorApp.cpp index b92c182..e7d7fb5 100644 --- a/Source/MetaCoreEditor/Private/MetaCoreEditorApp.cpp +++ b/Source/MetaCoreEditor/Private/MetaCoreEditorApp.cpp @@ -829,59 +829,6 @@ void MetaCoreDrawWorldOriginOverlay( return; } -void MetaCoreDrawViewportGridOverlay( - const MetaCoreEditorContext& editorContext, - const MetaCoreSceneViewportState& viewportState -) { - if (!editorContext.GetShowViewportGrid()) { - return; - } - if (viewportState.Width <= 1.0F || viewportState.Height <= 1.0F) { - return; - } - - ImDrawList* drawList = ImGui::GetForegroundDrawList(); - const ImVec2 topLeft(viewportState.Left, viewportState.Top); - const ImVec2 bottomRight(viewportState.Left + viewportState.Width, viewportState.Top + viewportState.Height); - const ImVec2 center((topLeft.x + bottomRight.x) * 0.5F, (topLeft.y + bottomRight.y) * 0.5F); - - const float minorSpacing = 32.0F; - const int verticalMinorCount = static_cast(viewportState.Width / minorSpacing) + 2; - const int horizontalMinorCount = static_cast(viewportState.Height / minorSpacing) + 2; - const ImU32 minorColor = IM_COL32(110, 120, 135, 40); - const ImU32 majorColor = IM_COL32(150, 165, 185, 70); - const ImU32 axisXColor = IM_COL32(220, 80, 80, 95); - const ImU32 axisYColor = IM_COL32(120, 210, 100, 95); - - for (int lineIndex = -verticalMinorCount; lineIndex <= verticalMinorCount; ++lineIndex) { - const float x = center.x + static_cast(lineIndex) * minorSpacing; - if (x < topLeft.x || x > bottomRight.x) { - continue; - } - const bool isMajor = (lineIndex % 4) == 0; - drawList->AddLine( - ImVec2(x, topLeft.y), - ImVec2(x, bottomRight.y), - lineIndex == 0 ? axisXColor : (isMajor ? majorColor : minorColor), - lineIndex == 0 ? 1.8F : (isMajor ? 1.2F : 1.0F) - ); - } - - for (int lineIndex = -horizontalMinorCount; lineIndex <= horizontalMinorCount; ++lineIndex) { - const float y = center.y + static_cast(lineIndex) * minorSpacing; - if (y < topLeft.y || y > bottomRight.y) { - continue; - } - const bool isMajor = (lineIndex % 4) == 0; - drawList->AddLine( - ImVec2(topLeft.x, y), - ImVec2(bottomRight.x, y), - lineIndex == 0 ? axisYColor : (isMajor ? majorColor : minorColor), - lineIndex == 0 ? 1.8F : (isMajor ? 1.2F : 1.0F) - ); - } -} - void MetaCoreDrawSelectionBoundsOverlay( const MetaCoreEditorContext& editorContext, const MetaCoreScene& scene, @@ -1654,6 +1601,7 @@ void MetaCoreEditorApp::DrawEditorFrame() { } // 6. 驱动 Filament 渲染 + ViewportRenderer_.SetEditorGridVisible(!isGameView && EditorContext_->GetShowViewportGrid()); if (isGameView) { if (hasGameCamera) { ViewportRenderer_.RenderSnapshotToViewport(gameViewSnapshot, &Scene_, sceneView); @@ -1740,7 +1688,6 @@ void MetaCoreEditorApp::DrawEditorFrame() { // 绘制 Overlays if (!isGameView) { - MetaCoreDrawViewportGridOverlay(*EditorContext_, viewportState); MetaCoreDrawWorldOriginOverlay(*EditorContext_, sceneView, viewportState); MetaCoreDrawSelectionBoundsOverlay(*EditorContext_, Scene_, sceneView, viewportState); MetaCoreDrawSelectionHierarchyOverlay(*EditorContext_, Scene_, sceneView, viewportState); @@ -1781,10 +1728,12 @@ void MetaCoreEditorApp::DrawEditorFrame() { // --- 补丁三重构结束 --- } else { SceneInteractionService_.ResetFrameState(); + ViewportRenderer_.SetEditorGridVisible(false); ViewportRenderer_.SetViewportRect(MetaCoreViewportRect{}); } } else { SceneInteractionService_.ResetFrameState(); + ViewportRenderer_.SetEditorGridVisible(false); ViewportRenderer_.SetViewportRect(MetaCoreViewportRect{}); } } diff --git a/Source/MetaCoreRender/Private/Materials/grid.mat b/Source/MetaCoreRender/Private/Materials/grid.mat new file mode 100644 index 0000000..ce83d1a --- /dev/null +++ b/Source/MetaCoreRender/Private/Materials/grid.mat @@ -0,0 +1,20 @@ +material { + name : MetaCoreEditorGrid, + shadingModel : unlit, + blending : transparent, + transparency : default, + depthWrite : false, + depthCulling : true, + doubleSided : true, + parameters : [ + { type : float4, name : baseColorFactor } + ], +} + +fragment { + void material(inout MaterialInputs material) { + prepareMaterial(material); + material.baseColor = materialParams.baseColorFactor; + material.baseColor.rgb *= material.baseColor.a; + } +} diff --git a/Source/MetaCoreRender/Private/MetaCoreEditorViewportRenderer.cpp b/Source/MetaCoreRender/Private/MetaCoreEditorViewportRenderer.cpp index 05217bc..c615cbb 100644 --- a/Source/MetaCoreRender/Private/MetaCoreEditorViewportRenderer.cpp +++ b/Source/MetaCoreRender/Private/MetaCoreEditorViewportRenderer.cpp @@ -127,6 +127,10 @@ void MetaCoreEditorViewportRenderer::SetProjectRootPath(const std::filesystem::p FilamentSceneBridge_.SetProjectRootPath(projectRootPath); } +void MetaCoreEditorViewportRenderer::SetEditorGridVisible(bool visible) { + FilamentSceneBridge_.SetEditorGridVisible(visible); +} + uint32_t MetaCoreEditorViewportRenderer::GetFilamentGLTextureId() const { return FilamentSceneBridge_.GetGLTextureId(); } diff --git a/Source/MetaCoreRender/Private/MetaCoreFilamentSceneBridge.cpp b/Source/MetaCoreRender/Private/MetaCoreFilamentSceneBridge.cpp index 1fcf14f..2965c3a 100644 --- a/Source/MetaCoreRender/Private/MetaCoreFilamentSceneBridge.cpp +++ b/Source/MetaCoreRender/Private/MetaCoreFilamentSceneBridge.cpp @@ -27,6 +27,9 @@ #include #include #include +#include +#include +#include #include #include @@ -52,8 +55,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -63,6 +68,8 @@ #include #include #include +#include +#include // 引入平台和 OpenGL 头文件以创建纹理 #if defined(_WIN32) @@ -377,6 +384,35 @@ public: return true; } + void SetEditorGridVisible(bool visible) { + EditorGridVisibleRequested_ = visible; + if (Engine_ == nullptr || Scene_ == nullptr) { + return; + } + + if (visible) { + if (!EnsureEditorGridRenderable()) { + return; + } + if (!EditorGridEntityInScene_) { + Scene_->addEntity(EditorGridEntity_); + EntitiesInScene_.insert(EditorGridEntity_); + EditorGridEntityInScene_ = true; + } + return; + } + + if (EditorGridEntityInScene_) { + Scene_->remove(EditorGridEntity_); + EntitiesInScene_.erase(EditorGridEntity_); + EditorGridEntityInScene_ = false; + } + } + + [[nodiscard]] bool VerifyEditorGridVisibleForTesting() const { + return EditorGridEntityInScene_; + } + void Shutdown() { if (RuntimeAssetSubscriptionId_ != 0) { MetaCoreRuntimeAssetRegistry::Get().Unsubscribe(RuntimeAssetSubscriptionId_); @@ -385,6 +421,8 @@ public: if (Engine_) { std::cout << "FilamentSceneBridge: Shutting down..." << std::endl; DebugRenderTargetState("Shutdown begin"); + + DestroyEditorGridRenderable(); // 1. 销毁所有加载的资产,切断其内部 Renderable 对克隆材质实例的占用引用 std::cout << "[DEBUG] LoadedAssets_ size: " << LoadedAssets_.size() << std::endl; @@ -2120,6 +2158,321 @@ public: } private: + struct MetaCoreEditorGridVertex { + filament::math::float3 Position{}; + }; + + struct MetaCoreEditorGridPrimitiveRange { + std::uint32_t Offset = 0; + std::uint32_t Count = 0; + }; + + [[nodiscard]] filament::Material* LoadEditorGridMaterial() { + if (Engine_ == nullptr) { + return nullptr; + } + + const std::array candidatePaths{ + std::filesystem::path("grid.filamat"), + std::filesystem::path("../grid.filamat"), + std::filesystem::path("build/grid.filamat"), + std::filesystem::path("build/linux-full-clang-libcxx-debug/grid.filamat"), + std::filesystem::path("build_filament/libs/filamentapp/generated/material/transparentColor.filamat"), + std::filesystem::path("../build_filament/libs/filamentapp/generated/material/transparentColor.filamat"), + std::filesystem::path("../../build_filament/libs/filamentapp/generated/material/transparentColor.filamat"), + std::filesystem::path("../../../build_filament/libs/filamentapp/generated/material/transparentColor.filamat") + }; + + for (const std::filesystem::path& candidate : candidatePaths) { + std::ifstream file(candidate, std::ios::binary); + if (!file.is_open()) { + continue; + } + + std::vector buffer( + (std::istreambuf_iterator(file)), + std::istreambuf_iterator() + ); + if (buffer.empty()) { + continue; + } + + filament::Material* material = filament::Material::Builder() + .package(buffer.data(), buffer.size()) + .build(*Engine_); + if (material != nullptr) { + MetaCoreFilamentDebugLog("Editor grid material loaded path=\"" + candidate.generic_string() + "\""); + return material; + } + } + + MetaCoreFilamentDebugLog("Editor grid material not found; using Filament default material fallback"); + return nullptr; + } + + void SetEditorGridMaterialColor( + filament::MaterialInstance& materialInstance, + filament::math::float4 color + ) const { + materialInstance.setColorWrite(true); + materialInstance.setDepthWrite(false); + materialInstance.setDepthCulling(true); + materialInstance.setCullingMode(filament::backend::CullingMode::NONE); + + const filament::Material* material = materialInstance.getMaterial(); + if (material == nullptr) { + return; + } + + const auto setColorIfPresent = [&](const char* parameterName) -> bool { + if (!material->hasParameter(parameterName)) { + return false; + } + materialInstance.setParameter(parameterName, filament::RgbaType::LINEAR, color); + return true; + }; + + if (setColorIfPresent("baseColor") || + setColorIfPresent("baseColorFactor") || + setColorIfPresent("color") || + setColorIfPresent("albedo")) { + return; + } + } + + [[nodiscard]] bool EnsureEditorGridRenderable() { + if (EditorGridBuilt_) { + return true; + } + if (Engine_ == nullptr || Scene_ == nullptr) { + return false; + } + + EditorGridMaterial_ = LoadEditorGridMaterial(); + const filament::Material* material = + EditorGridMaterial_ != nullptr ? EditorGridMaterial_ : Engine_->getDefaultMaterial(); + if (material == nullptr) { + return false; + } + + constexpr int gridExtent = 100; + constexpr int majorStep = 10; + enum class GridLineKind : std::size_t { + Minor = 0, + Major = 1, + AxisX = 2, + AxisY = 3, + Count = 4 + }; + + std::array, static_cast(GridLineKind::Count)> groupedVertices; + const auto appendLine = [&]( + GridLineKind kind, + float x0, + float y0, + float x1, + float y1 + ) { + auto& vertices = groupedVertices[static_cast(kind)]; + vertices.push_back(MetaCoreEditorGridVertex{filament::math::float3{x0, y0, 0.0F}}); + vertices.push_back(MetaCoreEditorGridVertex{filament::math::float3{x1, y1, 0.0F}}); + }; + + for (int coordinate = -gridExtent; coordinate <= gridExtent; ++coordinate) { + const bool isMajor = coordinate != 0 && (coordinate % majorStep) == 0; + const GridLineKind verticalKind = coordinate == 0 + ? GridLineKind::AxisY + : (isMajor ? GridLineKind::Major : GridLineKind::Minor); + appendLine( + verticalKind, + static_cast(coordinate), + static_cast(-gridExtent), + static_cast(coordinate), + static_cast(gridExtent) + ); + + const GridLineKind horizontalKind = coordinate == 0 + ? GridLineKind::AxisX + : (isMajor ? GridLineKind::Major : GridLineKind::Minor); + appendLine( + horizontalKind, + static_cast(-gridExtent), + static_cast(coordinate), + static_cast(gridExtent), + static_cast(coordinate) + ); + } + + std::vector vertices; + std::vector indices; + vertices.reserve((gridExtent * 2 + 1) * 4); + indices.reserve((gridExtent * 2 + 1) * 4); + + std::array(GridLineKind::Count)> ranges{}; + for (std::size_t kindIndex = 0; kindIndex < groupedVertices.size(); ++kindIndex) { + ranges[kindIndex].Offset = static_cast(indices.size()); + for (const MetaCoreEditorGridVertex& vertex : groupedVertices[kindIndex]) { + if (vertices.size() > std::numeric_limits::max()) { + return false; + } + vertices.push_back(vertex); + indices.push_back(static_cast(vertices.size() - 1)); + } + ranges[kindIndex].Count = static_cast(indices.size() - ranges[kindIndex].Offset); + } + + if (vertices.empty() || indices.empty()) { + return false; + } + + EditorGridVertexBuffer_ = filament::VertexBuffer::Builder() + .vertexCount(vertices.size()) + .bufferCount(1) + .attribute( + filament::VertexAttribute::POSITION, + 0, + filament::VertexBuffer::AttributeType::FLOAT3, + offsetof(MetaCoreEditorGridVertex, Position), + sizeof(MetaCoreEditorGridVertex) + ) + .build(*Engine_); + EditorGridIndexBuffer_ = filament::IndexBuffer::Builder() + .indexCount(indices.size()) + .bufferType(filament::IndexBuffer::IndexType::USHORT) + .build(*Engine_); + if (EditorGridVertexBuffer_ == nullptr || EditorGridIndexBuffer_ == nullptr) { + DestroyEditorGridRenderable(); + return false; + } + + const size_t vertexDataSize = vertices.size() * sizeof(MetaCoreEditorGridVertex); + void* vertexData = std::malloc(vertexDataSize); + if (vertexData == nullptr) { + DestroyEditorGridRenderable(); + return false; + } + std::memcpy(vertexData, vertices.data(), vertexDataSize); + EditorGridVertexBuffer_->setBufferAt( + *Engine_, + 0, + filament::VertexBuffer::BufferDescriptor( + vertexData, + vertexDataSize, + [](void* buffer, size_t, void*) { + std::free(buffer); + }, + nullptr + ) + ); + + const size_t indexDataSize = indices.size() * sizeof(std::uint16_t); + void* indexData = std::malloc(indexDataSize); + if (indexData == nullptr) { + DestroyEditorGridRenderable(); + return false; + } + std::memcpy(indexData, indices.data(), indexDataSize); + EditorGridIndexBuffer_->setBuffer( + *Engine_, + filament::IndexBuffer::BufferDescriptor( + indexData, + indexDataSize, + [](void* buffer, size_t, void*) { + std::free(buffer); + }, + nullptr + ) + ); + + const std::array(GridLineKind::Count)> colors{ + filament::math::float4{0.48F, 0.52F, 0.60F, 0.22F}, + filament::math::float4{0.62F, 0.68F, 0.78F, 0.36F}, + filament::math::float4{0.86F, 0.22F, 0.22F, 0.58F}, + filament::math::float4{0.42F, 0.82F, 0.26F, 0.58F} + }; + for (std::size_t kindIndex = 0; kindIndex < EditorGridMaterialInstances_.size(); ++kindIndex) { + EditorGridMaterialInstances_[kindIndex] = material->createInstance(); + if (EditorGridMaterialInstances_[kindIndex] == nullptr) { + DestroyEditorGridRenderable(); + return false; + } + SetEditorGridMaterialColor(*EditorGridMaterialInstances_[kindIndex], colors[kindIndex]); + } + + EditorGridEntity_ = utils::EntityManager::get().create(); + auto builder = filament::RenderableManager::Builder(static_cast(GridLineKind::Count)); + builder + .boundingBox({{0.0F, 0.0F, 0.0F}, {static_cast(gridExtent), static_cast(gridExtent), 0.05F}}) + .culling(false) + .castShadows(false) + .receiveShadows(false); + + for (std::size_t kindIndex = 0; kindIndex < ranges.size(); ++kindIndex) { + builder + .geometry( + kindIndex, + filament::RenderableManager::PrimitiveType::LINES, + EditorGridVertexBuffer_, + EditorGridIndexBuffer_, + ranges[kindIndex].Offset, + ranges[kindIndex].Count + ) + .material(kindIndex, EditorGridMaterialInstances_[kindIndex]) + .blendOrder(kindIndex, static_cast(kindIndex)); + } + + if (static_cast(builder.build(*Engine_, EditorGridEntity_)) != 0) { + DestroyEditorGridRenderable(); + return false; + } + + EditorGridBuilt_ = true; + return true; + } + + void DestroyEditorGridRenderable() { + if (Engine_ == nullptr) { + return; + } + + if (EditorGridEntityInScene_ && Scene_ != nullptr) { + Scene_->remove(EditorGridEntity_); + EntitiesInScene_.erase(EditorGridEntity_); + EditorGridEntityInScene_ = false; + } + + if (EditorGridEntity_) { + auto& renderableManager = Engine_->getRenderableManager(); + if (renderableManager.getInstance(EditorGridEntity_)) { + renderableManager.destroy(EditorGridEntity_); + } + Engine_->destroy(EditorGridEntity_); + utils::EntityManager::get().destroy(EditorGridEntity_); + EditorGridEntity_ = {}; + } + + for (filament::MaterialInstance*& materialInstance : EditorGridMaterialInstances_) { + if (materialInstance != nullptr) { + Engine_->destroy(materialInstance); + materialInstance = nullptr; + } + } + if (EditorGridVertexBuffer_ != nullptr) { + Engine_->destroy(EditorGridVertexBuffer_); + EditorGridVertexBuffer_ = nullptr; + } + if (EditorGridIndexBuffer_ != nullptr) { + Engine_->destroy(EditorGridIndexBuffer_); + EditorGridIndexBuffer_ = nullptr; + } + if (EditorGridMaterial_ != nullptr) { + Engine_->destroy(EditorGridMaterial_); + EditorGridMaterial_ = nullptr; + } + + EditorGridBuilt_ = false; + } + bool EntityBelongsToAsset(filament::gltfio::FilamentAsset* asset, utils::Entity entity) const { if (asset == nullptr || entity.isNull()) { return false; @@ -2518,6 +2871,15 @@ private: std::unordered_map SceneLightEntities_; std::unordered_set EntitiesInScene_; + bool EditorGridVisibleRequested_ = false; + bool EditorGridBuilt_ = false; + bool EditorGridEntityInScene_ = false; + utils::Entity EditorGridEntity_{}; + filament::VertexBuffer* EditorGridVertexBuffer_ = nullptr; + filament::IndexBuffer* EditorGridIndexBuffer_ = nullptr; + filament::Material* EditorGridMaterial_ = nullptr; + std::array EditorGridMaterialInstances_{}; + filament::View* UIView_ = nullptr; MetaCoreImGuiHelper* ImGuiHelper_ = nullptr; @@ -2571,6 +2933,10 @@ void MetaCoreFilamentSceneBridge::ApplySceneView(const MetaCoreSceneView& sceneV Impl_->ApplySceneView(sceneView); } +void MetaCoreFilamentSceneBridge::SetEditorGridVisible(bool visible) { + Impl_->SetEditorGridVisible(visible); +} + void MetaCoreFilamentSceneBridge::RenderAll() { Impl_->RenderAll(); } @@ -2615,4 +2981,8 @@ bool MetaCoreFilamentSceneBridge::VerifyEntityInSceneForTesting(MetaCoreId objec return Impl_->VerifyEntityInSceneForTesting(objectId); } +bool MetaCoreFilamentSceneBridge::VerifyEditorGridVisibleForTesting() const { + return Impl_->VerifyEditorGridVisibleForTesting(); +} + } // namespace MetaCore diff --git a/Source/MetaCoreRender/Public/MetaCoreRender/MetaCoreEditorViewportRenderer.h b/Source/MetaCoreRender/Public/MetaCoreRender/MetaCoreEditorViewportRenderer.h index b496e1f..78ea740 100644 --- a/Source/MetaCoreRender/Public/MetaCoreRender/MetaCoreEditorViewportRenderer.h +++ b/Source/MetaCoreRender/Public/MetaCoreRender/MetaCoreEditorViewportRenderer.h @@ -23,6 +23,7 @@ public: void RenderSnapshotToViewport(const MetaCoreSceneRenderSyncSnapshot& snapshot, MetaCoreScene* scene, const MetaCoreSceneView& sceneView); void RenderAll(); void SetProjectRootPath(const std::filesystem::path& projectRootPath); + void SetEditorGridVisible(bool visible); [[nodiscard]] uint32_t GetFilamentGLTextureId() const; [[nodiscard]] void* GetFilamentTexturePointer() const; diff --git a/Source/MetaCoreRender/Public/MetaCoreRender/MetaCoreFilamentSceneBridge.h b/Source/MetaCoreRender/Public/MetaCoreRender/MetaCoreFilamentSceneBridge.h index 6f30872..3126479 100644 --- a/Source/MetaCoreRender/Public/MetaCoreRender/MetaCoreFilamentSceneBridge.h +++ b/Source/MetaCoreRender/Public/MetaCoreRender/MetaCoreFilamentSceneBridge.h @@ -30,6 +30,7 @@ public: void SyncScene(MetaCoreScene& scene, bool compatibilityMeshOnly = false, bool useScenePrimaryCamera = false); void SyncScene(const MetaCoreSceneRenderSyncSnapshot& snapshot, MetaCoreScene* scene = nullptr, bool compatibilityMeshOnly = false, bool useScenePrimaryCamera = false); void ApplySceneView(const MetaCoreSceneView& sceneView); + void SetEditorGridVisible(bool visible); void RenderAll(); [[nodiscard]] uint32_t GetGLTextureId() const; [[nodiscard]] void* GetFilamentTexturePointer() const; @@ -43,6 +44,7 @@ public: [[nodiscard]] bool VerifyLightExistsForTesting(MetaCoreId objectId) const; [[nodiscard]] float GetDefaultLightIntensityForTesting() const; [[nodiscard]] bool VerifyEntityInSceneForTesting(MetaCoreId objectId) const; + [[nodiscard]] bool VerifyEditorGridVisibleForTesting() const; private: class MetaCoreFilamentSceneBridgeImpl;