add option for async loading glTF resources

This commit is contained in:
Nick Fisher
2024-10-10 14:58:09 +08:00
parent 9deafc7371
commit 95a44936ac
9 changed files with 37 additions and 19 deletions

View File

@@ -652,7 +652,7 @@ external ffi.Pointer<TScene> SceneManager_getScene(
@ffi.Native<
EntityId Function(ffi.Pointer<TSceneManager>, ffi.Pointer<ffi.Uint8>,
ffi.Size, ffi.Bool, ffi.Int, ffi.Int)>(isLeaf: true)
ffi.Size, ffi.Bool, ffi.Int, ffi.Int, ffi.Bool)>(isLeaf: true)
external int SceneManager_loadGlbFromBuffer(
ffi.Pointer<TSceneManager> sceneManager,
ffi.Pointer<ffi.Uint8> arg1,
@@ -660,6 +660,7 @@ external int SceneManager_loadGlbFromBuffer(
bool keepData,
int priority,
int layer,
bool loadResourcesAsync,
);
@ffi.Native<
@@ -1515,6 +1516,7 @@ external void remove_skybox_render_thread(
ffi.Bool,
ffi.Int,
ffi.Int,
ffi.Bool,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>>)>(
isLeaf: true)
external void SceneManager_loadGlbFromBufferRenderThread(
@@ -1525,6 +1527,7 @@ external void SceneManager_loadGlbFromBufferRenderThread(
bool keepData,
int priority,
int layer,
bool loadResourcesAsync,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>> callback,
);

View File

@@ -5,8 +5,8 @@ import 'package:animation_tools_dart/animation_tools_dart.dart';
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_gizmo.dart';
import 'package:vector_math/vector_math_64.dart';
import 'package:vector_math/vector_math_64.dart' as v64;
import '../../../../utils/gizmo.dart';
import '../../../../utils/matrix.dart';
import '../../../../utils/src/gizmo.dart';
import '../../../../utils/src/matrix.dart';
import '../../events.dart';
import '../../shared_types/view.dart';
import '../../thermion_viewer_base.dart';
@@ -546,7 +546,7 @@ class ThermionViewerFFI extends ThermionViewer {
int numInstances = 1,
bool keepData = false,
int priority = 4,
int layer = 0}) async {
int layer = 0, bool loadResourcesAsync=false}) async {
if (unlit) {
throw Exception("Not yet implemented");
}
@@ -557,7 +557,7 @@ class ThermionViewerFFI extends ThermionViewer {
var entity = await withIntCallback((callback) =>
SceneManager_loadGlbFromBufferRenderThread(_sceneManager!, data.address,
data.length, numInstances, keepData, priority, layer, callback));
data.length, numInstances, keepData, priority, layer, loadResourcesAsync, callback));
if (entity == _FILAMENT_ASSET_ERROR) {
throw Exception("An error occurred loading GLB from buffer");

View File

@@ -1,5 +1,5 @@
import 'package:thermion_dart/src/viewer/src/events.dart';
import '../../utils/gizmo.dart';
import '../../utils/src/gizmo.dart';
import 'shared_types/shared_types.dart';
export 'shared_types/shared_types.dart';
@@ -56,8 +56,10 @@ abstract class ThermionViewer {
///
/// Render a single frame and copy the pixel buffer to [out].
///
Future<Uint8List> capture({covariant SwapChain? swapChain,
covariant View? view, covariant RenderTarget? renderTarget});
Future<Uint8List> capture(
{covariant SwapChain? swapChain,
covariant View? view,
covariant RenderTarget? renderTarget});
///
///
@@ -214,12 +216,16 @@ abstract class ThermionViewer {
/// Specify [numInstances] to create multiple instances (this is more efficient than dynamically instantating at a later time). You can then retrieve the created instances with [getInstances].
/// If you want to be able to call [createInstance] at a later time, you must pass true for [keepData].
/// If [keepData] is false, the source glTF data will be released and [createInstance] will throw an exception.
/// If [loadResourcesAsync] is true, resources (textures, materials, etc) will
/// be loaded asynchronously (so expect some material/texture pop-in);
///
///
Future<ThermionEntity> loadGlbFromBuffer(Uint8List data,
{int numInstances = 1,
bool keepData = false,
int priority = 4,
int layer = 0});
int layer = 0,
bool loadResourcesAsync});
///
/// Create a new instance of [entity].