"""Verify moving slash root travel becomes persistent parent Transform keys.""" import json import math import unreal from ue_workshop import Scene, Sequence, Renderer, camera, lighting from ue_workshop.animations import FighterAnimations as F from ue_workshop.characters import FIGHTER_MODEL from ue_workshop.paths import PROJECT scene = Scene("KeepEndSmoke") actor = scene.skeletal_model(FIGHTER_MODEL, name="Fighter", height=200) child, imported = scene._skeletal_models[actor.get_path_name()] original = imported.animations[F.GREAT_SWORD_SLASH_2.key] bone = child.skeletal_mesh_component.get_bone_name(0) before = unreal.AnimationLibrary.get_bone_pose_for_time(original, bone, original.get_play_length(), False) scene.primitive("Cube", name="Floor", location=(0, 0, -10), scale=(20, 20, 0.2)) lighting.studio(scene) cam = camera.create(scene, location=(650, -650, 450), target=(0, 150, 100), fov=55) shot = Sequence(scene, fps=30, frames=300) shot.camera(cam) section = shot.animation(actor, F.GREAT_SWORD_SLASH_2, start=57, keep_end_position=True) shot.animation(actor, F.GREAT_SWORD_SLASH_3, start=161) copy = section.get_editor_property("params").animation assert copy != original end = unreal.AnimationLibrary.get_bone_pose_for_time(copy, bone, copy.get_play_length(), False) start = unreal.AnimationLibrary.get_bone_pose_for_time(copy, bone, 0, False) assert abs(end.translation.y - start.translation.y) < 0.001 after = unreal.AnimationLibrary.get_bone_pose_for_time(original, bone, original.get_play_length(), False) assert abs(after.translation.y - before.translation.y) < 0.001 channels = shot._transforms[actor.get_path_name()] last = [channel.get_keys()[-1].get_value() for channel in channels[:3]] assert math.hypot(last[0], last[1]) > 100, last assert channels[0].get_keys()[-1].get_time().frame_number.value == section.get_end_frame() shot.save(open_editor=False) unreal.LevelSequenceEditorBlueprintLibrary.open_level_sequence(shot.asset) positions = {} hips_positions = {} for frame in (57, 160, 161, 162, 163, 164, 190): unreal.LevelSequenceEditorBlueprintLibrary.set_current_time(frame) unreal.LevelSequenceEditorBlueprintLibrary.refresh_current_level_sequence() positions[frame] = actor.get_actor_location().to_tuple() hips_positions[frame] = child.skeletal_mesh_component.get_socket_location(bone).to_tuple() assert math.dist(positions[163], positions[190]) < 0.01, positions assert math.dist(positions[162], positions[163]) < 20, positions assert math.dist(hips_positions[162], hips_positions[163]) < 30, hips_positions assert abs((hips_positions[160][1] - hips_positions[57][1]) - (positions[160][1] - positions[57][1])) < 1, hips_positions (PROJECT / "Saved/Workshop/keep_end_position.json").write_text(json.dumps(positions, indent=2), encoding="utf-8") renderer = Renderer(width=640, height=360, samples=1, warmup=0, mp4=False)