internal: store bounding box with SceneAsset rather than recalculating from renderables
This commit is contained in:
@@ -4,40 +4,40 @@ import 'package:thermion_dart/src/viewer/src/ffi/src/callbacks.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_material.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/thermion_viewer_ffi.dart';
|
||||
import 'package:thermion_dart/thermion_dart.dart';
|
||||
import 'package:vector_math/vector_math_64.dart' as v64;
|
||||
|
||||
class FFIAsset extends ThermionAsset {
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
final Pointer<TSceneAsset> pointer;
|
||||
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
final Pointer<TSceneManager> sceneManager;
|
||||
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
Pointer<TRenderableManager> get renderableManager =>
|
||||
Engine_getRenderableManager(engine);
|
||||
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
final Pointer<TEngine> engine;
|
||||
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
FFIAsset? _highlight;
|
||||
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
final Pointer<TMaterialProvider> _unlitMaterialProvider;
|
||||
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
@@ -47,7 +47,7 @@ class FFIAsset extends ThermionAsset {
|
||||
///
|
||||
///
|
||||
late final ThermionEntity entity;
|
||||
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
@@ -236,16 +236,25 @@ class FFIAsset extends ThermionAsset {
|
||||
|
||||
FFIAsset? boundingBoxAsset;
|
||||
|
||||
Future<Aabb3> getBoundingBox() async {
|
||||
late ThermionEntity targetEntity;
|
||||
Future<v64.Aabb3> getBoundingBox() async {
|
||||
final entities = <ThermionEntity>[];
|
||||
if (RenderableManager_isRenderable(renderableManager, entity)) {
|
||||
targetEntity = entity;
|
||||
entities.add(entity);
|
||||
} else {
|
||||
targetEntity = (await getChildEntities()).first;
|
||||
entities.addAll(await getChildEntities());
|
||||
}
|
||||
final aabb3 =
|
||||
SceneManager_getRenderableBoundingBox(sceneManager, targetEntity);
|
||||
return aabb3;
|
||||
|
||||
var boundingBox = v64.Aabb3();
|
||||
|
||||
for (final entity in entities) {
|
||||
final aabb3 = SceneManager_getRenderableBoundingBox(sceneManager, entity);
|
||||
final entityBB = v64.Aabb3.centerAndHalfExtents(
|
||||
v64.Vector3(aabb3.centerX, aabb3.centerY, aabb3.centerZ),
|
||||
v64.Vector3(aabb3.halfExtentX, aabb3.halfExtentY, aabb3.halfExtentZ),
|
||||
);
|
||||
boundingBox.hull(entityBB);
|
||||
}
|
||||
return boundingBox;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -254,7 +263,8 @@ class FFIAsset extends ThermionAsset {
|
||||
@override
|
||||
Future<void> setBoundingBoxVisibility(bool visible) async {
|
||||
if (boundingBoxAsset == null) {
|
||||
final boundingBox = await getBoundingBox();
|
||||
final boundingBox = await SceneAsset_getBoundingBox(pointer!);
|
||||
|
||||
final min = [
|
||||
boundingBox.centerX - boundingBox.halfExtentX,
|
||||
boundingBox.centerY - boundingBox.halfExtentY,
|
||||
|
||||
@@ -1718,7 +1718,7 @@ external void SceneManager_destroyLightsRenderThread(
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
EntityId Function(
|
||||
ffi.Void Function(
|
||||
ffi.Pointer<TSceneManager>,
|
||||
ffi.Uint8,
|
||||
ffi.Float,
|
||||
@@ -1738,7 +1738,7 @@ external void SceneManager_destroyLightsRenderThread(
|
||||
ffi.Bool,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>>)>(
|
||||
isLeaf: true)
|
||||
external int SceneManager_addLightRenderThread(
|
||||
external void SceneManager_addLightRenderThread(
|
||||
ffi.Pointer<TSceneManager> tSceneManager,
|
||||
int type,
|
||||
double colour,
|
||||
@@ -2383,6 +2383,11 @@ external ffi.Pointer<TSceneAsset> SceneAsset_createInstance(
|
||||
int materialInstanceCount,
|
||||
);
|
||||
|
||||
@ffi.Native<Aabb3 Function(ffi.Pointer<TSceneAsset>)>(isLeaf: true)
|
||||
external Aabb3 SceneAsset_getBoundingBox(
|
||||
ffi.Pointer<TSceneAsset> asset,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Void Function(ffi.Pointer<TAnimationManager>, EntityId)>(
|
||||
isLeaf: true)
|
||||
external void AnimationManager_addAnimationComponent(
|
||||
|
||||
Reference in New Issue
Block a user