I'm need to programmatically generate box UVW maps in 3D-models, similar to how UVW Map -> Box
works in 3ds Max.
Example with box UV, what I'm after
I've tried javascript-based solutions such as this or this, but it seems to give various results depending on if the mesh/geometry is merged or if it already has any built in UV. Or it has different directions.
Applying box UV-map via Blender or 3ds Max to the same 3D-model always gives perfect results though.
Best case scenario would be a command line tool, similar to how gltf-pipeline works:
generate-box-map -i model.gltf -type box -size 50
I've found tools/projects such as PyMeshLab, Meshmatic, or running a Blender instance and attempting to do it via python, but I couldn't find a solution. Perhaps there's a native/easier way of doing this?
I ended up solving this in Blender through Docker via this image https://github.com/linuxserver/docker-blender.
The project structure is
app.js
Receives a request via
express
, body containshttps://some-storage.com/model.gltf
and starts a Blender process viachild_process.exec(`blender -b --addons magic_uv -P /app/src/main.py --log-level -1 -- ${pathToDownloadedGLTFFile}`)
main.py
Regarding the problem with different directions of UV, setting
rotation.x
to 270 seems to fix it.