fix: properly destroy entities/material/etc in Gizmo on destruction, remove custom scene creation logic

This commit is contained in:
Nick Fisher
2024-09-07 17:59:03 +08:00
parent 4c6c20f3de
commit c2eb28a8f5
2 changed files with 12 additions and 42 deletions

View File

@@ -62,7 +62,6 @@ class Gizmo {
Gizmo(Engine& engine, View *view, Scene *scene); Gizmo(Engine& engine, View *view, Scene *scene);
~Gizmo(); ~Gizmo();
void destroy();
Entity x() { Entity x() {
return _entities[0]; return _entities[0];
}; };

View File

@@ -16,23 +16,11 @@ using namespace filament::gltfio;
Gizmo::Gizmo(Engine &engine, View* view, Scene* scene) : _engine(engine) Gizmo::Gizmo(Engine &engine, View* view, Scene* scene) : _engine(engine)
{ {
if(scene) {
_scene = scene; _scene = scene;
_view = view; _view = view;
_camera = &(_view->getCamera()); _camera = &(_view->getCamera());
} else {
_scene = _engine.createScene();
_view = _engine.createView();
_view->setBlendMode(BlendMode::TRANSLUCENT);
utils::Entity camera = EntityManager::get().create();
_camera = engine.createCamera(camera);
_camera->setProjection(Camera::Projection::ORTHO, -1.0, 1.0, -1.0, 1.0, 1.0, 5.0);
_view->setScene(_scene);
_view->setCamera(_camera);
}
auto &entityManager = EntityManager::get(); auto &entityManager = EntityManager::get();
auto &transformManager = engine.getTransformManager(); auto &transformManager = engine.getTransformManager();
@@ -208,18 +196,17 @@ Gizmo::Gizmo(Engine &engine, View* view, Scene* scene) : _engine(engine)
Gizmo::~Gizmo() { Gizmo::~Gizmo() {
_scene->removeEntities(_entities, 7); _scene->removeEntities(_entities, 7);
for(int i = 0; i < 7; i++) {
_engine.destroy(_materialInstances[i]);
}
_engine.destroy(_material);
for(int i = 0; i < 7; i++) { for(int i = 0; i < 7; i++) {
_engine.destroy(_entities[i]); _engine.destroy(_entities[i]);
} }
_view->setScene(nullptr); for(int i = 0; i < 7; i++) {
_engine.destroy(_scene); _engine.destroy(_materialInstances[i]);
_engine.destroy(_view); }
_engine.destroy(_material);
} }
void Gizmo::createTransparentRectangles() void Gizmo::createTransparentRectangles()
@@ -343,22 +330,6 @@ void Gizmo::unhighlight() {
} }
} }
void Gizmo::destroy()
{
auto& rm = _engine.getRenderableManager();
auto& tm = _engine.getTransformManager();
for (int i = 0; i < 4; i++)
{
rm.destroy(_entities[i]);
tm.destroy(_entities[i]);
_engine.destroy(_entities[i]);
_engine.destroy(_materialInstances[i]);
}
_engine.destroy(_material);
}
void Gizmo::pick(uint32_t x, uint32_t y, void (*callback)(EntityId entityId, int x, int y)) void Gizmo::pick(uint32_t x, uint32_t y, void (*callback)(EntityId entityId, int x, int y))
{ {
auto handler = new Gizmo::PickCallbackHandler(this, callback); auto handler = new Gizmo::PickCallbackHandler(this, callback);