def assign_pedestal_capital(mesh): for f in mesh.faces: if faceUtils.center(f).z < 80: f.group = "pedestal" elif faceUtils.center(f).z > 280: f.group = "capital" else: f.group = "shaft"
def assign_pedestal_capital(_mesh): for f in _mesh.faces: if faceUtils.center(f).z < 80: f.group = 'pedestal' elif faceUtils.center(f).z > 290: f.group = 'pedestal' else: f.group = 'shaft'
def constructDodecahedron(cx,cy,cz,radius): mesh=_Mesh() phi = (1 + 5**0.5)/2 mesh.vertices = [_Vertex( 1, 1, 1), _Vertex( 1, 1,-1), _Vertex( 1,-1, 1), _Vertex( 1,-1,-1), _Vertex(-1, 1, 1), _Vertex(-1, 1,-1), _Vertex(-1,-1, 1), _Vertex(-1,-1,-1), _Vertex(0,-phi,-1/phi), _Vertex(0,-phi, 1/phi), _Vertex(0, phi,-1/phi), _Vertex(0, phi, 1/phi), _Vertex(-phi,-1/phi,0), _Vertex(-phi, 1/phi,0), _Vertex( phi,-1/phi,0), _Vertex( phi, 1/phi,0), _Vertex(-1/phi,0,-phi), _Vertex( 1/phi,0,-phi), _Vertex(-1/phi,0, phi), _Vertex( 1/phi,0, phi)] for i in range(len(mesh.vertices)): mesh.vertices[i] = _vec.scale(mesh.vertices[i],radius) mesh.vertices[i] = _vec.add(mesh.vertices[i],_Vertex(cx,cy,cz)) indices = [2,9,6,18,19, 4,11,0,19,18, 18,6,12,13,4, 19,0,15,14,2, 4,13,5,10,11, 14,15,1,17,3, 1,15,0,11,10, 3,17,16,7,8, 2,14,3,8,9, 6,9,8,7,12, 1,10,5,16,17, 12,7,16,5,13] faces = [] for i in range(0,len(indices),5): f = _Face([mesh.vertices[indices[i]], mesh.vertices[indices[i + 1]], mesh.vertices[indices[i + 2]], mesh.vertices[indices[i + 3]], mesh.vertices[indices[i + 4]]]) faces.append(f) # make triangles newfaces = [] for f in faces: v = _faceUtils.center(f) mesh.vertices.append(v) for i,cv in enumerate(f.vertices): nv = f.vertices[(i+1)%len(f.vertices)] newfaces.append(_Face([cv,v,nv])) mesh.faces = newfaces return mesh
def subdivide(mesh): for face in mesh.faces: face.vertex=faceUtils.center(face) for edge in mesh.edges: edge.vertex = edge.getCenter() for vertex in mesh.vertices: vertex.vertex = Vertex(vertex.x,vertex.y,vertex.z) return _collectNewFaces(mesh)
def subdivide_translate_facevertices(mesh,values): for face in mesh.faces: face.vertex=faceUtils.center(face) for edge in mesh.edges: edge.vertex = edge.getCenter() for vertex in mesh.vertices: vertex.vertex = Vertex(vertex.x,vertex.y,vertex.z) _translateFaceVertices(mesh,values) return _collectNewFaces(mesh)
def subdivideCatmull(_mesh): for face in _mesh.faces: face.vertex=faceUtils.center(face) for edge in _mesh.edges: if edge.face1==None or edge.face2==None: edge.v1.fix=True edge.v2.fix=True edge.vertex = edge.getCenter() else: vsum=Vertex() nElements=2 vsum=_vec.add(vsum,edge.v1) vsum=_vec.add(vsum,edge.v2) if edge.face1!=None: vsum=_vec.add(vsum,edge.face1.vertex) nElements+=1 if edge.face2!=None: vsum=_vec.add(vsum,edge.face2.vertex) nElements+=1 vsum=_vec.divide(vsum,nElements) edge.vertex=vsum if edge.v1.fix and edge.v2.fix: edge.vertex.fix=True for vertex in _mesh.vertices: if vertex.fix: vertex.vertex=copy.copy(vertex) else: averageFaces=Vertex() averageEdges=Vertex() nEdges=len(vertex.edges) for edge in vertex.edges: face=edge.face1 if edge.v2 is vertex: face=edge.face2 if face!=None: averageFaces=_vec.add(averageFaces,face.vertex) averageEdges=_vec.add(averageEdges,edge.getCenter()) averageEdges=_vec.scale(averageEdges,2.0/nEdges) averageFaces=_vec.scale(averageFaces,1.0/nEdges) v=Vertex(vertex.x,vertex.y,vertex.z) v=_vec.scale(v,nEdges-3) v=_vec.add(v,averageFaces) v=_vec.add(v,averageEdges) v=_vec.scale(v,1.0/nEdges) vertex.vertex=v return _collectNewFaces(_mesh)
def extrudeTapered(face, height=0.0, fraction=0.5,doCap=True): """ Extrudes the face tapered like a window by creating an offset face and quads between every original edge and the corresponding new edge. Arguments: ---------- face : mola.core.Face The face to be extruded height : float The distance of the new face to the original face, default 0 fraction : float The relative offset distance, 0: original vertex, 1: center point default 0.5 (halfway) """ center_vertex = faceUtils.center(face) normal = faceUtils.normal(face) scaled_normal = vec.scale(normal, height) # calculate new vertex positions new_vertices = [] for i in range(len(face.vertices)): n1 = face.vertices[i] betw = vec.subtract(center_vertex, n1) betw = vec.scale(betw, fraction) nn = vec.add(n1, betw) nn = vec.add(nn, scaled_normal) new_vertices.append(nn) new_faces = [] # create the quads along the edges num = len(face.vertices) for i in range(num): n1 = face.vertices[i] n2 = face.vertices[(i + 1) % num] n3 = new_vertices[(i + 1) % num] n4 = new_vertices[i] new_face = Face([n1,n2,n3,n4]) new_faces.append(new_face) # create the closing cap face if doCap: cap_face = Face(new_vertices) new_faces.append(cap_face) for new_face in new_faces: faceUtils.copyProperties(face,new_face) return new_faces
def extrudeToPointCenter(face, height=0.0): """ Extrudes the face to the center point moved by height normal to the face and creating a triangular face from each edge to the point. Arguments: ---------- face : mola.core.Face The face to be extruded height : float The distance of the new point to the face center, default 0 """ normal = faceUtils.normal(face) normal = vec.scale(normal,height) center = faceUtils.center(face) center = vec.add(center,normal) return extrudeToPoint(face,center)
def column_subdivide(_mesh): sdFunction = SinusFunction(sdFreq, sdAmp, sdPhase, sdOffset) newFaces=[] for f in _mesh.faces: if f.group=='shaft': fcs = sd_sided_tapered (f,0.2) for _f in fcs: _f.group='s_level_2' fcs[1].group = 's_level_3' newFaces.extend(fcs) elif f.group=='s_level_2': fcs=sd_sided_tapered (f,0.1) for _f in fcs: _f.group='stop' fcs[1].group='s_level_4' newFaces.extend(fcs) elif f.group=='s_level_3': fcs=subdivision.extrude(f,-10) for _f in fcs: if abs ( faceUtils.vertical_angle(_f)) < PI/2-0.1: _f.group = 'stop' newFaces.append(_f) elif f.group=='s_level_4': # sine based extrusion z = faceUtils.center(f).z pos_z = (z/300.0)*2*math.pi value = sdFunction.getValue(pos_z) fcs=subdivision.extrude(f,value) for _f in fcs: if abs ( faceUtils.vertical_angle(_f)) < PI/2-0.1: _f.group = 's_level_5' newFaces.append(_f) # pedestal_________ elif f.group == 'pedestal': fcs = sd_sided_tapered (f,0.2) for _f in fcs: _f.group='p_level_2' fcs[1].group = 'p_level_3' newFaces.extend(fcs) elif f.group=='p_level_2': fcs=sd_sided_tapered (f,0.1) for _f in fcs: _f.group='stop' fcs[1].group='p_level_4' newFaces.extend(fcs) elif f.group=='p_level_3': fcs=subdivision.extrude(f,-10) for _f in fcs: if abs (faceUtils.vertical_angle(_f)) < PI/2-0.1: _f.group = 'stop' newFaces.append(_f) elif f.group == 'p_level_4': fcs=subdivision.extrude(f,5) for _f in fcs: if abs(faceUtils.vertical_angle(_f))< PI/2-0.1: if fcs.index(_f)==1: _f.group ='stop' else: _f.group = 'p_level_5' newFaces.append(_f) elif f.group == 'p_level_5': # sine based extrusion z = faceUtils.center(f).z pos_z = (z/300.0)*2*math.pi value = sdFunction.getValue(pos_z) fcs = subdivision.extrudeTapered(f,value*3,0.5) for _f in fcs: _f.group='stop' newFaces.extend(fcs) # capital______ elif f.group == 'capital': fcs = sd_sided_tapered (f,0.4) for _f in fcs: _f.group='p_level_2' fcs[1].group = 'p_level_3' newFaces.extend(fcs) else: newFaces.append(f) m=Mesh() m.faces=newFaces return m