chore: refactoring and cleanup for Gizmo

This commit is contained in:
Nick Fisher
2024-09-28 13:24:28 +08:00
parent 03ab646713
commit 3596723d3d
29 changed files with 155 additions and 150 deletions

View File

@@ -21,7 +21,7 @@
#include "ThermionDartApi.h"
namespace thermion_filament {
namespace thermion {
using namespace filament;
using namespace utils;
@@ -29,38 +29,13 @@ using namespace utils;
class Gizmo {
enum Axis { X, Y, Z};
class PickCallbackHandler {
public:
PickCallbackHandler(Gizmo* gizmo, void (*callback)(EntityId entityId, int x, int y)) : _gizmo(gizmo), _callback(callback) {};
void handle(filament::View::PickingQueryResult const &result) {
auto x = static_cast<int32_t>(result.fragCoords.x);
auto y= static_cast<int32_t>(result.fragCoords.y);
for(int i = 0; i < 7; i++) {
if(_gizmo->_entities[i] == result.renderable) {
if(i < 4) {
return;
}
_gizmo->highlight(_gizmo->_entities[i - 4]);
_callback(Entity::smuggle(_gizmo->_entities[i - 4]), x, y);
return;
}
}
_gizmo->unhighlight();
_callback(0, x, y);
delete(this);
}
private:
Gizmo* _gizmo;
void (*_callback)(EntityId entityId, int x, int y);
};
public:
Gizmo(Engine& engine, Scene *scene);
Gizmo(Engine *engine, View *view, Scene *scene);
~Gizmo();
typedef void (*PickCallback)(EntityId entityId, uint32_t x, uint32_t y, View *view);
Entity x() {
return _entities[0];
};
@@ -78,16 +53,44 @@ class Gizmo {
return _isActive;
}
void pick(View* view, uint32_t x, uint32_t y, void (*callback)(EntityId entityId, int x, int y));
void pick(uint32_t x, uint32_t y, PickCallback callback);
bool isGizmoEntity(Entity entity);
void setVisibility(bool visible);
private:
class PickCallbackHandler {
public:
PickCallbackHandler(Gizmo* gizmo, PickCallback callback) : _gizmo(gizmo), _callback(callback) {};
void handle(filament::View::PickingQueryResult const &result) {
auto x = static_cast<int32_t>(result.fragCoords.x);
auto y= static_cast<int32_t>(result.fragCoords.y);
for(int i = 0; i < 7; i++) {
if(_gizmo->_entities[i] == result.renderable) {
if(i < 4) {
return;
}
_gizmo->highlight(_gizmo->_entities[i - 4]);
_callback(Entity::smuggle(_gizmo->_entities[i - 4]), x, y, _gizmo->_view);
return;
}
}
_gizmo->unhighlight();
_callback(0, x, y, _gizmo->_view);
delete(this);
}
private:
Gizmo* _gizmo;
PickCallback _callback;
};
void createTransparentRectangles();
void highlight(Entity entity);
void unhighlight();
Engine &_engine;
Engine *_engine;
Scene *_scene;
View *_view;
utils::Entity _entities[7] = { utils::Entity(), utils::Entity(), utils::Entity(), utils::Entity(), utils::Entity(), utils::Entity(), utils::Entity() };
Material* _material;
MaterialInstance* _materialInstances[7];