3D物体显示


import numpy as np
import trimesh
from glob import glob
import cv2


# 1. 载入上下两片空心核桃 OBJ
raw_file = r'D:\mydocs\git_src\1_ongoing\walnut3d\app\storage\w3d\17774392395110\raw_mesh\raw.obj'

merged = trimesh.load(raw_file)

# 获取中心
center = merged.centroid
print(f'center = {center}')
sphere = trimesh.creation.icosphere(
    radius=0.01,
    center=center
)
sphere.visual.color = [255, 0, 0, 255]

# sphere = trimesh.primitives.Sphere(radius=0.5)
# sphere_wireframe = sphere.outline
# sphere_wireframe.colors = np.array([[255, 0, 0, 255]] * len(sphere_wireframe.entities))
# sphere_wireframe.transform = trimesh.transformations.translation_matrix(center)



aabb = merged.bounds
aabb_box = trimesh.primitives.Box(
    extents=aabb[1] - aabb[0],
    transform=trimesh.transformations.translation_matrix((aabb[0] + aabb[1]) / 2)
)
aabb_box_wireframe = aabb_box.as_outline()



obb_box = merged.bounding_box_oriented
print(f'aabb = {aabb}')
print(f'obb = {obb_box.bounds}')
obb_box_wireframe = obb_box.as_outline()
obb_box_wireframe.colors = np.array(
    [[255, 0, 0, 255]] * len(obb_box_wireframe.entities)
)

# 设置颜色为红色
aabb_box_wireframe.colors = np.array([[255, 0, 0]] * len(aabb_box_wireframe.entities))
final_scene = trimesh.Scene([ obb_box_wireframe, aabb_box_wireframe, sphere ])
final_scene.show()



   

mask_faces = np.ones(len(merged.faces), dtype=bool)  # 先默认所有面都保留
for vid in useless_vertices:
    # 找到任何使用了 vid 的 face
    face_has_vertex = np.any(merged.faces == vid, axis=1)
    mask_faces &= ~face_has_vertex  # 这些面 = 不要
mesh_faces_cleaned = merged.faces[mask_faces]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值