Unreal 开发记录
1、Python And UEa. API文档
Unreal Python API Documentation — Unreal Python 5.0 (Experimental) documentation (unrealengine.com)
b. 开启插件
c. 插件设置
d.VSCode 配置
1、在项目的\Intermediate\PythonStub文件夹下生成了unreal.py
2、VSCode安装Python
3、VSCode的Python的配置
4、配置信息
"python.autoComplete.extraPaths": [
"E:\\UE\\Develop\\Project\\MyNaniteTestProject5\\Intermediate\\PythonStub"
],
"python.jediEnable": false,
"jupyter.enableExtendedKernelCompletions": true,
"python.analysis.extraPaths": [
"E:\\UE\\Develop\\Project\\MyNaniteTestProject5\\Intermediate\\PythonStub"
]
5、重启VSCode和Ue项目
6、实现了FBX和Datasmith的数据导入处理
7、示例程序
import unreal
#FBX导入
def build_static_mesh_import_options():
options = unreal.FbxImportUI()
options.set_editor_property('automated_import_should_detect_type', False)
options.set_editor_property('mesh_type_to_import', unreal.FBXImportType.FBXIT_STATIC_MESH)
options.set_editor_property('import_as_skeletal', False)# 是否当作骨骼物体来导入
options.set_editor_property('import_animations', False)
options.set_editor_property('import_materials', True)
options.set_editor_property('import_textures', True)
#上面是设置fbx import UI的数据
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))
options.static_mesh_import_data.set_editor_property('import_uniform_scale', 1.0)
options.static_mesh_import_data.set_editor_property('combine_meshes', False)
options.static_mesh_import_data.set_editor_property('generate_lightmap_u_vs', False)
options.static_mesh_import_data.set_editor_property('auto_generate_collision', False)
options.static_mesh_import_data.set_editor_property('one_convex_hull_per_ucx', True)
options.static_mesh_import_data.set_editor_property('reorder_material_to_fbx_order', True)
#上面是设置static_mesh_import_data的数据
return options
#Datasmith导入
def build_Datasmith_import_options():
options = unreal.DatasmithImportBaseOptions()
options.set_editor_property('include_animation', False)
options.set_editor_property('include_camera', False)
options.set_editor_property('include_geometry', True)
options.set_editor_property('include_light', False)
options.set_editor_property('include_material', True)
#上面是设置 UI的数据
#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))
#options.static_mesh_import_data.set_editor_property('import_uniform_scale', 1.0)
#options.static_mesh_import_data.set_editor_property('combine_meshes', False)
#options.static_mesh_import_data.set_editor_property('generate_lightmap_u_vs', False)
#options.static_mesh_import_data.set_editor_property('auto_generate_collision', False)
#options.static_mesh_import_data.set_editor_property('one_convex_hull_per_ucx', True)
#options.static_mesh_import_data.set_editor_property('reorder_material_to_fbx_order', True)
#上面是设置static_mesh_import_data的数据
return options
def creatImportTask(filename, Destination_path, options=None,factory = None):
importtask = unreal.AssetImportTask()
importtask.set_editor_property("automated", True)
importtask.set_editor_property('destination_path', Destination_path)
importtask.set_editor_property('filename', filename)
importtask.set_editor_property('replace_existing', True)
importtask.set_editor_property('options', options)
importtask.set_editor_property('save', True)
importtask.set_editor_property('factory',factory)
return importtask
def execute_import_tasks(tasks):
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()# 创建一个资产工具
asset_tools.import_asset_tasks()
Destination_path = "/Game/texture/"
StaticMesh_path = "E:/ue/data/bunny.obj"
DataSmith_path="E:/ue/data/bunny.udatasmith"
#FBX的导入
#options = build_static_mesh_import_options()
#execute_import_tasks(creatImportTask(StaticMesh_path, Destination_path, options,None))
##Datasmith导入
datasmithImportOptions =unreal.DatasmithImportOptions();
datasmithImportOptions.base_options = build_Datasmith_import_options();
#需要指定的导入工厂类型通过调试ue源码发现,需要指定个工厂类
datasmithFactory = unreal.DatasmithImportFactory();
execute_import_tasks(creatImportTask(DataSmith_path, Destination_path, datasmithImportOptions , datasmithFactory))
8、python的执行
8.1 命令行执行
UnrealEditor-Cmd.exe "E:\UE\projectTest.uproject" -run=pythonscript -script="C:\\Users\\Administrator\\Desktop\\UePython\\PythonUE.py"
8.2 编辑器界面下菜单栏 Tools->ExecutePython Script...
页:
[1]