Exemple #1
0
def meshExtrudePolyToByVectPlane(poly, vect, pln):
    extrudeVect = vect

    #find far line from vector to be intersected later
    farvect = rs.VectorScale(extrudeVect, 1000)
    pts = rs.CurveEditPoints(poly)

    meshes = []
    for i in range(0, len(pts) - 1):
        p1 = pts[i]
        p2 = pts[i + 1]

        line = [p1, p1 + farvect]
        p1pj = rs.LinePlaneIntersection(line, pln)
        line = [p2, p2 + farvect]
        p2pj = rs.LinePlaneIntersection(line, pln)
        m = addMeshQuad([p1, p1pj, p2pj, p2])
        meshes.append(m)

    pjPolyPts = []
    for p in pts:
        line = [p, p + farvect]
        xp = rs.LinePlaneIntersection(line, pln)
        pjPolyPts.append(xp)

    mesh = rs.JoinMeshes(meshes, True)
    return mesh, pjPolyPts
Exemple #2
0
def meshSwipPolyAlongPoly(profile, rail):
    profile = rs.CopyObject(profile)
    pts = rs.CurveEditPoints(rail)
    baseVect = Rhino.Geometry.Point3d(0, 1, 0)

    meshes = []
    for i in range(0, len(pts) - 2):
        p0 = pts[i]
        p1 = pts[i + 1]
        p2 = pts[i + 2]

        v1 = rs.VectorUnitize(p1 - p0)
        v2 = rs.VectorUnitize(p2 - p1)
        rv1 = rs.VectorUnitize(p0 - p1)
        vect = p1 - p0

        mid = rs.VectorUnitize((rv1 + v2) / 2)
        np = p1 + mid
        up = p1 + Rhino.Geometry.Point3d(0, 0, 1)
        pln = rs.PlaneFromPoints(p1, np, up)

        mesh, pjpts = meshExtrudePolyToByVectPlane(profile, vect, pln)
        meshes.append(mesh)
        rs.DeleteObject(profile)
        profile = rs.AddPolyline(pjpts)

    mesh = rs.JoinMeshes(meshes, True)
    rs.DeleteObject(profile)
    return mesh
def construct_mesh_center(points):

    meshes = []

    ### calc center point
    bbox = rs.BoundingBox(points)
    line = rs.AddLine(bbox[0], bbox[6])
    c = rs.CurveMidPoint(line)

    ### set new point list
    points.append(c)

    ###
    c_index = len(points) - 1
    # print(c_index)

    for j in xrange(len(points) - 1):
        if j < (len(points) - 2):
            vertex_ = [(c_index, int(j), int(j) + 1, int(j) + 1)]
            # print(vertex_)
            m = rs.AddMesh(points, vertex_)
            meshes.append(m)
        else:
            vertex_ = [(c_index, int(j), 0, 0)]
            # print(vertex_)
            m = rs.AddMesh(points, vertex_)
            meshes.append(m)

    mesh_joined = rs.JoinMeshes(meshes)

    return mesh_joined
Exemple #4
0
    def draw_faces(self, keys=None, color=None, join_faces=False):
        """Draw a selection of faces.

        Parameters
        ----------
        fkeys : list
            A list of face keys identifying which faces to draw.
            The default is ``None``, in which case all faces are drawn.
        color : str, tuple, dict
            The color specififcation for the faces.
            Colors should be specified in the form of a string (hex colors) or
            as a tuple of RGB components.
            To apply the same color to all faces, provide a single color
            specification. Individual colors can be assigned using a dictionary
            of key-color pairs. Missing keys will be assigned the default face
            color (``self.defaults['face.color']``).
            The default is ``None``, in which case all faces are assigned the
            default face color.

        Notes
        -----
        The faces are named using the following template:
        ``"{}.face.{}".format(self.datastructure.name, key)``.
        This name is used afterwards to identify faces in the Rhino model.

        """
        keys = keys or list(self.datastructure.faces())

        colordict = color_to_colordict(color,
                                       keys,
                                       default=self.defaults.get('color.face'),
                                       colorformat='rgb',
                                       normalize=False)
        faces = []
        for fkey in keys:
            faces.append({
                'points':
                self.datastructure.face_coordinates(fkey),
                'name':
                self.datastructure.face_name(fkey),
                'color':
                colordict[fkey],
                'layer':
                self.datastructure.face_attribute(fkey, 'layer', None)
            })

        guids = compas_rhino.draw_faces(faces,
                                        layer=self.layer,
                                        clear=False,
                                        redraw=False)
        if not join_faces:
            return guids
        guid = rs.JoinMeshes(guids, delete_input=True)
        rs.ObjectLayer(guid, self.layer)
        rs.ObjectName(guid, '{}.mesh'.format(self.datastructure.name))
        if color:
            rs.ObjectColor(guid, color)
        return guid
