internal: add bounding box to SceneAsset & subclasses

This commit is contained in:
Nick Fisher
2024-12-11 21:04:57 +08:00
parent 27e150ebf6
commit 278575c3e2
5 changed files with 24 additions and 3 deletions

View File

@@ -53,7 +53,14 @@ namespace thermion
return _materialInstanceCount; 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; } VertexBuffer *getVertexBuffer() const { return _vertexBuffer; }
IndexBuffer *getIndexBuffer() const { return _indexBuffer; } IndexBuffer *getIndexBuffer() const { return _indexBuffer; }
@@ -137,7 +144,6 @@ namespace thermion
utils::Entity _entity; utils::Entity _entity;
RenderableManager::PrimitiveType _primitiveType; RenderableManager::PrimitiveType _primitiveType;
std::vector<std::unique_ptr<GeometrySceneAsset>> _instances; std::vector<std::unique_ptr<GeometrySceneAsset>> _instances;
}; };
} // namespace thermion } // namespace thermion

View File

@@ -73,6 +73,10 @@ namespace thermion
return _asset; return _asset;
} }
const Aabb getBoundingBox() const override {
return _asset->getBoundingBox();
}
void addAllEntities(Scene *scene) override void addAllEntities(Scene *scene) override
{ {
scene->addEntities(_asset->getEntities(), _asset->getEntityCount()); scene->addEntities(_asset->getEntities(), _asset->getEntityCount());

View File

@@ -39,6 +39,10 @@ namespace thermion
return std::nullptr_t(); return std::nullptr_t();
}; };
const Aabb getBoundingBox() const override {
return _instance->getBoundingBox();
}
SceneAssetType getType() override SceneAssetType getType() override
{ {
return SceneAsset::SceneAssetType::Gltf; return SceneAsset::SceneAssetType::Gltf;

View File

@@ -22,6 +22,9 @@ class SceneAsset {
virtual ~SceneAsset() { virtual ~SceneAsset() {
} }
virtual const Aabb getBoundingBox() const = 0;
virtual SceneAssetType getType() = 0; virtual SceneAssetType getType() = 0;
virtual utils::Entity getEntity() { virtual utils::Entity getEntity() {

View File

@@ -30,11 +30,15 @@ namespace thermion
auto& rm = _engine->getRenderableManager(); auto& rm = _engine->getRenderableManager();
if(materialInstanceCount > 0) { if(materialInstanceCount > 0) {
TRACE("Instance entity count : %d", instance->getEntityCount());
for(int i = 0; i < instance->getEntityCount(); i++) { for(int i = 0; i < instance->getEntityCount(); i++) {
auto renderableInstance = rm.getInstance(instance->getEntities()[i]); auto renderableInstance = rm.getInstance(instance->getEntities()[i]);
if(!renderableInstance.isValid()) { if(!renderableInstance.isValid()) {
Log("Instance is not renderable"); TRACE("Instance child entity %d not renderable", i);
} else { } else {
TRACE("Instance child entity %d renderable", i);
for(int i = 0; i < materialInstanceCount; i++) { for(int i = 0; i < materialInstanceCount; i++) {
rm.setMaterialInstanceAt(renderableInstance, i, materialInstances[i]); rm.setMaterialInstanceAt(renderableInstance, i, materialInstances[i]);
} }