refactoring
This commit is contained in:
@@ -36,6 +36,7 @@ set(MATERIAL_SOURCES
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/material/image.c"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/material/grid.c"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/material/unlit.c"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/material/unlit_fixed_size.c"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/material/gizmo.c"
|
||||
)
|
||||
|
||||
|
||||
@@ -153,8 +153,8 @@ extern "C"
|
||||
typedef struct Aabb3 Aabb3;
|
||||
|
||||
enum TGizmoType {
|
||||
TRANSLATION,
|
||||
ROTATION
|
||||
GIZMO_TYPE_TRANSLATION,
|
||||
GIZMO_TYPE_ROTATION
|
||||
};
|
||||
|
||||
enum TPrimitiveType {
|
||||
|
||||
@@ -16,7 +16,15 @@ enum TGizmoPickResultType { AxisX, AxisY, AxisZ, Parent, None };
|
||||
|
||||
typedef void (*GizmoPickCallback)(TGizmoPickResultType resultType, float x, float y, float z);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TGizmo *Gizmo_create(TEngine *tEngine, TView *tView, TGizmoType tGizmoType);
|
||||
EMSCRIPTEN_KEEPALIVE TGizmo *Gizmo_create(
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *assetLoader,
|
||||
TGltfResourceLoader *tGltfResourceLoader,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
TView *tView,
|
||||
TMaterial *tMaterial,
|
||||
TGizmoType tGizmoType
|
||||
);
|
||||
EMSCRIPTEN_KEEPALIVE void Gizmo_pick(TGizmo *tGizmo, uint32_t x, uint32_t y, GizmoPickCallback callback);
|
||||
EMSCRIPTEN_KEEPALIVE void Gizmo_highlight(TGizmo *tGizmo, TGizmoAxis axis);
|
||||
EMSCRIPTEN_KEEPALIVE void Gizmo_unhighlight(TGizmo *tGizmo);
|
||||
|
||||
@@ -13,7 +13,7 @@ EMSCRIPTEN_KEEPALIVE TGltfAssetLoader *GltfAssetLoader_create(TEngine *tEngine,
|
||||
EMSCRIPTEN_KEEPALIVE TFilamentAsset *GltfAssetLoader_load(
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
uint8_t *data,
|
||||
const uint8_t *data,
|
||||
size_t length,
|
||||
uint8_t numInstances
|
||||
);
|
||||
|
||||
@@ -70,6 +70,7 @@ extern "C"
|
||||
EMSCRIPTEN_KEEPALIVE TMaterialInstance *Material_createInstance(TMaterial *tMaterial);
|
||||
EMSCRIPTEN_KEEPALIVE TMaterial *Material_createImageMaterial(TEngine *tEngine);
|
||||
EMSCRIPTEN_KEEPALIVE TMaterial *Material_createGridMaterial(TEngine *tEngine);
|
||||
EMSCRIPTEN_KEEPALIVE TMaterial *Material_createGizmoMaterial(TEngine *tEngine);
|
||||
EMSCRIPTEN_KEEPALIVE bool Material_hasParameter(TMaterial *tMaterial, const char *propertyName);
|
||||
EMSCRIPTEN_KEEPALIVE bool MaterialInstance_isStencilWriteEnabled(TMaterialInstance *materialInstance);
|
||||
EMSCRIPTEN_KEEPALIVE void MaterialInstance_setStencilWrite(TMaterialInstance *materialInstance, bool enabled);
|
||||
|
||||
@@ -27,7 +27,7 @@ extern "C"
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
uint8_t *data,
|
||||
const uint8_t *data,
|
||||
size_t length,
|
||||
size_t numInstances
|
||||
);
|
||||
@@ -37,7 +37,7 @@ extern "C"
|
||||
TGltfResourceLoader *tResourceLoader,
|
||||
TEngine *tEngine,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
uint8_t *data,
|
||||
const uint8_t *data,
|
||||
size_t length,
|
||||
size_t numInstances
|
||||
);
|
||||
|
||||
@@ -81,6 +81,7 @@ namespace thermion
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Material_createInstanceRenderThread(TMaterial *tMaterial, void (*onComplete)(TMaterialInstance *));
|
||||
EMSCRIPTEN_KEEPALIVE void Material_createImageMaterialRenderThread(TEngine *tEngine, void (*onComplete)(TMaterial *));
|
||||
EMSCRIPTEN_KEEPALIVE void Material_createGizmoMaterialRenderThread(TEngine *tEngine, void (*onComplete)(TMaterial *));
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void ColorGrading_createRenderThread(TEngine *tEngine, TToneMapping toneMapping, void (*callback)(TColorGrading *));
|
||||
EMSCRIPTEN_KEEPALIVE void View_setColorGradingRenderThread(TView *tView, TColorGrading *tColorGrading, void (*callback)());
|
||||
@@ -116,7 +117,6 @@ namespace thermion
|
||||
void (*callback)(TSceneAsset *)
|
||||
);
|
||||
EMSCRIPTEN_KEEPALIVE void MaterialProvider_createMaterialInstanceRenderThread(TMaterialProvider *tMaterialProvider, TMaterialKey *tKey, void (*callback)(TMaterialInstance *));
|
||||
EMSCRIPTEN_KEEPALIVE void SceneManager_destroyMaterialInstanceRenderThread(TSceneManager *tSceneManager, TMaterialInstance *tMaterialInstance, void (*callback)());
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void AnimationManager_updateBoneMatricesRenderThread(
|
||||
TAnimationManager *tAnimationManager,
|
||||
@@ -269,6 +269,16 @@ namespace thermion
|
||||
void (*callback)(TFilamentAsset *)
|
||||
);
|
||||
EMSCRIPTEN_KEEPALIVE void Scene_addFilamentAssetRenderThread(TScene* tScene, TFilamentAsset *tAsset, void (*callback)());
|
||||
EMSCRIPTEN_KEEPALIVE void Gizmo_createRenderThread(
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TGltfResourceLoader *tGltfResourceLoader,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
TView *tView,
|
||||
TMaterial *tMaterial,
|
||||
TGizmoType tGizmoType,
|
||||
void (*callback)(TGizmo *)
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ namespace thermion
|
||||
SceneAsset *sceneAsset,
|
||||
Engine *engine,
|
||||
View *view,
|
||||
Scene *scene,
|
||||
Material *material) noexcept;
|
||||
|
||||
Gizmo(Gizmo &&other) noexcept;
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace thermion
|
||||
Entity findEntityByName(const char* name) override {
|
||||
TRACE("Searching for entity with name %s", name);
|
||||
Entity entities[1];
|
||||
auto found = _asset->getEntitiesByName(name, entities, 1);
|
||||
auto found = _asset->getEntitiesByName(name, entities, 1);
|
||||
return entities[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +117,9 @@ namespace thermion
|
||||
for(int i = 0; i < getChildEntityCount(); i++) {
|
||||
auto entity = getChildEntities()[i];
|
||||
auto nameInstance = _ncm->getInstance(entity);
|
||||
if(!nameInstance.isValid()) {
|
||||
continue;
|
||||
}
|
||||
auto entityName = _ncm->getName(nameInstance);
|
||||
|
||||
if (strcmp(entityName, name) == 0) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -56,7 +56,7 @@ EMSCRIPTEN_KEEPALIVE TGltfAssetLoader *GltfAssetLoader_create(TEngine *tEngine,
|
||||
EMSCRIPTEN_KEEPALIVE TFilamentAsset *GltfAssetLoader_load(
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
uint8_t *data,
|
||||
const uint8_t *data,
|
||||
size_t length,
|
||||
uint8_t numInstances)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "MathUtils.hpp"
|
||||
#include "material/image.h"
|
||||
#include "material/grid.h"
|
||||
#include "material/unlit_fixed_size.h"
|
||||
|
||||
#include "c_api/TMaterialInstance.h"
|
||||
|
||||
@@ -45,7 +46,13 @@ namespace thermion
|
||||
return reinterpret_cast<TMaterial *>(material);
|
||||
}
|
||||
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TMaterial *Material_createGizmoMaterial(TEngine *tEngine) {
|
||||
auto *engine = reinterpret_cast<filament::Engine *>(tEngine);
|
||||
auto *material = filament::Material::Builder()
|
||||
.package(UNLIT_FIXED_SIZE_UNLIT_FIXED_SIZE_DATA, UNLIT_FIXED_SIZE_UNLIT_FIXED_SIZE_SIZE)
|
||||
.build(*engine);
|
||||
return reinterpret_cast<TMaterial *>(material);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE bool Material_hasParameter(TMaterial *tMaterial, const char *propertyName) {
|
||||
auto *material = reinterpret_cast<filament::Material *>(tMaterial);
|
||||
|
||||
@@ -70,7 +70,7 @@ extern "C"
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
uint8_t *data,
|
||||
const uint8_t *data,
|
||||
size_t length,
|
||||
size_t numInstances
|
||||
) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "c_api/APIBoundaryTypes.h"
|
||||
#include "c_api/TAnimationManager.h"
|
||||
#include "c_api/TEngine.h"
|
||||
#include "c_api/TGizmo.h"
|
||||
#include "c_api/TGltfAssetLoader.h"
|
||||
#include "c_api/TGltfResourceLoader.h"
|
||||
#include "c_api/TRenderer.h"
|
||||
@@ -380,6 +381,17 @@ extern "C"
|
||||
});
|
||||
auto fut = _renderThread->add_task(lambda);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Material_createGizmoMaterialRenderThread(TEngine *tEngine, void (*onComplete)(TMaterial *)) {
|
||||
std::packaged_task<void()> lambda(
|
||||
[=]() mutable
|
||||
{
|
||||
auto *instance = Material_createGizmoMaterial(tEngine);
|
||||
onComplete(instance);
|
||||
});
|
||||
auto fut = _renderThread->add_task(lambda);
|
||||
}
|
||||
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Material_createInstanceRenderThread(TMaterial *tMaterial, void (*onComplete)(TMaterialInstance *))
|
||||
{
|
||||
@@ -1010,4 +1022,23 @@ extern "C"
|
||||
});
|
||||
auto fut = _renderThread->add_task(lambda);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Gizmo_createRenderThread(
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TGltfResourceLoader *tGltfResourceLoader,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
TView *tView,
|
||||
TMaterial *tMaterial,
|
||||
TGizmoType tGizmoType,
|
||||
void (*callback)(TGizmo *)
|
||||
) {
|
||||
std::packaged_task<void()> lambda(
|
||||
[=]() mutable
|
||||
{
|
||||
auto *gizmo = Gizmo_create(tEngine, tAssetLoader,tGltfResourceLoader, tNameComponentManager, tView, tMaterial, tGizmoType);
|
||||
callback(gizmo);
|
||||
});
|
||||
auto fut = _renderThread->add_task(lambda);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user