fix animation looping bug

This commit is contained in:
Nick Fisher
2023-08-24 00:57:33 +08:00
parent 03dd2cf6ac
commit 7687e54a0d
3 changed files with 13 additions and 15 deletions

View File

@@ -231,16 +231,20 @@ class _ExampleWidgetState extends State<ExampleWidget> {
}, "animate cube morph weights #1 and #2"), }, "animate cube morph weights #1 and #2"),
_item(() { _item(() {
_filamentController.setMaterialColor(_cube!, "Cone", 0, Colors.purple); _filamentController.setMaterialColor(_cube!, "Cone", 0, Colors.purple);
}, "set cone material color to purple") }, "set cone material color to purple"),
_item(() {
_loop = !_loop;
setState(() {});
}, "toggle animation looping ${_loop ? "OFF" : "ON"}")
]; ];
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(_cube!, _animations!.indexOf(a),
replaceActive: true, crossfade: 0.5); 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(_cube!, _animations!.indexOf(a),
replaceActive: false); replaceActive: false, loop: _loop);
}, "play animation ${_animations!.indexOf(a)} (noreplace)"))); }, "play animation ${_animations!.indexOf(a)} (noreplace)")));
} }
@@ -268,9 +272,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
// _item(36 () async { 'play animation 3'), // _item(36 () async { 'play animation 3'),
// _item(34 () async { 'play animation 3 (noreplace)'), // _item(34 () async { 'play animation 3 (noreplace)'),
// _item(37 () async { 'stop animation 0'), // _item(37 () async { 'stop animation 0'),
// _item(11 () async {
// Text(
// _loop ? "don't loop animation" : "loop animation")),
// _item(14 () async { 'set camera'), // _item(14 () async { 'set camera'),
// _item(15 () async { 'animate weights'), // _item(15 () async { 'animate weights'),
// _item(16 () async { 'get target names'), // _item(16 () async { 'get target names'),

View File

@@ -303,6 +303,9 @@ void AssetManager::updateAnimations() {
break; break;
} }
} }
if(anim.mLoop && elapsed >= anim.mDuration) {
anim.mStart = now;
}
// animation has completed // animation has completed
} else { } else {
completed.push_back(anim); completed.push_back(anim);

View File

@@ -337,15 +337,8 @@ class FilamentController {
bool reverse = false, bool reverse = false,
bool replaceActive = true, bool replaceActive = true,
double crossfade = 0.0}) async { double crossfade = 0.0}) async {
await _channel.invokeMethod("playAnimation", [ await _channel.invokeMethod("playAnimation",
_assetManager, [_assetManager, asset, index, loop, reverse, replaceActive, crossfade]);
asset,
index,
loop ? 1 : 0,
reverse ? 1 : 0,
replaceActive,
crossfade
]);
} }
void setAnimationFrame( void setAnimationFrame(