add setViewFrustumCulling, zoomDelta for gesture detector and cleanup
This commit is contained in:
@@ -53,6 +53,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
||||
bool _initialized = false;
|
||||
|
||||
bool _coneHidden = false;
|
||||
bool _frustumCulling = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -251,6 +252,14 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
||||
_filamentController.moveCameraToAsset(_cube!);
|
||||
}, "Move camera to asset"));
|
||||
|
||||
children.add(_item(() {
|
||||
setState(() {
|
||||
_frustumCulling = !_frustumCulling;
|
||||
});
|
||||
|
||||
_filamentController.setViewFrustumCulling(_frustumCulling);
|
||||
}, "${_frustumCulling ? "Disable" : "Enable"} frustum culling"));
|
||||
|
||||
return Stack(children: [
|
||||
Positioned.fill(
|
||||
bottom: 100,
|
||||
|
||||
@@ -527,6 +527,13 @@ class FilamentController {
|
||||
await _channel.invokeMethod("moveCameraToAsset", asset);
|
||||
}
|
||||
|
||||
Future setViewFrustumCulling(bool enabled) async {
|
||||
if (_viewer == null || _resizing) {
|
||||
throw Exception("No viewer available, ignoring");
|
||||
}
|
||||
await _channel.invokeMethod("setViewFrustumCulling", enabled);
|
||||
}
|
||||
|
||||
Future setCameraExposure(
|
||||
double aperture, double shutterSpeed, double sensitivity) async {
|
||||
if (_viewer == null || _resizing) {
|
||||
|
||||
@@ -13,13 +13,15 @@ class FilamentGestureDetector extends StatefulWidget {
|
||||
final FilamentController controller;
|
||||
final bool showControlOverlay;
|
||||
final bool enableControls;
|
||||
final double zoomDelta;
|
||||
|
||||
const FilamentGestureDetector(
|
||||
{Key? key,
|
||||
required this.controller,
|
||||
this.child,
|
||||
this.showControlOverlay = false,
|
||||
this.enableControls = true})
|
||||
this.enableControls = true,
|
||||
this.zoomDelta = 1})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
@@ -91,8 +93,9 @@ class _FilamentGestureDetectorState extends State<FilamentGestureDetector> {
|
||||
if (pointerSignal is PointerScrollEvent) {
|
||||
_scrollTimer?.cancel();
|
||||
widget.controller.zoomBegin();
|
||||
widget.controller
|
||||
.zoomUpdate(pointerSignal.scrollDelta.dy > 0 ? 1 : -1);
|
||||
widget.controller.zoomUpdate(pointerSignal.scrollDelta.dy > 0
|
||||
? widget.zoomDelta
|
||||
: -widget.zoomDelta);
|
||||
_scrollTimer = Timer(Duration(milliseconds: 100), () {
|
||||
widget.controller.zoomEnd();
|
||||
_scrollTimer = null;
|
||||
@@ -118,7 +121,6 @@ class _FilamentGestureDetectorState extends State<FilamentGestureDetector> {
|
||||
? null
|
||||
: (PointerMoveEvent d) async {
|
||||
if (d.buttons == kTertiaryButton || _rotating) {
|
||||
print("Updating at ${d.position}");
|
||||
widget.controller
|
||||
.rotateUpdate(d.position.dx * 2.0, d.position.dy * 2.0);
|
||||
} else {
|
||||
|
||||
@@ -619,6 +619,9 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
||||
case "moveCameraToAsset":
|
||||
move_camera_to_asset(viewer, call.arguments as! EntityId)
|
||||
result(true)
|
||||
case "setViewFrustumCulling":
|
||||
set_view_frustum_culling(viewer, call.arguments as! Bool)
|
||||
result(true)
|
||||
case "setCameraPosition":
|
||||
let args = call.arguments as! [Any]
|
||||
set_camera_position(viewer, Float(args[0] as! Double), Float(args[1] as! Double), Float(args[2] as! Double))
|
||||
|
||||
@@ -82,6 +82,7 @@ namespace polyvox {
|
||||
void clearBackgroundImage();
|
||||
void setBackgroundImagePosition(float x, float y, bool clamp);
|
||||
void moveCameraToAsset(EntityId entityId);
|
||||
void setViewFrustumCulling(bool enabled);
|
||||
void setCameraExposure(float aperture, float shutterSpeed, float sensitivity);
|
||||
void setCameraPosition(float x, float y, float z);
|
||||
void setCameraRotation(float rads, float x, float y, float z);
|
||||
|
||||
@@ -90,6 +90,7 @@ void set_position(void* assetManager, EntityId asset, float x, float y, float z)
|
||||
void set_rotation(void* assetManager, EntityId asset, float rads, float x, float y, float z);
|
||||
void set_scale(void* assetManager, EntityId asset, float scale);
|
||||
void move_camera_to_asset(const void* const viewer, EntityId asset);
|
||||
void set_view_frustum_culling(const void* const viewer, bool enabled);
|
||||
void set_camera_exposure(const void* const viewer, float aperture, float shutterSpeed, float sensitivity);
|
||||
void set_camera_position(const void* const viewer, float x, float y, float z);
|
||||
void set_camera_rotation(const void* const viewer, float rads, float x, float y, float z);
|
||||
|
||||
@@ -872,7 +872,14 @@ void FilamentViewer::moveCameraToAsset(EntityId entityId) {
|
||||
const filament::Aabb bb = asset->getBoundingBox();
|
||||
auto corners = bb.getCorners();
|
||||
Camera& cam =_view->getCamera();
|
||||
cam.lookAt(corners.vertices[0], corners.vertices[7]);
|
||||
auto eye = corners.vertices[0] * 1.5;
|
||||
auto lookAt = corners.vertices[7];
|
||||
cam.lookAt(eye, lookAt);
|
||||
Log("Moved camera to %f %f %f, lookAt %f %f %f, near %f far %f", eye[0], eye[1], eye[2], lookAt[0], lookAt[1], lookAt[2], cam.getNear(), cam.getCullingFar());
|
||||
}
|
||||
|
||||
void FilamentViewer::setViewFrustumCulling(bool enabled) {
|
||||
_view->setFrustumCullingEnabled(enabled);
|
||||
}
|
||||
|
||||
void FilamentViewer::setCameraPosition(float x, float y, float z) {
|
||||
@@ -929,7 +936,7 @@ void FilamentViewer::grabUpdate(float x, float y) {
|
||||
return;
|
||||
}
|
||||
Camera& cam =_view->getCamera();
|
||||
auto eye = cam.getPosition();// math::float3 {0.0f, 0.5f, 50.0f } ;// ; //
|
||||
auto eye = cam.getPosition();
|
||||
auto target = eye + cam.getForwardVector();
|
||||
auto upward = cam.getUpVector();
|
||||
Viewport const& vp = _view->getViewport();
|
||||
@@ -938,9 +945,7 @@ void FilamentViewer::grabUpdate(float x, float y) {
|
||||
cam.setModelMatrix(trans);
|
||||
} else {
|
||||
auto trans = cam.getModelMatrix() * mat4::rotation(
|
||||
|
||||
0.01,
|
||||
// math::float3 { 0.0f, 1.0f, 0.0f });
|
||||
0.02,
|
||||
math::float3 { (y - _startY) / vp.height, (x - _startX) / vp.width, 0.0f });
|
||||
cam.setModelMatrix(trans);
|
||||
}
|
||||
|
||||
@@ -101,6 +101,10 @@ extern "C" {
|
||||
((FilamentViewer*)viewer)->moveCameraToAsset(asset);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_view_frustum_culling(const void* const viewer, bool enabled) {
|
||||
((FilamentViewer*)viewer)->setViewFrustumCulling(enabled);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_focus_distance(const void* const viewer, float distance) {
|
||||
((FilamentViewer*)viewer)->setCameraFocusDistance(distance);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user