feat: add flag for keepData for gltf instancing, add highlightScene, add stencilHighlight method

This commit is contained in:
Nick Fisher
2024-09-06 12:36:16 +08:00
parent 226c45ee2e
commit 9c5156e41a
20 changed files with 1967 additions and 93 deletions

View File

@@ -206,28 +206,33 @@ external void set_light_direction(
);
@ffi.Native<
EntityId Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Char>, ffi.Int)>()
EntityId Function(
ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Char>, ffi.Int, ffi.Bool)>()
external int load_glb(
ffi.Pointer<ffi.Void> sceneManager,
ffi.Pointer<ffi.Char> assetPath,
int numInstances,
);
@ffi.Native<
EntityId Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Void>, ffi.Size)>()
external int load_glb_from_buffer(
ffi.Pointer<ffi.Void> sceneManager,
ffi.Pointer<ffi.Void> data,
int length,
bool keepData,
);
@ffi.Native<
EntityId Function(
ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Char>)>()
ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Void>, ffi.Size, ffi.Bool)>()
external int load_glb_from_buffer(
ffi.Pointer<ffi.Void> sceneManager,
ffi.Pointer<ffi.Void> data,
int length,
bool keepData,
);
@ffi.Native<
EntityId Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.Char>, ffi.Bool)>()
external int load_gltf(
ffi.Pointer<ffi.Void> sceneManager,
ffi.Pointer<ffi.Char> assetPath,
ffi.Pointer<ffi.Char> relativePath,
bool keepData,
);
@ffi.Native<EntityId Function(ffi.Pointer<ffi.Void>, EntityId)>()
@@ -1111,6 +1116,12 @@ external void set_gizmo_visibility(
bool visible,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId)>()
external void set_stencil_highlight(
ffi.Pointer<ffi.Void> sceneManager,
int entity,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<ffi.Void>,
@@ -1347,12 +1358,17 @@ external void clear_lights_ffi(
);
@ffi.Native<
ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Char>, ffi.Int,
ffi.Void Function(
ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.Char>,
ffi.Int,
ffi.Bool,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>>)>()
external void load_glb_ffi(
ffi.Pointer<ffi.Void> sceneManager,
ffi.Pointer<ffi.Char> assetPath,
int numInstances,
bool keepData,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>> callback,
);
@@ -1362,12 +1378,14 @@ external void load_glb_ffi(
ffi.Pointer<ffi.Void>,
ffi.Size,
ffi.Int,
ffi.Bool,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>>)>()
external void load_glb_from_buffer_ffi(
ffi.Pointer<ffi.Void> sceneManager,
ffi.Pointer<ffi.Void> data,
int length,
int numInstances,
bool keepData,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>> callback,
);
@@ -1376,11 +1394,13 @@ external void load_glb_from_buffer_ffi(
ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.Char>,
ffi.Bool,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>>)>()
external void load_gltf_ffi(
ffi.Pointer<ffi.Void> sceneManager,
ffi.Pointer<ffi.Char> assetPath,
ffi.Pointer<ffi.Char> relativePath,
bool keepData,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>> callback,
);

View File

@@ -199,11 +199,14 @@ abstract class ThermionViewer {
///
/// Load the .glb asset at the given path and insert into the scene.
/// 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.
///
Future<ThermionEntity> loadGlb(String path, {int numInstances = 1});
Future<ThermionEntity> loadGlb(String path, {int numInstances = 1, bool keepData = false});
///
/// Create a new instance of [entity].
/// Create a new instance of [entity].
///
Future<ThermionEntity> createInstance(ThermionEntity entity);
@@ -221,9 +224,11 @@ abstract class ThermionViewer {
/// Load the .gltf asset at the given path and insert into the scene.
/// [relativeResourcePath] is the folder path where the glTF resources are stored;
/// this is usually the parent directory of the .gltf file itself.
///
/// See [loadGlb] for an explanation of [keepData].
///
Future<ThermionEntity> loadGltf(String path, String relativeResourcePath,
{bool force = false});
{bool keepData = false});
///
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
@@ -577,7 +582,8 @@ abstract class ThermionViewer {
///
/// Set the world space position for [lightEntity] to the given coordinates.
///
Future setLightPosition(ThermionEntity lightEntity, double x, double y, double z);
Future setLightPosition(
ThermionEntity lightEntity, double x, double y, double z);
///
/// Sets the world space direction for [lightEntity] to the given vector.
@@ -810,4 +816,9 @@ abstract class ThermionViewer {
/// Show/hide the translation gizmo.
///
Future setGizmoVisibility(bool visible);
///
/// Outlines [entity].
///
Future setStencilHighlight(ThermionEntity entity);
}

View File

@@ -403,8 +403,7 @@ class ThermionViewerFFI extends ThermionViewer {
///
@override
Future<ThermionEntity> createInstance(ThermionEntity entity) async {
var created = await withIntCallback(
(callback) => create_instance(_sceneManager!, entity));
var created = create_instance(_sceneManager!, entity);
if (created == _FILAMENT_ASSET_ERROR) {
throw Exception("Failed to create instance");
}
@@ -440,13 +439,13 @@ class ThermionViewerFFI extends ThermionViewer {
///
@override
Future<ThermionEntity> loadGlb(String path,
{bool unlit = false, int numInstances = 1}) async {
{bool unlit = false, int numInstances = 1, bool keepData = false}) async {
if (unlit) {
throw Exception("Not yet implemented");
}
final pathPtr = path.toNativeUtf8(allocator: allocator).cast<Char>();
var entity = await withIntCallback((callback) =>
load_glb_ffi(_sceneManager!, pathPtr, numInstances, callback));
load_glb_ffi(_sceneManager!, pathPtr, numInstances, keepData, callback));
allocator.free(pathPtr);
if (entity == _FILAMENT_ASSET_ERROR) {
throw Exception("An error occurred loading the asset at $path");
@@ -461,12 +460,12 @@ class ThermionViewerFFI extends ThermionViewer {
///
@override
Future<ThermionEntity> loadGltf(String path, String relativeResourcePath,
{bool force = false}) async {
{bool keepData = false}) async {
final pathPtr = path.toNativeUtf8(allocator: allocator).cast<Char>();
final relativeResourcePathPtr =
relativeResourcePath.toNativeUtf8(allocator: allocator).cast<Char>();
var entity = await withIntCallback((callback) => load_gltf_ffi(
_sceneManager!, pathPtr, relativeResourcePathPtr, callback));
_sceneManager!, pathPtr, relativeResourcePathPtr, keepData, callback));
allocator.free(pathPtr);
allocator.free(relativeResourcePathPtr);
if (entity == _FILAMENT_ASSET_ERROR) {
@@ -1300,9 +1299,11 @@ class ThermionViewerFFI extends ThermionViewer {
///
///
@override
Future setLightDirection(ThermionEntity lightEntity, Vector3 direction) async {
Future setLightDirection(
ThermionEntity lightEntity, Vector3 direction) async {
direction.normalize();
set_light_direction(_viewer!, lightEntity, direction.x, direction.y, direction.z);
set_light_direction(
_viewer!, lightEntity, direction.x, direction.y, direction.z);
}
///
@@ -1828,4 +1829,8 @@ class ThermionViewerFFI extends ThermionViewer {
Future setGizmoVisibility(bool visible) async {
set_gizmo_visibility(_sceneManager!, visible);
}
Future setStencilHighlight(ThermionEntity entity) async {
set_stencil_highlight(_sceneManager!, entity);
}
}