导入贴图、音频
# coding: utf-8
import unreal
texture_tag = 'D:/LiJIngsong_File/FBX/Colours.TGA'
sound_wav = 'D:/LiJIngsong_File/FBX/kof.wav'
def buildImportTask(file_name='C:/xx.xx', destinataion_path='/Game/xx'):
''' 根据源文件路径和目标路径,构建unreal.AssetImportTask '''
task = unreal.AssetImportTask()
task.set_editor_property('automated', True)
task.set_editor_property('destination_name', '')
task.set_editor_property('destination_path', destinataion_path)
task.set_editor_property('filename', file_name)
task.set_editor_property('replace_existing', True)
task.set_editor_property('save', True)
return task
def executeImportTasks(tasks):
''' 执行unreal.AssetImportTask '''
# unreal.AssetTools().import_asset_tasks的输入是个列表
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(tasks)
for task in tasks:
for path in task.get_editor_property('imported_object_paths'):
print('Improted: %s' % path)
def importMyAsset():
texture_task = buildImportTask(texture_tag, '/Game/Textures')
sound_task = buildImportTask(sound_wav, '/Game/Sounds')
executeImportTasks([texture_task, sound_task])
执行函数importMyAsset()即可
导入静态网格体、骨架网格体
# coding: utf-8
import unreal
static_mesh_fbx = 'D:/LiJIngsong_File/FBX/c.fbx'
skeletal_mesh_fbx = 'D:/LiJIngsong_File/FBX/Character.fbx'
def buildStaticMeshImportOptions():
options = unreal.FbxImportUI()
options.set_editor_property('import_mesh', True)
options.set_editor_property('import_textures', False)
options.set_editor_property('import_materials', False)
options.set_editor_property('import_as_skeletal', False) # 有骨骼仍会被当作骨骼网格体!
options.static_mesh_import_data.set_editor_property(
'import_translation', unreal.Vector(0.0, 0.0, 0.0))
options.static_mesh_import_data.set_editor_property(
'import_rotation', unreal.Rotator(0.0, 0.0, 0.0))
options.static_mesh_import_data.set_editor_property(
'import_uniform_scale', 1.0)
options.static_mesh_import_data.set_editor_property('combine_meshes', True)
options.static_mesh_import_data.set_editor_property(
'generate_lightmap_u_vs', True)
options.static_mesh_import_data.set_editor_property(
'auto_generate_collision', True)
return options
def buildSkeletalMeshImportantOptions():
options = unreal.FbxImportUI()
options.set_editor_property('import_mesh', True)
options.set_editor_property('import_textures', True)
options.set_editor_property('import_materials', True)
options.set_editor_property('import_as_skeletal', True) # 骨架网格体
options.skeletal_mesh_import_data.set_editor_property(
'import_translation', unreal.Vector(0.0, 0.0, 0.0))
options.skeletal_mesh_import_data.set_editor_property(
'import_rotation', unreal.Rotator(0.0, 0.0, 0.0))
options.skeletal_mesh_import_data.set_editor_property(
'import_uniform_scale', 1.0)
options.skeletal_mesh_import_data.set_editor_property(
'import_morph_targets', True)
options.skeletal_mesh_import_data.set_editor_property(
'update_skeleton_reference_pose', False)
return options
def buildImportTask(file_name='C:/xx.xx', destinataion_path='/Game/xx', options=None):
task = unreal.AssetImportTask()
task.set_editor_property('automated', True)
task.set_editor_property('destination_name', '')
task.set_editor_property('destination_path', destinataion_path)
task.set_editor_property('filename', file_name)
task.set_editor_property('replace_existing', True)
task.set_editor_property('save', True)
task.set_editor_property('options', options) # Options是新加的参数
return task
def executeImportTasks(tasks):
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(tasks)
for task in tasks:
for path in task.get_editor_property('imported_object_paths'):
print('Improted: %s' % path)
def importMyAssets():
static_mesh_task = buildImportTask(
static_mesh_fbx, '/Game/Temp/StaticMeshes', buildStaticMeshImportOptions())
skeletal_mesh_task = buildImportTask(
skeletal_mesh_fbx, '/Game/Temp/SkeletalMeshes', buildSkeletalMeshImportantOptions())
executeImportTasks([static_mesh_task, skeletal_mesh_task])
执行函数importMyAssets()即可
导入动画
# coding: utf-8
import unreal
animation_fbx = 'D:/LiJIngsong_File/FBX/Character@Idle.fbx'
def buildAnimationImportOptions(skeleton_path):
''' 动画导入Options '''
options = unreal.FbxImportUI()
options.set_editor_property('import_animations', True) # 导入动画时选这个
options.skeleton = unreal.load_asset(skeleton_path) # 在这里选择目标骨架
options.anim_sequence_import_data.set_editor_property(
'import_translation', unreal.Vector(0.0, 0.0, 0.0))
options.anim_sequence_import_data.set_editor_property(
'import_rotation', unreal.Rotator(0.0, 0.0, 0.0))
options.anim_sequence_import_data.set_editor_property(
'import_uniform_scale', 1.0)
options.anim_sequence_import_data.set_editor_property(
'animation_length', unreal.FBXAnimationLengthImportType.FBXALIT_EXPORTED_TIME)
options.anim_sequence_import_data.set_editor_property(
'remove_redundant_keys', False)
return options
def buildImportTask(file_name='C:/xx.xx', destinataion_path='/Game/xx', options=None):
task = unreal.AssetImportTask()
task.set_editor_property('automated', True)
task.set_editor_property('destination_name', '')
task.set_editor_property('destination_path', destinataion_path)
task.set_editor_property('filename', file_name)
task.set_editor_property('replace_existing', True)
task.set_editor_property('save', True)
task.set_editor_property('options', options)
return task
def executeImportTasks(tasks):
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(tasks)
for task in tasks:
for path in task.get_editor_property('imported_object_paths'):
print('Improted: %s' % path)
def importMyAssets():
animation_task = buildImportTask(
animation_fbx,
'/Game/SkeletalMeshes/Animations',
buildAnimationImportOptions('/Game/SkeletalMeshes/Character_Skeleton'))
executeImportTasks([animation_task])
执行importMyAssets()即可