def execute(self, context): for object in context.selected_objects: bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) depsgraph = bpy.context.evaluated_depsgraph_get() object = object.evaluated_get(depsgraph) # Get a BMesh representation bm = bmesh.new() # create an empty BMesh bm.from_mesh(object.data) # fill it in from a Mesh bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.001) bm.verts.ensure_lookup_table() vertices = [] for v in bm.verts: coor = v.co[:] vertex = Vertex.ByCoordinates(coor[0], coor[1], coor[2]) vertices.append(vertex) faces = cppyy.gbl.std.list[Face.Ptr]() for f in bm.faces: vertices_face = [] for v in f.verts: vertex = vertices[v.index] vertices_face.append(vertex) edges = edgesByVertices(vertices_face) face = Face.ByEdges(edges) faces.push_back(face) cc = CellComplex.ByFaces(faces, 0.0001) cc1 = TopologyUtility.Translate(cc, 5, 0, 0) centroid = Topology.Centroid(cc1) cc2 = TopologyUtility.Scale(cc1, centroid, 0.4, 0.4, 1.5) cc3 = TopologyUtility.Translate(cc2, -0.45, -0.45, 0) cc4 = TopologyUtility.Translate(cc2, 0.45, 0.45, 0) cc5 = Topology.Difference(cc1, cc3) cc6 = Topology.Difference(cc5, cc4) md = meshData(cc6) try: mesh = bpy.data.meshes.new(name="TopologicMesh") mesh.from_pydata(md[0], [], md[1]) # useful for development when the mesh may be invalid. #mesh.validate(verbose=True) object_data_add(context, mesh) print("success") except: print("error") return {'FINISHED'}
from topologic import Vertex, Edge, Topology print("START") print("1. Create Vertex (v1) at 0 0 0") v1 = Vertex.ByCoordinates(0,0,0) print("2. Create Vertex (v2) at 20 20 20") v2 = Vertex.ByCoordinates(20,20,20) print("3. Create an Edge (e1) connecting v1 to v2") e1 = Edge.ByStartVertexEndVertex(v1, v2) print("4. Print the coordinates of the start vertext of e1:") sv = e1.StartVertex() print(" "+str([sv.X(), sv.Y(), sv.Z()])) print("5. Print the coordinates of the end vertext of e1:") ev = e1.EndVertex() print(" "+str([ev.X(), ev.Y(), ev.Z()])) print("6. Print the coordinates of the centroid of e1:") cv = Topology.Centroid(e1) print(" "+str([cv.X(), cv.Y(), cv.Z()])) print("DONE")