update web/js interop types

This commit is contained in:
Nick Fisher
2024-06-15 13:49:24 +08:00
parent e47e8e39f3
commit 49f33cd7bf
5 changed files with 2009 additions and 145 deletions

View File

@@ -7,19 +7,25 @@ import 'package:dart_filament/dart_filament/abstract_filament_viewer.dart';
import 'package:dart_filament/dart_filament/entities/filament_entity.dart'; import 'package:dart_filament/dart_filament/entities/filament_entity.dart';
import 'package:dart_filament/dart_filament/scene.dart'; import 'package:dart_filament/dart_filament/scene.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
import 'dart_filament_js_extension_type.dart'; import 'shims/abstract_filament_viewer_js_shim.dart';
class JsInteropFilamentViewer implements AbstractFilamentViewer { ///
late final DartFilamentJSShim _jsObject; /// An [AbstractFilamentViewer] implementation that forwards calls to
/// a corresponding Javascript shim implementation (see [AbstractFilamentViewerJSShim]).
///
class FilamentViewerJS implements AbstractFilamentViewer {
late final AbstractFilamentViewerJSShim _shim;
JsInteropFilamentViewer(String globalPropertyName) { FilamentViewerJS.fromGlobalProperty(String globalPropertyName) {
this._jsObject = globalContext.getProperty(globalPropertyName.toJS) this._shim = globalContext.getProperty(globalPropertyName.toJS)
as DartFilamentJSShim; as AbstractFilamentViewerJSShim;
} }
FilamentViewerJS(this._shim);
@override @override
Future<bool> get initialized async { Future<bool> get initialized async {
var inited = _jsObject.initialized; var inited = _shim.initialized;
final JSBoolean result = await inited.toDart; final JSBoolean result = await inited.toDart;
return result.toDart; return result.toDart;
} }
@@ -30,76 +36,76 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
} }
@override @override
bool get rendering => _jsObject.rendering; bool get rendering => _shim.rendering;
@override @override
Future<void> setRendering(bool render) async { Future<void> setRendering(bool render) async {
await _jsObject.setRendering(render).toDart; await _shim.setRendering(render).toDart;
} }
@override @override
Future<void> render() async { Future<void> render() async {
await _jsObject.render().toDart; await _shim.render().toDart;
} }
@override @override
Future<void> setFrameRate(int framerate) async { Future<void> setFrameRate(int framerate) async {
await _jsObject.setFrameRate(framerate).toDart; await _shim.setFrameRate(framerate).toDart;
} }
@override @override
Future<void> dispose() async { Future<void> dispose() async {
await _jsObject.dispose().toDart; await _shim.dispose().toDart;
} }
@override @override
Future<void> setBackgroundImage(String path, Future<void> setBackgroundImage(String path,
{bool fillHeight = false}) async { {bool fillHeight = false}) async {
await _jsObject.setBackgroundImage(path, fillHeight).toDart; await _shim.setBackgroundImage(path, fillHeight).toDart;
} }
@override @override
Future<void> setBackgroundImagePosition(double x, double y, Future<void> setBackgroundImagePosition(double x, double y,
{bool clamp = false}) async { {bool clamp = false}) async {
await _jsObject.setBackgroundImagePosition(x, y, clamp).toDart; await _shim.setBackgroundImagePosition(x, y, clamp).toDart;
} }
@override @override
Future<void> clearBackgroundImage() async { Future<void> clearBackgroundImage() async {
await _jsObject.clearBackgroundImage().toDart; await _shim.clearBackgroundImage().toDart;
} }
@override @override
Future<void> setBackgroundColor( Future<void> setBackgroundColor(
double r, double g, double b, double alpha) async { double r, double g, double b, double alpha) async {
await _jsObject.setBackgroundColor(r, g, b, alpha).toDart; await _shim.setBackgroundColor(r, g, b, alpha).toDart;
} }
@override @override
Future<void> loadSkybox(String skyboxPath) async { Future<void> loadSkybox(String skyboxPath) async {
await _jsObject.loadSkybox(skyboxPath).toDart; await _shim.loadSkybox(skyboxPath).toDart;
} }
@override @override
Future<void> removeSkybox() async { Future<void> removeSkybox() async {
await _jsObject.removeSkybox().toDart; await _shim.removeSkybox().toDart;
} }
@override @override
Future<void> loadIbl(String lightingPath, {double intensity = 30000}) async { Future<void> loadIbl(String lightingPath, {double intensity = 30000}) async {
await _jsObject.loadIbl(lightingPath, intensity).toDart; await _shim.loadIbl(lightingPath, intensity).toDart;
} }
@override @override
Future<void> rotateIbl(Matrix3 rotation) async { Future<void> rotateIbl(Matrix3 rotation) async {
await _jsObject await _shim
.rotateIbl(rotation.storage.map((v) => v.toJS).toList().toJS) .rotateIbl(rotation.storage.map((v) => v.toJS).toList().toJS)
.toDart; .toDart;
} }
@override @override
Future<void> removeIbl() async { Future<void> removeIbl() async {
await _jsObject.removeIbl().toDart; await _shim.removeIbl().toDart;
} }
@override @override
@@ -120,7 +126,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
double sunHaloSize = 10.0, double sunHaloSize = 10.0,
double sunHaloFallof = 80.0, double sunHaloFallof = 80.0,
bool castShadows = true}) async { bool castShadows = true}) async {
return (await _jsObject return (await _shim
.addLight( .addLight(
type.index, type.index,
colour, colour,
@@ -144,36 +150,36 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
@override @override
Future<void> removeLight(FilamentEntity light) async { Future<void> removeLight(FilamentEntity light) async {
await _jsObject.removeLight(light).toDart; await _shim.removeLight(light).toDart;
} }
@override @override
Future<void> clearLights() async { Future<void> clearLights() async {
await _jsObject.clearLights().toDart; await _shim.clearLights().toDart;
} }
@override @override
Future<FilamentEntity> loadGlb(String path, {int numInstances = 1}) async { Future<FilamentEntity> loadGlb(String path, {int numInstances = 1}) async {
var entity = (await _jsObject.loadGlb(path, numInstances).toDart).toDartInt; var entity = (await _shim.loadGlb(path, numInstances).toDart).toDartInt;
scene.registerEntity(entity); scene.registerEntity(entity);
return entity; return entity;
} }
@override @override
Future<FilamentEntity> createInstance(FilamentEntity entity) async { Future<FilamentEntity> createInstance(FilamentEntity entity) async {
return (await _jsObject.createInstance(entity).toDart).toDartInt; return (await _shim.createInstance(entity).toDart).toDartInt;
} }
@override @override
Future<int> getInstanceCount(FilamentEntity entity) async { Future<int> getInstanceCount(FilamentEntity entity) async {
return (await _jsObject.getInstanceCount(entity).toDart).toDartInt; return (await _shim.getInstanceCount(entity).toDart).toDartInt;
} }
@override @override
Future<List<FilamentEntity>> getInstances(FilamentEntity entity) async { Future<List<FilamentEntity>> getInstances(FilamentEntity entity) async {
throw UnimplementedError(); throw UnimplementedError();
// final List<JSObject> jsInstances = // final List<JSObject> jsInstances =
// await _jsObject.getInstances(entity).toDart; // await _shim.getInstances(entity).toDart;
// return jsInstances // return jsInstances
// .map((js) => FilamentEntity._fromJSObject(js)) // .map((js) => FilamentEntity._fromJSObject(js))
// .toList() // .toList()
@@ -184,7 +190,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
Future<FilamentEntity> loadGltf(String path, String relativeResourcePath, Future<FilamentEntity> loadGltf(String path, String relativeResourcePath,
{bool force = false}) async { {bool force = false}) async {
throw UnimplementedError(); throw UnimplementedError();
// final FilamentEntity jsEntity = await _jsObject // final FilamentEntity jsEntity = await _shim
// .loadGltf(path, relativeResourcePath, force: force) // .loadGltf(path, relativeResourcePath, force: force)
// .toDart; // .toDart;
// return FilamentEntity._fromJSObject(jsEntity).toDart; // return FilamentEntity._fromJSObject(jsEntity).toDart;
@@ -192,53 +198,52 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
@override @override
Future<void> panStart(double x, double y) async { Future<void> panStart(double x, double y) async {
await _jsObject.panStart(x, y).toDart; await _shim.panStart(x, y).toDart;
} }
@override @override
Future<void> panUpdate(double x, double y) async { Future<void> panUpdate(double x, double y) async {
await _jsObject.panUpdate(x, y).toDart; await _shim.panUpdate(x, y).toDart;
} }
@override @override
Future<void> panEnd() async { Future<void> panEnd() async {
await _jsObject.panEnd().toDart; await _shim.panEnd().toDart;
} }
@override @override
Future<void> rotateStart(double x, double y) async { Future<void> rotateStart(double x, double y) async {
await _jsObject.rotateStart(x, y).toDart; await _shim.rotateStart(x, y).toDart;
} }
@override @override
Future<void> rotateUpdate(double x, double y) async { Future<void> rotateUpdate(double x, double y) async {
await _jsObject.rotateUpdate(x, y).toDart; await _shim.rotateUpdate(x, y).toDart;
} }
@override @override
Future<void> rotateEnd() async { Future<void> rotateEnd() async {
await _jsObject.rotateEnd().toDart; await _shim.rotateEnd().toDart;
} }
@override @override
Future<void> setMorphTargetWeights( Future<void> setMorphTargetWeights(
FilamentEntity entity, List<double> weights) async { FilamentEntity entity, List<double> weights) async {
var jsWeights = weights.map((x) => x.toJS).cast<JSNumber>().toList().toJS; var jsWeights = weights.map((x) => x.toJS).cast<JSNumber>().toList().toJS;
var promise = _jsObject.setMorphTargetWeights(entity, jsWeights); var promise = _shim.setMorphTargetWeights(entity, jsWeights);
await promise.toDart; await promise.toDart;
} }
@override @override
Future<List<String>> getMorphTargetNames( Future<List<String>> getMorphTargetNames(
FilamentEntity entity, FilamentEntity childEntity) async { FilamentEntity entity, FilamentEntity childEntity) async {
var result = var result = await _shim.getMorphTargetNames(entity, childEntity).toDart;
await _jsObject.getMorphTargetNames(entity, childEntity).toDart;
return result.toDart.map((r) => r.toDart).toList(); return result.toDart.map((r) => r.toDart).toList();
} }
@override @override
Future<List<String>> getAnimationNames(FilamentEntity entity) async { Future<List<String>> getAnimationNames(FilamentEntity entity) async {
var names = (await (_jsObject.getAnimationNames(entity).toDart)) var names = (await (_shim.getAnimationNames(entity).toDart))
.toDart .toDart
.map((x) => x.toDart) .map((x) => x.toDart)
.toList(); .toList();
@@ -248,7 +253,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
@override @override
Future<double> getAnimationDuration( Future<double> getAnimationDuration(
FilamentEntity entity, int animationIndex) async { FilamentEntity entity, int animationIndex) async {
return (await _jsObject.getAnimationDuration(entity, animationIndex).toDart) return (await _shim.getAnimationDuration(entity, animationIndex).toDart)
.toDartDouble; .toDartDouble;
} }
@@ -268,7 +273,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
.toJS; .toJS;
var targetMeshNamesJS = var targetMeshNamesJS =
targetMeshNames?.map((x) => x.toJS).cast<JSString>().toList().toJS; targetMeshNames?.map((x) => x.toJS).cast<JSString>().toList().toJS;
await _jsObject await _shim
.setMorphAnimationData(entity, animationDataJs, morphTargetsJs, .setMorphAnimationData(entity, animationDataJs, morphTargetsJs,
targetMeshNamesJS, animation.frameLengthInMs) targetMeshNamesJS, animation.frameLengthInMs)
.toDart; .toDart;
@@ -281,7 +286,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
@override @override
Future<void> resetBones(FilamentEntity entity) async { Future<void> resetBones(FilamentEntity entity) async {
await _jsObject.resetBones(entity).toDart; await _shim.resetBones(entity).toDart;
} }
@override @override
@@ -290,7 +295,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
{int skinIndex = 0, {int skinIndex = 0,
double fadeInInSecs = 0.0, double fadeInInSecs = 0.0,
double fadeOutInSecs = 0.0, double fadeOutInSecs = 0.0,
double maxDelta=1.0}) async { double maxDelta = 1.0}) async {
var boneNames = animation.bones.map((n) => n.toJS).toList().toJS; var boneNames = animation.bones.map((n) => n.toJS).toList().toJS;
var frameData = animation.frameData var frameData = animation.frameData
.map((frame) => frame .map((frame) => frame
@@ -308,7 +313,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
.toList() .toList()
.toJS; .toJS;
await _jsObject await _shim
.addBoneAnimation( .addBoneAnimation(
entity, entity,
boneNames, boneNames,
@@ -318,33 +323,33 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
skinIndex.toJS, skinIndex.toJS,
fadeInInSecs.toJS, fadeInInSecs.toJS,
fadeOutInSecs.toJS, fadeOutInSecs.toJS,
maxDelta) maxDelta.toJS)
.toDart; .toDart;
} }
@override @override
Future<void> removeEntity(FilamentEntity entity) async { Future<void> removeEntity(FilamentEntity entity) async {
await _jsObject.removeEntity(entity).toDart; await _shim.removeEntity(entity).toDart;
} }
@override @override
Future<void> clearEntities() async { Future<void> clearEntities() async {
await _jsObject.clearEntities().toDart; await _shim.clearEntities().toDart;
} }
@override @override
Future<void> zoomBegin() async { Future<void> zoomBegin() async {
await _jsObject.zoomBegin().toDart; await _shim.zoomBegin().toDart;
} }
@override @override
Future<void> zoomUpdate(double x, double y, double z) async { Future<void> zoomUpdate(double x, double y, double z) async {
await _jsObject.zoomUpdate(x, y, z).toDart; await _shim.zoomUpdate(x, y, z).toDart;
} }
@override @override
Future<void> zoomEnd() async { Future<void> zoomEnd() async {
await _jsObject.zoomEnd().toDart; await _shim.zoomEnd().toDart;
} }
@override @override
@@ -353,7 +358,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
bool reverse = false, bool reverse = false,
bool replaceActive = true, bool replaceActive = true,
double crossfade = 0.0}) async { double crossfade = 0.0}) async {
await _jsObject await _shim
.playAnimation(entity, index, loop, reverse, replaceActive, crossfade) .playAnimation(entity, index, loop, reverse, replaceActive, crossfade)
.toDart; .toDart;
} }
@@ -364,7 +369,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
bool reverse = false, bool reverse = false,
bool replaceActive = true, bool replaceActive = true,
double crossfade = 0.0}) async { double crossfade = 0.0}) async {
await _jsObject await _shim
.playAnimationByName( .playAnimationByName(
entity, name, loop, reverse, replaceActive, crossfade) entity, name, loop, reverse, replaceActive, crossfade)
.toDart; .toDart;
@@ -373,79 +378,79 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
@override @override
Future<void> setAnimationFrame( Future<void> setAnimationFrame(
FilamentEntity entity, int index, int animationFrame) async { FilamentEntity entity, int index, int animationFrame) async {
await _jsObject.setAnimationFrame(entity, index, animationFrame).toDart; await _shim.setAnimationFrame(entity, index, animationFrame).toDart;
} }
@override @override
Future<void> stopAnimation(FilamentEntity entity, int animationIndex) async { Future<void> stopAnimation(FilamentEntity entity, int animationIndex) async {
await _jsObject.stopAnimation(entity, animationIndex).toDart; await _shim.stopAnimation(entity, animationIndex).toDart;
} }
@override @override
Future<void> stopAnimationByName(FilamentEntity entity, String name) async { Future<void> stopAnimationByName(FilamentEntity entity, String name) async {
await _jsObject.stopAnimationByName(entity, name).toDart; await _shim.stopAnimationByName(entity, name).toDart;
} }
@override @override
Future<void> setCamera(FilamentEntity entity, String? name) async { Future<void> setCamera(FilamentEntity entity, String? name) async {
await _jsObject.setCamera(entity, name).toDart; await _shim.setCamera(entity, name).toDart;
} }
@override @override
Future<void> setMainCamera() async { Future<void> setMainCamera() async {
await _jsObject.setMainCamera().toDart; await _shim.setMainCamera().toDart;
} }
@override @override
Future<FilamentEntity> getMainCamera() async { Future<FilamentEntity> getMainCamera() async {
throw UnimplementedError(); throw UnimplementedError();
// final FilamentEntity jsEntity = await _jsObject.getMainCamera().toDart; // final FilamentEntity jsEntity = await _shim.getMainCamera().toDart;
// return FilamentEntity._fromJSObject(jsEntity).toDart; // return FilamentEntity._fromJSObject(jsEntity).toDart;
} }
@override @override
Future<void> setCameraFov(double degrees, double width, double height) async { Future<void> setCameraFov(double degrees, double width, double height) async {
await _jsObject.setCameraFov(degrees, width, height).toDart; await _shim.setCameraFov(degrees, width, height).toDart;
} }
@override @override
Future<void> setToneMapping(ToneMapper mapper) async { Future<void> setToneMapping(ToneMapper mapper) async {
await _jsObject.setToneMapping(mapper.index).toDart; await _shim.setToneMapping(mapper.index).toDart;
} }
@override @override
Future<void> setBloom(double bloom) async { Future<void> setBloom(double bloom) async {
await _jsObject.setBloom(bloom).toDart; await _shim.setBloom(bloom).toDart;
} }
@override @override
Future<void> setCameraFocalLength(double focalLength) async { Future<void> setCameraFocalLength(double focalLength) async {
await _jsObject.setCameraFocalLength(focalLength).toDart; await _shim.setCameraFocalLength(focalLength).toDart;
} }
@override @override
Future<void> setCameraCulling(double near, double far) async { Future<void> setCameraCulling(double near, double far) async {
await _jsObject.setCameraCulling(near, far).toDart; await _shim.setCameraCulling(near, far).toDart;
} }
@override @override
Future<double> getCameraCullingNear() async { Future<double> getCameraCullingNear() async {
return (await _jsObject.getCameraCullingNear().toDart).toDartDouble; return (await _shim.getCameraCullingNear().toDart).toDartDouble;
} }
@override @override
Future<double> getCameraCullingFar() async { Future<double> getCameraCullingFar() async {
return (await _jsObject.getCameraCullingFar().toDart).toDartDouble; return (await _shim.getCameraCullingFar().toDart).toDartDouble;
} }
@override @override
Future<void> setCameraFocusDistance(double focusDistance) async { Future<void> setCameraFocusDistance(double focusDistance) async {
await _jsObject.setCameraFocusDistance(focusDistance).toDart; await _shim.setCameraFocusDistance(focusDistance).toDart;
} }
@override @override
Future<Vector3> getCameraPosition() async { Future<Vector3> getCameraPosition() async {
final jsPosition = (await _jsObject.getCameraPosition().toDart).toDart; final jsPosition = (await _shim.getCameraPosition().toDart).toDart;
return Vector3(jsPosition[0].toDartDouble, jsPosition[1].toDartDouble, return Vector3(jsPosition[0].toDartDouble, jsPosition[1].toDartDouble,
jsPosition[2].toDartDouble); jsPosition[2].toDartDouble);
} }
@@ -453,14 +458,14 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
@override @override
Future<Matrix4> getCameraModelMatrix() async { Future<Matrix4> getCameraModelMatrix() async {
throw UnimplementedError(); throw UnimplementedError();
// final JSMatrix4 jsMatrix = await _jsObject.getCameraModelMatrix().toDart; // final JSMatrix4 jsMatrix = await _shim.getCameraModelMatrix().toDart;
// return Matrix4.fromList(jsMatrix.storage).toDart; // return Matrix4.fromList(jsMatrix.storage).toDart;
} }
@override @override
Future<Matrix4> getCameraViewMatrix() async { Future<Matrix4> getCameraViewMatrix() async {
throw UnimplementedError(); throw UnimplementedError();
// final JSMatrix4 jsMatrix = await _jsObject.getCameraViewMatrix().toDart; // final JSMatrix4 jsMatrix = await _shim.getCameraViewMatrix().toDart;
// return Matrix4.fromList(jsMatrix.storage).toDart; // return Matrix4.fromList(jsMatrix.storage).toDart;
} }
@@ -468,7 +473,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
Future<Matrix4> getCameraProjectionMatrix() async { Future<Matrix4> getCameraProjectionMatrix() async {
throw UnimplementedError(); throw UnimplementedError();
// final JSMatrix4 jsMatrix = // final JSMatrix4 jsMatrix =
// await _jsObject.getCameraProjectionMatrix().toDart; // await _shim.getCameraProjectionMatrix().toDart;
// return Matrix4.fromList(jsMatrix.storage).toDart; // return Matrix4.fromList(jsMatrix.storage).toDart;
} }
@@ -476,47 +481,45 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
Future<Matrix4> getCameraCullingProjectionMatrix() async { Future<Matrix4> getCameraCullingProjectionMatrix() async {
throw UnimplementedError(); throw UnimplementedError();
// final JSMatrix4 jsMatrix = // final JSMatrix4 jsMatrix =
// await _jsObject.getCameraCullingProjectionMatrix().toDart; // await _shim.getCameraCullingProjectionMatrix().toDart;
// return Matrix4.fromList(jsMatrix.storage).toDart; // return Matrix4.fromList(jsMatrix.storage).toDart;
} }
@override @override
Future<Frustum> getCameraFrustum() async { Future<Frustum> getCameraFrustum() async {
throw UnimplementedError(); throw UnimplementedError();
// final JSObject jsFrustum = await _jsObject.getCameraFrustum().toDart; // final JSObject jsFrustum = await _shim.getCameraFrustum().toDart;
// // Assuming Frustum is a class that can be constructed from the JSObject // // Assuming Frustum is a class that can be constructed from the JSObject
// return Frustum._fromJSObject(jsFrustum).toDart; // return Frustum._fromJSObject(jsFrustum).toDart;
} }
@override @override
Future<void> setCameraPosition(double x, double y, double z) async { Future<void> setCameraPosition(double x, double y, double z) async {
await _jsObject.setCameraPosition(x, y, z).toDart; await _shim.setCameraPosition(x, y, z).toDart;
} }
@override @override
Future<Matrix3> getCameraRotation() async { Future<Matrix3> getCameraRotation() async {
throw UnimplementedError(); throw UnimplementedError();
// final JSMatrix3 jsRotation = await _jsObject.getCameraRotation().toDart; // final JSMatrix3 jsRotation = await _shim.getCameraRotation().toDart;
// return Matrix3.fromList(jsRotation.storage).toDart; // return Matrix3.fromList(jsRotation.storage).toDart;
} }
@override @override
Future<void> moveCameraToAsset(FilamentEntity entity) async { Future<void> moveCameraToAsset(FilamentEntity entity) async {
await _jsObject.moveCameraToAsset(entity).toDart; await _shim.moveCameraToAsset(entity).toDart;
} }
@override @override
Future<void> setViewFrustumCulling(bool enabled) async { Future<void> setViewFrustumCulling(bool enabled) async {
throw UnimplementedError(); throw UnimplementedError();
// await _jsObject.setViewFrustumCulling(enabled.toJSBoolean()).toDart; // await _shim.setViewFrustumCulling(enabled.toJSBoolean()).toDart;
} }
@override @override
Future<void> setCameraExposure( Future<void> setCameraExposure(
double aperture, double shutterSpeed, double sensitivity) async { double aperture, double shutterSpeed, double sensitivity) async {
await _jsObject await _shim.setCameraExposure(aperture, shutterSpeed, sensitivity).toDart;
.setCameraExposure(aperture, shutterSpeed, sensitivity)
.toDart;
} }
@override @override
@@ -527,58 +530,58 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
quaternion.z.toJS, quaternion.z.toJS,
quaternion.w.toJS quaternion.w.toJS
]; ];
await _jsObject.setCameraRotation(values.toJS).toDart; await _shim.setCameraRotation(values.toJS).toDart;
} }
@override @override
Future<void> setCameraModelMatrix(List<double> matrix) async { Future<void> setCameraModelMatrix(List<double> matrix) async {
throw UnimplementedError(); throw UnimplementedError();
// await _jsObject.setCameraModelMatrix(matrix.toJSBox).toDart; // await _shim.setCameraModelMatrix(matrix.toJSBox).toDart;
} }
@override @override
Future<void> setMaterialColor(FilamentEntity entity, String meshName, Future<void> setMaterialColor(FilamentEntity entity, String meshName,
int materialIndex, double r, double g, double b, double a) async { int materialIndex, double r, double g, double b, double a) async {
await _jsObject await _shim
.setMaterialColor(entity, meshName, materialIndex, r, g, b, a) .setMaterialColor(entity, meshName, materialIndex, r, g, b, a)
.toDart; .toDart;
} }
@override @override
Future<void> transformToUnitCube(FilamentEntity entity) async { Future<void> transformToUnitCube(FilamentEntity entity) async {
await _jsObject.transformToUnitCube(entity).toDart; await _shim.transformToUnitCube(entity).toDart;
} }
@override @override
Future<void> setPosition( Future<void> setPosition(
FilamentEntity entity, double x, double y, double z) async { FilamentEntity entity, double x, double y, double z) async {
await _jsObject.setPosition(entity, x, y, z).toDart; await _shim.setPosition(entity, x, y, z).toDart;
} }
@override @override
Future<void> setScale(FilamentEntity entity, double scale) async { Future<void> setScale(FilamentEntity entity, double scale) async {
await _jsObject.setScale(entity, scale).toDart; await _shim.setScale(entity, scale).toDart;
} }
@override @override
Future<void> setRotation( Future<void> setRotation(
FilamentEntity entity, double rads, double x, double y, double z) async { FilamentEntity entity, double rads, double x, double y, double z) async {
await _jsObject.setRotation(entity, rads, x, y, z).toDart; await _shim.setRotation(entity, rads, x, y, z).toDart;
} }
@override @override
Future<void> queuePositionUpdate( Future<void> queuePositionUpdate(
FilamentEntity entity, double x, double y, double z, FilamentEntity entity, double x, double y, double z,
{bool relative = false}) async { {bool relative = false}) async {
await _jsObject.queuePositionUpdate(entity, x, y, z, relative).toDart; await _shim.queuePositionUpdate(entity, x, y, z, relative).toDart;
} }
@override @override
Future<void> queueRotationUpdate( Future<void> queueRotationUpdate(
FilamentEntity entity, double rads, double x, double y, double z, FilamentEntity entity, double rads, double x, double y, double z,
{bool relative = false}) async { {bool relative = false}) async {
await _jsObject.queueRotationUpdate(entity, rads, x, y, z, relative).toDart; await _shim.queueRotationUpdate(entity, rads, x, y, z, relative).toDart;
} }
@override @override
@@ -587,19 +590,19 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
throw UnimplementedError(); throw UnimplementedError();
// final JSQuaternion jsQuat = quat.toJSQuaternion().toDart; // final JSQuaternion jsQuat = quat.toJSQuaternion().toDart;
// await _jsObject // await _shim
// .queueRotationUpdateQuat(entity, jsQuat, relative: relative) // .queueRotationUpdateQuat(entity, jsQuat, relative: relative)
// .toDart; // .toDart;
} }
@override @override
Future<void> setPostProcessing(bool enabled) async { Future<void> setPostProcessing(bool enabled) async {
await _jsObject.setPostProcessing(enabled).toDart; await _shim.setPostProcessing(enabled).toDart;
} }
@override @override
Future<void> setAntiAliasing(bool msaa, bool fxaa, bool taa) async { Future<void> setAntiAliasing(bool msaa, bool fxaa, bool taa) async {
await _jsObject.setAntiAliasing(msaa, fxaa, taa).toDart; await _shim.setAntiAliasing(msaa, fxaa, taa).toDart;
} }
@override @override
@@ -607,30 +610,30 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
FilamentEntity entity, Quaternion rotation) async { FilamentEntity entity, Quaternion rotation) async {
throw UnimplementedError(); throw UnimplementedError();
// final JSQuaternion jsRotation = rotation.toJSQuaternion().toDart; // final JSQuaternion jsRotation = rotation.toJSQuaternion().toDart;
// await _jsObject.setRotationQuat(entity, jsRotation).toDart; // await _shim.setRotationQuat(entity, jsRotation).toDart;
} }
@override @override
Future<void> reveal(FilamentEntity entity, String? meshName) async { Future<void> reveal(FilamentEntity entity, String? meshName) async {
throw UnimplementedError(); throw UnimplementedError();
// await _jsObject.reveal(entity, meshName).toDart; // await _shim.reveal(entity, meshName).toDart;
} }
@override @override
Future<void> hide(FilamentEntity entity, String? meshName) async { Future<void> hide(FilamentEntity entity, String? meshName) async {
throw UnimplementedError(); throw UnimplementedError();
// await _jsObject.hide(entity, meshName).toDart; // await _shim.hide(entity, meshName).toDart;
} }
@override @override
void pick(int x, int y) { void pick(int x, int y) {
throw UnimplementedError(); throw UnimplementedError();
// _jsObject.pick(x, y).toDart; // _shim.pick(x, y).toDart;
} }
@override @override
String? getNameForEntity(FilamentEntity entity) { String? getNameForEntity(FilamentEntity entity) {
return _jsObject.getNameForEntity(entity); return _shim.getNameForEntity(entity);
} }
@override @override
@@ -639,7 +642,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
double orbitSpeedX = 0.01, double orbitSpeedX = 0.01,
double orbitSpeedY = 0.01, double orbitSpeedY = 0.01,
double zoomSpeed = 0.01}) async { double zoomSpeed = 0.01}) async {
await _jsObject await _shim
.setCameraManipulatorOptions( .setCameraManipulatorOptions(
mode.index, orbitSpeedX, orbitSpeedY, zoomSpeed) mode.index, orbitSpeedX, orbitSpeedY, zoomSpeed)
.toDart; .toDart;
@@ -649,7 +652,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
Future<List<FilamentEntity>> getChildEntities( Future<List<FilamentEntity>> getChildEntities(
FilamentEntity parent, bool renderableOnly) async { FilamentEntity parent, bool renderableOnly) async {
final children = final children =
await _jsObject.getChildEntities(parent, renderableOnly).toDart; await _shim.getChildEntities(parent, renderableOnly).toDart;
return children.toDart return children.toDart
.map((js) => js.toDartInt) .map((js) => js.toDartInt)
.cast<FilamentEntity>() .cast<FilamentEntity>()
@@ -659,31 +662,30 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
@override @override
Future<FilamentEntity> getChildEntity( Future<FilamentEntity> getChildEntity(
FilamentEntity parent, String childName) async { FilamentEntity parent, String childName) async {
return (await _jsObject.getChildEntity(parent, childName).toDart).toDartInt; return (await _shim.getChildEntity(parent, childName).toDart).toDartInt;
} }
@override @override
Future<List<String>> getChildEntityNames(FilamentEntity entity, Future<List<String>> getChildEntityNames(FilamentEntity entity,
{bool renderableOnly = true}) async { {bool renderableOnly = true}) async {
var names = var names = await _shim.getChildEntityNames(entity, renderableOnly).toDart;
await _jsObject.getChildEntityNames(entity, renderableOnly).toDart;
return names.toDart.map((x) => x.toDart).toList(); return names.toDart.map((x) => x.toDart).toList();
} }
@override @override
Future<void> setRecording(bool recording) async { Future<void> setRecording(bool recording) async {
throw UnimplementedError(); throw UnimplementedError();
// await _jsObject.setRecording(recording.toJSBoolean()).toDart; // await _shim.setRecording(recording.toJSBoolean()).toDart;
} }
@override @override
Future<void> setRecordingOutputDirectory(String outputDirectory) async { Future<void> setRecordingOutputDirectory(String outputDirectory) async {
await _jsObject.setRecordingOutputDirectory(outputDirectory).toDart; await _shim.setRecordingOutputDirectory(outputDirectory).toDart;
} }
@override @override
Future<void> addAnimationComponent(FilamentEntity entity) async { Future<void> addAnimationComponent(FilamentEntity entity) async {
await _jsObject.addAnimationComponent(entity).toDart; await _shim.addAnimationComponent(entity).toDart;
} }
@override @override
@@ -695,7 +697,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
// ? allowInterop( // ? allowInterop(
// (int entityId1, int entityId2) => callback(entityId1, entityId2)) // (int entityId1, int entityId2) => callback(entityId1, entityId2))
// : null; // : null;
// await _jsObject // await _shim
// .addCollisionComponent(entity, // .addCollisionComponent(entity,
// callback: jsCallback, // callback: jsCallback,
// affectsTransform: affectsTransform.toJSBoolean()) // affectsTransform: affectsTransform.toJSBoolean())
@@ -704,7 +706,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
@override @override
Future<void> removeCollisionComponent(FilamentEntity entity) async { Future<void> removeCollisionComponent(FilamentEntity entity) async {
await _jsObject.removeCollisionComponent(entity).toDart; await _shim.removeCollisionComponent(entity).toDart;
} }
@override @override
@@ -713,7 +715,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
{String? materialPath, {String? materialPath,
PrimitiveType primitiveType = PrimitiveType.TRIANGLES}) async { PrimitiveType primitiveType = PrimitiveType.TRIANGLES}) async {
throw UnimplementedError(); throw UnimplementedError();
// final FilamentEntity jsEntity = await _jsObject // final FilamentEntity jsEntity = await _shim
// .createGeometry(vertices, indices, // .createGeometry(vertices, indices,
// materialPath: materialPath, primitiveType: primitiveType.index) // materialPath: materialPath, primitiveType: primitiveType.index)
// .toDart; // .toDart;
@@ -722,17 +724,17 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
@override @override
Future<void> setParent(FilamentEntity child, FilamentEntity parent) async { Future<void> setParent(FilamentEntity child, FilamentEntity parent) async {
await _jsObject.setParent(child, parent).toDart; await _shim.setParent(child, parent).toDart;
} }
@override @override
Future<void> testCollisions(FilamentEntity entity) async { Future<void> testCollisions(FilamentEntity entity) async {
await _jsObject.testCollisions(entity).toDart; await _shim.testCollisions(entity).toDart;
} }
@override @override
Future<void> setPriority(FilamentEntity entityId, int priority) async { Future<void> setPriority(FilamentEntity entityId, int priority) async {
await _jsObject.setPriority(entityId, priority).toDart; await _shim.setPriority(entityId, priority).toDart;
} }
Scene? _scene; Scene? _scene;
@@ -748,14 +750,14 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
@override @override
Future<List<String>> getBoneNames(FilamentEntity entity, Future<List<String>> getBoneNames(FilamentEntity entity,
{int skinIndex = 0}) async { {int skinIndex = 0}) async {
var result = await _jsObject.getBoneNames(entity, skinIndex).toDart; var result = await _shim.getBoneNames(entity, skinIndex).toDart;
return result.toDart.map((n) => n.toDart).toList(); return result.toDart.map((n) => n.toDart).toList();
} }
@override @override
Future<FilamentEntity> getBone(FilamentEntity entity, int boneIndex, Future<FilamentEntity> getBone(FilamentEntity entity, int boneIndex,
{int skinIndex = 0}) async { {int skinIndex = 0}) async {
var result = await _jsObject.getBone(entity, boneIndex, skinIndex).toDart; var result = await _shim.getBone(entity, boneIndex, skinIndex).toDart;
return result.toDartInt; return result.toDartInt;
} }
@@ -768,32 +770,32 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
@override @override
Future<Matrix4> getLocalTransform(FilamentEntity entity) async { Future<Matrix4> getLocalTransform(FilamentEntity entity) async {
var result = await _jsObject.getLocalTransform(entity).toDart; var result = await _shim.getLocalTransform(entity).toDart;
return Matrix4.fromList(result.toDart.map((v) => v.toDartDouble).toList()); return Matrix4.fromList(result.toDart.map((v) => v.toDartDouble).toList());
} }
@override @override
Future<FilamentEntity?> getParent(FilamentEntity child) async { Future<FilamentEntity?> getParent(FilamentEntity child) async {
var result = await _jsObject.getParent(child).toDart; var result = await _shim.getParent(child).toDart;
return result.toDartInt; return result.toDartInt;
} }
@override @override
Future<Matrix4> getWorldTransform(FilamentEntity entity) async { Future<Matrix4> getWorldTransform(FilamentEntity entity) async {
var result = await _jsObject.getLocalTransform(entity).toDart; var result = await _shim.getLocalTransform(entity).toDart;
return Matrix4.fromList(result.toDart.map((v) => v.toDartDouble).toList()); return Matrix4.fromList(result.toDart.map((v) => v.toDartDouble).toList());
} }
@override @override
Future removeAnimationComponent(FilamentEntity entity) { Future removeAnimationComponent(FilamentEntity entity) {
return _jsObject.removeAnimationComponent(entity).toDart; return _shim.removeAnimationComponent(entity).toDart;
} }
@override @override
Future setBoneTransform( Future setBoneTransform(
FilamentEntity entity, int boneIndex, Matrix4 transform, FilamentEntity entity, int boneIndex, Matrix4 transform,
{int skinIndex = 0}) { {int skinIndex = 0}) {
return _jsObject return _shim
.setBoneTransform(entity, boneIndex, .setBoneTransform(entity, boneIndex,
transform.storage.map((v) => v.toJS).toList().toJS, skinIndex) transform.storage.map((v) => v.toJS).toList().toJS, skinIndex)
.toDart; .toDart;
@@ -801,7 +803,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
@override @override
Future setTransform(FilamentEntity entity, Matrix4 transform) { Future setTransform(FilamentEntity entity, Matrix4 transform) {
return _jsObject return _shim
.setTransform( .setTransform(
entity, transform.storage.map((v) => v.toJS).toList().toJS) entity, transform.storage.map((v) => v.toJS).toList().toJS)
.toDart; .toDart;
@@ -809,6 +811,6 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
@override @override
Future updateBoneMatrices(FilamentEntity entity) { Future updateBoneMatrices(FilamentEntity entity) {
return _jsObject.updateBoneMatrices(entity).toDart; return _shim.updateBoneMatrices(entity).toDart;
} }
} }

View File

@@ -2,30 +2,36 @@
library flutter_filament_js; library flutter_filament_js;
import 'dart:js_interop'; import 'dart:js_interop';
import 'dart:math'; import 'package:dart_filament/dart_filament/compatibility/web/interop/shims/abstract_filament_viewer_js_shim.dart';
import 'package:dart_filament/dart_filament/entities/filament_entity.dart';
import 'package:vector_math/vector_math_64.dart' as v64; import 'package:vector_math/vector_math_64.dart' as v64;
import 'package:animation_tools_dart/animation_tools_dart.dart'; import 'package:animation_tools_dart/animation_tools_dart.dart';
import 'package:animation_tools_dart/src/morph_animation_data.dart';
import 'package:dart_filament/dart_filament/abstract_filament_viewer.dart'; import 'package:dart_filament/dart_filament/abstract_filament_viewer.dart';
import 'package:dart_filament/dart_filament/entities/filament_entity.dart';
import 'package:dart_filament/dart_filament/compatibility/web/interop/dart_filament_js_extension_type.dart';
import 'dart:js_interop_unsafe'; import 'dart:js_interop_unsafe';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
///
/// A (Dart) class that wraps a (Dart) instance of [AbstractFilamentViewer],
/// but exported to JS by binding to a global property.
/// This is effectively an implementation of [AbstractFilamentViewerJSShim];
/// allowing users to interact with an instance of [AbstractFilamentViewer]
/// (presumably compiled to WASM) from any Javascript context (including
/// the browser console).
///
@JSExport() @JSExport()
class DartFilamentJSExportViewer { class FilamentViewerJSDartBridge {
final AbstractFilamentViewer viewer; final AbstractFilamentViewer viewer;
static void initializeBindings(AbstractFilamentViewer viewer) { FilamentViewerJSDartBridge(this.viewer);
var shim = DartFilamentJSExportViewer(viewer);
var wrapper = createJSInteropWrapper<DartFilamentJSExportViewer>(shim) void bind(
as DartFilamentJSShim; {String globalPropertyName = "filamentViewer"}) {
globalContext.setProperty("filamentViewer".toJS, wrapper); var wrapper = createJSInteropWrapper<FilamentViewerJSDartBridge>(this)
as AbstractFilamentViewerJSShim;
globalContext.setProperty(globalPropertyName.toJS, wrapper);
} }
DartFilamentJSExportViewer(this.viewer);
JSPromise<JSBoolean> get initialized { JSPromise<JSBoolean> get initialized {
return viewer.initialized.then((v) => v.toJS).toJS; return viewer.initialized.then((v) => v.toJS).toJS;
} }
@@ -559,28 +565,31 @@ class DartFilamentJSExportViewer {
@JSExport() @JSExport()
JSPromise setPostProcessing(bool enabled) => JSPromise setPostProcessing(bool enabled) =>
viewer.setPostProcessing(enabled).toJS; viewer.setPostProcessing(enabled).toJS;
@JSExport() @JSExport()
JSPromise setAntiAliasing(bool msaa, bool fxaa, bool taa) => JSPromise setAntiAliasing(bool msaa, bool fxaa, bool taa) =>
viewer.setAntiAliasing(msaa, fxaa, taa).toJS; viewer.setAntiAliasing(msaa, fxaa, taa).toJS;
@JSExport() @JSExport()
JSPromise setRotationQuat( JSPromise setRotationQuat(
FilamentEntity entity, JSArray<JSNumber> rotation) => FilamentEntity entity, JSArray<JSNumber> rotation) =>
throw UnimplementedError(); throw UnimplementedError();
// viewer.setRotationQuat(
// entity,
// rotation.toDartQuaternion(),
// ).toJS;
@JSExport() @JSExport()
JSPromise reveal(FilamentEntity entity, String? meshName) => JSPromise reveal(FilamentEntity entity, String? meshName) =>
viewer.reveal(entity, meshName).toJS; viewer.reveal(entity, meshName).toJS;
@JSExport() @JSExport()
JSPromise hide(FilamentEntity entity, String? meshName) => JSPromise hide(FilamentEntity entity, String? meshName) =>
viewer.hide(entity, meshName).toJS; viewer.hide(entity, meshName).toJS;
@JSExport() @JSExport()
void pick(int x, int y) => viewer.pick(x, y); void pick(int x, int y) => viewer.pick(x, y);
@JSExport() @JSExport()
String? getNameForEntity(FilamentEntity entity) => String? getNameForEntity(FilamentEntity entity) =>
viewer.getNameForEntity(entity); viewer.getNameForEntity(entity);
@JSExport() @JSExport()
JSPromise setCameraManipulatorOptions({ JSPromise setCameraManipulatorOptions({
int mode = 0, int mode = 0,
@@ -596,6 +605,7 @@ class DartFilamentJSExportViewer {
zoomSpeed: zoomSpeed, zoomSpeed: zoomSpeed,
) )
.toJS; .toJS;
@JSExport() @JSExport()
JSPromise<JSArray<JSNumber>> getChildEntities( JSPromise<JSArray<JSNumber>> getChildEntities(
FilamentEntity parent, bool renderableOnly) { FilamentEntity parent, bool renderableOnly) {
@@ -707,13 +717,5 @@ class DartFilamentJSExportViewer {
JSPromise addCollisionComponent(FilamentEntity entity, JSPromise addCollisionComponent(FilamentEntity entity,
{JSFunction? callback, bool affectsTransform = false}) { {JSFunction? callback, bool affectsTransform = false}) {
throw UnimplementedError(); throw UnimplementedError();
// final Function? dartCallback = callback != null
// ? allowInterop((int entityId1, int entityId2) => callback.apply([entityId1, entityId2]))
// : null;
// return viewer.addCollisionComponent(
// entity),
// callback: dartCallback,
// affectsTransform: affectsTransform,
// ).toJs
} }
} }

View File

@@ -2,10 +2,15 @@
library flutter_filament_js; library flutter_filament_js;
import 'dart:js_interop'; import 'dart:js_interop';
import 'package:dart_filament/dart_filament/entities/filament_entity.dart'; import 'package:dart_filament/dart_filament/entities/filament_entity.dart';
import 'package:dart_filament/dart_filament/abstract_filament_viewer.dart';
extension type DartFilamentJSShim(JSObject _) implements JSObject { ///
/// An extension type on [JSObject] that represents a
/// Javascript shim implementation of the [AbstractFilamentViewer] interface.
///
extension type AbstractFilamentViewerJSShim(JSObject _) implements JSObject {
@JS('initialized') @JS('initialized')
external JSPromise<JSBoolean> get initialized; external JSPromise<JSBoolean> get initialized;
@@ -401,3 +406,4 @@ extension type DartFilamentJSShim(JSObject _) implements JSObject {
external JSPromise setBoneTransform( external JSPromise setBoneTransform(
FilamentEntity entity, int boneIndex, JSArray<JSNumber> transform, int skinIndex); FilamentEntity entity, int boneIndex, JSArray<JSNumber> transform, int skinIndex);
} }

View File

@@ -0,0 +1,403 @@
@JS()
library flutter_filament_js;
import 'dart:js_interop';
import 'package:dart_filament/dart_filament/entities/filament_entity.dart';
import 'package:dart_filament/dart_filament/abstract_filament_viewer.dart';
///
/// An extension type on [JSObject] that represents a
/// Javascript shim implementation for the [AbstractFilamentViewer] interface.
///
extension type DartFilamentAPIJSShim(JSObject _) implements JSObject {
@JS('wasm_test')
external JSPromise wasm_test(String str);
@JS('set_rendering')
external JSPromise set_rendering(bool render);
@JS('render')
external JSPromise render();
@JS('setFrameRate')
external JSPromise setFrameRate(int framerate);
@JS('setBackgroundImage')
external JSPromise setBackgroundImage(String path, bool fillHeight);
@JS('setBackgroundImagePosition')
external JSPromise setBackgroundImagePosition(double x, double y, bool clamp);
@JS('clearBackgroundImage')
external JSPromise clearBackgroundImage();
@JS('setBackgroundColor')
external JSPromise setBackgroundColor(
double r, double g, double b, double alpha);
@JS('loadSkybox')
external JSPromise loadSkybox(String skyboxPath);
@JS('removeSkybox')
external JSPromise removeSkybox();
@JS('loadIbl')
external JSPromise loadIbl(String lightingPath, double intensity);
@JS('rotateIbl')
external JSPromise rotateIbl(JSArray<JSNumber> rotationMatrix);
@JS('removeIbl')
external JSPromise removeIbl();
@JS('addLight')
external JSPromise<JSNumber> addLight(
int type,
double colour,
double intensity,
double posX,
double posY,
double posZ,
double dirX,
double dirY,
double dirZ,
double falloffRadius,
double spotLightConeInner,
double spotLightConeOuter,
double sunAngularRadius,
double sunHaloSize,
double sunHaloFallof,
bool castShadows);
@JS('removeLight')
external JSPromise removeLight(FilamentEntity light);
@JS('clearLights')
external JSPromise clearLights();
@JS('loadGlb')
external JSPromise<JSNumber> loadGlb(String path, int numInstances);
@JS('createInstance')
external JSPromise<JSNumber> createInstance(FilamentEntity entity);
@JS('getInstanceCount')
external JSPromise<JSNumber> getInstanceCount(FilamentEntity entity);
@JS('getInstances')
external JSPromise<JSArray<JSNumber>> getInstances(FilamentEntity entity);
@JS('loadGltf')
external JSPromise<JSNumber> loadGltf(
String path, String relativeResourcePath);
@JS('panStart')
external JSPromise panStart(double x, double y);
@JS('panUpdate')
external JSPromise panUpdate(double x, double y);
@JS('panEnd')
external JSPromise panEnd();
@JS('rotateStart')
external JSPromise rotateStart(double x, double y);
@JS('rotateUpdate')
external JSPromise rotateUpdate(double x, double y);
@JS('rotateEnd')
external JSPromise rotateEnd();
@JS('setMorphTargetWeights')
external JSPromise setMorphTargetWeights(
FilamentEntity entity, JSArray<JSNumber> weights);
@JS('getMorphTargetNames')
external JSPromise<JSArray<JSString>> getMorphTargetNames(
FilamentEntity entity, FilamentEntity childEntity);
@JS('getBoneNames')
external JSPromise<JSArray<JSString>> getBoneNames(
FilamentEntity entity, int skinIndex);
@JS('getAnimationNames')
external JSPromise<JSArray<JSString>> getAnimationNames(
FilamentEntity entity);
@JS('getAnimationDuration')
external JSPromise<JSNumber> getAnimationDuration(
FilamentEntity entity, int animationIndex);
@JS('setMorphAnimationData')
external JSPromise setMorphAnimationData(
FilamentEntity entity,
JSArray<JSArray<JSNumber>> animation,
JSArray<JSString> morphTargets,
JSArray<JSString>? targetMeshNames,
double frameLengthInMs);
@JS('resetBones')
external JSPromise resetBones(FilamentEntity entity);
@JS('addBoneAnimation')
external JSPromise addBoneAnimation(
FilamentEntity entity,
JSArray<JSString> bones,
JSArray<JSArray<JSArray<JSNumber>>> frameData,
JSNumber frameLengthInMs,
JSNumber spaceEnum,
JSNumber skinIndex,
JSNumber fadeInInSecs,
JSNumber fadeOutInSecs,
JSNumber maxDelta);
@JS('removeEntity')
external JSPromise removeEntity(FilamentEntity entity);
@JS('clearEntities')
external JSPromise clearEntities();
@JS('zoomBegin')
external JSPromise zoomBegin();
@JS('zoomUpdate')
external JSPromise zoomUpdate(double x, double y, double z);
@JS('zoomEnd')
external JSPromise zoomEnd();
@JS('playAnimation')
external JSPromise playAnimation(
FilamentEntity entity,
int index,
bool loop,
bool reverse,
bool replaceActive,
double crossfade,
);
@JS('playAnimationByName')
external JSPromise playAnimationByName(
FilamentEntity entity,
String name,
bool loop,
bool reverse,
bool replaceActive,
double crossfade,
);
@JS('setAnimationFrame')
external JSPromise setAnimationFrame(
FilamentEntity entity, int index, int animationFrame);
@JS('stopAnimation')
external JSPromise stopAnimation(FilamentEntity entity, int animationIndex);
@JS('stopAnimationByName')
external JSPromise stopAnimationByName(FilamentEntity entity, String name);
@JS('setCamera')
external JSPromise setCamera(FilamentEntity entity, String? name);
@JS('setMainCamera')
external JSPromise setMainCamera();
@JS('getMainCamera')
external JSPromise<JSNumber> getMainCamera();
@JS('setCameraFov')
external JSPromise setCameraFov(double degrees, double width, double height);
@JS('setToneMapping')
external JSPromise setToneMapping(int mapper);
@JS('setBloom')
external JSPromise setBloom(double bloom);
@JS('setCameraFocalLength')
external JSPromise setCameraFocalLength(double focalLength);
@JS('setCameraCulling')
external JSPromise setCameraCulling(double near, double far);
@JS('getCameraCullingNear')
external JSPromise<JSNumber> getCameraCullingNear();
@JS('getCameraCullingFar')
external JSPromise<JSNumber> getCameraCullingFar();
@JS('setCameraFocusDistance')
external JSPromise setCameraFocusDistance(double focusDistance);
@JS('getCameraPosition')
external JSPromise<JSArray<JSNumber>> getCameraPosition();
@JS('getCameraModelMatrix')
external JSPromise<JSArray<JSNumber>> getCameraModelMatrix();
@JS('getCameraViewMatrix')
external JSPromise<JSArray<JSNumber>> getCameraViewMatrix();
@JS('getCameraProjectionMatrix')
external JSPromise<JSArray<JSNumber>> getCameraProjectionMatrix();
@JS('getCameraCullingProjectionMatrix')
external JSPromise<JSArray<JSNumber>> getCameraCullingProjectionMatrix();
@JS('getCameraFrustum')
external JSPromise<JSObject> getCameraFrustum();
@JS('setCameraPosition')
external JSPromise setCameraPosition(double x, double y, double z);
@JS('getCameraRotation')
external JSPromise<JSArray<JSNumber>> getCameraRotation();
@JS('moveCameraToAsset')
external JSPromise moveCameraToAsset(FilamentEntity entity);
@JS('setViewFrustumCulling')
external JSPromise setViewFrustumCulling(JSBoolean enabled);
@JS('setCameraExposure')
external JSPromise setCameraExposure(
double aperture, double shutterSpeed, double sensitivity);
@JS('setCameraRotation')
external JSPromise setCameraRotation(JSArray<JSNumber> quaternion);
@JS('setCameraModelMatrix')
external JSPromise setCameraModelMatrix(JSArray<JSNumber> matrix);
@JS('setMaterialColor')
external JSPromise setMaterialColor(FilamentEntity entity, String meshName,
int materialIndex, double r, double g, double b, double a);
@JS('transformToUnitCube')
external JSPromise transformToUnitCube(FilamentEntity entity);
@JS('setPosition')
external JSPromise setPosition(
FilamentEntity entity, double x, double y, double z);
@JS('setScale')
external JSPromise setScale(FilamentEntity entity, double scale);
@JS('setRotation')
external JSPromise setRotation(
FilamentEntity entity, double rads, double x, double y, double z);
@JS('queuePositionUpdate')
external JSPromise queuePositionUpdate(
FilamentEntity entity, double x, double y, double z, bool relative);
@JS('queueRotationUpdate')
external JSPromise queueRotationUpdate(FilamentEntity entity, double rads,
double x, double y, double z, bool relative);
@JS('queueRotationUpdateQuat')
external JSPromise queueRotationUpdateQuat(
FilamentEntity entity, JSArray<JSNumber> quat, bool relative);
@JS('setPostProcessing')
external JSPromise setPostProcessing(bool enabled);
@JS('setAntiAliasing')
external JSPromise setAntiAliasing(bool msaa, bool fxaa, bool taa);
@JS('setRotationQuat')
external JSPromise setRotationQuat(
FilamentEntity entity, JSArray<JSNumber> rotation);
@JS('reveal')
external JSPromise reveal(FilamentEntity entity, String? meshName);
@JS('hide')
external JSPromise hide(FilamentEntity entity, String? meshName);
@JS('pick')
external void pick(int x, int y);
@JS('getNameForEntity')
external String? getNameForEntity(FilamentEntity entity);
@JS('setCameraManipulatorOptions')
external JSPromise setCameraManipulatorOptions(
int mode,
double orbitSpeedX,
double orbitSpeedY,
double zoomSpeed,
);
@JS('getChildEntities')
external JSPromise<JSArray<JSNumber>> getChildEntities(
FilamentEntity parent, bool renderableOnly);
@JS('getChildEntity')
external JSPromise<JSNumber> getChildEntity(
FilamentEntity parent, String childName);
@JS('getChildEntityNames')
external JSPromise<JSArray<JSString>> getChildEntityNames(
FilamentEntity entity, bool renderableOnly);
@JS('setRecording')
external JSPromise setRecording(JSBoolean recording);
@JS('setRecordingOutputDirectory')
external JSPromise setRecordingOutputDirectory(String outputDirectory);
@JS('addAnimationComponent')
external JSPromise addAnimationComponent(FilamentEntity entity);
@JS('removeAnimationComponent')
external JSPromise removeAnimationComponent(FilamentEntity entity);
@JS('addCollisionComponent')
external JSPromise addCollisionComponent(FilamentEntity entity);
@JS('removeCollisionComponent')
external JSPromise removeCollisionComponent(FilamentEntity entity);
@JS('createGeometry')
external JSPromise<JSNumber> createGeometry(JSArray<JSNumber> vertices,
JSArray<JSNumber> indices, String? materialPath, int primitiveType);
@JS('setParent')
external JSPromise setParent(FilamentEntity child, FilamentEntity parent);
@JS('getParent')
external JSPromise<JSNumber> getParent(FilamentEntity child);
@JS('getParent')
external JSPromise<JSNumber> getBone(
FilamentEntity child, int boneIndex, int skinIndex);
@JS('testCollisions')
external JSPromise testCollisions(FilamentEntity entity);
@JS('setPriority')
external JSPromise setPriority(FilamentEntity entityId, int priority);
@JS('getLocalTransform')
external JSPromise<JSArray<JSNumber>> getLocalTransform(
FilamentEntity entity);
@JS('getWorldTransform')
external JSPromise<JSArray<JSNumber>> getWorldTransform(
FilamentEntity entity);
@JS('updateBoneMatrices')
external JSPromise updateBoneMatrices(FilamentEntity entity);
@JS('setTransform')
external JSPromise setTransform(
FilamentEntity entity, JSArray<JSNumber> transform);
@JS('setBoneTransform')
external JSPromise setBoneTransform(
FilamentEntity entity, int boneIndex, JSArray<JSNumber> transform, int skinIndex);
}