fix instancing so that gltf assets always fill the first instance slot
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "c_api/TGizmo.h"
|
||||
#include "c_api/TSceneAsset.h"
|
||||
#include "c_api/TGltfAssetLoader.h"
|
||||
#include "scene/Gizmo.hpp"
|
||||
#include "scene/GltfSceneAsset.hpp"
|
||||
#include "resources/translation_gizmo_glb.h"
|
||||
@@ -20,56 +21,59 @@ namespace thermion
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TGizmo *Gizmo_create(
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *assetLoader,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TGltfResourceLoader *tGltfResourceLoader,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
TView *tView,
|
||||
TMaterial *tMaterial,
|
||||
TGizmoType tGizmoType) {
|
||||
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;
|
||||
const uint8_t *data;
|
||||
size_t size;
|
||||
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
|
||||
);
|
||||
data = TRANSLATION_GIZMO_GLB_TRANSLATION_GIZMO_DATA;
|
||||
size = TRANSLATION_GIZMO_GLB_TRANSLATION_GIZMO_SIZE;
|
||||
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;
|
||||
}
|
||||
}
|
||||
case GIZMO_TYPE_ROTATION:
|
||||
{
|
||||
TRACE("Building rotation gizmo");
|
||||
data = ROTATION_GIZMO_GLB_ROTATION_GIZMO_DATA;
|
||||
size = ROTATION_GIZMO_GLB_ROTATION_GIZMO_SIZE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
auto *tFilamentAsset = GltfAssetLoader_load(
|
||||
tEngine,
|
||||
tAssetLoader,
|
||||
data,
|
||||
size,
|
||||
3);
|
||||
auto *filamentAsset = reinterpret_cast<gltfio::FilamentAsset *>(tFilamentAsset);
|
||||
auto *sceneAsset = SceneAsset_createFromFilamentAsset(
|
||||
tEngine,
|
||||
tAssetLoader,
|
||||
tNameComponentManager,
|
||||
tFilamentAsset);
|
||||
|
||||
auto *gltfSceneAsset = reinterpret_cast<GltfSceneAsset *>(sceneAsset);
|
||||
auto *filamentAsset = gltfSceneAsset->getAsset();
|
||||
|
||||
gltfResourceLoader->loadResources(filamentAsset);
|
||||
auto *gizmo = new Gizmo(
|
||||
gltfSceneAsset,
|
||||
engine,
|
||||
view,
|
||||
material
|
||||
);
|
||||
gltfSceneAsset,
|
||||
engine,
|
||||
view,
|
||||
material);
|
||||
return reinterpret_cast<TGizmo *>(gizmo);
|
||||
}
|
||||
|
||||
|
||||
@@ -114,6 +114,20 @@ EMSCRIPTEN_KEEPALIVE TMaterialProvider *GltfAssetLoader_getMaterialProvider(TGlt
|
||||
return reinterpret_cast<TMaterialProvider *>(&materialProvider);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE int32_t FilamentAsset_getResourceUriCount(
|
||||
TFilamentAsset *tFilamentAsset
|
||||
) {
|
||||
auto *filamentAsset = reinterpret_cast<gltfio::FilamentAsset *>(tFilamentAsset);
|
||||
return filamentAsset->getResourceUriCount();
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE const char* const* FilamentAsset_getResourceUris(
|
||||
TFilamentAsset *tFilamentAsset
|
||||
) {
|
||||
auto *filamentAsset = reinterpret_cast<gltfio::FilamentAsset *>(tFilamentAsset);
|
||||
return filamentAsset->getResourceUris();
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,17 +66,14 @@ extern "C"
|
||||
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TSceneAsset *SceneAsset_loadGlb(
|
||||
EMSCRIPTEN_KEEPALIVE TSceneAsset *SceneAsset_createFromFilamentAsset(
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
const uint8_t *data,
|
||||
size_t length,
|
||||
size_t numInstances
|
||||
TFilamentAsset *tFilamentAsset
|
||||
) {
|
||||
auto *engine = reinterpret_cast<filament::Engine *>(tEngine);
|
||||
auto *nameComponentManager = reinterpret_cast<utils::NameComponentManager *>(tNameComponentManager);
|
||||
auto *tFilamentAsset = GltfAssetLoader_load(tEngine, tAssetLoader, data, length, numInstances);
|
||||
auto *filamentAsset = reinterpret_cast<filament::gltfio::FilamentAsset *>(tFilamentAsset);
|
||||
|
||||
auto *assetLoader = reinterpret_cast<filament::gltfio::AssetLoader *>(tAssetLoader);
|
||||
@@ -89,33 +86,6 @@ extern "C"
|
||||
|
||||
return reinterpret_cast<TSceneAsset *>(sceneAsset);
|
||||
}
|
||||
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE int32_t SceneAsset_getResourceUriCount(
|
||||
TSceneAsset *tSceneAsset
|
||||
) {
|
||||
auto sceneAsset = reinterpret_cast<SceneAsset *>(tSceneAsset);
|
||||
if(sceneAsset->getType() != SceneAsset::SceneAssetType::Gltf) {
|
||||
Log("Error - not a gltf asset");
|
||||
return -1;
|
||||
}
|
||||
auto gltfAsset = reinterpret_cast<GltfSceneAsset *>(tSceneAsset);
|
||||
auto *filamentAsset = gltfAsset->getAsset();
|
||||
return filamentAsset->getResourceUriCount();
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE const char* const* SceneAsset_getResourceUris(
|
||||
TSceneAsset *tSceneAsset
|
||||
) {
|
||||
auto sceneAsset = reinterpret_cast<SceneAsset *>(tSceneAsset);
|
||||
if(sceneAsset->getType() != SceneAsset::SceneAssetType::Gltf) {
|
||||
Log("Error - not a gltf asset");
|
||||
return nullptr;
|
||||
}
|
||||
auto gltfAsset = reinterpret_cast<GltfSceneAsset *>(tSceneAsset);
|
||||
auto *filamentAsset = gltfAsset->getAsset();
|
||||
return filamentAsset->getResourceUris();
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TFilamentAsset *SceneAsset_getFilamentAsset(TSceneAsset *tSceneAsset) {
|
||||
auto sceneAsset = reinterpret_cast<SceneAsset *>(tSceneAsset);
|
||||
@@ -130,7 +100,6 @@ extern "C"
|
||||
return reinterpret_cast<TFilamentAsset *>(filamentAsset);
|
||||
}
|
||||
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TSceneAsset *SceneAsset_createGrid(TEngine *tEngine, TMaterial* tMaterial) {
|
||||
auto *engine = reinterpret_cast<filament::Engine *>(tEngine);
|
||||
auto *material = reinterpret_cast<filament::Material *>(tMaterial);
|
||||
@@ -234,6 +203,11 @@ extern "C"
|
||||
return reinterpret_cast<TSceneAsset*>(instance);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE size_t SceneAsset_getInstanceCount(TSceneAsset *tSceneAsset) {
|
||||
auto *asset = reinterpret_cast<SceneAsset*>(tSceneAsset);
|
||||
return asset->getInstanceCount();
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TSceneAsset *SceneAsset_createInstance(TSceneAsset *tSceneAsset, TMaterialInstance **tMaterialInstances, int materialInstanceCount)
|
||||
{
|
||||
auto *materialInstances = reinterpret_cast<MaterialInstance **>(tMaterialInstances);
|
||||
|
||||
@@ -415,23 +415,6 @@ extern "C"
|
||||
auto fut = _renderThread->add_task(lambda);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void SceneAsset_loadGlbRenderThread(
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
uint8_t *data,
|
||||
size_t length,
|
||||
size_t numInstances,
|
||||
void (*callback)(TSceneAsset *)
|
||||
) {
|
||||
std::packaged_task<void()> lambda(
|
||||
[=]
|
||||
{
|
||||
auto sceneAsset = SceneAsset_loadGlb(tEngine, tAssetLoader, tNameComponentManager, data, length, numInstances);
|
||||
callback(sceneAsset);
|
||||
});
|
||||
auto fut = _renderThread->add_task(lambda);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void SceneAsset_createGeometryRenderThread(
|
||||
TEngine *tEngine,
|
||||
@@ -457,6 +440,22 @@ extern "C"
|
||||
auto fut = _renderThread->add_task(lambda);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void SceneAsset_createFromFilamentAssetRenderThread(
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
TFilamentAsset *tFilamentAsset,
|
||||
void (*onComplete)(TSceneAsset *)
|
||||
) {
|
||||
std::packaged_task<void()> lambda(
|
||||
[=]
|
||||
{
|
||||
auto sceneAsset = SceneAsset_createFromFilamentAsset(tEngine, tAssetLoader, tNameComponentManager, tFilamentAsset);
|
||||
onComplete(sceneAsset);
|
||||
});
|
||||
auto fut = _renderThread->add_task(lambda);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void SceneAsset_createInstanceRenderThread(
|
||||
TSceneAsset *asset, TMaterialInstance **tMaterialInstances,
|
||||
int materialInstanceCount,
|
||||
|
||||
Reference in New Issue
Block a user