Пример #1
0
def get_shells(components=None):
    """
    Collect selected uv shells.
    """
    s = components or mampy.selected()
    if not s:
        h = mampy.ls(hl=True)
        if not h:
            return logger.warn('Nothing selected.')
        s.extend(h)

    shells = SelectionList()
    for c in s.itercomps():
        if not c:
            c = MeshMap(c.dagpath).get_complete()
        else:
            c = c.to_map()

        count, array = c.mesh.getUvShellsIds()
        if c.is_complete():
            wanted = set(xrange(count))
        else:
            wanted = set([array[idx] for idx in c.indices])

        for each in wanted:
            shell = MeshMap.create(c.dagpath)
            shell.add([idx for idx, num in enumerate(array) if num == each])
            shells.append(shell)
    return list(shells.itercomps())
Пример #2
0
    def __init__(self, mode, context=False, add=False):
        super(coplanar, self).__init__(self.CONTEXT_NAME)

        self.add = add
        self.mode = mode
        self.default = self.threshold
        self.value = self.threshold

        # properties
        self._slist = None
        self._normal = None
        self._label = None
        self._mesh_vectors = None
        self._comp_indices = None

        if add:
            self.old_selection = mampy.selected()

        if mode == self.HILITED:
            self._setup_hilited()
        elif mode == self.OBJECT or mode == self.CONTIGUOUS:
            self._setup_contiguous_object()

        if context:
            self.run()
        else:
            self.tear_down()
Пример #3
0
 def slist(self):
     if self._slist is None:
         if self.add:
             self._slist = mampy.ordered_selection(-1)
         else:
             self._slist = mampy.selected()
         if not self._slist:
             raise TypeError('Invalid selection, select mesh face.')
     return self._slist
Пример #4
0
def tear_off():
    """
    Creates a new uv shell from selected faces.
    """
    s = mampy.selected()

    for comp in s.itercomps():
        if not comp.is_face():
            continue

        edges = comp.to_edge(border=True)
        cmds.polyMapCut(list(edges))
    cmds.select(list(s))
Пример #5
0
def scale_mirror():
    piv = ScaleManip()

    sel = mampy.selected()[0]
    if isinstance(sel, Component):
        scalar = [1, 1, 1]
    else:
        scalar = cmds.xform(str(sel), q=True, r=True, scale=True)

    try:
        value = scalar[piv.active_axis]
        scalar[piv.active_axis] = value * -1
    except IndexError:
        return
    cmds.scale(*scalar, pivot=piv.position)
Пример #6
0
def set_density(shell=True, target_density=0, texture_size=1024):
    if shell:
        areas = [UV3DArea(c) for c in get_shells()]
    else:
        selected = mampy.selected()
        components = SelectionList()
        components.extend([c.get_complete() for c in selected.itercomps()])
        areas = [UV3DArea(c) for c in get_shells(components)]

    if target_density == 0:
        target_density = get_average_density(areas, texture_size)

    print areas
    for area in areas:
        scale_value = (area.ratio * texture_size) / target_density
        print scale_value

        uvs = area.comp.to_map()
        print uvs
        point = uvs.bounding_box.center
        uvs.translate(su=scale_value, sv=scale_value, pu=point.u, pv=point.v)
Пример #7
0
def get_object_vector():
    selected = mampy.selected().iterdags().next()
    transform = selected.get_transform()
    rotation = transform._mfntrans.rotation()
    return rotation.asMatrix()
Пример #8
0
def get_areas():
    s = mampy.selected()
    if not s:
        logger.warn('Nothing selected.')

    return [UV3DArea(c) for c in s.itercomps()]