def construct_mesh_step(points):

    meshes = []

    ### step
    for i in xrange(1, len(points) - 1):
        vertex_ = [(0, int(i), int(i) + 1, int(i) + 1)]
        m = rs.AddMesh(points, vertex_)
        meshes.append(m)

    mesh_joined = rs.JoinMeshes(meshes)

    return mesh_joined
Exemple #6
0
def draw_mesh_as_faces(mesh,
                       layer=None,
                       clear_layer=False,
                       facecolor=None,
                       redraw=True):

    guids = compas_rhino.get_objects(
        name='{0}.*'.format(mesh.attributes['name']))
    compas_rhino.delete_objects(guids)

    if clear_layer:
        if not layer:
            compas_rhino.clear_current_layer()
        else:
            compas_rhino.clear_layer(layer)

    facecolor = facecolor or {}

    meshes = []

    for fkey in mesh.faces():
        vertices = mesh.face_coordinates(fkey)
        faces = [range(len(vertices))]
        color = facecolor.get(fkey, (255, 255, 255))
        guid = compas_rhino.xdraw_mesh(vertices,
                                       faces,
                                       None,
                                       '{0}.face.{1}'.format(
                                           mesh.attributes['name'], fkey),
                                       layer=layer,
                                       clear=False,
                                       redraw=False)
        compas_rhino.set_mesh_vertex_colors(
            guid, [color for i in range(len(vertices))])
        meshes.append(guid)

    if layer:
        previous = rs.CurrentLayer(layer)

    guid = rs.JoinMeshes(meshes, delete_input=True)

    if layer:
        rs.CurrentLayer(previous)

    rs.ObjectName(guid, '{0}'.format(mesh.attributes['name']))

    rs.EnableRedraw()
    rs.Redraw()
Exemple #7
0
def meshExtrudePtsByVect(pts,vect,colorRow=None):
    extrudeVect=vect
    #rs.AddPoints(pts)
    meshes=[]
    #verts=[]
    #faces=[]
    for i in range(0,len(pts)-1):
        p1=pts[i]
        p2=pts[i+1]
        p1up=p1+extrudeVect
        p2up=p2+extrudeVect
        m=addMeshQuad([p1,p1up,p2up,p2])
        if colorRow is not None:
            # rs.ObjectColor(m,colorRow[i])
            rs.MeshVertexColors(m,[colorRow[i],colorRow[i],colorRow[i],colorRow[i]])
        meshes.append(m)
    mesh=rs.JoinMeshes(meshes,True)
    return mesh
Exemple #8
0
def meshExtrudeCrvToPattern(crv, facadeType, totalHeightVect):
    crv = rs.CopyObject(crv)
    global TYPECOLORS
    totalLength = rs.VectorLength(totalHeightVect)
    restLength = totalLength
    length = facadeType.heights[0]
    counter = 0
    meshes = []

    def genRow(crv, length, facadeType, counter):
        patterIndex = counter % len(facadeType.pattern)
        extrudeVect = Rhino.Geometry.Vector3d(0, 0, length)
        pts = divCrvByLengths(crv, facadeType.widths)
        colorRow = genMeshColorRow(pts, facadeType.pattern[patterIndex],
                                   TYPECOLORS)
        m = meshExtrudePtsByVect(pts, extrudeVect, colorRow)
        return m

    if length > 0:
        while restLength - length > 0:
            m = genRow(crv, length, facadeType, counter)
            meshes.append(m)
            #prepare for next round
            counter += 1
            restLength -= length
            if counter > 20: break
            crv = rs.MoveObject(crv, Rhino.Geometry.Vector3d(0, 0, length))
            length = facadeType.heights[counter % len(facadeType.heights)]
            #print('length:',length)
            #print('rest length:',restLength)
            if length == -1: break

    if restLength > 0:
        finalLength = restLength
        #print('final length:',finalLength)
        m = genRow(crv, finalLength, facadeType, counter)
        meshes.append(m)
    rs.DeleteObject(crv)
    return rs.JoinMeshes(meshes, True)
