refactoring

This commit is contained in:
Nick Fisher
2025-03-22 10:49:24 +08:00
parent a67f42f0de
commit 0cbbc058e0
22 changed files with 675 additions and 463 deletions

View File

@@ -3,7 +3,11 @@
#include <filament/Scene.h>
#include "c_api/TGizmo.h"
#include "c_api/TSceneAsset.h"
#include "scene/Gizmo.hpp"
#include "scene/GltfSceneAsset.hpp"
#include "resources/translation_gizmo_glb.h"
#include "resources/rotation_gizmo_glb.h"
#include "Log.hpp"
#ifdef __cplusplus
@@ -14,6 +18,61 @@ namespace thermion
using namespace filament;
#endif
EMSCRIPTEN_KEEPALIVE TGizmo *Gizmo_create(
TEngine *tEngine,
TGltfAssetLoader *assetLoader,
TGltfResourceLoader *tGltfResourceLoader,
TNameComponentManager *tNameComponentManager,
TView *tView,
TMaterial *tMaterial,
TGizmoType tGizmoType) {
auto *engine = reinterpret_cast<Engine *>(tEngine);
auto *view = reinterpret_cast<View *>(tView);
auto *material = reinterpret_cast<Material *>(tMaterial);
auto *gltfResourceLoader = reinterpret_cast<gltfio::ResourceLoader *>(tGltfResourceLoader);
TSceneAsset *sceneAsset;
switch (tGizmoType)
{
case GIZMO_TYPE_TRANSLATION:
{
TRACE("Building translation gizmo");
sceneAsset = SceneAsset_loadGlb(
tEngine,
assetLoader,
tNameComponentManager,
TRANSLATION_GIZMO_GLB_TRANSLATION_GIZMO_DATA,
TRANSLATION_GIZMO_GLB_TRANSLATION_GIZMO_SIZE,
3
);
break;
}
case GIZMO_TYPE_ROTATION:
{
TRACE("Building rotation gizmo");
sceneAsset = SceneAsset_loadGlb(
tEngine,
assetLoader,
tNameComponentManager,
ROTATION_GIZMO_GLB_ROTATION_GIZMO_DATA,
ROTATION_GIZMO_GLB_ROTATION_GIZMO_SIZE,
3
);
break;
}
}
auto *gltfSceneAsset = reinterpret_cast<GltfSceneAsset *>(sceneAsset);
auto *filamentAsset = gltfSceneAsset->getAsset();
gltfResourceLoader->loadResources(filamentAsset);
auto *gizmo = new Gizmo(
gltfSceneAsset,
engine,
view,
material
);
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);