hub/city_model_structure/plying_with_geometry.py

23 lines
726 B
Python
Raw Normal View History

import trimesh
from helpers.geometry import Geometry as Geo
import stl
import numpy as np
# example triangle
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]]
#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]]
# 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)
normal_plane = [0, 0, 1]
point_plane = [0, 0, 2]
mesh_result = Geo.divide_mesh_by_plane(mesh, normal_plane, point_plane)
for mesh in mesh_result:
print(len(mesh.vertices), len(mesh.faces))