refactoring
This commit is contained in:
@@ -11,40 +11,13 @@ import 'package:thermion_flutter_platform_interface/thermion_flutter_platform_in
|
|||||||
class ThermionFlutterPlugin {
|
class ThermionFlutterPlugin {
|
||||||
ThermionFlutterPlugin._();
|
ThermionFlutterPlugin._();
|
||||||
|
|
||||||
static bool _initializing = false;
|
|
||||||
|
|
||||||
static ThermionViewer? _viewer;
|
|
||||||
|
|
||||||
static ThermionFlutterOptions? options;
|
|
||||||
|
|
||||||
static Future<ThermionViewer> createViewer(
|
static Future<ThermionViewer> createViewer(
|
||||||
{ThermionFlutterOptions options =
|
{ThermionFlutterOptions options =
|
||||||
const ThermionFlutterOptions.empty()}) async {
|
const ThermionFlutterOptions()}) async {
|
||||||
if (_initializing) {
|
|
||||||
throw Exception("Existing call to createViewer has not completed.");
|
|
||||||
}
|
|
||||||
_initializing = true;
|
|
||||||
|
|
||||||
if (_viewer != null) {
|
final viewer =
|
||||||
throw Exception(
|
|
||||||
"Instance of ThermionViewer has already been created. Ensure you call dispose() on that instance.");
|
|
||||||
}
|
|
||||||
|
|
||||||
options = options;
|
|
||||||
|
|
||||||
_viewer =
|
|
||||||
await ThermionFlutterPlatform.instance.createViewer(options: options);
|
await ThermionFlutterPlatform.instance.createViewer(options: options);
|
||||||
|
|
||||||
await _viewer!.initialized;
|
return viewer;
|
||||||
|
|
||||||
var camera = await _viewer!.getActiveCamera();
|
|
||||||
await camera.setLensProjection();
|
|
||||||
|
|
||||||
_viewer!.onDispose(() async {
|
|
||||||
_viewer = null;
|
|
||||||
ThermionFlutterPlugin.options = null;
|
|
||||||
});
|
|
||||||
_initializing = false;
|
|
||||||
return _viewer!;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
import 'package:vector_math/vector_math_64.dart' as v;
|
import 'package:vector_math/vector_math_64.dart';
|
||||||
|
|
||||||
class CameraOrientation {
|
class CameraOrientation {
|
||||||
v.Vector3 position = v.Vector3(0, 0, 0);
|
Vector3 position = Vector3.zero();
|
||||||
|
Vector3 rotation = Vector3.zero();
|
||||||
|
|
||||||
var rotationX = 0.0;
|
Matrix4 compose() {
|
||||||
var rotationY = 0.0;
|
final quat = Quaternion.axisAngle(Vector3(0, 0, 1), rotation.z) *
|
||||||
var rotationZ = 0.0;
|
Quaternion.axisAngle(Vector3(0, 1, 0), rotation.y) *
|
||||||
|
Quaternion.axisAngle(Vector3(1, 0, 0), rotation.x);
|
||||||
v.Quaternion compose() {
|
return Matrix4.compose(position, quat, Vector3.all(1));
|
||||||
return v.Quaternion.axisAngle(v.Vector3(0, 0, 1), rotationZ) *
|
|
||||||
v.Quaternion.axisAngle(v.Vector3(0, 1, 0), rotationY) *
|
|
||||||
v.Quaternion.axisAngle(v.Vector3(1, 0, 0), rotationX);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
|
|
||||||
import 'package:thermion_dart/thermion_dart.dart';
|
import 'package:thermion_dart/thermion_dart.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../../../utils/camera_orientation.dart';
|
import '../../../utils/camera_orientation.dart';
|
||||||
|
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
|
|
||||||
class CameraOptionsWidget extends StatefulWidget {
|
class CameraOptionsWidget extends StatefulWidget {
|
||||||
final ThermionViewer controller;
|
final Camera camera;
|
||||||
final CameraOrientation cameraOrientation;
|
final CameraOrientation cameraOrientation;
|
||||||
final List<({ThermionEntity entity, String name})> cameras;
|
|
||||||
|
|
||||||
CameraOptionsWidget(
|
CameraOptionsWidget(
|
||||||
{super.key,
|
{super.key, required this.camera, required this.cameraOrientation}) {}
|
||||||
required this.controller,
|
|
||||||
required this.cameras,
|
|
||||||
required this.cameraOrientation}) {}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() => _CameraOptionsWidgetState();
|
State<StatefulWidget> createState() => _CameraOptionsWidgetState();
|
||||||
@@ -51,24 +45,17 @@ class _CameraOptionsWidgetState extends State<CameraOptionsWidget> {
|
|||||||
@override
|
@override
|
||||||
void didUpdateWidget(CameraOptionsWidget oldWidget) {
|
void didUpdateWidget(CameraOptionsWidget oldWidget) {
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
if (oldWidget.cameras.length != widget.cameras.length) {
|
if (oldWidget.camera != widget.camera) {
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _set() async {
|
Future _set() async {
|
||||||
await widget.controller.setCameraExposure(
|
await widget.camera.setCameraExposure(
|
||||||
double.parse(_apertureController.text),
|
double.parse(_apertureController.text),
|
||||||
double.parse(_speedController.text),
|
double.parse(_speedController.text),
|
||||||
double.parse(_sensitivityController.text));
|
double.parse(_sensitivityController.text));
|
||||||
await widget.controller.setCameraPosition(
|
await widget.camera.setModelMatrix(widget.cameraOrientation.compose());
|
||||||
widget.cameraOrientation.position.x,
|
|
||||||
widget.cameraOrientation.position.y,
|
|
||||||
widget.cameraOrientation.position.z);
|
|
||||||
var rotation = widget.cameraOrientation.compose();
|
|
||||||
await widget.controller.setCameraRotation(rotation);
|
|
||||||
print(
|
|
||||||
"Camera : ${widget.cameraOrientation.position} ${widget.cameraOrientation.rotationX} ${widget.cameraOrientation.rotationY} ${widget.cameraOrientation.rotationZ}");
|
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,34 +85,20 @@ class _CameraOptionsWidgetState extends State<CameraOptionsWidget> {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: TextField(controller: _sensitivityController)),
|
child: TextField(controller: _sensitivityController)),
|
||||||
]),
|
]),
|
||||||
Row(children: [
|
// Row(children: [
|
||||||
Text("Bloom: ${_bloom.toStringAsFixed(2)}"),
|
// const Text("Focal length"),
|
||||||
Slider(
|
// Slider(
|
||||||
value: _bloom,
|
// label: _focalLength.toString(),
|
||||||
min: 0.0,
|
// value: _focalLength,
|
||||||
max: 1.0,
|
// min: 1.0,
|
||||||
onChanged: (v) async {
|
// max: 100.0,
|
||||||
setState(() {
|
// onChanged: (v) async {
|
||||||
_bloom = v;
|
// setState(() {
|
||||||
});
|
// _focalLength = v;
|
||||||
await widget.controller.setBloom(_bloom);
|
// });
|
||||||
})
|
// await widget.camera.setLensProjection(near: kNear, far:kFar, _focalLength);
|
||||||
]),
|
// })
|
||||||
Row(children: [
|
// ]),
|
||||||
const Text("Focal length"),
|
|
||||||
Slider(
|
|
||||||
label: _focalLength.toString(),
|
|
||||||
value: _focalLength,
|
|
||||||
min: 1.0,
|
|
||||||
max: 100.0,
|
|
||||||
onChanged: (v) async {
|
|
||||||
setState(() {
|
|
||||||
_focalLength = v;
|
|
||||||
});
|
|
||||||
await widget.controller
|
|
||||||
.setCameraFocalLength(_focalLength);
|
|
||||||
})
|
|
||||||
]),
|
|
||||||
Row(children: [
|
Row(children: [
|
||||||
const Text("X"),
|
const Text("X"),
|
||||||
Slider(
|
Slider(
|
||||||
@@ -140,94 +113,6 @@ class _CameraOptionsWidgetState extends State<CameraOptionsWidget> {
|
|||||||
_set();
|
_set();
|
||||||
})
|
})
|
||||||
]),
|
]),
|
||||||
Row(children: [
|
|
||||||
const Text("Y"),
|
|
||||||
Slider(
|
|
||||||
label: widget.cameraOrientation.position.y.toString(),
|
|
||||||
value: widget.cameraOrientation.position.y,
|
|
||||||
min: -100.0,
|
|
||||||
max: 100.0,
|
|
||||||
onChanged: (v) async {
|
|
||||||
setState(() {
|
|
||||||
widget.cameraOrientation.position.y = v;
|
|
||||||
});
|
|
||||||
_set();
|
|
||||||
})
|
|
||||||
]),
|
|
||||||
Row(children: [
|
|
||||||
const Text("Z"),
|
|
||||||
Slider(
|
|
||||||
label: widget.cameraOrientation.position.z.toString(),
|
|
||||||
value: widget.cameraOrientation.position.z,
|
|
||||||
min: -100.0,
|
|
||||||
max: 100.0,
|
|
||||||
onChanged: (v) async {
|
|
||||||
setState(() {
|
|
||||||
widget.cameraOrientation.position.z = v;
|
|
||||||
});
|
|
||||||
_set();
|
|
||||||
})
|
|
||||||
]),
|
|
||||||
Row(children: [
|
|
||||||
const Text("ROTX"),
|
|
||||||
Slider(
|
|
||||||
label: widget.cameraOrientation.rotationX.toString(),
|
|
||||||
value: widget.cameraOrientation.rotationX,
|
|
||||||
min: -pi,
|
|
||||||
max: pi,
|
|
||||||
onChanged: (value) async {
|
|
||||||
setState(() {
|
|
||||||
widget.cameraOrientation.rotationX = value;
|
|
||||||
});
|
|
||||||
_set();
|
|
||||||
})
|
|
||||||
]),
|
|
||||||
Row(children: [
|
|
||||||
const Text("ROTY"),
|
|
||||||
Slider(
|
|
||||||
label: widget.cameraOrientation.rotationY.toString(),
|
|
||||||
value: widget.cameraOrientation.rotationY,
|
|
||||||
min: -pi,
|
|
||||||
max: pi,
|
|
||||||
onChanged: (v) async {
|
|
||||||
setState(() {
|
|
||||||
widget.cameraOrientation.rotationY = v;
|
|
||||||
});
|
|
||||||
_set();
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
Row(children: [
|
|
||||||
const Text("ROTZ"),
|
|
||||||
Slider(
|
|
||||||
label: widget.cameraOrientation.rotationZ.toString(),
|
|
||||||
value: widget.cameraOrientation.rotationZ,
|
|
||||||
min: -pi,
|
|
||||||
max: pi,
|
|
||||||
onChanged: (v) async {
|
|
||||||
setState(() {
|
|
||||||
widget.cameraOrientation.rotationZ = v;
|
|
||||||
});
|
|
||||||
_set();
|
|
||||||
})
|
|
||||||
]),
|
|
||||||
Wrap(
|
|
||||||
children: [
|
|
||||||
GestureDetector(
|
|
||||||
child: const Text("Main "),
|
|
||||||
onTap: () {
|
|
||||||
widget.controller.setMainCamera();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
...widget.cameras
|
|
||||||
.map((camera) => GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
widget.controller
|
|
||||||
.setCamera(camera.entity, camera.name);
|
|
||||||
},
|
|
||||||
child: Text(camera.name)))
|
|
||||||
.toList()
|
|
||||||
],
|
|
||||||
)
|
|
||||||
]))));
|
]))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,16 @@ import 'package:vector_math/vector_math_64.dart' as v64;
|
|||||||
class CameraOrientationWidget extends StatefulWidget {
|
class CameraOrientationWidget extends StatefulWidget {
|
||||||
final ThermionViewer viewer;
|
final ThermionViewer viewer;
|
||||||
|
|
||||||
const CameraOrientationWidget({Key? key, required this.viewer}) : super(key: key);
|
const CameraOrientationWidget({Key? key, required this.viewer})
|
||||||
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_CameraOrientationWidgetState createState() => _CameraOrientationWidgetState();
|
_CameraOrientationWidgetState createState() =>
|
||||||
|
_CameraOrientationWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CameraOrientationWidgetState extends State<CameraOrientationWidget> with SingleTickerProviderStateMixin {
|
class _CameraOrientationWidgetState extends State<CameraOrientationWidget>
|
||||||
|
with SingleTickerProviderStateMixin {
|
||||||
late AnimationController _controller;
|
late AnimationController _controller;
|
||||||
v64.Vector3? _position;
|
v64.Vector3? _position;
|
||||||
v64.Matrix3? _rotation;
|
v64.Matrix3? _rotation;
|
||||||
@@ -30,6 +33,7 @@ class _CameraOrientationWidgetState extends State<CameraOrientationWidget> with
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _updateCameraInfo() async {
|
void _updateCameraInfo() async {
|
||||||
|
final camera = await widget.viewer.getActiveCamera();
|
||||||
final position = await widget.viewer.getCameraPosition();
|
final position = await widget.viewer.getCameraPosition();
|
||||||
final rotation = await widget.viewer.getCameraRotation();
|
final rotation = await widget.viewer.getCameraRotation();
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|||||||
@@ -75,7 +75,6 @@ class _ThermionWidgetState extends State<ThermionWidget> {
|
|||||||
key: ObjectKey(widget.viewer),
|
key: ObjectKey(widget.viewer),
|
||||||
initial: widget.initial,
|
initial: widget.initial,
|
||||||
viewer: widget.viewer,
|
viewer: widget.viewer,
|
||||||
view: widget.viewer.view,
|
|
||||||
showFpsCounter: widget.showFpsCounter,
|
showFpsCounter: widget.showFpsCounter,
|
||||||
onResize: widget.onResize);
|
onResize: widget.onResize);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ class _ViewerWidgetState extends State<ViewerWidget> {
|
|||||||
Future _tearDown() async {
|
Future _tearDown() async {
|
||||||
await viewer!.dispose();
|
await viewer!.dispose();
|
||||||
if (widget.options.destroyAppOnUnload) {
|
if (widget.options.destroyAppOnUnload) {
|
||||||
await viewer!.app.destroy();
|
await FilamentApp.instance!.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user