如何将plydata对象转换为trimesh对象而不保存为.ply?

问题描述

我有一个 plydata 对象 plydata_resize,它是原始 .ply 文件的调整大小版本。

我想将 plydata_resize 转换为 myTrimesh,这是一个trimesh 对象。目前,我已将 plydata_resize 保存为临时 .plt 文件 tri_resized.ply,然后将该文件加载为一个trimesh。但我不想使用保存/加载方法,因为会涉及到硬盘,而且速度会很慢(我有数千个 .ply 文件要以这种方式转换,所以我需要一个快速的方法)。

如何跳过将其另存为 .ply 的步骤?

import trimesh
import pyrender
import numpy as np
from plyfile import PlyData,PlyElement

file_path = "C:/Users/H42/Desktop/tri.ply" # the input file
ply_path = "C:/Users/H42/Desktop/tri_resized.ply" # the temporary file

plydata = PlyData.read(file_path)

element_vertices = plydata.elements[0] # 0 for vertices; 1 for faces
element_faces = plydata.elements[1]

vertices_values = np.array([list(vertix_values) for vertix_values in element_vertices.data]) # re-format vertices' coordinates/color as array
XYZ = vertices_values[:,0:3]*0.005 # vertices coordinates resize
RGB = vertices_values[:,3:6] # vertices color

myList = [(np.round(xyz[0],4),np.round(xyz[1],np.round(xyz[2],rgb[0],rgb[1],rgb[2]) for xyz,rgb in zip(XYZ,RGB)]
vertices_xyzrgb = np.array(myList,dtype=[('x','f4'),('y',('z',('red','u1'),('green',('blue','u1')])

element_vertices_resize = PlyElement.describe(vertices_xyzrgb,'vertex')

plydata_resize = PlyData([element_vertices_resize,element_faces],text=True)
plydata_resize.write(ply_path)

myTrimesh = trimesh.load(ply_path)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...