add option for async loading glTF resources
This commit is contained in:
@@ -652,7 +652,7 @@ external ffi.Pointer<TScene> SceneManager_getScene(
|
|||||||
|
|
||||||
@ffi.Native<
|
@ffi.Native<
|
||||||
EntityId Function(ffi.Pointer<TSceneManager>, ffi.Pointer<ffi.Uint8>,
|
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(
|
external int SceneManager_loadGlbFromBuffer(
|
||||||
ffi.Pointer<TSceneManager> sceneManager,
|
ffi.Pointer<TSceneManager> sceneManager,
|
||||||
ffi.Pointer<ffi.Uint8> arg1,
|
ffi.Pointer<ffi.Uint8> arg1,
|
||||||
@@ -660,6 +660,7 @@ external int SceneManager_loadGlbFromBuffer(
|
|||||||
bool keepData,
|
bool keepData,
|
||||||
int priority,
|
int priority,
|
||||||
int layer,
|
int layer,
|
||||||
|
bool loadResourcesAsync,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ffi.Native<
|
@ffi.Native<
|
||||||
@@ -1515,6 +1516,7 @@ external void remove_skybox_render_thread(
|
|||||||
ffi.Bool,
|
ffi.Bool,
|
||||||
ffi.Int,
|
ffi.Int,
|
||||||
ffi.Int,
|
ffi.Int,
|
||||||
|
ffi.Bool,
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>>)>(
|
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>>)>(
|
||||||
isLeaf: true)
|
isLeaf: true)
|
||||||
external void SceneManager_loadGlbFromBufferRenderThread(
|
external void SceneManager_loadGlbFromBufferRenderThread(
|
||||||
@@ -1525,6 +1527,7 @@ external void SceneManager_loadGlbFromBufferRenderThread(
|
|||||||
bool keepData,
|
bool keepData,
|
||||||
int priority,
|
int priority,
|
||||||
int layer,
|
int layer,
|
||||||
|
bool loadResourcesAsync,
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>> callback,
|
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>> callback,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -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: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';
|
||||||
import 'package:vector_math/vector_math_64.dart' as v64;
|
import 'package:vector_math/vector_math_64.dart' as v64;
|
||||||
import '../../../../utils/gizmo.dart';
|
import '../../../../utils/src/gizmo.dart';
|
||||||
import '../../../../utils/matrix.dart';
|
import '../../../../utils/src/matrix.dart';
|
||||||
import '../../events.dart';
|
import '../../events.dart';
|
||||||
import '../../shared_types/view.dart';
|
import '../../shared_types/view.dart';
|
||||||
import '../../thermion_viewer_base.dart';
|
import '../../thermion_viewer_base.dart';
|
||||||
@@ -546,7 +546,7 @@ class ThermionViewerFFI extends ThermionViewer {
|
|||||||
int numInstances = 1,
|
int numInstances = 1,
|
||||||
bool keepData = false,
|
bool keepData = false,
|
||||||
int priority = 4,
|
int priority = 4,
|
||||||
int layer = 0}) async {
|
int layer = 0, bool loadResourcesAsync=false}) async {
|
||||||
if (unlit) {
|
if (unlit) {
|
||||||
throw Exception("Not yet implemented");
|
throw Exception("Not yet implemented");
|
||||||
}
|
}
|
||||||
@@ -557,7 +557,7 @@ class ThermionViewerFFI extends ThermionViewer {
|
|||||||
|
|
||||||
var entity = await withIntCallback((callback) =>
|
var entity = await withIntCallback((callback) =>
|
||||||
SceneManager_loadGlbFromBufferRenderThread(_sceneManager!, data.address,
|
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) {
|
if (entity == _FILAMENT_ASSET_ERROR) {
|
||||||
throw Exception("An error occurred loading GLB from buffer");
|
throw Exception("An error occurred loading GLB from buffer");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:thermion_dart/src/viewer/src/events.dart';
|
import 'package:thermion_dart/src/viewer/src/events.dart';
|
||||||
import '../../utils/gizmo.dart';
|
import '../../utils/src/gizmo.dart';
|
||||||
import 'shared_types/shared_types.dart';
|
import 'shared_types/shared_types.dart';
|
||||||
export '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].
|
/// Render a single frame and copy the pixel buffer to [out].
|
||||||
///
|
///
|
||||||
Future<Uint8List> capture({covariant SwapChain? swapChain,
|
Future<Uint8List> capture(
|
||||||
covariant View? view, covariant RenderTarget? renderTarget});
|
{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].
|
/// 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 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 [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,
|
Future<ThermionEntity> loadGlbFromBuffer(Uint8List data,
|
||||||
{int numInstances = 1,
|
{int numInstances = 1,
|
||||||
bool keepData = false,
|
bool keepData = false,
|
||||||
int priority = 4,
|
int priority = 4,
|
||||||
int layer = 0});
|
int layer = 0,
|
||||||
|
bool loadResourcesAsync});
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Create a new instance of [entity].
|
/// Create a new instance of [entity].
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace thermion
|
|||||||
/// @return an Entity representing the FilamentAsset associated with the loaded FilamentAsset.
|
/// @return an Entity representing the FilamentAsset associated with the loaded FilamentAsset.
|
||||||
///
|
///
|
||||||
EntityId loadGlb(const char *uri, int numInstances, bool keepData);
|
EntityId loadGlb(const char *uri, int numInstances, bool keepData);
|
||||||
EntityId loadGlbFromBuffer(const uint8_t *data, size_t length, int numInstances = 1, bool keepData = false, int priority = 4, int layer = 0);
|
EntityId loadGlbFromBuffer(const uint8_t *data, size_t length, int numInstances = 1, bool keepData = false, int priority = 4, int layer = 0, bool loadResourcesAsync = false);
|
||||||
EntityId createInstance(EntityId entityId);
|
EntityId createInstance(EntityId entityId);
|
||||||
|
|
||||||
void remove(EntityId entity);
|
void remove(EntityId entity);
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ extern "C"
|
|||||||
EMSCRIPTEN_KEEPALIVE TCamera* SceneManager_findCameraByName(TSceneManager* tSceneManager, EntityId entity, const char* name);
|
EMSCRIPTEN_KEEPALIVE TCamera* SceneManager_findCameraByName(TSceneManager* tSceneManager, EntityId entity, const char* name);
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneManager_setVisibilityLayer(TSceneManager *tSceneManager, EntityId entity, int layer);
|
EMSCRIPTEN_KEEPALIVE void SceneManager_setVisibilityLayer(TSceneManager *tSceneManager, EntityId entity, int layer);
|
||||||
EMSCRIPTEN_KEEPALIVE TScene* SceneManager_getScene(TSceneManager *tSceneManager);
|
EMSCRIPTEN_KEEPALIVE TScene* SceneManager_getScene(TSceneManager *tSceneManager);
|
||||||
EMSCRIPTEN_KEEPALIVE EntityId SceneManager_loadGlbFromBuffer(TSceneManager *sceneManager, const uint8_t *const, size_t length, bool keepData, int priority, int layer);
|
EMSCRIPTEN_KEEPALIVE EntityId SceneManager_loadGlbFromBuffer(TSceneManager *sceneManager, const uint8_t *const, size_t length, bool keepData, int priority, int layer, bool loadResourcesAsync);
|
||||||
EMSCRIPTEN_KEEPALIVE bool SceneManager_setMorphAnimation(
|
EMSCRIPTEN_KEEPALIVE bool SceneManager_setMorphAnimation(
|
||||||
TSceneManager *sceneManager,
|
TSceneManager *sceneManager,
|
||||||
EntityId entity,
|
EntityId entity,
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ extern "C"
|
|||||||
void load_skybox_render_thread(TViewer *viewer, const char *skyboxPath, void (*onComplete)());
|
void load_skybox_render_thread(TViewer *viewer, const char *skyboxPath, void (*onComplete)());
|
||||||
void remove_skybox_render_thread(TViewer *viewer);
|
void remove_skybox_render_thread(TViewer *viewer);
|
||||||
|
|
||||||
void SceneManager_loadGlbFromBufferRenderThread(TSceneManager *sceneManager, const uint8_t *const data, size_t length, int numInstances, bool keepData, int priority, int layer, void (*callback)(EntityId));
|
void SceneManager_loadGlbFromBufferRenderThread(TSceneManager *sceneManager, const uint8_t *const data, size_t length, int numInstances, bool keepData, int priority, int layer, bool loadResourcesAsync, void (*callback)(EntityId));
|
||||||
void load_glb_render_thread(TSceneManager *sceneManager, const char *assetPath, int numInstances, bool keepData, void (*callback)(EntityId));
|
void load_glb_render_thread(TSceneManager *sceneManager, const char *assetPath, int numInstances, bool keepData, void (*callback)(EntityId));
|
||||||
void load_gltf_render_thread(TSceneManager *sceneManager, const char *assetPath, const char *relativePath, bool keepData, void (*callback)(EntityId));
|
void load_gltf_render_thread(TSceneManager *sceneManager, const char *assetPath, const char *relativePath, bool keepData, void (*callback)(EntityId));
|
||||||
void create_instance_render_thread(TSceneManager *sceneManager, EntityId entityId, void (*callback)(EntityId));
|
void create_instance_render_thread(TSceneManager *sceneManager, EntityId entityId, void (*callback)(EntityId));
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ namespace thermion
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityId SceneManager::loadGlbFromBuffer(const uint8_t *data, size_t length, int numInstances, bool keepData, int priority, int layer)
|
EntityId SceneManager::loadGlbFromBuffer(const uint8_t *data, size_t length, int numInstances, bool keepData, int priority, int layer, bool loadResourcesAsync)
|
||||||
{
|
{
|
||||||
|
|
||||||
FilamentAsset *asset = nullptr;
|
FilamentAsset *asset = nullptr;
|
||||||
@@ -304,10 +304,18 @@ namespace thermion
|
|||||||
_gltfResourceLoader->asyncUpdateLoad();
|
_gltfResourceLoader->asyncUpdateLoad();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (!_gltfResourceLoader->loadResources(asset))
|
if(loadResourcesAsync) {
|
||||||
{
|
if (!_gltfResourceLoader->asyncBeginLoad(asset))
|
||||||
Log("Unknown error loading glb asset");
|
{
|
||||||
return 0;
|
Log("Unknown error loading glb asset");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!_gltfResourceLoader->loadResources(asset))
|
||||||
|
{
|
||||||
|
Log("Unknown error loading glb asset");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ extern "C"
|
|||||||
return ((SceneManager *)sceneManager)->loadGlb(assetPath, numInstances, keepData);
|
return ((SceneManager *)sceneManager)->loadGlb(assetPath, numInstances, keepData);
|
||||||
}
|
}
|
||||||
|
|
||||||
EMSCRIPTEN_KEEPALIVE EntityId SceneManager_loadGlbFromBuffer(TSceneManager *sceneManager, const uint8_t *const data, size_t length, bool keepData, int priority, int layer)
|
EMSCRIPTEN_KEEPALIVE EntityId SceneManager_loadGlbFromBuffer(TSceneManager *sceneManager, const uint8_t *const data, size_t length, bool keepData, int priority, int layer, bool loadResourcesAsync)
|
||||||
{
|
{
|
||||||
return ((SceneManager *)sceneManager)->loadGlbFromBuffer((const uint8_t *)data, length, 1, keepData, priority, layer);
|
return ((SceneManager *)sceneManager)->loadGlbFromBuffer((const uint8_t *)data, length, 1, keepData, priority, layer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -336,12 +336,13 @@ extern "C"
|
|||||||
bool keepData,
|
bool keepData,
|
||||||
int priority,
|
int priority,
|
||||||
int layer,
|
int layer,
|
||||||
|
bool loadResourcesAsync,
|
||||||
void (*callback)(EntityId))
|
void (*callback)(EntityId))
|
||||||
{
|
{
|
||||||
std::packaged_task<EntityId()> lambda(
|
std::packaged_task<EntityId()> lambda(
|
||||||
[=]() mutable
|
[=]() mutable
|
||||||
{
|
{
|
||||||
auto entity = SceneManager_loadGlbFromBuffer(sceneManager, data, length, keepData, priority, layer);
|
auto entity = SceneManager_loadGlbFromBuffer(sceneManager, data, length, keepData, priority, layer, loadResourcesAsync);
|
||||||
callback(entity);
|
callback(entity);
|
||||||
return entity;
|
return entity;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user