Exemplo n.º 1
0
def hsl_color_offset_float(rgb_color,
                           hue_offset=0,
                           saturation_offset=0,
                           lightness_offset=0):
    """
    Offsets color with hue, saturation and lightness (brighten/darken) values
    :param rgb_color: tuple(float, float, float), RGB color in 0.0-1.0 float range
    :param hue_offset: float, hue offset in 0-360 range
    :param saturation_offset: float, saturation offset in 0-255 range
    :param lightness_offset: float, lightness value offset, lighten(0.2) or darken (-0.3) in -1.0 and 1.0 range
    :return: tuple(float, float, float), color in 0-1 range
    """

    if hue_offset:
        hsv = convert_rgb_to_hsv(list(rgb_color))
        new_hue = hsv[0] + hue_offset
        if new_hue > 360.0:
            new_hue -= 360.0
        elif new_hue < 360.0:
            new_hue += 360.0
        hsv = (new_hue, hsv[1], hsv[2])
        rgb_color = convert_hsv_to_rgb(list(hsv))
    if saturation_offset:
        hsv = convert_rgb_to_hsv(rgb_color)
        hsv = (hsv[0], mathlib.clamp(hsv[1] + saturation_offset), hsv[2])
        rgb_color = convert_hsv_to_rgb(list(hsv))
    if lightness_offset:
        rgb_color = (mathlib.clamp(rgb_color[0] + lightness_offset),
                     mathlib.clamp(rgb_color[1] + lightness_offset),
                     mathlib.clamp(rgb_color[2] + lightness_offset))

    return rgb_color
    def _create_follicles(self):
        """
        Internal function that creates the follicles that will drive rig joints setup transforms
        :return:
        """
        u_count = self._num_joints
        v_count = 1

        for i in range(v_count):
            u_pos = (1.0 / u_count) * 0.5
            v_pos = (1.0 / v_count) * 0.5

            for j in range(u_count):
                follicle_name = self._get_name('follicle', id=j, node_type='follicle')
                new_follicle = follicle.create_surface_follicle(
                    self._nurbs_plane, follicle_name, [u_pos, v_pos], hide_follicle=True)
                dcc.set_parent(new_follicle, self._follicles_group)
                self._follicles.append(new_follicle)

                if u_count > 1:
                    u_pos = mathlib.clamp(0, u_pos + (1.0 / u_count), 1.0)
                if v_count > 1:
                    v_pos = mathlib.clamp(0, v_pos + (1.0 / v_count), 1.0)

        # We make sure that follicles are scaled if global group is scaled
        for flc in self._follicles:
            dcc.create_scale_constraint(flc, self._global_move_group)
Exemplo n.º 3
0
    def apply(self, r, g, b):

        from tpDcc.libs.python import mathlib

        rx = r * self.matrix[0][0] + g * self.matrix[0][1] + b * self.matrix[
            0][2]
        gx = r * self.matrix[1][0] + g * self.matrix[1][1] + b * self.matrix[
            1][2]
        bx = r * self.matrix[2][0] + g * self.matrix[2][1] + b * self.matrix[
            2][2]
        return mathlib.clamp(rx, 0, 255), mathlib.clamp(gx, 0,
                                                        255), mathlib.clamp(
                                                            bx, 0, 255)
Exemplo n.º 4
0
def offset_color(color_to_offset, offset=0):
    """
    Returns a color with the offset applied
    :param color_to_offset: tuple(int, int, int), color in for of tuple of 3 digits
    :param offset: int, color offset value
    :return: tuple(int, int, int), offset color
    """

    return tuple([
        mathlib.clamp((color_channel + offset), 0, 255)
        for color_channel in color_to_offset
    ])
Exemplo n.º 5
0
 def update(self, rect, pos):
     if self._enabled:
         if pos.x() < 0:
             self._auto_pan_delta = QVector2D(-self._amount, 0.0)
             self._been_outside = True
             self._amount = mathlib.clamp(abs(pos.x()) * 0.3, 0.0, 25.0)
         if pos.x() > rect.width():
             self._auto_pan_delta = QVector2D(self._amount, 0.0)
             self._been_outside = True
             self._amount = mathlib.clamp(
                 abs(rect.width() - pos.x()) * 0.3, 0.0, 25.0)
         if pos.y() < 0:
             self._auto_pan_delta = QVector2D(0.0, -self._amount)
             self._been_outside = True
             self._amount = mathlib.clamp(abs(pos.y()) * 0.3, 0.0, 25.0)
         if pos.y() > rect.height():
             self._auto_pan_delta = QVector2D(0.0, self._amount)
             self._been_outside = True
             self._amount = mathlib.clamp(
                 abs(rect.height() - pos.y()) * 0.3, 0.0, 25.0)
         if self._been_outside and rect.contains(pos):
             self.reset()
Exemplo n.º 6
0
    def eventFilter(self, obj, event):
        if event.type() == QEvent.MouseMove:
            if self._active_drag:
                modifiers = event.modifiers()
                self._active_drag.setStyleSheet(self._get_style_sheet())
                if not self._initial_pos:
                    self._initial_pos = event.globalPos()
                delta_x = event.globalPos().x() - self._initial_pos.x()
                self._change_direction = mathlib.clamp(delta_x - self._last_delta_x, -1.0, 1.0)
                if self._change_direction != 0:
                    v = self._change_direction * self._active_drag.factor
                    if modifiers == Qt.NoModifier and delta_x % 4 == 0:
                        self.increment.emit(v)
                    if modifiers in [Qt.ShiftModifier, Qt.ControlModifier] and delta_x % 8 == 0:
                        self.increment.emit(v)
                    if modifiers == Qt.ShiftModifier | Qt.ControlModifier and delta_x % 32 == 0:
                        self.increment.emit(v)
                self._last_delta_x = delta_x
        if event.type() == QEvent.MouseButtonRelease:
            self.hide()
            self._last_delta_x = 0
            del(self)

        return False