feature!:
This is a breaking change needed to fully implement instancing and stencil highlighting.
Previously, users would work directly with entities (on the Dart side, ThermionEntity), e.g.
final entity = await viewer.loadGlb("some.glb");
However, Filament "entities" are a lower-level abstraction.
Loading a glTF file, for example, inserts multiple entities into the scene.
For example, each mesh, light, and camera within a glTF asset will be assigned an entity. A top-level (non-renderable) entity will also be created for the glTF asset, which can be used to transform the entire hierarchy.
"Asset" is a better representation for loading/inserting objects into the scene; think of this as a bundle of entities.
Unless you need to work directly with transforms, instancing, materials and renderables, you can work directly with ThermionAsset.
This commit is contained in:
@@ -4,4 +4,6 @@ export 'src/input_handler.dart';
|
||||
export 'src/delegates.dart';
|
||||
export 'src/delegate_input_handler.dart';
|
||||
export 'src/implementations/default_pick_delegate.dart';
|
||||
export 'src/implementations/gizmo_pick_delegate.dart';
|
||||
export 'src/implementations/gizmo_input_handler.dart';
|
||||
export 'src/implementations/third_person_camera_delegate.dart';
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:thermion_dart/thermion_dart.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
@@ -54,6 +53,13 @@ class DelegateInputHandler implements InputHandler {
|
||||
_actions = actions;
|
||||
}
|
||||
|
||||
if (pickDelegate != null) {
|
||||
if (_actions[InputType.LMB_DOWN] != null) {
|
||||
throw Exception();
|
||||
}
|
||||
_actions[InputType.LMB_DOWN] = InputAction.PICK;
|
||||
}
|
||||
|
||||
for (var gestureType in InputType.values) {
|
||||
_inputDeltas[gestureType] = Vector3.zero();
|
||||
}
|
||||
@@ -94,7 +100,7 @@ class DelegateInputHandler implements InputHandler {
|
||||
clampY: clampY,
|
||||
entity: entity,
|
||||
rotationSensitivity: rotateSensitivity,
|
||||
zoomSensitivity:zoomSensitivity,
|
||||
zoomSensitivity: zoomSensitivity,
|
||||
panSensitivity: panSensitivity,
|
||||
movementSensitivity: movementSensitivity),
|
||||
actions: {
|
||||
@@ -265,7 +271,8 @@ class DelegateInputHandler implements InputHandler {
|
||||
Future<void> onScaleEnd(int pointerCount, double velocity) async {}
|
||||
|
||||
@override
|
||||
Future<void> onScaleStart(Vector2 localPosition, int pointerCount, Duration? sourceTimestamp ) async {
|
||||
Future<void> onScaleStart(Vector2 localPosition, int pointerCount,
|
||||
Duration? sourceTimestamp) async {
|
||||
// noop
|
||||
}
|
||||
|
||||
|
||||
@@ -24,4 +24,5 @@ abstract class VelocityDelegate {
|
||||
abstract class PickDelegate {
|
||||
const PickDelegate();
|
||||
void pick(Vector2 location);
|
||||
Future dispose();
|
||||
}
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:thermion_dart/thermion_dart.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
class DefaultPickDelegate extends PickDelegate {
|
||||
final ThermionViewer viewer;
|
||||
|
||||
const DefaultPickDelegate(this.viewer);
|
||||
DefaultPickDelegate(this.viewer);
|
||||
|
||||
final _picked = StreamController<ThermionEntity>();
|
||||
Stream<ThermionEntity> get picked => _picked.stream;
|
||||
|
||||
Future dispose() async {
|
||||
_picked.close();
|
||||
}
|
||||
|
||||
@override
|
||||
void pick(Vector2 location) {
|
||||
viewer.pick(location.x.toInt(), location.y.toInt());
|
||||
viewer.pick(location.x.toInt(), location.y.toInt(), (result) {
|
||||
_picked.sink.add(result.entity);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,13 +86,14 @@ class FreeFlightInputHandlerDelegate implements InputHandlerDelegate {
|
||||
if (_queuedRotationDelta.length2 > 0.0) {
|
||||
double deltaX = _queuedRotationDelta.x * rotationSensitivity;
|
||||
double deltaY = _queuedRotationDelta.y * rotationSensitivity;
|
||||
relativeRotation = Quaternion.axisAngle(current.up, -deltaX) * Quaternion.axisAngle(current.right, -deltaY);
|
||||
relativeRotation = Quaternion.axisAngle(current.up, -deltaX) *
|
||||
Quaternion.axisAngle(current.right, -deltaY);
|
||||
_queuedRotationDelta = Vector2.zero();
|
||||
}
|
||||
|
||||
// Apply (mouse) pan
|
||||
if (_queuedTranslateDelta.length2 > 0.0) {
|
||||
double deltaX = _queuedTranslateDelta.x * panSensitivity;
|
||||
double deltaX = -_queuedTranslateDelta.x * panSensitivity;
|
||||
double deltaY = _queuedTranslateDelta.y * panSensitivity;
|
||||
double deltaZ = -_queuedTranslateDelta.z * panSensitivity;
|
||||
|
||||
@@ -104,8 +105,9 @@ class FreeFlightInputHandlerDelegate implements InputHandlerDelegate {
|
||||
|
||||
// Apply zoom
|
||||
if (_queuedZoomDelta != 0.0) {
|
||||
relativeTranslation += current.forward
|
||||
..scaled(_queuedZoomDelta * zoomSensitivity);
|
||||
var zoomTranslation = current.forward..scaled(zoomSensitivity);
|
||||
zoomTranslation.scale(_queuedZoomDelta);
|
||||
relativeTranslation += zoomTranslation;
|
||||
_queuedZoomDelta = 0.0;
|
||||
}
|
||||
|
||||
@@ -128,11 +130,10 @@ class FreeFlightInputHandlerDelegate implements InputHandlerDelegate {
|
||||
|
||||
await viewer.setTransform(
|
||||
await entity,
|
||||
|
||||
Matrix4.compose(
|
||||
relativeTranslation, relativeRotation, Vector3(1, 1, 1)) * current );
|
||||
Matrix4.compose(
|
||||
relativeTranslation, relativeRotation, Vector3(1, 1, 1)) *
|
||||
current);
|
||||
|
||||
_executing = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
import 'dart:async';
|
||||
import 'package:thermion_dart/thermion_dart.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
class _Gizmo {
|
||||
bool isVisible = false;
|
||||
|
||||
final ThermionViewer viewer;
|
||||
final nonPickable = <ThermionEntity>{};
|
||||
final GizmoAsset _asset;
|
||||
|
||||
_Gizmo(this._asset, this.viewer);
|
||||
|
||||
Axis? _active;
|
||||
Axis? get active => _active;
|
||||
|
||||
Vector3? _activeCords;
|
||||
|
||||
void checkHover(int x, int y) async {
|
||||
_asset.pick(x, y, handler: (result, coords) async {
|
||||
switch (result) {
|
||||
case GizmoPickResultType.None:
|
||||
await _asset.unhighlight();
|
||||
_active = null;
|
||||
break;
|
||||
case GizmoPickResultType.AxisX:
|
||||
_active = Axis.X;
|
||||
_activeCords = coords;
|
||||
|
||||
case GizmoPickResultType.AxisY:
|
||||
_active = Axis.Y;
|
||||
_activeCords = coords;
|
||||
|
||||
case GizmoPickResultType.AxisZ:
|
||||
_active = Axis.Z;
|
||||
_activeCords = coords;
|
||||
|
||||
default:
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Matrix4? gizmoTransform;
|
||||
|
||||
Future attach(ThermionEntity entity) async {
|
||||
if (_asset.nonPickableEntities.contains(entity)) {
|
||||
return;
|
||||
}
|
||||
final transform = await viewer.getWorldTransform(entity);
|
||||
transform.setRotation(Matrix3.identity());
|
||||
transform.setDiagonal(Vector4.all(1.0));
|
||||
await viewer.setTransform(_asset.entity, transform);
|
||||
await viewer.setParent(entity, _asset.entity);
|
||||
if (!isVisible) {
|
||||
await _asset.addToScene();
|
||||
isVisible = true;
|
||||
}
|
||||
gizmoTransform = await viewer.getWorldTransform(_asset.entity);
|
||||
}
|
||||
|
||||
Future detach() async {
|
||||
await _asset.removeFromScene();
|
||||
_active = null;
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
void _updateTransform(Vector2 currentPosition, Vector2 delta) async {
|
||||
if (gizmoTransform == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var view = await viewer.getViewAt(0);
|
||||
var camera = await viewer.getActiveCamera();
|
||||
|
||||
var viewport = await view.getViewport();
|
||||
|
||||
var projectionMatrix = await viewer.getCameraProjectionMatrix();
|
||||
var viewMatrix = await camera.getViewMatrix();
|
||||
var inverseViewMatrix = await camera.getModelMatrix();
|
||||
var inverseProjectionMatrix = projectionMatrix.clone()..invert();
|
||||
|
||||
// get gizmo position in screenspace
|
||||
var gizmoPositionWorldSpace = gizmoTransform!.getTranslation();
|
||||
Vector4 gizmoClipSpace = projectionMatrix *
|
||||
viewMatrix *
|
||||
Vector4(gizmoPositionWorldSpace.x, gizmoPositionWorldSpace.y,
|
||||
gizmoPositionWorldSpace.z, 1.0);
|
||||
|
||||
var gizmoNdc = gizmoClipSpace / gizmoClipSpace.w;
|
||||
|
||||
var gizmoScreenSpace = Vector2(((gizmoNdc.x / 2) + 0.5) * viewport.width,
|
||||
viewport.height - (((gizmoNdc.y / 2) + 0.5) * viewport.height));
|
||||
|
||||
gizmoScreenSpace += delta;
|
||||
|
||||
gizmoNdc = Vector4(((gizmoScreenSpace.x / viewport.width) - 0.5) * 2,
|
||||
(((gizmoScreenSpace.y / viewport.height)) - 0.5) * -2, gizmoNdc.z, 1.0);
|
||||
|
||||
var gizmoViewSpace = inverseProjectionMatrix * gizmoNdc;
|
||||
gizmoViewSpace /= gizmoViewSpace.w;
|
||||
|
||||
var newPosition = (inverseViewMatrix * gizmoViewSpace).xyz;
|
||||
|
||||
Vector3 worldSpaceDelta = newPosition - gizmoTransform!.getTranslation();
|
||||
worldSpaceDelta.multiply(_active!.asVector());
|
||||
|
||||
gizmoTransform!.setTranslation(gizmoTransform!.getTranslation() + worldSpaceDelta);
|
||||
|
||||
await viewer.setTransform(_asset.entity, gizmoTransform!);
|
||||
}
|
||||
}
|
||||
|
||||
class GizmoInputHandler extends InputHandler {
|
||||
final InputHandler wrapped;
|
||||
final ThermionViewer viewer;
|
||||
late final _Gizmo translationGizmo;
|
||||
|
||||
GizmoInputHandler({required this.wrapped, required this.viewer}) {
|
||||
initialize();
|
||||
}
|
||||
|
||||
final _initialized = Completer<bool>();
|
||||
Future initialize() async {
|
||||
if (_initialized.isCompleted) {
|
||||
throw Exception("Already initialized");
|
||||
}
|
||||
await viewer.initialized;
|
||||
final view = await viewer.getViewAt(0);
|
||||
var translationGizmoAsset =
|
||||
await viewer.createGizmo(view, GizmoType.translation);
|
||||
this.translationGizmo = _Gizmo(translationGizmoAsset, viewer);
|
||||
_initialized.complete(true);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream get cameraUpdated => throw UnimplementedError();
|
||||
|
||||
@override
|
||||
Future dispose() async {
|
||||
await viewer.removeEntity(translationGizmo._asset);
|
||||
}
|
||||
|
||||
@override
|
||||
InputAction? getActionForType(InputType gestureType) {
|
||||
if (gestureType == InputType.LMB_DOWN) {
|
||||
return InputAction.PICK;
|
||||
}
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> get initialized => _initialized.future;
|
||||
|
||||
@override
|
||||
void keyDown(PhysicalKey key) {
|
||||
wrapped.keyDown(key);
|
||||
}
|
||||
|
||||
@override
|
||||
void keyUp(PhysicalKey key) {
|
||||
wrapped.keyDown(key);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onPointerDown(Vector2 localPosition, bool isMiddle) async {
|
||||
if (!_initialized.isCompleted) {
|
||||
return;
|
||||
}
|
||||
await viewer.pick(localPosition.x.toInt(), localPosition.y.toInt(),
|
||||
(result) {
|
||||
translationGizmo.attach(result.entity);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onPointerHover(Vector2 localPosition, Vector2 delta) async {
|
||||
if (!_initialized.isCompleted) {
|
||||
return;
|
||||
}
|
||||
translationGizmo.checkHover(
|
||||
localPosition.x.floor(), localPosition.y.floor());
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onPointerMove(
|
||||
Vector2 localPosition, Vector2 delta, bool isMiddle) async {
|
||||
if (!isMiddle && translationGizmo._active != null) {
|
||||
final scaledDelta = Vector2(
|
||||
delta.x,
|
||||
delta.y,
|
||||
);
|
||||
translationGizmo._updateTransform(localPosition, scaledDelta);
|
||||
return;
|
||||
}
|
||||
return wrapped.onPointerMove(localPosition, delta, isMiddle);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onPointerScroll(
|
||||
Vector2 localPosition, double scrollDelta) async {
|
||||
return wrapped.onPointerScroll(localPosition, scrollDelta);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onPointerUp(bool isMiddle) async {
|
||||
await wrapped.onPointerUp(isMiddle);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onScaleEnd(int pointerCount, double velocity) {
|
||||
return wrapped.onScaleEnd(pointerCount, velocity);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onScaleStart(
|
||||
Vector2 focalPoint, int pointerCount, Duration? sourceTimestamp) {
|
||||
return wrapped.onScaleStart(focalPoint, pointerCount, sourceTimestamp);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onScaleUpdate(
|
||||
Vector2 focalPoint,
|
||||
Vector2 focalPointDelta,
|
||||
double horizontalScale,
|
||||
double verticalScale,
|
||||
double scale,
|
||||
int pointerCount,
|
||||
double rotation,
|
||||
Duration? sourceTimestamp) {
|
||||
return wrapped.onScaleUpdate(focalPoint, focalPointDelta, horizontalScale,
|
||||
verticalScale, scale, pointerCount, rotation, sourceTimestamp);
|
||||
}
|
||||
|
||||
@override
|
||||
void setActionForType(InputType gestureType, InputAction gestureAction) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// import 'dart:async';
|
||||
|
||||
// import 'package:thermion_dart/thermion_dart.dart';
|
||||
// import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
// class GizmoPickDelegate extends PickDelegate {
|
||||
// final ThermionViewer viewer;
|
||||
// late final GizmoAsset translationGizmo;
|
||||
|
||||
// GizmoPickDelegate(this.viewer) {
|
||||
// initialize();
|
||||
// }
|
||||
|
||||
// bool _initialized = false;
|
||||
// Future initialize() async {
|
||||
// if (_initialized) {
|
||||
// throw Exception("Already initialized");
|
||||
// }
|
||||
// final view = await viewer.getViewAt(0);
|
||||
// translationGizmo = await viewer.createGizmo(view, GizmoType.translation);
|
||||
// await translationGizmo.addToScene();
|
||||
// _initialized = true;
|
||||
// }
|
||||
|
||||
// final _picked = StreamController<ThermionEntity>();
|
||||
// Stream<ThermionEntity> get picked => _picked.stream;
|
||||
|
||||
// Future dispose() async {
|
||||
// _picked.close();
|
||||
// }
|
||||
|
||||
// @override
|
||||
// void pick(Vector2 location) {
|
||||
// if (!_initialized) {
|
||||
// return;
|
||||
// }
|
||||
// viewer.pick(location.x.toInt(), location.y.toInt(), (result) {
|
||||
// translationGizmo.attach(result.entity);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
@@ -1,230 +1,329 @@
|
||||
// import 'dart:async';
|
||||
|
||||
// import 'package:flutter/gestures.dart';
|
||||
// import 'package:flutter/services.dart';
|
||||
// import 'package:logging/logging.dart';
|
||||
// import 'package:thermion_dart/thermion_dart/entities/abstract_gizmo.dart';
|
||||
// import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';
|
||||
// import 'dart:ui';
|
||||
// import 'package:thermion_dart/thermion_dart/input/input_handler.dart';
|
||||
// import 'package:thermion_dart/thermion_dart.dart';
|
||||
// import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
// // Renamed implementation
|
||||
// class PickingCameraGestureHandler implements InputHandler {
|
||||
// import '../input_handler.dart';
|
||||
|
||||
// class GizmoPickingHandler implements InputHandler {
|
||||
// final ThermionViewer viewer;
|
||||
// final bool enableCamera;
|
||||
// final bool enablePicking;
|
||||
// final Logger _logger = Logger("PickingCameraGestureHandler");
|
||||
// late final GizmoAsset _translationGizmo;
|
||||
|
||||
// AbstractGizmo? _gizmo;
|
||||
// Timer? _scrollTimer;
|
||||
// ThermionEntity? _highlightedEntity;
|
||||
// StreamSubscription<FilamentPickResult>? _pickResultSubscription;
|
||||
// GizmoPickingHandler(this.viewer) {}
|
||||
|
||||
// bool _gizmoAttached = false;
|
||||
// final _initialized = Completer<bool>();
|
||||
|
||||
// PickingCameraGestureHandler({
|
||||
// required this.viewer,
|
||||
// this.enableCamera = true,
|
||||
// this.enablePicking = true,
|
||||
// }) {
|
||||
// try {
|
||||
// _gizmo = viewer.gizmo;
|
||||
// } catch (err) {
|
||||
// _logger.warning(
|
||||
// "Failed to get gizmo. If you are running on WASM, this is expected");
|
||||
// Future initialize() async {
|
||||
// if (_initialized.isCompleted) {
|
||||
// throw Exception("Already initialized");
|
||||
// }
|
||||
// final view = await viewer.getViewAt(0);
|
||||
// _translationGizmo = await viewer.createGizmo(view, GizmoType.translation);
|
||||
// _initialized.complete(true);
|
||||
// }
|
||||
|
||||
// _pickResultSubscription = viewer.pickResult.listen(_onPickResult);
|
||||
|
||||
// // Add keyboard listener
|
||||
// RawKeyboard.instance.addListener(_handleKeyEvent);
|
||||
// Future dispose() async {
|
||||
// await viewer.removeEntity(_translationGizmo);
|
||||
// }
|
||||
|
||||
// @override
|
||||
// ThermionGestureState get currentState => _currentState;
|
||||
|
||||
// void _handleKeyEvent(RawKeyEvent event) {
|
||||
// if (event is RawKeyDownEvent &&
|
||||
// event.logicalKey == LogicalKeyboardKey.escape) {
|
||||
// _resetToNullState();
|
||||
// }
|
||||
// }
|
||||
|
||||
// void _resetToNullState() async {
|
||||
// _currentState = ThermionGestureState.NULL;
|
||||
// if (_highlightedEntity != null) {
|
||||
// await viewer.removeStencilHighlight(_highlightedEntity!);
|
||||
// _highlightedEntity = null;
|
||||
// }
|
||||
// }
|
||||
|
||||
// void _onPickResult(FilamentPickResult result) async {
|
||||
// var targetEntity = await viewer.getAncestor(result.entity) ?? result.entity;
|
||||
|
||||
// if (_highlightedEntity != targetEntity) {
|
||||
// if (_highlightedEntity != null) {
|
||||
// await viewer.removeStencilHighlight(_highlightedEntity!);
|
||||
// }
|
||||
|
||||
// _highlightedEntity = targetEntity;
|
||||
// if (_highlightedEntity != null) {
|
||||
// await viewer.setStencilHighlight(_highlightedEntity!);
|
||||
// _gizmo?.attach(_highlightedEntity!);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// Stream get cameraUpdated => throw UnimplementedError();
|
||||
|
||||
// @override
|
||||
// Future<void> onPointerHover(Offset localPosition, Offset delta) async {
|
||||
// if (_gizmoAttached) {
|
||||
// _gizmo?.checkHover(localPosition.dx, localPosition.dy);
|
||||
// }
|
||||
|
||||
// if (_highlightedEntity != null) {
|
||||
// await viewer.queuePositionUpdateFromViewportCoords(
|
||||
// _highlightedEntity!,
|
||||
// localPosition.dx,
|
||||
// localPosition.dy,
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Future<void> onPointerScroll(Offset localPosition, double scrollDelta) async {
|
||||
// if (!enableCamera) {
|
||||
// return;
|
||||
// }
|
||||
// if (_currentState == ThermionGestureState.NULL ||
|
||||
// _currentState == ThermionGestureState.ZOOMING) {
|
||||
// await _zoom(localPosition, scrollDelta);
|
||||
// }
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Future<void> onPointerDown(Offset localPosition, int buttons) async {
|
||||
// if (_highlightedEntity != null) {
|
||||
// _resetToNullState();
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (enablePicking && buttons != kMiddleMouseButton) {
|
||||
// viewer.pick(localPosition.dx.toInt(), localPosition.dy.toInt());
|
||||
// }
|
||||
|
||||
// if (buttons == kMiddleMouseButton && enableCamera) {
|
||||
// await viewer.rotateStart(localPosition.dx, localPosition.dy);
|
||||
// _currentState = ThermionGestureState.ROTATING;
|
||||
// } else if (buttons == kPrimaryMouseButton && enableCamera) {
|
||||
// await viewer.panStart(localPosition.dx, localPosition.dy);
|
||||
// _currentState = ThermionGestureState.PANNING;
|
||||
// }
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Future<void> onPointerMove(
|
||||
// Offset localPosition, Offset delta, int buttons) async {
|
||||
// if (_highlightedEntity != null) {
|
||||
// await _handleEntityHighlightedMove(localPosition);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// switch (_currentState) {
|
||||
// case ThermionGestureState.NULL:
|
||||
// break;
|
||||
|
||||
// case ThermionGestureState.ROTATING:
|
||||
// if (enableCamera) {
|
||||
// await viewer.rotateUpdate(localPosition.dx, localPosition.dy);
|
||||
// }
|
||||
// break;
|
||||
// case ThermionGestureState.PANNING:
|
||||
// if (enableCamera) {
|
||||
// await viewer.panUpdate(localPosition.dx, localPosition.dy);
|
||||
// }
|
||||
// break;
|
||||
// case ThermionGestureState.ZOOMING:
|
||||
// // ignore
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Future<void> onPointerUp(int buttons) async {
|
||||
// switch (_currentState) {
|
||||
// case ThermionGestureState.ROTATING:
|
||||
// await viewer.rotateEnd();
|
||||
// _currentState = ThermionGestureState.NULL;
|
||||
// break;
|
||||
// case ThermionGestureState.PANNING:
|
||||
// await viewer.panEnd();
|
||||
// _currentState = ThermionGestureState.NULL;
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Future<void> _handleEntityHighlightedMove(Offset localPosition) async {
|
||||
// if (_highlightedEntity != null) {
|
||||
// await viewer.queuePositionUpdateFromViewportCoords(
|
||||
// _highlightedEntity!,
|
||||
// localPosition.dx,
|
||||
// localPosition.dy,
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// Future<void> _zoom(Offset localPosition, double scrollDelta) async {
|
||||
// _scrollTimer?.cancel();
|
||||
// _currentState = ThermionGestureState.ZOOMING;
|
||||
// await viewer.zoomBegin();
|
||||
// await viewer.zoomUpdate(
|
||||
// localPosition.dx, localPosition.dy, scrollDelta > 0 ? 1 : -1);
|
||||
|
||||
// _scrollTimer = Timer(const Duration(milliseconds: 100), () async {
|
||||
// await viewer.zoomEnd();
|
||||
// _currentState = ThermionGestureState.NULL;
|
||||
// });
|
||||
// }
|
||||
|
||||
// @override
|
||||
// void dispose() {
|
||||
// _pickResultSubscription?.cancel();
|
||||
// if (_highlightedEntity != null) {
|
||||
// viewer.removeStencilHighlight(_highlightedEntity!);
|
||||
// }
|
||||
// RawKeyboard.instance.removeListener(_handleKeyEvent);
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Future<bool> get initialized => viewer.initialized;
|
||||
|
||||
// @override
|
||||
// InputAction getActionForType(InputType type) {
|
||||
// // TODO: implement getActionForType
|
||||
// InputAction? getActionForType(InputType gestureType) {
|
||||
// throw UnimplementedError();
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Future<void> onScaleEnd() {
|
||||
// Future<bool> get initialized => _initialized.future;
|
||||
|
||||
// @override
|
||||
// void keyDown(PhysicalKey key) {}
|
||||
|
||||
// @override
|
||||
// void keyUp(PhysicalKey key) {}
|
||||
|
||||
// @override
|
||||
// Future<void> onPointerDown(Vector2 localPosition, bool isMiddle) {
|
||||
// viewer.pick(localPosition.x.floor(), localPosition.y.floor(), (axis) {
|
||||
|
||||
// })
|
||||
// // _translationGizmo.pick(
|
||||
// // localPosition.x.floor(), localPosition.y.floor(), (axis) {});
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Future<void> onPointerHover(Vector2 localPosition, Vector2 delta) {
|
||||
// // TODO: implement onPointerHover
|
||||
// throw UnimplementedError();
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Future<void> onPointerMove(
|
||||
// Vector2 localPosition, Vector2 delta, bool isMiddle) {
|
||||
// // TODO: implement onPointerMove
|
||||
// throw UnimplementedError();
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Future<void> onPointerScroll(Vector2 localPosition, double scrollDelta) {
|
||||
// // TODO: implement onPointerScroll
|
||||
// throw UnimplementedError();
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Future<void> onPointerUp(bool isMiddle) {
|
||||
// // TODO: implement onPointerUp
|
||||
// throw UnimplementedError();
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Future<void> onScaleEnd(int pointerCount, double velocity) {
|
||||
// // TODO: implement onScaleEnd
|
||||
// throw UnimplementedError();
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Future<void> onScaleStart() {
|
||||
// Future<void> onScaleStart(
|
||||
// Vector2 focalPoint, int pointerCount, Duration? sourceTimestamp) {
|
||||
// // TODO: implement onScaleStart
|
||||
// throw UnimplementedError();
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Future<void> onScaleUpdate() {
|
||||
// Future<void> onScaleUpdate(
|
||||
// Vector2 focalPoint,
|
||||
// Vector2 focalPointDelta,
|
||||
// double horizontalScale,
|
||||
// double verticalScale,
|
||||
// double scale,
|
||||
// int pointerCount,
|
||||
// double rotation,
|
||||
// Duration? sourceTimestamp) {
|
||||
// // TODO: implement onScaleUpdate
|
||||
// throw UnimplementedError();
|
||||
// }
|
||||
|
||||
// @override
|
||||
// void setActionForType(InputType type, InputAction action) {
|
||||
// void setActionForType(InputType gestureType, InputAction gestureAction) {
|
||||
// // TODO: implement setActionForType
|
||||
// }
|
||||
// }
|
||||
// // final ThermionViewer viewer;
|
||||
// // final bool enableCamera;
|
||||
// // final bool enablePicking;
|
||||
// // final Logger _logger = Logger("PickingCameraGestureHandler");
|
||||
|
||||
// // AbstractGizmo? _gizmo;
|
||||
// // Timer? _scrollTimer;
|
||||
// // ThermionEntity? _highlightedEntity;
|
||||
// // StreamSubscription<FilamentPickResult>? _pickResultSubscription;
|
||||
|
||||
// // bool _gizmoAttached = false;
|
||||
|
||||
// // PickingCameraGestureHandler({
|
||||
// // required this.viewer,
|
||||
// // this.enableCamera = true,
|
||||
// // this.enablePicking = true,
|
||||
// // }) {
|
||||
// // try {
|
||||
// // _gizmo = viewer.gizmo;
|
||||
// // } catch (err) {
|
||||
// // _logger.warning(
|
||||
// // "Failed to get gizmo. If you are running on WASM, this is expected");
|
||||
// // }
|
||||
|
||||
// // _pickResultSubscription = viewer.pickResult.listen(_onPickResult);
|
||||
|
||||
// // // Add keyboard listener
|
||||
// // RawKeyboard.instance.addListener(_handleKeyEvent);
|
||||
// // }
|
||||
|
||||
// // @override
|
||||
// // ThermionGestureState get currentState => _currentState;
|
||||
|
||||
// // void _handleKeyEvent(RawKeyEvent event) {
|
||||
// // if (event is RawKeyDownEvent &&
|
||||
// // event.logicalKey == LogicalKeyboardKey.escape) {
|
||||
// // _resetToNullState();
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // void _resetToNullState() async {
|
||||
// // _currentState = ThermionGestureState.NULL;
|
||||
// // if (_highlightedEntity != null) {
|
||||
// // await viewer.removeStencilHighlight(_highlightedEntity!);
|
||||
// // _highlightedEntity = null;
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // void _onPickResult(FilamentPickResult result) async {
|
||||
// // var targetEntity = await viewer.getAncestor(result.entity) ?? result.entity;
|
||||
|
||||
// // if (_highlightedEntity != targetEntity) {
|
||||
// // if (_highlightedEntity != null) {
|
||||
// // await viewer.removeStencilHighlight(_highlightedEntity!);
|
||||
// // }
|
||||
|
||||
// // _highlightedEntity = targetEntity;
|
||||
// // if (_highlightedEntity != null) {
|
||||
// // await viewer.setStencilHighlight(_highlightedEntity!);
|
||||
// // _gizmo?.attach(_highlightedEntity!);
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // @override
|
||||
// // Future<void> onPointerHover(Offset localPosition, Offset delta) async {
|
||||
// // if (_gizmoAttached) {
|
||||
// // _gizmo?.checkHover(localPosition.dx, localPosition.dy);
|
||||
// // }
|
||||
|
||||
// // if (_highlightedEntity != null) {
|
||||
// // await viewer.queuePositionUpdateFromViewportCoords(
|
||||
// // _highlightedEntity!,
|
||||
// // localPosition.dx,
|
||||
// // localPosition.dy,
|
||||
// // );
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // @override
|
||||
// // Future<void> onPointerScroll(Offset localPosition, double scrollDelta) async {
|
||||
// // if (!enableCamera) {
|
||||
// // return;
|
||||
// // }
|
||||
// // if (_currentState == ThermionGestureState.NULL ||
|
||||
// // _currentState == ThermionGestureState.ZOOMING) {
|
||||
// // await _zoom(localPosition, scrollDelta);
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // @override
|
||||
// // Future<void> onPointerDown(Offset localPosition, int buttons) async {
|
||||
// // if (_highlightedEntity != null) {
|
||||
// // _resetToNullState();
|
||||
// // return;
|
||||
// // }
|
||||
|
||||
// // if (enablePicking && buttons != kMiddleMouseButton) {
|
||||
// // viewer.pick(localPosition.dx.toInt(), localPosition.dy.toInt());
|
||||
// // }
|
||||
|
||||
// // if (buttons == kMiddleMouseButton && enableCamera) {
|
||||
// // await viewer.rotateStart(localPosition.dx, localPosition.dy);
|
||||
// // _currentState = ThermionGestureState.ROTATING;
|
||||
// // } else if (buttons == kPrimaryMouseButton && enableCamera) {
|
||||
// // await viewer.panStart(localPosition.dx, localPosition.dy);
|
||||
// // _currentState = ThermionGestureState.PANNING;
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // @override
|
||||
// // Future<void> onPointerMove(
|
||||
// // Offset localPosition, Offset delta, int buttons) async {
|
||||
// // if (_highlightedEntity != null) {
|
||||
// // await _handleEntityHighlightedMove(localPosition);
|
||||
// // return;
|
||||
// // }
|
||||
|
||||
// // switch (_currentState) {
|
||||
// // case ThermionGestureState.NULL:
|
||||
// // break;
|
||||
|
||||
// // case ThermionGestureState.ROTATING:
|
||||
// // if (enableCamera) {
|
||||
// // await viewer.rotateUpdate(localPosition.dx, localPosition.dy);
|
||||
// // }
|
||||
// // break;
|
||||
// // case ThermionGestureState.PANNING:
|
||||
// // if (enableCamera) {
|
||||
// // await viewer.panUpdate(localPosition.dx, localPosition.dy);
|
||||
// // }
|
||||
// // break;
|
||||
// // case ThermionGestureState.ZOOMING:
|
||||
// // // ignore
|
||||
// // break;
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // @override
|
||||
// // Future<void> onPointerUp(int buttons) async {
|
||||
// // switch (_currentState) {
|
||||
// // case ThermionGestureState.ROTATING:
|
||||
// // await viewer.rotateEnd();
|
||||
// // _currentState = ThermionGestureState.NULL;
|
||||
// // break;
|
||||
// // case ThermionGestureState.PANNING:
|
||||
// // await viewer.panEnd();
|
||||
// // _currentState = ThermionGestureState.NULL;
|
||||
// // break;
|
||||
// // default:
|
||||
// // break;
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // Future<void> _handleEntityHighlightedMove(Offset localPosition) async {
|
||||
// // if (_highlightedEntity != null) {
|
||||
// // await viewer.queuePositionUpdateFromViewportCoords(
|
||||
// // _highlightedEntity!,
|
||||
// // localPosition.dx,
|
||||
// // localPosition.dy,
|
||||
// // );
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // Future<void> _zoom(Offset localPosition, double scrollDelta) async {
|
||||
// // _scrollTimer?.cancel();
|
||||
// // _currentState = ThermionGestureState.ZOOMING;
|
||||
// // await viewer.zoomBegin();
|
||||
// // await viewer.zoomUpdate(
|
||||
// // localPosition.dx, localPosition.dy, scrollDelta > 0 ? 1 : -1);
|
||||
|
||||
// // _scrollTimer = Timer(const Duration(milliseconds: 100), () async {
|
||||
// // await viewer.zoomEnd();
|
||||
// // _currentState = ThermionGestureState.NULL;
|
||||
// // });
|
||||
// // }
|
||||
|
||||
// // @override
|
||||
// // void dispose() {
|
||||
// // _pickResultSubscription?.cancel();
|
||||
// // if (_highlightedEntity != null) {
|
||||
// // viewer.removeStencilHighlight(_highlightedEntity!);
|
||||
// // }
|
||||
// // RawKeyboard.instance.removeListener(_handleKeyEvent);
|
||||
// // }
|
||||
|
||||
// // @override
|
||||
// // Future<bool> get initialized => viewer.initialized;
|
||||
|
||||
// // @override
|
||||
// // InputAction getActionForType(InputType type) {
|
||||
// // // TODO: implement getActionForType
|
||||
// // throw UnimplementedError();
|
||||
// // }
|
||||
|
||||
// // @override
|
||||
// // Future<void> onScaleEnd() {
|
||||
// // // TODO: implement onScaleEnd
|
||||
// // throw UnimplementedError();
|
||||
// // }
|
||||
|
||||
// // @override
|
||||
// // Future<void> onScaleStart() {
|
||||
// // // TODO: implement onScaleStart
|
||||
// // throw UnimplementedError();
|
||||
// // }
|
||||
|
||||
// // @override
|
||||
// // Future<void> onScaleUpdate() {
|
||||
// // // TODO: implement onScaleUpdate
|
||||
// // throw UnimplementedError();
|
||||
// // }
|
||||
|
||||
// // @override
|
||||
// // void setActionForType(InputType type, InputAction action) {
|
||||
// // // TODO: implement setActionForType
|
||||
// // }
|
||||
// // }
|
||||
|
||||
Reference in New Issue
Block a user