From f816274fb94f2a75eb3f7dc7d2f44ca8aedaa00d Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Fri, 20 Sep 2024 14:06:42 +0800 Subject: [PATCH] replace some async methods with futures, fix setMaterialProperty4, update unproject, setMaterialPropertyInt, createUnlitMaterialInstance --- .../viewer/ffi/thermion_viewer_ffi.dart | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/thermion_dart/lib/thermion_dart/viewer/ffi/thermion_viewer_ffi.dart b/thermion_dart/lib/thermion_dart/viewer/ffi/thermion_viewer_ffi.dart index c52c9129..cd2109f2 100644 --- a/thermion_dart/lib/thermion_dart/viewer/ffi/thermion_viewer_ffi.dart +++ b/thermion_dart/lib/thermion_dart/viewer/ffi/thermion_viewer_ffi.dart @@ -1147,8 +1147,8 @@ class ThermionViewerFFI extends ThermionViewer { set_main_camera(_viewer!); } - Future getMainCamera() async { - return get_main_camera(_viewer!); + Future getMainCamera() { + return Future.value(get_main_camera(_viewer!)); } /// @@ -1290,7 +1290,7 @@ class ThermionViewerFFI extends ThermionViewer { Future setCameraPosition(double x, double y, double z) async { var modelMatrix = await getCameraModelMatrix(); modelMatrix.setTranslation(Vector3(x, y, z)); - await setCameraModelMatrix4(modelMatrix); + return setCameraModelMatrix4(modelMatrix); } /// @@ -1965,22 +1965,22 @@ class ThermionViewerFFI extends ThermionViewer { Future setMaterialPropertyFloat4(ThermionEntity entity, String propertyName, int materialIndex, double f1, double f2, double f3, double f4) async { final ptr = propertyName.toNativeUtf8(allocator: allocator); - var struct = Struct.create(); + var struct = Struct.create(); struct.x = f1; struct.y = f2; struct.z = f3; - struct.w = f3; + struct.w = f4; set_material_property_float4( _sceneManager!, entity, materialIndex, ptr.cast(), struct); allocator.free(ptr); } - Future unproject( - ThermionEntity entity, Uint8List input, int inputWidth, int inputHeight, int outWidth, int outHeight) async { + Future unproject(ThermionEntity entity, Uint8List input, + int inputWidth, int inputHeight, int outWidth, int outHeight) async { final outPtr = Uint8List(outWidth * outHeight * 4); await withVoidCallback((callback) { - unproject_texture_ffi( - _viewer!, entity, input.address, inputWidth, inputHeight, outPtr.address, outWidth, outHeight, callback); + unproject_texture_ffi(_viewer!, entity, input.address, inputWidth, + inputHeight, outPtr.address, outWidth, outHeight, callback); }); return outPtr.buffer.asUint8List(); @@ -2098,6 +2098,24 @@ class ThermionViewerFFI extends ThermionViewer { ThermionFFIMaterialInstance materialInstance) async { destroy_material_instance(_sceneManager!, materialInstance._pointer); } + + Future createUnlitMaterialInstance() async { + var instance = create_unlit_material_instance(_sceneManager!); + if (instance == nullptr) { + throw Exception("Failed to create material instance"); + } + return ThermionFFIMaterialInstance(instance); + } + + @override + Future setMaterialPropertyInt(ThermionEntity entity, String propertyName, + int materialIndex, int value) { + final ptr = propertyName.toNativeUtf8(allocator: allocator); + set_material_property_int( + _sceneManager!, entity, materialIndex, ptr.cast(), value); + allocator.free(ptr); + return Future.value(); + } } class ThermionFFITexture extends ThermionTexture {