chore: refactoring and cleanup for Gizmo
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
#include "Log.hpp"
|
||||
#include "CustomGeometry.hpp"
|
||||
|
||||
namespace thermion_filament {
|
||||
namespace thermion {
|
||||
|
||||
using namespace filament;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "SceneManager.hpp"
|
||||
|
||||
namespace thermion_filament
|
||||
namespace thermion
|
||||
{
|
||||
|
||||
SceneManager::HighlightOverlay::HighlightOverlay(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
namespace thermion_filament {
|
||||
namespace thermion {
|
||||
|
||||
class StreamBufferAdapter : public std::streambuf
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user