feat: add getAncestor method

This commit is contained in:
Nick Fisher
2024-09-08 13:52:33 +08:00
parent 5c4d5d4b9d
commit 476b552fd0
4 changed files with 73 additions and 3 deletions

View File

@@ -1043,6 +1043,12 @@ external int get_parent(
int child,
);
@ffi.Native<EntityId Function(ffi.Pointer<ffi.Void>, EntityId)>()
external int get_ancestor(
ffi.Pointer<ffi.Void> sceneManager,
int child,
);
@ffi.Native<
ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId, EntityId, ffi.Bool)>()
external void set_parent(

View File

@@ -773,9 +773,14 @@ abstract class ThermionViewer {
PrimitiveType primitiveType = PrimitiveType.TRIANGLES});
///
/// Gets the parent transform of [child].
/// Gets the parent entity of [entity]. Returns null if the entity has no parent.
///
Future<ThermionEntity?> getParent(ThermionEntity child);
Future<ThermionEntity?> getParent(ThermionEntity entity);
///
/// Gets the ancestor (ultimate parent) entity of [entity]. Returns null if the entity has no parent.
///
Future<ThermionEntity?> getAncestor(ThermionEntity entity);
///
/// Sets the parent transform of [child] to [parent].

View File

@@ -1805,6 +1805,21 @@ class ThermionViewerFFI extends ThermionViewer {
return parent;
}
///
///
///
@override
Future<ThermionEntity?> getAncestor(ThermionEntity child) async {
if (_sceneManager == null) {
throw Exception("Asset manager must be non-null");
}
var parent = get_ancestor(_sceneManager!, child);
if (parent == _FILAMENT_ASSET_ERROR) {
return null;
}
return parent;
}
///
///
///