update integration test
This commit is contained in:
309
example/lib/menus/asset_submenu.dart
Normal file
309
example/lib/menus/asset_submenu.dart
Normal file
@@ -0,0 +1,309 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_filament/filament_controller.dart';
|
||||
import 'package:flutter_filament_example/main.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
class AssetSubmenu extends StatefulWidget {
|
||||
final FilamentController 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(
|
||||
onPressed: () async {
|
||||
if (ExampleWidgetState.shapes == null) {
|
||||
ExampleWidgetState.shapes =
|
||||
await widget.controller.loadGlb('assets/shapes/shapes.glb');
|
||||
ExampleWidgetState.animations = await widget.controller
|
||||
.getAnimationNames(ExampleWidgetState.shapes!);
|
||||
} else {
|
||||
await widget.controller.removeAsset(ExampleWidgetState.shapes!);
|
||||
ExampleWidgetState.shapes = null;
|
||||
ExampleWidgetState.animations = null;
|
||||
}
|
||||
},
|
||||
child: const Text('Load GLB')),
|
||||
MenuItemButton(
|
||||
onPressed: ExampleWidgetState.shapes != null
|
||||
? null
|
||||
: () async {
|
||||
if (ExampleWidgetState.shapes != null) {
|
||||
widget.controller.removeAsset(ExampleWidgetState.shapes!);
|
||||
}
|
||||
ExampleWidgetState.shapes = await widget.controller
|
||||
.loadGltf('assets/shapes/shapes.gltf', 'assets/shapes');
|
||||
},
|
||||
child: const Text('Load GLTF')),
|
||||
MenuItemButton(
|
||||
onPressed: ExampleWidgetState.shapes == null
|
||||
? null
|
||||
: () async {
|
||||
await widget.controller
|
||||
.transformToUnitCube(ExampleWidgetState.shapes!);
|
||||
},
|
||||
child: const Text('Transform to unit cube')),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
var names = await widget.controller
|
||||
.getMorphTargetNames(ExampleWidgetState.shapes!, "Cylinder");
|
||||
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 {
|
||||
widget.controller.setMorphTargetWeights(
|
||||
ExampleWidgetState.shapes!, "Cylinder", List.filled(4, 1.0));
|
||||
},
|
||||
child: const Text("set Cylinder morph weights to 1")),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
widget.controller.setMorphTargetWeights(
|
||||
ExampleWidgetState.shapes!, "Cylinder", List.filled(4, 0.0));
|
||||
},
|
||||
child: const Text("Set Cylinder morph weights to 0")),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
widget.controller
|
||||
.setPosition(ExampleWidgetState.shapes!, 1.0, 1.0, -1.0);
|
||||
},
|
||||
child: const Text('Set position to 1, 1, -1'),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
if (ExampleWidgetState.coneHidden) {
|
||||
widget.controller.reveal(ExampleWidgetState.shapes!, "Cone");
|
||||
} else {
|
||||
widget.controller.hide(ExampleWidgetState.shapes!, "Cone");
|
||||
}
|
||||
|
||||
ExampleWidgetState.coneHidden = !ExampleWidgetState.coneHidden;
|
||||
},
|
||||
child:
|
||||
Text(ExampleWidgetState.coneHidden ? 'show cone' : 'hide cone')),
|
||||
MenuItemButton(
|
||||
onPressed: ExampleWidgetState.shapes == null
|
||||
? null
|
||||
: () async {
|
||||
widget.controller.setMaterialColor(
|
||||
ExampleWidgetState.shapes!, "Cone", 0, Colors.purple);
|
||||
},
|
||||
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"}"))
|
||||
];
|
||||
if (ExampleWidgetState.animations != null) {
|
||||
children.addAll(ExampleWidgetState.animations!.map((a) => MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.playAnimation(ExampleWidgetState.shapes!,
|
||||
ExampleWidgetState.animations!.indexOf(a),
|
||||
replaceActive: true,
|
||||
crossfade: 0.5,
|
||||
loop: ExampleWidgetState.loop);
|
||||
},
|
||||
child: Text(
|
||||
"play animation ${ExampleWidgetState.animations!.indexOf(a)} (replace/fade)"))));
|
||||
children.addAll(ExampleWidgetState.animations!.map((a) => MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.playAnimation(ExampleWidgetState.shapes!,
|
||||
ExampleWidgetState.animations!.indexOf(a),
|
||||
replaceActive: false, loop: ExampleWidgetState.loop);
|
||||
},
|
||||
child: Text(
|
||||
"Play animation ${ExampleWidgetState.animations!.indexOf(a)} (noreplace)"))));
|
||||
}
|
||||
|
||||
return SubmenuButton(menuChildren: children, child: const Text("Shapes"));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SubmenuButton(
|
||||
menuChildren: [
|
||||
_shapesSubmenu(),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
ExampleWidgetState.directionalLight = 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.clearLights();
|
||||
},
|
||||
child: const Text("Clear lights"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
if (ExampleWidgetState.buster == null) {
|
||||
ExampleWidgetState.buster = await widget.controller.loadGltf(
|
||||
"assets/BusterDrone/scene.gltf", "assets/BusterDrone",
|
||||
force: true);
|
||||
await widget.controller
|
||||
.playAnimation(ExampleWidgetState.buster!, 0, loop: true);
|
||||
ExampleWidgetState.animations = await widget.controller
|
||||
.getAnimationNames(ExampleWidgetState.shapes!);
|
||||
} else {
|
||||
await widget.controller.removeAsset(ExampleWidgetState.buster!);
|
||||
ExampleWidgetState.buster = null;
|
||||
}
|
||||
},
|
||||
child: Text(ExampleWidgetState.shapes == null
|
||||
? 'Load buster'
|
||||
: 'Remove buster')),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
if (ExampleWidgetState.flightHelmet == null) {
|
||||
ExampleWidgetState.flightHelmet ??= await widget.controller
|
||||
.loadGltf('assets/FlightHelmet/FlightHelmet.gltf',
|
||||
'assets/FlightHelmet',
|
||||
force: true);
|
||||
} else {
|
||||
await widget.controller
|
||||
.removeAsset(ExampleWidgetState.flightHelmet!);
|
||||
ExampleWidgetState.flightHelmet = null;
|
||||
}
|
||||
},
|
||||
child: Text(ExampleWidgetState.shapes == null
|
||||
? 'Load flight helmet'
|
||||
: 'Remove flight helmet')),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.setBackgroundColor(const Color(0xFF73C9FA));
|
||||
},
|
||||
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: () async {
|
||||
await Permission.microphone.request();
|
||||
},
|
||||
child: const Text("Request permissions (tests inactive->resume)")),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await widget.controller.clearAssets();
|
||||
ExampleWidgetState.flightHelmet = null;
|
||||
ExampleWidgetState.buster = null;
|
||||
ExampleWidgetState.shapes = null;
|
||||
},
|
||||
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"),
|
||||
|
||||
136
example/lib/menus/camera_submenu.dart
Normal file
136
example/lib/menus/camera_submenu.dart
Normal file
@@ -0,0 +1,136 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_filament/filament_controller.dart';
|
||||
import 'package:flutter_filament_example/main.dart';
|
||||
|
||||
class CameraSubmenu extends StatefulWidget {
|
||||
final FilamentController controller;
|
||||
const CameraSubmenu({super.key, required this.controller});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _CameraSubmenuState();
|
||||
}
|
||||
|
||||
class _CameraSubmenuState extends State<CameraSubmenu> {
|
||||
List<Widget> _cameraMenu() {
|
||||
return [
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
widget.controller.setCameraPosition(1.0, 1.0, -1.0);
|
||||
},
|
||||
child: const Text('Move to 1, 1, -1'),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: ExampleWidgetState.last == null
|
||||
? null
|
||||
: () async {
|
||||
await widget.controller
|
||||
.setCamera(ExampleWidgetState.last!, null);
|
||||
},
|
||||
child: const Text('Set to first camera in last added asset'),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: ExampleWidgetState.last == null
|
||||
? null
|
||||
: () async {
|
||||
await widget.controller
|
||||
.moveCameraToAsset(ExampleWidgetState.last!);
|
||||
},
|
||||
child: const Text("Move to last added asset"),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () {
|
||||
widget.controller.setCameraRotation(pi / 4, 0.0, 1.0, 0.0);
|
||||
},
|
||||
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"),
|
||||
),
|
||||
SubmenuButton(
|
||||
menuChildren: ManipulatorMode.values.map((mm) {
|
||||
return MenuItemButton(
|
||||
onPressed: () {
|
||||
ExampleWidgetState.cameraManipulatorMode = mm;
|
||||
widget.controller.setCameraManipulatorOptions(
|
||||
mode: ExampleWidgetState.cameraManipulatorMode,
|
||||
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(
|
||||
mode: ExampleWidgetState.cameraManipulatorMode,
|
||||
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(
|
||||
mode: ExampleWidgetState.cameraManipulatorMode,
|
||||
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) {
|
||||
return SubmenuButton(
|
||||
menuChildren: _cameraMenu(),
|
||||
child: const Text("Camera"),
|
||||
);
|
||||
}
|
||||
}
|
||||
117
example/lib/menus/controller_menu.dart
Normal file
117
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/filament_controller.dart';
|
||||
import 'package:flutter_filament/filament_controller_ffi.dart';
|
||||
|
||||
class ControllerMenu extends StatefulWidget {
|
||||
final FilamentController? controller;
|
||||
final void Function(FilamentController controller) onControllerCreated;
|
||||
final void Function() onControllerDestroyed;
|
||||
|
||||
ControllerMenu(
|
||||
{this.controller,
|
||||
required this.onControllerCreated,
|
||||
required this.onControllerDestroyed});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _ControllerMenuState();
|
||||
}
|
||||
|
||||
class _ControllerMenuState extends State<ControllerMenu> {
|
||||
FilamentController? _filamentController;
|
||||
final FocusNode _buttonFocusNode = FocusNode(debugLabel: 'Camera Menu');
|
||||
|
||||
void _createController({String? uberArchivePath}) {
|
||||
if (_filamentController != null) {
|
||||
throw Exception("Controller already exists");
|
||||
}
|
||||
_filamentController =
|
||||
FilamentControllerFFI(uberArchivePath: uberArchivePath);
|
||||
widget.onControllerCreated(_filamentController!);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_filamentController = widget.controller;
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ControllerMenu oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.controller != _filamentController) {
|
||||
setState(() {
|
||||
_filamentController = widget.controller;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var items = <Widget>[];
|
||||
if (_filamentController?.hasViewer.value != true) {
|
||||
items.addAll([
|
||||
MenuItemButton(
|
||||
child: const Text("Create FilamentViewer"),
|
||||
onPressed: _filamentController == null
|
||||
? null
|
||||
: () {
|
||||
_filamentController!.createViewer();
|
||||
},
|
||||
),
|
||||
MenuItemButton(
|
||||
child: const Text("Create FilamentController (default ubershader)"),
|
||||
onPressed: () {
|
||||
_createController();
|
||||
},
|
||||
),
|
||||
MenuItemButton(
|
||||
child: const Text(
|
||||
"Create FilamentController (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: () {
|
||||
_filamentController!.destroy();
|
||||
_filamentController = null;
|
||||
widget.onControllerDestroyed();
|
||||
setState(() {});
|
||||
},
|
||||
)
|
||||
]);
|
||||
}
|
||||
return MenuAnchor(
|
||||
childFocusNode: _buttonFocusNode,
|
||||
menuChildren: items,
|
||||
builder:
|
||||
(BuildContext context, MenuController controller, Widget? child) {
|
||||
return Align(
|
||||
alignment: Alignment.bottomLeft,
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
if (controller.isOpen) {
|
||||
controller.close();
|
||||
} else {
|
||||
controller.open();
|
||||
}
|
||||
},
|
||||
child: const Text("Controller / Viewer"),
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
63
example/lib/menus/rendering_submenu.dart
Normal file
63
example/lib/menus/rendering_submenu.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_filament/filament_controller.dart';
|
||||
import 'package:flutter_filament_example/main.dart';
|
||||
|
||||
class RenderingSubmenu extends StatefulWidget {
|
||||
final FilamentController 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"),
|
||||
),
|
||||
],
|
||||
child: const Text("Rendering"),
|
||||
);
|
||||
}
|
||||
}
|
||||
68
example/lib/menus/scene_menu.dart
Normal file
68
example/lib/menus/scene_menu.dart
Normal file
@@ -0,0 +1,68 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_filament/filament_controller.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 FilamentController? controller;
|
||||
|
||||
const SceneMenu({super.key, required this.controller});
|
||||
|
||||
@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 ||
|
||||
widget.controller!.hasViewer != oldWidget.controller!.hasViewer) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ValueListenableBuilder(
|
||||
valueListenable:
|
||||
widget.controller?.hasViewer ?? ValueNotifier<bool>(false),
|
||||
builder: (BuildContext ctx, bool hasViewer, Widget? child) {
|
||||
return MenuAnchor(
|
||||
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 Align(
|
||||
alignment: Alignment.bottomLeft,
|
||||
child: TextButton(
|
||||
onPressed: !hasViewer
|
||||
? null
|
||||
: () {
|
||||
if (controller.isOpen) {
|
||||
controller.close();
|
||||
} else {
|
||||
controller.open();
|
||||
}
|
||||
},
|
||||
child: const Text("Scene"),
|
||||
));
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user