example project updates

This commit is contained in:
Nick Fisher
2023-10-03 17:18:54 +11:00
parent 6ccae1121a
commit 0c9387a9d6

View File

@@ -42,7 +42,7 @@ class ExampleWidget extends StatefulWidget {
class _ExampleWidgetState extends State<ExampleWidget> { class _ExampleWidgetState extends State<ExampleWidget> {
final _filamentController = FilamentControllerFFI(); final _filamentController = FilamentControllerFFI();
FilamentEntity? _cube; FilamentEntity? _shapes;
FilamentEntity? _flightHelmet; FilamentEntity? _flightHelmet;
List<String>? _animations; List<String>? _animations;
FilamentEntity? _light; FilamentEntity? _light;
@@ -118,36 +118,36 @@ class _ExampleWidgetState extends State<ExampleWidget> {
'remove skybox', 'remove skybox',
), ),
_item(() async { _item(() async {
_cube = await _filamentController.loadGlb('assets/cube.glb'); _shapes = await _filamentController.loadGlb('assets/shapes/shapes.glb');
_animations = await _filamentController.getAnimationNames(_cube!); _animations = await _filamentController.getAnimationNames(_shapes!);
setState(() {}); setState(() {});
}, 'load cube GLB'), }, 'load shapes GLB'),
_item(() async { _item(() async {
if (_coneHidden) { if (_coneHidden) {
_filamentController.reveal(_cube!, "Cone"); _filamentController.reveal(_shapes!, "Cone");
} else { } else {
_filamentController.hide(_cube!, "Cone"); _filamentController.hide(_shapes!, "Cone");
} }
setState(() { setState(() {
_coneHidden = !_coneHidden; _coneHidden = !_coneHidden;
}); });
}, _coneHidden ? 'show cone' : 'hide cone'), }, _coneHidden ? 'show cone' : 'hide cone'),
_item(() async { _item(() async {
if (_cube != null) { if (_shapes != null) {
_filamentController.removeAsset(_cube!); _filamentController.removeAsset(_shapes!);
} }
_cube = _shapes =
await _filamentController.loadGltf('assets/cube.gltf', 'assets'); await _filamentController.loadGltf('assets/shapes/shapes.gltf', 'assets/shapes');
}, 'load cube GLTF'), }, 'load shapes GLTF'),
_item(() async { _item(() async {
_filamentController.transformToUnitCube(_cube!); _filamentController.transformToUnitCube(_shapes!);
}, 'transform to unit cube'), }, 'transform to unit cube'),
_item(() async { _item(() async {
_filamentController.setPosition(_cube!, 1.0, 1.0, -1.0); _filamentController.setPosition(_shapes!, 1.0, 1.0, -1.0);
}, 'set cube position to 1, 1, -1'), }, 'set shapes position to 1, 1, -1'),
_item(() async { _item(() async {
_filamentController.setPosition(_cube!, 1.0, 1.0, -1.0); _filamentController.setPosition(_shapes!, 1.0, 1.0, -1.0);
}, 'move camera to cube position'), }, 'move camera to shapes position'),
_item(() async { _item(() async {
var frameData = Float32List.fromList( var frameData = Float32List.fromList(
List<double>.generate(120, (i) => i / 120).expand((x) { List<double>.generate(120, (i) => i / 120).expand((x) {
@@ -160,7 +160,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
}).toList()); }).toList());
_filamentController.setBoneAnimation( _filamentController.setBoneAnimation(
_cube!, _shapes!,
BoneAnimationData( BoneAnimationData(
"Bone.001", ["Cube.001"], frameData, 1000.0 / 60.0)); "Bone.001", ["Cube.001"], frameData, 1000.0 / 60.0));
// , // ,
@@ -170,14 +170,16 @@ class _ExampleWidgetState extends State<ExampleWidget> {
// [Quaternion(x: 1, y: 1, z: 1, w: 1)])); // [Quaternion(x: 1, y: 1, z: 1, w: 1)]));
}, 'construct bone animation'), }, 'construct bone animation'),
_item(() async { _item(() async {
_filamentController.removeAsset(_cube!); _filamentController.removeAsset(_shapes!);
}, 'remove cube'), _shapes = null;
}, 'remove shapes'),
_item(() async { _item(() async {
_filamentController.clearAssets(); _filamentController.clearAssets();
_shapes = null;
}, 'clear all assets'), }, 'clear all assets'),
_item(() async { _item(() async {
var names = var names =
await _filamentController.getMorphTargetNames(_cube!, "Cylinder"); await _filamentController.getMorphTargetNames(_shapes!, "Cylinder");
await showDialog( await showDialog(
context: context, context: context,
builder: (ctx) { builder: (ctx) {
@@ -190,47 +192,47 @@ class _ExampleWidgetState extends State<ExampleWidget> {
}, "show morph target names for Cylinder"), }, "show morph target names for Cylinder"),
_item(() { _item(() {
_filamentController.setMorphTargetWeights( _filamentController.setMorphTargetWeights(
_cube!, "Cylinder", List.filled(4, 1.0)); _shapes!, "Cylinder", List.filled(4, 1.0));
}, "set Cylinder morph weights to 1"), }, "set Cylinder morph weights to 1"),
_item(() { _item(() {
_filamentController.setMorphTargetWeights( _filamentController.setMorphTargetWeights(
_cube!, "Cylinder", List.filled(4, 0.0)); _shapes!, "Cylinder", List.filled(4, 0.0));
}, "set Cylinder morph weights to 0.0"), }, "set Cylinder morph weights to 0.0"),
_item(() async { _item(() async {
var morphs = var morphs =
await _filamentController.getMorphTargetNames(_cube!, "Cylinder"); await _filamentController.getMorphTargetNames(_shapes!, "Cylinder");
final animation = AnimationBuilder( final animation = AnimationBuilder(
availableMorphs: morphs, framerate: 30, meshName: "Cylinder") availableMorphs: morphs, framerate: 30, meshName: "Cylinder")
.setDuration(4) .setDuration(4)
.setMorphTargets(["Key 1", "Key 2"]) .setMorphTargets(["Key 1", "Key 2"])
.interpolateMorphWeights(0, 4, 0, 1) .interpolateMorphWeights(0, 4, 0, 1)
.build(); .build();
_filamentController.setMorphAnimationData(_cube!, animation); _filamentController.setMorphAnimationData(_shapes!, animation);
}, "animate cylinder morph weights #1 and #2"), }, "animate cylinder morph weights #1 and #2"),
_item(() async { _item(() async {
var morphs = var morphs =
await _filamentController.getMorphTargetNames(_cube!, "Cylinder"); await _filamentController.getMorphTargetNames(_shapes!, "Cylinder");
final animation = AnimationBuilder( final animation = AnimationBuilder(
availableMorphs: morphs, framerate: 30, meshName: "Cylinder") availableMorphs: morphs, framerate: 30, meshName: "Cylinder")
.setDuration(4) .setDuration(4)
.setMorphTargets(["Key 3", "Key 4"]) .setMorphTargets(["Key 3", "Key 4"])
.interpolateMorphWeights(0, 4, 0, 1) .interpolateMorphWeights(0, 4, 0, 1)
.build(); .build();
_filamentController.setMorphAnimationData(_cube!, animation); _filamentController.setMorphAnimationData(_shapes!, animation);
}, "animate cylinder morph weights #3 and #4"), }, "animate cylinder morph weights #3 and #4"),
_item(() async { _item(() async {
var morphs = var morphs =
await _filamentController.getMorphTargetNames(_cube!, "Cube"); await _filamentController.getMorphTargetNames(_shapes!, "Cube");
final animation = AnimationBuilder( final animation = AnimationBuilder(
availableMorphs: morphs, framerate: 30, meshName: "Cube") availableMorphs: morphs, framerate: 30, meshName: "Cube")
.setDuration(4) .setDuration(4)
.setMorphTargets(["Key 1", "Key 2"]) .setMorphTargets(["Key 1", "Key 2"])
.interpolateMorphWeights(0, 4, 0, 1) .interpolateMorphWeights(0, 4, 0, 1)
.build(); .build();
_filamentController.setMorphAnimationData(_cube!, animation); _filamentController.setMorphAnimationData(_shapes!, animation);
}, "animate cube morph weights #1 and #2"), }, "animate shapes morph weights #1 and #2"),
_item(() { _item(() {
_filamentController.setMaterialColor(_cube!, "Cone", 0, Colors.purple); _filamentController.setMaterialColor(_shapes!, "Cone", 0, Colors.purple);
}, "set cone material color to purple"), }, "set cone material color to purple"),
_item(() { _item(() {
_loop = !_loop; _loop = !_loop;
@@ -239,11 +241,11 @@ class _ExampleWidgetState extends State<ExampleWidget> {
]; ];
if (_animations != null) { if (_animations != null) {
children.addAll(_animations!.map((a) => _item(() { children.addAll(_animations!.map((a) => _item(() {
_filamentController.playAnimation(_cube!, _animations!.indexOf(a), _filamentController.playAnimation(_shapes!, _animations!.indexOf(a),
replaceActive: true, crossfade: 0.5, loop: _loop); replaceActive: true, crossfade: 0.5, loop: _loop);
}, "play animation ${_animations!.indexOf(a)} (replace/fade)"))); }, "play animation ${_animations!.indexOf(a)} (replace/fade)")));
children.addAll(_animations!.map((a) => _item(() { children.addAll(_animations!.map((a) => _item(() {
_filamentController.playAnimation(_cube!, _animations!.indexOf(a), _filamentController.playAnimation(_shapes!, _animations!.indexOf(a),
replaceActive: false, loop: _loop); replaceActive: false, loop: _loop);
}, "play animation ${_animations!.indexOf(a)} (noreplace)"))); }, "play animation ${_animations!.indexOf(a)} (noreplace)")));
} }
@@ -253,7 +255,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
}, "Set tone mapping to linear")); }, "Set tone mapping to linear"));
children.add(_item(() { children.add(_item(() {
_filamentController.moveCameraToAsset(_cube!); _filamentController.moveCameraToAsset(_shapes!);
}, "Move camera to asset")); }, "Move camera to asset"));
children.add(_item(() { children.add(_item(() {
@@ -350,14 +352,14 @@ class _ExampleWidgetState extends State<ExampleWidget> {
// }); // });
// break; // break;
// case 14: // case 14:
// _filamentController.setCamera(_cube!, "Camera_Orientation"); // _filamentController.setCamera(_shapes!, "Camera_Orientation");
// break; // break;
// case 15: // case 15:
// break; // break;
// case 17: // case 17:
// var animationNames = // var animationNames =
// await _filamentController.getAnimationNames(_cube!); // await _filamentController.getAnimationNames(_shapes!);
// await showDialog( // await showDialog(
// context: context, // context: context,
@@ -390,7 +392,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
// case 23: // case 23:
// break; // break;
// case 24: // case 24:
// _filamentController.setRotation(_cube!, pi / 2, 0.0, 1.0, 0.0); // _filamentController.setRotation(_shapes!, pi / 2, 0.0, 1.0, 0.0);
// break; // break;
// case 25: // case 25:
// setState(() { // setState(() {
@@ -430,8 +432,8 @@ class _ExampleWidgetState extends State<ExampleWidget> {
// break; // break;
// case 34: // case 34:
// var duration = // var duration =
// await _filamentController.getAnimationDuration(_cube!, 0); // await _filamentController.getAnimationDuration(_shapes!, 0);
// _filamentController.playAnimation(_cube!, 0, // _filamentController.playAnimation(_shapes!, 0,
// loop: false, crossfade: 0.5); // loop: false, crossfade: 0.5);
// await Future.delayed( // await Future.delayed(
// Duration(milliseconds: (duration * 1000.0).toInt())); // Duration(milliseconds: (duration * 1000.0).toInt()));
@@ -447,13 +449,13 @@ class _ExampleWidgetState extends State<ExampleWidget> {
// // }); // // });
// break; // break;
// case 35: // case 35:
// _filamentController.playAnimation(_cube!, 1, // _filamentController.playAnimation(_shapes!, 1,
// loop: false, crossfade: 0.5); // loop: false, crossfade: 0.5);
// break; // break;
// case 36: // case 36:
// _filamentController.playAnimation(_cube!, 2, // _filamentController.playAnimation(_shapes!, 2,
// loop: false, crossfade: 0.5); // loop: false, crossfade: 0.5);
// break; // break;
// case 37: // case 37:
// _filamentController.stopAnimation(_cube!, 0); // _filamentController.stopAnimation(_shapes!, 0);
// break; // break;