def Activated(self): import numpy as np import flatmesh obj = Gui.Selection.getSelection()[0] # obj must be a Mesh (Mesh-Design->Meshes->Create-Mesh) points = np.array([[i.x, i.y, i.z] for i in obj.Mesh.Points]) faces = np.array([list(i) for i in obj.Mesh.Topology[1]]) flattener = flatmesh.FaceUnwrapper(points, faces) flattener.findFlatNodes(5, 0.95) boundaries = flattener.getFlatBoundaryNodes() #print('number of nodes: {}'.format(len(flattener.ze_nodes))) #print('number of faces: {}'.format(len(flattener.tris))) wires = [] for edge in boundaries: pi = Part.makePolygon([App.Vector(*node) for node in edge]) Part.show(Part.Wire(pi))
def Activated(self): import numpy as np import flatmesh face = Gui.Selection.getSelectionEx()[0].SubObjects[0] shape = face.toNurbs() face = shape.Faces[0] nurbs = face.Surface nurbs.setUNotPeriodic() nurbs.setVNotPeriodic() bs = nurbs.toBSpline(1, "C0", "C0", 3, 3, 10) face = bs.toShape() face.tessellate(0.01) flattener = flatmesh.FaceUnwrapper(face) flattener.findFlatNodes(5, 0.99) poles = flattener.interpolateFlatFace(face) num_u_poles = len(bs.getPoles()) num_v_poles = len(bs.getPoles()[0]) i = 0 for u in range(num_u_poles): for v in range(num_v_poles): bs.setPole(u + 1, v + 1, App.Vector(poles[i])) i += 1 Part.show(bs.toShape())
m = t.Mesh uvpts = [p.Vector for p in m.Points] pts = [seval(p.Vector.x, p.Vector.y) for p in m.Points] tris = [x.PointIndices for x in m.Facets] facets = [[pts[i0], pts[i1], pts[i2]] for i0, i1, i2 in tris] uvcentre = sum( (p.Vector for p in m.Points), Vector()) * (1 / m.CountPoints) mesh = createobjectingroup(doc, stg, "Mesh::Feature", "s%s" % t.Name[1:]) mesh.Mesh = Mesh.Mesh(facets) mesh.ViewObject.Lighting = "Two side" mesh.ViewObject.ShapeColor = t.ViewObject.ShapeColor print(mesh.Name, "tris", len(tris), "pts", len(pts), mesh.Mesh) gpts = numpy.array([[p.x, p.y, p.z] for p in pts]) ##################### # This is where the flattener function is called ##################### flattener = flatmesh.FaceUnwrapper(gpts, numpy.array(tris)) flattener.findFlatNodes(10, 0.95) fpts = [Vector(ze[0], ze[1], 0) for ze in flattener.ze_nodes] rfpts = transformalignfpts(uvpts, fpts, t.Name[1:]) rffacets = [[rfpts[i0], rfpts[i1], rfpts[i2]] for i0, i1, i2 in tris] fmesh = createobjectingroup(doc, flg, "Mesh::Feature", "f%s" % t.Name[1:]) fmesh.Mesh = Mesh.Mesh(rffacets) fmesh.ViewObject.Lighting = "Two side" fmesh.ViewObject.ShapeColor = t.ViewObject.ShapeColor