Exemplo n.º 1
0
def draw_px_point(self, context):
    """
    Draws the handle seen when rotating or scaling
    """
    vx = Vector([1, 0])
    try:
        math.degrees(self.vec_act.angle_signed(vx))
        math.degrees(self.vec_act.angle_signed(vx))
    except ValueError:
        return

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 0.5, 0.0, 1.0)

    bgl.glLineStipple(4, 0x5555)
    bgl.glEnable(bgl.GL_LINE_STIPPLE)

    bgl.glPushMatrix()
    bgl.glTranslatef(self.center_area.x, self.center_area.y, 0)
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2f(0, 0)
    bgl.glVertex2f(self.vec_act.x, self.vec_act.y)
    bgl.glEnd()
    bgl.glPopMatrix()

    bgl.glDisable(bgl.GL_LINE_STIPPLE)

    bgl.glLineWidth(3)

    bgl.glPushMatrix()
    bgl.glTranslatef(self.center_area.x + self.vec_act.x,
                     self.center_area.y + self.vec_act.y, 0)

    if self.bl_idname == 'VSE_TRANSFORM_TOOLS_OT_scale':
        bgl.glRotatef(math.degrees(self.vec_act.angle_signed(vx)), 0, 0, 1)
    if self.bl_idname == 'VSE_TRANSFORM_TOOLS_OT_rotate':
        bgl.glRotatef(
            math.degrees(self.vec_act.angle_signed(vx)) + 90, 0, 0, 1)

    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2f(5, 0)
    bgl.glVertex2f(15, 0)
    bgl.glVertex2f(15, 0)
    bgl.glVertex2f(10, -7)
    bgl.glVertex2f(15, 0)
    bgl.glVertex2f(10, 7)

    bgl.glVertex2f(-5, 0)
    bgl.glVertex2f(-15, 0)
    bgl.glVertex2f(-15, 0)
    bgl.glVertex2f(-10, -7)
    bgl.glVertex2f(-15, 0)
    bgl.glVertex2f(-10, 7)
    bgl.glEnd()
    bgl.glPopMatrix()

    bgl.glLineWidth(1)

    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Exemplo n.º 2
0
def drawText(context,
             text,
             location,
             text_scale_value=TEXT_SCALE_VALUE,
             *,
             enable_depth=False,
             constant_scale=False):
    if (enable_depth):
        bgl.glEnable(bgl.GL_DEPTH_TEST)
    v3d = context.space_data
    rv3d = v3d.region_3d
    text_scale = text_scale_value * (
        (max(min(MAX_ZOOM_DISTANCE, rv3d.view_distance), MIN_ZOOM_DISTANCE)) /
        FRIENDLY_ZOOM_DISTANCE)

    font_id = 0

    axis, angle = getScreenLookAxis(context, location)

    bgl.glPushMatrix()
    bgl.glTranslatef(location.x, location.y, location.z)

    bgl.glPushMatrix()
    bgl.glRotatef(angle, axis.x, axis.y, axis.z)

    bgl.glPushMatrix()
    if (not constant_scale):
        bgl.glScalef(text_scale, text_scale, text_scale)
    else:
        bgl.glScalef(text_scale_value, text_scale_value, text_scale_value)

    bgl.glPushMatrix()
    bgl.glRotatef(90.0, 1.0, 0.0, 0.0)

    blf.position(font_id, 0.0, 0.0, 0.0)
    blf.size(font_id, 72, 72)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    blf.draw(0, text)
    #     blf.rotation(0, 1.57);
    bgl.glPopMatrix()

    bgl.glPopMatrix()

    bgl.glPopMatrix()

    bgl.glPopMatrix()

    if (enable_depth):
        bgl.glDisable(bgl.GL_DEPTH_TEST)
