enable camera rotate

This commit is contained in:
Nick Fisher
2021-09-18 09:27:41 +08:00
parent 76f25ae7d5
commit 29008993d3
3 changed files with 55 additions and 13 deletions

View File

@@ -21,7 +21,7 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
final FilamentController _filamentController = MimeticFilamentController();
double _zoomValue = 0;
bool _rotate = false;
int _primitiveIndex = 0;
double _weight = 0.0;
@@ -40,19 +40,27 @@ class _MyAppState extends State<MyApp> {
body: GestureDetector(
behavior: HitTestBehavior.opaque,
onPanDown: (details) {
_filamentController.panStart(
details.localPosition.dx, details.localPosition.dy);
_rotate
? _filamentController.rotateStart(
details.localPosition.dx, details.localPosition.dy)
: _filamentController.panStart(
details.localPosition.dx, details.localPosition.dy);
},
onPanUpdate: (details) {
_filamentController.panUpdate(
details.localPosition.dx, details.localPosition.dy);
_rotate
? _filamentController.rotateUpdate(
details.localPosition.dx, details.localPosition.dy)
: _filamentController.panUpdate(
details.localPosition.dx, details.localPosition.dy);
},
onPanEnd: (d) {
_filamentController.panEnd();
_rotate
? _filamentController.rotateEnd()
: _filamentController.panEnd();
},
child: Stack(children: [
FilamentWidget(controller: _filamentController),
Column(children: [
Column(mainAxisSize: MainAxisSize.min, children: [
ElevatedButton(
child: Text("initialize"),
onPressed: () {
@@ -63,9 +71,9 @@ class _MyAppState extends State<MyApp> {
"assets/default_env/default_env_ibl.ktx");
_filamentController.loadGltf(
"assets/guy.gltf", "assets", "Material");
_filamentController.createMorpher(
"CC_Base_Body.003", "CC_Base_Body.003",
materialName: "Material");
// _filamentController.createMorpher(
// "CC_Base_Body.003", "CC_Base_Body.003",
// materialName: "Material");
}),
// ElevatedButton(
// child: Text("load skybox"),
@@ -121,13 +129,20 @@ class _MyAppState extends State<MyApp> {
});
}),
Row(children: [
Checkbox(
value: _rotate,
onChanged: (v) {
setState(() {
_rotate = v == true;
});
}),
ElevatedButton(
onPressed: () => _filamentController.zoom(1.0),
onPressed: () => _filamentController.zoom(100.0),
child: Text("+")),
ElevatedButton(
onPressed: () => _filamentController.zoom(-1.0),
onPressed: () => _filamentController.zoom(-100.0),
child: Text("-"))
])
]),
]),
])),
),

View File

@@ -71,6 +71,18 @@ static void* freeResourceGlobal(void* mem, size_t size, void* misc) {
if(!_viewer)
return;
_viewer->manipulator->grabEnd();
} else if([@"rotateStart" isEqualToString:call.method]) {
if(!_viewer)
return;
_viewer->manipulator->grabBegin([call.arguments[0] intValue], [call.arguments[1] intValue], false);
} else if([@"rotateUpdate" isEqualToString:call.method]) {
if(!_viewer)
return;
_viewer->manipulator->grabUpdate([call.arguments[0] intValue], [call.arguments[1] intValue]);
} else if([@"rotate End" isEqualToString:call.method]) {
if(!_viewer)
return;
_viewer->manipulator->grabEnd();
} else if([@"createMorpher" isEqualToString:call.method]) {
_viewer->createMorpher([call.arguments[0] UTF8String], [call.arguments[1] UTF8String],[call.arguments[2] UTF8String]);
} else if([@"applyWeights" isEqualToString:call.method]) {

View File

@@ -10,6 +10,9 @@ abstract class FilamentController {
Future panStart(double x, double y);
Future panUpdate(double x, double y);
Future panEnd();
Future rotateStart(double x, double y);
Future rotateUpdate(double x, double y);
Future rotateEnd();
Future applyWeights(List<double> weights, int primitiveIndex);
Future createMorpher(String meshName, String entityName,
{String? materialName});
@@ -58,6 +61,18 @@ class MimeticFilamentController extends FilamentController {
await _channel.invokeMethod("panEnd");
}
Future rotateStart(double x, double y) async {
await _channel.invokeMethod("rotateStart", [x.toInt(), y.toInt()]);
}
Future rotateUpdate(double x, double y) async {
await _channel.invokeMethod("rotateUpdate", [x.toInt(), y.toInt()]);
}
Future rotateEnd() async {
await _channel.invokeMethod("rotateEnd");
}
Future applyWeights(List<double> weights, int primitiveIndex) async {
await _channel.invokeMethod("applyWeights", [weights, primitiveIndex]);
}