update example project

This commit is contained in:
Nick Fisher
2023-10-27 20:58:33 +08:00
parent 4280172767
commit 78094fbf61

View File

@@ -31,10 +31,7 @@ class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
Widget build(BuildContext context) {
return MaterialApp(
// showPerformanceOverlay: true,
home: Scaffold(
body:
ExampleWidget()
));
home: Scaffold(body: ExampleWidget()));
}
}
@@ -60,7 +57,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
bool _loop = false;
EdgeInsets _viewportMargin = EdgeInsets.zero;
bool _readyForScene = false;
bool _hasViewer = false;
bool _rendering = false;
int _framerate = 60;
@@ -69,13 +66,10 @@ class _ExampleWidgetState extends State<ExampleWidget> {
bool _coneHidden = false;
bool _frustumCulling = true;
StreamSubscription? _hasViewerListener;
@override
void dispose() {
super.dispose();
_pickResultListener?.cancel();
_hasViewerListener?.cancel();
}
Widget _item(void Function() onTap, String text) {
@@ -99,12 +93,6 @@ class _ExampleWidgetState extends State<ExampleWidget> {
picked = _filamentController!.getNameForEntity(entityId!);
});
});
_hasViewerListener =
_filamentController!.hasViewer.listen((bool hasViewer) {
setState(() {
_readyForScene = hasViewer;
});
});
}
@override
@@ -115,7 +103,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
children.addAll([
_item(() {
_createController();
}, "create viewer (default ubershader)"),
}, "create FilamentController (default ubershader)"),
_item(() {
_createController(
uberArchivePath: Platform.isWindows
@@ -125,15 +113,26 @@ class _ExampleWidgetState extends State<ExampleWidget> {
: Platform.isIOS
? "assets/lit_opaque_43.uberz"
: "assets/lit_opaque_43_gles.uberz");
}, "create viewer (custom ubershader - lit opaque only)"),
}, "create FilamentController (custom ubershader - lit opaque only)"),
]);
}
if (_readyForScene) {
} else {
if (!_hasViewer) {
children.addAll([
_item(() {
_filamentController!.createViewer();
setState(() {
_hasViewer = true;
});
}, "create FilamentViewer")
]);
} else {
children.addAll([
_item(() {
_filamentController!.destroy();
_filamentController = null;
setState(() {
_hasViewer = true;
});
}, "destroy viewer/texture"),
_item(() {
_filamentController!.render();
@@ -190,7 +189,8 @@ class _ExampleWidgetState extends State<ExampleWidget> {
_item(() async {
_shapes =
await _filamentController!.loadGlb('assets/shapes/shapes.glb');
_animations = await _filamentController!.getAnimationNames(_shapes!);
_animations =
await _filamentController!.getAnimationNames(_shapes!);
setState(() {});
}, 'load shapes GLB'),
_item(() async {
@@ -266,18 +266,20 @@ class _ExampleWidgetState extends State<ExampleWidget> {
});
}, "show morph target names for Cylinder"),
_item(() {
_filamentController!
.setMorphTargetWeights(_shapes!, "Cylinder", List.filled(4, 1.0));
_filamentController!.setMorphTargetWeights(
_shapes!, "Cylinder", List.filled(4, 1.0));
}, "set Cylinder morph weights to 1"),
_item(() {
_filamentController!
.setMorphTargetWeights(_shapes!, "Cylinder", List.filled(4, 0.0));
_filamentController!.setMorphTargetWeights(
_shapes!, "Cylinder", List.filled(4, 0.0));
}, "set Cylinder morph weights to 0.0"),
_item(() async {
var morphs = await _filamentController!
.getMorphTargetNames(_shapes!, "Cylinder");
final animation = AnimationBuilder(
availableMorphs: morphs, framerate: 30, meshName: "Cylinder")
availableMorphs: morphs,
framerate: 30,
meshName: "Cylinder")
.setDuration(4)
.setMorphTargets(["Key 1", "Key 2"])
.interpolateMorphWeights(0, 4, 0, 1)
@@ -288,7 +290,9 @@ class _ExampleWidgetState extends State<ExampleWidget> {
var morphs = await _filamentController!
.getMorphTargetNames(_shapes!, "Cylinder");
final animation = AnimationBuilder(
availableMorphs: morphs, framerate: 30, meshName: "Cylinder")
availableMorphs: morphs,
framerate: 30,
meshName: "Cylinder")
.setDuration(4)
.setMorphTargets(["Key 3", "Key 4"])
.interpolateMorphWeights(0, 4, 0, 1)
@@ -296,8 +300,8 @@ class _ExampleWidgetState extends State<ExampleWidget> {
_filamentController!.setMorphAnimationData(_shapes!, animation);
}, "animate cylinder morph weights #3 and #4"),
_item(() async {
var morphs =
await _filamentController!.getMorphTargetNames(_shapes!, "Cube");
var morphs = await _filamentController!
.getMorphTargetNames(_shapes!, "Cube");
final animation = AnimationBuilder(
availableMorphs: morphs, framerate: 30, meshName: "Cube")
.setDuration(4)
@@ -353,6 +357,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
_filamentController!.setViewFrustumCulling(_frustumCulling);
}, "${_frustumCulling ? "Disable" : "Enable"} frustum culling"));
}
}
return Stack(children: [
_filamentController != null
? Positioned.fill(