documentation & further renaming

This commit is contained in:
Nick Fisher
2024-06-15 21:26:08 +08:00
parent 3f88598498
commit dc0c855135
221 changed files with 5923 additions and 691 deletions

View File

@@ -1,16 +1,18 @@
import 'dart:async';
import 'dart:ui';
import 'package:thermion_dart/thermion_dart/abstract_filament_viewer.dart';
import 'package:thermion_dart/thermion_dart.dart';
import 'package:flutter/widgets.dart';
import 'package:thermion_flutter_platform_interface/thermion_flutter_platform_interface.dart';
import 'package:thermion_flutter_platform_interface/thermion_flutter_texture.dart';
///
/// A Flutter-only class that instantiates/wraps a [AbstractFilamentViewer],
/// handling all platform-specific initialization work necessary to create a
/// backing rendering surface.
/// Handles all platform-specific initialization work necessary to create a
/// backing rendering surface in a Flutter application.
/// Instantiates/wraps a [ThermionViewer],
///
class ThermionFlutterPlugin {
ThermionViewer get _viewer => ThermionFlutterPlatform.instance.viewer;
bool _wasRenderingOnInactive = false;
void _handleStateChange(AppLifecycleState state) async {
@@ -19,50 +21,51 @@ class ThermionFlutterPlugin {
case AppLifecycleState.detached:
print("Detached");
if (!_wasRenderingOnInactive) {
_wasRenderingOnInactive = viewer.rendering;
_wasRenderingOnInactive = _viewer.rendering;
}
await viewer.setRendering(false);
await _viewer.setRendering(false);
break;
case AppLifecycleState.hidden:
print("Hidden");
if (!_wasRenderingOnInactive) {
_wasRenderingOnInactive = viewer.rendering;
_wasRenderingOnInactive = _viewer.rendering;
}
await viewer.setRendering(false);
await _viewer.setRendering(false);
break;
case AppLifecycleState.inactive:
print("Inactive");
if (!_wasRenderingOnInactive) {
_wasRenderingOnInactive = viewer.rendering;
_wasRenderingOnInactive = _viewer.rendering;
}
// on Windows in particular, restoring a window after minimizing stalls the renderer (and the whole application) for a considerable length of time.
// disabling rendering on minimize seems to fix the issue (so I wonder if there's some kind of command buffer that's filling up while the window is minimized).
await viewer.setRendering(false);
await _viewer.setRendering(false);
break;
case AppLifecycleState.paused:
print("Paused");
if (!_wasRenderingOnInactive) {
_wasRenderingOnInactive = viewer.rendering;
_wasRenderingOnInactive = _viewer.rendering;
}
await viewer.setRendering(false);
await _viewer.setRendering(false);
break;
case AppLifecycleState.resumed:
print("Resumed");
await viewer.setRendering(_wasRenderingOnInactive);
await _viewer.setRendering(_wasRenderingOnInactive);
break;
}
}
AppLifecycleListener? _appLifecycleListener;
AbstractFilamentViewer get viewer => ThermionFlutterPlatform.instance.viewer;
final _initialized = Completer<bool>();
Future<bool> get initialized => _initialized.future;
Future initialize({String? uberArchivePath}) async {
bool _initializing = false;
Future<ThermionViewer> initialize({String? uberArchivePath}) async {
_initializing = true;
if (_initialized.isCompleted) {
throw Exception("Instance already initialized");
return ThermionFlutterPlatform.instance.viewer;
}
await ThermionFlutterPlatform.instance
.initialize(uberArchivePath: uberArchivePath);
@@ -70,9 +73,10 @@ class ThermionFlutterPlugin {
_appLifecycleListener = AppLifecycleListener(
onStateChange: _handleStateChange,
);
_viewer.initialized;
_initialized.complete(true);
await viewer.initialized;
_initializing = false;
return ThermionFlutterPlatform.instance.viewer;
}
Future<ThermionFlutterTexture?> createTexture(

View File

@@ -1,5 +1,5 @@
import 'package:thermion_dart/thermion_dart/entities/filament_entity.dart';
import 'package:thermion_dart/thermion_dart/abstract_filament_viewer.dart';import 'package:flutter/material.dart';
import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import '../../utils/camera_orientation.dart';
@@ -7,9 +7,9 @@ import 'dart:math';
import 'package:vector_math/vector_math_64.dart' as v64;
class CameraOptionsWidget extends StatefulWidget {
final AbstractFilamentViewer controller;
final ThermionViewer controller;
final CameraOrientation cameraOrientation;
final List<({FilamentEntity entity, String name})> cameras;
final List<({ThermionEntity entity, String name})> cameras;
CameraOptionsWidget(
{super.key,

View File

@@ -1,6 +1,6 @@
import 'dart:io';
import 'package:thermion_dart/thermion_dart/abstract_filament_viewer.dart';
import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'filament_gesture_detector_desktop.dart';
@@ -14,15 +14,15 @@ enum GestureType { rotateCamera, panCamera, panBackground }
class FilamentGestureDetector extends StatelessWidget {
///
/// The content to display below the gesture detector/listener widget.
/// This will usually be a FilamentWidget (so you can navigate by directly interacting with the viewport), but this is not necessary.
/// This will usually be a ThermionWidget (so you can navigate by directly interacting with the viewport), but this is not necessary.
/// It is equally possible to render the viewport/gesture controls elsewhere in the widget hierarchy. The only requirement is that they share the same [FilamentController].
///
final Widget? child;
///
/// The [controller] attached to the [FilamentWidget] you wish to control.
/// The [controller] attached to the [ThermionWidget] you wish to control.
///
final AbstractFilamentViewer controller;
final ThermionViewer controller;
///
/// If true, an overlay will be shown with buttons to toggle whether pointer movements are interpreted as:

View File

@@ -1,6 +1,6 @@
import 'dart:async';
import 'package:thermion_dart/thermion_dart/abstract_filament_viewer.dart';
import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
@@ -10,15 +10,15 @@ import 'package:flutter/material.dart';
class FilamentGestureDetectorDesktop extends StatefulWidget {
///
/// The content to display below the gesture detector/listener widget.
/// This will usually be a FilamentWidget (so you can navigate by directly interacting with the viewport), but this is not necessary.
/// This will usually be a ThermionWidget (so you can navigate by directly interacting with the viewport), but this is not necessary.
/// It is equally possible to render the viewport/gesture controls elsewhere in the widget hierarchy. The only requirement is that they share the same [FilamentController].
///
final Widget? child;
///
/// The [controller] attached to the [FilamentWidget] you wish to control.
/// The [controller] attached to the [ThermionWidget] you wish to control.
///
final AbstractFilamentViewer controller;
final ThermionViewer controller;
///
/// If true, an overlay will be shown with buttons to toggle whether pointer movements are interpreted as:

View File

@@ -1,5 +1,5 @@
import 'dart:async';
import 'package:thermion_dart/thermion_dart/abstract_filament_viewer.dart';
import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';
import 'package:flutter/material.dart';
enum GestureType { rotateCamera, panCamera, panBackground }
@@ -10,15 +10,15 @@ enum GestureType { rotateCamera, panCamera, panBackground }
class FilamentGestureDetectorMobile extends StatefulWidget {
///
/// The content to display below the gesture detector/listener widget.
/// This will usually be a FilamentWidget (so you can navigate by directly interacting with the viewport), but this is not necessary.
/// This will usually be a ThermionWidget (so you can navigate by directly interacting with the viewport), but this is not necessary.
/// It is equally possible to render the viewport/gesture controls elsewhere in the widget hierarchy. The only requirement is that they share the same [FilamentController].
///
final Widget? child;
///
/// The [controller] attached to the [FilamentWidget] you wish to control.
/// The [controller] attached to the [ThermionWidget] you wish to control.
///
final AbstractFilamentViewer controller;
final ThermionViewer controller;
///
/// If true, an overlay will be shown with buttons to toggle whether pointer movements are interpreted as:

View File

@@ -1,18 +1,18 @@
import 'package:animation_tools_dart/animation_tools_dart.dart';
import 'package:thermion_dart/thermion_dart/abstract_filament_viewer.dart';
import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';
import 'package:thermion_dart/thermion_dart/entities/filament_entity.dart';
import 'package:flutter/material.dart';
import 'package:thermion_flutter/filament/widgets/debug/skeleton_menu_item_widget.dart';
import 'dart:math';
class ChildRenderableWidget extends StatelessWidget {
final AbstractFilamentViewer controller;
final FilamentEntity entity;
final ThermionViewer controller;
final ThermionEntity entity;
const ChildRenderableWidget(
{super.key, required this.controller, required this.entity});
Widget _childRenderable(FilamentEntity childEntity) {
Widget _childRenderable(ThermionEntity childEntity) {
var name = controller.getNameForEntity(childEntity) ?? "<none>";
var names = controller.getMorphTargetNames(entity, childEntity);

View File

@@ -1,11 +1,11 @@
import 'package:thermion_dart/thermion_dart/abstract_filament_viewer.dart';
import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';
import 'package:thermion_dart/thermion_dart/entities/filament_entity.dart';
import 'package:thermion_flutter/filament/widgets/debug/child_renderable_widget.dart';
import 'package:flutter/material.dart';
import 'package:thermion_flutter/filament/widgets/debug/skeleton_menu_item_widget.dart';
class EntityListWidget extends StatefulWidget {
final AbstractFilamentViewer? controller;
final ThermionViewer? controller;
const EntityListWidget({super.key, required this.controller});
@@ -19,7 +19,7 @@ class _EntityListWidget extends State<EntityListWidget> {
super.didUpdateWidget(oldWidget);
}
Widget _entity(FilamentEntity entity) {
Widget _entity(ThermionEntity entity) {
return FutureBuilder(
future: widget.controller!.getAnimationNames(entity),
builder: (_, animations) {
@@ -108,7 +108,7 @@ class _EntityListWidget extends State<EntityListWidget> {
});
}
Widget _light(FilamentEntity entity) {
Widget _light(ThermionEntity entity) {
final controller = MenuController();
return Row(children: [
GestureDetector(

View File

@@ -1,15 +1,15 @@
import 'dart:math';
import 'package:thermion_dart/thermion_dart.dart';
import 'package:thermion_dart/thermion_dart/abstract_filament_viewer.dart';
import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';
import 'package:animation_tools_dart/animation_tools_dart.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:vector_math/vector_math_64.dart';
class SkeletonMenuItemWidget extends StatelessWidget {
final AbstractFilamentViewer controller;
final FilamentEntity entity;
final ThermionViewer controller;
final ThermionEntity entity;
const SkeletonMenuItemWidget(
{super.key, required this.controller, required this.entity});

View File

@@ -1,10 +1,10 @@
import 'dart:math';
import 'package:thermion_dart/thermion_dart/abstract_filament_viewer.dart';
import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';
import 'package:flutter/material.dart';
import 'package:vector_math/vector_math_64.dart' as v;
class IblRotationSliderWidget extends StatefulWidget {
final AbstractFilamentViewer controller;
final ThermionViewer controller;
const IblRotationSliderWidget({super.key, required this.controller});
@override

View File

@@ -1,5 +1,5 @@
import 'package:thermion_dart/thermion_dart/entities/filament_entity.dart';
import 'package:thermion_dart/thermion_dart/abstract_filament_viewer.dart';
import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';
import 'package:thermion_dart/thermion_dart/utils/light_options.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
@@ -7,7 +7,7 @@ import 'package:flutter/widgets.dart';
import 'package:vector_math/vector_math_64.dart' as v;
class LightSliderWidget extends StatefulWidget {
final AbstractFilamentViewer controller;
final ThermionViewer controller;
final LightOptions options;
final bool showControls;
@@ -22,7 +22,7 @@ class LightSliderWidget extends StatefulWidget {
}
class _LightSliderWidgetState extends State<LightSliderWidget> {
FilamentEntity? _light;
ThermionEntity? _light;
@override
void initState() {

View File

@@ -8,7 +8,7 @@ import 'package:thermion_flutter_platform_interface/thermion_flutter_texture.dar
import 'package:thermion_flutter/thermion_flutter.dart';
import 'resize_observer.dart';
class FilamentWidget extends StatefulWidget {
class ThermionWidget extends StatefulWidget {
final ThermionFlutterPlugin plugin;
///
@@ -17,20 +17,20 @@ class FilamentWidget extends StatefulWidget {
///
final Widget? initial;
const FilamentWidget({Key? key, this.initial, required this.plugin})
const ThermionWidget({Key? key, this.initial, required this.plugin})
: super(key: key);
@override
_FilamentWidgetState createState() => _FilamentWidgetState();
_ThermionWidgetState createState() => _ThermionWidgetState();
}
class _FilamentWidgetState extends State<FilamentWidget> {
class _ThermionWidgetState extends State<ThermionWidget> {
ThermionFlutterTexture? _texture;
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
await widget.plugin.initialized;
var dpr = MediaQuery.of(context).devicePixelRatio;
var size = ((context.findRenderObject()) as RenderBox).size;
var width = (dpr * size.width).ceil();
@@ -72,14 +72,12 @@ class _FilamentWidgetState extends State<FilamentWidget> {
@override
Widget build(BuildContext context) {
if (_texture?.usesBackingWindow == true) {
return Stack(children: [
Positioned.fill(child: CustomPaint(painter: TransparencyPainter()))
]);
}
if (_texture == null || _resizing) {
return widget.initial ??
Container(color: kIsWeb ? Colors.transparent : Colors.red);
@@ -107,7 +105,6 @@ class _FilamentWidgetState extends State<FilamentWidget> {
}
}
class TransparencyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
@@ -121,4 +118,4 @@ class TransparencyPainter extends CustomPainter {
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}
}

View File

@@ -1,4 +1,4 @@
library thermion_flutter;
export 'filament/thermion_flutter_plugin.dart';
export 'thermion/thermion_flutter_plugin.dart';
export 'package:thermion_dart/thermion_dart.dart';