def divSrfsToMesh(srfs,width=1500,extrudeVect=None):
    meshes=[]
    for s in srfs:
        if not rs.IsSurface(s):continue
        top,bot,verts=getSrfTopBotVertCrvs(s)

        if extrudeVect is None:
            p1=rs.CurveStartPoint(verts[0])
            p2=rs.CurveEndPoint(verts[0])
            if p1[2]>p2[2]: extrudeVect=p1-p2
            else: extrudeVect=p2-p1
        if bot is None:
            continue

        pts=rs.DivideCurve(bot,round(rs.CurveLength(bot)/width))
        meshes.append(meshExtrudePtsByVect(pts,extrudeVect))

        rs.DeleteObjects([top,bot])
        rs.DeleteObjects(verts)


    mesh=rs.JoinMeshes(meshes,True)
    return mesh
Exemple #10
0
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

for l in rs.LayerNames():
    rs.CurrentLayer(l)
    print(l)
    meshes = rs.ObjectsByLayer(l)
    print(meshes)
    meshes = rs.JoinMeshes(meshes, True)
    rs.SplitDisjointMesh(meshes, True)
Exemple #11
0
def mesh_draw_faces(mesh,
                    keys=None,
                    color=None,
                    layer=None,
                    clear_layer=False,
                    clear_faces=False,
                    redraw=True,
                    join_faces=False):
    """Draw a selection of faces of the mesh.

    Parameters
    ----------
    keys : list (None)
        A list of face keys identifying which faces to draw.
        Default is to draw all faces.
    color : str, tuple, dict (None)
        The color specififcation for the faces.
        Colors should be specified in the form of a string (hex colors) or as a tuple of RGB components.
        To apply the same color to all faces, provide a single color specification.
        Individual colors can be assigned using a dictionary of key-color pairs.
        Missing keys will be assigned the default face color (``self.defaults['face.color']``).
        Default is to use the color of the parent layer.
    layer : str (None)
        The layer in which the edges are drawn.
        Default is to draw in the current layer.
    clear_layer : bool (False)
        Clear the drawing layer.
    redraw : bool (True)
        Redraw the view after adding the edges.
    join_faces : bool (False)
        Join the faces into a polymesh object.

    Notes
    -----
    The faces are named using the following template:
    ``"{}.face.{}".format(self.mesh.attributes['name'], key)``.
    This name is used afterwards to identify faces of the mesh in the Rhino model.

    Examples
    --------
    >>>

    """
    artist = MeshArtist(mesh)
    artist.layer = layer

    if clear_layer:
        artist.clear_layer()

    if clear_faces:
        artist.clear_faces()

    guids = artist.draw_faces(color=color)

    if redraw:
        artist.redraw()

    if join_faces:
        guid = rs.JoinMeshes(guids, delete_input=True)
        return guid

    return guids
Exemple #12
0
import rhinoscriptsyntax as rs

if __name__ == '__main__':

    poly_srf = rs.GetObjects("Select Objects", 8 + 16)

    if poly_srf:
        srfs_explo = rs.ExplodePolysurfaces(poly_srf)

    if srfs_explo:
        srfs = srfs_explo
    else:
        srfs = poly_srf

    trg_len_min = 1
    trg_len_max = 2.8
    dummy = rs.GetReal("Maximum distance to surface", 0.05)
    rhino_meshes = []
    for i, srf in enumerate(srfs):
        print("Computing Surface {0} of {1}".format(i + 1, len(srfs) + 1))
        rs.EnableRedraw(False)
        rs.HideObject(srf)
        rhino_meshes.append(
            nurbs_to_mesh_ani(srf, trg_len_min, trg_len_max, vis=1))
        if srfs_explo:
            rs.DeleteObject(srf)

    #rs.ShowObjects(srfs)
    rs.JoinMeshes(rhino_meshes, True)
Exemple #13
0
        pointsToSurface(masterList[i], masterList[x], resultingSurfaces)

for i in range(len(rMasterList)):
    x = i + 1
    if x >= len(rMasterList):
        print "Done Two"
        break
    else:
        pointsToSurface(rMasterList[i], rMasterList[x], rResultingSurfaces)

for i in range(len(sMasterList)):
    x = i + 1
    if x >= len(sMasterList):
        print "Done Three"
        break
    else:
        pointsToSurface(sMasterList[i], sMasterList[x], sResultingSurfaces)

rSurfaces = resultingSurfaces + rResultingSurfaces + sResultingSurfaces

rs.SelectObjects(rSurfaces)
rs.Command("_Mesh")
rs.Command("_Delete")
rs.Command("_SelDup")
rs.Command("_Delete")

rs.EnableRedraw(True)
rMeshes = rs.GetObjects("Select resulting meshes", 32)

finalMesh = rs.JoinMeshes(rMeshes, True)