我需要以编程方式在 3D 模型中生成长方体 UVW 贴图,类似于
UVW Map -> Box
在 3ds Max 中的工作方式。
我尝试过基于javascript的解决方案例如this或this,但它似乎会给出不同的结果,具体取决于网格/几何体是否合并或者是否已经有任何内置UV。或者。
通过 Blender 或 3ds Max 将盒子 UV 贴图应用到同一个 3D 模型总是能给出完美的结果。
最好的情况是命令行工具,类似于 gltf-pipeline 的工作方式:
generate-box-map -i model.gltf -type box -size 50
我找到了诸如 PyMeshLab、Meshmatic 之类的工具/项目,或者运行 Blender 实例并尝试通过 python 来完成此操作,但我找不到解决方案。也许有一种本地/更简单的方法可以做到这一点?
我最终通过这个图像通过 Docker 在 Blender 中解决了这个问题 https://github.com/linuxserver/docker-blender.
项目结构是
app.js
通过
express
接收请求,主体包含 https://some-storage.com/model.gltf
并通过 child_process.exec(`blender -b --addons magic_uv -P /app/src/main.py --log-level -1 -- ${pathToDownloadedGLTFFile}`)
启动 Blender 进程
main.py
...
argv = sys.argv
argv = argv[argv.index("--") + 1:] # get all args after "--"
param_input_file = argv[0]
bpy.ops.import_scene.gltf(filepath=param_input_file)
for obj in bpy.data.objects:
if obj.type == 'MESH':
obj.select_set(True) # select the object
bpy.context.view_layer.objects.active = obj # needed to enable Edit mode below
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.uv.muv_uvw_box_map(size=instructions['size'], rotation=(instructions['rotationX'], instructions['rotationY'], instructions['rotationZ']))
...
# export back to GLTF and write to /some/dir/model.gltf