fix: web/JS bool checks need to compare to int
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
library thermion_flutter_js;
|
||||
|
||||
import 'dart:js_interop';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:thermion_dart/thermion_dart/compatibility/web/interop/thermion_viewer_js_shim.dart';
|
||||
|
||||
import 'package:vector_math/vector_math_64.dart' as v64;
|
||||
@@ -21,6 +22,7 @@ import 'package:vector_math/vector_math_64.dart';
|
||||
///
|
||||
@JSExport()
|
||||
class ThermionViewerJSDartBridge {
|
||||
final _logger = Logger("ThermionViewerJSDartBridge");
|
||||
final ThermionViewer viewer;
|
||||
|
||||
ThermionViewerJSDartBridge(this.viewer);
|
||||
@@ -76,7 +78,7 @@ class ThermionViewerJSDartBridge {
|
||||
|
||||
@JSExport()
|
||||
JSPromise loadIbl(String lightingPath, double intensity) {
|
||||
print("Loading IBL from $lightingPath with intensity $intensity");
|
||||
_logger.info("Loading IBL from $lightingPath with intensity $intensity");
|
||||
return viewer.loadIbl(lightingPath, intensity: intensity).toJS;
|
||||
}
|
||||
|
||||
@@ -130,12 +132,12 @@ class ThermionViewerJSDartBridge {
|
||||
|
||||
@JSExport()
|
||||
JSPromise<JSNumber> loadGlb(String path, {int numInstances = 1}) {
|
||||
print("Loading GLB from path $path with numInstances $numInstances");
|
||||
_logger.info("Loading GLB from path $path with numInstances $numInstances");
|
||||
return viewer
|
||||
.loadGlb(path, numInstances: numInstances)
|
||||
.then((entity) => entity.toJS)
|
||||
.catchError((err) {
|
||||
print("Error: $err");
|
||||
_logger.info("Error: $err");
|
||||
}).toJS;
|
||||
}
|
||||
|
||||
@@ -253,13 +255,13 @@ class ThermionViewerJSDartBridge {
|
||||
targetMeshNames: targetMeshNamesDart,
|
||||
)
|
||||
.onError((err, st) {
|
||||
print("ERROR SETTING MORPH ANIMATION DATA : $err\n$st");
|
||||
_logger.severe("ERROR SETTING MORPH ANIMATION DATA : $err\n$st");
|
||||
return null;
|
||||
});
|
||||
return result.toJS;
|
||||
} catch (err, st) {
|
||||
print(err);
|
||||
print(st);
|
||||
_logger.severe(err);
|
||||
_logger.severe(st);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
@@ -618,7 +620,7 @@ class ThermionViewerJSDartBridge {
|
||||
)
|
||||
.then((entities) => entities.map((entity) => entity.toJS).toList().toJS)
|
||||
.onError((e, st) async {
|
||||
print("Error : $e\n$st");
|
||||
_logger.severe("Error : $e\n$st");
|
||||
return <JSNumber>[].toJS;
|
||||
}).toJS;
|
||||
}
|
||||
@@ -632,7 +634,7 @@ class ThermionViewerJSDartBridge {
|
||||
)
|
||||
.then((entity) => entity.toJS)
|
||||
.onError((e, st) async {
|
||||
print("Error getChildEntity : $e\n$st");
|
||||
_logger.severe("Error getChildEntity : $e\n$st");
|
||||
return 0.toJS;
|
||||
}).toJS;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:js_interop_unsafe';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:animation_tools_dart/animation_tools_dart.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:thermion_dart/thermion_dart/scene.dart';
|
||||
import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';
|
||||
|
||||
@@ -15,6 +16,7 @@ import 'thermion_viewer_js_shim.dart';
|
||||
/// a corresponding Javascript shim implementation (see [ThermionViewerJSShim]).
|
||||
///
|
||||
class ThermionViewerJS implements ThermionViewer {
|
||||
final _logger = Logger("ThermionViewerJS");
|
||||
late final ThermionViewerJSShim _shim;
|
||||
|
||||
ThermionViewerJS.fromGlobalProperty(String globalPropertyName) {
|
||||
@@ -282,8 +284,8 @@ class ThermionViewerJS implements ThermionViewer {
|
||||
targetMeshNamesJS, animation.frameLengthInMs)
|
||||
.toDart;
|
||||
} catch (err, st) {
|
||||
print(err);
|
||||
print(st);
|
||||
_logger.severe(err);
|
||||
_logger.severe(st);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
@@ -826,17 +828,17 @@ class ThermionViewerJS implements ThermionViewer {
|
||||
void onDispose(Future Function() callback) {
|
||||
_onDispose.add(callback);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Future setShadowType(ShadowType shadowType) {
|
||||
return _shim.setShadowType(shadowType.index).toDart;
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Future setShadowsEnabled(bool enabled) {
|
||||
return _shim.setShadowsEnabled(enabled).toDart;
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Future setSoftShadowOptions(double penumbraScale, double penumbraRatioScale) {
|
||||
return _shim.setSoftShadowOptions(penumbraScale, penumbraRatioScale).toDart;
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'dart:js_interop_unsafe';
|
||||
import 'dart:math';
|
||||
import 'dart:typed_data' as td;
|
||||
import 'dart:typed_data';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:thermion_dart/thermion_dart/scene.dart';
|
||||
import 'package:web/web.dart';
|
||||
import 'package:animation_tools_dart/animation_tools_dart.dart';
|
||||
@@ -40,6 +41,8 @@ typedef ThermionViewerImpl = ThermionViewerWasm;
|
||||
/// (Emscripten-generated) ThermionDart JS module.
|
||||
///
|
||||
class ThermionViewerWasm implements ThermionViewer {
|
||||
final _logger = Logger("ThermionViewerWasm");
|
||||
|
||||
late _EmscriptenModule _module;
|
||||
|
||||
bool _initialized = false;
|
||||
@@ -812,7 +815,7 @@ class ThermionViewerWasm implements ThermionViewer {
|
||||
var meshEntity = meshEntities[i];
|
||||
|
||||
if (targetMeshNames?.contains(meshName) == false) {
|
||||
// print("Skipping $meshName, not contained in target");
|
||||
// _logger.info("Skipping $meshName, not contained in target");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -820,7 +823,7 @@ class ThermionViewerWasm implements ThermionViewer {
|
||||
|
||||
var meshMorphTargets = await getMorphTargetNames(entity, meshEntity);
|
||||
|
||||
print("Got mesh morph targets ${meshMorphTargets}");
|
||||
_logger.info("Got mesh morph targets ${meshMorphTargets}");
|
||||
|
||||
var intersection = animation.morphTargets
|
||||
.toSet()
|
||||
@@ -862,35 +865,42 @@ class ThermionViewerWasm implements ThermionViewer {
|
||||
// Copy the morph indices to WASM
|
||||
_module.writeArrayToMemory(
|
||||
idxList.buffer.asUint8List(idxList.offsetInBytes).toJS, idxPtr);
|
||||
|
||||
var result = _module.ccall(
|
||||
"set_morph_animation",
|
||||
"bool",
|
||||
[
|
||||
"void*".toJS,
|
||||
"int".toJS,
|
||||
"float*".toJS,
|
||||
"int*".toJS,
|
||||
"int".toJS,
|
||||
"int".toJS,
|
||||
"float".toJS
|
||||
].toJS,
|
||||
[
|
||||
_sceneManager!,
|
||||
meshEntity.toJS,
|
||||
dataPtr,
|
||||
idxPtr,
|
||||
indices.length.toJS,
|
||||
animation.numFrames.toJS,
|
||||
animation.frameLengthInMs.toJS
|
||||
].toJS,
|
||||
null) as JSBoolean;
|
||||
bool result = false;
|
||||
try {
|
||||
var jsResult = _module.ccall(
|
||||
"set_morph_animation",
|
||||
"bool",
|
||||
[
|
||||
"void*".toJS,
|
||||
"int".toJS,
|
||||
"float*".toJS,
|
||||
"int*".toJS,
|
||||
"int".toJS,
|
||||
"int".toJS,
|
||||
"float".toJS
|
||||
].toJS,
|
||||
[
|
||||
_sceneManager!,
|
||||
meshEntity.toJS,
|
||||
dataPtr,
|
||||
idxPtr,
|
||||
indices.length.toJS,
|
||||
animation.numFrames.toJS,
|
||||
animation.frameLengthInMs.toJS
|
||||
].toJS,
|
||||
null);
|
||||
_logger.info("Got jsResult $jsResult");
|
||||
result = (jsResult as JSNumber).toDartInt == 1;
|
||||
} catch (err, st) {
|
||||
_logger.severe(err);
|
||||
_logger.severe(st);
|
||||
}
|
||||
|
||||
// Free the memory allocated in WASM
|
||||
_module._free(dataPtr);
|
||||
_module._free(idxPtr);
|
||||
|
||||
if (!result.toDart) {
|
||||
if (!result) {
|
||||
throw Exception("Failed to set morph animation data for ${meshName}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:thermion_dart/thermion_dart.dart';
|
||||
import 'package:thermion_dart/thermion_dart/thermion_viewer_ffi.dart';
|
||||
import 'package:thermion_flutter_platform_interface/thermion_flutter_platform_interface.dart';
|
||||
import 'package:thermion_flutter_platform_interface/thermion_flutter_texture.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
///
|
||||
/// An implementation of [ThermionFlutterPlatform] that uses a Flutter platform
|
||||
@@ -13,6 +14,7 @@ import 'package:thermion_flutter_platform_interface/thermion_flutter_texture.dar
|
||||
///
|
||||
class ThermionFlutterFFI extends ThermionFlutterPlatform {
|
||||
final _channel = const MethodChannel("dev.thermion.flutter/event");
|
||||
final _logger = Logger("ThermionFlutterFFI");
|
||||
|
||||
ThermionViewerFFI? _viewer;
|
||||
|
||||
@@ -133,7 +135,7 @@ class ThermionFlutterFFI extends ThermionFlutterPlatform {
|
||||
final hardwareTextureId = result[1] as int?;
|
||||
final surfaceAddress = result[2] as int?;
|
||||
|
||||
print(
|
||||
_logger.info(
|
||||
"Created texture with flutter texture id ${flutterTextureId}, hardwareTextureId $hardwareTextureId and surfaceAddress $surfaceAddress");
|
||||
|
||||
_viewer?.viewportDimensions = (width.toDouble(), height.toDouble());
|
||||
|
||||
Reference in New Issue
Block a user