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