UE4引擎自动导入资产开发中文件导入问题(Python)

@UE4引擎自动导入资产开发中文件导入问题(Python)

话不多说上代码,这是我的代码

#coding:utf-8
import unreal
task = unreal.AssetImportTask()
# 要导入的文件名 filename (str)
task.filename = " E:\Shot\Camera\S3_E01_Sc01_Cam003_Cam_s367e424.fbx"
# 要导入资产内容的路径 
task.destination_path = '/Game/test'
 # 导入内容的自定义名称
task.destination_name = 'test'
task.replace_existing = True
task.automated = True
task.save = True

task.options = unreal.FbxImportUI()
task.options.import_as_skeletal = True
task.options.override_full_name = True
task.options.mesh_type_to_import = unreal.FBXImportType.FBXIT_SKELETAL_MESH
task.options.skeletal_mesh_import_data.set_editor_property('update_skeleton_reference_pose', False
task.options.skeletal_mesh_import_data.set_editor_property('use_t0_as_ref_pose', True) 
task.options.skeletal_mesh_import_data.set_editor_property('preserve_smoothing_groups', 1) 
task.options.skeletal_mesh_import_data.set_editor_property('import_meshes_in_bone_hierarchy', False)
task.options.skeletal_mesh_import_data.set_editor_property('import_morph_targets', True
task.options.skeletal_mesh_import_data.set_editor_property('threshold_position', 0.0002
task.options.skeletal_mesh_import_data.set_editor_property('threshold_tangent_normal', 0.0002)
task.options.skeletal_mesh_import_data.set_editor_property('threshold_uv', 0.001)
task.options.create_physics_asset = False
task.options.import_animations = False

task.options.skeletal_mesh_import_data.set_editor_property('convert_scene', True) 
task.options.skeletal_mesh_import_data.set_editor_property('force_front_x_axis', False)
task.options.skeletal_mesh_import_data.set_editor_property('convert_scene_unit', False)

normal_import_method = unreal.FBXNormalImportMethod.FBXNIM_IMPORT_NORMALS_AND_TANGENTS
normal_generation_method = unreal.FBXNormalGenerationMethod.MIKK_T_SPACE

task.options.skeletal_mesh_import_data.set_editor_property('normal_generation_method', normal_generation_method)
task.options.skeletal_mesh_import_data.set_editor_property('normal_import_method', normal_import_method) 

# 导入方法
imported_asset = unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
# 导入的路径
imported_skelmesh = task.imported_object_paths

UE4运行报的错误信息

LogAssetTools: Warning: Failed to import 'Q:\Shot\GodGunStory\S3_E01\S3_E01_Sc01_Cam003\Layout\Check\Camera\S3_E01_Sc01_Cam003_Cam_s367e424.fbx'. Failed to create asset '/Game/B/my'.
Please see Output Log for details.

这个错误信息的准确解释就是,UE4它找到了这个文件,但是无法导入。

刚开始我一直以为是UE4 API权限的问题,足足花费了一天的时间在研究如何UE4的权限。后来我请教了了一位高人,帮我找到了根本原因。当时我那个心情无比激动0

解决办法

问题所在不是代码的原因,而是资源的问题,因为我用的是import_asset_tasks方法导入的,所以只能导入资产资源,而我测试的时候用的那个资源是摄影机资源。
因为摄影机里面没有模型(这里以fbx为例,模型就是用motionbuilder打开fbx文件有骨骼的资产),而摄影机只有一些数据帧,所以导入失败,因为用的是import_asset_tasks导入的只能是asset有模型的资源,而摄影机没有。

因为项目研发时就把这下资源分好类了,所以,能够解决的办法就是,不要用这个脚本导入摄影机资源即可。

扩展,摄影机需要用另外一个api----Sequencer,有兴趣的可以研究研究,我也在研究

这是我的第一篇博客,希望可以帮到你,有写的不好的也可以提出意见哦~

发布了13 篇原创文章 · 获赞 16 · 访问量 1926

猜你喜欢

转载自blog.csdn.net/weixin_43614573/article/details/95683421