refactor: rearrange some stubs/imports for easier web WASM deployment

This commit is contained in:
Nick Fisher
2024-06-21 15:13:41 +08:00
parent c28c518057
commit 9eb2285433
15 changed files with 749 additions and 15 deletions

View File

@@ -1,3 +1 @@
export 'web/compatibility.dart' if (dart.library.io) 'native/compatibility.dart';
export 'native/compatibility.dart';

View File

@@ -6,7 +6,7 @@ import 'dart:convert';
import 'dart:ffi' as ffi hide Uint8Pointer, FloatPointer;
import 'dart:typed_data';
import 'package:thermion_dart/thermion_dart/compatibility/web/thermion_dart.g.dart';
import 'package:thermion_dart/thermion_dart/compatibility/web/ffi/thermion_dart.g.dart';
import 'package:ffi/ffi.dart';
export 'package:ffi/ffi.dart' hide StringUtf8Pointer, Utf8Pointer;

View File

@@ -1,6 +1,6 @@
import 'dart:async';
import 'dart:js_interop';
import 'package:thermion_dart/thermion_dart/compatibility/web/interop.dart';
import 'package:thermion_dart/thermion_dart/compatibility/web/ffi/interop.dart';
import "allocator.dart";

View File

@@ -33,8 +33,11 @@ extension type _EmscriptenModule(JSObject _) implements JSObject {
external JSAny get HEAP32;
}
typedef ThermionViewerImpl = ThermionViewerWasm;
///
/// An [ThermionViewer] implementation that forwards calls to
/// A [ThermionViewer] implementation that forwards calls to
/// the (Emscripten-generated) ThermionDart JS module.
///
class ThermionViewerWasm implements ThermionViewer {
@@ -43,8 +46,8 @@ class ThermionViewerWasm implements ThermionViewer {
bool _initialized = false;
bool _rendering = false;
ThermionViewerWasm({String moduleName = "thermion_dart"}) {
_module = window.getProperty<_EmscriptenModule>(moduleName.toJS);
ThermionViewerWasm({JSObject? module, String moduleName = "thermion_dart"}) {
_module = module as _EmscriptenModule? ?? window.getProperty<_EmscriptenModule>(moduleName.toJS);
}
JSNumber? _viewer;
@@ -1687,7 +1690,7 @@ class ThermionViewerWasm implements ThermionViewer {
Future setMorphTargetWeights(
ThermionEntity entity, List<double> weights) async {
final numWeights = weights.length;
final ptr = _module._malloc(numWeights * 4) as JSNumber;
final ptr = _module._malloc(numWeights * 4);
for (int i = 0; i < numWeights; i++) {
_module.setValue(
(ptr.toDartInt + (i * 4)).toJS, weights[i].toJS, "float");