more refactoring

This commit is contained in:
Nick Fisher
2025-03-18 18:06:17 +08:00
parent 77fe40848b
commit 951f5daa2d
54 changed files with 19065 additions and 16751 deletions
+31 -21
View File
@@ -1,25 +1,31 @@
#pragma once
#include <filament/Engine.h>
#include <filament/Renderer.h>
#include <filament/View.h>
#include <math/vec3.h>
#include <math/vec4.h>
#include <math/mat3.h>
#include <math/norm.h>
#include <fstream>
#include <iostream>
#include <string>
#include <chrono>
#include <mutex>
#include <vector>
#include <map>
#include "scene/SceneManager.hpp"
#include <filament/Renderer.h>
#include <filament/SwapChain.h>
#include <filament/View.h>
#include <filament/Viewport.h>
#include <filament/Camera.h>
#include <filament/Engine.h>
#include <filament/IndexBuffer.h>
#include <filament/Material.h>
#include <filament/MaterialInstance.h>
#include <filament/RenderableManager.h>
#include <filament/Scene.h>
#include <filament/TransformManager.h>
#include <filament/VertexBuffer.h>
#include "scene/AnimationManager.hpp"
namespace thermion
{
typedef std::chrono::time_point<std::chrono::high_resolution_clock> time_point_t;
typedef std::chrono::time_point time_point_t;
using namespace std::chrono;
@@ -27,22 +33,26 @@ namespace thermion
{
public:
RenderTicker(filament::Renderer renderer, thermion::SceneManager sceneManager) : mRenderer(renderer), mSceneManager(sceneManager) { }
RenderTicker(filament::Renderer *renderer) : mRenderer(renderer) { }
~RenderTicker();
void render(
uint64_t frameTimeInNanos
);
void setRenderable(SwapChain *swapChain, View **view, uint8_t numViews);
void setRenderable(filament::SwapChain *swapChain, filament::View **view, uint8_t numViews);
void addAnimationManager(AnimationManager* animationManager);
void removeAnimationManager(AnimationManager* animationManager);
private:
std::mutex mMutex;
Renderer *mRenderer = nullptr;
SceneManager *mSceneManager = nullptr;
std::vector<SwapChain*> mSwapChains;
std::map<SwapChain*, std::vector<View*>> mRenderable;
filament::Renderer *mRenderer = nullptr;
std::vector<AnimationManager*> mAnimationManagers;
std::vector<filament::SwapChain*> mSwapChains;
std::map<filament::SwapChain*, std::vector<filament::View*>> mRenderable;
};
}
}
@@ -8,6 +8,8 @@ extern "C"
{
#endif
EMSCRIPTEN_KEEPALIVE TAnimationManager *AnimationManager_create(TEngine *tEngine);
EMSCRIPTEN_KEEPALIVE void AnimationManager_addAnimationComponent(TAnimationManager *tAnimationManager, EntityId entityId);
EMSCRIPTEN_KEEPALIVE void AnimationManager_removeAnimationComponent(TAnimationManager *tAnimationManager, EntityId entityId);
@@ -43,6 +43,7 @@ EMSCRIPTEN_KEEPALIVE void Engine_flushAndWait(TEngine *tEngine);
EMSCRIPTEN_KEEPALIVE TMaterial *Engine_buildMaterial(TEngine *tEngine, const uint8_t* materialData, size_t length);
EMSCRIPTEN_KEEPALIVE void Engine_destroyMaterial(TEngine *tEngine, TMaterial *tMaterial);
EMSCRIPTEN_KEEPALIVE void Engine_destroyMaterialInstance(TEngine *tEngine, TMaterialInstance *tMaterialInstance);
EMSCRIPTEN_KEEPALIVE TScene *Engine_createScene(TEngine *tEngine);
EMSCRIPTEN_KEEPALIVE TSkybox *Engine_buildSkybox(TEngine *tEngine, uint8_t* ktxData, size_t length, void(*onTextureUploadComplete)());
EMSCRIPTEN_KEEPALIVE TIndirectLight *Engine_buildIndirectLight(TEngine *tEngine, uint8_t* ktxData, size_t length, float intensity, void(*onTextureUploadComplete)());
@@ -12,7 +12,7 @@ extern "C"
{
#endif
EMSCRIPTEN_KEEPALIVE void IndirectLight_setRotation(TIndirectLight TIndirectLight, double3x3 rotation);
EMSCRIPTEN_KEEPALIVE void IndirectLight_setRotation(TIndirectLight *tIndirectLight, double *rotation);
#ifdef __cplusplus
}
@@ -9,11 +9,19 @@ extern "C"
{
#endif
enum TLightType {
LIGHT_TYPE_SUN,
LIGHT_TYPE_DIRECTIONAL,
LIGHT_TYPE_POINT,
LIGHT_TYPE_FOCUSED_SPOT,
LIGHT_TYPE_SPOT
};
EMSCRIPTEN_KEEPALIVE void LightManager_setPosition(TLightManager *tLightManager, EntityId light, double x, double y, double z);
EMSCRIPTEN_KEEPALIVE void LightManager_setDirection(TLightManager *tLightManager, EntityId light, double x, double y, double z);
EMSCRIPTEN_KEEPALIVE int LightManager_createLight(TLightManager *tLightManager, EntityId entity, int type);
EMSCRIPTEN_KEEPALIVE int LightManager_createLight(TLightManager *tLightManager, TLightType tLightTtype);
EMSCRIPTEN_KEEPALIVE void LightManager_destroyLight(TLightManager *tLightManager, EntityId entity);
EMSCRIPTEN_KEEPALIVE void LightManager_setColor(TLightManager *tLightManager, EntityId entity, double r, double g, double b);
EMSCRIPTEN_KEEPALIVE void LightManager_setColor(TLightManager *tLightManager, EntityId entity, float colorTemperature);
EMSCRIPTEN_KEEPALIVE void LightManager_setIntensity(TLightManager *tLightManager, EntityId entity, double intensity);
EMSCRIPTEN_KEEPALIVE void LightManager_setFalloff(TLightManager *tLightManager, EntityId entity, double falloff);
EMSCRIPTEN_KEEPALIVE void LightManager_setSpotLightCone(TLightManager *tLightManager, EntityId entity, double inner, double outer);
@@ -7,7 +7,7 @@
extern "C"
{
#endif
EMSCRIPTEN_KEEPALIVE TNameComponentManager *NameComponentManager_create();
EMSCRIPTEN_KEEPALIVE const char *NameComponentManager_getName(TNameComponentManager *tNameComponentManager, EntityId entity);
@@ -8,7 +8,10 @@ extern "C"
{
#endif
EMSCRIPTEN_KEEPALIVE TRenderTicker *RenderTicker_create(TRenderer *tRenderer, TSceneManager *tSceneManager);
EMSCRIPTEN_KEEPALIVE TRenderTicker *RenderTicker_create(TRenderer *tRenderer);
EMSCRIPTEN_KEEPALIVE void RenderTicker_addAnimationManager(TRenderTicker *tRenderTicker, TAnimationManager *tAnimationManager);
EMSCRIPTEN_KEEPALIVE void RenderTicker_removeAnimationManager(TRenderTicker *tRenderTicker, TAnimationManager *tAnimationManager);
EMSCRIPTEN_KEEPALIVE void RenderTicker_render(TRenderTicker *tRenderTicker, uint64_t frameTimeInNanos);
EMSCRIPTEN_KEEPALIVE void RenderTicker_setRenderable(TRenderTicker *tFilamentRender, TSwapChain *swapChain, TView **views, uint8_t numViews);
@@ -20,6 +20,7 @@ extern "C"
EMSCRIPTEN_KEEPALIVE void RenderableManager_setReceiveShadows(TRenderableManager *tRenderableManager, EntityId entityId, bool receiveShadows);
EMSCRIPTEN_KEEPALIVE bool RenderableManager_isShadowReceiver(TRenderableManager *tRenderableManager, EntityId entityId);
EMSCRIPTEN_KEEPALIVE bool RenderableManager_getFogEnabled(TRenderableManager *tRenderableManager, EntityId entityId);
EMSCRIPTEN_KEEPALIVE Aabb3 RenderableManager_getAabb(TRenderableManager *tRenderableManager, EntityId entityId);
#ifdef __cplusplus
}
@@ -16,6 +16,7 @@ extern "C"
EMSCRIPTEN_KEEPALIVE void Scene_addEntity(TScene* tScene, EntityId entityId);
EMSCRIPTEN_KEEPALIVE void Scene_removeEntity(TScene* tScene, EntityId entityId);
EMSCRIPTEN_KEEPALIVE void Scene_setSkybox(TScene* tScene, TSkybox *skybox);
EMSCRIPTEN_KEEPALIVE void Scene_setIndirectLight(TScene* tScene, TIndirectLight *tIndirectLight);
EMSCRIPTEN_KEEPALIVE void Scene_addFilamentAsset(TScene* tScene, TFilamentAsset *asset);
@@ -24,7 +24,29 @@ extern "C"
TMaterialInstance **materialInstances,
int materialInstanceCount
);
EMSCRIPTEN_KEEPALIVE TSceneAsset *SceneAsset_loadGlb(
TGltfAssetLoader *tAssetLoader,
TGltfResourceLoader *tResourceLoader,
TEngine *tEngine,
TNameComponentManager *tNameComponentManager,
uint8_t *data,
size_t length,
size_t numInstances
);
EMSCRIPTEN_KEEPALIVE TSceneAsset *SceneAsset_loadGltf(
TGltfAssetLoader *tAssetLoader,
TGltfResourceLoader *tResourceLoader,
TEngine *tEngine,
TNameComponentManager *tNameComponentManager,
uint8_t *data,
size_t length,
size_t numInstances
);
EMSCRIPTEN_KEEPALIVE void SceneAsset_addToScene(TSceneAsset *tSceneAsset, TScene *tScene);
EMSCRIPTEN_KEEPALIVE void SceneAsset_removeFromScene(TSceneAsset *tSceneAsset, TScene *tScene);
EMSCRIPTEN_KEEPALIVE EntityId SceneAsset_getEntity(TSceneAsset *tSceneAsset);
EMSCRIPTEN_KEEPALIVE int SceneAsset_getChildEntityCount(TSceneAsset* tSceneAsset);
EMSCRIPTEN_KEEPALIVE void SceneAsset_getChildEntities(TSceneAsset* tSceneAsset, EntityId *out);
@@ -20,6 +20,8 @@ namespace thermion
EMSCRIPTEN_KEEPALIVE void RenderTicker_renderRenderThread(TRenderTicker *tRenderTicker, uint64_t frameTimeInNanos,);
// EMSCRIPTEN_KEEPALIVE void RenderLoop_addTask(TRenderLoop* tRenderLoop, void (*task)());
EMSCRIPTEN_KEEPALIVE void AnimationManager_createRenderThread(TEngine *tEngine, TScene *tScene, void (*onComplete)(TAnimationManager *));
EMSCRIPTEN_KEEPALIVE void Engine_createRenderThread(
TBackend backend,
void* platform,
@@ -36,6 +38,7 @@ namespace thermion
EMSCRIPTEN_KEEPALIVE void Engine_buildMaterialRenderThread(TEngine *tEngine, const uint8_t *materialData, size_t length, void (*onComplete)(TMaterial *));
EMSCRIPTEN_KEEPALIVE void Engine_destroySwapChainRenderThread(TEngine *tEngine, TSwapChain *tSwapChain, void (*onComplete)());
EMSCRIPTEN_KEEPALIVE void Engine_destroyMaterialRenderThread(TEngine *tEngine, TMaterial *tMaterial, void (*onComplete)());
EMSCRIPTEN_KEEPALIVE void Engine_destroyMaterialInstanceRenderThread(TEngine *tEngine, TMaterialInstance *tMaterialInstance, void (*onComplete)());
EMSCRIPTEN_KEEPALIVE void Engine_destroySkyboxRenderThread(TEngine *tEngine, TSkybox *tSkybox, void (*onComplete)());
EMSCRIPTEN_KEEPALIVE void Engine_destroyIndirectLightRenderThread(TEngine *tEngine, TIndirectLight *tIndirectLight, void (*onComplete)());
EMSCRIPTEN_KEEPALIVE void Texture_buildRenderThread(TEngine *engine,
@@ -8,5 +8,5 @@ GIZMO_PACKAGE:
GIZMO_GIZMO_OFFSET:
.int 0
GIZMO_GIZMO_SIZE:
.int 45584
.int 45867
@@ -8,5 +8,5 @@ _GIZMO_PACKAGE:
_GIZMO_GIZMO_OFFSET:
.int 0
_GIZMO_GIZMO_SIZE:
.int 45584
.int 45867
Binary file not shown.
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -8,5 +8,5 @@ GRID_PACKAGE:
GRID_GRID_OFFSET:
.int 0
GRID_GRID_SIZE:
.int 52130
.int 52018
@@ -8,5 +8,5 @@ _GRID_PACKAGE:
_GRID_GRID_OFFSET:
.int 0
_GRID_GRID_SIZE:
.int 52130
.int 52018
Binary file not shown.
File diff suppressed because it is too large Load Diff
@@ -8,5 +8,5 @@ IMAGE_PACKAGE:
IMAGE_IMAGE_OFFSET:
.int 0
IMAGE_IMAGE_SIZE:
.int 56612
.int 63850
@@ -8,5 +8,5 @@ _IMAGE_PACKAGE:
_IMAGE_IMAGE_OFFSET:
.int 0
_IMAGE_IMAGE_SIZE:
.int 56612
.int 63850
Binary file not shown.
File diff suppressed because it is too large Load Diff
@@ -8,5 +8,5 @@ UNLIT_PACKAGE:
UNLIT_UNLIT_OFFSET:
.int 0
UNLIT_UNLIT_SIZE:
.int 106370
.int 157994
@@ -8,5 +8,5 @@ _UNLIT_PACKAGE:
_UNLIT_UNLIT_OFFSET:
.int 0
_UNLIT_UNLIT_SIZE:
.int 106370
.int 157994
Binary file not shown.
File diff suppressed because it is too large Load Diff
@@ -8,5 +8,5 @@ UNLIT_FIXED_SIZE_PACKAGE:
UNLIT_FIXED_SIZE_UNLIT_FIXED_SIZE_OFFSET:
.int 0
UNLIT_FIXED_SIZE_UNLIT_FIXED_SIZE_SIZE:
.int 45632
.int 45907
@@ -8,5 +8,5 @@ _UNLIT_FIXED_SIZE_PACKAGE:
_UNLIT_FIXED_SIZE_UNLIT_FIXED_SIZE_OFFSET:
.int 0
_UNLIT_FIXED_SIZE_UNLIT_FIXED_SIZE_SIZE:
.int 45632
.int 45907
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+56 -25
View File
@@ -1,3 +1,5 @@
#if __APPLE__
#include "TargetConditionals.h"
#endif
@@ -6,35 +8,31 @@
#pragma comment(lib, "Ws2_32.lib")
#endif
#include <filament/Camera.h>
#include <filament/SwapChain.h>
#include <backend/DriverEnums.h>
#include <backend/platforms/OpenGLPlatform.h>
#include <math/mat4.h>
#include <utils/EntityManager.h>
#include <utils/Panic.h>
#include <utils/Systrace.h>
#ifdef __EMSCRIPTEN__
#include <backend/platforms/PlatformWebGL.h>
#include <emscripten/emscripten.h>
#include <emscripten/bind.h>
#include <emscripten.h>
#include <emscripten/html5.h>
#include <emscripten/threading.h>
#include <emscripten/val.h>
#include <filament/webgl/WebEngine.h>
#include <sys/types.h>
#endif
#include <filament/Box.h>
#include <filament/Camera.h>
#include <filament/ColorGrading.h>
#include <filament/Engine.h>
#include <filament/Options.h>
#include <filament/Renderer.h>
#include <filament/View.h>
#include <filament/IndexBuffer.h>
#include <filament/IndirectLight.h>
#include <filament/LightManager.h>
#include <filament/Material.h>
#include <filament/MaterialInstance.h>
#include <filament/RenderableManager.h>
#include <iostream>
#include <streambuf>
#include <sstream>
#include <istream>
#include <fstream>
#include <filesystem>
#include <mutex>
#include <iomanip>
#include <unordered_set>
#include <filament/Scene.h>
#include <filament/Skybox.h>
#include <filament/TransformManager.h>
#include <filament/VertexBuffer.h>
#include "Log.hpp"
@@ -70,13 +68,32 @@ namespace thermion
}
mRenderable[swapChain] = swapChainViews;
// Keep track of the swapchains, so we can iterate them in the render method.
bool found = false;
for (auto existingSwapChain : mSwapChains) {
if (existingSwapChain == swapChain) {
found = true;
break;
}
}
if (!found) {
mSwapChains.push_back(swapChain);
}
}
}
void RenderTicker::render(uint64_t frameTimeInNanos)
{
std::lock_guard lock(mMutex);
mSceneManager->update();
// Update all animation managers
for (auto animationManager : mAnimationManagers) {
if (animationManager) { // Check for nullptr just in case
animationManager->update(frameTimeInNanos * 1e-9);
}
}
for (auto swapChain : mSwapChains)
{
@@ -99,5 +116,19 @@ namespace thermion
#endif
}
void RenderTicker::addAnimationManager(AnimationManager* animationManager) {
std::lock_guard<std::mutex> lock(mMutex);
mAnimationManagers.push_back(animationManager);
}
} // namespace thermion
void RenderTicker::removeAnimationManager(AnimationManager* animationManager) {
std::lock_guard<std::mutex> lock(mMutex);
auto it = std::find(mAnimationManagers.begin(), mAnimationManagers.end(), animationManager);
if (it != mAnimationManagers.end()) {
mAnimationManagers.erase(it);
}
}
RenderTicker::~RenderTicker() {}
} // namespace thermion
@@ -10,6 +10,13 @@ extern "C"
#include "c_api/TAnimationManager.h"
EMSCRIPTEN_KEEPALIVE TAnimationManager *AnimationManager_create(TEngine *tEngine, TScene *tScene) {
auto *engine = reinterpret_cast<filament::Engine *>(tEngine);
auto *scene = reinterpret_cast<filament::Scene *>(tScene);
auto animationManager = new AnimationManager(engine, scene);
return reinterpret_cast<TAnimationManager *>(animationManager);
}
EMSCRIPTEN_KEEPALIVE void AnimationManager_addAnimationComponent(TAnimationManager *tAnimationManager, EntityId entityId)
{
auto animationManager = reinterpret_cast<AnimationManager *>(tAnimationManager);
@@ -162,6 +162,12 @@ namespace thermion
engine->destroy(material);
}
EMSCRIPTEN_KEEPALIVE void Engine_destroyMaterialInstance(TEngine *tEngine, TMaterialInstance *tMaterialInstance) {
auto *engine = reinterpret_cast<Engine *>(tEngine);
auto *mi = reinterpret_cast<MaterialInstance *>(tMaterialInstance);
engine->destroy(mi);
}
EMSCRIPTEN_KEEPALIVE void Engine_destroyTexture(TEngine *tEngine, TTexture *tTexture)
{
auto *engine = reinterpret_cast<Engine *>(tEngine);
@@ -24,13 +24,13 @@ namespace thermion
using namespace filament;
#endif
EMSCRIPTEN_KEEPALIVE void IndirectLight_setRotation(TIndirectLight *tIndirectLight, double3x3 rotation)
EMSCRIPTEN_KEEPALIVE void IndirectLight_setRotation(TIndirectLight *tIndirectLight, double *rotation)
{
auto *indirectLight = reinterpret_cast<filament::IndirectLight *>(tIndirectLight);
const filament::math::mat3f fRotation {
filament::math::float3 { rotation.col1.x, rotation.col1.y, rotation.col1.z },
filament::math::float3 { rotation.col2.x, rotation.col2.y, rotation.col2.z },
filament::math::float3 { rotation.col3.x, rotation.col3.y, rotation.col3.z },
filament::math::float3 { static_cast<float>(rotation[0]), static_cast<float>(rotation[1]), static_cast<float>(rotation[2]) },
filament::math::float3 { static_cast<float>(rotation[3]), static_cast<float>(rotation[4]), static_cast<float>(rotation[5]) },
filament::math::float3 { static_cast<float>(rotation[6]), static_cast<float>(rotation[7]), static_cast<float>(rotation[8]) },
};
indirectLight->setRotation(fRotation);
}
@@ -1,10 +1,14 @@
#include <filament/LightManager.h>
#include <utils/Entity.h>
#include <utils/EntityManager.h>
#include "c_api/APIExport.h"
#include "Log.hpp"
#include "c_api/TLightManager.h"
#include "Log.hpp"
extern "C" {
EMSCRIPTEN_KEEPALIVE void LightManager_setPosition(TLightManager *tLightManager, EntityId light, double x, double y, double z) {
@@ -27,8 +31,9 @@ EMSCRIPTEN_KEEPALIVE void LightManager_setDirection(TLightManager *tLightManager
lightManager->setDirection(instance, filament::math::float3 { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z) });
}
EMSCRIPTEN_KEEPALIVE int LightManager_createLight(TLightManager *tLightManager, EntityId entity, int type) {
auto* lm = reinterpret_cast<filament::LightManager*>(tLightManager);
EMSCRIPTEN_KEEPALIVE int LightManager_createLight(TEngine *tEngine, TLightManager *tLightManager, TLightType type) {
auto *engine = reinterpret_cast<filament::Engine *>(tEngine);
auto *lightManager = reinterpret_cast<filament::LightManager*>(tLightManager);
filament::LightManager::Type lightType;
switch (type) {
@@ -41,9 +46,12 @@ EMSCRIPTEN_KEEPALIVE int LightManager_createLight(TLightManager *tLightManager,
}
filament::LightManager::Builder builder(lightType);
return false;
// auto result = builder.build(*lm->getEngine(), utils::Entity::import(entity));
// return result == filament::LightManager::Result::Success ? 0 : -1;
auto entity = utils::EntityManager::create();
auto result = builder.build(*engine, utils::Entity::import(entity));
if(result != filament::LightManager::Result::Success) {
Log("Failed to create light");
}
return entity;
}
EMSCRIPTEN_KEEPALIVE void LightManager_destroyLight(TLightManager *tLightManager, EntityId entity) {
@@ -51,11 +59,13 @@ EMSCRIPTEN_KEEPALIVE void LightManager_destroyLight(TLightManager *tLightManager
lm->destroy(utils::Entity::import(entity));
}
EMSCRIPTEN_KEEPALIVE void LightManager_setColor(TLightManager *tLightManager, EntityId entity, double r, double g, double b) {
EMSCRIPTEN_KEEPALIVE void LightManager_setColor(TLightManager *tLightManager, EntityId entity, float colorTemperature) {
auto* lm = reinterpret_cast<filament::LightManager*>(tLightManager);
auto color = filament::Color::cct(colorTemperature);
auto instance = lm->getInstance(utils::Entity::import(entity));
if (instance.isValid()) {
lm->setColor(instance, {static_cast<float>(r), static_cast<float>(g), static_cast<float>(b)});
lm->setColor(instance, color);
}
}
@@ -8,6 +8,12 @@ extern "C"
{
#endif
EMSCRIPTEN_KEEPALIVE TNameComponentManager *NameComponentManager_create()
{
auto *ncm = new utils::NameComponentManager(utils::EntityManager::get());
return reinterpret_cast<TNameComponentManager *>(ncm);
}
EMSCRIPTEN_KEEPALIVE const char *NameComponentManager_getName(TNameComponentManager *tNameComponentManager, EntityId entity)
{
auto ncm = reinterpret_cast<utils::NameComponentManager *>(tNameComponentManager);
@@ -18,13 +18,24 @@ extern "C"
{
#include "c_api/TRenderTicker.hpp"
EMSCRIPTEN_KEEPALIVE TRenderTicker *RenderTicker_create(TRenderer *tRenderer, TSceneManager *tSceneManager) {
EMSCRIPTEN_KEEPALIVE TRenderTicker *RenderTicker_create(TRenderer *tRenderer) {
auto *renderer = reinterpret_cast<filament::Renderer *>(tRenderer);
auto *sceneManager = reinterpret_cast<thermion::SceneManager *>(tSceneManager);
auto *renderTicker = new RenderTicker(renderer, sceneManager);
auto *renderTicker = new RenderTicker(renderer);
return reinterpret_cast<TRenderTicker *>(renderTicker);
}
EMSCRIPTEN_KEEPALIVE void RenderTicker_addAnimationManager(TRenderTicker *tRenderTicker, TAnimationManager *tAnimationManager) {
auto *renderTicker = reinterpret_cast<RenderTicker *>(tRenderTicker);
auto *animationManager = reinterpret_cast<thermion::AnimationManager *>(tAnimationManager);
renderTicker->addAnimationManager(animationManager);
}
EMSCRIPTEN_KEEPALIVE void RenderTicker_removeAnimationManager(TRenderTicker *tRenderTicker, TAnimationManager *tAnimationManager) {
auto *renderTicker = reinterpret_cast<RenderTicker *>(tRenderTicker);
auto *animationManager = reinterpret_cast<thermion::AnimationManager *>(tAnimationManager);
renderTicker->removeAnimationManager(animationManager);
}
EMSCRIPTEN_KEEPALIVE void RenderTicker_render(TRenderTicker *tRenderTicker, uint64_t frameTimeInNanos) {
auto *renderTicker = reinterpret_cast<RenderTicker *>
renderTicker->render(frameTimeInNanos);
@@ -120,5 +120,16 @@ namespace thermion
}
return renderableManager->getFogEnabled(renderableInstance);
}
EMSCRIPTEN_KEEPALIVE Aabb3 RenderableManager_getAabb(TRenderableManager *tRenderableManager, EntityId entityId) {
auto *renderableManager = reinterpret_cast<filament::RenderableManager *>(tRenderableManager);
const auto &entity = utils::Entity::import(entityId);
auto renderableInstance = renderableManager->getInstance(entity);
if (!renderableInstance.isValid()) {
return false;
}
auto box = rm.getAxisAlignedBoundingBox(instance);
return Aabb3{box.center.x, box.center.y, box.center.z, box.halfExtent.x, box.halfExtent.y, box.halfExtent.z};
}
}
}
@@ -29,6 +29,11 @@ namespace thermion
auto *scene = reinterpret_cast<Scene *>(tScene);
scene->addEntity(utils::Entity::import(entityId));
}
EMSCRIPTEN_KEEPALIVE void Scene_removeEntity(TScene* tScene, EntityId entityId) {
auto *scene = reinterpret_cast<Scene *>(tScene);
scene->removeEntity(utils::Entity::import(entityId));
}
EMSCRIPTEN_KEEPALIVE void Scene_setSkybox(TScene* tScene, TSkybox *tSkybox) {
auto *scene = reinterpret_cast<Scene *>(tScene);
@@ -1,4 +1,10 @@
#include <gltfio/AssetLoader.h>
#include <gltfio/ResourceLoader.h>
#include <utils/NameComponentManager.h>
#include "c_api/TGltfAssetLoader.h"
#include "c_api/TSceneAsset.h"
#include "scene/SceneAsset.hpp"
#include "scene/GltfSceneAsset.hpp"
@@ -59,12 +65,43 @@ extern "C"
}
EMSCRIPTEN_KEEPALIVE TSceneAsset *SceneAsset_loadGlb(
TGltfAssetLoader *tAssetLoader,
TGltfResourceLoader *tResourceLoader,
TEngine *tEngine,
TNameComponentManager *tNameComponentManager,
uint8_t *data,
size_t length,
size_t numInstances
) {
auto *engine = reinterpret_cast<filament::Engine *>(tEngine);
auto *nameComponentManager = reinterpret_cast<utils::NameComponentManager *>(tNameComponentManager);
auto *tFilamentAsset = GltfAssetLoader_load(tAssetLoader, tResourceLoader, data, length, numInstances);
auto *filamentAsset = reinterpret_cast<filament::gltfio::FilamentAsset *>(tFilamentAsset);
auto *assetLoader = reinterpret_cast<filament::gltfio::AssetLoader *>(tAssetLoader);
auto *resourceLoader = reinterpret_cast<filament::gltfio::ResourceLoader *>(tResourceLoader);
auto *sceneAsset = new GltfSceneAsset(
filamentAsset,
assetLoader,
engine,
nameComponentManager
);
return reinterpret_cast<TSceneAsset *>(sceneAsset);
}
EMSCRIPTEN_KEEPALIVE void SceneAsset_addToScene(TSceneAsset *tSceneAsset, TScene *tScene) {
auto *asset = reinterpret_cast<SceneAsset*>(tSceneAsset);
auto *scene = reinterpret_cast<Scene*>(tScene);
asset->addAllEntities(scene);
}
EMSCRIPTEN_KEEPALIVE void SceneAsset_removeFromScene(TSceneAsset *tSceneAsset, TScene *tScene) {
auto *asset = reinterpret_cast<SceneAsset*>(tSceneAsset);
auto *scene = reinterpret_cast<Scene*>(tScene);
asset->removeAllEntities(scene);
}
EMSCRIPTEN_KEEPALIVE EntityId SceneAsset_getEntity(TSceneAsset *tSceneAsset) {
auto *asset = reinterpret_cast<SceneAsset*>(tSceneAsset);
return utils::Entity::smuggle(asset->getEntity());
@@ -683,6 +683,16 @@ extern "C"
auto fut = _rl->add_task(lambda);
}
EMSCRIPTEN_KEEPALIVE void AnimationManager_createRenderThread(TEngine *tEngine, TScene *tScene, void (*onComplete)(TAnimationManager *)) {
std::packaged_task<void()> lambda(
[=]() mutable
{
auto *animationManager = AnimationManager_create(tEngine, tScene);
callback(animationManager);
});
auto fut = _rl->add_task(lambda);
}
EMSCRIPTEN_KEEPALIVE void AnimationManager_updateBoneMatricesRenderThread(
TAnimationManager *tAnimationManager,
TSceneAsset *sceneAsset,