start using menu for example project & add methods for getting camera model/view matrices

This commit is contained in:
Nick Fisher
2023-11-03 22:17:39 +08:00
parent f5cc7a8174
commit 48be185bba
15 changed files with 895 additions and 729 deletions

View File

@@ -1,12 +1,11 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_filament/filament_controller.dart';
class SceneMenu extends StatefulWidget {
final FilamentController? controller;
SceneMenu({super.key, required this.controller});
const SceneMenu({super.key, required this.controller});
@override
State<StatefulWidget> createState() {
@@ -15,9 +14,8 @@ class SceneMenu extends StatefulWidget {
}
class _SceneMenuState extends State<SceneMenu> {
FilamentEntity? _shapes;
List<String>? _animations;
bool _hasSkybox = false;
bool _postProcessing = true;
final FocusNode _buttonFocusNode = FocusNode(debugLabel: 'Camera Menu');
@override
@@ -29,6 +27,14 @@ class _SceneMenuState extends State<SceneMenu> {
}
}
bool _coneHidden = false;
FilamentEntity? _shapes;
FilamentEntity? _directionalLight;
List<String>? _animations;
bool _loop = false;
bool _hasSkybox = false;
List<MenuItemButton> _assetMenu() {
return [
MenuItemButton(
@@ -84,6 +90,101 @@ class _SceneMenuState extends State<SceneMenu> {
];
}
bool _frustumCulling = true;
ManipulatorMode _cameraManipulatorMode = ManipulatorMode.ORBIT;
double _zoomSpeed = 0.01;
double _orbitSpeedX = 0.01;
double _orbitSpeedY = 0.01;
List<Widget> _cameraMenu() {
return [
MenuItemButton(
onPressed: () {
widget.controller!.moveCameraToAsset(_shapes!);
},
child: const Text("Move camera to shapes asset"),
),
MenuItemButton(
onPressed: () {
setState(() {
_frustumCulling = !_frustumCulling;
});
widget.controller!.setViewFrustumCulling(_frustumCulling);
},
child:
Text("${_frustumCulling ? "Disable" : "Enable"} frustum culling"),
),
SubmenuButton(
menuChildren: ManipulatorMode.values.map((mm) {
return MenuItemButton(
onPressed: () {
_cameraManipulatorMode = mm;
widget.controller!.setCameraManipulatorOptions(
mode: _cameraManipulatorMode,
orbitSpeedX: _orbitSpeedX,
orbitSpeedY: _orbitSpeedY,
zoomSpeed: _zoomSpeed);
setState(() {});
},
child: Text(
mm.name,
style: TextStyle(
fontWeight: _cameraManipulatorMode == mm
? FontWeight.bold
: FontWeight.normal),
),
);
}).toList(),
child: Text("Manipulator mode")),
SubmenuButton(
menuChildren: [0.01, 0.1, 1.0, 10.0, 100.0].map((speed) {
return MenuItemButton(
onPressed: () {
_zoomSpeed = speed;
widget.controller!.setCameraManipulatorOptions(
mode: _cameraManipulatorMode,
orbitSpeedX: _orbitSpeedX,
orbitSpeedY: _orbitSpeedY,
zoomSpeed: _zoomSpeed);
setState(() {});
},
child: Text(
speed.toString(),
style: TextStyle(
fontWeight: (speed - _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: () {
_orbitSpeedX = speed;
_orbitSpeedY = speed;
widget.controller!.setCameraManipulatorOptions(
mode: _cameraManipulatorMode,
orbitSpeedX: _orbitSpeedX,
orbitSpeedY: _orbitSpeedY,
zoomSpeed: _zoomSpeed);
setState(() {});
},
child: Text(
speed.toString(),
style: TextStyle(
fontWeight: (speed - _orbitSpeedX).abs() < 0.0001
? FontWeight.bold
: FontWeight.normal),
),
);
}).toList(),
child: const Text("Orbit speed (X & Y)"))
];
}
bool _rendering = false;
int _framerate = 60;
@@ -107,7 +208,35 @@ class _SceneMenuState extends State<SceneMenu> {
_framerate = _framerate == 60 ? 30 : 60;
widget.controller!.setFrameRate(_framerate);
},
child: const Text("Toggle framerate (currently ) "),
child: Text("Toggle framerate (currently $_framerate) "),
),
MenuItemButton(
onPressed: () {
widget.controller!.setToneMapping(ToneMapper.LINEAR);
},
child: const Text("Set tone mapping to linear"),
),
MenuItemButton(
onPressed: () {
setState(() {
_postProcessing = !_postProcessing;
});
widget.controller!.setPostProcessing(_postProcessing);
},
child: Text("${_postProcessing ? "Disable" : "Enable"} postprocessing"),
),
MenuItemButton(
onPressed: () async {
_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 all lights"),
),
];
}
@@ -129,9 +258,9 @@ class _SceneMenuState extends State<SceneMenu> {
menuChildren: _assetMenu(),
child: const Text("Assets"),
),
const SubmenuButton(
menuChildren: <Widget>[],
child: Text("Camera"),
SubmenuButton(
menuChildren: _cameraMenu(),
child: const Text("Camera"),
),
],
builder: (BuildContext context, MenuController controller,