refactoring
This commit is contained in:
@@ -70,6 +70,11 @@ abstract class FilamentApp<T> {
|
||||
///
|
||||
Future destroy();
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
Future destroyAsset(covariant ThermionAsset asset);
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
@@ -227,7 +232,8 @@ abstract class FilamentApp<T> {
|
||||
///
|
||||
///
|
||||
///
|
||||
Future<Uint8List> capture(covariant View view, {bool captureRenderTarget = false});
|
||||
Future<Uint8List> capture(covariant View view,
|
||||
{bool captureRenderTarget = false});
|
||||
|
||||
///
|
||||
///
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/thermion_dart.g.dart';
|
||||
export 'package:ffi/ffi.dart';
|
||||
export 'dart:ffi';
|
||||
export 'thermion_dart.g.dart';
|
||||
@@ -18,8 +19,9 @@ Future<void> withVoidCallback2(Function() func) async {
|
||||
void Function() callback = () {
|
||||
func.call();
|
||||
completer.complete();
|
||||
};
|
||||
};
|
||||
final nativeCallable = NativeCallable<Void Function()>.listener(callback);
|
||||
RenderLoop_addTask(nativeCallable.nativeFunction);
|
||||
await completer.future;
|
||||
nativeCallable.close();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:typed_data';
|
||||
|
||||
import 'package:thermion_dart/src/filament/src/engine.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/callbacks.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_asset.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_material.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_render_target.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_swapchain.dart';
|
||||
@@ -187,6 +188,14 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
|
||||
Engine_destroy(engine);
|
||||
}
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
Future destroyAsset(covariant FFIAsset asset) async {
|
||||
await withVoidCallback(
|
||||
(cb) => SceneAsset_destroyRenderThread(asset.asset, cb));
|
||||
}
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
|
||||
@@ -234,7 +234,7 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
}
|
||||
|
||||
Pointer<TIndirectLight>? indirectLight;
|
||||
|
||||
|
||||
Pointer<TSkybox>? skybox;
|
||||
|
||||
///
|
||||
@@ -279,47 +279,13 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
@override
|
||||
Future removeIbl() async {
|
||||
if (indirectLight != null) {
|
||||
Scene_setIndirectLight(scene.scene, nullptr);
|
||||
await withVoidCallback((cb) => Engine_destroyIndirectLightRenderThread(
|
||||
app.engine, indirectLight!, cb));
|
||||
indirectLight = null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ThermionEntity> addLight(
|
||||
LightType type,
|
||||
double colour,
|
||||
double intensity,
|
||||
double posX,
|
||||
double posY,
|
||||
double posZ,
|
||||
double dirX,
|
||||
double dirY,
|
||||
double dirZ,
|
||||
{double falloffRadius = 1.0,
|
||||
double spotLightConeInner = pi / 8,
|
||||
double spotLightConeOuter = pi / 4,
|
||||
double sunAngularRadius = 0.545,
|
||||
double sunHaloSize = 10.0,
|
||||
double sunHaloFallof = 80.0,
|
||||
bool castShadows = true}) async {
|
||||
DirectLight directLight = DirectLight(
|
||||
type: type,
|
||||
color: colour,
|
||||
intensity: intensity,
|
||||
position: Vector3(posX, posY, posZ),
|
||||
direction: Vector3(dirX, dirY, dirZ)..normalize(),
|
||||
falloffRadius: falloffRadius,
|
||||
spotLightConeInner: spotLightConeInner,
|
||||
spotLightConeOuter: spotLightConeOuter,
|
||||
sunAngularRadius: sunAngularRadius,
|
||||
sunHaloSize: sunHaloSize,
|
||||
sunHaloFallof: sunHaloFallof,
|
||||
castShadows: castShadows);
|
||||
|
||||
return addDirectLight(directLight);
|
||||
}
|
||||
|
||||
final _lights = <ThermionEntity>{};
|
||||
|
||||
///
|
||||
@@ -347,7 +313,7 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
// LightManager_setSunHaloFalloff(app.lightManager, entity, directLight.spotLightConeInner, directLight.spotLightConeOuter);
|
||||
LightManager_setShadowCaster(
|
||||
app.lightManager, entity, directLight.castShadows);
|
||||
|
||||
|
||||
Scene_addEntity(scene.scene, entity);
|
||||
|
||||
_lights.add(entity);
|
||||
@@ -453,9 +419,7 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
@override
|
||||
Future destroyAsset(covariant FFIAsset asset) async {
|
||||
await scene.remove(asset);
|
||||
|
||||
await withVoidCallback(
|
||||
(cb) => SceneAsset_destroyRenderThread(asset.asset, cb));
|
||||
await FilamentApp.instance!.destroyAsset(asset);
|
||||
|
||||
// if (asset.boundingBoxAsset != null) {
|
||||
// await asset.setBoundingBoxVisibility(false);
|
||||
@@ -790,4 +754,12 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
// gizmoEntities.toSet()
|
||||
// ..add(SceneAsset_getEntity(gizmo.cast<TSceneAsset>())));
|
||||
}
|
||||
|
||||
Future addToScene(covariant FFIAsset asset) async {
|
||||
await scene.add(asset);
|
||||
}
|
||||
|
||||
Future removeFromScene(covariant FFIAsset asset) async {
|
||||
await scene.remove(asset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import 'dart:async';
|
||||
/// using the methods directly via FilamentApp.instance;
|
||||
///
|
||||
abstract class ThermionViewer {
|
||||
|
||||
Future<bool> get initialized;
|
||||
|
||||
///
|
||||
@@ -294,4 +293,7 @@ abstract class ThermionViewer {
|
||||
///
|
||||
///
|
||||
int getCameraCount();
|
||||
|
||||
Future addToScene(covariant ThermionAsset asset);
|
||||
Future removeFromScene(covariant ThermionAsset asset);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user