make all FFI calls async with completers

This commit is contained in:
Nick Fisher
2024-03-05 13:51:57 +08:00
parent 39fa9387e6
commit adfb607eb7
10 changed files with 598 additions and 346 deletions

View File

@@ -4,6 +4,7 @@ import 'dart:io';
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'dart:developer' as dev;
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:ffi/ffi.dart';
import 'package:flutter/widgets.dart';
@@ -140,7 +141,7 @@ class FilamentControllerFFI extends FilamentController {
Future setFrameRate(int framerate) async {
final interval = 1000.0 / framerate;
set_frame_interval_ffi(interval);
dev.log("Set frame interval to $interval");
print("Set frame interval to $interval");
}
@override
@@ -182,7 +183,82 @@ class FilamentControllerFFI extends FilamentController {
await _channel.invokeMethod(
"destroyTexture", textureDetails.value!.textureId);
}
dev.log("Texture destroyed");
print("Texture destroyed");
}
Future<void> _withVoidCallback(
Function(Pointer<NativeFunction<Void Function()>>) func) async {
final completer = Completer();
// ignore: prefer_function_declarations_over_variables
void Function() callback = () {
completer.complete();
};
final nativeCallable = NativeCallable<Void Function()>.listener(callback);
func.call(nativeCallable.nativeFunction);
await completer.future;
nativeCallable.close();
}
Future<Pointer<Void>> _withVoidPointerCallback(
Function(Pointer<NativeFunction<Void Function(Pointer<Void>)>>)
func) async {
final completer = Completer<Pointer<Void>>();
// ignore: prefer_function_declarations_over_variables
void Function(Pointer<Void>) callback = (Pointer<Void> ptr) {
completer.complete(ptr);
};
final nativeCallable =
NativeCallable<Void Function(Pointer<Void>)>.listener(callback);
func.call(nativeCallable.nativeFunction);
await completer.future;
nativeCallable.close();
return completer.future;
}
Future<bool> _withBoolCallback(
Function(Pointer<NativeFunction<Void Function(Bool)>>) func) async {
final completer = Completer<bool>();
// ignore: prefer_function_declarations_over_variables
void Function(bool) callback = (bool result) {
completer.complete(result);
};
final nativeCallable =
NativeCallable<Void Function(Bool)>.listener(callback);
func.call(nativeCallable.nativeFunction);
await completer.future;
nativeCallable.close();
return completer.future;
}
Future<int> _withIntCallback(
Function(Pointer<NativeFunction<Void Function(Int32)>>) func) async {
final completer = Completer<int>();
// ignore: prefer_function_declarations_over_variables
void Function(int) callback = (int result) {
completer.complete(result);
};
final nativeCallable =
NativeCallable<Void Function(Int32)>.listener(callback);
func.call(nativeCallable.nativeFunction);
await completer.future;
nativeCallable.close();
return completer.future;
}
Future<String> _withCharPtrCallback(
Function(Pointer<NativeFunction<Void Function(Pointer<Char>)>>)
func) async {
final completer = Completer<String>();
// ignore: prefer_function_declarations_over_variables
void Function(Pointer<Char>) callback = (Pointer<Char> result) {
completer.complete(result.cast<Utf8>().toDartString());
};
final nativeCallable =
NativeCallable<Void Function(Pointer<Char>)>.listener(callback);
func.call(nativeCallable.nativeFunction);
await completer.future;
nativeCallable.close();
return completer.future;
}
bool _creating = false;
@@ -190,6 +266,7 @@ class FilamentControllerFFI extends FilamentController {
///
/// Called by `FilamentWidget`. You do not need to call this yourself.
///
///
@override
Future createViewer() async {
if (_creating) {
@@ -234,43 +311,60 @@ class FilamentControllerFFI extends FilamentController {
var renderingSurface = await _createRenderingSurface();
dev.log("Got rendering surface");
print("Got rendering surface");
final uberarchivePtr =
uberArchivePath?.toNativeUtf8().cast<Char>() ?? nullptr;
_viewer = create_filament_viewer_ffi(
Pointer<Void>.fromAddress(renderingSurface.sharedContext),
_driver,
uberarchivePtr,
loader,
renderCallback,
renderCallbackOwner);
_viewer = await _withVoidPointerCallback((callback) =>
create_filament_viewer_ffi(
Pointer<Void>.fromAddress(renderingSurface.sharedContext),
_driver,
uberarchivePtr,
loader,
renderCallback,
renderCallbackOwner,
callback));
allocator.free(uberarchivePtr);
dev.log("Created viewer");
print("Created viewer ${_viewer!.address}");
if (_viewer!.address == 0) {
throw Exception("Failed to create viewer. Check logs for details");
}
_sceneManager = get_scene_manager(_viewer!);
create_swap_chain_ffi(_viewer!, renderingSurface.surface,
_rect.value!.width.toInt(), _rect.value!.height.toInt());
dev.log("Created swap chain");
await _withVoidCallback((callback) {
create_swap_chain_ffi(_viewer!, renderingSurface.surface,
_rect.value!.width.toInt(), _rect.value!.height.toInt(), callback);
});
print("Created swap chain");
if (renderingSurface.textureHandle != 0) {
dev.log(
print(
"Creating render target from native texture ${renderingSurface.textureHandle}");
create_render_target_ffi(_viewer!, renderingSurface.textureHandle,
_rect.value!.width.toInt(), _rect.value!.height.toInt());
await _withVoidCallback((callback) => create_render_target_ffi(
_viewer!,
renderingSurface.textureHandle,
_rect.value!.width.toInt(),
_rect.value!.height.toInt(),
callback));
}
textureDetails.value = TextureDetails(
textureId: renderingSurface.flutterTextureId,
width: _rect.value!.width.toInt(),
height: _rect.value!.height.toInt());
dev.log("texture details ${textureDetails.value}");
update_viewport_and_camera_projection_ffi(
_viewer!, _rect.value!.width.toInt(), _rect.value!.height.toInt(), 1.0);
print("texture details ${textureDetails.value}");
await _withVoidCallback((callback) {
update_viewport_and_camera_projection_ffi(
_viewer!,
_rect.value!.width.toInt(),
_rect.value!.height.toInt(),
1.0,
callback);
});
hasViewer.value = true;
_creating = false;
}
@@ -365,7 +459,8 @@ class FilamentControllerFFI extends FilamentController {
set_rendering_ffi(_viewer!, false);
if (!_usesBackingWindow) {
destroy_swap_chain_ffi(_viewer!);
await _withVoidCallback(
(callback) => destroy_swap_chain_ffi(_viewer!, callback));
}
if (requiresTextureWidget) {
@@ -374,7 +469,7 @@ class FilamentControllerFFI extends FilamentController {
"destroyTexture", textureDetails.value!.textureId);
}
} else if (Platform.isWindows) {
dev.log("Resizing window with rect ${_rect.value}");
print("Resizing window with rect ${_rect.value}");
await _channel.invokeMethod("resizeWindow", [
_rect.value!.width,
_rect.value!.height,
@@ -390,15 +485,23 @@ class FilamentControllerFFI extends FilamentController {
}
if (!_usesBackingWindow) {
create_swap_chain_ffi(_viewer!, renderingSurface.surface,
_rect.value!.width.toInt(), _rect.value!.height.toInt());
_withVoidCallback((callback) => create_swap_chain_ffi(
_viewer!,
renderingSurface.surface,
_rect.value!.width.toInt(),
_rect.value!.height.toInt(),
callback));
}
if (renderingSurface.textureHandle != 0) {
dev.log(
print(
"Creating render target from native texture ${renderingSurface.textureHandle}");
create_render_target_ffi(_viewer!, renderingSurface.textureHandle,
_rect.value!.width.toInt(), _rect.value!.height.toInt());
_withVoidCallback((callback) => create_render_target_ffi(
_viewer!,
renderingSurface.textureHandle,
_rect.value!.width.toInt(),
_rect.value!.height.toInt(),
callback));
}
textureDetails.value = TextureDetails(
@@ -406,8 +509,12 @@ class FilamentControllerFFI extends FilamentController {
width: _rect.value!.width.toInt(),
height: _rect.value!.height.toInt());
update_viewport_and_camera_projection_ffi(_viewer!,
_rect.value!.width.toInt(), _rect.value!.height.toInt(), 1.0);
_withVoidCallback((callback) => update_viewport_and_camera_projection_ffi(
_viewer!,
_rect.value!.width.toInt(),
_rect.value!.height.toInt(),
1.0,
callback));
await setRendering(_rendering);
} finally {
@@ -518,8 +625,19 @@ class FilamentControllerFFI extends FilamentController {
if (_viewer == null) {
throw Exception("No viewer available, ignoring");
}
var entity = add_light_ffi(_viewer!, type, colour, intensity, posX, posY,
posZ, dirX, dirY, dirZ, castShadows);
var entity = await _withIntCallback((callback) => add_light_ffi(
_viewer!,
type,
colour,
intensity,
posX,
posY,
posZ,
dirX,
dirY,
dirZ,
castShadows,
callback));
_onLoadController.sink.add(entity);
_lights.add(entity);
return entity;
@@ -572,8 +690,8 @@ class FilamentControllerFFI extends FilamentController {
data = (ptr.cast<Void>(), asset.lengthInBytes);
}
var entity = load_glb_from_buffer_ffi(
_sceneManager!, data.$1, data.$2, numInstances);
var entity = await _withIntCallback((callback) => load_glb_from_buffer_ffi(
_sceneManager!, data.$1, data.$2, numInstances, callback));
if (!cache) {
allocator.free(data.$1);
} else {
@@ -587,7 +705,8 @@ class FilamentControllerFFI extends FilamentController {
@override
Future<FilamentEntity> createInstance(FilamentEntity entity) async {
var created = create_instance(_sceneManager!, entity);
var created = await _withIntCallback(
(callback) => create_instance(_sceneManager!, entity));
if (created == _FILAMENT_ASSET_ERROR) {
throw Exception("Failed to create instance");
}
@@ -630,7 +749,8 @@ class FilamentControllerFFI extends FilamentController {
throw Exception("Not yet implemented");
}
final pathPtr = path.toNativeUtf8().cast<Char>();
var entity = load_glb_ffi(_sceneManager!, pathPtr, numInstances);
var entity = await _withIntCallback((callback) =>
load_glb_ffi(_sceneManager!, pathPtr, numInstances, callback));
allocator.free(pathPtr);
if (entity == _FILAMENT_ASSET_ERROR) {
throw Exception("An error occurred loading the asset at $path");
@@ -653,8 +773,8 @@ class FilamentControllerFFI extends FilamentController {
final pathPtr = path.toNativeUtf8().cast<Char>();
final relativeResourcePathPtr =
relativeResourcePath.toNativeUtf8().cast<Char>();
var entity =
load_gltf_ffi(_sceneManager!, pathPtr, relativeResourcePathPtr);
var entity = await _withIntCallback((callback) => load_gltf_ffi(
_sceneManager!, pathPtr, relativeResourcePathPtr, callback));
allocator.free(pathPtr);
allocator.free(relativeResourcePathPtr);
if (entity == _FILAMENT_ASSET_ERROR) {
@@ -739,8 +859,9 @@ class FilamentControllerFFI extends FilamentController {
}
var names = <String>[];
var meshNamePtr = meshName.toNativeUtf8().cast<Char>();
var count =
get_morph_target_name_count_ffi(_sceneManager!, entity, meshNamePtr);
var count = await _withIntCallback((callback) =>
get_morph_target_name_count_ffi(
_sceneManager!, entity, meshNamePtr, callback));
var outPtr = allocator<Char>(255);
for (int i = 0; i < count; i++) {
get_morph_target_name(_sceneManager!, entity, meshNamePtr, outPtr, i);
@@ -760,9 +881,11 @@ class FilamentControllerFFI extends FilamentController {
var names = <String>[];
var outPtr = allocator<Char>(255);
for (int i = 0; i < animationCount; i++) {
get_animation_name_ffi(_sceneManager!, entity, outPtr, i);
await _withVoidCallback((callback) =>
get_animation_name_ffi(_sceneManager!, entity, outPtr, i, callback));
names.add(outPtr.cast<Utf8>().toDartString());
}
allocator.free(outPtr);
return names;
}
@@ -896,7 +1019,8 @@ class FilamentControllerFFI extends FilamentController {
throw Exception("No viewer available, ignoring");
}
_entities.remove(entity);
remove_entity_ffi(_viewer!, entity);
await _withVoidCallback(
(callback) => remove_entity_ffi(_viewer!, entity, callback));
_onUnloadController.add(entity);
}
@@ -905,7 +1029,8 @@ class FilamentControllerFFI extends FilamentController {
if (_viewer == null) {
throw Exception("No viewer available, ignoring");
}
clear_entities_ffi(_viewer!);
await _withVoidCallback(
(callback) => clear_entities_ffi(_viewer!, callback));
for (final entity in _entities) {
_onUnloadController.add(entity);
@@ -1537,8 +1662,14 @@ class FilamentControllerFFI extends FilamentController {
indicesPtr.elementAt(i).value = indices[i];
}
var entity = create_geometry_ffi(_viewer!, vertexPtr, vertices.length,
indicesPtr, indices.length, materialPathPtr.cast<Char>());
var entity = await _withIntCallback((callback) => create_geometry_ffi(
_viewer!,
vertexPtr,
vertices.length,
indicesPtr,
indices.length,
materialPathPtr.cast<Char>(),
callback));
if (entity == _FILAMENT_ASSET_ERROR) {
throw Exception("Failed to create geometry");
}

View File

@@ -984,7 +984,10 @@ external void test_collisions(
ffi.NativeFunction<
ffi.Void Function(
ffi.Pointer<ffi.Void> renderCallbackOwner)>>,
ffi.Pointer<ffi.Void>)>(
ffi.Pointer<ffi.Void>,
ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(ffi.Pointer<ffi.Void> viewer)>>)>(
symbol: 'create_filament_viewer_ffi', assetId: 'flutter_filament_plugin')
external ffi.Pointer<ffi.Void> create_filament_viewer_ffi(
ffi.Pointer<ffi.Void> context,
@@ -996,34 +999,46 @@ external ffi.Pointer<ffi.Void> create_filament_viewer_ffi(
ffi.Void Function(ffi.Pointer<ffi.Void> renderCallbackOwner)>>
renderCallback,
ffi.Pointer<ffi.Void> renderCallbackOwner,
ffi.Pointer<
ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void> viewer)>>
callback,
);
@ffi.Native<
ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Void>,
ffi.Uint32, ffi.Uint32)>(
ffi.Void Function(
ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.Void>,
ffi.Uint32,
ffi.Uint32,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(
symbol: 'create_swap_chain_ffi', assetId: 'flutter_filament_plugin')
external void create_swap_chain_ffi(
ffi.Pointer<ffi.Void> viewer,
ffi.Pointer<ffi.Void> surface,
int width,
int height,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(
symbol: 'destroy_swap_chain_ffi', assetId: 'flutter_filament_plugin')
external void destroy_swap_chain_ffi(
ffi.Pointer<ffi.Void> viewer,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<ffi.Void>, ffi.IntPtr, ffi.Uint32, ffi.Uint32)>(
ffi.Void Function(ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(
symbol: 'destroy_swap_chain_ffi', assetId: 'flutter_filament_plugin')
external void destroy_swap_chain_ffi(
ffi.Pointer<ffi.Void> viewer,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
);
@ffi.Native<
ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.IntPtr, ffi.Uint32,
ffi.Uint32, ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(
symbol: 'create_render_target_ffi', assetId: 'flutter_filament_plugin')
external void create_render_target_ffi(
ffi.Pointer<ffi.Void> viewer,
int nativeTextureId,
int width,
int height,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(
@@ -1059,8 +1074,8 @@ external void set_frame_interval_ffi(
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<ffi.Void>, ffi.Uint32, ffi.Uint32, ffi.Float)>(
ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Uint32, ffi.Uint32,
ffi.Float, ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(
symbol: 'update_viewport_and_camera_projection_ffi',
assetId: 'flutter_filament_plugin')
external void update_viewport_and_camera_projection_ffi(
@@ -1068,6 +1083,7 @@ external void update_viewport_and_camera_projection_ffi(
int width,
int height,
double scaleFactor,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
);
@ffi.Native<
@@ -1153,19 +1169,21 @@ external void remove_ibl_ffi(
);
@ffi.Native<
EntityId Function(
ffi.Pointer<ffi.Void>,
ffi.Uint8,
ffi.Float,
ffi.Float,
ffi.Float,
ffi.Float,
ffi.Float,
ffi.Float,
ffi.Float,
ffi.Float,
ffi.Bool)>(symbol: 'add_light_ffi', assetId: 'flutter_filament_plugin')
external int add_light_ffi(
ffi.Void Function(
ffi.Pointer<ffi.Void>,
ffi.Uint8,
ffi.Float,
ffi.Float,
ffi.Float,
ffi.Float,
ffi.Float,
ffi.Float,
ffi.Float,
ffi.Float,
ffi.Bool,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>>)>(
symbol: 'add_light_ffi', assetId: 'flutter_filament_plugin')
external void add_light_ffi(
ffi.Pointer<ffi.Void> viewer,
int type,
double colour,
@@ -1177,6 +1195,7 @@ external int add_light_ffi(
double dirY,
double dirZ,
bool shadows,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>> callback,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId)>(
@@ -1193,63 +1212,87 @@ external void clear_lights_ffi(
);
@ffi.Native<
EntityId Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Char>,
ffi.Int)>(symbol: 'load_glb_ffi', assetId: 'flutter_filament_plugin')
external int load_glb_ffi(
ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Char>, ffi.Int,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>>)>(
symbol: 'load_glb_ffi', assetId: 'flutter_filament_plugin')
external void load_glb_ffi(
ffi.Pointer<ffi.Void> sceneManager,
ffi.Pointer<ffi.Char> assetPath,
int numInstances,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>> callback,
);
@ffi.Native<
EntityId Function(
ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Void>, ffi.Size, ffi.Int)>(
ffi.Void Function(
ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.Void>,
ffi.Size,
ffi.Int,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>>)>(
symbol: 'load_glb_from_buffer_ffi', assetId: 'flutter_filament_plugin')
external int load_glb_from_buffer_ffi(
external void load_glb_from_buffer_ffi(
ffi.Pointer<ffi.Void> sceneManager,
ffi.Pointer<ffi.Void> data,
int length,
int numInstances,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>> callback,
);
@ffi.Native<
EntityId Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.Char>)>(
ffi.Void Function(
ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>>)>(
symbol: 'load_gltf_ffi', assetId: 'flutter_filament_plugin')
external int load_gltf_ffi(
external void load_gltf_ffi(
ffi.Pointer<ffi.Void> sceneManager,
ffi.Pointer<ffi.Char> assetPath,
ffi.Pointer<ffi.Char> relativePath,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>> callback,
);
@ffi.Native<EntityId Function(ffi.Pointer<ffi.Void>, EntityId)>(
@ffi.Native<
ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>>)>(
symbol: 'create_instance_ffi', assetId: 'flutter_filament_plugin')
external int create_instance_ffi(
external void create_instance_ffi(
ffi.Pointer<ffi.Void> sceneManager,
int entityId,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>> callback,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId)>(
@ffi.Native<
ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(
symbol: 'remove_entity_ffi', assetId: 'flutter_filament_plugin')
external void remove_entity_ffi(
ffi.Pointer<ffi.Void> viewer,
int asset,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(
@ffi.Native<
ffi.Void Function(ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(
symbol: 'clear_entities_ffi', assetId: 'flutter_filament_plugin')
external void clear_entities_ffi(
ffi.Pointer<ffi.Void> viewer,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
);
@ffi.Native<
ffi.Bool Function(
ffi.Pointer<ffi.Void>, EntityId, ffi.Pointer<ffi.Char>)>(
ffi.Pointer<ffi.Void>,
EntityId,
ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(
symbol: 'set_camera_ffi', assetId: 'flutter_filament_plugin')
external bool set_camera_ffi(
ffi.Pointer<ffi.Void> viewer,
int asset,
ffi.Pointer<ffi.Char> nodeName,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
);
@ffi.Native<
@@ -1296,27 +1339,40 @@ external void stop_animation_ffi(
int index,
);
@ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>, EntityId)>(
@ffi.Native<
ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Int)>>)>(
symbol: 'get_animation_count_ffi', assetId: 'flutter_filament_plugin')
external int get_animation_count_ffi(
external void get_animation_count_ffi(
ffi.Pointer<ffi.Void> sceneManager,
int asset,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Int)>> callback,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<ffi.Void>, EntityId, ffi.Pointer<ffi.Char>, ffi.Int)>(
ffi.Pointer<ffi.Void>,
EntityId,
ffi.Pointer<ffi.Char>,
ffi.Int,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(
symbol: 'get_animation_name_ffi', assetId: 'flutter_filament_plugin')
external void get_animation_name_ffi(
ffi.Pointer<ffi.Void> sceneManager,
int asset,
ffi.Pointer<ffi.Char> outPtr,
int index,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
);
@ffi.Native<
ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId,
ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Char>, ffi.Int)>(
ffi.Void Function(
ffi.Pointer<ffi.Void>,
EntityId,
ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.Char>,
ffi.Int,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(
symbol: 'get_morph_target_name_ffi', assetId: 'flutter_filament_plugin')
external void get_morph_target_name_ffi(
ffi.Pointer<ffi.Void> sceneManager,
@@ -1324,17 +1380,22 @@ external void get_morph_target_name_ffi(
ffi.Pointer<ffi.Char> meshName,
ffi.Pointer<ffi.Char> outPtr,
int index,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
);
@ffi.Native<
ffi.Int Function(
ffi.Pointer<ffi.Void>, EntityId, ffi.Pointer<ffi.Char>)>(
ffi.Void Function(
ffi.Pointer<ffi.Void>,
EntityId,
ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Int32)>>)>(
symbol: 'get_morph_target_name_count_ffi',
assetId: 'flutter_filament_plugin')
external int get_morph_target_name_count_ffi(
external void get_morph_target_name_count_ffi(
ffi.Pointer<ffi.Void> sceneManager,
int asset,
ffi.Pointer<ffi.Char> meshName,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Int32)>> callback,
);
@ffi.Native<
@@ -1350,7 +1411,7 @@ external void set_morph_target_weights_ffi(
);
@ffi.Native<
ffi.Bool Function(
ffi.Void Function(
ffi.Pointer<ffi.Void>,
EntityId,
ffi.Pointer<ffi.Char>,
@@ -1358,9 +1419,10 @@ external void set_morph_target_weights_ffi(
ffi.Pointer<ffi.Int>,
ffi.Int,
ffi.Int,
ffi.Float)>(
ffi.Float,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Bool)>>)>(
symbol: 'set_morph_animation_ffi', assetId: 'flutter_filament_plugin')
external bool set_morph_animation_ffi(
external void set_morph_animation_ffi(
ffi.Pointer<ffi.Void> sceneManager,
int asset,
ffi.Pointer<ffi.Char> entityName,
@@ -1369,22 +1431,25 @@ external bool set_morph_animation_ffi(
int numMorphTargets,
int numFrames,
double frameLengthInMs,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Bool)>> callback,
);
@ffi.Native<
ffi.Bool Function(
ffi.Void Function(
ffi.Pointer<ffi.Void>,
EntityId,
ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.Float>,
ffi.Pointer<ffi.Char>)>(
ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Bool)>>)>(
symbol: 'set_bone_transform_ffi', assetId: 'flutter_filament_plugin')
external bool set_bone_transform_ffi(
external void set_bone_transform_ffi(
ffi.Pointer<ffi.Void> sceneManager,
int asset,
ffi.Pointer<ffi.Char> entityName,
ffi.Pointer<ffi.Float> transform,
ffi.Pointer<ffi.Char> boneName,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Bool)>> callback,
);
@ffi.Native<
@@ -1441,16 +1506,23 @@ external void reset_to_rest_pose_ffi(
external void ios_dummy_ffi();
@ffi.Native<
EntityId Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Float>,
ffi.Int, ffi.Pointer<ffi.Uint16>, ffi.Int, ffi.Pointer<ffi.Char>)>(
ffi.Void Function(
ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.Float>,
ffi.Int,
ffi.Pointer<ffi.Uint16>,
ffi.Int,
ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>>)>(
symbol: 'create_geometry_ffi', assetId: 'flutter_filament_plugin')
external int create_geometry_ffi(
external void create_geometry_ffi(
ffi.Pointer<ffi.Void> viewer,
ffi.Pointer<ffi.Float> vertices,
int numVertices,
ffi.Pointer<ffi.Uint16> indices,
int numIndices,
ffi.Pointer<ffi.Char> materialPath,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>> callback,
);
final class __mbstate_t extends ffi.Union {

View File

@@ -124,15 +124,20 @@ class _FilamentGestureDetectorMobileState
double _lastScale = 0;
// pinch zoom on mobile
// couldn't find any equivalent for pointerCount in Listener so we use two widgets:
// - outer is a GestureDetector only for pinch zoom
// - inner is a Listener for all other gestures (including scroll zoom on desktop)
// couldn't find any equivalent for pointerCount in Listener (?) so we use a GestureDetector
@override
Widget build(BuildContext context) {
return Stack(children: [
Positioned.fill(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
behavior: HitTestBehavior.translucent,
onTapDown: (d) {
if (widget.enablePicking) {
print("PICK");
widget.controller.pick(
d.globalPosition.dx.toInt(), d.globalPosition.dy.toInt());
}
},
onDoubleTap: () {
setState(() {
_rotateOnPointerMove = !_rotateOnPointerMove;