1.其中Meshes 类有自带的计算bounding box的方法,如:
mesh.get_bounding_boxes()
2.Meshes类还有计算offset的方法,如通过通过torch.mean计算出中心坐标center后,需要将mesh移动至原点,通过mesh.offset(center)就可以做到。
output_mesh = mesh.offset_verts(offset)
3.而mesh的缩放,可以通过Meshes类中的scale_verts_()或scale_verts()做到,二者的区别是scale_verts_() return self, 而scale_verts()返回mesh,如scale_verts_()用法如下
output_mesh.scale_verts_(scale)
import torch
import pytorch3d.io as IO
from pytorch3d.structures import Meshes
mesh = IO.load_objs_as_meshes([path], device, load_textures=True)
mesh_verts = mesh.verts_padded()
center = torch.mean(mesh_verts, dim=1, keepdim=True).repeat(1, mesh_verts.shape[1], 1)
offset = -1*center.reshape(-1,3)
boxes = mesh.get_bounding_boxes()
#get_bounding_boxes, [N, 3, 2] return the min and max value [i,j] along the n coordinates axis
distance = torch.abs(boxes[:,:,0] - boxes[:,:,1])
max