I want to load a GLB model in Python, replace the existing texture with another texture image and save it.
So far I can load, modify and export the model. Also, I found a way to append a local image to the model. But I'm not sure how to find and replace the existing texture.
Example 3D model with one texture file: 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)