Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
2ba02e3
ubuntu系统打包carla
jiandaoshou-aidehua Jun 5, 2026
9e66a46
修改对应文件
jiandaoshou-aidehua Jun 8, 2026
3964566
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Jun 8, 2026
3396b14
对齐缩进
jiandaoshou-aidehua Jun 8, 2026
4c36f87
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
jiandaoshou-aidehua Jun 8, 2026
1be6ed3
linux CI/CD 自动触发
jiandaoshou-aidehua Jun 8, 2026
93d63dc
与服务器的标签相同做的修改
jiandaoshou-aidehua Jun 8, 2026
e55b918
全局替换 Git 镜像源
jiandaoshou-aidehua Jun 8, 2026
3d2056d
不使用代理
jiandaoshou-aidehua Jun 9, 2026
fd2cd49
解决/wd4103问题
jiandaoshou-aidehua Jun 10, 2026
98e7dc1
解决LFS上传不了的问题
jiandaoshou-aidehua Jun 10, 2026
1276e9e
加快排错速度
jiandaoshou-aidehua Jun 10, 2026
ffb128e
运行不了该插件
jiandaoshou-aidehua Jun 11, 2026
74789ca
解决wd4301问题
jiandaoshou-aidehua Jun 11, 2026
4dcb45f
不使用新增插件
jiandaoshou-aidehua Jun 12, 2026
c70bdec
cpu核数过多,内存不够用
jiandaoshou-aidehua Jun 15, 2026
5a329c5
修改为原样
jiandaoshou-aidehua Jun 16, 2026
cba6f85
解决python版本过高问题
jiandaoshou-aidehua Jun 17, 2026
43c5c85
让打包机跳过扫描这批坏资产,成功完成主体打包
jiandaoshou-aidehua Jun 26, 2026
75a5f92
解决运行Checkout repository时间过长问题
jiandaoshou-aidehua Jul 1, 2026
b484dde
测试过后并非该问题
jiandaoshou-aidehua Jul 1, 2026
5a5267b
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Jul 7, 2026
0bd3706
动态跳过扫描这批坏资产
jiandaoshou-aidehua Jul 8, 2026
c76aacf
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
jiandaoshou-aidehua Jul 8, 2026
2929fe5
对LFS状态修复,先试试吧
jiandaoshou-aidehua Jul 9, 2026
179c147
回退LFS状态修复
jiandaoshou-aidehua Jul 10, 2026
89b824e
Cook 前自动修复 .uasset 中非法 /RoadRunnerMaterials/ 材质路径为 /Game/RoadRunnerMa…
jiandaoshou-aidehua Jul 12, 2026
b56b835
Merge branch 'hutb' into hutb
xiao-ma-gua Jul 12, 2026
d9d34a7
将新增的插件先改为false
jiandaoshou-aidehua Jul 13, 2026
c4459a9
将新增的插件先改为false
jiandaoshou-aidehua Jul 13, 2026
77c359a
将新增的插件先设置为false
jiandaoshou-aidehua Jul 13, 2026
f0c5d36
fix: register RoadRunnerCarlaContent plugin to resolve Cook mount poi…
jiandaoshou-aidehua Jul 14, 2026
7316845
启动最新的插件以及将依赖放在
jiandaoshou-aidehua Jul 16, 2026
33a1ad7
解压对应插件以及依赖
jiandaoshou-aidehua Jul 16, 2026
e4a3fab
只解压 插件相关 文件(RoadRunner、Cesium、MuJoCo、CoACD、libzmq)以及清理 Build/*-source…
jiandaoshou-aidehua Jul 17, 2026
7af0566
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Jul 21, 2026
4cf2ed9
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Jul 21, 2026
fb7d708
在自己远程仓库做CI/CD测试以及修改,不影响主仓库做CI/CD测试
jiandaoshou-aidehua Jul 21, 2026
f090d23
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
jiandaoshou-aidehua Jul 21, 2026
24cd092
在自己远程仓库做CI/CD测试以及修改,不影响主仓库做CI/CD测试
jiandaoshou-aidehua Jul 21, 2026
ff0f5a4
在自己远程仓库做CI/CD测试以及修改,不影响主仓库做CI/CD测试
jiandaoshou-aidehua Jul 21, 2026
d8b3e32
测试从github克隆的代码是否走代理
jiandaoshou-aidehua Jul 22, 2026
3708c54
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Jul 23, 2026
f743307
复现启动加入UnrealRoboticsLab插件的问题
jiandaoshou-aidehua Jul 23, 2026
2d159c9
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
jiandaoshou-aidehua Jul 23, 2026
604b277
fix(ci): UnrealRoboticsLab Linux编译和打包兼容性修复
jiandaoshou-aidehua Jul 24, 2026
53e4629
尝试linux用mujoco-2.3.7版本,无果
jiandaoshou-aidehua Jul 24, 2026
395a4df
在 Setup.sh 的 libpng 下载部分,下载前临时取消代理
jiandaoshou-aidehua Jul 24, 2026
2083c01
在 Plugins.sh 中添加缺失的环境源
jiandaoshou-aidehua Jul 24, 2026
00bf3ae
在 Setup.sh 的 libpng 下载部分,下载前临时取消代理
jiandaoshou-aidehua Jul 26, 2026
c21d46e
启用错误禁用的 UnrealRoboticsLab 插件的Linux系统打包
jiandaoshou-aidehua Jul 28, 2026
a43a2cc
添加个人仓库github服务器标签
jiandaoshou-aidehua Jul 28, 2026
425fe87
注释Util/BuildTools/Plugins.sh
jiandaoshou-aidehua Jul 28, 2026
56a43eb
fix(URLab): 修复 Cook 阶段 SetupAttachment ensure 崩溃导致打包失败
xiao-ma-gua Jul 29, 2026
324b516
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Jul 30, 2026
c367c30
更换标签以及在执行 make package 之前,不动态注入 return 0
xiao-ma-gua Jul 31, 2026
4d216ad
解决执行./CarlaUE4.sh没有libmujoco.so文件的问题
xiao-ma-gua Jul 31, 2026
d215992
将libmujoco.so复制到插件的相应位置
xiao-ma-gua Aug 1, 2026
ee66165
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Aug 1, 2026
feef166
绕过代理,以解决通过代理失败的外部下载问题
xiao-ma-gua Aug 1, 2026
4011663
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Aug 1, 2026
844e311
更改clang为11版本来解决编译 Boost 1.84.0 的 wrapper.cpp 时,clang-10 预处理器的宏展开栈溢出
xiao-ma-gua Aug 2, 2026
9ba482f
让 Boost 用 GCC 编译
xiao-ma-gua Aug 2, 2026
c8ad0eb
删除注释行
xiao-ma-gua Aug 2, 2026
9a2228b
在主仓库进行测试
xiao-ma-gua Aug 2, 2026
8adfd35
gcc-9编译boost还是会出现编译器崩溃的问题,改用clang11编译
xiao-ma-gua Aug 3, 2026
351b901
使用clang-10编译器
xiao-ma-gua Aug 3, 2026
c11eab6
使用clang-10编译器
xiao-ma-gua Aug 3, 2026
a26930a
关掉设置的代理
xiao-ma-gua Aug 4, 2026
fa2a05e
打开设置的代理
xiao-ma-gua Aug 4, 2026
04319cb
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Aug 5, 2026
90209a9
由于还是要使用代理来编译carla,就更换stellar(不限流量的)代理了。但是他的配置文件是加密的端口改不了,所以只能同步他的端口了
xiao-ma-gua Aug 7, 2026
7ae8842
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Aug 7, 2026
dbc64f0
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Aug 7, 2026
1dd3010
使用本地仓库执行make check
xiao-ma-gua Aug 31, 2026
28be6d0
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Aug 31, 2026
44e13d0
完成合并冲突并更新工作流
xiao-ma-gua Aug 31, 2026
ae971f2
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Aug 31, 2026
f8ee0d4
在本地仓库执行make check
xiao-ma-gua Aug 31, 2026
d9a18f9
添加make check自动化测试
xiao-ma-gua Sep 2, 2026
f345cb8
解决make setup时ninja 构建失败的问题
xiao-ma-gua Sep 3, 2026
0c4a989
解决use of undeclared identifier 'AsView' 和 no matching function for ca…
xiao-ma-gua Sep 4, 2026
f682a4f
切换服务器
xiao-ma-gua Sep 4, 2026
3c3f838
限制ninja并行任务数量,以避免资源激增
xiao-ma-gua Sep 6, 2026
f6eff34
优先使用环境中的Python系统,以便构建的wheel文件与Boost库所匹配的Python版本一致
xiao-ma-gua Sep 6, 2026
1585f22
解决parse-options:未识别的选项 ‘--chrono’
xiao-ma-gua Sep 7, 2026
b5a029d
准备好miniconda的python虚拟环境
xiao-ma-gua Sep 7, 2026
6de479e
与dependencies_u/init.sh重复实现
xiao-ma-gua Sep 8, 2026
2dc49ee
更改服务器
xiao-ma-gua Sep 8, 2026
40fcd47
使用自带而非系统miniconda
xiao-ma-gua Sep 8, 2026
24c0ffd
准备好miniconda的python虚拟环境,并构建boost时用的python和构建wheel时用的一致
xiao-ma-gua Sep 8, 2026
2ced2d3
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Sep 8, 2026
899ae3c
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Sep 8, 2026
21c89c1
删除仅创建python3.8环境的内容
xiao-ma-gua Sep 8, 2026
064efc3
准备 conda 环境 hutb_3.14 ~ hutb_3.7
xiao-ma-gua Sep 8, 2026
c8e4384
在make setup中加入执行./setup.sh指令
xiao-ma-gua Sep 9, 2026
5564d3d
setup.sh与setup.bat同步,实现对各种依赖和插件的解压
xiao-ma-gua Sep 9, 2026
d1ca47c
使用自定义的python虚拟环境
xiao-ma-gua Sep 9, 2026
65c1c3a
在make(不只是package)其他步骤时,也能创建所需要但没有的环境
xiao-ma-gua Sep 10, 2026
ee350ce
在actions-runner中加入ulimit -s unlimited不限制栈的大小
xiao-ma-gua Sep 10, 2026
77911b5
去除Package.sh中所实现的内容
xiao-ma-gua Sep 14, 2026
8b20fc1
限制并发数
xiao-ma-gua Sep 14, 2026
fafe4cc
优先使用仓库里boost的本地包
xiao-ma-gua Sep 15, 2026
ec5a831
单元测试通过
xiao-ma-gua Sep 16, 2026
fbf29a0
make check中的内容与windows同步
xiao-ma-gua Sep 17, 2026
33d6024
加入冒烟、空中、VR、上传的check指令
xiao-ma-gua Sep 17, 2026
0087dbe
运行./CarlaUE4.sh是OBJ/STL解码器重复运行而导致运行崩溃
xiao-ma-gua Sep 17, 2026
78a0b39
Linux上部分Python版本导入失败,此时跳过补丁
xiao-ma-gua Sep 17, 2026
547a33e
注释掉一些check指令
xiao-ma-gua Sep 17, 2026
b860f4a
Merge branch 'hutb' into hutb
xiao-ma-gua Sep 17, 2026
21d60b9
加入冒烟、飞行模拟器、VR测试;对脚本排版,位置与Check.bat相对应
xiao-ma-gua Sep 17, 2026
83f13e4
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Sep 17, 2026
6a88bcd
切换服务器
xiao-ma-gua Sep 18, 2026
b57866d
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Sep 20, 2026
44d20b8
更换到主仓库的服务器
xiao-ma-gua Sep 20, 2026
4a3925d
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Sep 20, 2026
c6abebf
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Sep 21, 2026
4ce7898
切换服务器
xiao-ma-gua Sep 21, 2026
4f38987
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Sep 21, 2026
c1f542e
同步Check.bat,在执行check.pythonAPI时,没有杀死进程。虽然开始也会杀死进程,但是执行完pythonAPI后就立马执…
xiao-ma-gua Sep 21, 2026
f547278
只在后台打开一次进程
xiao-ma-gua Sep 21, 2026
eadd51d
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Sep 21, 2026
aed604d
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Sep 21, 2026
c4bdd37
解决dirname:未识别的选项 ‘---------------------------|-----------------’问题
xiao-ma-gua Sep 21, 2026
e1b8765
与Check.sh中air测试同步
xiao-ma-gua Sep 28, 2026
f0d6be0
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Sep 28, 2026
ec86f91
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Sep 28, 2026
b37785d
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Sep 30, 2026
5a09782
将AIR测试放在最后
xiao-ma-gua Sep 30, 2026
b86c40f
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Oct 6, 2026
4075ce9
注释03_spawn_traffic.py代码
xiao-ma-gua Oct 6, 2026
6801775
与Check.sh同步】
xiao-ma-gua Oct 6, 2026
a53ed60
修正语法错误
xiao-ma-gua Oct 6, 2026
5fc36e3
注释TrafficManager.cpp
xiao-ma-gua Oct 8, 2026
9f245d8
加上报错信息,更快锁定错误
xiao-ma-gua Oct 8, 2026
0c957fd
先提交通过API、冒烟和vr测试的代码
xiao-ma-gua Oct 8, 2026
13f52df
将无人机的测试逐步排查
xiao-ma-gua Oct 10, 2026
025ae58
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Oct 11, 2026
080a432
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Oct 11, 2026
0921ff2
删除无人机测试的03py脚本
xiao-ma-gua Oct 11, 2026
ae7a325
下载后解压生成的模拟器路径和Windows不一致,但只治标不治本
xiao-ma-gua Oct 13, 2026
8b1109b
删掉04py脚本
xiao-ma-gua Oct 13, 2026
a3aa93b
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Oct 13, 2026
ed46e4f
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Oct 13, 2026
21b0276
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Oct 14, 2026
cd6e394
打包的文件夹与windows同步
xiao-ma-gua Oct 14, 2026
c93c135
通过后缀判断重命名为对应的压缩包
xiao-ma-gua Oct 14, 2026
cb65fa3
加入打包成功后自动上传到工蜂的步骤
xiao-ma-gua Oct 15, 2026
9d1d8da
实现打包成功自动上传到工蜂仓库
xiao-ma-gua Oct 15, 2026
834d205
上传工蜂仓库成功后删除工作目录。合并时根据对应文件头合成对应压缩包并用对应解压器解压
xiao-ma-gua Oct 15, 2026
54400d6
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Oct 21, 2026
b28dc3e
适配 Ubuntu 24.04 的 Boost/rpclib 构建参数
xiao-ma-gua Oct 21, 2026
aeb1ad8
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Oct 21, 2026
cc2ff9d
libc++改为统一使用 UE4 4.26 自带的 libc++ 10
xiao-ma-gua Oct 22, 2026
3566edb
libc++改为统一使用 UE4 4.26 自带的 libc++ 10
xiao-ma-gua Oct 22, 2026
5a5d6ad
Revert "libc++改为统一使用 UE4 4.26 自带的 libc++ 10"
xiao-ma-gua Oct 22, 2026
aef4142
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Oct 22, 2026
1328b64
libc++改为统一使用 UE4 4.26 自带的 libc++ 10
xiao-ma-gua Oct 22, 2026
966d16f
重启CI/CD
xiao-ma-gua Oct 22, 2026
227be04
解决链接器找不到 pthread 函数的定义问题
xiao-ma-gua Oct 22, 2026
b886a92
修正 -pthread 参数位置,确保进入链接
xiao-ma-gua Oct 24, 2026
046e4f0
解决car_assets.zip从线上拉取速度慢的问题
xiao-ma-gua Oct 27, 2026
d24d576
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Oct 27, 2026
60de18b
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Oct 27, 2026
1fc3a51
做完check再上传可执行文件,防止上传的可以执行文件打不开
xiao-ma-gua Oct 28, 2026
dc05633
还原之前的文件,加快xerces-c的下载速度
xiao-ma-gua Oct 28, 2026
6a410d7
先从工蜂下载osm2odr压缩包再从github
xiao-ma-gua Nov 3, 2026
0a2f518
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Nov 3, 2026
c3ac8bf
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Nov 4, 2026
99e8a71
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Nov 6, 2026
ed53579
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Nov 9, 2026
3b304ae
解决资产生成成功但蓝图不显示
xiao-ma-gua Nov 11, 2026
66707fa
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Nov 11, 2026
bf5a9b9
Merge branch 'hutb' of github.com:xiao-ma-gua/hutb into hutb
xiao-ma-gua Nov 11, 2026
02eaf34
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Nov 15, 2026
e40ca18
Merge branch 'OpenHUTB:hutb' into hutb
xiao-ma-gua Nov 16, 2026
ea69def
首次拉xml文件到内容编辑器中,所需包进行弹窗提示
xiao-ma-gua Nov 16, 2026
e16145b
解决MS-Human-700.xml 导入失败
xiao-ma-gua Nov 19, 2026
504faef
取消强制推送至工蜂仓库
xiao-ma-gua Nov 22, 2026
0f28016
手动触发make check.upload
xiao-ma-gua Nov 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ jobs:
make check.smoke
make check.vr
make check.air
make check.upload
# 只在手动触发时上传
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then make check.upload; fi
shell: bash


154 changes: 98 additions & 56 deletions Unreal/CarlaUE4/Plugins/UnrealRoboticsLab/Scripts/clean_meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@
# CoACD (MIT), and libzmq (MPL 2.0). See ThirdPartyNotices.txt for details.

"""
Prepare MuJoCo MJCF meshes for Unreal import.
准备 MuJoCo MJCF 网格以供 Unreal 导入。

Parses an MJCF XML, converts all referenced meshes (OBJ, STL) to GLB,
resolves naming conflicts (e.g., link1.obj and link1.stl both becoming link1.glb),
and writes an updated XML ready for drag-and-drop import into Unreal.
解析 MJCF XML(展开 <include> 文件),将所有引用的网格文件(OBJ、STL)转换为 GLB 格式,
解决命名冲突(例如 link1.obj 和 link1.stl 均被转为 link1.glb),并生成更新后的 XML 文件,
可直接拖拽导入 Unreal.

Installation:
安装:
pip install trimesh numpy

Usage:
用法:
python clean_meshes_trimesh.py <path_to_xml>

Example:
示例:
python clean_meshes_trimesh.py "path/to/mujoco_menagerie/franka_emika_panda/panda.xml"
"""


import trimesh
import numpy as np
from pathlib import Path
Expand All @@ -46,14 +47,14 @@


def clean_mesh(mesh):
"""Clean up a mesh using trimesh."""
"""使用 trimesh 清理网格。"""
print(f" Original: {len(mesh.vertices)} vertices, {len(mesh.faces)} faces")

mesh.merge_vertices(merge_tex=False, merge_norm=False)
mesh.remove_unreferenced_vertices()
mesh.fix_normals()

# Rotate -90 degrees around X for GLTF Y-up -> Unreal Z-up
# 绕 X 轴旋转 -90 度,将 GLTF 的 Y 轴向上坐标系转换为 Unreal 的 Z 轴向上坐标系
rotation_matrix = trimesh.transformations.rotation_matrix(-np.radians(90), [1, 0, 0])
mesh.apply_transform(rotation_matrix)

Expand All @@ -62,7 +63,7 @@ def clean_mesh(mesh):


def convert_mesh(input_path: Path, output_path: Path) -> bool:
"""Convert a single mesh file to GLB."""
"""将单个网格文件转换为 GLB。"""
print(f"\n Converting: {input_path.name} -> {output_path.name}")

try:
Expand All @@ -74,9 +75,9 @@ def convert_mesh(input_path: Path, output_path: Path) -> bool:

cleaned_mesh = clean_mesh(mesh)

# Strip embedded materials/textures to prevent Unreal's Interchange importer
# from creating a Texture2D instead of a StaticMesh.
# Preserve UV coordinates so textures can be applied via material instances.
# 剥离内嵌的材质/纹理,防止 Unreal 的 Interchange 导入器
# 将其创建为 Texture2D 而不是 StaticMesh。
# 保留 UV 坐标,以便之后通过材质实例来应用纹理。
if hasattr(cleaned_mesh.visual, 'uv') and cleaned_mesh.visual.uv is not None:
uv = cleaned_mesh.visual.uv.copy()
cleaned_mesh.visual = trimesh.visual.TextureVisuals(uv=uv)
Expand Down Expand Up @@ -104,7 +105,7 @@ def convert_mesh(input_path: Path, output_path: Path) -> bool:


def process_xml(xml_path: Path):
"""Parse MJCF XML, convert meshes, resolve conflicts, write updated XML."""
"""解析MJCF XML,转换网格,解决冲突,生成更新后的XML。"""

if not xml_path.exists():
print(f"Error: XML file not found: {xml_path}")
Expand All @@ -116,24 +117,79 @@ def process_xml(xml_path: Path):
print(f"Dir: {xml_dir}")
print("=" * 60)

# Parse XML
# ET.parse() 打开文件并解析整个 XML,返回一个 ElementTree 对象。
# tree.getroot() 取出根元素。对于 MJCF 文件,根就是 <mujoco> 标签。
tree = ET.parse(str(xml_path))
root = tree.getroot()

# Find meshdir from compiler
# 从 <compiler> 元素中查找 meshdir 属性
meshdir = ""
for compiler in root.iter("compiler"):
md = compiler.get("meshdir", "")
if md:
meshdir = md

# Path 的 / 运算符是路径拼接,不是算术除法。
mesh_base = xml_dir / meshdir if meshdir else xml_dir
print(f"Mesh directory: {mesh_base}")

# Collect all mesh elements
mesh_elements = list(root.iter("mesh"))

# Also convert meshes referenced by <flexcomp file="...">
# ------------------------------------------------------------------
# 收集网格,递归展开 <include>
# 相对的网格路径会相对于声明它们的文件所在目录进行解析(即 MuJoCo 的解析方式)。
# <compiler meshdir="..."> 具有优先权,且相对于主 XML 目录。
# ------------------------------------------------------------------
mesh_elements = [] # (mesh_element, source_path) 列表
# 递归展开 <include> 时的**“已访问文件”集合**,用来防止死循环和重复解析
seen_includes = {xml_path.resolve()}

# 递归函数:从给定节点收集网格和 <include>,并解析包含的文件
def collect_from_include(node_root: ET.Element, owner_dir: Path):
base_dir = mesh_base if meshdir else owner_dir

for mesh_el in node_root.iter("mesh"):
file_attr = mesh_el.get("file")
if not file_attr:
continue

# 确保显式名称属性存在——如果省略,MuJoCo 默认使用文件名前缀。
# 在更改文件属性之前,我们必须保留它。
if mesh_el.get("name") is None:
implicit_name = Path(file_attr).stem
mesh_el.set("name", implicit_name)
print(f" Set explicit name='{implicit_name}' on mesh with file='{file_attr}'")

# 添加网格条目:包括 mesh 元素和源文件路径
mesh_elements.append((mesh_el, base_dir / file_attr))

for include_el in node_root.iter("include"):
file_attr = include_el.get("file")
if not file_attr:
continue
# resolve() 是 pathlib.Path 的方法:把路径规范化成唯一的绝对路径。
# 它做三件事:
# 1.变成绝对路径(相对路径拼上当前工作目录)
# 2.消掉 . 和 ..(纯字符串/路径层面的规整)
# 3.解析符号链接(symlink 指向哪,就得到真实路径)
include_path = (owner_dir / file_attr).resolve()
if include_path in seen_includes:
continue
seen_includes.add(include_path)
if not include_path.exists():
print(f" x Included file not found: {include_path}")
continue
print(f" Expanding include: {include_path}")
try:
# 得到include的文件中的根节点
include_root = ET.parse(str(include_path)).getroot()
except ET.ParseError as e:
print(f" x Failed to parse {include_path}: {e}")
continue
# 再看include文件中的 <include>,递归展开
collect_from_include(include_root, include_path.parent)

collect_from_include(root, xml_dir)

# 转换由 <flexcomp file="..."> 引用的网格(也包括来自 include 文件的网格)。
for flexcomp in root.iter("flexcomp"):
file_attr = flexcomp.get("file")
if file_attr:
Expand All @@ -148,77 +204,63 @@ def process_xml(xml_path: Path):

print(f"Found {len(mesh_elements)} mesh assets in XML\n")

# Phase 1: Plan output filenames, detect conflicts
# Map: glb_stem -> list of (mesh_element, source_path)
# 阶段 1:规划输出文件名,检测冲突。
# 映射:glb_stem -> (mesh_element, source_path) 列表
stem_usage = {}

for mesh_el in mesh_elements:
file_attr = mesh_el.get("file")
if not file_attr:
continue

source_path = mesh_base / file_attr
glb_stem = source_path.stem # e.g., "link1" from "link1.stl"

# Ensure explicit name attribute exists — MuJoCo defaults to filename stem
# if omitted. We must preserve it before changing the file attribute.
if mesh_el.get("name") is None:
implicit_name = Path(file_attr).stem
mesh_el.set("name", implicit_name)
print(f" Set explicit name='{implicit_name}' on mesh with file='{file_attr}'")

for mesh_el, source_path in mesh_elements:
glb_stem = source_path.stem # 例如,从 "/…/assets/geometry/link1.stl" 得到 "link1"
if glb_stem not in stem_usage:
stem_usage[glb_stem] = []
stem_usage[glb_stem].append((mesh_el, source_path))

# Phase 2: Assign unique output names and resolve conflicts
# For each mesh: keep the original format (OBJ/STL) in the XML (MuJoCo needs it),
# but rename conflicting files so their stems are unique. Then convert each to GLB
# alongside — Unreal's importer will find the GLB via "higher priority" fallback.
#
# output_plan: list of (mesh_element, source_path, renamed_source_path, output_glb_path, new_file_attr)
# 阶段 2:分配唯一的输出名称并解决冲突
# 对于每个网格:在 XML 中保留原始格式(OBJ/STL)(MuJoCo 需要它),
# 但重命名冲突的文件,使其文件名主干唯一。然后将每个网格一并转换为 GLB——
# Unreal 的导入器会通过“更高优先级”的回退机制找到 GLB。
# output_plan:由 (mesh_el, original_source, actual_source, output_glb) 组成的列表
import shutil
output_plan = []
conflicts_found = 0

for glb_stem, entries in stem_usage.items():
if len(entries) == 1:
# No conflict
# 无冲突
mesh_el, source_path = entries[0]
output_glb = source_path.with_suffix(".glb")
# file attr stays unchanged in the XML
# XML 中的 file 属性保持不变
output_plan.append((mesh_el, source_path, source_path, output_glb))
else:
# Conflict — multiple source files share the same stem
# 冲突——多个源文件共用同一主干名
conflicts_found += len(entries) - 1
print(f" CONFLICT: {len(entries)} files map to stem '{glb_stem}':")
for i, (mesh_el, source_path) in enumerate(entries):
mesh_name = mesh_el.get("name", "?")
print(f" [{i}] mesh name='{mesh_name}' <- {source_path.name}")

# First one keeps original name, rest get a counter suffix
# 第一个保留原始名称,其余添加计数后缀
for i, (mesh_el, source_path) in enumerate(entries):
if i == 0:
# No rename needed
# 无需重命名
output_glb = source_path.with_suffix(".glb")
output_plan.append((mesh_el, source_path, source_path, output_glb))
else:
# Rename: link1.stl -> link1_1.stl, link1_1.glb
# Save to meshdir root (not the source subdirectory) so the
# XML file attribute stays a simple filename relative to meshdir.
# 重命名:link1.stl -> link1_1.stl,link1_1.glb
# 保存到 meshdir 根目录(而不是源文件所在子目录),
# 这样 XML 的 file 属性可以保持为相对于 meshdir 的简单文件名。
new_stem = f"{glb_stem}_{i}"
ext = source_path.suffix # .stl, .obj, etc.
renamed_source = mesh_base / f"{new_stem}{ext}"
output_glb = mesh_base / f"{new_stem}.glb"

# Update XML file attribute (relative to meshdir)
# 更新 XML 的 file 属性(相对于 meshdir)
new_file_attr = f"{new_stem}{ext}"
mesh_el.set("file", new_file_attr)

mesh_name = mesh_el.get("name", "?")
print(f" -> Renaming '{mesh_name}': {source_path.name} -> {new_stem}{ext}")

# Copy the source file to the new name
# 将源文件复制到新名称
if not source_path.exists():
print(f" x Source file missing: {source_path} — skipping")
continue
Expand All @@ -231,7 +273,7 @@ def process_xml(xml_path: Path):
print(f"\n{len(output_plan)} meshes to convert, {conflicts_found} naming conflicts resolved")
print("=" * 60)

# Phase 3: Convert meshes to GLB (alongside the originals)
# 阶段 3:将网格转换为 GLB(与原文件放在同一目录)
success_count = 0
for mesh_el, original_source, actual_source, output_glb in output_plan:
mesh_name = mesh_el.get("name", "?")
Expand All @@ -240,7 +282,7 @@ def process_xml(xml_path: Path):
print(f"\n x Source not found: {actual_source}")
continue

# Skip if GLB already exists and is newer than source
# 如果 GLB 已存在且比源文件新,则跳过
if output_glb.exists() and output_glb.stat().st_mtime > actual_source.stat().st_mtime:
print(f"\n Skipping '{mesh_name}' (GLB up to date): {output_glb.name}")
success_count += 1
Expand All @@ -252,7 +294,7 @@ def process_xml(xml_path: Path):
else:
print(f" x FAILED to convert {actual_source.name}")

# Phase 4: Write updated XML
# 阶段 4:写出更新后的 XML
output_xml = xml_path.parent / f"{xml_path.stem}_ue.xml"
tree.write(str(output_xml), encoding="unicode", xml_declaration=True)

Expand Down
Loading
Loading