add android option to pause rendering

This commit is contained in:
Nick Fisher
2022-09-01 15:19:29 +10:00
parent 7dd9ed971f
commit d9470912ed
3 changed files with 84 additions and 40 deletions

View File

@@ -94,7 +94,7 @@ class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
choreographer.postFrameCallback(this) choreographer.postFrameCallback(this)
executor.execute { executor.execute {
if(_viewer == null) { if(_viewer == null || !_render) {
} else if(!surface.isValid()) { } else if(!surface.isValid()) {
Log.v(TAG, "INVALID") Log.v(TAG, "INVALID")
@@ -124,6 +124,7 @@ class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
private lateinit var _lib : FilamentInterop private lateinit var _lib : FilamentInterop
private var _viewer : Pointer? = null private var _viewer : Pointer? = null
private var _render : Boolean = true
private lateinit var choreographer: Choreographer private lateinit var choreographer: Choreographer
@@ -214,6 +215,10 @@ class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
result.success(null) result.success(null)
} }
} }
"setRendering" -> {
_render = call.arguments as Boolean
result.success(null)
}
"setFrameInterval" -> { "setFrameInterval" -> {
executor.execute { executor.execute {
_lib.set_frame_interval(_viewer!!, (call.arguments as Double).toFloat()); _lib.set_frame_interval(_viewer!!, (call.arguments as Double).toFloat());

View File

@@ -3,7 +3,7 @@ import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:polyvox_filament/filament_controller.dart'; import 'package:polyvox_filament/filament_controller.dart';
import 'package:polyvox_filament/filament_widget.dart'; import 'package:polyvox_filament/filament_widget.dart';
import 'package:polyvox_filament/gesture_detecting_filament_view.dart';
void main() { void main() {
runApp(const MyApp()); runApp(const MyApp());
@@ -27,6 +27,8 @@ class _MyAppState extends State<MyApp> {
List<String> _animationNames = []; List<String> _animationNames = [];
bool _loop = false; bool _loop = false;
bool _vertical = false; bool _vertical = false;
bool _rendering = true;
int _framerate = 60;
@override @override
void initState() { void initState() {
@@ -44,31 +46,18 @@ class _MyAppState extends State<MyApp> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
GestureDetector( Container(
onScaleStart: (d) { width: _vertical ? 200 : 400,
if (d.pointerCount == 1) height: _vertical ? 400 : 200,
_filamentController.panStart(0.5, 0.5); alignment: Alignment.center,
}, child: SizedBox(
onScaleEnd: (d) { child: GestureDetectingFilamentView(
// if(d.pointerCount == 2) {} showControls: true,
// _filamentController.panEnd(d. .focalPoint.dx,d.focalPoint.dy);
},
onScaleUpdate: (d) {
if (d.pointerCount == 1) {
// _filamentController.panUpdate(d.focalPoint.dx,d.focalPoint.dy);
} else {
_filamentController.zoom(10.0);
}
},
child: Container(
width: _vertical ? 100 : 200, height: _vertical ? 200 : 100,
alignment: Alignment.center,
child: SizedBox(
child: FilamentWidget(
controller: _filamentController, controller: _filamentController,
)), ),
)), )),
Text("Target names : ${_targetNames.join(",")}, Animation names : ${_animationNames.join(",")}"), Text(
"Target names : ${_targetNames.join(",")}, Animation names : ${_animationNames.join(",")}"),
Align( Align(
alignment: Alignment.bottomLeft, alignment: Alignment.bottomLeft,
child: Container( child: Container(
@@ -80,6 +69,10 @@ class _MyAppState extends State<MyApp> {
child: const Icon(Icons.menu), child: const Icon(Icons.menu),
onSelected: (int item) async { onSelected: (int item) async {
switch (item) { switch (item) {
case -1:
await _filamentController
.initialize();
break;
case 0: case 0:
await _filamentController await _filamentController
.setBackgroundImage( .setBackgroundImage(
@@ -141,7 +134,8 @@ class _MyAppState extends State<MyApp> {
loop: _loop); loop: _loop);
break; break;
case 10: case 10:
_filamentController.stopAnimation(_cube!, 0); _filamentController.stopAnimation(
_cube!, 0);
break; break;
case 11: case 11:
setState(() { setState(() {
@@ -176,19 +170,14 @@ class _MyAppState extends State<MyApp> {
1000 / framerate.toDouble()); 1000 / framerate.toDouble());
break; break;
case 16: case 16:
_targetNames = await _filamentController _targetNames = await _filamentController
.getTargetNames(_cube!, "Cube"); .getTargetNames(_cube!, "Cube");
setState(() { setState(() {});
});
break; break;
case 17: case 17:
_animationNames = await _filamentController _animationNames = await _filamentController
.getAnimationNames(_cube!); .getAnimationNames(_cube!);
setState(() { setState(() {});
});
break; break;
case 18: case 18:
@@ -226,11 +215,21 @@ class _MyAppState extends State<MyApp> {
}); });
break; break;
case 26: case 26:
await _filamentController.reload(); await _filamentController.setCameraPosition(
0, -3, 10);
await _filamentController.setCameraRotation(
pi / 8, 1, 0, 0);
break;
case 27:
_framerate = _framerate == 60 ? 30 : 60;
await _filamentController.setFrameRate(_framerate);
} }
}, },
itemBuilder: (BuildContext context) => itemBuilder: (BuildContext context) =>
<PopupMenuEntry<int>>[ <PopupMenuEntry<int>>[
const PopupMenuItem(
value: -1,
child: Text("initialize")),
const PopupMenuItem( const PopupMenuItem(
value: 0, value: 0,
child: Text("load background image")), child: Text("load background image")),
@@ -283,8 +282,9 @@ class _MyAppState extends State<MyApp> {
child: Text('stop animations')), child: Text('stop animations')),
PopupMenuItem( PopupMenuItem(
value: 11, value: 11,
child: Text( child: Text(_loop
_loop ? "don't loop animation" : "loop animation")), ? "don't loop animation"
: "loop animation")),
const PopupMenuItem( const PopupMenuItem(
value: 12, child: Text('zoom in')), value: 12, child: Text('zoom in')),
const PopupMenuItem( const PopupMenuItem(
@@ -305,11 +305,44 @@ class _MyAppState extends State<MyApp> {
const PopupMenuItem( const PopupMenuItem(
value: 19, child: Text('pan right')), value: 19, child: Text('pan right')),
PopupMenuItem( PopupMenuItem(
value: 25, child: Text(_vertical ? 'set horizontal' : 'set vertical')), value: 25,
child: Text(_vertical
? 'set horizontal'
: 'set vertical')),
PopupMenuItem( PopupMenuItem(
value: 26, child: Text( value: 26,
"reload native assets")), child:
]))) Text('set camera pos to 0,1,10')),
PopupMenuItem(
value: 27,
child:
Text('toggle framerate')),
]))),
Align(
alignment: Alignment.bottomRight,
child: Row(children:[
GestureDetector(
onTap: () {
setState(() {
_rendering = !_rendering;
_filamentController.setRendering(_rendering);
});
},
child:Container(
color: Colors.white,
padding: const EdgeInsets.all(50),
child:Text("Rendering: $_rendering "))),
GestureDetector(
onTap: () {
setState(() {
_framerate = _framerate == 60 ? 30 : 60;
_filamentController.setFrameRate(_framerate);
});
},
child:Container(
color: Colors.white,
padding: const EdgeInsets.all(50),
child:Text("$_framerate fps")) )]))
]))); ])));
} }
} }

View File

@@ -11,6 +11,8 @@ abstract class FilamentController {
Future initialize(); Future initialize();
Future createTextureViewer(int width, int height, { double devicePixelRatio = 1}); Future createTextureViewer(int width, int height, { double devicePixelRatio = 1});
Future setFrameRate(int framerate); Future setFrameRate(int framerate);
Future setRendering(bool render);
Future resize(int width, int height, { double devicePixelRatio = 1, double contentScaleFactor=1}); Future resize(int width, int height, { double devicePixelRatio = 1, double contentScaleFactor=1});
Future setBackgroundImage(String path); Future setBackgroundImage(String path);
Future loadSkybox(String skyboxPath); Future loadSkybox(String skyboxPath);
@@ -86,6 +88,10 @@ class PolyvoxFilamentController extends FilamentController {
return _initialized.future; return _initialized.future;
} }
Future setRendering(bool render) async {
await _channel.invokeMethod("setRendering", render);
}
Future setFrameRate(int framerate) async { Future setFrameRate(int framerate) async {
await _channel.invokeMethod("setFrameInterval", 1/ framerate); await _channel.invokeMethod("setFrameInterval", 1/ framerate);
} }