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

@@ -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;

View File

@@ -11,7 +11,7 @@
#include <filament/Viewport.h>
#include <filament/Frustum.h>
namespace thermion_filament
namespace thermion
{
using namespace filament;

View File

@@ -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;

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];

View File

@@ -22,7 +22,7 @@
#include "material/gizmo.h"
namespace thermion_filament {
namespace thermion {
using namespace filament;
using namespace utils;

View File

@@ -8,7 +8,7 @@
using namespace std::chrono_literals;
#endif
namespace thermion_filament
namespace thermion
{
struct ResourceLoaderWrapperImpl : public ResourceLoaderWrapper

View File

@@ -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;

View File

@@ -5,7 +5,7 @@
#include <cassert>
#include <cstring>
namespace thermion_filament {
namespace thermion {
//

View File

@@ -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

View File

@@ -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

View File

@@ -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);

View File

@@ -15,7 +15,7 @@
#ifndef _THREADPOOL_HPP
#define _THREADPOOL_HPP
namespace thermion_filament {
namespace thermion {
class ThreadPool {
std::vector<std::thread> pool;

View File

@@ -17,7 +17,7 @@
#include "CustomGeometry.hpp"
namespace thermion_filament {
namespace thermion {
class UnprojectTexture {
public:

View File

@@ -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;

View File

@@ -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) ;

View File

@@ -11,7 +11,7 @@
#include <math/norm.h>
#include "Log.hpp"
namespace thermion_filament {
namespace thermion {
class FileMaterialProvider : public filament::gltfio::MaterialProvider {

View File

@@ -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

View File

@@ -11,7 +11,7 @@
#include "Log.hpp"
#include "CustomGeometry.hpp"
namespace thermion_filament {
namespace thermion {
using namespace filament;

View File

@@ -105,7 +105,7 @@ namespace filament
class LightManager;
} // namespace filament
namespace thermion_filament
namespace thermion
{
using namespace filament;
@@ -349,7 +349,7 @@ namespace thermion_filament
void FilamentViewer::loadPngTexture(string path, ResourceBuffer rb)
{
thermion_filament::StreamBufferAdapter sb((char *)rb.data, (char *)rb.data + rb.size);
thermion::StreamBufferAdapter sb((char *)rb.data, (char *)rb.data + rb.size);
std::istream inputStream(&sb);
@@ -1209,10 +1209,9 @@ namespace thermion_filament
void FilamentViewer::pick(View *view, uint32_t x, uint32_t y, void (*callback)(EntityId entityId, int x, int y))
{
view->pick(x, y, [=](filament::View::PickingQueryResult const &result)
{
view->pick(x, y, [=](filament::View::PickingQueryResult const &result) {
if(_sceneManager->gizmo->isGizmoEntity(result.renderable)) {
if(_sceneManager->isGizmoEntity(result.renderable)) {
Log("Gizmo entity, ignoring");
return;
}
@@ -1243,4 +1242,4 @@ namespace thermion_filament
// unproject.unproject(utils::Entity::import(entityId), input, out, inputWidth, inputHeight, outWidth, outHeight);
}
} // namespace thermion_filament
} // namespace thermion

View File

@@ -10,23 +10,21 @@
#include "material/gizmo.h"
#include "Log.hpp"
namespace thermion_filament {
namespace thermion {
using namespace filament::gltfio;
Gizmo::Gizmo(Engine &engine, Scene* scene) : _engine(engine)
Gizmo::Gizmo(Engine *engine, View *view, Scene* scene) : _engine(engine), _view(view), _scene(scene)
{
_scene = scene;
auto &entityManager = EntityManager::get();
auto &transformManager = engine.getTransformManager();
auto &transformManager = _engine->getTransformManager();
_material =
Material::Builder()
.package(GIZMO_GIZMO_DATA, GIZMO_GIZMO_SIZE)
.build(engine);
.build(*_engine);
// First, create the black cube at the center
// The axes widgets will be parented to this entity
@@ -60,13 +58,13 @@ Gizmo::Gizmo(Engine &engine, Scene* scene) : _engine(engine)
.vertexCount(8)
.bufferCount(1)
.attribute(VertexAttribute::POSITION, 0, VertexBuffer::AttributeType::FLOAT3)
.build(engine);
.build(*engine);
centerCubeVb->setBufferAt(engine, 0, VertexBuffer::BufferDescriptor(centerCubeVertices, 8 * sizeof(filament::math::float3), [](void *buffer, size_t size, void *)
centerCubeVb->setBufferAt(*engine, 0, VertexBuffer::BufferDescriptor(centerCubeVertices, 8 * sizeof(filament::math::float3), [](void *buffer, size_t size, void *)
{ delete[] static_cast<float *>(buffer); }));
auto centerCubeIb = IndexBuffer::Builder().indexCount(36).bufferType(IndexBuffer::IndexType::USHORT).build(engine);
centerCubeIb->setBuffer(engine, IndexBuffer::BufferDescriptor(
auto centerCubeIb = IndexBuffer::Builder().indexCount(36).bufferType(IndexBuffer::IndexType::USHORT).build(*engine);
centerCubeIb->setBuffer(*engine, IndexBuffer::BufferDescriptor(
centerCubeIndices, 36 * sizeof(uint16_t),
[](void *buffer, size_t size, void *)
{ delete[] static_cast<uint16_t *>(buffer); }));
@@ -79,7 +77,7 @@ Gizmo::Gizmo(Engine &engine, Scene* scene) : _engine(engine)
.priority(7)
.geometry(0, RenderableManager::PrimitiveType::TRIANGLES, centerCubeVb, centerCubeIb, 0, 36)
.culling(false)
.build(engine, _entities[3]);
.build(*engine, _entities[3]);
auto cubeTransformInstance = transformManager.getInstance(_entities[3]);
math::mat4f cubeTransform;
@@ -126,13 +124,13 @@ Gizmo::Gizmo(Engine &engine, Scene* scene) : _engine(engine)
.vertexCount(13)
.bufferCount(1)
.attribute(VertexAttribute::POSITION, 0, VertexBuffer::AttributeType::FLOAT3)
.build(engine);
.build(*engine);
vb->setBufferAt(engine, 0, VertexBuffer::BufferDescriptor(vertices, 13 * sizeof(filament::math::float3), [](void *buffer, size_t size, void *)
vb->setBufferAt(*engine, 0, VertexBuffer::BufferDescriptor(vertices, 13 * sizeof(filament::math::float3), [](void *buffer, size_t size, void *)
{ delete[] static_cast<float *>(buffer); }));
auto ib = IndexBuffer::Builder().indexCount(54).bufferType(IndexBuffer::IndexType::USHORT).build(engine);
ib->setBuffer(engine, IndexBuffer::BufferDescriptor(
auto ib = IndexBuffer::Builder().indexCount(54).bufferType(IndexBuffer::IndexType::USHORT).build(*engine);
ib->setBuffer(*engine, IndexBuffer::BufferDescriptor(
indices, 54 * sizeof(uint16_t),
[](void *buffer, size_t size, void *)
{ delete[] static_cast<uint16_t *>(buffer); }));
@@ -174,7 +172,7 @@ Gizmo::Gizmo(Engine &engine, Scene* scene) : _engine(engine)
.culling(false)
.receiveShadows(false)
.castShadows(false)
.build(engine, _entities[i]);
.build(*engine, _entities[i]);
auto instance = transformManager.getInstance(_entities[i]);
@@ -192,21 +190,21 @@ Gizmo::~Gizmo() {
_scene->removeEntities(_entities, 7);
for(int i = 0; i < 7; i++) {
_engine.destroy(_entities[i]);
_engine->destroy(_entities[i]);
}
for(int i = 0; i < 7; i++) {
_engine.destroy(_materialInstances[i]);
_engine->destroy(_materialInstances[i]);
}
_engine.destroy(_material);
_engine->destroy(_material);
}
void Gizmo::createTransparentRectangles()
{
auto &entityManager = EntityManager::get();
auto &transformManager = _engine.getTransformManager();
auto &transformManager = _engine->getTransformManager();
float volumeWidth = 0.2f;
float volumeLength = 1.2f;
@@ -236,9 +234,9 @@ void Gizmo::createTransparentRectangles()
.vertexCount(8)
.bufferCount(1)
.attribute(VertexAttribute::POSITION, 0, VertexBuffer::AttributeType::FLOAT3)
.build(_engine);
.build(*_engine);
volumeVb->setBufferAt(_engine, 0, VertexBuffer::BufferDescriptor(
volumeVb->setBufferAt(*_engine, 0, VertexBuffer::BufferDescriptor(
volumeVertices, 8 * sizeof(filament::math::float3),
[](void *buffer, size_t size, void *) { delete[] static_cast<float *>(buffer); }
));
@@ -246,9 +244,9 @@ void Gizmo::createTransparentRectangles()
auto volumeIb = IndexBuffer::Builder()
.indexCount(36)
.bufferType(IndexBuffer::IndexType::USHORT)
.build(_engine);
.build(*_engine);
volumeIb->setBuffer(_engine, IndexBuffer::BufferDescriptor(
volumeIb->setBuffer(*_engine, IndexBuffer::BufferDescriptor(
volumeIndices, 36 * sizeof(uint16_t),
[](void *buffer, size_t size, void *) { delete[] static_cast<uint16_t *>(buffer); }
));
@@ -282,7 +280,7 @@ void Gizmo::createTransparentRectangles()
.culling(false)
.receiveShadows(false)
.castShadows(false)
.build(_engine, _entities[i]);
.build(*_engine, _entities[i]);
auto instance = transformManager.getInstance(_entities[i]);
transformManager.setTransform(instance, transform);
@@ -293,7 +291,7 @@ void Gizmo::createTransparentRectangles()
}
void Gizmo::highlight(Entity entity) {
auto &rm = _engine.getRenderableManager();
auto &rm = _engine->getRenderableManager();
auto renderableInstance = rm.getInstance(entity);
auto materialInstance = rm.getMaterialInstanceAt(renderableInstance, 0);
@@ -313,7 +311,7 @@ void Gizmo::highlight(Entity entity) {
}
void Gizmo::unhighlight() {
auto &rm = _engine.getRenderableManager();
auto &rm = _engine->getRenderableManager();
for(int i = 0; i < 3; i++) {
auto renderableInstance = rm.getInstance(_entities[i]);
@@ -324,10 +322,10 @@ void Gizmo::unhighlight() {
}
}
void Gizmo::pick(View *view, uint32_t x, uint32_t y, void (*callback)(EntityId entityId, int x, int y))
void Gizmo::pick(uint32_t x, uint32_t y, PickCallback callback)
{
auto handler = new Gizmo::PickCallbackHandler(this, callback);
view->pick(x, y, [=](filament::View::PickingQueryResult const &result) {
_view->pick(x, y, [=](filament::View::PickingQueryResult const &result) {
handler->handle(result);
});
}

View File

@@ -11,7 +11,7 @@
#include "SceneManager.hpp"
#include "Log.hpp"
namespace thermion_filament {
namespace thermion {
using namespace filament::gltfio;
@@ -194,4 +194,4 @@ void GridOverlay::destroy()
_engine.destroy(_gridEntity);
}
} // namespace thermion_filament
} // namespace thermion

View File

@@ -4,7 +4,7 @@
#include "SceneManager.hpp"
namespace thermion_filament
namespace thermion
{
SceneManager::HighlightOverlay::HighlightOverlay(

View File

@@ -38,7 +38,7 @@ extern "C"
#include "material/image.h"
}
namespace thermion_filament
namespace thermion
{
using namespace std::chrono;
@@ -98,7 +98,6 @@ namespace thermion_filament
_collisionComponentManager = new CollisionComponentManager(tm);
_animationComponentManager = new AnimationComponentManager(tm, _engine->getRenderableManager());
gizmo = new Gizmo(*_engine, _scene);
_gridOverlay = new GridOverlay(*_engine);
_scene->addEntity(_gridOverlay->sphere());
@@ -114,7 +113,7 @@ namespace thermion_filament
_engine->getEntityManager().destroy(entity);
}
_cameras.clear();
delete gizmo;
_gridOverlay->destroy();
destroyAll();
@@ -132,6 +131,10 @@ namespace thermion_filament
AssetLoader::destroy(&_assetLoader);
}
bool SceneManager::isGizmoEntity(Entity entity) {
return false; // TODO
}
int SceneManager::getInstanceCount(EntityId entityId)
{
auto *asset = getAssetByEntityId(entityId);
@@ -2502,4 +2505,4 @@ EntityId SceneManager::createGeometry(
}
} // namespace thermion_filament
} // namespace thermion

View File

@@ -3,7 +3,7 @@
#include <cassert>
#include <cstring>
namespace thermion_filament {
namespace thermion {
class StreamBufferAdapter : public std::streambuf
{

View File

@@ -1,29 +1,40 @@
#ifdef _WIN32
#pragma comment(lib, "Shlwapi.lib")
#pragma comment(lib, "opengl32.lib")
#endif
#include <filament/View.h>
#include <filament/Engine.h>
#include <filament/Scene.h>
#include "ResourceBuffer.hpp"
#include "FilamentViewer.hpp"
#include "filament/LightManager.h"
#include "ThermionDartApi.h"
#include "TGizmo.h"
#include "Gizmo.hpp"
#include "Log.hpp"
#include "ThreadPool.hpp"
#include <thread>
#include <functional>
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif
using namespace thermion_filament;
#ifdef __cplusplus
namespace thermion {
extern "C"
{
EMSCRIPTEN_KEEPALIVE void Gizmo_pick(TGizmo *tGizmo, TView *tView, int x, int y, void (*callback)(EntityId entityId, int x, int y))
using namespace filament;
#endif
EMSCRIPTEN_KEEPALIVE TGizmo* Gizmo_new(TEngine *tEngine, TView *tView, TScene *tScene)
{
auto *view = reinterpret_cast<View*>(tView);
auto *engine = reinterpret_cast<Engine*>(tEngine);
auto *scene = reinterpret_cast<Scene*>(tScene);
auto gizmo = new Gizmo(engine, view, scene);
return reinterpret_cast<TGizmo*>(gizmo);
}
EMSCRIPTEN_KEEPALIVE void Gizmo_pick(TGizmo *tGizmo, uint32_t x, uint32_t y, GizmoPickCallback callback)
{
auto *gizmo = reinterpret_cast<Gizmo*>(tGizmo);
auto *view = reinterpret_cast<View*>(tView);
gizmo->pick(view, x, y, callback);
gizmo->pick(x, y, reinterpret_cast<Gizmo::PickCallback>(callback));
}
}
EMSCRIPTEN_KEEPALIVE void Gizmo_setVisibility(TGizmo *tGizmo, bool visible) {
auto *gizmo = reinterpret_cast<Gizmo*>(tGizmo);
gizmo->setVisibility(visible);
}
#ifdef __cplusplus
}
}
#endif

View File

@@ -145,6 +145,11 @@ using namespace filament;
view->setCamera(camera);
}
EMSCRIPTEN_KEEPALIVE TScene* View_getScene(TView* tView) {
auto view = reinterpret_cast<View *>(tView);
return reinterpret_cast<TScene*>(view->getScene());
}
#ifdef __cplusplus
}

View File

@@ -16,7 +16,7 @@
#include <emscripten/emscripten.h>
#endif
using namespace thermion_filament;
using namespace thermion;
extern "C"
{
@@ -681,11 +681,6 @@ extern "C"
return nullptr;
}
EMSCRIPTEN_KEEPALIVE TGizmo* SceneManager_getGizmo(TSceneManager *tSceneManager) {
auto *sceneManager = reinterpret_cast<SceneManager*>(tSceneManager);
auto *gizmo = sceneManager->gizmo;
return reinterpret_cast<TGizmo*>(gizmo);
}
EMSCRIPTEN_KEEPALIVE bool SceneManager_setTransform(TSceneManager *sceneManager, EntityId entityId, const double *const transform)
{
@@ -911,15 +906,7 @@ extern "C"
((SceneManager *)sceneManager)->setPriority(entity, priority);
}
EMSCRIPTEN_KEEPALIVE void get_gizmo(TSceneManager *sceneManager, EntityId *out)
{
auto gizmo = ((SceneManager *)sceneManager)->gizmo;
out[0] = Entity::smuggle(gizmo->x());
out[1] = Entity::smuggle(gizmo->y());
out[2] = Entity::smuggle(gizmo->z());
out[3] = Entity::smuggle(gizmo->center());
}
EMSCRIPTEN_KEEPALIVE Aabb2 get_bounding_box(TSceneManager *sceneManager, TView *tView, EntityId entity)
{
auto view = reinterpret_cast<View*>(tView);
@@ -947,11 +934,6 @@ extern "C"
free(ptr);
}
EMSCRIPTEN_KEEPALIVE void set_gizmo_visibility(TSceneManager *sceneManager, bool visible)
{
((SceneManager *)sceneManager)->gizmo->setVisibility(visible);
}
EMSCRIPTEN_KEEPALIVE void set_stencil_highlight(TSceneManager *sceneManager, EntityId entityId, float r, float g, float b)
{
((SceneManager *)sceneManager)->setStencilHighlight(entityId, r, g, b);

View File

@@ -26,7 +26,7 @@ extern "C"
#include <thread>
#include <stdlib.h>
using namespace thermion_filament;
using namespace thermion;
using namespace std::chrono_literals;
#include <time.h>

View File

@@ -20,7 +20,7 @@
#include "CustomGeometry.hpp"
#include "UnprojectTexture.hpp"
namespace thermion_filament
namespace thermion
{
bool UnprojectTexture::isInsideTriangle(const math::float2 &p, const math::float2 &a, const math::float2 &b, const math::float2 &c)
@@ -207,5 +207,5 @@ namespace thermion_filament
}
}
} // namespace thermion_filament
} // namespace thermion