From ee306549d87789d76c22a2294a88e0dec1e4f960 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Sat, 17 May 2025 21:51:51 +0800 Subject: [PATCH] rename relativeResourcePath to resourceUri move resource loader from viewer to FilamentApp --- .../src/implementation/ffi_filament_app.dart | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/thermion_dart/lib/src/filament/src/implementation/ffi_filament_app.dart b/thermion_dart/lib/src/filament/src/implementation/ffi_filament_app.dart index 2379b81e..df15d17e 100644 --- a/thermion_dart/lib/src/filament/src/implementation/ffi_filament_app.dart +++ b/thermion_dart/lib/src/filament/src/implementation/ffi_filament_app.dart @@ -17,7 +17,7 @@ typedef RenderCallback = Pointer)>>; class FFIFilamentConfig extends FilamentConfig> { FFIFilamentConfig( - {super.resourceLoader = null, + {super.loadResource = null, super.backend = Backend.DEFAULT, super.platform = null, super.sharedContext = null, @@ -35,7 +35,7 @@ class FFIFilamentApp extends FilamentApp { final Pointer renderTicker; final Pointer nameComponentManager; - late final Future Function(String uri) resourceLoader; + late final Future Function(String uri) _loadResource; static final _logger = Logger("FFIFilamentApp"); @@ -49,7 +49,7 @@ class FFIFilamentApp extends FilamentApp { this.ubershaderMaterialProvider, this.renderTicker, this.nameComponentManager, - Future Function(String uri)? resourceLoader) + Future Function(String uri)? loadResource) : super( engine: engine, gltfAssetLoader: gltfAssetLoader, @@ -58,7 +58,11 @@ class FFIFilamentApp extends FilamentApp { lightManager: lightManager, renderableManager: renderableManager, ubershaderMaterialProvider: ubershaderMaterialProvider) { - this.resourceLoader = resourceLoader ?? defaultResourceLoader; + this._loadResource = loadResource ?? defaultResourceLoader; + } + + Future loadResource(String uri) { + return _loadResource(uri); } static Future create({FFIFilamentConfig? config}) async { @@ -107,7 +111,7 @@ class FFIFilamentApp extends FilamentApp { ubershaderMaterialProvider, renderTicker, nameComponentManager, - config.resourceLoader); + config.loadResource); _logger.info("Initialization complete"); } @@ -782,9 +786,13 @@ class FFIFilamentApp extends FilamentApp { bool keepData = false, int priority = 4, int layer = 0, - String? relativeResourcePath, - bool loadResourcesAsync = false}) async { + bool loadResourcesAsync = false, + String? resourceUri}) async { final resources = []; + + if (resourceUri != null && !resourceUri.endsWith("/")) { + resourceUri = "${resourceUri}/"; + } try { late Pointer stackPtr; if (FILAMENT_WASM) { @@ -793,14 +801,8 @@ class FFIFilamentApp extends FilamentApp { loadResourcesAsync = FILAMENT_SINGLE_THREADED; - if (relativeResourcePath != null && !relativeResourcePath.endsWith("/")) { - relativeResourcePath = "$relativeResourcePath/"; - } var gltfResourceLoader = await withPointerCallback( - (cb) => GltfResourceLoader_createRenderThread( - engine, - relativeResourcePath?.toNativeUtf8().cast() ?? nullptr, - cb)); + (cb) => GltfResourceLoader_createRenderThread(engine, cb)); var filamentAsset = await withPointerCallback((cb) => GltfAssetLoader_loadRenderThread(engine, gltfAssetLoader, @@ -815,9 +817,9 @@ class FFIFilamentApp extends FilamentApp { for (int i = 0; i < resourceUriCount; i++) { final resourceUriDart = resourceUris[i].cast().toDartString(); - final resourceData = await resourceLoader(relativeResourcePath == null - ? resourceUriDart - : "$relativeResourcePath/$resourceUriDart"); + + final resourceData = + await loadResource("${resourceUri ?? ""}${resourceUriDart}"); resources.add(FinalizableUint8List(resourceUris[i], resourceData)); @@ -829,6 +831,7 @@ class FFIFilamentApp extends FilamentApp { resourceData.lengthInBytes, cb)); } + if (loadResourcesAsync) { final result = await withBoolCallback((cb) => GltfResourceLoader_asyncBeginLoadRenderThread(