internal: store bounding box with SceneAsset rather than recalculating from renderables
This commit is contained in:
@@ -21,6 +21,7 @@ extern "C"
|
||||
EMSCRIPTEN_KEEPALIVE TSceneAsset *SceneAsset_getInstance(TSceneAsset *tSceneAsset, int index);
|
||||
EMSCRIPTEN_KEEPALIVE size_t SceneAsset_getInstanceCount(TSceneAsset *tSceneAsset);
|
||||
EMSCRIPTEN_KEEPALIVE TSceneAsset * SceneAsset_createInstance(TSceneAsset *asset, TMaterialInstance **materialInstances, int materialInstanceCount);
|
||||
EMSCRIPTEN_KEEPALIVE Aabb3 SceneAsset_getBoundingBox(TSceneAsset *asset);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -122,6 +122,10 @@ namespace thermion
|
||||
return Entity(); // not currently implemented
|
||||
}
|
||||
|
||||
const filament::Aabb getBoundingBox() const override {
|
||||
return _boundingBox;
|
||||
}
|
||||
|
||||
static std::unique_ptr<GeometrySceneAsset> create(
|
||||
float *vertices, uint32_t numVertices,
|
||||
float *normals, uint32_t numNormals,
|
||||
@@ -136,7 +140,7 @@ namespace thermion
|
||||
VertexBuffer *_vertexBuffer = nullptr;
|
||||
IndexBuffer *_indexBuffer = nullptr;
|
||||
std::vector<MaterialInstance*> _materialInstances;
|
||||
Box _boundingBox;
|
||||
Aabb _boundingBox;
|
||||
GeometrySceneAsset *_instanceOwner = std::nullptr_t();
|
||||
utils::Entity _entity;
|
||||
RenderableManager::PrimitiveType _primitiveType;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <utils/Entity.h>
|
||||
#include <filament/Box.h>
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/Material.h>
|
||||
#include <filament/MaterialInstance.h>
|
||||
@@ -145,6 +146,10 @@ namespace thermion
|
||||
|
||||
math::mat4f getRotationForAxis(Gizmo::Axis axis);
|
||||
|
||||
const filament::Aabb getBoundingBox() const override {
|
||||
return _boundingBox;
|
||||
}
|
||||
|
||||
private:
|
||||
SceneAsset *_source;
|
||||
Engine *_engine;
|
||||
@@ -161,6 +166,8 @@ namespace thermion
|
||||
std::vector<utils::Entity> _entities;
|
||||
std::vector<MaterialInstance *> _materialInstances;
|
||||
|
||||
filament::Aabb _boundingBox;
|
||||
|
||||
GizmoPickResultType getPickResult(utils::Entity entity)
|
||||
{
|
||||
if (entity.isNull())
|
||||
|
||||
@@ -167,6 +167,10 @@ namespace thermion
|
||||
return entities[0];
|
||||
}
|
||||
|
||||
const filament::Aabb getBoundingBox() const override {
|
||||
return _asset->getBoundingBox();
|
||||
}
|
||||
|
||||
private:
|
||||
gltfio::FilamentAsset *_asset;
|
||||
gltfio::AssetLoader *_assetLoader;
|
||||
|
||||
@@ -159,7 +159,9 @@ namespace thermion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const filament::Aabb getBoundingBox() const override {
|
||||
return _instance->getBoundingBox();
|
||||
}
|
||||
|
||||
private:
|
||||
filament::Engine *_engine;
|
||||
|
||||
@@ -48,6 +48,10 @@ public:
|
||||
const Entity* getChildEntities() override;
|
||||
Entity findEntityByName(const char* name) override;
|
||||
|
||||
const filament::Aabb getBoundingBox() const override {
|
||||
return filament::Aabb();
|
||||
}
|
||||
|
||||
private:
|
||||
Engine& _engine;
|
||||
utils::Entity _gridEntity;
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <utils/Entity.h>
|
||||
#include <gltfio/FilamentAsset.h>
|
||||
#include <filament/Scene.h>
|
||||
|
||||
#include <gltfio/FilamentAsset.h>
|
||||
#include <math.h>
|
||||
#include <utils/Entity.h>
|
||||
|
||||
#include "CustomGeometry.hpp"
|
||||
#include "Log.hpp"
|
||||
|
||||
@@ -51,6 +53,8 @@ class SceneAsset {
|
||||
virtual void setPriority(RenderableManager& rm, int mask) = 0;
|
||||
virtual void setLayer(RenderableManager& rm, int layer) = 0;
|
||||
|
||||
virtual const filament::Aabb getBoundingBox() const = 0;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -101,6 +101,12 @@ extern "C"
|
||||
return reinterpret_cast<TSceneAsset *>(instance);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE Aabb3 SceneAsset_getBoundingBox(TSceneAsset *tSceneAsset) {
|
||||
auto *asset = reinterpret_cast<SceneAsset*>(tSceneAsset);
|
||||
auto box = asset->getBoundingBox();
|
||||
return Aabb3{box.center().x, box.center().y, box.center().z, box.extent().x, box.extent().y, box.extent().z};
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ namespace thermion
|
||||
_vertexBuffer(vertexBuffer),
|
||||
_indexBuffer(indexBuffer),
|
||||
_primitiveType(primitiveType),
|
||||
_boundingBox(boundingBox),
|
||||
_instanceOwner(instanceOwner)
|
||||
{
|
||||
_materialInstances.insert(_materialInstances.begin(), materialInstances, materialInstances + materialInstanceCount);
|
||||
@@ -39,11 +38,15 @@ namespace thermion
|
||||
_entity = utils::EntityManager::get().create();
|
||||
|
||||
RenderableManager::Builder builder(1);
|
||||
builder.boundingBox(_boundingBox)
|
||||
builder.boundingBox(boundingBox)
|
||||
.geometry(0, _primitiveType, _vertexBuffer, _indexBuffer)
|
||||
.culling(true)
|
||||
.receiveShadows(true)
|
||||
.castShadows(true);
|
||||
|
||||
_boundingBox.min = boundingBox.getMin();
|
||||
_boundingBox.max = boundingBox.getMax();
|
||||
|
||||
for (int i = 0; i < materialInstanceCount; i++)
|
||||
{
|
||||
builder.material(i, materialInstances[i]);
|
||||
@@ -83,7 +86,7 @@ namespace thermion
|
||||
materialInstances,
|
||||
materialInstanceCount,
|
||||
_primitiveType,
|
||||
_boundingBox,
|
||||
filament::Box().set(_boundingBox.min, _boundingBox.max),
|
||||
this);
|
||||
auto *raw = instance.get();
|
||||
_instances.push_back(std::move(instance));
|
||||
|
||||
@@ -26,7 +26,10 @@ namespace thermion
|
||||
}
|
||||
TRACE("Creating instance %d", instanceNumber);
|
||||
auto instance = _asset->getAssetInstances()[instanceNumber];
|
||||
|
||||
instance->recomputeBoundingBoxes();
|
||||
auto bb = instance->getBoundingBox();
|
||||
TRACE("Instance bounding box center (%f,%f,%f), extent (%f,%f,%f)", bb.center().x, bb.center().y, bb.center().z, bb.extent().x,bb.extent().y,bb.extent().z);
|
||||
instance->getAnimator()->updateBoneMatrices();
|
||||
|
||||
auto& rm = _engine->getRenderableManager();
|
||||
|
||||
Reference in New Issue
Block a user