Tom*_*Tom 6 python 3d-model gltf
我想在Python中加载GLB模型,用另一个纹理图像替换现有纹理并保存它。
到目前为止我可以加载、修改和导出模型。另外,我找到了一种将本地图像附加到模型的方法。但我不确定如何查找和替换现有纹理。
具有一个纹理文件的 3D 模型示例:https://modelviewer.dev/shared-assets/models/Astronaut.glb
from pygltflib import GLTF2
from pygltflib.utils import ImageFormat, Image
filename = "Astronaut.glb"
gltf = GLTF2().load(filename)
image = Image()
image.uri = "new-texture.png"
gltf.images.append(image)
gltf.convert_images(ImageFormat.DATAURI)
gltf.images[0].uri
gltf.images[0].name
# How to find and replace the existing texture?
# ...
filename2 = "updated-3D-model.glb"
gltf.save(filename2)
Run Code Online (Sandbox Code Playgroud)