From 278575c3e2e1490cfe56f66e4c83c530f48eebc1 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Wed, 11 Dec 2024 21:04:57 +0800 Subject: [PATCH] internal: add bounding box to SceneAsset & subclasses --- .../native/include/scene/GeometrySceneAsset.hpp | 10 ++++++++-- thermion_dart/native/include/scene/GltfSceneAsset.hpp | 4 ++++ .../native/include/scene/GltfSceneAssetInstance.hpp | 4 ++++ thermion_dart/native/include/scene/SceneAsset.hpp | 3 +++ thermion_dart/native/src/scene/GltfSceneAsset.cpp | 6 +++++- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/thermion_dart/native/include/scene/GeometrySceneAsset.hpp b/thermion_dart/native/include/scene/GeometrySceneAsset.hpp index 9ce5432b..361680b2 100644 --- a/thermion_dart/native/include/scene/GeometrySceneAsset.hpp +++ b/thermion_dart/native/include/scene/GeometrySceneAsset.hpp @@ -53,7 +53,14 @@ namespace thermion return _materialInstanceCount; } - const Box &getBoundingBox() const { return _boundingBox; } + const Aabb getBoundingBox() const override + { + return Aabb { + + .min = _boundingBox.getMin(), // center - halfExtent + .max = _boundingBox.getMax() // center + halfExtent + }; + } VertexBuffer *getVertexBuffer() const { return _vertexBuffer; } IndexBuffer *getIndexBuffer() const { return _indexBuffer; } @@ -137,7 +144,6 @@ namespace thermion utils::Entity _entity; RenderableManager::PrimitiveType _primitiveType; std::vector> _instances; - }; } // namespace thermion \ No newline at end of file diff --git a/thermion_dart/native/include/scene/GltfSceneAsset.hpp b/thermion_dart/native/include/scene/GltfSceneAsset.hpp index d954880e..6db31079 100644 --- a/thermion_dart/native/include/scene/GltfSceneAsset.hpp +++ b/thermion_dart/native/include/scene/GltfSceneAsset.hpp @@ -73,6 +73,10 @@ namespace thermion return _asset; } + const Aabb getBoundingBox() const override { + return _asset->getBoundingBox(); + } + void addAllEntities(Scene *scene) override { scene->addEntities(_asset->getEntities(), _asset->getEntityCount()); diff --git a/thermion_dart/native/include/scene/GltfSceneAssetInstance.hpp b/thermion_dart/native/include/scene/GltfSceneAssetInstance.hpp index 1aaf610c..4eddb29b 100644 --- a/thermion_dart/native/include/scene/GltfSceneAssetInstance.hpp +++ b/thermion_dart/native/include/scene/GltfSceneAssetInstance.hpp @@ -39,6 +39,10 @@ namespace thermion return std::nullptr_t(); }; + const Aabb getBoundingBox() const override { + return _instance->getBoundingBox(); + } + SceneAssetType getType() override { return SceneAsset::SceneAssetType::Gltf; diff --git a/thermion_dart/native/include/scene/SceneAsset.hpp b/thermion_dart/native/include/scene/SceneAsset.hpp index 588716c3..8aa7229a 100644 --- a/thermion_dart/native/include/scene/SceneAsset.hpp +++ b/thermion_dart/native/include/scene/SceneAsset.hpp @@ -22,6 +22,9 @@ class SceneAsset { virtual ~SceneAsset() { } + + virtual const Aabb getBoundingBox() const = 0; + virtual SceneAssetType getType() = 0; virtual utils::Entity getEntity() { diff --git a/thermion_dart/native/src/scene/GltfSceneAsset.cpp b/thermion_dart/native/src/scene/GltfSceneAsset.cpp index f950a19c..d7adf0ba 100644 --- a/thermion_dart/native/src/scene/GltfSceneAsset.cpp +++ b/thermion_dart/native/src/scene/GltfSceneAsset.cpp @@ -30,11 +30,15 @@ namespace thermion auto& rm = _engine->getRenderableManager(); if(materialInstanceCount > 0) { + + TRACE("Instance entity count : %d", instance->getEntityCount()); + for(int i = 0; i < instance->getEntityCount(); i++) { auto renderableInstance = rm.getInstance(instance->getEntities()[i]); if(!renderableInstance.isValid()) { - Log("Instance is not renderable"); + TRACE("Instance child entity %d not renderable", i); } else { + TRACE("Instance child entity %d renderable", i); for(int i = 0; i < materialInstanceCount; i++) { rm.setMaterialInstanceAt(renderableInstance, i, materialInstances[i]); }