Beispiel #1
0
def adjacent_faces(mesh_id):
    """Constructs a set of adjacent faces for each vertex.
    Returns a list of form
        [
          [0]: [face_index_1, face_index_2, ...]
          [1]: [face_index_1, ...]
               ...
        ]
    """
    vertices = rs.MeshVertices(mesh_id)
    face_vertices = rs.MeshFaceVertices(mesh_id)
    adjacency_list = [[] for _ in xrange(len(vertices))]
    face_planes = [
        rs.PlaneFitFromPoints(mu.get_face_points(mesh_id, face))
        for face in xrange(len(face_vertices))
    ]
    for next_face in xrange(len(face_vertices)):
        for vertex_index in face_vertices[next_face]:
            for face in adjacency_list[vertex_index]:
                # NOTE(mikhaildubov): we have to check the face planes as well because
                #                     of the way Rhinoceros works.
                if (face == next_face or rs.PlanePlaneIntersection(
                        face_planes[face], face_planes[next_face]) is None):
                    break
            else:
                adjacency_list[vertex_index].append(next_face)
    return adjacency_list
def getSolarGeom(boundary,ht,lat,shourlst,ehourlst,day,north,long,timeZ,s_mth,e_mth):
    CH = ConvexHull2d()
    boundary_pts = rs.CurvePoints(boundary) # you'll need this later
    boundary_pts.pop(-1)
    bchullpts = CH.convex_hull(boundary_pts)
    centerPt = rs.CurveAreaCentroid(rs.AddCurve(bchullpts + [bchullpts[0]],1))[0]
    #centerPt = rs.CurveAreaCentroid(boundary)[0]
    boundary_plane = rs.PlaneFitFromPoints(boundary_pts)
    top_plane = get_plane(boundary,ht)

    # project curve to user_defined height
    sun_pts = get_sunpt(lat,centerPt,s_mth,day,shourlst,north_=north,lon=long,tZ=timeZ,scale_=100)
    sun_pts.extend(get_sunpt(lat,centerPt,e_mth,day,ehourlst,north_=north,lon=long,tZ=timeZ,scale_=100))

    top_lst = project_curve(sun_pts,centerPt,top_plane,boundary)
    top_curves = map(lambda x: rs.coercecurve(x),top_lst) # temp for viz
    top_lst = map(lambda x: rs.CurvePoints(x),top_lst)
    top_pts = map(lambda x: rs.coerce3dpoint(x),\
        reduce(lambda i,j:i+j,top_lst))

    # convex hull methods
    chull_pts = CH.convex_hull(top_pts)
    chull_crv = rs.AddCurve(chull_pts + [chull_pts[0]],1)
    #chull_centerPt = rs.CurveAreaCentroid(chull_crv)[0]
    # adjust curve directions
    #if not rs.CurveDirectionsMatch(boundary,chull_crv):
    #   rs.ReverseCurve(boundary)

    #b = rs.CurvePoints(boundary) + rs.CurvePoints(chull_crv)
    #c = rs.CurvePoints(chull_crv)
    return (boundary,chull_crv),top_curves
def get_face_planes(mesh_id):
    """Returns a list of planes corresponding to the faces of the given mesh.
    The elements of the list are Plane objects and come in the same order as
    the faces returned from rs.MeshFaceVertices().
    """
    f = rs.MeshFaceCount(mesh_id)
    return [
        rs.PlaneFitFromPoints(get_face_points(mesh_id, i)) for i in xrange(f)
    ]
Beispiel #4
0
def color_mesh(mesh,dis_ub,dis_lb):
    
    max_distances = []
    mesh_faces = []
    for fkey in mesh.faces_iter():
                   
        keys = mesh.face_vertices(fkey,ordered=True)
        points = [mesh.vertex_coordinates(key) for key in keys]
        plane = rs.PlaneFitFromPoints(points)
        points_planar = [rs.PlaneClosestPoint(plane, pt) for pt in points] 
        distances = [distance(pt1,pt2) for pt1,pt2 in zip(points,points_planar)]
        max_distances.append(max(distances))
        mesh_faces.append(rs.AddMesh(points,[(0,1,2,3)]))
        
    values = normalize_values(max_distances,dis_ub,dis_lb,1,0)
    
    for i,face in enumerate(mesh_faces):
        rs.ObjectColor(face,i2rgb(values[i]))
    return mesh_faces
def get_plane(b, ht):
    endpt = rs.AddPoint(0, 0, ht)
    startpt = rs.AddPoint(0, 0, 0)
    top_vec = rs.VectorCreate(endpt, startpt)
    top_pts = rs.CurvePoints(rs.CopyObject(b, top_vec))
    return rs.PlaneFitFromPoints(top_pts)