Exemplo n.º 3
0
def draw_axes(self, context, angle):
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(2)

    bgl.glPushMatrix()

    transforms = []
    strips = bpy.context.selected_sequences
    for strip in strips:
        if strip.type == 'TRANSFORM':
            transforms.append(strip)

    group_box = get_group_box(transforms)
    min_left, max_right, min_bottom, max_top = group_box
    group_width = max_right - min_left
    group_height = max_top - min_bottom

    group_pos_x = min_left + (group_width / 2)
    group_pos_y = min_bottom + (group_height / 2)

    offset_x, offset_y, fac, preview_zoom = get_preview_offset()

    x = (group_pos_x * fac * preview_zoom) + offset_x
    y = (group_pos_y * fac * preview_zoom) + offset_y

    bgl.glTranslatef(x, y, 0)
    bgl.glRotatef(angle, 0, 0, 1)

    bgl.glBegin(bgl.GL_LINES)
    bgl.glColor4f(1.0, 0.0, 0.0, 0.2 * self.choose_axis + self.axis_x * 0.8)
    bgl.glVertex2f(-10000, 0)
    bgl.glVertex2f(10000, 0)
    bgl.glColor4f(0.0, 1.0, 0.0, 0.2 * self.choose_axis + self.axis_y * 0.8)
    bgl.glVertex2f(0, -10000)
    bgl.glVertex2f(0, 10000)
    bgl.glEnd()

    bgl.glPopMatrix()

    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Exemplo n.º 4
0
    def afficher(self):
        """Affiche l'image"""
        VT = __class__.VT
        gl = __class__.gl
        bgl = __class__.bgl
        math = __class__.math

        if self.ok:

            id = self.VT_img.bindId

            if id:
                bgl.glMatrixMode(bgl.GL_PROJECTION)
                bgl.glLoadIdentity()
                vp = self.viewport
                bgl.glOrtho(vp[0], vp[1], vp[2], vp[3], -1.0, 1.0)

                bgl.glMatrixMode(bgl.GL_MODELVIEW)
                bgl.glLoadIdentity()

                bgl.glEnable(bgl.GL_TEXTURE_2D)
                bgl.glEnable(bgl.GL_BLEND)
                bgl.glBindTexture(bgl.GL_TEXTURE_2D, id)

                bgl.glTranslatef(self.bary[0], self.bary[1], 0)
                bgl.glRotatef(math.degrees(self.angle), 0.0, 0.0, 1.0)
                bgl.glTranslatef(-self.bary[0], -self.bary[1], 0)

                bgl.glBegin(bgl.GL_QUADS)
                col = self.couleur
                for i in range(len(self.texco)):
                    bgl.glColor4f(col[0], col[1], col[2], col[3])
                    bgl.glTexCoord2f(self.texco[i][0], self.texco[i][1])
                    bgl.glVertex2f(self.verco[i][0], self.verco[i][1])
                bgl.glEnd()

                bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)
            else:
                self.ok = False

        return
Exemplo n.º 5
0
def drawHollowCircleBillBoard(context, location, radius, resolution=20):
    fl_resolution = float(resolution)
    #Marker Highlight
    axis, angle = getScreenLookAxis(context, location)
    bgl.glPushMatrix()
    bgl.glTranslatef(location.x, location.y, location.z)
    bgl.glPushMatrix()
    bgl.glRotatef(angle + 90.0, axis.x, axis.y, axis.z)
    bgl.glPushMatrix()
    #     bgl.glBegin(bgl.GL_TRIANGLE_FAN);
    bgl.glLineWidth(5.0)
    bgl.glBegin(bgl.GL_LINE_LOOP)
    x, y = 0.0, 0.0
    for i in range(resolution):
        factor = (float(i) / fl_resolution) * TWOPI
        xpos = x + (radius * math.cos(factor))
        ypos = y + (radius * math.sin(factor))
        bgl.glVertex2f(xpos, ypos)

    bgl.glEnd()
    bgl.glPopMatrix()
    bgl.glPopMatrix()
    bgl.glPopMatrix()
Exemplo n.º 6
0
def drawText(context, text, location):
    v3d = context.space_data;
    rv3d = v3d.region_3d;
    text_scale = TEXT_SCALE_VALUE * ((max(min(MAX_ZOOM_DISTANCE, rv3d.view_distance), MIN_ZOOM_DISTANCE)) / FRIENDLY_ZOOM_DISTANCE);
