expose getters for near/far culling distance and clean up example project for more readability on frustum
This commit is contained in:
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_filament/filament_controller.dart';
|
||||
import 'package:vector_math/vector_math_64.dart' as v;
|
||||
|
||||
class CameraMatrixOverlay extends StatefulWidget {
|
||||
final FilamentController controller;
|
||||
@@ -43,6 +44,7 @@ class _CameraMatrixOverlayState extends State<CameraMatrixOverlay> {
|
||||
projMatrix.storage.map((v) => v.toStringAsFixed(2)).join(",");
|
||||
_cameraCullingProjectionMatrix =
|
||||
cullingMatrix.storage.map((v) => v.toStringAsFixed(2)).join(",");
|
||||
_getFrustum();
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
@@ -55,6 +57,12 @@ class _CameraMatrixOverlayState extends State<CameraMatrixOverlay> {
|
||||
}
|
||||
}
|
||||
|
||||
v.Frustum? _frustum;
|
||||
|
||||
void _getFrustum() async {
|
||||
_frustum = await widget.controller.getCameraFrustum();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -87,17 +95,50 @@ class _CameraMatrixOverlayState extends State<CameraMatrixOverlay> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text("Camera position : $_cameraPosition $_cameraRotation",
|
||||
style: const TextStyle(color: Colors.white, fontSize: 12)),
|
||||
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(),
|
||||
]));
|
||||
children: <Widget>[
|
||||
Text("Camera position : $_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())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,20 @@ class CameraSubmenu extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _CameraSubmenuState extends State<CameraSubmenu> {
|
||||
double _near = 0.05;
|
||||
double _far = 1000.0;
|
||||
double? _near;
|
||||
double? _far;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.controller.getCameraCullingNear().then((v) {
|
||||
_near = v;
|
||||
widget.controller.getCameraCullingFar().then((v) {
|
||||
_far = v;
|
||||
setState(() {});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
final _menuController = MenuController();
|
||||
|
||||
@@ -30,7 +42,7 @@ class _CameraSubmenuState extends State<CameraSubmenu> {
|
||||
print("Set to ${ExampleWidgetState.showProjectionMatrices}");
|
||||
},
|
||||
child: Text(
|
||||
'${ExampleWidgetState.showProjectionMatrices.value ? "Hide" : "Display"} camera projection/culling projection matrices',
|
||||
'${ExampleWidgetState.showProjectionMatrices.value ? "Hide" : "Display"} camera frustum',
|
||||
style: TextStyle(
|
||||
fontWeight: ExampleWidgetState.showProjectionMatrices.value
|
||||
? FontWeight.bold
|
||||
@@ -54,7 +66,9 @@ class _CameraSubmenuState extends State<CameraSubmenu> {
|
||||
.map((v) => MenuItemButton(
|
||||
onPressed: () {
|
||||
_near = v;
|
||||
widget.controller.setCameraCulling(_near, _far);
|
||||
print("Setting camera culling to $_near $_far!");
|
||||
|
||||
widget.controller.setCameraCulling(_near!, _far!);
|
||||
},
|
||||
child: Text(
|
||||
v.toStringAsFixed(2),
|
||||
@@ -67,7 +81,8 @@ class _CameraSubmenuState extends State<CameraSubmenu> {
|
||||
.map((v) => MenuItemButton(
|
||||
onPressed: () {
|
||||
_far = v;
|
||||
widget.controller.setCameraCulling(_near, _far);
|
||||
print("Setting camera culling to $_near! $_far");
|
||||
widget.controller.setCameraCulling(_near!, _far!);
|
||||
},
|
||||
child: Text(
|
||||
v.toStringAsFixed(2),
|
||||
@@ -79,7 +94,14 @@ class _CameraSubmenuState extends State<CameraSubmenu> {
|
||||
onPressed: () async {
|
||||
widget.controller.setCameraPosition(1.0, 1.0, -1.0);
|
||||
},
|
||||
child: const Text('Move to 1, 1, -1'),
|
||||
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(0, 0.0, 1.0, 0.0);
|
||||
},
|
||||
child: const Text('Move to 0,0,0, facing towards 0,0,-1'),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
@@ -130,38 +152,6 @@ class _CameraSubmenuState extends State<CameraSubmenu> {
|
||||
});
|
||||
},
|
||||
child: const Text("Get projection matrix")),
|
||||
MenuItemButton(
|
||||
closeOnActivate: false,
|
||||
onPressed: () async {
|
||||
var frustum = await widget.controller.getCameraFrustum();
|
||||
var normalString = [
|
||||
frustum.plane0,
|
||||
frustum.plane1,
|
||||
frustum.plane2,
|
||||
frustum.plane3,
|
||||
frustum.plane4,
|
||||
frustum.plane5
|
||||
]
|
||||
.map((plane) =>
|
||||
plane.normal.storage
|
||||
.map((v) => v.toStringAsFixed(2))
|
||||
.join(",") +
|
||||
",${plane.constant}")
|
||||
.join("\n");
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) {
|
||||
return Center(
|
||||
child: Container(
|
||||
height: 300,
|
||||
width: 300,
|
||||
color: Colors.white,
|
||||
child:
|
||||
Text("Frustum plane normals : $normalString ")));
|
||||
});
|
||||
_menuController.close();
|
||||
},
|
||||
child: const Text("Get frustum")),
|
||||
SubmenuButton(
|
||||
menuChildren: ManipulatorMode.values.map((mm) {
|
||||
return MenuItemButton(
|
||||
@@ -233,6 +223,9 @@ class _CameraSubmenuState extends State<CameraSubmenu> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_near == null || _far == null) {
|
||||
return Container();
|
||||
}
|
||||
return SubmenuButton(
|
||||
controller: _menuController,
|
||||
menuChildren: _cameraMenu(),
|
||||
|
||||
Reference in New Issue
Block a user