@@ -195,7 +195,7 @@ def copy(self):
195195 Copy the mesh.
196196 """
197197 return Mesh (
198- mesh = self ._mesh .copy (include_cache = True ),
198+ mesh = self ._mesh .copy (** ( dict ( include_cache = True ) if isinstance ( self . _mesh , trimesh . Trimesh ) else {}) ),
199199 surface = self ._surface .copy (),
200200 uvs = self ._uvs .copy () if self ._uvs is not None else None ,
201201 metadata = self ._metadata .copy (),
@@ -221,7 +221,7 @@ def from_trimesh(
221221 surface .update_texture ()
222222 else :
223223 surface = surface .copy ()
224- mesh = mesh .copy (include_cache = True )
224+ mesh = mesh .copy (** ( dict ( include_cache = True ) if isinstance ( mesh , trimesh . Trimesh ) else {}) )
225225
226226 try : # always parse uvs because roughness and normal map also need uvs
227227 uvs = mesh .visual .uv .copy ()
@@ -234,9 +234,10 @@ def from_trimesh(
234234 color_factor = None
235235 opacity = 1.0
236236
237- if mesh .visual .defined :
238- if mesh .visual .kind == "texture" :
239- material = mesh .visual .material
237+ visual = mesh .visual
238+ if isinstance (visual , trimesh .visual .texture .TextureVisuals ) and visual .defined :
239+ if visual .kind == "texture" :
240+ material = visual .material
240241
241242 # TODO: Parsing PBR in obj or not
242243 # trimesh from .obj file will never use PBR material, but that from .glb file will
@@ -267,12 +268,15 @@ def from_trimesh(
267268 else :
268269 color_factor = (* color_factor [:3 ], color_factor [3 ] * opacity )
269270 else :
270- gs .raise_exception ()
271-
271+ gs .raise_exception (f"Unsupported Trimesh material type '{ type (material )} '." )
272272 else :
273273 # TODO: support vertex/face colors in luisa
274- color_factor = tuple (np .array (mesh .visual .main_color , dtype = np .float32 ) / 255.0 )
275-
274+ color_factor = tuple (np .array (visual .main_color , dtype = np .float32 ) / 255.0 )
275+ elif isinstance (visual , trimesh .visual .color .VertexColor ) and visual .vertex_colors .size > 0 :
276+ color = np .unique (visual .vertex_colors , axis = 0 )
277+ if len (color ) > 1 :
278+ gs .raise_exception ("Loading point clouds with heterogeneous colors is not supported." )
279+ color_factor = tuple (np .array (color , dtype = np .float32 ) / 255.0 )
276280 else :
277281 # use white color as default
278282 color_factor = (1.0 , 1.0 , 1.0 , 1.0 )
@@ -328,7 +332,7 @@ def from_attrs(cls, verts, faces, normals=None, surface=None, uvs=None, scale=No
328332 def from_morph_surface (cls , morph , surface = None ):
329333 """
330334 Create a genesis.Mesh from morph and surface options.
331- If the morph is a Mesh morph (morphs.Mesh), it could contain multiple submeshes , so we return a list.
335+ If the morph is a Mesh morph (morphs.Mesh), it could contain multiple sub-meshes , so we return a list.
332336 """
333337 if isinstance (morph , gs .options .morphs .Mesh ):
334338 if morph .is_format (gs .options .morphs .MESH_FORMATS ):
@@ -355,9 +359,7 @@ def from_morph_surface(cls, morph, surface=None):
355359 assert all (isinstance (mesh , trimesh .Trimesh ) for mesh in morph .files )
356360 meshes = [mu .trimesh_to_mesh (mesh , morph .scale , surface ) for mesh in morph .files ]
357361 else :
358- gs .raise_exception (
359- f"File type not supported (yet). Submit a feature request if you need this: { morph .file } ."
360- )
362+ gs .raise_exception (f"File type not supported: { morph .file } " )
361363
362364 return meshes
363365
0 commit comments