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]
3D物体显示
于 2026-04-29 16:09:17 首次发布

4518

被折叠的 条评论
为什么被折叠?



