chore: refactoring and cleanup for Gizmo
This commit is contained in:
@@ -8,7 +8,6 @@ extern "C"
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int32_t EntityId;
|
||||
typedef int32_t _ManipulatorMode;
|
||||
typedef struct TCamera TCamera;
|
||||
typedef struct TMaterialInstance TMaterialInstance;
|
||||
typedef struct TEngine TEngine;
|
||||
@@ -19,6 +18,7 @@ extern "C"
|
||||
typedef struct TSwapChain TSwapChain;
|
||||
typedef struct TView TView;
|
||||
typedef struct TGizmo TGizmo;
|
||||
typedef struct TScene TScene;
|
||||
|
||||
struct TMaterialKey {
|
||||
bool doubleSided = 1;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <filament/Viewport.h>
|
||||
#include <filament/Frustum.h>
|
||||
|
||||
namespace thermion_filament
|
||||
namespace thermion
|
||||
{
|
||||
|
||||
using namespace filament;
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include "SceneManager.hpp"
|
||||
#include "ThreadPool.hpp"
|
||||
|
||||
namespace thermion_filament
|
||||
namespace thermion
|
||||
{
|
||||
|
||||
typedef std::chrono::time_point<std::chrono::high_resolution_clock> time_point_t;
|
||||
@@ -139,7 +139,7 @@ namespace thermion_filament
|
||||
void* _context = nullptr;
|
||||
Scene *_scene = nullptr;
|
||||
Engine *_engine = nullptr;
|
||||
thermion_filament::ThreadPool *_tp = nullptr;
|
||||
thermion::ThreadPool *_tp = nullptr;
|
||||
Renderer *_renderer = nullptr;
|
||||
SceneManager *_sceneManager = nullptr;
|
||||
std::vector<RenderTarget*> _renderTargets;
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "material/gizmo.h"
|
||||
|
||||
|
||||
namespace thermion_filament {
|
||||
namespace thermion {
|
||||
|
||||
using namespace filament;
|
||||
using namespace utils;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
using namespace std::chrono_literals;
|
||||
#endif
|
||||
|
||||
namespace thermion_filament
|
||||
namespace thermion
|
||||
{
|
||||
|
||||
struct ResourceLoaderWrapperImpl : public ResourceLoaderWrapper
|
||||
|
||||
@@ -19,10 +19,8 @@
|
||||
#include <filament/InstanceBuffer.h>
|
||||
#include <utils/NameComponentManager.h>
|
||||
|
||||
#include "material/gizmo.h"
|
||||
|
||||
#include "CustomGeometry.hpp"
|
||||
#include "Gizmo.hpp"
|
||||
|
||||
#include "APIBoundaryTypes.h"
|
||||
#include "GridOverlay.hpp"
|
||||
#include "ResourceBuffer.hpp"
|
||||
@@ -32,7 +30,7 @@
|
||||
#include "tsl/robin_map.h"
|
||||
|
||||
|
||||
namespace thermion_filament
|
||||
namespace thermion
|
||||
{
|
||||
typedef int32_t EntityId;
|
||||
|
||||
@@ -253,8 +251,6 @@ namespace thermion_filament
|
||||
|
||||
friend class FilamentViewer;
|
||||
|
||||
Gizmo* gizmo = nullptr;
|
||||
|
||||
gltfio::MaterialProvider * const unlitMaterialProvider() {
|
||||
return _unlitMaterialProvider;
|
||||
}
|
||||
@@ -267,10 +263,6 @@ namespace thermion_filament
|
||||
return _geometry[entityId].get();
|
||||
}
|
||||
|
||||
Scene* const getScene() {
|
||||
return _scene;
|
||||
}
|
||||
|
||||
bool isGltfAsset(EntityId entity) {
|
||||
return getAssetByEntityId(entity) != nullptr;
|
||||
}
|
||||
@@ -307,6 +299,12 @@ namespace thermion_filament
|
||||
|
||||
Camera* getCameraAt(size_t index);
|
||||
|
||||
bool isGizmoEntity(utils::Entity entity);
|
||||
|
||||
Scene* getScene() {
|
||||
return _scene;
|
||||
}
|
||||
|
||||
private:
|
||||
gltfio::AssetLoader *_assetLoader = nullptr;
|
||||
const ResourceLoaderWrapperImpl *const _resourceLoaderWrapper;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
namespace thermion_filament {
|
||||
namespace thermion {
|
||||
|
||||
|
||||
//
|
||||
|
||||
@@ -6,10 +6,14 @@ extern "C"
|
||||
#endif
|
||||
|
||||
#include "ThermionDartApi.h"
|
||||
#include "TGizmo.h"
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Gizmo_pick(TGizmo *tGizmo, TView *tView, int x, int y, void (*callback)(EntityId entityId, int x, int y));
|
||||
typedef void (*GizmoPickCallback)(EntityId entityId, uint32_t x, uint32_t y, TView* view);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TGizmo* Gizmo_new(TEngine *tEngine, TView *tView, TScene *tScene);
|
||||
EMSCRIPTEN_KEEPALIVE void Gizmo_pick(TGizmo *tGizmo, uint32_t x, uint32_t y, GizmoPickCallback callback);
|
||||
EMSCRIPTEN_KEEPALIVE void Gizmo_setVisibility(TGizmo *tGizmo, bool visible);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -40,6 +40,7 @@ EMSCRIPTEN_KEEPALIVE void View_setToneMapping(TView* tView, TEngine* tEngine, To
|
||||
EMSCRIPTEN_KEEPALIVE void View_setAntiAliasing(TView *tView, bool msaa, bool fxaa, bool taa);
|
||||
EMSCRIPTEN_KEEPALIVE void View_setLayerEnabled(TView *tView, int layer, bool visible);
|
||||
EMSCRIPTEN_KEEPALIVE void View_setCamera(TView *tView, TCamera *tCamera);
|
||||
EMSCRIPTEN_KEEPALIVE TScene* View_getScene(TView *tView);
|
||||
EMSCRIPTEN_KEEPALIVE TCamera* View_getCamera(TView *tView);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -211,7 +211,8 @@ extern "C"
|
||||
EMSCRIPTEN_KEEPALIVE void SceneManager_queueTransformUpdates(TSceneManager *sceneManager, EntityId* entities, const double* const transforms, int numEntities);
|
||||
EMSCRIPTEN_KEEPALIVE TCamera* SceneManager_findCameraByName(TSceneManager* tSceneManager, EntityId entity, const char* name);
|
||||
EMSCRIPTEN_KEEPALIVE void SceneManager_setVisibilityLayer(TSceneManager *tSceneManager, EntityId entity, int layer);
|
||||
EMSCRIPTEN_KEEPALIVE TGizmo* SceneManager_getGizmo(TSceneManager *tSceneManager);
|
||||
EMSCRIPTEN_KEEPALIVE TScene* SceneManager_getScene(TSceneManager *tSceneManager);
|
||||
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE bool update_bone_matrices(TSceneManager *sceneManager, EntityId entityId);
|
||||
EMSCRIPTEN_KEEPALIVE void get_morph_target_name(TSceneManager *sceneManager, EntityId assetEntity, EntityId childEntity, char *const outPtr, int index);
|
||||
@@ -302,11 +303,11 @@ extern "C"
|
||||
EMSCRIPTEN_KEEPALIVE void set_parent(TSceneManager *sceneManager, EntityId child, EntityId parent, bool preserveScaling);
|
||||
EMSCRIPTEN_KEEPALIVE void test_collisions(TSceneManager *sceneManager, EntityId entity);
|
||||
EMSCRIPTEN_KEEPALIVE void set_priority(TSceneManager *sceneManager, EntityId entityId, int priority);
|
||||
EMSCRIPTEN_KEEPALIVE void get_gizmo(TSceneManager *sceneManager, EntityId *out);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE Aabb2 get_bounding_box(TSceneManager *sceneManager, TView *view, EntityId entity);
|
||||
EMSCRIPTEN_KEEPALIVE void get_bounding_box_to_out(TSceneManager *sceneManager, TView *view, EntityId entity, float *minX, float *minY, float *maxX, float *maxY);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void set_gizmo_visibility(TSceneManager *sceneManager, bool visible);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void set_stencil_highlight(TSceneManager *sceneManager, EntityId entity, float r, float g, float b);
|
||||
EMSCRIPTEN_KEEPALIVE void remove_stencil_highlight(TSceneManager *sceneManager, EntityId entity);
|
||||
EMSCRIPTEN_KEEPALIVE void set_material_property_float(TSceneManager *sceneManager, EntityId entity, int materialIndex, const char *property, float value);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#ifndef _THREADPOOL_HPP
|
||||
#define _THREADPOOL_HPP
|
||||
|
||||
namespace thermion_filament {
|
||||
namespace thermion {
|
||||
|
||||
class ThreadPool {
|
||||
std::vector<std::thread> pool;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include "CustomGeometry.hpp"
|
||||
|
||||
namespace thermion_filament {
|
||||
namespace thermion {
|
||||
|
||||
class UnprojectTexture {
|
||||
public:
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <utils/NameComponentManager.h>
|
||||
|
||||
template class std::vector<float>;
|
||||
namespace thermion_filament
|
||||
namespace thermion
|
||||
{
|
||||
using namespace filament;
|
||||
using namespace filament::gltfio;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "gltfio/FilamentInstance.h"
|
||||
#include "Log.hpp"
|
||||
|
||||
namespace thermion_filament
|
||||
namespace thermion
|
||||
{
|
||||
|
||||
typedef void(*CollisionCallback)(int32_t entityId1, int32_t entityId2) ;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <math/norm.h>
|
||||
#include "Log.hpp"
|
||||
|
||||
namespace thermion_filament {
|
||||
namespace thermion {
|
||||
|
||||
|
||||
class FileMaterialProvider : public filament::gltfio::MaterialProvider {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
|
||||
namespace thermion_filament {
|
||||
namespace thermion {
|
||||
|
||||
class UnlitMaterialProvider : public filament::gltfio::MaterialProvider {
|
||||
private:
|
||||
@@ -63,6 +63,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace thermion_filament
|
||||
} // namespace thermion
|
||||
|
||||
#endif // UNLIT_MATERIAL_PROVIDER_HPP
|
||||
Reference in New Issue
Block a user