#     print("RV3D PARAMETERS ::: " , rv3d.view_location, rv3d.view_distance);
#     print('TEXT SCALE USED :::: ', text_scale);
    
    
    font_id = 0;
    
    axis, angle = getScreenLookAxis(context);
    
    bgl.glPushMatrix();
    bgl.glTranslatef(location.x, location.y , location.z);
    
    bgl.glPushMatrix();
    bgl.glRotatef(angle, axis.x, axis.y, axis.z);
    
    bgl.glPushMatrix();
    bgl.glScalef(text_scale,text_scale,text_scale);
    
    bgl.glPushMatrix();
    bgl.glRotatef(90.0, 1.0, 0.0, 0.0);
    
    blf.position(font_id, 0.0, 0.0 , 0.0);
    blf.size(font_id, 72, 72);
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0);
    blf.draw(0, text);
#     blf.rotation(0, 1.57);
    bgl.glPopMatrix();
    
    bgl.glPopMatrix();
    
    bgl.glPopMatrix();
    
    bgl.glPopMatrix();
Exemplo n.º 7
0
def draw_cube(context, r3d):
    
    #direction = r3d.view_rotation * mathutils.Vector((0.0, 0.0, -1.0))
    #position = r3d.view_matrix.inverted().translation
    
    #r3d.view_distance = 1;
    #r3d.view_camera_zoom = 1
    
    rad2deg = 360.0 / (math.pi * 2.0)
    rotation = r3d.view_rotation.to_euler()
    rotation.x = (rotation.x * rad2deg) + 180
    rotation.y = (rotation.y * rad2deg)
    rotation.z = (rotation.z * rad2deg)
    
    #r3d.view_rotation = mathutils.Euler((0.0, 0.0, 0.0), 'XYZ').to_quaternion()
    
    size = 1
    
    centerX = 0
    centerY = 0
    centerZ = 0
    
    #colors
    cTop = mathutils.Color((130.0/255.0, 130.0/255.0, 130.0/255.0))
    cBot = mathutils.Color((100.0/255.0, 100.0/255.0, 100.0/255.0))
    cLine = mathutils.Color((0.0/255.0, 0.0/255.0, 0.0/255.0))
    
    # BEGIN MATRIX
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    #bgl.glTranslated(0.0, 0.0, 0.0)
    bgl.glOrtho(-5, 5, -5, 5, 0.01, 100)
    
    bgl.glRotatef(rotation.x, 1.0, 0.0, 0.0)
    bgl.glRotatef(rotation.y, 0.0, 1.0, 0.0)
    bgl.glRotatef(rotation.z, 0.0, 0.0, 1.0)
    
    # FACES TEXT
    #font_id = 0
    #blf.position(font_id, 0, 0, 1)
    #blf.size(font_id, 10, 72)
    #blf.draw(font_id, "top")
    
    # QUADS
    bgl.glBegin(bgl.GL_QUADS)
    
    # top
    bgl.glColor3f(cTop.r, cTop.g, cTop.b)
    bgl.glVertex3f(centerX - size, centerY - size, centerZ + size)
    bgl.glVertex3f(centerX + size, centerY - size, centerZ + size)
    bgl.glVertex3f(centerX + size, centerY + size, centerZ + size)
    bgl.glVertex3f(centerX - size, centerY + size, centerZ + size)
    
    # bottom
    bgl.glColor3f(cBot.r, cBot.g, cBot.b)
    bgl.glVertex3f(centerX - size, centerY - size, centerZ - size)
    bgl.glVertex3f(centerX + size, centerY - size, centerZ - size)
    bgl.glVertex3f(centerX + size, centerY + size, centerZ - size)
    bgl.glVertex3f(centerX - size, centerY + size, centerZ - size)
    
    # left
    bgl.glColor3f(cBot.r, cBot.g, cBot.b)
    bgl.glVertex3f(centerX - size, centerY - size, centerZ - size)
    bgl.glVertex3f(centerX - size, centerY + size, centerZ - size)
    bgl.glColor3f(cTop.r, cTop.g, cTop.b)
    bgl.glVertex3f(centerX - size, centerY + size, centerZ + size)
    bgl.glVertex3f(centerX - size, centerY - size, centerZ + size)
    
    # right
    bgl.glColor3f(cBot.r, cBot.g, cBot.b)
    bgl.glVertex3f(centerX + size, centerY - size, centerZ - size)
    bgl.glVertex3f(centerX + size, centerY + size, centerZ - size)
    bgl.glColor3f(cTop.r, cTop.g, cTop.b)
    bgl.glVertex3f(centerX + size, centerY + size, centerZ + size)
    bgl.glVertex3f(centerX + size, centerY - size, centerZ + size)
    
    # front
    bgl.glColor3f(cBot.r, cBot.g, cBot.b)
    bgl.glVertex3f(centerX + size, centerY + size, centerZ - size)
    bgl.glVertex3f(centerX - size, centerY + size, centerZ - size)
    bgl.glColor3f(cTop.r, cTop.g, cTop.b)
    bgl.glVertex3f(centerX - size, centerY + size, centerZ + size)
    bgl.glVertex3f(centerX + size, centerY + size, centerZ + size)
    
    # back
    bgl.glColor3f(cBot.r, cBot.g, cBot.b)
    bgl.glVertex3f(centerX + size, centerY - size, centerZ - size)
    bgl.glVertex3f(centerX - size, centerY - size, centerZ - size)
    bgl.glColor3f(cTop.r, cTop.g, cTop.b)
    bgl.glVertex3f(centerX - size, centerY - size, centerZ + size)
    bgl.glVertex3f(centerX + size, centerY - size, centerZ + size)
    
    bgl.glEnd()
    
    # LINES
    bgl.glColor3f(cLine.r, cLine.g, cLine.b)
    bgl.glLineWidth(1)
    size = size * 1.01
    
    # top
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex3f(centerX - size, centerY - size, centerZ + size)
    bgl.glVertex3f(centerX + size, centerY - size, centerZ + size)
    bgl.glVertex3f(centerX + size, centerY + size, centerZ + size)
    bgl.glVertex3f(centerX - size, centerY + size, centerZ + size)
    bgl.glVertex3f(centerX - size, centerY - size, centerZ + size)
    bgl.glEnd()
    
    # bottom
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex3f(centerX - size, centerY - size, centerZ - size)
    bgl.glVertex3f(centerX + size, centerY - size, centerZ - size)
    bgl.glVertex3f(centerX + size, centerY + size, centerZ - size)
    bgl.glVertex3f(centerX - size, centerY + size, centerZ - size)
    bgl.glVertex3f(centerX - size, centerY - size, centerZ - size)
    bgl.glEnd()
    
    # left
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex3f(centerX - size, centerY - size, centerZ - size)
    bgl.glVertex3f(centerX - size, centerY + size, centerZ - size)
    bgl.glVertex3f(centerX - size, centerY + size, centerZ + size)
    bgl.glVertex3f(centerX - size, centerY - size, centerZ + size)
    bgl.glVertex3f(centerX - size, centerY - size, centerZ - size)
    bgl.glEnd()
    
    # right
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex3f(centerX + size, centerY - size, centerZ - size)
    bgl.glVertex3f(centerX + size, centerY + size, centerZ - size)
    bgl.glVertex3f(centerX + size, centerY + size, centerZ + size)
    bgl.glVertex3f(centerX + size, centerY - size, centerZ + size)
    bgl.glVertex3f(centerX + size, centerY - size, centerZ - size)
    bgl.glEnd()
    
    # front
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex3f(centerX + size, centerY + size, centerZ - size)
    bgl.glVertex3f(centerX - size, centerY + size, centerZ - size)
    bgl.glVertex3f(centerX - size, centerY + size, centerZ + size)
    bgl.glVertex3f(centerX + size, centerY + size, centerZ + size)
    bgl.glVertex3f(centerX + size, centerY + size, centerZ - size)
    bgl.glEnd()
    
    # back
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex3f(centerX + size, centerY - size, centerZ - size)
    bgl.glVertex3f(centerX - size, centerY - size, centerZ - size)
    bgl.glVertex3f(centerX - size, centerY - size, centerZ + size)
    bgl.glVertex3f(centerX + size, centerY - size, centerZ + size)
    bgl.glVertex3f(centerX + size, centerY - size, centerZ - size)
    bgl.glEnd()
    
    # END MATRIX
    bgl.glPopMatrix()