Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving textured GLB file #1296

Open
Tzanker opened this issue Jul 23, 2021 · 4 comments
Open

Saving textured GLB file #1296

Tzanker opened this issue Jul 23, 2021 · 4 comments

Comments

@Tzanker
Copy link

Tzanker commented Jul 23, 2021

Hi,

I am trying to save a textured OBJ file as a GLB. The texturing imports fine, i can see it using mesh.show(), but when i export as a GLB no texture appears on the model. I saw another similar issue that makes it seem as if this has been implemented but it doesnt seem to be working here.

Thanks so much!!

mesh = trimesh.load("models/all/odm_texturing/odm_textured_model_geo.obj")  
mesh.show()  
mesh.export(file_type="glb", file_obj="output/landslide.glb")  

mesh.show():
image
After export:
image

@palferenc
Copy link

Had the same issue.
I think there is a bug in this line, it's indented too deeply. Linking mesh to material should not depend on UV, at least not in the case of PBR material.
Unindented that line and resolved the export problem.

@mikedh
Copy link
Owner

mikedh commented Nov 9, 2023

Hey, is this still happening on the latest versions? This should be unit tested and I just quickly ran

    e = trimesh.load('models/fuze.obj')
    e.export('~/Downloads/textest.glb')

Which loaded fine on https://gltf-viewer.donmccurdy.com/

If it's not working unit testable examples super welcome!

@palferenc
Copy link

Hi,
my use case is that I load STL files, add material and export it as GLB.
Here is runable minimal example (attached the input file):

import trimesh
import trimesh.visual

m = trimesh.load('example.stl')
m.visual = trimesh.visual.TextureVisuals(
                material=trimesh.visual.material.PBRMaterial(
                    baseColorFactor=trimesh.visual.random_color()
                )
            )
m.show()
m.export("example.glb")

The shown object has color, however after exporting the material/color is lost.
I must use PBR material because the software reading my output only handles that.
example.stl.zip

@hambsch
Copy link

hambsch commented Apr 4, 2024

the "fix" is presented here:
#1895

 sphere.visual.material = primary_color_material
 # material will *not* export without uv coordinates to gltf
 # as GLTF requires TEXCOORD_0 be defined if there is a material
 sphere.visual.uv = g.np.zeros((len(sphere.vertices), 2))

maybe it should give some kind of warning on saving a scene as gltf with materials and empty uv. This used to just work before 1895

Had the same issue. I think there is a bug in this line, it's indented too deeply. Linking mesh to material should not depend on UV, at least not in the case of PBR material. Unindented that line and resolved the export problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants