@@ -288,23 +288,33 @@ def save(self, filename, dtype=np.float32):
288288 if wcolors .max () > 1.0 or wcolors .min () < 0.0 :
289289 raise ValueError ("Invalid values for wedge colors, must be between 0 and 1 (inclusive)" )
290290
291+ # Meshlab expects colors to be uint8 for PLY files
292+ if filename .endswith (".ply" ):
293+ vcolors = (vcolors * 255.0 ).astype (np .uint8 )
294+ fcolors = (fcolors * 255.0 ).astype (np .uint8 )
295+ wcolors = (wcolors * 255.0 ).astype (np .uint8 )
296+ else :
297+ vcolors = vcolors .astype (dtype )
298+ fcolors = fcolors .astype (dtype )
299+ wcolors = wcolors .astype (dtype )
300+
291301 save_mesh_internal (filename ,
292302 np .ascontiguousarray (self .vertex_data .positions .astype (dtype )),
293303 np .ascontiguousarray (self .vertex_data .normals .astype (dtype )),
294304 np .ascontiguousarray (self .vertex_data .texcoords .astype (dtype )),
295- np .ascontiguousarray (( vcolors * 255.0 ). astype ( np . uint8 ) ),
305+ np .ascontiguousarray (vcolors ),
296306 np .ascontiguousarray (self .vertex_data .quality .astype (dtype )),
297307 np .ascontiguousarray (self .vertex_data .radius .astype (dtype )),
298308 np .ascontiguousarray (self .vertex_data .tex_ids .astype (np .int32 )),
299309 np .ascontiguousarray (self .vertex_data .flags .astype (np .int32 )),
300310
301311 np .ascontiguousarray (self .face_data .vertex_ids .astype (np .int32 )),
302312 np .ascontiguousarray (self .face_data .normals .astype (dtype )),
303- np .ascontiguousarray (( fcolors * 255.0 ). astype ( np . uint8 ) ),
313+ np .ascontiguousarray (fcolors ),
304314 np .ascontiguousarray (self .face_data .quality .astype (dtype )),
305315 np .ascontiguousarray (self .face_data .flags .astype (np .int32 )),
306316
307- np .ascontiguousarray (( wcolors * 255.0 ). astype ( np . uint8 ) ),
317+ np .ascontiguousarray (wcolors ),
308318 np .ascontiguousarray (self .face_data .wedge_normals .astype (dtype )),
309319 np .ascontiguousarray (self .face_data .wedge_texcoords .astype (dtype )),
310320 np .ascontiguousarray (self .face_data .wedge_tex_ids .astype (np .int32 )),
0 commit comments