reimplement grid as SceneAsset
This commit is contained in:
@@ -2,13 +2,13 @@ import 'dart:async';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/callbacks.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_asset.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/shared_types/entities.dart';
|
||||
import 'thermion_dart.g.dart';
|
||||
import 'package:thermion_dart/thermion_dart.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
import 'ffi_view.dart';
|
||||
|
||||
class FFIGizmo extends FFIAsset implements GizmoAsset {
|
||||
final Set<ThermionEntity> nonPickableEntities;
|
||||
final Set<ThermionEntity> gizmoEntities;
|
||||
late NativeCallable<GizmoPickCallbackFunction> _nativeCallback;
|
||||
|
||||
@@ -20,8 +20,10 @@ class FFIGizmo extends FFIAsset implements GizmoAsset {
|
||||
_callback?.call(GizmoPickResultType.values[resultType], Vector3(x, y, z));
|
||||
}
|
||||
|
||||
bool isNonPickable(ThermionEntity entity) =>
|
||||
nonPickableEntities.contains(entity);
|
||||
bool isNonPickable(ThermionEntity entity) {
|
||||
return SceneManager_isGridEntity(sceneManager!, entity);
|
||||
}
|
||||
|
||||
bool isGizmoEntity(ThermionEntity entity) => gizmoEntities.contains(entity);
|
||||
|
||||
FFIGizmo(
|
||||
@@ -30,7 +32,6 @@ class FFIGizmo extends FFIAsset implements GizmoAsset {
|
||||
super.sceneManager,
|
||||
super.renderableManager,
|
||||
super.unlitMaterialProvider,
|
||||
this.nonPickableEntities,
|
||||
this.gizmoEntities) {
|
||||
_nativeCallback =
|
||||
NativeCallable<GizmoPickCallbackFunction>.listener(_onPickResult);
|
||||
|
||||
@@ -1905,16 +1905,17 @@ external ffi.Pointer<TNameComponentManager>
|
||||
ffi.Pointer<TSceneManager> tSceneManager,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Size Function(ffi.Pointer<TSceneManager>)>(isLeaf: true)
|
||||
external int SceneManager_getOverlayEntityCount(
|
||||
@ffi.Native<ffi.Pointer<TSceneAsset> Function(ffi.Pointer<TSceneManager>)>(
|
||||
isLeaf: true)
|
||||
external ffi.Pointer<TSceneAsset> SceneManager_createGrid(
|
||||
ffi.Pointer<TSceneManager> tSceneManager,
|
||||
);
|
||||
|
||||
@ffi.Native<EntityId Function(ffi.Pointer<TSceneManager>, ffi.Size)>(
|
||||
@ffi.Native<ffi.Bool Function(ffi.Pointer<TSceneManager>, EntityId)>(
|
||||
isLeaf: true)
|
||||
external int SceneManager_getOverlayEntityAt(
|
||||
external bool SceneManager_isGridEntity(
|
||||
ffi.Pointer<TSceneManager> tSceneManager,
|
||||
int index,
|
||||
int entityId,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
|
||||
@@ -1755,6 +1755,31 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
SceneManager_setVisibilityLayer(_sceneManager!, entity, layer.value);
|
||||
}
|
||||
|
||||
FFIAsset? _grid;
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
Future showGridOverlay() async {
|
||||
final ptr = SceneManager_createGrid(_sceneManager!);
|
||||
_grid ??= FFIAsset(ptr, _sceneManager!, _engine!, _unlitMaterialProvider!);
|
||||
await _grid!.addToScene();
|
||||
}
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
Future removeGridOverlay() async {
|
||||
if (_grid != null) {
|
||||
await _grid!.removeFromScene();
|
||||
SceneManager_destroyAsset(_sceneManager!, _grid!.pointer);
|
||||
_grid = null;
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
Future<Uint8List> unproject(ThermionEntity entity, Uint8List input,
|
||||
int inputWidth, int inputHeight, int outWidth, int outHeight) async {
|
||||
final outPtr = Uint8List(outWidth * outHeight * 4);
|
||||
@@ -1933,6 +1958,9 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
return instance;
|
||||
}
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
@override
|
||||
Future requestFrame() async {
|
||||
for (final hook in _hooks) {
|
||||
@@ -1963,6 +1991,9 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
return camera;
|
||||
}
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
Future destroyCamera(FFICamera camera) async {
|
||||
SceneManager_destroyCamera(_sceneManager!, camera.camera);
|
||||
}
|
||||
@@ -2037,10 +2068,6 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
if (gizmo == nullptr) {
|
||||
throw Exception("Failed to create gizmo");
|
||||
}
|
||||
final overlayEntityCount =
|
||||
SceneManager_getOverlayEntityCount(_sceneManager!);
|
||||
final overlayEntities = List<ThermionEntity>.generate(overlayEntityCount,
|
||||
(i) => SceneManager_getOverlayEntityAt(_sceneManager!, i)).toSet();
|
||||
|
||||
final gizmoEntityCount =
|
||||
SceneAsset_getChildEntityCount(gizmo.cast<TSceneAsset>());
|
||||
@@ -2054,7 +2081,6 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
_sceneManager!,
|
||||
_engine!,
|
||||
nullptr,
|
||||
overlayEntities,
|
||||
gizmoEntities.toSet()
|
||||
..add(SceneAsset_getEntity(gizmo.cast<TSceneAsset>())));
|
||||
}
|
||||
|
||||
@@ -724,8 +724,7 @@ abstract class ThermionViewer {
|
||||
///
|
||||
/// The gizmo for translating/rotating objects. Only one gizmo can be active for a given view.
|
||||
///
|
||||
Future<GizmoAsset> createGizmo(covariant View view,
|
||||
GizmoType type);
|
||||
Future<GizmoAsset> createGizmo(covariant View view, GizmoType type);
|
||||
|
||||
///
|
||||
/// Register a callback to be invoked when this viewer is disposed.
|
||||
@@ -763,6 +762,16 @@ abstract class ThermionViewer {
|
||||
///
|
||||
Future setVisibilityLayer(ThermionEntity entity, VisibilityLayers layer);
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
Future showGridOverlay();
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
Future removeGridOverlay();
|
||||
|
||||
///
|
||||
/// Decodes the specified image data and creates a texture.
|
||||
///
|
||||
@@ -875,7 +884,7 @@ abstract class ThermionViewer {
|
||||
///
|
||||
/// Returns the camera specified by the given index. Note that the camera at
|
||||
/// index 0 is always the main camera; this cannot be destroyed.
|
||||
///
|
||||
///
|
||||
/// Throws an exception if the index is out-of-bounds.
|
||||
///
|
||||
Camera getCameraAt(int index);
|
||||
|
||||
Reference in New Issue
Block a user