Open pvnieo opened 3 years ago
Hi @mikedh I'm getting a step closer!
I succeeded to add the image to the shape, but because my surface coordinates are random, the texture it self is random. This is what I did:
uv = np.random.rand(m.vertices.shape[0], 2)
material = trimesh.visual.texture.SimpleMaterial(image=im)
color_visuals = trimesh.visual.TextureVisuals(uv=uv, image=im, material=material)
mesh=trimesh.Trimesh(vertices=m.vertices, faces=m.faces, visual=color_visuals, validate=True, process=False)
mesh.show
and this gives me the following:
Can you suggest me a way to compute the uv
?
Thank you in advance!
Hi @mikedh I'm getting a step closer!
I succeeded to add the image to the shape, but because my surface coordinates are random, the texture it self is random. This is what I did:
uv = np.random.rand(m.vertices.shape[0], 2) material = trimesh.visual.texture.SimpleMaterial(image=im) color_visuals = trimesh.visual.TextureVisuals(uv=uv, image=im, material=material) mesh=trimesh.Trimesh(vertices=m.vertices, faces=m.faces, visual=color_visuals, validate=True, process=False) mesh.show
and this gives me the following:
Can you suggest me a way to compute the
uv
?Thank you in advance! I can tell you the way to compute the uv cordinate, but I want to know how apply multiple texture to a Trimesh and show it
In my case, the .obj file contains uv information. Note that if the mesh.show() present a dark texture, use pyrender library
Just a note for others, I managed to manually calculate and pack my UV coordinates into a .ply, then I read that in by Trimesh, then applied my image as a texture, and boom!
import trimesh
from PIL import Image
mesh = trimesh.load("model.ply", process=False)
uv = mesh.visual.uv
im = Image.open("image.png")
material = trimesh.visual.texture.SimpleMaterial(image=im)
color_visuals = trimesh.visual.TextureVisuals(uv=uv, image=im, material=material)
mesh.visual = color_visuals
mesh.export(file_obj='model.glb')
Hey! Nice solution, how did you manage to manually calculate your UV coords though?
Hey! Nice solution, how did you manage to manually calculate your UV coords though?
You can use xatlas-python
Hi,
I have a 3D shape loaded from an .off file, and I have an image load as a PIL image.
I want to add this image as a texture to the mesh but I can't figure out how to do it. I did the following manipulation, but when I show the mesh, the texture is not applied.
How can I do this? Thank you in advance.