-
|
Hi! I'm trying to write a converter that turns Here is a simple example to illustrate the issue. We'll be using the This is what it ought to look like: This is what the trimesh material looks like: >>> import trimesh as tm
>>> mesh = tm.load('/Users/philipps/Downloads/fuze.obj')
>>> mesh
<trimesh.Trimesh(vertices.shape=(664, 3), faces.shape=(1000, 3), name=`fuze.obj`)>
>>> # The image
>>> mesh.visual.material.image
>>> # Which we can turn into a np array
>>> im = np.asarray(mesh.visual.material.image).astype(np.float32)
>>> im /= 255
>>> im.shape
(1024, 1024, 3)
>>> # The UV coordinates are here
>>> texcoords = mesh.visual.uv.astype(np.float32)
>>> texcoords.shape
(664, 2)Here is how I tried to convert: >>> import pygfx as gfx
>>> geometry = gfx.Geometry(
... indices=mesh.faces.astype(np.int32, copy=False),
... positions=mesh.vertices.astype(np.float32, copy=False)
... )
>>> tex = gfx.Texture(im, dim=2)
>>> material = gfx.MeshPhongMaterial(map=tex)
>>> vis = gfx.Mesh(geometry, material)
>>> vis.geometry.texcoords = gfx.Buffer(texcoords)Here is the result: As you can see it did something but it seems the UV coordinates are off. I tried flipping the axis in the image but that didn't do it either. It's probably an easy fix but as I said, I'm a bit stuck with this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
There are some utilities to convert from trimesh to pygfx, please review the following functions to see if you can learn what you need there: There is indeed a conversion step required in UV coordinates which you can see in |
Beta Was this translation helpful? Give feedback.
There are some utilities to convert from trimesh to pygfx, please review the following functions to see if you can learn what you need there:
There is indeed a conversion step required in UV coordinates which you can see in
geometry_from_trimeshas referenced above.