# coding: utf-8
import unreal
def getOrAddPossessableInSequenceAsset(sequence_path='', actor=None):
''' 在sequence中为Actor添加unreal.SequencerBindingProxy '''
sequence_asset = unreal.LevelSequence.cast(unreal.load_asset(sequence_path))
possessable = sequence_asset.add_possessable(object_to_possess=actor)
return possessable # 返回unreal.SequencerBindingProxy
def addSkeletalAnimationTrackOnPossessable(animation_path='', possessable=None):
''' unreal.SequencerBindingProxy添加动画 '''
# 加载动画资源
animation_asset = unreal.AnimSequence.cast(unreal.load_asset(animation_path))
# 给unreal.SequencerBindingProxy 添加Track
animation_track = possessable.add_track(track_type=unreal.MovieSceneSkeletalAnimationTrack)
# 给Track添加段
animation_section = animation_track.add_section()
# 设置段的范围
animation_section.set_range(0, animation_asset.get_editor_property('sequence_length'))
# 设置段上的动画
params = unreal.MovieSceneSkeletalAnimationParams()
params.set_editor_property('Animation', animation_asset)
animation_section.set_editor_property('Params', params)
def addskeletalAnimationTrackOnActor_EXAMPLE():
sequence_path = '/Game/GenericAssets/sequence'
animation_path = '/Game/SkeletalMeshes/Animations/Character_Idle'
world = unreal.EditorLevelLibrary.get_editor_world()
actor_in_world = unreal.GameplayStatics.get_all_actors_of_class(world, unreal.SkeletalMeshActor)[0]
possessable_in_sequence = getOrAddPossessableInSequenceAsset(sequence_path, actor_in_world)
addSkeletalAnimationTrackOnPossessable(animation_path, possessable_in_sequence)
UE4编辑器Python编程8——给Sequencer添加动画
最新推荐文章于 2021-12-08 17:33:16 发布