refactoring

This commit is contained in:
Nick Fisher
2025-03-19 23:22:19 +08:00
parent 931aab5159
commit a8a2f14b34
13 changed files with 106 additions and 56 deletions

View File

@@ -227,7 +227,7 @@ abstract class FilamentApp<T> {
/// ///
/// ///
/// ///
Future<Uint8List> capture(covariant View view); Future<Uint8List> capture(covariant View view, {bool captureRenderTarget = false});
/// ///
/// ///

View File

@@ -25,6 +25,9 @@ class BackgroundImage extends ThermionAsset {
BackgroundImage._( BackgroundImage._(
this.asset, this.scene, this.texture, this.sampler, this.mi); this.asset, this.scene, this.texture, this.sampler, this.mi);
///
///
///
Future destroy() async { Future destroy() async {
Scene_removeEntity(scene.scene, entity); Scene_removeEntity(scene.scene, entity);
@@ -33,6 +36,9 @@ class BackgroundImage extends ThermionAsset {
await mi.destroy(); await mi.destroy();
} }
///
///
///
static Future<BackgroundImage> create( static Future<BackgroundImage> create(
ThermionViewer viewer, FFIScene scene) async { ThermionViewer viewer, FFIScene scene) async {
var imageMaterialInstance = var imageMaterialInstance =
@@ -41,7 +47,8 @@ class BackgroundImage extends ThermionAsset {
var backgroundImage = var backgroundImage =
await viewer.createGeometry(GeometryHelper.fullscreenQuad()); await viewer.createGeometry(GeometryHelper.fullscreenQuad());
await imageMaterialInstance.setParameterInt("showImage", 0); await imageMaterialInstance.setParameterInt("showImage", 0);
await imageMaterialInstance.setParameterMat4("transform", Matrix4.identity()); await imageMaterialInstance.setParameterMat4(
"transform", Matrix4.identity());
backgroundImage.setMaterialInstanceAt(imageMaterialInstance); backgroundImage.setMaterialInstanceAt(imageMaterialInstance);
await scene.add(backgroundImage as FFIAsset); await scene.add(backgroundImage as FFIAsset);
@@ -49,21 +56,31 @@ class BackgroundImage extends ThermionAsset {
backgroundImage, scene, null, null, imageMaterialInstance); backgroundImage, scene, null, null, imageMaterialInstance);
} }
///
///
///
Future setBackgroundColor(double r, double g, double b, double a) async { Future setBackgroundColor(double r, double g, double b, double a) async {
await mi.setParameterFloat4("backgroundColor", r, g, b, a); await mi.setParameterFloat4("backgroundColor", r, g, b, a);
} }
///
///
///
Future setImage(Uint8List imageData) async { Future setImage(Uint8List imageData) async {
final image = await FilamentApp.instance!.decodeImage(imageData); final image = await FilamentApp.instance!.decodeImage(imageData);
texture ??= await FilamentApp.instance! texture ??= await FilamentApp.instance!.createTexture(
.createTexture(await image.getWidth(), await image.getHeight()); await image.getWidth(), await image.getHeight(),
textureFormat: TextureFormat.RGBA32F);
await texture!
.setLinearImage(image, PixelDataFormat.RGBA, PixelDataType.FLOAT);
sampler ??= sampler ??=
await FilamentApp.instance!.createTextureSampler() as FFITextureSampler; await FilamentApp.instance!.createTextureSampler() as FFITextureSampler;
await mi.setParameterTexture( await mi.setParameterTexture(
"image", texture as FFITexture, sampler as FFITextureSampler); "image", texture as FFITexture, sampler as FFITextureSampler);
await setBackgroundColor(1, 1, 1, 0);
await mi.setParameterInt("showImage", 1);
} }
/// ///

View File

@@ -81,7 +81,7 @@ class FFICamera extends Camera {
/// ///
@override @override
Future setModelMatrix(Matrix4 matrix) async { Future setModelMatrix(Matrix4 matrix) async {
Camera_setModelMatrix(camera, matrix4ToDouble4x4(matrix)); Camera_setModelMatrix(camera, matrix.storage.address);
} }
@override @override

View File

@@ -211,7 +211,7 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
TextureFormat textureFormat = TextureFormat.RGBA16F, TextureFormat textureFormat = TextureFormat.RGBA16F,
int? importedTextureHandle}) async { int? importedTextureHandle}) async {
var bitmask = flags.fold(0, (a, b) => a | b.value); var bitmask = flags.fold(0, (a, b) => a | b.value);
print("bitmask $bitmask");
final texturePtr = await withPointerCallback<TTexture>((cb) { final texturePtr = await withPointerCallback<TTexture>((cb) {
Texture_buildRenderThread( Texture_buildRenderThread(
engine, engine,
@@ -247,24 +247,24 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
TextureCompareMode compareMode = TextureCompareMode.NONE, TextureCompareMode compareMode = TextureCompareMode.NONE,
TextureCompareFunc compareFunc = TextureCompareFunc.LESS_EQUAL}) async { TextureCompareFunc compareFunc = TextureCompareFunc.LESS_EQUAL}) async {
final samplerPtr = TextureSampler_create(); final samplerPtr = TextureSampler_create();
TextureSampler_setMinFilter( // TextureSampler_setMinFilter(
samplerPtr, TSamplerMinFilter.values[minFilter.index]); // samplerPtr, TSamplerMinFilter.values[minFilter.index]);
TextureSampler_setMagFilter( // TextureSampler_setMagFilter(
samplerPtr, TSamplerMagFilter.values[magFilter.index]); // samplerPtr, TSamplerMagFilter.values[magFilter.index]);
TextureSampler_setWrapModeS( // TextureSampler_setWrapModeS(
samplerPtr, TSamplerWrapMode.values[wrapS.index]); // samplerPtr, TSamplerWrapMode.values[wrapS.index]);
TextureSampler_setWrapModeT( // TextureSampler_setWrapModeT(
samplerPtr, TSamplerWrapMode.values[wrapT.index]); // samplerPtr, TSamplerWrapMode.values[wrapT.index]);
TextureSampler_setWrapModeR( // TextureSampler_setWrapModeR(
samplerPtr, TSamplerWrapMode.values[wrapR.index]); // samplerPtr, TSamplerWrapMode.values[wrapR.index]);
if (anisotropy > 0) { // if (anisotropy > 0) {
TextureSampler_setAnisotropy(samplerPtr, anisotropy); // TextureSampler_setAnisotropy(samplerPtr, anisotropy);
} // }
TextureSampler_setCompareMode( // TextureSampler_setCompareMode(
samplerPtr, // samplerPtr,
TSamplerCompareMode.values[compareMode.index], // TSamplerCompareMode.values[compareMode.index],
TSamplerCompareFunc.values[compareFunc.index]); // TSamplerCompareFunc.values[compareFunc.index]);
return FFITextureSampler(samplerPtr); return FFITextureSampler(samplerPtr);
} }
@@ -555,11 +555,16 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
/// ///
/// ///
/// ///
Future<Uint8List> capture(covariant FFIView view) async { Future<Uint8List> capture(covariant FFIView view,
{bool captureRenderTarget = false}) async {
final viewport = await view.getViewport(); final viewport = await view.getViewport();
final swapChain = _viewMappings[view]; final swapChain = _viewMappings[view];
final out = Uint8List(viewport.width * viewport.height * 4); final out = Uint8List(viewport.width * viewport.height * 4);
await withVoidCallback((cb) {
Engine_flushAndWaitRenderThead(engine, cb);
});
await withBoolCallback((cb) { await withBoolCallback((cb) {
Renderer_beginFrameRenderThread(renderer, swapChain!.swapChain, 0, cb); Renderer_beginFrameRenderThread(renderer, swapChain!.swapChain, 0, cb);
}); });
@@ -570,11 +575,15 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
cb, cb,
); );
}); });
if (captureRenderTarget && view.renderTarget == null) {
throw Exception();
}
await withVoidCallback((cb) { await withVoidCallback((cb) {
Renderer_readPixelsRenderThread( Renderer_readPixelsRenderThread(
renderer, renderer,
view.view, view.view,
view.renderTarget?.renderTarget ?? nullptr, captureRenderTarget ? view.renderTarget!.renderTarget : nullptr,
TPixelDataFormat.PIXELDATAFORMAT_RGBA, TPixelDataFormat.PIXELDATAFORMAT_RGBA,
TPixelDataType.PIXELDATATYPE_UBYTE, TPixelDataType.PIXELDATATYPE_UBYTE,
out.address, out.address,

View File

@@ -2,7 +2,6 @@ import 'package:thermion_dart/src/filament/src/scene.dart';
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_filament_app.dart'; import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_filament_app.dart';
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_render_target.dart'; import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_render_target.dart';
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_scene.dart'; import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_scene.dart';
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_swapchain.dart';
import 'package:thermion_dart/src/filament/src/layers.dart'; import 'package:thermion_dart/src/filament/src/layers.dart';
import 'package:thermion_dart/src/filament/src/shared_types.dart'; import 'package:thermion_dart/src/filament/src/shared_types.dart';
import 'callbacks.dart'; import 'callbacks.dart';
@@ -75,14 +74,15 @@ class FFIView extends View {
@override @override
Future setBloom(bool enabled, double strength) async { Future setBloom(bool enabled, double strength) async {
await withVoidCallback((cb) { await withVoidCallback((cb) {
View_setBloomRenderThread(view, enabled, strength); View_setBloomRenderThread(view, enabled, strength, cb);
}); });
} }
@override @override
Future setToneMapper(ToneMapper mapper) async { Future setToneMapper(ToneMapper mapper) async {
await withVoidCallback((cb) =>
View_setToneMappingRenderThread( View_setToneMappingRenderThread(
view, app.engine, TToneMapping.values[mapper.index]); view, app.engine, TToneMapping.values[mapper.index], cb));
} }
Future setStencilBufferEnabled(bool enabled) async { Future setStencilBufferEnabled(bool enabled) async {

View File

@@ -1165,12 +1165,6 @@ external void Camera_setExposure(
double sensitivity, double sensitivity,
); );
@ffi.Native<ffi.Void Function(ffi.Pointer<TCamera>, double4x4)>(isLeaf: true)
external void Camera_setModelMatrix(
ffi.Pointer<TCamera> camera,
double4x4 matrix,
);
@ffi.Native<double4x4 Function(ffi.Pointer<TCamera>)>(isLeaf: true) @ffi.Native<double4x4 Function(ffi.Pointer<TCamera>)>(isLeaf: true)
external double4x4 Camera_getModelMatrix( external double4x4 Camera_getModelMatrix(
ffi.Pointer<TCamera> camera, ffi.Pointer<TCamera> camera,
@@ -1199,11 +1193,11 @@ external void Camera_getFrustum(
); );
@ffi.Native< @ffi.Native<
ffi.Void Function( ffi.Void Function(ffi.Pointer<TCamera>, ffi.Pointer<ffi.Double>, ffi.Double,
ffi.Pointer<TCamera>, double4x4, ffi.Double, ffi.Double)>(isLeaf: true) ffi.Double)>(isLeaf: true)
external void Camera_setProjectionMatrix( external void Camera_setProjectionMatrix(
ffi.Pointer<TCamera> camera, ffi.Pointer<TCamera> camera,
double4x4 matrix, ffi.Pointer<ffi.Double> matrix,
double near, double near,
double far, double far,
); );
@@ -1271,6 +1265,13 @@ external void Camera_setCustomProjectionWithCulling(
double far, double far,
); );
@ffi.Native<ffi.Void Function(ffi.Pointer<TCamera>, ffi.Pointer<ffi.Double>)>(
isLeaf: true)
external void Camera_setModelMatrix(
ffi.Pointer<TCamera> camera,
ffi.Pointer<ffi.Double> tModelMatrix,
);
@ffi.Native< @ffi.Native<
ffi.Void Function(ffi.Pointer<TCamera>, ffi.Double, ffi.Double, ffi.Double, ffi.Void Function(ffi.Pointer<TCamera>, ffi.Double, ffi.Double, ffi.Double,
ffi.Double)>(isLeaf: true) ffi.Double)>(isLeaf: true)
@@ -1938,31 +1939,39 @@ external void Material_createImageMaterialRenderThread(
@ffi.Native< @ffi.Native<
ffi.Void Function( ffi.Void Function(
ffi.Pointer<TView>, ffi.Pointer<TEngine>, ffi.UnsignedInt)>( ffi.Pointer<TView>,
ffi.Pointer<TEngine>,
ffi.UnsignedInt,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(
symbol: "View_setToneMappingRenderThread", isLeaf: true) symbol: "View_setToneMappingRenderThread", isLeaf: true)
external void _View_setToneMappingRenderThread( external void _View_setToneMappingRenderThread(
ffi.Pointer<TView> tView, ffi.Pointer<TView> tView,
ffi.Pointer<TEngine> tEngine, ffi.Pointer<TEngine> tEngine,
int toneMapping, int toneMapping,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
); );
void View_setToneMappingRenderThread( void View_setToneMappingRenderThread(
ffi.Pointer<TView> tView, ffi.Pointer<TView> tView,
ffi.Pointer<TEngine> tEngine, ffi.Pointer<TEngine> tEngine,
TToneMapping toneMapping, TToneMapping toneMapping,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
) => ) =>
_View_setToneMappingRenderThread( _View_setToneMappingRenderThread(
tView, tView,
tEngine, tEngine,
toneMapping.value, toneMapping.value,
callback,
); );
@ffi.Native<ffi.Void Function(ffi.Pointer<TView>, ffi.Bool, ffi.Double)>( @ffi.Native<
isLeaf: true) ffi.Void Function(ffi.Pointer<TView>, ffi.Bool, ffi.Double,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
external void View_setBloomRenderThread( external void View_setBloomRenderThread(
ffi.Pointer<TView> tView, ffi.Pointer<TView> tView,
bool enabled, bool enabled,
double strength, double strength,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
); );
@ffi.Native< @ffi.Native<

View File

@@ -234,6 +234,7 @@ class ThermionViewerFFI extends ThermionViewer {
} }
Pointer<TIndirectLight>? indirectLight; Pointer<TIndirectLight>? indirectLight;
Pointer<TSkybox>? skybox; Pointer<TSkybox>? skybox;
/// ///
@@ -418,6 +419,8 @@ class ThermionViewerFFI extends ThermionViewer {
_assets.add(thermionAsset); _assets.add(thermionAsset);
await scene.add(thermionAsset);
return thermionAsset; return thermionAsset;
} }
@@ -451,7 +454,8 @@ class ThermionViewerFFI extends ThermionViewer {
Future destroyAsset(covariant FFIAsset asset) async { Future destroyAsset(covariant FFIAsset asset) async {
await scene.remove(asset); await scene.remove(asset);
await withVoidCallback((cb) => SceneAsset_destroyRenderThread(asset.asset, cb)); await withVoidCallback(
(cb) => SceneAsset_destroyRenderThread(asset.asset, cb));
// if (asset.boundingBoxAsset != null) { // if (asset.boundingBoxAsset != null) {
// await asset.setBoundingBoxVisibility(false); // await asset.setBoundingBoxVisibility(false);
@@ -786,5 +790,4 @@ class ThermionViewerFFI extends ThermionViewer {
// gizmoEntities.toSet() // gizmoEntities.toSet()
// ..add(SceneAsset_getEntity(gizmo.cast<TSceneAsset>()))); // ..add(SceneAsset_getEntity(gizmo.cast<TSceneAsset>())));
} }
} }

View File

@@ -16,13 +16,12 @@ enum TProjection {
// Camera methods // Camera methods
EMSCRIPTEN_KEEPALIVE void Camera_setExposure(TCamera *camera, float aperture, float shutterSpeed, float sensitivity); EMSCRIPTEN_KEEPALIVE void Camera_setExposure(TCamera *camera, float aperture, float shutterSpeed, float sensitivity);
EMSCRIPTEN_KEEPALIVE void Camera_setModelMatrix(TCamera *camera, double4x4 matrix);
EMSCRIPTEN_KEEPALIVE double4x4 Camera_getModelMatrix(TCamera *const camera); EMSCRIPTEN_KEEPALIVE double4x4 Camera_getModelMatrix(TCamera *const camera);
EMSCRIPTEN_KEEPALIVE double4x4 Camera_getViewMatrix(TCamera *const camera); EMSCRIPTEN_KEEPALIVE double4x4 Camera_getViewMatrix(TCamera *const camera);
EMSCRIPTEN_KEEPALIVE double4x4 Camera_getProjectionMatrix(TCamera *const camera); EMSCRIPTEN_KEEPALIVE double4x4 Camera_getProjectionMatrix(TCamera *const camera);
EMSCRIPTEN_KEEPALIVE double4x4 Camera_getCullingProjectionMatrix(TCamera *const camera); EMSCRIPTEN_KEEPALIVE double4x4 Camera_getCullingProjectionMatrix(TCamera *const camera);
EMSCRIPTEN_KEEPALIVE void Camera_getFrustum(TCamera *camera, double* out); EMSCRIPTEN_KEEPALIVE void Camera_getFrustum(TCamera *camera, double* out);
EMSCRIPTEN_KEEPALIVE void Camera_setProjectionMatrix(TCamera *camera, double4x4 matrix, double near, double far); EMSCRIPTEN_KEEPALIVE void Camera_setProjectionMatrix(TCamera *camera, double *matrix, double near, double far);
EMSCRIPTEN_KEEPALIVE void Camera_setProjectionFromFov(TCamera *camera, double fovInDegrees, double aspect, double near, double far, bool horizontal); EMSCRIPTEN_KEEPALIVE void Camera_setProjectionFromFov(TCamera *camera, double fovInDegrees, double aspect, double near, double far, bool horizontal);
EMSCRIPTEN_KEEPALIVE double Camera_getFocalLength(TCamera *const camera); EMSCRIPTEN_KEEPALIVE double Camera_getFocalLength(TCamera *const camera);
EMSCRIPTEN_KEEPALIVE double4x4 Camera_getViewMatrix(TCamera *const camera); EMSCRIPTEN_KEEPALIVE double4x4 Camera_getViewMatrix(TCamera *const camera);
@@ -41,7 +40,7 @@ EMSCRIPTEN_KEEPALIVE void Camera_setCustomProjectionWithCulling(
double near, double near,
double far double far
); );
EMSCRIPTEN_KEEPALIVE void Camera_setModelMatrix(TCamera* camera, double4x4 modelMatrix); EMSCRIPTEN_KEEPALIVE void Camera_setModelMatrix(TCamera* camera, double *tModelMatrix);
EMSCRIPTEN_KEEPALIVE void Camera_setLensProjection(TCamera *camera, double near, double far, double aspect, double focalLength); EMSCRIPTEN_KEEPALIVE void Camera_setLensProjection(TCamera *camera, double near, double far, double aspect, double focalLength);
EMSCRIPTEN_KEEPALIVE EntityId Camera_getEntity(TCamera* camera); EMSCRIPTEN_KEEPALIVE EntityId Camera_getEntity(TCamera* camera);
EMSCRIPTEN_KEEPALIVE void Camera_setProjection(TCamera *const tCamera, TProjection projection, double left, double right, EMSCRIPTEN_KEEPALIVE void Camera_setProjection(TCamera *const tCamera, TProjection projection, double left, double right,

View File

@@ -77,8 +77,8 @@ namespace thermion
EMSCRIPTEN_KEEPALIVE void Material_createInstanceRenderThread(TMaterial *tMaterial, void (*onComplete)(TMaterialInstance *)); EMSCRIPTEN_KEEPALIVE void Material_createInstanceRenderThread(TMaterial *tMaterial, void (*onComplete)(TMaterialInstance *));
EMSCRIPTEN_KEEPALIVE void Material_createImageMaterialRenderThread(TEngine *tEngine, void (*onComplete)(TMaterial *)); EMSCRIPTEN_KEEPALIVE void Material_createImageMaterialRenderThread(TEngine *tEngine, void (*onComplete)(TMaterial *));
EMSCRIPTEN_KEEPALIVE void View_setToneMappingRenderThread(TView *tView, TEngine *tEngine, TToneMapping toneMapping); EMSCRIPTEN_KEEPALIVE void View_setToneMappingRenderThread(TView *tView, TEngine *tEngine, TToneMapping toneMapping, void (*callback)());
EMSCRIPTEN_KEEPALIVE void View_setBloomRenderThread(TView *tView, bool enabled, double strength); EMSCRIPTEN_KEEPALIVE void View_setBloomRenderThread(TView *tView, bool enabled, double strength, void (*callback)());
EMSCRIPTEN_KEEPALIVE void View_setCameraRenderThread(TView *tView, TCamera *tCamera, void (*callback)()); EMSCRIPTEN_KEEPALIVE void View_setCameraRenderThread(TView *tView, TCamera *tCamera, void (*callback)());
FilamentRenderCallback make_render_callback_fn_pointer(FilamentRenderCallback); FilamentRenderCallback make_render_callback_fn_pointer(FilamentRenderCallback);

View File

@@ -43,13 +43,14 @@ namespace thermion
} }
EMSCRIPTEN_KEEPALIVE void Camera_setLensProjection(TCamera *tCamera, double near, double far, double aspect, double focalLength) { EMSCRIPTEN_KEEPALIVE void Camera_setLensProjection(TCamera *tCamera, double near, double far, double aspect, double focalLength) {
TRACE("Setting lens projection %f %f %f %f", near, far, aspect, focalLength);
auto *camera = reinterpret_cast<Camera *>(tCamera); auto *camera = reinterpret_cast<Camera *>(tCamera);
camera->setLensProjection(near, far, aspect, focalLength); camera->setLensProjection(focalLength, aspect, near, far);
} }
EMSCRIPTEN_KEEPALIVE void Camera_setModelMatrix(TCamera *tCamera, double4x4 tModelMatrix) { EMSCRIPTEN_KEEPALIVE void Camera_setModelMatrix(TCamera *tCamera, double *tModelMatrix) {
auto *camera = reinterpret_cast<Camera *>(tCamera); auto *camera = reinterpret_cast<Camera *>(tCamera);
auto modelMatrix = convert_double4x4_to_mat4(tModelMatrix); auto modelMatrix = convert_double_to_mat4f(tModelMatrix);
camera->setModelMatrix(modelMatrix); camera->setModelMatrix(modelMatrix);
} }
@@ -65,6 +66,12 @@ namespace thermion
return camera->getFocusDistance(); return camera->getFocusDistance();
} }
EMSCRIPTEN_KEEPALIVE double4x4 Camera_getProjectionMatrix(TCamera *const tCamera) {
auto *camera = reinterpret_cast<Camera *>(tCamera);
return convert_mat4_to_double4x4(camera->getProjectionMatrix());
}
EMSCRIPTEN_KEEPALIVE void Camera_setFocusDistance(TCamera *tCamera, float distance) { EMSCRIPTEN_KEEPALIVE void Camera_setFocusDistance(TCamera *tCamera, float distance) {
auto *camera = reinterpret_cast<Camera *>(tCamera); auto *camera = reinterpret_cast<Camera *>(tCamera);
return camera->setFocusDistance(distance); return camera->setFocusDistance(distance);

View File

@@ -28,17 +28,20 @@ namespace thermion
{ {
auto *scene = reinterpret_cast<Scene *>(tScene); auto *scene = reinterpret_cast<Scene *>(tScene);
scene->addEntity(utils::Entity::import(entityId)); scene->addEntity(utils::Entity::import(entityId));
TRACE("Added entity %d", entityId);
} }
EMSCRIPTEN_KEEPALIVE void Scene_removeEntity(TScene* tScene, EntityId entityId) { EMSCRIPTEN_KEEPALIVE void Scene_removeEntity(TScene* tScene, EntityId entityId) {
auto *scene = reinterpret_cast<Scene *>(tScene); auto *scene = reinterpret_cast<Scene *>(tScene);
scene->remove(utils::Entity::import(entityId)); scene->remove(utils::Entity::import(entityId));
TRACE("Removed entity %d", entityId);
} }
EMSCRIPTEN_KEEPALIVE void Scene_setSkybox(TScene* tScene, TSkybox *tSkybox) { EMSCRIPTEN_KEEPALIVE void Scene_setSkybox(TScene* tScene, TSkybox *tSkybox) {
auto *scene = reinterpret_cast<Scene *>(tScene); auto *scene = reinterpret_cast<Scene *>(tScene);
auto *skybox = reinterpret_cast<Skybox *>(tSkybox); auto *skybox = reinterpret_cast<Skybox *>(tSkybox);
scene->setSkybox(skybox); scene->setSkybox(skybox);
TRACE("Set skybox");
} }
EMSCRIPTEN_KEEPALIVE void Scene_setIndirectLight(TScene* tScene, TIndirectLight *tIndirectLight) { EMSCRIPTEN_KEEPALIVE void Scene_setIndirectLight(TScene* tScene, TIndirectLight *tIndirectLight) {

View File

@@ -32,6 +32,7 @@ using namespace filament;
{ {
auto view = reinterpret_cast<View *>(tView); auto view = reinterpret_cast<View *>(tView);
view->setViewport({0, 0, width, height}); view->setViewport({0, 0, width, height});
TRACE("Set viewport to %dx%d", width, height);
} }
EMSCRIPTEN_KEEPALIVE TRenderTarget *View_getRenderTarget(TView *tView) { EMSCRIPTEN_KEEPALIVE TRenderTarget *View_getRenderTarget(TView *tView) {

View File

@@ -427,22 +427,24 @@ extern "C"
auto fut = _rl->add_task(lambda); auto fut = _rl->add_task(lambda);
} }
EMSCRIPTEN_KEEPALIVE void View_setToneMappingRenderThread(TView *tView, TEngine *tEngine, TToneMapping toneMapping) EMSCRIPTEN_KEEPALIVE void View_setToneMappingRenderThread(TView *tView, TEngine *tEngine, TToneMapping toneMapping, void (*callback)())
{ {
std::packaged_task<void()> lambda( std::packaged_task<void()> lambda(
[=] [=]
{ {
View_setToneMapping(tView, tEngine, toneMapping); View_setToneMapping(tView, tEngine, toneMapping);
callback();
}); });
auto fut = _rl->add_task(lambda); auto fut = _rl->add_task(lambda);
} }
EMSCRIPTEN_KEEPALIVE void View_setBloomRenderThread(TView *tView, bool enabled, double strength) EMSCRIPTEN_KEEPALIVE void View_setBloomRenderThread(TView *tView, bool enabled, double strength, void (*callback)())
{ {
std::packaged_task<void()> lambda( std::packaged_task<void()> lambda(
[=] [=]
{ {
View_setBloom(tView, enabled, strength); View_setBloom(tView, enabled, strength);
callback();
}); });
auto fut = _rl->add_task(lambda); auto fut = _rl->add_task(lambda);
} }