more refactoring
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user