2020-06-04 12:50:10 -04:00
|
|
|
import trimesh
|
2020-06-09 11:34:12 -04:00
|
|
|
from helpers.geometry import Geometry as Geo
|
|
|
|
import stl
|
2020-06-04 12:50:10 -04:00
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
2020-06-09 11:34:12 -04:00
|
|
|
# example triangle
|
2020-06-04 12:50:10 -04:00
|
|
|
vertices = [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]
|
2020-06-09 11:34:12 -04:00
|
|
|
#faces = [[0, 1, 2], [1, 3, 2], [1, 5, 3], [5, 7, 3], [0, 4, 1], [4, 5, 1], [4, 6, 5], [5, 6, 7], [0, 2, 4], [2, 6, 4],
|
|
|
|
# [3, 7, 6], [2, 3, 6]]
|
2020-06-04 12:50:10 -04:00
|
|
|
|
2020-06-09 11:34:12 -04:00
|
|
|
# example rectangle
|
|
|
|
faces = [[0, 1, 3, 2], [1, 5, 7, 3], [0, 4, 5, 1], [4, 6, 7, 5], [0, 2, 6, 4], [3, 7, 6, 2]]
|
|
|
|
mesh = trimesh.Trimesh(vertices=vertices, faces=faces)
|
2020-06-04 12:50:10 -04:00
|
|
|
|
2020-06-09 11:34:12 -04:00
|
|
|
normal_plane = [0, 0, 1]
|
|
|
|
point_plane = [0, 0, 2]
|
2020-06-04 12:50:10 -04:00
|
|
|
|
2020-06-09 11:34:12 -04:00
|
|
|
mesh_result = Geo.divide_mesh_by_plane(mesh, normal_plane, point_plane)
|
2020-06-04 12:50:10 -04:00
|
|
|
|
2020-06-09 11:34:12 -04:00
|
|
|
for mesh in mesh_result:
|
|
|
|
print(len(mesh.vertices), len(mesh.faces))
|