split animation components into GltfAnimation/MorphAnimation/BoneAnimation

This commit is contained in:
Nick Fisher
2025-05-17 10:11:55 +08:00
parent f9d09e17ef
commit c98e604e76
12 changed files with 1109 additions and 483 deletions

View File

@@ -3,45 +3,87 @@ import 'dart:typed_data';
import 'package:animation_tools_dart/animation_tools_dart.dart';
import 'package:test/test.dart';
import 'package:thermion_dart/src/bindings/bindings.dart';
import 'package:thermion_dart/src/filament/src/implementation/ffi_asset.dart';
import 'package:thermion_dart/src/viewer/src/ffi/src/thermion_viewer_ffi.dart';
import 'package:thermion_dart/thermion_dart.dart';
import 'helpers.dart';
void main() async {
final testHelper = TestHelper("animation");
await testHelper.setup();
group('morph animation tests', () {
test('retrieve morph target names', () async {
await testHelper.withViewer((viewer) async {
final cube = await viewer.loadGltf(
"${testHelper.testDir}/assets/cube_with_morph_targets.glb");
final childEntities = await cube.getChildEntities();
var morphTargets =
await cube.getMorphTargetNames(entity: childEntities.first);
expect(morphTargets.length, 1);
expect(morphTargets.first, "Key 1");
});
});
test('set morph target weights', () async {
await testHelper.withViewer((viewer) async {
final cube = await viewer.loadGltf(
"${testHelper.testDir}/assets/cube_with_morph_targets.glb");
print(await cube.getChildEntityNames());
await viewer.addToScene(cube);
await testHelper.capture(viewer.view, "cube_no_morph");
test('get morph target names', () async {
await testHelper.withViewer((viewer) async {
var cube = await viewer.loadGltf("${testHelper.testDir}/assets/cube.glb");
var morphTargets = await cube.getMorphTargetNames();
expect(morphTargets.length, 0);
final childEntities = await cube.getChildEntities();
var childEntities = await cube.getChildEntities();
var childEntity = childEntities.first;
var morphData = MorphAnimationData(
Float32List.fromList([1.0]), ["Key 1"],
frameLengthInMs: 1000.0 / 60.0);
await cube.addAnimationComponent(childEntities.first);
await cube.setMorphAnimationData(morphData);
await viewer.render();
await testHelper.capture(viewer.view, "cube_with_morph");
}, bg: kRed);
morphTargets = await cube.getMorphTargetNames(entity: childEntity);
expect(morphTargets.length, 0);
cube = await viewer
.loadGltf("${testHelper.testDir}/assets/cube_with_morph_targets.glb");
morphTargets = await cube.getMorphTargetNames();
expect(morphTargets.length, 0);
childEntities = await cube.getChildEntities();
morphTargets =
await cube.getMorphTargetNames(entity: childEntities.first);
expect(morphTargets.length, 1);
expect(morphTargets.first, "Key 1");
});
});
test('set morph target weights', () async {
await testHelper.withViewer((viewer) async {
final cube = await viewer.loadGltf(
"${testHelper.testDir}/assets/cube_with_morph_targets.glb");
await viewer.addToScene(cube);
await testHelper.capture(viewer.view, "cube_no_morph");
await cube.setMorphTargetWeights((await cube.getChildEntities()).first, [1.0]);
await testHelper.capture(viewer.view, "cube_with_morph");
}, bg:kRed, cameraPosition: Vector3(3, 2, 6));
});
test('set morph target animation', () async {
await testHelper.withViewer((viewer) async {
final cube = await viewer.loadGltf(
"${testHelper.testDir}/assets/cube_with_morph_targets.glb");
await viewer.addToScene(cube);
var morphData = MorphAnimationData(Float32List.fromList([1.0]), ["Key 1"],
frameLengthInMs: 1000.0 / 60.0);
await cube.setMorphAnimationData(morphData);
await viewer.render();
await testHelper.capture(viewer.view, "cube_with_morph_animation");
}, bg:kRed, cameraPosition: Vector3(3, 2, -6));
});
test('get gltf animation names', () async {
await testHelper.withViewer((viewer) async {
final cube = await viewer
.loadGltf("${testHelper.testDir}/assets/cube_with_morph_targets.glb");
await viewer.addToScene(cube);
await testHelper.capture(viewer.view, "gltf_animation_stopped");
final animationNames = await cube.getGltfAnimationNames();
expect(animationNames.first, "CubeAction");
await cube.playGltfAnimation(0);
await Future.delayed(Duration(seconds: 1));
await viewer.render();
await testHelper.capture(viewer.view, "gltf_animation_started");
}, bg: kRed);
});
}