move bounding box asset methods from ThermionAsset to ThermionViewer

This commit is contained in:
Nick Fisher
2025-06-23 11:57:15 +08:00
parent e8721b6133
commit abd1a1fd55
2 changed files with 43 additions and 22 deletions

View File

@@ -2,26 +2,34 @@ library;
import 'package:animation_tools_dart/animation_tools_dart.dart'; import 'package:animation_tools_dart/animation_tools_dart.dart';
import 'package:thermion_dart/src/filament/src/interface/layers.dart'; import 'package:thermion_dart/src/filament/src/interface/layers.dart';
import 'package:thermion_dart/src/filament/src/interface/scene.dart';
import 'package:thermion_dart/thermion_dart.dart'; import 'package:thermion_dart/thermion_dart.dart';
export 'geometry.dart'; export 'geometry.dart';
export 'gltf.dart'; export 'gltf.dart';
/// ///
/// Represents a renderable object (i.e. not cameras or lights). /// A high-level interface for a renderable object
/// (i.e. not a camera or light).
/// ///
/// At a low level, Filament works with entities. In practice, /// Filament represents most "objects" with an integer handle (in C++,
/// it can be difficult to work directly with these at a higher level /// filament::Entity).
/// because:
/// a) certain objects don't map exactly to entities (e.g. glTF assets, which
/// are represented by a hierarchy of entities).
/// b) it is not trivial to create instances directly from entities
/// ///
/// [ThermionAsset] is intended to provide a unified high-level interface /// In practice, working with filament::Entity at a higher level is difficult
/// for working with renderable objects. /// because certain objects don't map exactly to entities (e.g. glTF assets, which
/// are represented by a hierarchy of entities) and creating instances
/// directly from entities is not possible.
/// ///
/// ///
abstract class ThermionAsset { abstract class ThermionAsset {
///
///
///
T getHandle<T>() {
throw UnimplementedError();
}
/// ///
/// The top-most entity in the hierarchy. If this is a glTF asset /// The top-most entity in the hierarchy. If this is a glTF asset
/// ///
@@ -75,16 +83,15 @@ abstract class ThermionAsset {
throw UnimplementedError(); throw UnimplementedError();
} }
/// For each entity in the given map, set the material instance
/// For each entity in the given map, set the material instance
/// for the respective primitive. /// for the respective primitive.
/// ///
/// Mainly intended for use with [getMaterialInstancesAsMap] so you can /// Mainly intended for use with [getMaterialInstancesAsMap] so you can
/// easily save/restore an asset's material instances. /// easily save/restore an asset's material instances.
/// ///
Future setMaterialInstancesFromMap( Future setMaterialInstancesFromMap(
Map<ThermionEntity, List<MaterialInstance>> materialInstances) async { Map<ThermionEntity, List<MaterialInstance>> materialInstances) async {
throw UnimplementedError(); throw UnimplementedError();
} }
/// ///
@@ -96,18 +103,21 @@ abstract class ThermionAsset {
/// ///
/// The bounding box for this asset, as an actual renderable asset. /// The bounding box for this asset, as an actual renderable asset.
/// Null by default; call [createBoundingBoxAsset] first to create.
///
ThermionAsset? get boundingBoxAsset;
///
/// Creates the renderable bounding box for this asset.
/// This is safe to call multiple times; if [boundingBoxAsset] is non-null, /// This is safe to call multiple times; if [boundingBoxAsset] is non-null,
/// this will simply return the existing bounding box asset. /// this will simply return the existing bounding box asset.
/// ///
/// You will still need to call [Scene.add] to add this to the scene. /// You will still need to call [Scene.add] to add this to the scene.
/// ///
Future<ThermionAsset> createBoundingBoxAsset(); Future<ThermionAsset> getBoundingBoxAsset() {
throw UnimplementedError();
}
///
///
///
Future destroyBoundingBoxAsset(Scene scene) {
throw UnimplementedError();
}
/// ///
/// ///

View File

@@ -290,6 +290,17 @@ abstract class ThermionViewer {
/// ///
Future<Aabb3> getRenderableBoundingBox(ThermionEntity entity); Future<Aabb3> getRenderableBoundingBox(ThermionEntity entity);
/// Render the bounding box for [asset] with an unlit material.
///
Future showBoundingBox(ThermionAsset asset);
/// Removes the bounding box for [asset] from the scene.
///
/// If [destroy] is true, the geometry and material instance for the asset
/// will also be destroyed.
///
Future hideBoundingBox(ThermionAsset asset, { bool destroy = false});
/// ///
/// Gets the 2D bounding box (in viewport coordinates) for the given entity. /// Gets the 2D bounding box (in viewport coordinates) for the given entity.
/// ///