#ifdef _WIN32 #pragma comment(lib, "Shlwapi.lib") #pragma comment(lib, "opengl32.lib") #endif #include "ResourceBuffer.hpp" #include "FilamentViewer.hpp" #include "filament/LightManager.h" #include "Log.hpp" #include "ThreadPool.hpp" #include #include #ifdef __EMSCRIPTEN__ #include #endif using namespace thermion_filament; extern "C" { #include "ThermionDartApi.h" EMSCRIPTEN_KEEPALIVE void View_updateViewport(TView *tView, uint32_t width, uint32_t height) { auto view = reinterpret_cast(tView); view->setViewport({0, 0, width, height}); } EMSCRIPTEN_KEEPALIVE void View_setRenderTarget(TView *tView, TRenderTarget *tRenderTarget) { auto view = reinterpret_cast(tView); auto renderTarget = reinterpret_cast(tRenderTarget); view->setRenderTarget(renderTarget); } EMSCRIPTEN_KEEPALIVE void View_setFrustumCullingEnabled(TView *tView, bool enabled) { auto view = reinterpret_cast(tView); view->setFrustumCullingEnabled(enabled); } EMSCRIPTEN_KEEPALIVE void View_setPostProcessing(TView *tView, bool enabled) { auto view = reinterpret_cast(tView); view->setPostProcessingEnabled(enabled); } EMSCRIPTEN_KEEPALIVE void View_setShadowsEnabled(TView *tView, bool enabled) { auto view = reinterpret_cast(tView); view->setShadowingEnabled(enabled); } EMSCRIPTEN_KEEPALIVE void View_setShadowType(TView *tView, ShadowType shadowType) { auto view = reinterpret_cast(tView); view->setShadowType(shadowType); } EMSCRIPTEN_KEEPALIVE void View_setSoftShadowOptions(TView *tView, float penumbraScale, float penumbraRatioScale) { auto view = reinterpret_cast(tView); SoftShadowOptions opts; opts.penumbraRatioScale = penumbraRatioScale; opts.penumbraScale = penumbraScale; view->setSoftShadowOptions(opts); } EMSCRIPTEN_KEEPALIVE void View_setBloom(TView *tView, float strength) { auto view = reinterpret_cast(tView); #ifndef __EMSCRIPTEN__ decltype(view->getBloomOptions()) opts; opts.enabled = true; opts.strength = strength; view->setBloomOptions(opts); #endif } EMSCRIPTEN_KEEPALIVE void View_setToneMapping(TView *tView, TEngine *tEngine, int toneMapping) { auto view = reinterpret_cast(tView); auto engine = reinterpret_cast(tEngine); ToneMapper *tm; switch (toneMapping) { case ToneMapping::ACES: Log("Setting tone mapping to ACES"); tm = new ACESToneMapper(); break; case ToneMapping::LINEAR: Log("Setting tone mapping to Linear"); tm = new LinearToneMapper(); break; case ToneMapping::FILMIC: Log("Setting tone mapping to Filmic"); tm = new FilmicToneMapper(); break; default: Log("ERROR: Unsupported tone mapping"); return; } auto newColorGrading = ColorGrading::Builder().toneMapper(tm).build(*engine); auto oldColorGrading = view->getColorGrading(); view->setColorGrading(newColorGrading); if (oldColorGrading) { engine->destroy(oldColorGrading); } delete tm; } void View_setAntiAliasing(TView *tView, bool msaa, bool fxaa, bool taa) { auto view = reinterpret_cast(tView); View::MultiSampleAntiAliasingOptions multiSampleAntiAliasingOptions; multiSampleAntiAliasingOptions.enabled = msaa; view->setMultiSampleAntiAliasingOptions(multiSampleAntiAliasingOptions); TemporalAntiAliasingOptions taaOpts; taaOpts.enabled = taa; view->setTemporalAntiAliasingOptions(taaOpts); view->setAntiAliasing(fxaa ? AntiAliasing::FXAA : AntiAliasing::NONE); } EMSCRIPTEN_KEEPALIVE void View_setLayerEnabled(TView* tView, int layer, bool enabled) { auto view = reinterpret_cast(tView); view->setLayerEnabled(layer, enabled); } EMSCRIPTEN_KEEPALIVE void View_setCamera(TView *tView, TCamera *tCamera) { auto view = reinterpret_cast(tView); auto *camera = reinterpret_cast(tCamera); view->setCamera(camera); } }