initial work to split into dart_filament and flutter_filament
This commit is contained in:
138
flutter_filament/example/lib/camera_matrix_overlay.dart
Normal file
138
flutter_filament/example/lib/camera_matrix_overlay.dart
Normal file
@@ -0,0 +1,138 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_filament/flutter_filament.dart';
|
||||
import 'package:vector_math/vector_math_64.dart' as v;
|
||||
|
||||
class CameraMatrixOverlay extends StatefulWidget {
|
||||
final FlutterFilamentPlugin 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())));
|
||||
}
|
||||
}
|
||||
32
flutter_filament/example/lib/example_viewport.dart
Normal file
32
flutter_filament/example/lib/example_viewport.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_filament/flutter_filament.dart';
|
||||
|
||||
class ExampleViewport extends StatelessWidget {
|
||||
final FlutterFilamentPlugin? 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!,
|
||||
child: FilamentWidget(
|
||||
plugin: controller!,
|
||||
))))
|
||||
: Container();
|
||||
}
|
||||
}
|
||||
214
flutter_filament/example/lib/main.dart
Normal file
214
flutter_filament/example/lib/main.dart
Normal file
@@ -0,0 +1,214 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_filament_example/camera_matrix_overlay.dart';
|
||||
import 'package:flutter_filament_example/menus/controller_menu.dart';
|
||||
import 'package:flutter_filament_example/example_viewport.dart';
|
||||
import 'package:flutter_filament_example/picker_result_widget.dart';
|
||||
import 'package:flutter_filament_example/menus/scene_menu.dart';
|
||||
|
||||
import 'package:flutter_filament/flutter_filament.dart';
|
||||
|
||||
const loadDefaultScene = bool.hasEnvironment('--load-default-scene');
|
||||
|
||||
void main() async {
|
||||
print(loadDefaultScene);
|
||||
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(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> {
|
||||
FlutterFilamentPlugin? _plugin;
|
||||
|
||||
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();
|
||||
if (loadDefaultScene) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
||||
_plugin = await FlutterFilamentPlugin.create();
|
||||
setState(() {});
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
||||
await _plugin!.initialized;
|
||||
|
||||
await _plugin!
|
||||
.loadSkybox("assets/default_env/default_env_skybox.ktx");
|
||||
|
||||
await _plugin!.setRendering(true);
|
||||
|
||||
await _plugin!.loadGlb("assets/shapes/shapes.glb");
|
||||
|
||||
await _plugin!.setCameraManipulatorOptions(zoomSpeed: 1.0);
|
||||
|
||||
hasSkybox = true;
|
||||
rendering = true;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_listener.cancel();
|
||||
}
|
||||
|
||||
EntityTransformController? _transformController;
|
||||
|
||||
final _sharedFocusNode = FocusNode();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(children: [
|
||||
Positioned.fill(
|
||||
child: ExampleViewport(
|
||||
controller: _plugin,
|
||||
entityTransformController: _transformController,
|
||||
padding: _viewportMargin,
|
||||
keyboardFocusNode: _sharedFocusNode),
|
||||
),
|
||||
EntityListWidget(controller: _plugin),
|
||||
Positioned(
|
||||
bottom: Platform.isIOS ? 30 : 0,
|
||||
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: (controller) {
|
||||
setState(() {
|
||||
_plugin = controller;
|
||||
});
|
||||
}),
|
||||
SceneMenu(
|
||||
sharedFocusNode: _sharedFocusNode,
|
||||
controller: _plugin,
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
await _plugin!
|
||||
.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!.loadGlb('assets/1.glb');
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.transparent, child: const Text("1.glb"))),
|
||||
const SizedBox(width: 5),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
await _plugin!.loadGlb('assets/2.glb');
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.transparent, child: const Text("2.glb"))),
|
||||
const SizedBox(width: 5),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
await _plugin!.loadGlb('assets/3.glb');
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.transparent, child: const Text("3.glb"))),
|
||||
Expanded(child: Container()),
|
||||
]))),
|
||||
_plugin == null
|
||||
? Container()
|
||||
: Padding(
|
||||
padding: const EdgeInsets.only(top: 10, left: 20, right: 20),
|
||||
child: ValueListenableBuilder(
|
||||
valueListenable: showProjectionMatrices,
|
||||
builder: (ctx, value, child) => CameraMatrixOverlay(
|
||||
controller: _plugin!, showProjectionMatrices: value)),
|
||||
),
|
||||
_plugin == null
|
||||
? Container()
|
||||
: Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: PickerResultWidget(controller: _plugin!),
|
||||
)
|
||||
]);
|
||||
}
|
||||
}
|
||||
372
flutter_filament/example/lib/menus/asset_submenu.dart
Normal file
372
flutter_filament/example/lib/menus/asset_submenu.dart
Normal file
@@ -0,0 +1,372 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_filament/flutter_filament.dart';
|
||||
import 'package:flutter_filament_example/main.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:animation_tools_dart/animation_tools_dart.dart';
|
||||
import 'package:vector_math/vector_math_64.dart' as v;
|
||||
import 'package:dart_filament/dart_filament.dart';
|
||||
|
||||
class AssetSubmenu extends StatefulWidget {
|
||||
final FlutterFilamentPlugin 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.getChildEntity(
|
||||
widget.controller.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 {
|
||||
await widget.controller.addBoneAnimation(
|
||||
widget.controller.scene.listEntities().last,
|
||||
BoneAnimationData([
|
||||
"Bone"
|
||||
], [
|
||||
"Cylinder"
|
||||
], [
|
||||
[v.Quaternion.axisAngle(v.Vector3(1, 1, 1), pi / 2)]
|
||||
], [
|
||||
[v.Vector3.zero()]
|
||||
], 16));
|
||||
},
|
||||
child:
|
||||
const Text('Set bone transform for Cylinder (pi/2 rotation X)')),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await widget.controller
|
||||
.resetBones(widget.controller.scene.listEntities().last);
|
||||
},
|
||||
child: const Text('Reset bones for Cylinder')),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await widget.controller.addBoneAnimation(
|
||||
widget.controller.scene.listEntities().last,
|
||||
BoneAnimationData(
|
||||
["Bone"],
|
||||
["Cylinder"],
|
||||
List.generate(
|
||||
60,
|
||||
(idx) => [
|
||||
v.Quaternion.axisAngle(
|
||||
v.Vector3(0, 0, 1), pi * 8 * (idx / 60))
|
||||
.normalized()
|
||||
]),
|
||||
List.generate(60, (idx) => [v.Vector3.zero()]),
|
||||
1000.0 / 60.0));
|
||||
},
|
||||
child: const Text('Set bone transform animation for Cylinder')),
|
||||
MenuItemButton(
|
||||
closeOnActivate: false,
|
||||
onPressed: () async {
|
||||
var names = await widget.controller.getMorphTargetNames(
|
||||
widget.controller.scene.listEntities().last, "Cylinder");
|
||||
print("NAMES : $names");
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (ctx) {
|
||||
return Container(
|
||||
height: 100,
|
||||
width: 100,
|
||||
color: Colors.white,
|
||||
child: Text(names.join(",")));
|
||||
});
|
||||
},
|
||||
child: const Text("Show morph target names for Cylinder")),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
var cylinder = await widget.controller.getChildEntity(
|
||||
widget.controller.scene.listEntities().last, "Cylinder");
|
||||
widget.controller
|
||||
.setMorphTargetWeights(cylinder, List.filled(4, 1.0));
|
||||
},
|
||||
child: const Text("set Cylinder morph weights to 1")),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
var cylinder = await widget.controller.getChildEntity(
|
||||
widget.controller.scene.listEntities().last, "Cylinder");
|
||||
widget.controller
|
||||
.setMorphTargetWeights(cylinder, List.filled(4, 0.0));
|
||||
},
|
||||
child: const Text("Set Cylinder morph weights to 0")),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
var morphTargets = await widget.controller.getMorphTargetNames(
|
||||
widget.controller.scene.listEntities().last, "Cylinder");
|
||||
|
||||
var morphData = MorphAnimationData(
|
||||
List.generate(
|
||||
60,
|
||||
(frameNum) =>
|
||||
List.generate(4, (morphIndex) => frameNum / 60)),
|
||||
morphTargets);
|
||||
await widget.controller.setMorphAnimationData(
|
||||
widget.controller.scene.listEntities().last, morphData,
|
||||
targetMeshNames: [
|
||||
"Cylinder",
|
||||
]);
|
||||
},
|
||||
child: const Text("create manual morph animation for Cylinder")),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
widget.controller.setPosition(
|
||||
widget.controller.scene.listEntities().last, 1.0, 1.0, -1.0);
|
||||
},
|
||||
child: const Text('Set position to 1, 1, -1'),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
if (ExampleWidgetState.coneHidden) {
|
||||
widget.controller
|
||||
.reveal(widget.controller.scene.listEntities().last, "Cone");
|
||||
} else {
|
||||
widget.controller
|
||||
.hide(widget.controller.scene.listEntities().last, "Cone");
|
||||
}
|
||||
|
||||
ExampleWidgetState.coneHidden = !ExampleWidgetState.coneHidden;
|
||||
},
|
||||
child:
|
||||
Text(ExampleWidgetState.coneHidden ? 'show cone' : 'hide cone')),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
final color = Colors.purple;
|
||||
widget.controller.setMaterialColor(
|
||||
widget.controller.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")),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
ExampleWidgetState.loop = !ExampleWidgetState.loop;
|
||||
},
|
||||
child: Text(
|
||||
"Toggle animation looping ${ExampleWidgetState.loop ? "OFF" : "ON"}"))
|
||||
];
|
||||
|
||||
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.createGeometry(verts, indices,
|
||||
materialPath: "asset://assets/solidcolor.filamat");
|
||||
},
|
||||
child: const Text("Quad")),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await widget.controller.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
|
||||
.addLight(1, 6500, 150000, 0, 1, 0, 0, -1, 0, true);
|
||||
},
|
||||
child: const Text("Add directional light"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await widget.controller
|
||||
.addLight(2, 6500, 150000, 0, 1, 0, 0, -1, 0, true);
|
||||
},
|
||||
child: const Text("Add point light"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await widget.controller
|
||||
.addLight(3, 6500, 15000000, 0, 1, 0, 0, -1, 0, true);
|
||||
},
|
||||
child: const Text("Add spot light"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await widget.controller.clearLights();
|
||||
},
|
||||
child: const Text("Clear lights"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
final color = const Color(0xAA73C9FA);
|
||||
widget.controller.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.setBackgroundImage('assets/background.ktx');
|
||||
},
|
||||
child: const Text("Load background image")),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.setBackgroundImage('assets/background.ktx',
|
||||
fillHeight: true);
|
||||
},
|
||||
child: const Text("Load background image (fill height)")),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
if (ExampleWidgetState.hasSkybox) {
|
||||
widget.controller.removeSkybox();
|
||||
} else {
|
||||
widget.controller
|
||||
.loadSkybox('assets/default_env/default_env_skybox.ktx');
|
||||
}
|
||||
ExampleWidgetState.hasSkybox = !ExampleWidgetState.hasSkybox;
|
||||
},
|
||||
child: Text(ExampleWidgetState.hasSkybox
|
||||
? 'Remove skybox'
|
||||
: 'Load skybox')),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller
|
||||
.loadIbl('assets/default_env/default_env_ibl.ktx');
|
||||
},
|
||||
child: const Text('Load IBL')),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.removeIbl();
|
||||
},
|
||||
child: const Text('Remove IBL')),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await Permission.microphone.request();
|
||||
},
|
||||
child: const Text("Request permissions (tests inactive->resume)")),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await widget.controller.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"),
|
||||
|
||||
225
flutter_filament/example/lib/menus/camera_submenu.dart
Normal file
225
flutter_filament/example/lib/menus/camera_submenu.dart
Normal file
@@ -0,0 +1,225 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:vector_math/vector_math_64.dart' as v;
|
||||
import 'package:flutter_filament/flutter_filament.dart';
|
||||
import 'package:dart_filament/dart_filament.dart';
|
||||
|
||||
import 'package:flutter_filament_example/main.dart';
|
||||
|
||||
class CameraSubmenu extends StatefulWidget {
|
||||
final FlutterFilamentPlugin 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.initialized.then((_) {
|
||||
widget.controller.getCameraCullingNear().then((v) {
|
||||
_near = v;
|
||||
widget.controller.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.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.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.setCameraCulling(_near!, _far!);
|
||||
},
|
||||
child: Text(
|
||||
v.toStringAsFixed(2),
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
child: const Text("Set far")),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
widget.controller.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.setCameraPosition(0.0, 0.0, 0.0);
|
||||
widget.controller.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.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
|
||||
.setViewFrustumCulling(ExampleWidgetState.frustumCulling);
|
||||
},
|
||||
child: Text(
|
||||
"${ExampleWidgetState.frustumCulling ? "Disable" : "Enable"} frustum culling"),
|
||||
),
|
||||
MenuItemButton(
|
||||
closeOnActivate: false,
|
||||
onPressed: () async {
|
||||
var projMatrix =
|
||||
await widget.controller.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.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.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.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"),
|
||||
);
|
||||
}
|
||||
}
|
||||
117
flutter_filament/example/lib/menus/controller_menu.dart
Normal file
117
flutter_filament/example/lib/menus/controller_menu.dart
Normal file
@@ -0,0 +1,117 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'package:flutter_filament/flutter_filament.dart';
|
||||
|
||||
class ControllerMenu extends StatefulWidget {
|
||||
final FlutterFilamentPlugin? controller;
|
||||
final void Function() onToggleViewport;
|
||||
final void Function(FlutterFilamentPlugin controller) onControllerCreated;
|
||||
final void Function() onControllerDestroyed;
|
||||
final FocusNode sharedFocusNode;
|
||||
|
||||
ControllerMenu(
|
||||
{this.controller,
|
||||
required this.onControllerCreated,
|
||||
required this.onControllerDestroyed,
|
||||
required this.sharedFocusNode,
|
||||
required this.onToggleViewport});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _ControllerMenuState();
|
||||
}
|
||||
|
||||
class _ControllerMenuState extends State<ControllerMenu> {
|
||||
FlutterFilamentPlugin? _flutterFilamentPlugin;
|
||||
|
||||
void _createController({String? uberArchivePath}) async {
|
||||
if (_flutterFilamentPlugin != null) {
|
||||
throw Exception("Controller already exists");
|
||||
}
|
||||
_flutterFilamentPlugin =
|
||||
await FlutterFilamentPlugin.create(uberArchivePath: uberArchivePath);
|
||||
widget.onControllerCreated(_flutterFilamentPlugin!);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_flutterFilamentPlugin = widget.controller;
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ControllerMenu oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.controller != _flutterFilamentPlugin) {
|
||||
setState(() {
|
||||
_flutterFilamentPlugin = widget.controller;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var items = <Widget>[];
|
||||
if (_flutterFilamentPlugin == null) {
|
||||
items.addAll([
|
||||
MenuItemButton(
|
||||
child:
|
||||
const Text("Create FlutterFilamentPlugin (default ubershader)"),
|
||||
onPressed: () {
|
||||
_createController();
|
||||
},
|
||||
),
|
||||
MenuItemButton(
|
||||
child: const Text(
|
||||
"Create FlutterFilamentPlugin (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 {
|
||||
await _flutterFilamentPlugin!.dispose();
|
||||
_flutterFilamentPlugin = null;
|
||||
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"),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
102
flutter_filament/example/lib/menus/rendering_submenu.dart
Normal file
102
flutter_filament/example/lib/menus/rendering_submenu.dart
Normal file
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_filament/flutter_filament.dart';
|
||||
import 'package:flutter_filament_example/main.dart';
|
||||
import 'package:dart_filament/dart_filament.dart';
|
||||
|
||||
class RenderingSubmenu extends StatefulWidget {
|
||||
final FlutterFilamentPlugin 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.render();
|
||||
},
|
||||
child: const Text("Render single frame"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.rendering = !ExampleWidgetState.rendering;
|
||||
widget.controller.setRendering(ExampleWidgetState.rendering);
|
||||
},
|
||||
child: Text(
|
||||
"Set continuous rendering to ${!ExampleWidgetState.rendering}"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.framerate =
|
||||
ExampleWidgetState.framerate == 60 ? 30 : 60;
|
||||
widget.controller.setFrameRate(ExampleWidgetState.framerate);
|
||||
},
|
||||
child: Text(
|
||||
"Toggle framerate (currently ${ExampleWidgetState.framerate}) "),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.setToneMapping(ToneMapper.LINEAR);
|
||||
},
|
||||
child: const Text("Set tone mapping to linear"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.postProcessing =
|
||||
!ExampleWidgetState.postProcessing;
|
||||
widget.controller
|
||||
.setPostProcessing(ExampleWidgetState.postProcessing);
|
||||
},
|
||||
child: Text(
|
||||
"${ExampleWidgetState.postProcessing ? "Disable" : "Enable"} postprocessing"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.antiAliasingMsaa =
|
||||
!ExampleWidgetState.antiAliasingMsaa;
|
||||
widget.controller.setAntiAliasing(
|
||||
ExampleWidgetState.antiAliasingMsaa,
|
||||
ExampleWidgetState.antiAliasingFxaa,
|
||||
ExampleWidgetState.antiAliasingTaa);
|
||||
},
|
||||
child: Text(
|
||||
"${ExampleWidgetState.antiAliasingMsaa ? "Disable" : "Enable"} MSAA antialiasing"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.antiAliasingFxaa =
|
||||
!ExampleWidgetState.antiAliasingFxaa;
|
||||
widget.controller.setAntiAliasing(
|
||||
ExampleWidgetState.antiAliasingMsaa,
|
||||
ExampleWidgetState.antiAliasingFxaa,
|
||||
ExampleWidgetState.antiAliasingTaa);
|
||||
},
|
||||
child: Text(
|
||||
"${ExampleWidgetState.antiAliasingFxaa ? "Disable" : "Enable"} FXAA antialiasing"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.recording = !ExampleWidgetState.recording;
|
||||
widget.controller.setRecording(ExampleWidgetState.recording);
|
||||
},
|
||||
child: Text(
|
||||
"Turn recording ${ExampleWidgetState.recording ? "OFF" : "ON"}) "),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await widget.controller
|
||||
.addLight(2, 6000, 100000, 0, 0, 0, 0, 1, 0, false);
|
||||
},
|
||||
child: Text("Add light"),
|
||||
),
|
||||
],
|
||||
child: const Text("Rendering"),
|
||||
);
|
||||
}
|
||||
}
|
||||
62
flutter_filament/example/lib/menus/scene_menu.dart
Normal file
62
flutter_filament/example/lib/menus/scene_menu.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_filament/flutter_filament.dart';
|
||||
import 'package:flutter_filament_example/menus/asset_submenu.dart';
|
||||
import 'package:flutter_filament_example/menus/camera_submenu.dart';
|
||||
import 'package:flutter_filament_example/menus/rendering_submenu.dart';
|
||||
|
||||
class SceneMenu extends StatefulWidget {
|
||||
final FlutterFilamentPlugin? 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"),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
21
flutter_filament/example/lib/picker_result_widget.dart
Normal file
21
flutter_filament/example/lib/picker_result_widget.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_filament/flutter_filament.dart';
|
||||
import 'package:dart_filament/dart_filament.dart';
|
||||
|
||||
class PickerResultWidget extends StatelessWidget {
|
||||
final FilamentViewer 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