renaming to Thermion
This commit is contained in:
139
examples/flutter/example/lib/camera_matrix_overlay.dart
Normal file
139
examples/flutter/example/lib/camera_matrix_overlay.dart
Normal file
@@ -0,0 +1,139 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:thermion_flutter/thermion_flutter.dart';
|
||||
import 'package:vector_math/vector_math_64.dart' as v;
|
||||
import 'package:thermion_dart/thermion_dart/abstract_filament_viewer.dart';
|
||||
|
||||
class CameraMatrixOverlay extends StatefulWidget {
|
||||
final AbstractFilamentViewer controller;
|
||||
final bool showProjectionMatrices;
|
||||
|
||||
const CameraMatrixOverlay(
|
||||
{super.key,
|
||||
required this.controller,
|
||||
required this.showProjectionMatrices});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _CameraMatrixOverlayState();
|
||||
}
|
||||
|
||||
class _CameraMatrixOverlayState extends State<CameraMatrixOverlay> {
|
||||
Timer? _cameraTimer;
|
||||
String? _cameraPosition;
|
||||
String? _cameraRotation;
|
||||
|
||||
String? _cameraProjectionMatrix;
|
||||
String? _cameraCullingProjectionMatrix;
|
||||
|
||||
void _tick(Timer timer) async {
|
||||
var cameraPosition = await widget.controller.getCameraPosition();
|
||||
var cameraRotation = await widget.controller.getCameraRotation();
|
||||
|
||||
_cameraPosition =
|
||||
"${cameraPosition.storage.map((v) => v.toStringAsFixed(2))}";
|
||||
_cameraRotation =
|
||||
"${cameraRotation.storage.map((v) => v.toStringAsFixed(2))}";
|
||||
|
||||
if (widget.showProjectionMatrices) {
|
||||
var projMatrix = await widget.controller.getCameraProjectionMatrix();
|
||||
var cullingMatrix =
|
||||
await widget.controller.getCameraCullingProjectionMatrix();
|
||||
|
||||
_cameraProjectionMatrix =
|
||||
projMatrix.storage.map((v) => v.toStringAsFixed(2)).join(",");
|
||||
_cameraCullingProjectionMatrix =
|
||||
cullingMatrix.storage.map((v) => v.toStringAsFixed(2)).join(",");
|
||||
_getFrustum();
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
void _updateTimer() async {
|
||||
_cameraTimer?.cancel();
|
||||
await widget.controller.initialized;
|
||||
}
|
||||
|
||||
v.Frustum? _frustum;
|
||||
|
||||
void _getFrustum() async {
|
||||
_frustum = await widget.controller.getCameraFrustum();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_updateTimer();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(CameraMatrixOverlay oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_cameraTimer?.cancel();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
borderRadius: BorderRadius.circular(29)),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
Text("Camera : $_cameraPosition $_cameraRotation",
|
||||
style:
|
||||
const TextStyle(color: Colors.white, fontSize: 10)),
|
||||
// widget.showProjectionMatrices
|
||||
// ? Text("Projection matrix : $_cameraProjectionMatrix",
|
||||
// style: const TextStyle(color: Colors.white, fontSize: 12))
|
||||
// : Container(),
|
||||
// widget.showProjectionMatrices
|
||||
// ? Text("Culling matrix : $_cameraCullingProjectionMatrix",
|
||||
// style: const TextStyle(color: Colors.white, fontSize: 12))
|
||||
// : Container(),
|
||||
widget.showProjectionMatrices
|
||||
? const Text("Frustum matrix",
|
||||
style: TextStyle(color: Colors.white, fontSize: 10))
|
||||
: Container()
|
||||
] +
|
||||
(_frustum == null
|
||||
? []
|
||||
: [
|
||||
_frustum!.plane0,
|
||||
_frustum!.plane1,
|
||||
_frustum!.plane2,
|
||||
_frustum!.plane3,
|
||||
_frustum!.plane4,
|
||||
_frustum!.plane5
|
||||
]
|
||||
.map((plane) => Row(
|
||||
children: [
|
||||
plane.normal.x,
|
||||
plane.normal.y,
|
||||
plane.normal.z,
|
||||
plane.constant
|
||||
]
|
||||
.map((v) => Text(
|
||||
v.toStringAsFixed(2) + " ",
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 10),
|
||||
textAlign: TextAlign.center,
|
||||
))
|
||||
.cast<Widget>()
|
||||
.toList()))
|
||||
.cast<Widget>()
|
||||
.toList())));
|
||||
}
|
||||
}
|
||||
37
examples/flutter/example/lib/example_viewport.dart
Normal file
37
examples/flutter/example/lib/example_viewport.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:thermion_flutter/filament/widgets/camera/entity_controller_mouse_widget.dart';
|
||||
import 'package:thermion_flutter/filament/widgets/camera/gestures/filament_gesture_detector.dart';
|
||||
import 'package:thermion_flutter/filament/widgets/filament_widget.dart';
|
||||
import 'package:thermion_flutter/thermion_flutter.dart';
|
||||
import 'package:thermion_dart/thermion_dart/entities/entity_transform_controller.dart';
|
||||
|
||||
|
||||
class ExampleViewport extends StatelessWidget {
|
||||
final ThermionFlutterPlugin? controller;
|
||||
final EntityTransformController? entityTransformController;
|
||||
final EdgeInsets padding;
|
||||
final FocusNode keyboardFocusNode;
|
||||
|
||||
const ExampleViewport(
|
||||
{super.key,
|
||||
required this.controller,
|
||||
required this.padding,
|
||||
required this.keyboardFocusNode,
|
||||
this.entityTransformController});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return controller != null
|
||||
? Padding(
|
||||
padding: padding,
|
||||
child: EntityTransformMouseControllerWidget(
|
||||
transformController: entityTransformController,
|
||||
child: FilamentGestureDetector(
|
||||
showControlOverlay: true,
|
||||
controller: controller!.viewer,
|
||||
child: FilamentWidget(
|
||||
plugin: controller!,
|
||||
))))
|
||||
: Container();
|
||||
}
|
||||
}
|
||||
203
examples/flutter/example/lib/main.dart
Normal file
203
examples/flutter/example/lib/main.dart
Normal file
@@ -0,0 +1,203 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:thermion_flutter/filament/widgets/debug/entity_list_widget.dart';
|
||||
import 'package:thermion_flutter_example/camera_matrix_overlay.dart';
|
||||
import 'package:thermion_flutter_example/menus/controller_menu.dart';
|
||||
import 'package:thermion_flutter_example/example_viewport.dart';
|
||||
import 'package:thermion_dart/thermion_dart/entities/entity_transform_controller.dart';
|
||||
import 'package:thermion_flutter_example/menus/scene_menu.dart';
|
||||
import 'package:thermion_flutter/thermion_flutter.dart';
|
||||
import 'package:thermion_flutter_example/picker_result_widget.dart';
|
||||
|
||||
|
||||
const loadDefaultScene = bool.hasEnvironment('--load-default-scene');
|
||||
|
||||
void main() async {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MyApp> createState() => _MyAppState();
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(
|
||||
useMaterial3: true,
|
||||
textTheme: const TextTheme(
|
||||
labelLarge: TextStyle(fontSize: 12),
|
||||
displayMedium: TextStyle(fontSize: 12),
|
||||
headlineMedium: const TextStyle(fontSize: 12),
|
||||
titleMedium: TextStyle(fontSize: 12),
|
||||
bodyLarge: TextStyle(fontSize: 14),
|
||||
bodyMedium: TextStyle(fontSize: 12))),
|
||||
// showPerformanceOverlay: true,
|
||||
home: const Scaffold(
|
||||
backgroundColor: Color(0x00000000),
|
||||
body: ExampleWidget()));
|
||||
}
|
||||
}
|
||||
|
||||
class ExampleWidget extends StatefulWidget {
|
||||
const ExampleWidget({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return ExampleWidgetState();
|
||||
}
|
||||
}
|
||||
|
||||
enum MenuType { controller, assets, camera, misc }
|
||||
|
||||
class ExampleWidgetState extends State<ExampleWidget> {
|
||||
final _plugin = ThermionFlutterPlugin();
|
||||
|
||||
EdgeInsets _viewportMargin = EdgeInsets.zero;
|
||||
|
||||
// these are all the options that can be set via the menu
|
||||
// we store them here
|
||||
static bool rendering = false;
|
||||
static bool recording = false;
|
||||
static int framerate = 60;
|
||||
static bool postProcessing = false;
|
||||
static bool antiAliasingMsaa = false;
|
||||
static bool antiAliasingTaa = false;
|
||||
static bool antiAliasingFxaa = false;
|
||||
static bool frustumCulling = true;
|
||||
|
||||
static double zoomSpeed = 0.01;
|
||||
static double orbitSpeedX = 0.01;
|
||||
static double orbitSpeedY = 0.01;
|
||||
|
||||
static bool hasSkybox = false;
|
||||
static bool coneHidden = false;
|
||||
|
||||
static bool loop = false;
|
||||
static final showProjectionMatrices = ValueNotifier<bool>(false);
|
||||
|
||||
late StreamSubscription _listener;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_listener.cancel();
|
||||
}
|
||||
|
||||
EntityTransformController? _transformController;
|
||||
|
||||
final _sharedFocusNode = FocusNode();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
future: _plugin.initialized,
|
||||
builder: (_, AsyncSnapshot<bool> initialized) {
|
||||
var isInitialized = initialized.data == true;
|
||||
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
if (isInitialized)
|
||||
Positioned.fill(
|
||||
child: ExampleViewport(
|
||||
controller: isInitialized ? _plugin : null,
|
||||
entityTransformController: _transformController,
|
||||
padding: _viewportMargin,
|
||||
keyboardFocusNode: _sharedFocusNode),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 30,
|
||||
left: 0,
|
||||
right: 10,
|
||||
height: 30,
|
||||
child: Container(
|
||||
height: 30,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
color: Colors.white.withOpacity(0.25),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
ControllerMenu(
|
||||
sharedFocusNode: _sharedFocusNode,
|
||||
controller: _plugin,
|
||||
onToggleViewport: () {
|
||||
setState(() {
|
||||
_viewportMargin =
|
||||
(_viewportMargin == EdgeInsets.zero)
|
||||
? const EdgeInsets.all(30)
|
||||
: EdgeInsets.zero;
|
||||
});
|
||||
},
|
||||
onControllerDestroyed: () {},
|
||||
onControllerCreated: () {}),
|
||||
SceneMenu(
|
||||
sharedFocusNode: _sharedFocusNode,
|
||||
controller: _plugin,
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
await _plugin.viewer.loadGlb(
|
||||
'assets/shapes/shapes.glb',
|
||||
numInstances: 1);
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
child: const Text("shapes.glb"))),
|
||||
const SizedBox(width: 5),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
await _plugin.viewer.loadGlb('assets/1.glb');
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
child: const Text("1.glb"))),
|
||||
const SizedBox(width: 5),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
await _plugin.viewer.loadGlb('assets/2.glb');
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
child: const Text("2.glb"))),
|
||||
const SizedBox(width: 5),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
await _plugin.viewer.loadGlb('assets/3.glb');
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
child: const Text("3.glb"))),
|
||||
Expanded(child: Container()),
|
||||
]))),
|
||||
if (isInitialized) ...[
|
||||
Positioned(top:10, left:10, width:200, height:200, child:Container(
|
||||
child:EntityListWidget(controller: _plugin.viewer))),
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.only(top: 10, left: 20, right: 20),
|
||||
// child: ValueListenableBuilder(
|
||||
// valueListenable: showProjectionMatrices,
|
||||
// builder: (ctx, value, child) => CameraMatrixOverlay(
|
||||
// controller: _plugin.viewer, showProjectionMatrices: value)),
|
||||
// ),
|
||||
// Align(
|
||||
// alignment: Alignment.topRight,
|
||||
// child: PickerResultWidget(controller: _plugin.viewer),
|
||||
// )
|
||||
]
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
263
examples/flutter/example/lib/menus/asset_submenu.dart
Normal file
263
examples/flutter/example/lib/menus/asset_submenu.dart
Normal file
@@ -0,0 +1,263 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:thermion_flutter/thermion_flutter.dart';
|
||||
import 'package:animation_tools_dart/animation_tools_dart.dart';
|
||||
import 'package:thermion_flutter_example/main.dart';
|
||||
import 'package:vector_math/vector_math_64.dart' as v;
|
||||
import 'package:thermion_dart/thermion_dart/abstract_filament_viewer.dart';
|
||||
|
||||
class AssetSubmenu extends StatefulWidget {
|
||||
final ThermionFlutterPlugin controller;
|
||||
const AssetSubmenu({super.key, required this.controller});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _AssetSubmenuState();
|
||||
}
|
||||
|
||||
class _AssetSubmenuState extends State<AssetSubmenu> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
Widget _shapesSubmenu() {
|
||||
var children = [
|
||||
MenuItemButton(
|
||||
closeOnActivate: false,
|
||||
onPressed: () async {
|
||||
var entity = await widget.controller.viewer.getChildEntity(
|
||||
widget.controller.viewer.scene.listEntities().last, "Cylinder");
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return Center(
|
||||
child: Container(
|
||||
color: Colors.white, child: Text(entity.toString())));
|
||||
});
|
||||
},
|
||||
child: const Text('Find Cylinder entity by name')),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
widget.controller.viewer.setPosition(
|
||||
widget.controller.viewer.scene.listEntities().last,
|
||||
1.0,
|
||||
1.0,
|
||||
-1.0);
|
||||
},
|
||||
child: const Text('Set position to 1, 1, -1'),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
final color = Colors.purple;
|
||||
widget.controller.viewer.setMaterialColor(
|
||||
widget.controller.viewer.scene.listEntities().last,
|
||||
"Cone",
|
||||
0,
|
||||
color.red / 255.0,
|
||||
color.green / 255.0,
|
||||
color.blue / 255.0,
|
||||
1.0);
|
||||
},
|
||||
child: const Text("Set cone material color to purple")),
|
||||
];
|
||||
|
||||
return SubmenuButton(menuChildren: children, child: const Text("Shapes"));
|
||||
}
|
||||
|
||||
Widget _geometrySubmenu() {
|
||||
return SubmenuButton(
|
||||
menuChildren: [
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
var verts = [
|
||||
-1.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
1.0,
|
||||
1.0,
|
||||
0.0,
|
||||
1.0,
|
||||
1.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
];
|
||||
var indices = [0, 1, 2, 2, 3, 0];
|
||||
var geom = await widget.controller.viewer.createGeometry(
|
||||
verts, indices,
|
||||
materialPath: "asset://assets/solidcolor.filamat");
|
||||
},
|
||||
child: const Text("Quad")),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await widget.controller.viewer.createGeometry([
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
], [
|
||||
0,
|
||||
1
|
||||
], primitiveType: PrimitiveType.LINES);
|
||||
},
|
||||
child: const Text("Line"))
|
||||
],
|
||||
child: const Text("Custom Geometry"),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SubmenuButton(
|
||||
menuChildren: [
|
||||
_shapesSubmenu(),
|
||||
_geometrySubmenu(),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await widget.controller.viewer.addLight(
|
||||
LightType.DIRECTIONAL, 6500, 100000, 0, 1, 0, 0, -1, 0);
|
||||
},
|
||||
child: const Text("Add directional light"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await widget.controller.viewer.addLight(
|
||||
LightType.POINT, 6500, 100000, 0, 1, 0, 0, -1, 0,
|
||||
falloffRadius: 1.0);
|
||||
},
|
||||
child: const Text("Add point light"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await widget.controller.viewer.addLight(
|
||||
LightType.SPOT, 6500, 1000000, 0, 0, 0, 0, 1, 0,
|
||||
spotLightConeInner: 0.1,
|
||||
spotLightConeOuter: 0.4,
|
||||
falloffRadius: 100.0);
|
||||
},
|
||||
child: const Text("Add spot light"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await widget.controller.viewer.clearLights();
|
||||
},
|
||||
child: const Text("Clear lights"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
final color = const Color(0xAA73C9FA);
|
||||
widget.controller.viewer.setBackgroundColor(color.red / 255.0,
|
||||
color.green / 255.0, color.blue / 255.0, 1.0);
|
||||
},
|
||||
child: const Text("Set background color")),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.viewer
|
||||
.setBackgroundImage('assets/background.ktx');
|
||||
},
|
||||
child: const Text("Load background image")),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.viewer.setBackgroundImage(
|
||||
'assets/background.ktx',
|
||||
fillHeight: true);
|
||||
},
|
||||
child: const Text("Load background image (fill height)")),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
if (ExampleWidgetState.hasSkybox) {
|
||||
widget.controller.viewer.removeSkybox();
|
||||
} else {
|
||||
widget.controller.viewer
|
||||
.loadSkybox('assets/default_env/default_env_skybox.ktx');
|
||||
}
|
||||
ExampleWidgetState.hasSkybox = !ExampleWidgetState.hasSkybox;
|
||||
},
|
||||
child: Text(ExampleWidgetState.hasSkybox
|
||||
? 'Remove skybox'
|
||||
: 'Load skybox')),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.viewer
|
||||
.loadIbl('assets/default_env/default_env_ibl.ktx');
|
||||
},
|
||||
child: const Text('Load IBL')),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.viewer.removeIbl();
|
||||
},
|
||||
child: const Text('Remove IBL')),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await widget.controller.viewer.clearEntities();
|
||||
},
|
||||
child: const Text('Clear assets')),
|
||||
],
|
||||
child: const Text("Assets"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// _item(() async {
|
||||
// var frameData = Float32List.fromList(
|
||||
// List<double>.generate(120, (i) => i / 120).expand((x) {
|
||||
// var vals = List<double>.filled(7, x);
|
||||
// vals[3] = 1.0;
|
||||
// // vals[4] = 0;
|
||||
// vals[5] = 0;
|
||||
// vals[6] = 0;
|
||||
// return vals;
|
||||
// }).toList());
|
||||
|
||||
// widget.controller!.setBoneAnimation(
|
||||
// _shapes!,
|
||||
// BoneAnimationData(
|
||||
// "Bone.001", ["Cube.001"], frameData, 1000.0 / 60.0));
|
||||
// // ,
|
||||
// // "Bone.001",
|
||||
// // "Cube.001",
|
||||
// // BoneTransform([Vec3(x: 0, y: 0.0, z: 0.0)],
|
||||
// // [Quaternion(x: 1, y: 1, z: 1, w: 1)]));
|
||||
// }, 'construct bone animation'),
|
||||
|
||||
// _item(() async {
|
||||
// var morphs = await widget.controller!
|
||||
// .getMorphTargetNames(_shapes!, "Cylinder");
|
||||
// final animation = AnimationBuilder(
|
||||
// availableMorphs: morphs,
|
||||
// framerate: 30,
|
||||
// meshName: "Cylinder")
|
||||
// .setDuration(4)
|
||||
// .setMorphTargets(["Key 1", "Key 2"])
|
||||
// .interpolateMorphWeights(0, 4, 0, 1)
|
||||
// .build();
|
||||
// widget.controller!.setMorphAnimationData(_shapes!, animation);
|
||||
// }, "animate cylinder morph weights #1 and #2"),
|
||||
// _item(() async {
|
||||
// var morphs = await widget.controller!
|
||||
// .getMorphTargetNames(_shapes!, "Cylinder");
|
||||
// final animation = AnimationBuilder(
|
||||
// availableMorphs: morphs,
|
||||
// framerate: 30,
|
||||
// meshName: "Cylinder")
|
||||
// .setDuration(4)
|
||||
// .setMorphTargets(["Key 3", "Key 4"])
|
||||
// .interpolateMorphWeights(0, 4, 0, 1)
|
||||
// .build();
|
||||
// widget.controller!.setMorphAnimationData(_shapes!, animation);
|
||||
// }, "animate cylinder morph weights #3 and #4"),
|
||||
// _item(() async {
|
||||
// var morphs = await widget.controller!
|
||||
// .getMorphTargetNames(_shapes!, "Cube");
|
||||
// final animation = AnimationBuilder(
|
||||
// availableMorphs: morphs, framerate: 30, meshName: "Cube")
|
||||
// .setDuration(4)
|
||||
// .setMorphTargets(["Key 1", "Key 2"])
|
||||
// .interpolateMorphWeights(0, 4, 0, 1)
|
||||
// .build();
|
||||
// widget.controller!.setMorphAnimationData(_shapes!, animation);
|
||||
// }, "animate shapes morph weights #1 and #2"),
|
||||
224
examples/flutter/example/lib/menus/camera_submenu.dart
Normal file
224
examples/flutter/example/lib/menus/camera_submenu.dart
Normal file
@@ -0,0 +1,224 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:vector_math/vector_math_64.dart' as v;
|
||||
import 'package:thermion_flutter/thermion_flutter.dart';
|
||||
import 'package:thermion_dart/thermion_dart/abstract_filament_viewer.dart';
|
||||
import 'package:thermion_flutter_example/main.dart';
|
||||
|
||||
class CameraSubmenu extends StatefulWidget {
|
||||
final ThermionFlutterPlugin controller;
|
||||
const CameraSubmenu({super.key, required this.controller});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _CameraSubmenuState();
|
||||
}
|
||||
|
||||
class _CameraSubmenuState extends State<CameraSubmenu> {
|
||||
double? _near;
|
||||
double? _far;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.controller.viewer.initialized.then((_) {
|
||||
widget.controller.viewer.getCameraCullingNear().then((v) {
|
||||
_near = v;
|
||||
widget.controller.viewer.getCameraCullingFar().then((v) {
|
||||
_far = v;
|
||||
setState(() {});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
final _menuController = MenuController();
|
||||
|
||||
List<Widget> _cameraMenu() {
|
||||
return [
|
||||
MenuItemButton(
|
||||
closeOnActivate: false,
|
||||
onPressed: () async {
|
||||
ExampleWidgetState.showProjectionMatrices.value =
|
||||
!ExampleWidgetState.showProjectionMatrices.value;
|
||||
print("Set to ${ExampleWidgetState.showProjectionMatrices}");
|
||||
},
|
||||
child: Text(
|
||||
'${ExampleWidgetState.showProjectionMatrices.value ? "Hide" : "Display"} camera frustum',
|
||||
style: TextStyle(
|
||||
fontWeight: ExampleWidgetState.showProjectionMatrices.value
|
||||
? FontWeight.bold
|
||||
: FontWeight.normal),
|
||||
),
|
||||
),
|
||||
SubmenuButton(
|
||||
menuChildren: [1.0, 7.0, 14.0, 28.0, 56.0]
|
||||
.map((v) => MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.viewer.setCameraFocalLength(v);
|
||||
},
|
||||
child: Text(
|
||||
v.toStringAsFixed(2),
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
child: const Text("Set camera focal length")),
|
||||
SubmenuButton(
|
||||
menuChildren: [0.05, 0.1, 1.0, 10.0, 100.0]
|
||||
.map((v) => MenuItemButton(
|
||||
onPressed: () {
|
||||
_near = v;
|
||||
print("Setting camera culling to $_near $_far!");
|
||||
|
||||
widget.controller.viewer.setCameraCulling(_near!, _far!);
|
||||
},
|
||||
child: Text(
|
||||
v.toStringAsFixed(2),
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
child: const Text("Set near")),
|
||||
SubmenuButton(
|
||||
menuChildren: [5.0, 50.0, 500.0, 1000.0, 100000.0]
|
||||
.map((v) => MenuItemButton(
|
||||
onPressed: () {
|
||||
_far = v;
|
||||
print("Setting camera culling to $_near! $_far");
|
||||
widget.controller.viewer.setCameraCulling(_near!, _far!);
|
||||
},
|
||||
child: Text(
|
||||
v.toStringAsFixed(2),
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
child: const Text("Set far")),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
widget.controller.viewer.setCameraPosition(1.0, 1.0, -1.0);
|
||||
},
|
||||
child: const Text('Set position to 1, 1, -1 (leave rotation as-is)'),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
widget.controller.viewer.setCameraPosition(0.0, 0.0, 0.0);
|
||||
widget.controller.viewer.setCameraRotation(
|
||||
v.Quaternion.axisAngle(v.Vector3(0, 0.0, 1.0), 0.0));
|
||||
},
|
||||
child: const Text('Move to 0,0,0, facing towards 0,0,-1'),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.viewer.setCameraRotation(
|
||||
v.Quaternion.axisAngle(v.Vector3(0, 1, 0), pi / 4));
|
||||
},
|
||||
child: const Text("Rotate camera 45 degrees around y axis"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.frustumCulling =
|
||||
!ExampleWidgetState.frustumCulling;
|
||||
widget.controller.viewer
|
||||
.setViewFrustumCulling(ExampleWidgetState.frustumCulling);
|
||||
},
|
||||
child: Text(
|
||||
"${ExampleWidgetState.frustumCulling ? "Disable" : "Enable"} frustum culling"),
|
||||
),
|
||||
MenuItemButton(
|
||||
closeOnActivate: false,
|
||||
onPressed: () async {
|
||||
var projMatrix =
|
||||
await widget.controller.viewer.getCameraProjectionMatrix();
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (ctx) {
|
||||
return Center(
|
||||
child: Container(
|
||||
height: 100,
|
||||
width: 300,
|
||||
color: Colors.white,
|
||||
child: Text(projMatrix.storage
|
||||
.map((v) => v.toStringAsFixed(2))
|
||||
.join(","))));
|
||||
});
|
||||
},
|
||||
child: const Text("Get projection matrix")),
|
||||
SubmenuButton(
|
||||
menuChildren: ManipulatorMode.values.map((mm) {
|
||||
return MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.viewer.setCameraManipulatorOptions(
|
||||
mode: mm,
|
||||
orbitSpeedX: ExampleWidgetState.orbitSpeedX,
|
||||
orbitSpeedY: ExampleWidgetState.orbitSpeedY,
|
||||
zoomSpeed: ExampleWidgetState.zoomSpeed);
|
||||
},
|
||||
child: Text(
|
||||
mm.name,
|
||||
style: TextStyle(
|
||||
// fontWeight: ExampleWidgetState.cameraManipulatorMode == mm
|
||||
// ? FontWeight.bold
|
||||
// : FontWeight.normal
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
child: const Text("Manipulator mode")),
|
||||
SubmenuButton(
|
||||
menuChildren: [0.01, 0.1, 1.0, 10.0, 100.0].map((speed) {
|
||||
return MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.zoomSpeed = speed;
|
||||
widget.controller.viewer.setCameraManipulatorOptions(
|
||||
orbitSpeedX: ExampleWidgetState.orbitSpeedX,
|
||||
orbitSpeedY: ExampleWidgetState.orbitSpeedY,
|
||||
zoomSpeed: ExampleWidgetState.zoomSpeed);
|
||||
},
|
||||
child: Text(
|
||||
speed.toString(),
|
||||
style: TextStyle(
|
||||
fontWeight:
|
||||
(speed - ExampleWidgetState.zoomSpeed).abs() < 0.0001
|
||||
? FontWeight.bold
|
||||
: FontWeight.normal),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
child: const Text("Zoom speed")),
|
||||
SubmenuButton(
|
||||
menuChildren: [0.001, 0.01, 0.1, 1.0].map((speed) {
|
||||
return MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.orbitSpeedX = speed;
|
||||
ExampleWidgetState.orbitSpeedY = speed;
|
||||
widget.controller.viewer.setCameraManipulatorOptions(
|
||||
orbitSpeedX: ExampleWidgetState.orbitSpeedX,
|
||||
orbitSpeedY: ExampleWidgetState.orbitSpeedY,
|
||||
zoomSpeed: ExampleWidgetState.zoomSpeed);
|
||||
},
|
||||
child: Text(
|
||||
speed.toString(),
|
||||
style: TextStyle(
|
||||
fontWeight:
|
||||
(speed - ExampleWidgetState.orbitSpeedX).abs() < 0.0001
|
||||
? FontWeight.bold
|
||||
: FontWeight.normal),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
child: const Text("Orbit speed (X & Y)"))
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// if (_near == null || _far == null) {
|
||||
// return Container();
|
||||
// }
|
||||
return SubmenuButton(
|
||||
controller: _menuController,
|
||||
menuChildren: _cameraMenu(),
|
||||
child: const Text("Camera"),
|
||||
);
|
||||
}
|
||||
}
|
||||
106
examples/flutter/example/lib/menus/controller_menu.dart
Normal file
106
examples/flutter/example/lib/menus/controller_menu.dart
Normal file
@@ -0,0 +1,106 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'package:thermion_flutter/thermion_flutter.dart';
|
||||
|
||||
class ControllerMenu extends StatefulWidget {
|
||||
final ThermionFlutterPlugin controller;
|
||||
final void Function() onToggleViewport;
|
||||
final void Function() onControllerCreated;
|
||||
final void Function() onControllerDestroyed;
|
||||
final FocusNode sharedFocusNode;
|
||||
|
||||
|
||||
ControllerMenu(
|
||||
{required this.controller,
|
||||
required this.onControllerCreated,
|
||||
required this.onControllerDestroyed,
|
||||
required this.sharedFocusNode,
|
||||
required this.onToggleViewport});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _ControllerMenuState();
|
||||
}
|
||||
|
||||
class _ControllerMenuState extends State<ControllerMenu> {
|
||||
void _createController({String? uberArchivePath}) async {
|
||||
widget.controller.initialize(uberArchivePath: uberArchivePath);
|
||||
widget.onControllerCreated();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ControllerMenu oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
}
|
||||
|
||||
bool _initialized = false;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var items = <Widget>[];
|
||||
if (!_initialized) {
|
||||
items.addAll([
|
||||
MenuItemButton(
|
||||
child:
|
||||
const Text("Create ThermionFlutterPlugin (default ubershader)"),
|
||||
onPressed: () {
|
||||
_createController();
|
||||
},
|
||||
),
|
||||
MenuItemButton(
|
||||
child: const Text(
|
||||
"Create ThermionFlutterPlugin (custom ubershader - lit opaque only)"),
|
||||
onPressed: () {
|
||||
_createController(
|
||||
uberArchivePath: Platform.isWindows
|
||||
? "assets/lit_opaque_32.uberz"
|
||||
: Platform.isMacOS
|
||||
? "assets/lit_opaque_43.uberz"
|
||||
: Platform.isIOS
|
||||
? "assets/lit_opaque_43.uberz"
|
||||
: "assets/lit_opaque_43_gles.uberz");
|
||||
},
|
||||
)
|
||||
]);
|
||||
} else {
|
||||
items.addAll([
|
||||
MenuItemButton(
|
||||
child: const Text("Destroy viewer"),
|
||||
onPressed: () async {
|
||||
widget.controller.dispose();
|
||||
widget.onControllerDestroyed();
|
||||
setState(() {});
|
||||
},
|
||||
)
|
||||
]);
|
||||
}
|
||||
return MenuAnchor(
|
||||
childFocusNode: widget.sharedFocusNode,
|
||||
menuChildren: items +
|
||||
[
|
||||
TextButton(
|
||||
child: const Text("Toggle viewport size"),
|
||||
onPressed: widget.onToggleViewport,
|
||||
)
|
||||
],
|
||||
builder:
|
||||
(BuildContext context, MenuController controller, Widget? child) {
|
||||
return TextButton(
|
||||
onPressed: () {
|
||||
if (controller.isOpen) {
|
||||
controller.close();
|
||||
} else {
|
||||
controller.open();
|
||||
}
|
||||
},
|
||||
child: const Text("Controller / Viewer"),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
95
examples/flutter/example/lib/menus/rendering_submenu.dart
Normal file
95
examples/flutter/example/lib/menus/rendering_submenu.dart
Normal file
@@ -0,0 +1,95 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:thermion_flutter/thermion_flutter.dart';
|
||||
import 'package:thermion_flutter_example/main.dart';
|
||||
import 'package:thermion_dart/thermion_dart/abstract_filament_viewer.dart';
|
||||
|
||||
class RenderingSubmenu extends StatefulWidget {
|
||||
final ThermionFlutterPlugin controller;
|
||||
|
||||
const RenderingSubmenu({super.key, required this.controller});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _RenderingSubmenuState();
|
||||
}
|
||||
|
||||
class _RenderingSubmenuState extends State<RenderingSubmenu> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SubmenuButton(
|
||||
menuChildren: [
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.viewer.render();
|
||||
},
|
||||
child: const Text("Render single frame"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.rendering = !ExampleWidgetState.rendering;
|
||||
widget.controller.viewer.setRendering(ExampleWidgetState.rendering);
|
||||
},
|
||||
child: Text(
|
||||
"Set continuous rendering to ${!ExampleWidgetState.rendering}"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.framerate =
|
||||
ExampleWidgetState.framerate == 60 ? 30 : 60;
|
||||
widget.controller.viewer.setFrameRate(ExampleWidgetState.framerate);
|
||||
},
|
||||
child: Text(
|
||||
"Toggle framerate (currently ${ExampleWidgetState.framerate}) "),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.viewer.setToneMapping(ToneMapper.LINEAR);
|
||||
},
|
||||
child: const Text("Set tone mapping to linear"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.postProcessing =
|
||||
!ExampleWidgetState.postProcessing;
|
||||
widget.controller.viewer
|
||||
.setPostProcessing(ExampleWidgetState.postProcessing);
|
||||
},
|
||||
child: Text(
|
||||
"${ExampleWidgetState.postProcessing ? "Disable" : "Enable"} postprocessing"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.antiAliasingMsaa =
|
||||
!ExampleWidgetState.antiAliasingMsaa;
|
||||
widget.controller.viewer.setAntiAliasing(
|
||||
ExampleWidgetState.antiAliasingMsaa,
|
||||
ExampleWidgetState.antiAliasingFxaa,
|
||||
ExampleWidgetState.antiAliasingTaa);
|
||||
},
|
||||
child: Text(
|
||||
"${ExampleWidgetState.antiAliasingMsaa ? "Disable" : "Enable"} MSAA antialiasing"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.antiAliasingFxaa =
|
||||
!ExampleWidgetState.antiAliasingFxaa;
|
||||
widget.controller.viewer.setAntiAliasing(
|
||||
ExampleWidgetState.antiAliasingMsaa,
|
||||
ExampleWidgetState.antiAliasingFxaa,
|
||||
ExampleWidgetState.antiAliasingTaa);
|
||||
},
|
||||
child: Text(
|
||||
"${ExampleWidgetState.antiAliasingFxaa ? "Disable" : "Enable"} FXAA antialiasing"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.recording = !ExampleWidgetState.recording;
|
||||
widget.controller.viewer.setRecording(ExampleWidgetState.recording);
|
||||
},
|
||||
child: Text(
|
||||
"Turn recording ${ExampleWidgetState.recording ? "OFF" : "ON"}) "),
|
||||
),
|
||||
],
|
||||
child: const Text("Rendering"),
|
||||
);
|
||||
}
|
||||
}
|
||||
62
examples/flutter/example/lib/menus/scene_menu.dart
Normal file
62
examples/flutter/example/lib/menus/scene_menu.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:thermion_flutter/thermion_flutter.dart';
|
||||
import 'package:thermion_flutter_example/menus/asset_submenu.dart';
|
||||
import 'package:thermion_flutter_example/menus/camera_submenu.dart';
|
||||
import 'package:thermion_flutter_example/menus/rendering_submenu.dart';
|
||||
|
||||
class SceneMenu extends StatefulWidget {
|
||||
final ThermionFlutterPlugin? controller;
|
||||
final FocusNode sharedFocusNode;
|
||||
|
||||
const SceneMenu(
|
||||
{super.key, required this.controller, required this.sharedFocusNode});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _SceneMenuState();
|
||||
}
|
||||
}
|
||||
|
||||
class _SceneMenuState extends State<SceneMenu> {
|
||||
@override
|
||||
void didUpdateWidget(SceneMenu oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.controller != null &&
|
||||
(widget.controller != oldWidget.controller)) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MenuAnchor(
|
||||
onClose: () {},
|
||||
childFocusNode: widget.sharedFocusNode,
|
||||
menuChildren: widget.controller == null
|
||||
? []
|
||||
: <Widget>[
|
||||
RenderingSubmenu(
|
||||
controller: widget.controller!,
|
||||
),
|
||||
AssetSubmenu(controller: widget.controller!),
|
||||
CameraSubmenu(
|
||||
controller: widget.controller!,
|
||||
),
|
||||
],
|
||||
builder:
|
||||
(BuildContext context, MenuController controller, Widget? child) {
|
||||
return TextButton(
|
||||
onPressed: () {
|
||||
if (controller.isOpen) {
|
||||
controller.close();
|
||||
} else {
|
||||
controller.open();
|
||||
}
|
||||
},
|
||||
child: const Text("Scene"),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
20
examples/flutter/example/lib/picker_result_widget.dart
Normal file
20
examples/flutter/example/lib/picker_result_widget.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:thermion_dart/thermion_dart/abstract_filament_viewer.dart';
|
||||
|
||||
class PickerResultWidget extends StatelessWidget {
|
||||
final AbstractFilamentViewer controller;
|
||||
|
||||
const PickerResultWidget({required this.controller, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return StreamBuilder(
|
||||
stream: controller.pickResult.map((result) {
|
||||
return controller.getNameForEntity(result.entity);
|
||||
}),
|
||||
builder: (ctx, snapshot) => snapshot.data == null
|
||||
? Container()
|
||||
: Text(snapshot.data!,
|
||||
style: const TextStyle(color: Colors.green, fontSize: 24)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user