add onDispose() implementations for web viewers
This commit is contained in:
@@ -3,9 +3,10 @@ import 'dart:js_interop_unsafe';
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:animation_tools_dart/animation_tools_dart.dart';
|
import 'package:animation_tools_dart/animation_tools_dart.dart';
|
||||||
|
import 'package:thermion_dart/thermion_dart/scene.dart';
|
||||||
import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';
|
import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';
|
||||||
|
|
||||||
import 'package:thermion_dart/thermion_dart/scene.dart';
|
import 'package:thermion_dart/thermion_dart/scene_impl.dart';
|
||||||
import 'package:vector_math/vector_math_64.dart';
|
import 'package:vector_math/vector_math_64.dart';
|
||||||
import 'shims/thermion_viewer_js_shim.dart';
|
import 'shims/thermion_viewer_js_shim.dart';
|
||||||
|
|
||||||
@@ -56,6 +57,9 @@ class ThermionViewerFFIJS implements ThermionViewer {
|
|||||||
@override
|
@override
|
||||||
Future<void> dispose() async {
|
Future<void> dispose() async {
|
||||||
await _shim.dispose().toDart;
|
await _shim.dispose().toDart;
|
||||||
|
for (final callback in _onDispose) {
|
||||||
|
callback.call();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -813,4 +817,13 @@ class ThermionViewerFFIJS implements ThermionViewer {
|
|||||||
Future updateBoneMatrices(ThermionEntity entity) {
|
Future updateBoneMatrices(ThermionEntity entity) {
|
||||||
return _shim.updateBoneMatrices(entity).toDart;
|
return _shim.updateBoneMatrices(entity).toDart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final _onDispose = <Future Function()>[];
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
void onDispose(Future Function() callback) {
|
||||||
|
_onDispose.add(callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'dart:js_interop_unsafe';
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
import 'dart:typed_data' as td;
|
import 'dart:typed_data' as td;
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
import 'package:thermion_dart/thermion_dart/scene.dart';
|
||||||
import 'package:web/web.dart';
|
import 'package:web/web.dart';
|
||||||
import 'package:animation_tools_dart/animation_tools_dart.dart';
|
import 'package:animation_tools_dart/animation_tools_dart.dart';
|
||||||
import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';
|
import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';
|
||||||
@@ -62,7 +63,6 @@ class ThermionViewerFFIWasm implements ThermionViewer {
|
|||||||
["void*".toJS, "void*".toJS, "void*".toJS, "string".toJS].toJS,
|
["void*".toJS, "void*".toJS, "void*".toJS, "string".toJS].toJS,
|
||||||
[context, loader, null, uberArchivePath?.toJS].toJS,
|
[context, loader, null, uberArchivePath?.toJS].toJS,
|
||||||
null) as JSBigInt;
|
null) as JSBigInt;
|
||||||
print("Created viewer");
|
|
||||||
await createSwapChain(width, height);
|
await createSwapChain(width, height);
|
||||||
_updateViewportAndCameraProjection(width, height, 1.0);
|
_updateViewportAndCameraProjection(width, height, 1.0);
|
||||||
_sceneManager = _module.ccall("get_scene_manager", "void*",
|
_sceneManager = _module.ccall("get_scene_manager", "void*",
|
||||||
@@ -84,7 +84,6 @@ class ThermionViewerFFIWasm implements ThermionViewer {
|
|||||||
[_viewer!].toJS, null);
|
[_viewer!].toJS, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void _updateViewportAndCameraProjection(
|
void _updateViewportAndCameraProjection(
|
||||||
int width, int height, double scaleFactor) {
|
int width, int height, double scaleFactor) {
|
||||||
_module.ccall(
|
_module.ccall(
|
||||||
@@ -110,10 +109,28 @@ class ThermionViewerFFIWasm implements ThermionViewer {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future dispose() async {
|
Future dispose() async {
|
||||||
|
if (_viewer == null) {
|
||||||
|
// we've already cleaned everything up, ignore the call to dispose
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await setRendering(false);
|
||||||
|
await clearEntities();
|
||||||
|
await clearLights();
|
||||||
|
_destroyViewer();
|
||||||
|
|
||||||
|
_sceneManager = null;
|
||||||
|
_viewer = null;
|
||||||
|
|
||||||
|
for (final callback in _onDispose) {
|
||||||
|
await callback.call();
|
||||||
|
}
|
||||||
|
_onDispose.clear();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void _destroyViewer() {
|
||||||
_module.ccall("destroy_filament_viewer", "void", ["void*".toJS].toJS,
|
_module.ccall("destroy_filament_viewer", "void", ["void*".toJS].toJS,
|
||||||
[_viewer].toJS, null);
|
[_viewer].toJS, null);
|
||||||
_initialized = false;
|
|
||||||
_viewer = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -956,7 +973,6 @@ class ThermionViewerFFIWasm implements ThermionViewer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement scene
|
|
||||||
Scene get scene => throw UnimplementedError();
|
Scene get scene => throw UnimplementedError();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -1444,4 +1460,13 @@ class ThermionViewerFFIWasm implements ThermionViewer {
|
|||||||
// TODO: implement zoomUpdate
|
// TODO: implement zoomUpdate
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final _onDispose = <Future Function()>[];
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
void onDispose(Future Function() callback) {
|
||||||
|
_onDispose.add(callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user