-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjSlicer.py
31 lines (24 loc) · 861 Bytes
/
objSlicer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
from mpl_toolkits import mplot3d
import ply
import meshcut
import numpy as np
import matplotlib.pyplot as plt
import itertools
import openmesh as om
from obj2verts import *
class ObjSlicer:
def singleSlice(self, objFile, plane_norm, planeOrig='firstVert'):
o2v = Obj2MeshVerts()
geometry = o2v.readFile(objFile)
verts = geometry.v
faces = geometry.f
mesh = meshcut.TriangleMesh(verts, faces)
if planeOrig == 'firstVert':
# Plane orig 0 means the orgin of the cutting plane is the first vertex
firstVert = verts[0]
# Place plane origin at the firt vertex
plane_orig = (firstVert[0], firstVert[1], firstVert[2])
# plane_norm = (0, 0, 1)
plane = meshcut.Plane(plane_orig, plane_norm)
return meshcut.cross_section_mesh(mesh, plane)