def draw_callback_px(self, context):
    oblist = [
        ob for ob in bpy.data.objects
        if ((ob.get('flagEX') is not None) or (ob.meshname != ""))
    ]
    for ob in oblist:
        vec = ob["cvec"]
        color = list(
            ((context.user_preferences.themes[0].view_3d.grid) / 4 +
             (context.user_preferences.themes[0].user_interface.axis_z) / 1.5)
        )
        color.append(1.0)

        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glColor4f(color[0], color[1], color[2], color[3])
        bgl.glLineWidth(1)

        bgl.glBegin(bgl.GL_LINES)
        bgl.glVertex3f(*ob.matrix_world.translation)
        bgl.glVertex3f(*vec)
        bgl.glEnd()

        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Example #2
0
def draw_line(self, context, vertexloc, vertexnorm, colour, thick):
    obj = context.active_object
    
    #get obj rotation
    rot = obj.rotation_euler.to_matrix().inverted()
    scale = obj.scale
    vertex = vertexloc * rot
    normal = vertexnorm * rot

    x1 = vertex[0] * scale[0] + obj.location[0]
    y1 = vertex[1] * scale[1] + obj.location[1]
    z1 = vertex[2] * scale[2] + obj.location[2]
    
    x2 = normal[0]*context.scene.tool_settings.normal_size* scale[0] + x1
    y2 = normal[1]*context.scene.tool_settings.normal_size* scale[1] + y1
    z2 = normal[2]*context.scene.tool_settings.normal_size* scale[2] + z1
    
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(thick)
    # set colour
    bgl.glColor4f(*colour)
    
    # draw line
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex3f(x1,y1,z1)
    bgl.glVertex3f(x2,y2,z2)
    bgl.glEnd()
    bgl.glDisable(bgl.GL_BLEND)
Example #3
0
def draw3d_closed_polylines(context, lpoints, color, thickness, LINE_TYPE):
    lpoints = list(lpoints)
    if LINE_TYPE == "GL_LINE_STIPPLE":
        bgl.glLineStipple(4, 0x5555)  #play with this later
        bgl.glEnable(bgl.GL_LINE_STIPPLE)  
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(thickness)
    bgl.glDepthRange(0.0, 0.997)
    bgl.glColor4f(*color)
    for points in lpoints:
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for coord in points:
            bgl.glVertex3f(*coord)
        bgl.glVertex3f(*points[0])
        bgl.glEnd()
    #if settings.symmetry_plane == 'x':
    #    bgl.glColor4f(*color_mirror)
    #    for points in lpoints:
    #        bgl.glBegin(bgl.GL_LINE_STRIP)
    #        for coord in points:
    #            bgl.glVertex3f(-coord.x, coord.y, coord.z)
    #        bgl.glVertex3f(-points[0].x, points[0].y, points[0].z)
    #        bgl.glEnd()
        
    bgl.glLineWidth(1)
    if LINE_TYPE == "GL_LINE_STIPPLE":
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glEnable(bgl.GL_BLEND)  # back to uninterrupted lines  
def draw_line(vertexloc, vertexnorm, scale):
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex3f(vertexloc[0], vertexloc[1], vertexloc[2])
    bgl.glVertex3f(((vertexnorm[0] * scale) + vertexloc[0]),
                   ((vertexnorm[1] * scale) + vertexloc[1]),
                   ((vertexnorm[2] * scale) + vertexloc[2]))
    bgl.glEnd()
Example #5
0
def draw_normal(context, vertexloc, vertexnorm, objscale, is_selected = True):
    # draw normals in object mode
    obj = context.active_object
    color1, thick1 = (0.5, 1.0, 1.0, 1.0), 3

    # input in localspace
    vertexloc = copy.copy(vertexloc)
    vertexloc.resize_4d()
    obmat = obj.matrix_world
    r1 = obmat*vertexloc
    r1.resize_3d()
    del vertexloc
    r2 = obj.rotation_euler.to_matrix() * mathutils.Vector(vertexnorm)
    r2 = r2* objscale
    r2 = r2* context.scene.tool_settings.normal_size + r1

    bgl.glEnable(bgl.GL_BLEND)

    bgl.glLineWidth(thick1)
    # set colour
    bgl.glColor4f(*color1)
    # draw line
    bgl.glBegin(bgl.GL_LINES)

    bgl.glVertex3f(r1.x,r1.y,r1.z)
    bgl.glVertex3f(r2.x,r2.y,r2.z)

    bgl.glEnd()
    bgl.glDisable(bgl.GL_BLEND)
	def draw_callback_postview(self, context):
		bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)    # save OpenGL attributes
		self.draw_postview(context)
		if len(self.selectCntrl):
			cntrlLength = len(self.selectCntrl)
			for x in range(0,cntrlLength):
				# assuming that we have only one control point, so if
				# anything is selected it would be the only point
				p111 = self.selectCntrl[x]
				t111 = p111.to_tuple()
				vrot = context.space_data.region_3d.view_rotation
				dx = (vrot * Vector((1,0,0))).normalized()          # compute right dir relative to view
				dy = (vrot * Vector((0,1,0))).normalized()          # compute up dir relative to view
				px = tuple(p111 + dx*0.5)
				py = tuple(p111 + dy*0.5)

				# highlight the point
				bgl.glColor3f(1,1,0)
				bgl.glBegin(bgl.GL_POINTS)
				bgl.glVertex3f(*t111)
				bgl.glEnd()

				# draw lines to indicate right (red) and up (green)
				bgl.glBegin(bgl.GL_LINES)
				bgl.glColor3f(1,0,0)
				bgl.glVertex3f(*t111)
				bgl.glVertex3f(*px)
				bgl.glColor3f(0,1,0)
				bgl.glVertex3f(*t111)
				bgl.glVertex3f(*py)
				bgl.glEnd()
		bgl.glPopAttrib()                           # restore OpenGL attributes
def display_face(options, pol, data_vector, data_matrix, k, i):

    colo = options['face_colors']
    shade = options['shading']
    forced_tessellation = options['forced_tessellation']

    num_verts = len(pol)
    dvk = data_vector[k]

    if shade:
        vectorlight = options['light_direction']
        face_color = get_color_from_normal(dvk, pol, num_verts, vectorlight, colo)
    else:
        face_color = colo[:]

    glColor3f(*face_color)

    if (num_verts in {3, 4}) or (not forced_tessellation):
        glBegin(GL_POLYGON)
        for point in pol:
            vec = data_matrix[i] * dvk[point]
            glVertex3f(*vec)
        glEnd()

    else:
        ''' ngons, we tessellate '''
        glBegin(GL_TRIANGLES)
        v = [dvk[i] for i in pol]
        for pol in tessellate([v]):
            for point in pol:
                vec = data_matrix[i] * v[point]
                glVertex3f(*vec)
        glEnd()
Example #8
0
def mi_draw_3d_polyline(points, p_size, p_col, x_ray):
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(1)

    if x_ray is True:
        bgl.glDisable(bgl.GL_DEPTH_TEST)

    bgl.glPointSize(p_size)
#    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glColor4f(p_col[0], p_col[1], p_col[2], p_col[3])
 #   bgl.glBegin(bgl.GL_POLYGON)

    for point in points:
        bgl.glVertex3f(point[0], point[1], point[2])

    if x_ray is True:
        bgl.glEnable(bgl.GL_DEPTH_TEST)

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Example #9
0
def draw_line(point0, point1, width):
    bgl.glLineWidth(width)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex3f(point0.x, point0.y, point0.z)
    bgl.glVertex3f(point1.x, point1.y, point1.z)
    bgl.glEnd()
    bgl.glLineWidth(1)
Example #10
0
def screen_v3dBGL(context, args):
    region = context.region
    region3d = context.space_data.region_3d
    
    points = args[0]
    colors = args[1]
    size= 5.0
    
    bgl.glEnable(bgl.GL_POINT_SMOOTH) # for round vertex
    bgl.glPointSize(size)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    
    if colors:
        bgl.glBegin(bgl.GL_POINTS)
        for coord, color in zip(points, colors):
            bgl.glColor4f(*color)    
            bgl.glVertex3f(*coord)
        bgl.glEnd()

    else:
        gl_col = (0.9, 0.9, 0.8, 1.0)
        bgl.glColor4f(*gl_col)    
        bgl.glBegin(bgl.GL_POINTS)
        for coord in points:
            bgl.glVertex3f(*coord)
        bgl.glEnd()        
    
    bgl.glDisable(bgl.GL_POINT_SMOOTH)
    bgl.glDisable(bgl.GL_POINTS)
Example #11
0
def draw_mouse(context, shape, style, alpha):
    # shape and position
    wm = context.window_manager
    size = wm.display_font_size * 3
    offset_x = context.region.width - wm.display_pos_x - (size*0.535)
    offset_y = wm.display_pos_y
    shape_data = get_shape_data(shape)
    bgl.glTranslatef(offset_x, offset_y, 0)
    # color
    r, g, b = wm.display_color
    bgl.glEnable(bgl.GL_BLEND)
    #bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    #bgl.glColor4f(r, g, b, alpha)
    
    # inner shape for filled style
    if style == "filled":
        inner_shape = []
        for i in shape_data:
            inner_shape.append(i[0])
    
    # outer shape
    for i in shape_data:
        shape_segment = i
        shape_segment[0] = [size * k for k in shape_segment[0]]
        shape_segment[1] = [size * k for k in shape_segment[1]]
        shape_segment[2] = [size * k for k in shape_segment[2]]
        shape_segment[3] = [size * k for k in shape_segment[3]]
        
        # create the buffer
        shape_buffer = bgl.Buffer(bgl.GL_FLOAT, [4, 3], shape_segment)
        
        # create the map and draw the triangle fan
        bgl.glMap1f(bgl.GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, shape_buffer)
        bgl.glEnable(bgl.GL_MAP1_VERTEX_3)
        bgl.glColor4f(r, g, b, alpha)
        
        if style == "outline":
            bgl.glBegin(bgl.GL_LINE_STRIP)
        else: # style == "filled"
            bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for j in range(10):
            bgl.glEvalCoord1f(j / 10.0)
        x, y, z = shape_segment[3]
        
        # make sure the last vertex is indeed the last one, to avoid gaps
        bgl.glVertex3f(x, y, z)
        bgl.glEnd()
        bgl.glDisable(bgl.GL_MAP1_VERTEX_3)
    
    # draw interior
    if style == "filled":
        bgl.glColor4f(r, g, b, alpha)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for i in inner_shape:
            j = [size * k for k in i]
            x, y, z = j
            bgl.glVertex3f(x, y, z)
        bgl.glEnd()
    
    bgl.glTranslatef(-offset_x, -offset_y, 0)
 def draw3d_closed_polylines(context, lpoints, color, thickness, LINE_TYPE, mirror):
     #if type(lpoints) is types.GeneratorType:
     #    lpoints = list(lpoints)
     lpoints = [[mirror(pt) for pt in points] for points in lpoints]
     if len(lpoints) == 0: return
     if LINE_TYPE == "GL_LINE_STIPPLE":
         bgl.glLineStipple(4, 0x5555)  #play with this later
         bgl.glEnable(bgl.GL_LINE_STIPPLE)  
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glLineWidth(thickness)
     bgl.glColor4f(*color)
     for points in lpoints:
         set_depthrange(0.0, 0.997, points)
         bgl.glBegin(bgl.GL_LINE_STRIP)
         for coord in chain(points,points[:1]):
             bgl.glVertex3f(*coord)
         bgl.glEnd()
     # if settings.symmetry_plane == 'x':
     #     bgl.glColor4f(*color_mirror)
     #     for points in lpoints:
     #         bgl.glBegin(bgl.GL_LINE_STRIP)
     #         for coord in points:
     #             bgl.glVertex3f(-coord.x, coord.y, coord.z)
     #         bgl.glVertex3f(-points[0].x, points[0].y, points[0].z)
     #         bgl.glEnd()
         
     bgl.glLineWidth(1)
     if LINE_TYPE == "GL_LINE_STIPPLE":
         bgl.glDisable(bgl.GL_LINE_STIPPLE)
         bgl.glEnable(bgl.GL_BLEND)  # back to uninterrupted lines  
Example #13
0
def draw_elipse(cen, r, axis, xy_ratio, mat):

    base_axis = mathutils.Vector((0, 0, 1))
    axis = mathutils.Vector(axis)

    dot = base_axis.dot(axis)
    cross = base_axis.cross(axis)

    rot_mat = mathutils.Matrix.Rotation(math.acos(dot), 4, cross)

    bgl.glBegin(bgl.GL_LINE_STRIP)

    iterations = 32
    for i in range (iterations + 1):
        i = (1 if i == iterations + 1 else i)
        i *= 2 * math.pi / iterations
        co = (math.cos(i) * r, math.sin(i) * r * xy_ratio, 0)
        co = mathutils.Vector(co)

        co = rot_mat * co

        co[0] += cen[0]
        co[1] += cen[1]
        co[2] += cen[2]

        co = mat * co
        bgl.glVertex3f(co[0], co[1], co[2])

    bgl.glEnd()
Example #14
0
 def draw_line(v1, v2):
     if len(v1) == 3:
         bgl.glVertex3f(*v1)
         bgl.glVertex3f(*v2)
     else:
         bgl.glVertex2f(*v1)
         bgl.glVertex2f(*v2)
Example #15
0
def draw_line(v1, v2, width=1, color=(0,1,0)):
    glColor3f(*color)
    glLineWidth(width)
    glBegin(GL_LINE_STRIP)
    glVertex3f(*v1)
    glVertex3f(*v2)
    glEnd()
    glLineWidth(1)
def draw_points_3d(points, color, size, far=0.997):
    bgl.glColor4f(*color)
    bgl.glPointSize(size)
    bgl.glDepthRange(0.0, far)
    bgl.glBegin(bgl.GL_POINTS)
    for coord in points: bgl.glVertex3f(*coord)
    bgl.glEnd()
    bgl.glPointSize(1.0)
Example #17
0
 def draw3d_points(context, points, color, size):
     bgl.glColor4f(*color)
     bgl.glPointSize(size)
     bgl.glDepthRange(0.0, 0.997)
     bgl.glBegin(bgl.GL_POINTS)
     for coord in points: bgl.glVertex3f(*coord)
     bgl.glEnd()
     bgl.glPointSize(1.0)
Example #18
0
    def draw_brush(self, brush, outline_color=(0, 0, 0, 1),
                   outline_thickness=1, interior_color=(0, 0, 0, 0.2)):
        if not self.is_enabled:
            return

        # Treat the brush as a sphere centered at the origin with a pole in the
        # direction of it's normal.  Given this scenario, find a point on the
        # sphere's equator.
        brush_radius = brush.radius
        brush_normal = brush.normal
        if brush.normal.xy != Vector((0, 0)):
            point_on_equator = brush_radius * (
                Vector((brush_normal.y, -brush_normal.x, 0)).normalized()
            )
        else:
            point_on_equator = brush_radius * (
                Vector((brush_normal.z, -brush_normal.y, 0)).normalized()
            )

        # Generate a list of radially symmetrical vertices around the pole.
        segments = 48
        rotation_matrix = Matrix.Rotation(2 * pi / segments, 3, brush_normal)
        vertices = [point_on_equator]
        for side in range(segments - 1):
            vertices.append(rotation_matrix * vertices[-1])

        # Translate the vertices from the world origin to the brush's center.
        brush_center = brush.center
        brush_center_x = brush_center.x
        brush_center_y = brush_center.y
        brush_center_z = brush_center.z
        for vertex in vertices:
            vertex.x += brush_center_x
            vertex.y += brush_center_y
            vertex.z += brush_center_z

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glDepthRange(0, 0.1)

        # Draw the brush's outline.
        if outline_color[3] > 0:
            bgl.glLineWidth(outline_thickness)
            bgl.glColor4f(*outline_color)
            bgl.glBegin(bgl.GL_LINE_LOOP)
            for vertex in vertices:
                bgl.glVertex3f(*vertex)
            bgl.glEnd()

        # Draw the brush's interior.
        if interior_color[3] > 0:
            bgl.glColor4f(*interior_color)
            bgl.glBegin(bgl.GL_POLYGON)
            for vertex in vertices:
                bgl.glVertex3f(*vertex)
            bgl.glEnd()

        self.restore_opengl()
Example #19
0
        def display_laser(self):
            sr = self._ray    # shorcut in expressions
            bgl.glColor3f(sr['color'][0], sr['color'][1], sr['color'][2])
            bgl.glLineWidth(1.0)

            bgl.glBegin(bgl.GL_LINES)
            bgl.glVertex3f(sr['origin'].x, sr['origin'].y, sr['origin'].z)
            bgl.glVertex3f(sr['destin'].x, sr['destin'].y, sr['destin'].z)
            bgl.glEnd()
def draw3d_points(points, color, size, view_loc, view_ortho, zfar=0.997):
    if not points: return
    bgl.glColor4f(*color)
    bgl.glPointSize(size)
    set_depthrange(0.0, zfar, points, view_loc, view_ortho)
    bgl.glBegin(bgl.GL_POINTS)
    for coord in points: bgl.glVertex3f(*coord)
    bgl.glEnd()
    bgl.glPointSize(1.0)
def drawCallback():
    if bpy.context.mode == 'OBJECT':
        if do_draw[0]:
            # from math_viz
            glPointSize(5.0)
            glBegin(GL_POINTS)
            glColor3f(0.0, 1.0, 0.0)
            glVertex3f(*com[0])
            glEnd()
            glPointSize(1.0)
def draw3d_quad(context, points, color):
    if context.space_data.region_3d.view_perspective == 'ORTHO':
        bias = 0.9999
    else:
        bias = 0.999
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(*color)
    bgl.glDepthRange(0.0, bias)
    bgl.glBegin(bgl.GL_QUADS)
    for coord in points: bgl.glVertex3f(*coord)
    bgl.glEnd()
Example #23
0
def draw_limit_strip(points, color, is_border=False):
    alpha = BORDER_ALPHA if is_border else NORMAL_ALPHA
    lwidth = BORDER_WIDTH if is_border else NORMAL_WIDTH
    bgl.glColor4f(color[0], color[1], color[2], alpha)
    bgl.glLineWidth(lwidth)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for point in points:
        bgl.glVertex3f(point.x, point.y, point.z)
    bgl.glEnd()
    bgl.glLineWidth(1)
def draw_vectorfield(self, context):
	bgl.glEnable(bgl.GL_BLEND)
	bgl.glColor3f(0.0,1.0,0.0)
	
	for i in range(len(vf_vdata.particle_velocitieslist)):
		bgl.glBegin(bgl.GL_LINES)
		bgl.glVertex3f(vf_vdata.particle_startlocs[i][0],vf_vdata.particle_startlocs[i][1],vf_vdata.particle_startlocs[i][2])
		bgl.glVertex3f(vf_vdata.particle_velocitieslist[i][0] + vf_vdata.particle_startlocs[i][0],vf_vdata.particle_velocitieslist[i][1] + vf_vdata.particle_startlocs[i][1],vf_vdata.particle_velocitieslist[i][2] + vf_vdata.particle_startlocs[i][2])
		bgl.glEnd()
	
	bgl.glDisable(bgl.GL_BLEND)
 def draw3d_points(context, points, color, size, mirror):
     #if type(points) is types.GeneratorType:
     #    points = list(points)
     points = [mirror(pt) for pt in points]
     if len(points) == 0: return
     bgl.glColor4f(*color)
     bgl.glPointSize(size)
     set_depthrange(0.0, 0.997, points)
     bgl.glBegin(bgl.GL_POINTS)
     for coord in points: bgl.glVertex3f(*coord)
     bgl.glEnd()
     bgl.glPointSize(1.0)
def draw3d_points(context, points, color, size):
    if context.space_data.region_3d.view_perspective == 'ORTHO':
        bias = 0.9997
    else:
        bias = 0.997
    bgl.glColor4f(*color)
    bgl.glPointSize(size)
    bgl.glDepthRange(0.0, bias)
    bgl.glBegin(bgl.GL_POINTS)
    for coord in points: bgl.glVertex3f(*coord)  
    bgl.glEnd()
    bgl.glPointSize(1.0)
Example #27
0
 def draw():
     if not self.edges_: return
     self.drawing.enable_stipple()
     if self.edge_loop:
         bgl.glBegin(bgl.GL_LINE_LOOP)
     else:
         bgl.glBegin(bgl.GL_LINE_STRIP)
     for _,c0,c1 in self.edges_:
         c = c0 + (c1 - c0) * self.percent
         bgl.glVertex3f(*c)
     bgl.glEnd()
     self.drawing.disable_stipple()
Example #28
0
 def draw3d_quad(context, points, color):
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glDepthRange(0.0, 0.999)
     bgl.glBegin(bgl.GL_QUADS)
     bgl.glColor4f(*color)
     for coord in points:
         bgl.glVertex3f(*coord)
     if settings.symmetry_plane == 'x':
         bgl.glColor4f(*color_mirror)
         for coord in points:
             bgl.glVertex3f(-coord.x,coord.y,coord.z)
     bgl.glEnd()
Example #29
0
def draw_callback_area(op, context):
    area = getAreaObject(context)
    if not area:
        # stop drawing
        bpy.types.SpaceView3D.draw_handler_remove(op._handle, "WINDOW")
        op._handle = None
        return
    bgl.glColor4f(0., 0., 1.0, 1.0)
    bgl.glLineWidth(4)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for v in area.data.vertices:
        bgl.glVertex3f(*(area.matrix_world*v.co))
Example #30
0
def draw_shape_z_axis_neg(mat, size):
    """
    Draws negative Z axis for "Locator".
    :param mat:
    :param size:
    :return:
    """
    glLineWidth(2.0)
    glBegin(GL_LINES)
    glColor3f(0.0, 0.0, 0.5)
    glVertex3f(*(mat * Vector((0.0, 0.0, -0.25))))
    glVertex3f(*(mat * Vector((0.0, 0.0, size * -1))))
    glEnd()
    glLineWidth(1.0)
Example #31
0
def draw_poly(points):
    for i in range(len(points)):
        glVertex3f(points[i][0], points[i][1], points[i][2])
    def draw_matrix(mat):
        zero_tx = mat * zero

        glLineWidth(2.0)
        # x
        glColor3f(1.0, 0.2, 0.2)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * x_p))
        glEnd()

        glColor3f(0.6, 0.0, 0.0)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * x_n))
        glEnd()

        # y
        glColor3f(0.2, 1.0, 0.2)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * y_p))
        glEnd()

        glColor3f(0.0, 0.6, 0.0)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * y_n))
        glEnd()

        # z
        glColor3f(0.2, 0.2, 1.0)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * z_p))
        glEnd()

        glColor3f(0.0, 0.0, 0.6)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * z_n))
        glEnd()

        # bounding box vertices
        i = 0
        glColor3f(1.0, 1.0, 1.0)
        series1 = (-0.5, -0.3, -0.1, 0.1, 0.3, 0.5)
        series2 = (-0.5, 0.5)
        z = 0
        for x in series1:
            for y in series2:
                bb[i][:] = x, y, z
                bb[i] = mat * bb[i]
                i += 1
        for y in series1:
            for x in series2:
                bb[i][:] = x, y, z
                bb[i] = mat * bb[i]
                i += 1

        # bounding box drawing
        glLineWidth(1.0)
        glLineStipple(1, 0xAAAA)
        glEnable(GL_LINE_STIPPLE)

        for i in range(0, 24, 2):
            glBegin(GL_LINE_STRIP)
            glVertex3f(*bb[i])
            glVertex3f(*bb[i + 1])
            glEnd()
def draw_line_3d(color, start, end, width=1):
    bgl.glLineWidth(width)
    bgl.glColor4f(*color)
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex3f(*start)
    bgl.glVertex3f(*end)
Example #34
0
    def draw_matrix(mat):
        zero_tx = mat * zero

        glLineWidth(2.0)

        # x
        glColor3f(1.0, 0.2, 0.2)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * x_p))
        glEnd()

        glColor3f(0.6, 0.0, 0.0)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * x_n))
        glEnd()

        # y
        glColor3f(0.2, 1.0, 0.2)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * y_p))
        glEnd()

        glColor3f(0.0, 0.6, 0.0)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * y_n))
        glEnd()

        # z
        glColor3f(0.4, 0.4, 1.0)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * z_p))
        glEnd()

        glColor3f(0.0, 0.0, 0.6)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * z_n))
        glEnd()

        # bounding box
        if bbox_hide:
            return

        i = 0
        glColor3f(1.0, 1.0, 1.0)
        for x in (-bbox_scale, bbox_scale):
            for y in (-bbox_scale, bbox_scale):
                for z in (-bbox_scale, bbox_scale):
                    bb[i][:] = x, y, z
                    bb[i] = mat * bb[i]
                    i += 1

        # strip
        glLineWidth(1.0)
        glLineStipple(1, 0xAAAA)
        glEnable(GL_LINE_STIPPLE)

        glBegin(GL_LINE_STRIP)
        for i in 0, 1, 3, 2, 0, 4, 5, 7, 6, 4:
            glVertex3f(*bb[i])
        glEnd()

        # not done by the strip
        glBegin(GL_LINES)
        glVertex3f(*bb[1])
        glVertex3f(*bb[5])

        glVertex3f(*bb[2])
        glVertex3f(*bb[6])

        glVertex3f(*bb[3])
        glVertex3f(*bb[7])
        glEnd()
        glDisable(GL_LINE_STIPPLE)
Example #35
0
    def draw_callback_3d(self, context):
        domain = context.scene.flip_fluid.get_domain_object()
        if domain is None:
            return
        dprops = context.scene.flip_fluid.get_domain_properties()

        if dprops.debug.grid_display_mode == 'GRID_DISPLAY_PREVIEW':
            resolution = dprops.simulation.preview_resolution
        else:
            resolution = dprops.simulation.resolution

        bbox = AABB.from_blender_object(domain)
        max_dim = max(bbox.xdim, bbox.ydim, bbox.zdim)
        if dprops.simulation.lock_cell_size:
            unlocked_dx = max_dim / resolution
            locked_dx = dprops.simulation.locked_cell_size
            dx = locked_dx
            if abs(locked_dx - unlocked_dx) < 1e-6:
                dx = unlocked_dx
        else:
            dx = max_dim / resolution

        isize = math.ceil(bbox.xdim / dx)
        jsize = math.ceil(bbox.ydim / dx)
        ksize = math.ceil(bbox.zdim / dx)
        if dprops.debug.grid_display_mode == 'GRID_DISPLAY_MESH':
            isize *= (dprops.surface.subdivisions + 1)
            jsize *= (dprops.surface.subdivisions + 1)
            ksize *= (dprops.surface.subdivisions + 1)
            dx /= (dprops.surface.subdivisions + 1)

        disp_scale = dprops.debug.grid_display_scale
        igrid = math.ceil(isize / disp_scale)
        jgrid = math.ceil(jsize / disp_scale)
        kgrid = math.ceil(ksize / disp_scale)
        dxgrid = dx * disp_scale

        if dprops.debug.snap_offsets_to_grid:
            xoffset = math.ceil(dprops.debug.debug_grid_offsets[0] * igrid) * dxgrid
            yoffset = math.ceil(dprops.debug.debug_grid_offsets[1] * jgrid) * dxgrid
            zoffset = math.ceil(dprops.debug.debug_grid_offsets[2] * kgrid) * dxgrid
        else:
            xoffset = dprops.debug.debug_grid_offsets[0] * igrid * dxgrid
            yoffset = dprops.debug.debug_grid_offsets[1] * jgrid * dxgrid
            zoffset = dprops.debug.debug_grid_offsets[2] * kgrid * dxgrid

        x_color = dprops.debug.x_grid_color
        y_color = dprops.debug.y_grid_color
        z_color = dprops.debug.z_grid_color

        bgl.glLineWidth(1)
        bgl.glBegin(bgl.GL_LINES)
        if dprops.debug.enabled_debug_grids[2]:
            bgl.glColor4f(*z_color, 1.0)
            for i in range(igrid + 1):
                bgl.glVertex3f(bbox.x + i * dxgrid, bbox.y, bbox.z + zoffset)
                bgl.glVertex3f(bbox.x + i * dxgrid, bbox.y + jgrid * dxgrid, bbox.z + zoffset)
            for j in range(jgrid + 1):
                bgl.glVertex3f(bbox.x, bbox.y + j * dxgrid, bbox.z + zoffset)
                bgl.glVertex3f(bbox.x + igrid * dxgrid, bbox.y + j * dxgrid, bbox.z + zoffset)

        if dprops.debug.enabled_debug_grids[1]:
            bgl.glColor4f(*y_color, 1.0)
            for i in range(igrid + 1):
                bgl.glVertex3f(bbox.x + i * dxgrid, bbox.y + yoffset, bbox.z)
                bgl.glVertex3f(bbox.x + i * dxgrid, bbox.y + yoffset, bbox.z + kgrid * dxgrid)
            for k in range(kgrid + 1):
                bgl.glVertex3f(bbox.x, bbox.y + yoffset, bbox.z + k * dxgrid)
                bgl.glVertex3f(bbox.x + igrid * dxgrid, bbox.y + yoffset, bbox.z + k * dxgrid)

        if dprops.debug.enabled_debug_grids[0]:
            bgl.glColor4f(*x_color, 1.0)
            for j in range(jgrid + 1):
                bgl.glVertex3f(bbox.x + xoffset, bbox.y + j * dxgrid, bbox.z)
                bgl.glVertex3f(bbox.x + xoffset, bbox.y + j * dxgrid, bbox.z + kgrid * dxgrid)
            for k in range(kgrid + 1):
                bgl.glVertex3f(bbox.x + xoffset, bbox.y, bbox.z + k * dxgrid)
                bgl.glVertex3f(bbox.x + xoffset, bbox.y + jgrid * dxgrid, bbox.z + k * dxgrid)

        bgl.glEnd()
        bgl.glLineWidth(1)
        bgl.glEnable(bgl.GL_DEPTH_TEST)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
 def createLine(self, p0, p1, color=(0, 0, 0)):
     bgl.glColor3f(*color)
     bgl.glBegin(bgl.GL_LINES)
     bgl.glVertex3f(*p0)
     bgl.glVertex3f(*p1)
     bgl.glEnd
Example #37
0
def drawColorSize(coords, color):
    glColor3f(*color[:3])
    for coord in coords:
        glVertex3f(*coord)
Example #38
0
def draw_geometry(n_id, options, data_vector, data_polygons, data_matrix,
                  data_edges):

    show_verts = options['show_verts']
    show_edges = options['show_edges']
    show_faces = options['show_faces']

    vertex_colors = options['vertex_colors']
    edge_colors = options['edge_colors']
    edge_width = options['edge_width']

    tran = options['transparent']
    shade = options['shading']

    verlen = options['verlen']
    max_verts_ = [len(d) for d in data_vector]

    if tran:
        polyholy = GL_POLYGON_STIPPLE
        edgeholy = GL_LINE_STIPPLE
        edgeline = GL_LINE_STRIP
    else:
        polyholy = GL_POLYGON
        edgeholy = GL_LINE
        edgeline = GL_LINES

    def get_max_k(i, verlen):
        k = i
        if i > verlen:
            k = verlen
        return k

    ''' vertices '''

    glEnable(GL_POINT_SIZE)
    glEnable(GL_POINT_SMOOTH)
    glHint(GL_POINT_SMOOTH_HINT, GL_NICEST)
    # glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST)

    vsize = options['vertex_size']

    if show_verts and data_vector:

        glPointSize(vsize)
        glColor3f(*vertex_colors)
        glBegin(GL_POINTS)

        for i, matrix in enumerate(data_matrix):
            k = get_max_k(i, verlen)
            for vert in data_vector[k]:
                vec = data_matrix[i] * vert
                glVertex3f(*vec)

        glEnd()

    glDisable(GL_POINT_SIZE)
    glDisable(GL_POINT_SMOOTH)
    ''' polygons '''

    if data_polygons and data_vector:
        num_datapolygon_lists = len(data_polygons)

        glEnable(polyholy)
        for i, matrix in enumerate(data_matrix):

            k = get_max_k(i, verlen)
            mesh_edges = set()
            if k >= num_datapolygon_lists:
                k = (num_datapolygon_lists - 1)
                #break

            if len(data_vector[k]) < 3:
                print("can't make faces between fewer than 3 vertices")
                continue

            for j, pol in enumerate(data_polygons[k]):

                if max(pol) >= max_verts_[k]:
                    continue

                if show_faces:
                    display_face(options, pol, data_vector, data_matrix, k, i)

                # collect raw edges, sort by index, use set to prevent dupes.
                if show_edges:
                    er = list(pol) + [pol[0]]
                    kb = {
                        tuple(sorted((e, er[i + 1])))
                        for i, e in enumerate(er[:-1])
                    }
                    mesh_edges.update(kb)

            if show_edges and mesh_edges:
                # glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
                glEnable(edgeholy)
                glLineWidth(edge_width)
                glColor3f(*edge_colors)
                glBegin(GL_LINES)
                for edge in mesh_edges:
                    for p in edge:
                        vec = data_matrix[i] * data_vector[k][p]
                        glVertex3f(*vec)

                glEnd()
                glDisable(edgeholy)

        glDisable(polyholy)
    ''' edges '''

    if data_edges and data_vector and show_edges:

        glColor3f(*edge_colors)
        glLineWidth(edge_width)
        # glEnable(GL_LINE_SMOOTH)
        glEnable(edgeholy)
        # glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)

        for i, matrix in enumerate(data_matrix):
            k = get_max_k(i, verlen)

            if k >= len(data_edges):
                continue

            if len(data_vector[k]) < 2:
                print("can't make edges between fewer than 2 vertices")
                continue

            for line in data_edges[k]:

                # i think this catches edges which refer to indices not present in
                # the accompanying vertex list.
                if max(line) >= max_verts_[k]:
                    continue

                glBegin(edgeline)
                for p in line:
                    vec = data_matrix[i] * data_vector[k][p]
                    glVertex3f(*vec)
                glEnd()

        glDisable(edgeholy)
        # glDisable(GL_LINE_SMOOTH)
    ''' matrix '''

    if data_matrix and not data_vector:
        md = MatrixDraw()
        for mat in data_matrix:
            md.draw_matrix(mat)
Example #39
0
 def line3d(self, start, end, width=1.5, color=(1, 0, 0, 1)):
     bgl.glLineWidth(width)
     bgl.glColor4f(*color)
     bgl.glVertex3f(*start)
     bgl.glVertex3f(*end)
Example #40
0
 def line(color, start, end):
     bgl.glColor4f(*color)
     bgl.glBegin(bgl.GL_LINES)
     bgl.glVertex3f(*start)
     bgl.glVertex3f(*end)
     bgl.glEnd()
Example #41
0
def DrawNorth_callback(self, context):

    if not Sun.SP.ShowNorth and North.isActive:
        North.deactivate()
        return

    # ------------------------------------------------------------------
    # Set up the compass needle using the current north offset angle
    # less 90 degrees.  This forces the unit circle to begin at the
    # 12 O'clock instead of 3 O'clock position.
    # ------------------------------------------------------------------
    color = (0.2, 0.6, 1.0, 0.7)
    radius = 100
    angle = -(Sun.NorthOffset - math.pi / 2)
    x = math.cos(angle) * radius
    y = math.sin(angle) * radius

    p1, p2 = (0, 0, 0), (x, y, 0)  # Start & end of needle

    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Thanks to Buerbaum Martin for the following which draws openGL
    # lines.  ( From his script space_view3d_panel_measure.py )
    #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ------------------------------------------------------------------
    # Convert the Perspective Matrix of the current view/region.
    # ------------------------------------------------------------------
    view3d = bpy.context
    region = view3d.region_data
    perspMatrix = region.perspective_matrix
    tempMat = [perspMatrix[j][i] for i in range(4) for j in range(4)]
    perspBuff = bgl.Buffer(bgl.GL_FLOAT, 16, tempMat)

    # ---------------------------------------------------------
    # Store previous OpenGL settings.
    # ---------------------------------------------------------
    MatrixMode_prev = bgl.Buffer(bgl.GL_INT, [1])
    bgl.glGetIntegerv(bgl.GL_MATRIX_MODE, MatrixMode_prev)
    MatrixMode_prev = MatrixMode_prev[0]

    # Store projection matrix
    ProjMatrix_prev = bgl.Buffer(bgl.GL_DOUBLE, [16])
    bgl.glGetFloatv(bgl.GL_PROJECTION_MATRIX, ProjMatrix_prev)

    # Store Line width
    lineWidth_prev = bgl.Buffer(bgl.GL_FLOAT, [1])
    bgl.glGetFloatv(bgl.GL_LINE_WIDTH, lineWidth_prev)
    lineWidth_prev = lineWidth_prev[0]

    # Store GL_BLEND
    blend_prev = bgl.Buffer(bgl.GL_BYTE, [1])
    bgl.glGetFloatv(bgl.GL_BLEND, blend_prev)
    blend_prev = blend_prev[0]

    line_stipple_prev = bgl.Buffer(bgl.GL_BYTE, [1])
    bgl.glGetFloatv(bgl.GL_LINE_STIPPLE, line_stipple_prev)
    line_stipple_prev = line_stipple_prev[0]

    # Store glColor4f
    color_prev = bgl.Buffer(bgl.GL_FLOAT, [4])
    bgl.glGetFloatv(bgl.GL_COLOR, color_prev)

    # ---------------------------------------------------------
    # Prepare for 3D drawing
    # ---------------------------------------------------------
    bgl.glLoadIdentity()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadMatrixf(perspBuff)

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_LINE_STIPPLE)

    # ------------------
    # and draw the line
    # ------------------
    width = 2
    bgl.glLineWidth(width)
    bgl.glColor4f(color[0], color[1], color[2], color[3])
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex3f(p1[0], p1[1], p1[2])
    bgl.glVertex3f(p2[0], p2[1], p2[2])
    bgl.glEnd()

    # ---------------------------------------------------------
    # Restore previous OpenGL settings
    # ---------------------------------------------------------
    bgl.glLoadIdentity()
    bgl.glMatrixMode(MatrixMode_prev)
    bgl.glLoadMatrixf(ProjMatrix_prev)
    bgl.glLineWidth(lineWidth_prev)

    if not blend_prev:
        bgl.glDisable(bgl.GL_BLEND)
    if not line_stipple_prev:
        bgl.glDisable(bgl.GL_LINE_STIPPLE)

    bgl.glColor4f(color_prev[0], color_prev[1], color_prev[2], color_prev[3])
Example #42
0
    def draw_callback_3d(self, context):
        global x_coords
        global y_coords
        global z_coords
        global bounds_coords

        domain = context.scene.flip_fluid.get_domain_object()
        if domain is None:
            return
        dprops = context.scene.flip_fluid.get_domain_properties()

        if vcu.get_object_hide_viewport(domain):
            return

        if not vcu.is_blender_28():
            dlayers = [i for i, v in enumerate(domain.layers) if v]
            slayers = [i for i, v in enumerate(context.scene.layers) if v]
            if not (set(dlayers) & set(slayers)):
                return

        x_color = dprops.debug.x_grid_color
        y_color = dprops.debug.y_grid_color
        z_color = dprops.debug.z_grid_color
        bounds_color = dprops.debug.domain_bounds_color

        # Draw
        display_grid = dprops.debug.display_simulation_grid
        if vcu.is_blender_28():
            if display_grid and dprops.debug.enabled_debug_grids[2]:
                shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
                batch = batch_for_shader(shader, 'LINES', {"pos": z_coords})
                shader.bind()
                shader.uniform_float("color",
                                     (z_color[0], z_color[1], z_color[2], 1.0))
                batch.draw(shader)
            if display_grid and dprops.debug.enabled_debug_grids[1]:
                shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
                batch = batch_for_shader(shader, 'LINES', {"pos": y_coords})
                shader.bind()
                shader.uniform_float("color",
                                     (y_color[0], y_color[1], y_color[2], 1.0))
                batch.draw(shader)
            if display_grid and dprops.debug.enabled_debug_grids[0]:
                shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
                batch = batch_for_shader(shader, 'LINES', {"pos": x_coords})
                shader.bind()
                shader.uniform_float("color",
                                     (x_color[0], x_color[1], x_color[2], 1.0))
                batch.draw(shader)
            if dprops.debug.display_domain_bounds:
                shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
                batch = batch_for_shader(shader, 'LINES',
                                         {"pos": bounds_coords})
                shader.bind()
                shader.uniform_float(
                    "color",
                    (bounds_color[0], bounds_color[1], bounds_color[2], 1.0))
                batch.draw(shader)
        else:
            bgl.glLineWidth(1)
            bgl.glBegin(bgl.GL_LINES)

            if display_grid and dprops.debug.enabled_debug_grids[2]:
                bgl.glColor4f(*z_color, 1.0)
                for c in z_coords:
                    bgl.glVertex3f(*c)
            if display_grid and dprops.debug.enabled_debug_grids[1]:
                bgl.glColor4f(*y_color, 1.0)
                for c in y_coords:
                    bgl.glVertex3f(*c)
            if display_grid and dprops.debug.enabled_debug_grids[0]:
                bgl.glColor4f(*x_color, 1.0)
                for c in x_coords:
                    bgl.glVertex3f(*c)
            if dprops.debug.display_domain_bounds:
                bgl.glColor4f(*(bounds_color), 1.0)
                for c in bounds_coords:
                    bgl.glVertex3f(*c)

            bgl.glEnd()
            bgl.glLineWidth(1)
            bgl.glEnable(bgl.GL_DEPTH_TEST)
            bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    def draw_callback_px(self, context):
        # draw 3d point OpenGL in the 3D View
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_DEPTH_TEST)
        # bgl.glPushMatrix()
        # bgl.glMultMatrixf(self.obj_glmatrix)

##        if DEBUG:
##            mesh_drawing._store_current_shader_state(mesh_drawing.PreviousGLState)
##            self.screen.Draw(self.sctx._texture)
##            mesh_drawing._restore_shader_state(mesh_drawing.PreviousGLState)

        if self.vector_constrain:
            vc = self.vector_constrain
            if hasattr(self, 'preloc') and self.type in {'VERT', 'FACE'}:
                bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
                bgl.glPointSize(5)
                bgl.glBegin(bgl.GL_POINTS)
                bgl.glVertex3f(*self.preloc)
                bgl.glEnd()
            if vc[2] == 'X':
                Color4f = (self.axis_x_color + (1.0,))
            elif vc[2] == 'Y':
                Color4f = (self.axis_y_color + (1.0,))
            elif vc[2] == 'Z':
                Color4f = (self.axis_z_color + (1.0,))
            else:
                Color4f = self.constrain_shift_color
        else:
            if self.type == 'OUT':
                Color4f = self.out_color
            elif self.type == 'FACE':
                Color4f = self.face_color
            elif self.type == 'EDGE':
                Color4f = self.edge_color
            elif self.type == 'VERT':
                Color4f = self.vert_color
            elif self.type == 'CENTER':
                Color4f = self.center_color
            elif self.type == 'PERPENDICULAR':
                Color4f = self.perpendicular_color
            else: # self.type == None
                Color4f = self.out_color

        bgl.glColor4f(*Color4f)
        bgl.glPointSize(10)
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glVertex3f(*self.location)
        bgl.glEnd()

        # draw 3d line OpenGL in the 3D View
        bgl.glEnable(bgl.GL_DEPTH_TEST)
        bgl.glDepthRange(0, 0.9999)
        bgl.glColor4f(1.0, 0.8, 0.0, 1.0)
        bgl.glLineWidth(2)
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for vert_co in self.list_verts_co:
            bgl.glVertex3f(*vert_co)
        bgl.glVertex3f(*self.location)
        bgl.glEnd()

        # restore opengl defaults
        # bgl.glPopMatrix()
        bgl.glDepthRange(0, 1)
        bgl.glPointSize(1)
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Example #44
0
# standart modules
import math

# blender modules
import bgl

# addon modules
from . import settings

axis_draw_functions = {
    'X': (lambda x, y: bgl.glVertex3f(0, -x, -y)),
    'Y': (lambda x, y: bgl.glVertex3f(-y, 0, -x)),
    'Z': (lambda x, y: bgl.glVertex3f(x, y, 0))
}


def matrix_to_buffer(matrix):
    buff = bgl.Buffer(bgl.GL_FLOAT, len(matrix.row) * len(matrix.col))
    for row_index, row in enumerate(matrix.row):
        buff[4 * row_index:4 * row_index + 4] = row
    return buff


def draw_wire_cube(half_size_x, half_size_y, half_size_z):
    # bottom of the box (plane xy)
    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glVertex3f(-half_size_x, -half_size_y, -half_size_z)
    bgl.glVertex3f(+half_size_x, -half_size_y, -half_size_z)
    bgl.glVertex3f(+half_size_x, +half_size_y, -half_size_z)
    bgl.glVertex3f(-half_size_x, +half_size_y, -half_size_z)
    bgl.glEnd()
Example #45
0
def drawCallback():

    if bpy.context.mode == 'EDIT_MESH':

        obj = bpy.context.object

        bl = obj.border_lines
        if obj and obj.type == 'MESH' and obj.data:
            if bl.borderlines_use:
                mesh = obj.data
                matrix_world = obj.matrix_world
                settings = bpy.context.user_preferences.themes[0].view_3d

                transform = settings.transform
                edge_select = settings.edge_select
                wire_edit = settings.wire_edit
                wire = settings.wire
                object_active = settings.object_active

                glLineWidth(bl.borderlines_width)

                draw_with_test = True

                if bm_old[0] is None or not bm_old[0].is_valid:
                    bm = bm_old[0] = bmesh.from_edit_mesh(mesh)

                else:
                    bm = bm_old[0]

                no_depth = not bpy.context.space_data.use_occlude_geometry

                if no_depth:
                    glDisable(GL_DEPTH_TEST)

                    draw_with_test = False

                    if bl.finer_lines_behind_use:
                        glLineWidth(bl.borderlines_width / 4.0)
                        draw_with_test = True

                    glBegin(GL_LINES)

                    if bl.custom_color_use:
                        glColor3f(*bl.custom_color)
                        for edge in bm.edges:
                            if edge.is_valid and edge.is_boundary:
                                coords = [
                                    matrix_world * vert.co
                                    for vert in edge.verts
                                ]
                                for coord in coords:
                                    glVertex3f(*coord)

                    else:
                        active = bm.select_history.active
                        for edge in bm.edges:
                            if edge.is_valid and edge.is_boundary and not edge.hide:
                                coords = [
                                    matrix_world * vert.co
                                    for vert in edge.verts
                                ]

                                if active == edge:
                                    drawColorSize(coords, transform)
                                elif edge.select:
                                    drawColorSize(coords, edge_select)
                                else:
                                    drawColorSize(coords, wire_edit)

                    glEnd()

                    glLineWidth(bl.borderlines_width)

                    glEnable(GL_DEPTH_TEST)

                if draw_with_test:

                    glBegin(GL_LINES)

                    if bl.custom_color_use:
                        glColor3f(*bl.custom_color)
                        for edge in bm.edges:
                            if edge.is_valid and edge.is_boundary:
                                coords = [
                                    matrix_world * vert.co
                                    for vert in edge.verts
                                ]
                                for coord in coords:
                                    glVertex3f(*coord)

                    else:
                        active = bm.select_history.active
                        for edge in bm.edges:
                            if edge.is_valid and edge.is_boundary:
                                coords = [
                                    matrix_world * vert.co
                                    for vert in edge.verts
                                ]

                                if active == edge:
                                    drawColorSize(coords, transform)
                                elif edge.select:
                                    drawColorSize(coords, edge_select)
                                else:
                                    drawColorSize(coords, wire_edit)

                    glEnd()

    elif bpy.context.mode == 'OBJECT':
        for obj in bpy.context.visible_objects:
            if obj and obj.type == 'MESH' and obj.data:
                if (obj.show_wire or bpy.context.space_data.viewport_shade
                        == 'WIREFRAME'):
                    bl = obj.border_lines

                    if bl.borderlines_use:

                        mesh = obj.data
                        matrix_world = obj.matrix_world
                        settings = bpy.context.user_preferences.themes[
                            0].view_3d

                        wire = settings.wire
                        object_selected = settings.object_selected

                        counts = edge_face_count(mesh)

                        glLineWidth(bl.borderlines_width)

                        glBegin(GL_LINES)

                        if bl.custom_color_use:
                            glColor3f(*bl.custom_color)
                        elif obj == bpy.context.active_object and obj.select:
                            glColor3f(*settings.object_active)
                        elif obj.select:
                            glColor3f(*settings.object_selected)
                        else:
                            glColor3f(*settings.wire)

                        for edge, count in zip(mesh.edges, counts):
                            # border edges
                            if count == 1:
                                coords = [
                                    matrix_world * Vector(mesh.vertices[i].co)
                                    for i in edge.key
                                ]
                                for coord in coords:
                                    glVertex3f(*coord)

                        glEnd()

    glLineWidth(1.0)
def draw_grid(self, context, event):
    wm = context.window_manager
    asset_sketcher = wm.asset_sketcher
    region = bpy.context.region
    rv3d = bpy.context.space_data.region_3d

    self.circle_color = [0.102758, 0.643065, 1.000000, 1.000000]
    if event.ctrl and event.type != "MIDDLEMOUSE":
        self.circle_color = [1.000000, 0.202489, 0.401234, 1.000000]

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(self.circle_color[0], self.circle_color[1],
                  self.circle_color[2], self.circle_color[3])

    ### draw brush center point
    bgl.glPointSize(5)
    bgl.glColor4f(self.circle_color[0], self.circle_color[1],
                  self.circle_color[2], .5)
    bgl.glBegin(bgl.GL_POINTS)
    p = bpy_extras.view3d_utils.location_3d_to_region_2d(
        region, rv3d, self.projected_mouse)
    if p != None:
        bgl.glVertex2f(p[0], p[1])
    bgl.glEnd()

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(self.circle_color[0], self.circle_color[1],
                  self.circle_color[2], self.circle_color[3])
    bgl.glLineWidth(2)

    ### Plane XY
    mat = get_grid_mat(self, context)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    ### draw tile grid
    grid_size = 18
    for i in range(grid_size):

        self.circle_color = [0.102758, 0.643065, 1.000000, 1.000000]
        bgl.glColor4f(self.circle_color[0], self.circle_color[1],
                      self.circle_color[2], .4)
        bgl.glLineWidth(1)

        offset = Vector(
            ((grid_size / 2) - .5,
             (grid_size / 2) - .5, 0)) * asset_sketcher.sketch_grid_size

        bgl.glBegin(bgl.GL_LINE_STRIP)
        p = self.projected_mouse + ((Vector(
            (0, i * asset_sketcher.sketch_grid_size, 0)) - offset) * mat)
        p_2d = bpy_extras.view3d_utils.location_3d_to_region_2d(
            region, rv3d, p)
        bgl.glVertex3f(p[0], p[1], p[2])

        p = self.projected_mouse + ((Vector(
            ((grid_size - 1) * asset_sketcher.sketch_grid_size,
             i * asset_sketcher.sketch_grid_size, 0)) - offset) * mat)
        p_2d = bpy_extras.view3d_utils.location_3d_to_region_2d(
            region, rv3d, p)
        bgl.glVertex3f(p[0], p[1], p[2])
        bgl.glEnd()

        bgl.glBegin(bgl.GL_LINE_STRIP)
        p = self.projected_mouse + ((Vector(
            (i * asset_sketcher.sketch_grid_size, 0, 0)) - offset) * mat)
        p_2d = bpy_extras.view3d_utils.location_3d_to_region_2d(
            region, rv3d, p)
        bgl.glVertex3f(p[0], p[1], p[2])

        p = self.projected_mouse + ((Vector(
            (i * asset_sketcher.sketch_grid_size,
             (grid_size - 1) * asset_sketcher.sketch_grid_size, 0)) - offset) *
                                    mat)
        p_2d = bpy_extras.view3d_utils.location_3d_to_region_2d(
            region, rv3d, p)
        bgl.glVertex3f(p[0], p[1], p[2])
        bgl.glEnd()

    restore_opengl_defaults()
Example #47
0
    def draw(context, event, glsettings):
        if context.mode != 'EDIT_MESH':
            return
        ob = context.active_object
        bm = bmesh.from_edit_mesh(ob.data)

        # convex_hull (2D)
        convex_hull_2d_coords = []
        project = bpy_extras.view3d_utils.location_3d_to_region_2d
        mat = ob.matrix_world
        region_coords = []
        for eve in bm.verts:
            v = project(context.region, context.region_data, mat * eve.co)
            region_coords.append(v)
        indices = convex_hull(region_coords)
        indices = convexhull.convex_hull(region_coords)
        for i in indices:
            convex_hull_2d_coords.append(region_coords[i])

        # obb (2D)
        obb_mat_2d, obb_scale_2d = OBB(region_coords)
        obb_mat_2d, obb_scale_2d = convexhull.OBB(region_coords)
        obb_mat_2d = Matrix(obb_mat_2d)
        obb_scale_2d = Vector(obb_scale_2d)

        # draw 3d obb
        cm = glsettings.region_view3d_space()
        cm.__enter__()
        x, y, z = obb_scale / 2
        vecs = [
            obb_mat * Vector(v)
            for v in [(-x, -y,
                       -z), (x, -y, -z), (x, y,
                                          -z), (-x, y,
                                                -z), (-x, -y,
                                                      z), (x, -y,
                                                           z), (x, y,
                                                                z), (-x, y, z)]
        ]

        def draw_line(v1, v2):
            if len(v1) == 3:
                bgl.glVertex3f(*v1)
                bgl.glVertex3f(*v2)
            else:
                bgl.glVertex2f(*v1)
                bgl.glVertex2f(*v2)

        bgl.glLineWidth(2.0)
        # X
        bgl.glColor3f(1.0, 0.0, 0.0)
        bgl.glBegin(bgl.GL_LINES)
        for v in vecs:
            bgl.glVertex3f(*v)
        bgl.glEnd()

        # Y
        bgl.glColor3f(0.0, 1.0, 0.0)
        bgl.glBegin(bgl.GL_LINES)
        draw_line(vecs[1], vecs[2])
        draw_line(vecs[3], vecs[0])
        draw_line(vecs[5], vecs[6])
        draw_line(vecs[7], vecs[4])
        bgl.glEnd()

        # Z
        bgl.glColor3f(0.0, 0.0, 1.0)
        bgl.glBegin(bgl.GL_LINES)
        for i in range(4):
            draw_line(vecs[i], vecs[i + 4])
        bgl.glEnd()

        cm.__exit__(None, None, None)

        # draw 2d
        bgl.glLineWidth(1.0)
        bgl.glColor3f(1.0, 1.0, 1.0)
        bgl.glBegin(bgl.GL_LINE_LOOP)
        for v in convex_hull_2d_coords:
            bgl.glVertex2f(*v)
        bgl.glEnd()

        # draw 2d obb
        bgl.glColor3f(0.0, 1.0, 0.0)
        x, y = obb_scale_2d / 2
        m = Matrix.Identity(4)
        m.col[0][:2] = obb_mat_2d.col[0][:2]
        m.col[1][:2] = obb_mat_2d.col[1][:2]
        m.col[3][:2] = obb_mat_2d.col[2][:2]
        vecs = [(m * Vector(v).to_3d()).to_2d()
                for v in [(-x, -y), (x, -y), (x, y), (-x, y)]]
        # X
        bgl.glColor3f(1.0, 0.0, 0.0)
        bgl.glBegin(bgl.GL_LINES)
        draw_line(vecs[0], vecs[1])
        draw_line(vecs[2], vecs[3])
        bgl.glEnd()
        # Y
        bgl.glColor3f(0.0, 1.0, 0.0)
        bgl.glBegin(bgl.GL_LINES)
        draw_line(vecs[1], vecs[2])
        draw_line(vecs[3], vecs[0])
        bgl.glEnd()
Example #48
0
def draw3d_arrow(context, pfrom, pto, normal, color, thickness, LINE_TYPE):
    pdiff = pto - pfrom
    l = pdiff.length
    hd = l * 0.10
    hw = l * 0.05
    pdir = pdiff / l
    portho = pdir.cross(normal).normalized()
    pto0 = pto - pdir * hd + portho * hw
    pto1 = pto - pdir * hd - portho * hw

    if context.space_data.region_3d.view_perspective == 'ORTHO':
        bias = 0.9997
    else:
        bias = 0.997
    if LINE_TYPE == "GL_LINE_STIPPLE":
        bgl.glLineStipple(4, 0x5555)  #play with this later
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(*color)
    bgl.glLineWidth(thickness)
    bgl.glDepthRange(0.0, bias)
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex3f(*pfrom)
    bgl.glVertex3f(*pto)
    bgl.glVertex3f(*pto0)
    bgl.glVertex3f(*pto)
    bgl.glVertex3f(*pto1)
    bgl.glVertex3f(*pto)
    bgl.glEnd()
    bgl.glLineWidth(1)
    if LINE_TYPE == "GL_LINE_STIPPLE":
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
 def createVert(self, point, color=(1, 0, 0)):
     bgl.glColor3f(*color)
     bgl.glBegin(bgl.GL_POINTS)
     bgl.glVertex3f(*point)
     bgl.glEnd()
Example #50
0
def draw_callback_px(self, context):

    if not context.window_manager.jewelcraft.widget_toggle or context.space_data.show_only_render:
        return

    prefs = context.user_preferences.addons[var.ADDON_ID].preferences
    use_ovrd = prefs.widget_use_overrides
    default_settings = {
        "color": prefs.widget_color,
        "linewidth": prefs.widget_linewidth,
        "distance": prefs.widget_distance,
    }
    obs = context.selected_objects if prefs.widget_selection_only else context.visible_objects
    key = "jewelcraft_widget" if use_ovrd and prefs.widget_overrides_only else "gem"

    bgl.glEnable(bgl.GL_BLEND)

    if prefs.widget_x_ray:
        bgl.glDisable(bgl.GL_DEPTH_TEST)

    for ob in obs:
        if key in ob:
            settings = default_settings.copy()

            if use_ovrd and "jewelcraft_widget" in ob:
                settings.update(ob["jewelcraft_widget"])

            bgl.glLineWidth(settings["linewidth"])
            bgl.glColor4f(*settings["color"])
            radius = max(ob.dimensions[:2]) / 2 + settings["distance"]

            mat_loc = Matrix.Translation(ob.matrix_world.translation)
            mat_rot = ob.matrix_world.to_quaternion().to_matrix().to_4x4()
            mat = mat_loc * mat_rot

            coords = circle_coords(radius)

            bgl.glBegin(bgl.GL_LINE_LOOP)
            for co in coords:
                bgl.glVertex3f(*(mat * co))
            bgl.glEnd()

            # Duplifaces
            # ----------------------------

            if ob.parent and ob.parent.dupli_type == "FACES":

                ob.parent.dupli_list_create(context.scene)

                for dup in ob.parent.dupli_list:
                    if dup.object == ob:
                        mat = dup.matrix
                        bgl.glBegin(bgl.GL_LINE_LOOP)
                        for co in coords:
                            bgl.glVertex3f(*(mat * co))
                        bgl.glEnd()

                ob.parent.dupli_list_clear()

    # Restore OpenGL defaults
    # ----------------------------

    bgl.glLineWidth(1)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_DEPTH_TEST)
Example #51
0
def draw_wire_cube(half_size_x, half_size_y, half_size_z):
    # bottom of the box (plane xy)
    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glVertex3f(-half_size_x, -half_size_y, -half_size_z)
    bgl.glVertex3f(+half_size_x, -half_size_y, -half_size_z)
    bgl.glVertex3f(+half_size_x, +half_size_y, -half_size_z)
    bgl.glVertex3f(-half_size_x, +half_size_y, -half_size_z)
    bgl.glEnd()

    # top of the box (plane xy)
    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glVertex3f(-half_size_x, -half_size_y, +half_size_z)
    bgl.glVertex3f(+half_size_x, -half_size_y, +half_size_z)
    bgl.glVertex3f(+half_size_x, +half_size_y, +half_size_z)
    bgl.glVertex3f(-half_size_x, +half_size_y, +half_size_z)
    bgl.glEnd()

    # vertical lines
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex3f(-half_size_x, -half_size_y, -half_size_z)
    bgl.glVertex3f(-half_size_x, -half_size_y, +half_size_z)
    bgl.glVertex3f(+half_size_x, -half_size_y, -half_size_z)
    bgl.glVertex3f(+half_size_x, -half_size_y, +half_size_z)
    bgl.glVertex3f(+half_size_x, +half_size_y, -half_size_z)
    bgl.glVertex3f(+half_size_x, +half_size_y, +half_size_z)
    bgl.glVertex3f(-half_size_x, +half_size_y, -half_size_z)
    bgl.glVertex3f(-half_size_x, +half_size_y, +half_size_z)
    bgl.glEnd()
Example #52
0
def draw_line(start, end, color):
    bgl.glBegin(bgl.GL_LINES)
    bgl.glColor4f(*color)
    bgl.glVertex3f(*start)
    bgl.glVertex3f(*end)
    bgl.glEnd()
Example #53
0
def draw_callback_view():
    context = bpy.context

    from bgl import (
        glEnable,
        glDisable,
        glColor3f,
        glVertex3f,
        glPointSize,
        glLineWidth,
        glBegin,
        glEnd,
        glLineStipple,
        GL_POINTS,
        GL_LINE_STRIP,
        GL_LINES,
        GL_LINE_STIPPLE
    )

    data_matrix, data_quat, data_euler, data_vector, data_vector_array = utils.console_math_data()

    # draw_matrix modifiers
    bbox_hide = context.window_manager.MathVisProp.bbox_hide
    bbox_scale = context.window_manager.MathVisProp.bbox_scale

    # draw_matrix vars
    zero = Vector((0.0, 0.0, 0.0))
    x_p = Vector((bbox_scale, 0.0, 0.0))
    x_n = Vector((-bbox_scale, 0.0, 0.0))
    y_p = Vector((0.0, bbox_scale, 0.0))
    y_n = Vector((0.0, -bbox_scale, 0.0))
    z_p = Vector((0.0, 0.0, bbox_scale))
    z_n = Vector((0.0, 0.0, -bbox_scale))
    bb = [Vector() for i in range(8)]

    def draw_matrix(mat):
        zero_tx = mat * zero

        glLineWidth(2.0)

        # x
        glColor3f(1.0, 0.2, 0.2)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * x_p))
        glEnd()

        glColor3f(0.6, 0.0, 0.0)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * x_n))
        glEnd()

        # y
        glColor3f(0.2, 1.0, 0.2)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * y_p))
        glEnd()

        glColor3f(0.0, 0.6, 0.0)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * y_n))
        glEnd()

        # z
        glColor3f(0.4, 0.4, 1.0)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * z_p))
        glEnd()

        glColor3f(0.0, 0.0, 0.6)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * z_n))
        glEnd()

        # bounding box
        if bbox_hide:
            return

        i = 0
        glColor3f(1.0, 1.0, 1.0)
        for x in (-bbox_scale, bbox_scale):
            for y in (-bbox_scale, bbox_scale):
                for z in (-bbox_scale, bbox_scale):
                    bb[i][:] = x, y, z
                    bb[i] = mat * bb[i]
                    i += 1

        # strip
        glLineWidth(1.0)
        glLineStipple(1, 0xAAAA)
        glEnable(GL_LINE_STIPPLE)

        glBegin(GL_LINE_STRIP)
        for i in 0, 1, 3, 2, 0, 4, 5, 7, 6, 4:
            glVertex3f(*bb[i])
        glEnd()

        # not done by the strip
        glBegin(GL_LINES)
        glVertex3f(*bb[1])
        glVertex3f(*bb[5])

        glVertex3f(*bb[2])
        glVertex3f(*bb[6])

        glVertex3f(*bb[3])
        glVertex3f(*bb[7])
        glEnd()
        glDisable(GL_LINE_STIPPLE)

    # points
    if data_vector:
        glPointSize(3.0)
        glBegin(GL_POINTS)
        glColor3f(0.5, 0.5, 1)
        for key, vec in data_vector.items():
            glVertex3f(*vec.to_3d())
        glEnd()
        glPointSize(1.0)

    # lines
    if data_vector_array:
        glColor3f(0.5, 0.5, 1)
        glLineWidth(2.0)

        for line in data_vector_array.values():
            glBegin(GL_LINE_STRIP)
            for vec in line:
                glVertex3f(*vec)
            glEnd()
            glPointSize(1.0)

        glLineWidth(1.0)

    # matrix
    if data_matrix:
        for mat in data_matrix.values():
            draw_matrix(mat)

    if data_quat:
        loc = context.scene.cursor_location.copy()
        for quat in data_quat.values():
            mat = quat.to_matrix().to_4x4()
            mat.translation = loc
            draw_matrix(mat)

    if data_euler:
        loc = context.scene.cursor_location.copy()
        for eul in data_euler.values():
            mat = eul.to_matrix().to_4x4()
            mat.translation = loc
            draw_matrix(mat)
Example #54
0
def draw_cross(size):
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex3f(-size, 0, 0)
    bgl.glVertex3f(+size, 0, 0)
    bgl.glVertex3f(0, -size, 0)
    bgl.glVertex3f(0, +size, 0)
    bgl.glVertex3f(0, 0, -size)
    bgl.glVertex3f(0, 0, +size)
    bgl.glEnd()
def draw_callback_view(handle, sl1, sl2, sl3, vs, colo, tran, shade):
    context = bpy.context
    from bgl import glEnable, glDisable, glColor3f, glVertex3f, glPointSize, \
                glLineWidth, glBegin, glEnd, glLineStipple, GL_POINTS, \
                GL_LINE_STRIP, GL_LINES, GL_LINE, GL_LINE_STIPPLE, GL_POLYGON, \
                GL_POLYGON_STIPPLE, GL_POLYGON_SMOOTH, glPolygonStipple, \
                GL_TRIANGLES, GL_QUADS, glColor4f
    # define globals, separate edgs from pols
    if tran:
        polyholy = GL_POLYGON_STIPPLE
        edgeholy = GL_LINE_STIPPLE
        edgeline = GL_LINE_STRIP
    else:
        polyholy = GL_POLYGON
        edgeholy = GL_LINE
        edgeline = GL_LINES

    if sl1:
        data_vector = Vector_generate(sl1)
        verlen = len(data_vector) - 1
        verlen_every = [len(d) - 1 for d in data_vector]
    else:
        data_vector = []
        verlen = 0

    if sl2:
        if sl2[0]:
            if len(sl2[0][0]) == 2:
                data_edges = sl2
                data_polygons = []
            elif len(sl2[0][0]) > 2:
                data_polygons = sl2
                data_edges = []
        else:
            data_polygons = []
            data_edges = []

    else:
        data_edges, data_polygons = [], []

    if sl3:
        data_matrix = Matrix_generate(sl3)
    else:
        data_matrix = [Matrix() for i in range(verlen + 1)]

    coloa = colo[0]
    colob = colo[1]
    coloc = colo[2]

    if (data_vector, data_polygons, data_matrix, data_edges) == (0, 0, 0, 0):
        callback_disable(handle)
    #print ('вход', sl1, sl2, sl3)
    #print ('преобраз', data_vector)

    # draw_matrix vars
    zero = Vector((0.0, 0.0, 0.0))
    x_p = Vector((0.5, 0.0, 0.0))
    x_n = Vector((-0.5, 0.0, 0.0))
    y_p = Vector((0.0, 0.5, 0.0))
    y_n = Vector((0.0, -0.5, 0.0))
    z_p = Vector((0.0, 0.0, 0.5))
    z_n = Vector((0.0, 0.0, -0.5))
    bb = [Vector() for i in range(24)]

    def draw_matrix(mat):
        zero_tx = mat * zero

        glLineWidth(2.0)
        # x
        glColor3f(1.0, 0.2, 0.2)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * x_p))
        glEnd()

        glColor3f(0.6, 0.0, 0.0)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * x_n))
        glEnd()

        # y
        glColor3f(0.2, 1.0, 0.2)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * y_p))
        glEnd()

        glColor3f(0.0, 0.6, 0.0)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * y_n))
        glEnd()

        # z
        glColor3f(0.2, 0.2, 1.0)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * z_p))
        glEnd()

        glColor3f(0.0, 0.0, 0.6)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * z_n))
        glEnd()

        # bounding box vertices
        i = 0
        glColor3f(1.0, 1.0, 1.0)
        series1 = (-0.5, -0.3, -0.1, 0.1, 0.3, 0.5)
        series2 = (-0.5, 0.5)
        z = 0
        for x in series1:
            for y in series2:
                bb[i][:] = x, y, z
                bb[i] = mat * bb[i]
                i += 1
        for y in series1:
            for x in series2:
                bb[i][:] = x, y, z
                bb[i] = mat * bb[i]
                i += 1

        # bounding box drawing
        glLineWidth(1.0)
        glLineStipple(1, 0xAAAA)
        glEnable(GL_LINE_STIPPLE)

        for i in range(0, 24, 2):
            glBegin(GL_LINE_STRIP)
            glVertex3f(*bb[i])
            glVertex3f(*bb[i + 1])
            glEnd()

    # MAYBE WE SHOULD CONNECT ITERATION FOR ALL PROCESS TO DECREASE
    # TIME?
    ########
    # points
    if vs:
        if data_vector:
            glPointSize(3.0)
            glColor3f(0.8, 0.9, 1.0)

            for i, matrix in enumerate(data_matrix):
                glBegin(GL_POINTS)
                k = i
                if i > verlen:
                    k = verlen
                for vert in data_vector[k]:
                    vec_corrected = data_matrix[i] * vert
                    glVertex3f(*vec_corrected)
                    #print ('рисовальня', matrix, vec_corrected)
                glEnd()
                glPointSize(3.0)

    #######
    # lines
    if data_edges and data_vector:
        glColor3f(coloa, colob, coloc)
        glLineWidth(1.0)
        glEnable(edgeholy)

        for i, matrix in enumerate(data_matrix):  # object
            k = i
            if i > verlen:  # filter to share objects
                k = verlen
            for line in data_edges[k]:  # line
                if max(line) > verlen_every[k]:
                    line = data_edges[k][-1]
                glBegin(edgeline)
                for point in line:  # point
                    vec_corrected = data_matrix[i] * data_vector[k][int(point)]
                    glVertex3f(*vec_corrected)
                glEnd()
                glPointSize(1.75)
                glLineWidth(1.0)
        glDisable(edgeholy)

    #######
    # polygons
    vectorlight = Vector((-0.66, -0.66, -0.66))
    if data_polygons and data_vector:
        glLineWidth(1.0)
        glEnable(polyholy)

        for i, matrix in enumerate(data_matrix):  # object
            k = i
            if i > verlen:
                k = verlen
            oblen = len(data_polygons[k])
            for j, pol in enumerate(data_polygons[k]):
                if max(pol) > verlen_every[k]:
                    pol = data_edges[k][-1]
                    j = len(data_edges[k]) - 1
                if shade:
                    normal_no_ = mathutils.geometry.normal(
                        data_vector[k][pol[0]], data_vector[k][pol[1]],
                        data_vector[k][pol[2]])
                    normal_no = (normal_no_.angle(vectorlight, 0)) / math.pi
                    randa = (normal_no * coloa) - 0.1
                    randb = (normal_no * colob) - 0.1
                    randc = (normal_no * coloc) - 0.1
                else:
                    randa = ((j / oblen) + coloa) / 2.5
                    randb = ((j / oblen) + colob) / 2.5
                    randc = ((j / oblen) + coloc) / 2.5
                if len(pol) > 4:
                    glBegin(GL_TRIANGLES)
                    glColor4f(randa + 0.2, randb + 0.2, randc + 0.2, 0.5)
                    #glColor3f(randa+0.2, randb+0.2, randc+0.2)
                    v = [data_vector[k][i] for i in pol]
                    tess_poly = mathutils.geometry.tessellate_polygon([v])
                    for a, b, c in tess_poly:
                        glVertex3f(*(data_matrix[i] * v[a]))
                        glVertex3f(*(data_matrix[i] * v[b]))
                        glVertex3f(*(data_matrix[i] * v[c]))
                elif len(pol) == 4:
                    glBegin(GL_POLYGON)
                    glColor3f(randa + 0.2, randb + 0.2, randc + 0.2)
                    for point in pol:
                        vec_corrected = data_matrix[i] * data_vector[k][int(
                            point)]
                        glVertex3f(*vec_corrected)
                else:
                    glBegin(GL_TRIANGLES)
                    glColor3f(randa + 0.2, randb + 0.2, randc + 0.2)
                    for point in pol:
                        vec_corrected = data_matrix[i] * data_vector[k][int(
                            point)]
                        glVertex3f(*vec_corrected)
                glEnd()
                glPointSize(1.75)
                glLineWidth(1.0)
        glDisable(polyholy)

    # for future bezier drawing - to remake
    #if data_edges and data_vector and bezier:
    # here 3 lines that i must understand
    #from bpy_extras.view3d_utils import location_3d_to_region_2d
    #region = context.region
    #region_data = context.region_data

    #glEnable(GL_BLEND)
    #glColor4f(1, 0, 0, 0.5)
    #glLineWidth(1.0)
    #glBegin(GL_LINE_STRIP)
    #for i in range(current_frame):
    #glVertex2f(*location_3d_to_region_2d(region, region_data, (math.sin(i / 10), 0, i / 10)).to_tuple())
    #glEnd()
    #glDisable(GL_BLEND)

    #######
    # matrix
    if data_matrix and not data_vector:
        for mat in data_matrix:
            draw_matrix(mat)
Example #56
0
def draw_wire_cylinder(radius, half_height, num_segments):
    bgl.glBegin(bgl.GL_LINE_LOOP)
    gen_circle(radius, num_segments,
               lambda x, y: bgl.glVertex3f(x, -half_height, y))
    bgl.glEnd()
    bgl.glBegin(bgl.GL_LINE_LOOP)
    gen_circle(radius, num_segments,
               lambda x, y: bgl.glVertex3f(x, +half_height, y))
    bgl.glEnd()
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex3f(-radius, -half_height, 0)
    bgl.glVertex3f(-radius, +half_height, 0)
    bgl.glVertex3f(+radius, -half_height, 0)
    bgl.glVertex3f(+radius, +half_height, 0)
    bgl.glVertex3f(0, -half_height, -radius)
    bgl.glVertex3f(0, +half_height, -radius)
    bgl.glVertex3f(0, -half_height, +radius)
    bgl.glVertex3f(0, +half_height, +radius)
    bgl.glEnd()
Example #57
0
def draw_stuff():
    # print("draw_stuff")
    # FIXME this should use glPushAttrib
    from bgl import glColor3f, glVertex3f, glBegin, glEnd, GL_POLYGON, GL_LINES
    global draw_stuff_dirty, draw_stuff_objects
    ctx = bpy.context
    if not len(ctx.selected_objects) and not ctx.object:
        return
    if not bpy.context.window_manager.thug_show_face_collision_colors:
        return

    VERT_FLAG = FACE_FLAGS["mFD_VERT"]
    WALLRIDABLE_FLAG = FACE_FLAGS["mFD_WALL_RIDABLE"]
    TRIGGER_FLAG = FACE_FLAGS["mFD_TRIGGER"]
    NON_COLLIDABLE_FLAG = FACE_FLAGS["mFD_NON_COLLIDABLE"]

    bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
    try:
        _tmp_buf = bgl.Buffer(bgl.GL_FLOAT, 1)
        bgl.glGetFloatv(bgl.GL_POLYGON_OFFSET_FACTOR, _tmp_buf)
        old_offset_factor = _tmp_buf[0]
        bgl.glGetFloatv(bgl.GL_POLYGON_OFFSET_UNITS, _tmp_buf)
        old_offset_units = _tmp_buf[0]
        del _tmp_buf

        objects = set([ob.name for ob in ctx.selected_objects] if ctx.mode == "OBJECT" else [ctx.object.name])
        if draw_stuff_objects != objects:
            draw_stuff_dirty = True
        # print("draw_stuff2")

        if not draw_stuff_dirty:
            bgl.glCallList(draw_stuff_display_list_id)
            bgl.glPolygonOffset(old_offset_factor, old_offset_units)
            bgl.glDisable(bgl.GL_POLYGON_OFFSET_FILL)
            bgl.glDisable(bgl.GL_CULL_FACE)
            return

        bm = None
        bgl.glNewList(draw_stuff_display_list_id, bgl.GL_COMPILE_AND_EXECUTE)
        try:
            bgl.glCullFace(bgl.GL_BACK)
            bgl.glEnable(bgl.GL_CULL_FACE)
            bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
            #bgl.glEnable(bgl.GL_POLYGON_OFFSET_LINE)
            bgl.glPolygonOffset(-2, -2)

            bgl.glEnable(bgl.GL_BLEND)
            bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA);

            prefs = ctx.user_preferences.addons[ADDON_NAME].preferences

            bgl.glLineWidth(prefs.line_width)

            draw_stuff_objects = objects
            bdobs = {ob.name: ob for ob in bpy.data.objects}
            for ob in objects:
                ob = bdobs[ob]
                if not bm: bm = bmesh.new()
                if (ob and
                        ob.type == "CURVE" and
                        ob.data.splines and
                        ob.data.splines[-1].points and
                        ob.thug_path_type == "Rail" and
                        ob.thug_rail_connects_to):
                    connects_to = bdobs[ob.thug_rail_connects_to]
                    if (connects_to and
                            connects_to.type == "CURVE" and
                            connects_to.data.splines and
                            connects_to.data.splines[0].points):
                        glBegin(GL_LINES)
                        bgl.glColor4f(*prefs.rail_end_connection_color)
                        v = ob.matrix_world * ob.data.splines[-1].points[-1].co.to_3d()
                        glVertex3f(v[0], v[1], v[2])
                        v = connects_to.matrix_world * connects_to.data.splines[0].points[0].co.to_3d()
                        glVertex3f(v[0], v[1], v[2])
                        glEnd()

                # Draw previews for area lights - tube/sphere lights and area lights
                if (ob and ob.type == 'LAMP'):
                    if ob.data.thug_light_props.light_type == 'TUBE':
                        if ob.data.thug_light_props.light_end_pos != (0, 0, 0):
                            glBegin(GL_LINES)
                            bgl.glColor4f(1.0, 0.75, 0.25, 1.0)
                            glVertex3f(ob.location[0], ob.location[1], ob.location[2])
                            glVertex3f(ob.location[0] + ob.data.thug_light_props.light_end_pos[0], ob.location[1] + ob.data.thug_light_props.light_end_pos[1], ob.location[2] + ob.data.thug_light_props.light_end_pos[2])
                            glEnd()
                        continue
                    elif ob.data.thug_light_props.light_type == 'SPHERE':
                        continue
                    elif ob.data.thug_light_props.light_type == 'AREA':
                        continue
                    else:
                        continue
                elif (ob and ob.type == 'EMPTY'):
                    if ob.thug_empty_props.empty_type == 'LightVolume' or ob.thug_empty_props.empty_type == 'CubemapProbe':
                        # Draw light volume bbox!
                        bbox, bbox_min, bbox_max, bbox_mid = get_bbox_from_node(ob)
                        
                        # 50% alpha, 2 pixel width line
                        bgl.glEnable(bgl.GL_BLEND)
                        bgl.glColor4f(1.0, 0.0, 0.0, 0.5)
                        bgl.glLineWidth(4)
                        
                        glBegin(bgl.GL_LINE_STRIP)
                        bgl.glVertex3f(*bbox[0])
                        bgl.glVertex3f(*bbox[1])
                        bgl.glVertex3f(*bbox[2])
                        bgl.glVertex3f(*bbox[3])
                        bgl.glVertex3f(*bbox[0])
                        bgl.glVertex3f(*bbox[4])
                        bgl.glVertex3f(*bbox[5])
                        bgl.glVertex3f(*bbox[6])
                        bgl.glVertex3f(*bbox[7])
                        bgl.glVertex3f(*bbox[4])
                        bgl.glEnd()

                        bgl.glBegin(bgl.GL_LINES)
                        bgl.glVertex3f(*bbox[1])
                        bgl.glVertex3f(*bbox[5])
                        bgl.glVertex3f(*bbox[2])
                        bgl.glVertex3f(*bbox[6])
                        bgl.glVertex3f(*bbox[3])
                        bgl.glVertex3f(*bbox[7])
                        glEnd()
                        
                if not ob or ob.type != "MESH":
                    continue

                if ob.mode == "EDIT":
                    bm.free()
                    bm = bmesh.from_edit_mesh(ob.data).copy()
                else:
                    bm.clear()
                    if ob.modifiers:
                        final_mesh = ob.to_mesh(bpy.context.scene, True, "PREVIEW")
                        try:
                            bm.from_mesh(final_mesh)
                        finally:
                            bpy.data.meshes.remove(final_mesh)
                    else:
                        bm.from_mesh(ob.data)

                arl = bm.edges.layers.int.get("thug_autorail")
                if arl:
                    bgl.glColor4f(*prefs.autorail_edge_color)
                    glBegin(GL_LINES)
                    for edge in bm.edges:
                        if edge[arl] == AUTORAIL_NONE:
                            continue

                        for vert in edge.verts:
                            v = ob.matrix_world * vert.co
                            glVertex3f(v[0], v[1], v[2])
                    glEnd()

                cfl = bm.faces.layers.int.get("collision_flags")
                flag_stuff = ((VERT_FLAG, prefs.vert_face_color),
                              (WALLRIDABLE_FLAG, prefs.wallridable_face_color),
                              (TRIGGER_FLAG, prefs.trigger_face_color),
                              (NON_COLLIDABLE_FLAG, prefs.non_collidable_face_color))
                if cfl:
                    bmesh.ops.triangulate(bm, faces=bm.faces)

                    for face in bm.faces:
                        drawn_face = False
                        if prefs.show_bad_face_colors:
                            if (face[cfl] & (VERT_FLAG | WALLRIDABLE_FLAG | NON_COLLIDABLE_FLAG) not in
                                (VERT_FLAG, WALLRIDABLE_FLAG, NON_COLLIDABLE_FLAG, 0)):
                                bgl.glColor4f(*prefs.bad_face_color)
                                glBegin(GL_POLYGON)
                                for vert in face.verts:
                                    v = ob.matrix_world * vert.co
                                    glVertex3f(v[0], v[1], v[2])
                                glEnd()
                                continue

                        for face_flag, face_color in flag_stuff:
                            if face[cfl] & face_flag and (not drawn_face or prefs.mix_face_colors):
                                bgl.glColor4f(*face_color)
                                drawn_face = True

                                glBegin(GL_POLYGON)
                                for vert in face.verts:
                                    v = ob.matrix_world * vert.co
                                    glVertex3f(v[0], v[1], v[2])
                                glEnd()
        finally:
            draw_stuff_dirty = False
            bgl.glEndList()
            if bm: bm.free()
            bgl.glPolygonOffset(old_offset_factor, old_offset_units)
            bgl.glDisable(bgl.GL_POLYGON_OFFSET_FILL)
    finally:
        bgl.glPopAttrib()
Example #58
0
def draw_mouse(context, shape, style, alpha):
    # shape and position
    sc = context.scene
    mouse_size = sc.screencast_keys_mouse_size
    font_size = sc.screencast_keys_font_size
    box_draw = sc.screencast_keys_box_draw

    pos_x, pos_y = getDisplayLocation(context)

    if sc.screencast_keys_mouse_position == 'left':
        offset_x = pos_x
    if sc.screencast_keys_mouse_position == 'right':
        offset_x = context.region.width - pos_x - (mouse_size * MOUSE_RATIO)

    offset_y = pos_y
    if font_size > mouse_size:
        offset_y += (font_size - mouse_size) / 2

    shape_data = get_shape_data(shape)

    bgl.glTranslatef(offset_x, offset_y, 0)

    # color
    r, g, b, a = sc.screencast_keys_text_color
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(r, g, b, alpha)

    # inner shape for filled style
    if style == "filled":
        inner_shape = []
        for i in shape_data:
            inner_shape.append(i[0])

    # outer shape
    for i in shape_data:
        shape_segment = i
        shape_segment[0] = [mouse_size * k for k in shape_segment[0]]
        shape_segment[1] = [mouse_size * k for k in shape_segment[1]]
        shape_segment[2] = [mouse_size * k for k in shape_segment[2]]
        shape_segment[3] = [mouse_size * k for k in shape_segment[3]]

        # create the buffer
        shape_buffer = bgl.Buffer(bgl.GL_FLOAT, [4, 3], shape_segment)

        # create the map and draw the triangle fan
        bgl.glMap1f(bgl.GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, shape_buffer)
        bgl.glEnable(bgl.GL_MAP1_VERTEX_3)

        if style == "outline":
            bgl.glBegin(bgl.GL_LINE_STRIP)
        else:  # style == "filled"
            bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for j in range(10):
            bgl.glEvalCoord1f(j / 10.0)
        x, y, z = shape_segment[3]

        # make sure the last vertex is indeed the last one, to avoid gaps
        bgl.glVertex3f(x, y, z)
        bgl.glEnd()
        bgl.glDisable(bgl.GL_MAP1_VERTEX_3)

    # draw interior
    if style == "filled":
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for i in inner_shape:
            j = [mouse_size * k for k in i]
            x, y, z = j
            bgl.glVertex3f(x, y, z)
        bgl.glEnd()

    bgl.glTranslatef(-offset_x, -offset_y, 0)
Example #59
0
    def stroke_postview(self):
        if self.mode not in {'main','stroke'}: return
        if not self.hit: return
        cx,cy,cp = self.hit_x,self.hit_y,self.hit_p
        cs_outer = self.scale * 20
        cs_inner = self.scale * 20 * 0.5
        cr,cg,cb = self.color

        bgl.glDepthRange(0, 0.999)      # squeeze depth just a bit
        bgl.glEnable(bgl.GL_BLEND)
        self.drawing.line_width(2.0)
        self.drawing.point_size(3.0)

        ######################################
        # draw in front of geometry

        bgl.glDepthFunc(bgl.GL_LEQUAL)
        bgl.glDepthMask(bgl.GL_FALSE)   # do not overwrite depth

        bgl.glColor4f(cr, cg, cb, 1.0)       # outer ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_outer * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        bgl.glColor4f(cr, cg, cb, 0.1)     # inner ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_inner * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        bgl.glColor4f(1, 1, 1, 0.25)    # center point
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glVertex3f(*cp)
        bgl.glEnd()

        ######################################
        # draw behind geometry (hidden below)

        bgl.glDepthFunc(bgl.GL_GREATER)
        bgl.glDepthMask(bgl.GL_FALSE)   # do not overwrite depth

        bgl.glColor4f(cr, cg, cb, 0.05)    # outer ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_outer * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        bgl.glColor4f(cr, cg, cb, 0.01)   # inner ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_inner * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        ######################################
        # reset to defaults

        bgl.glDepthFunc(bgl.GL_LEQUAL)
        bgl.glDepthMask(bgl.GL_TRUE)

        bgl.glDepthRange(0, 1)
Example #60
0
def _draw_3dview_report(region):
    """Draws reports in 3d views.

    :param region: region of 3D viewport
    :type region: bpy.types.Region
    """
    pos = region.height - 65

    if _Show3DViewReportOperator.has_lines():

        glEnable(GL_TEXTURE_2D)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glBindTexture(GL_TEXTURE_2D, _Show3DViewReportOperator.get_scs_logo_img_bindcode())

        # draw BT logo
        glBegin(GL_POLYGON)
        glColor3f(1, 1, 1)
        glTexCoord2f(0, 1)
        glVertex3f(_OP_consts.View3DReport.BT_LOGO_AREA[0], region.height - _OP_consts.View3DReport.BT_LOGO_AREA[2], 0)
        glTexCoord2f(1, 1)
        glVertex3f(_OP_consts.View3DReport.BT_LOGO_AREA[1], region.height - _OP_consts.View3DReport.BT_LOGO_AREA[2], 0)
        glTexCoord2f(1, 0)
        glVertex3f(_OP_consts.View3DReport.BT_LOGO_AREA[1], region.height - _OP_consts.View3DReport.BT_LOGO_AREA[3], 0)
        glTexCoord2f(0, 0)
        glVertex3f(_OP_consts.View3DReport.BT_LOGO_AREA[0], region.height - _OP_consts.View3DReport.BT_LOGO_AREA[3], 0)
        glEnd()

        glDisable(GL_TEXTURE_2D)

        # draw version string
        blf.size(0, 11, 72)
        glColor3f(.952, .635, .062)
        blf.position(0, 20, pos, 0)
        blf.draw(0, _info_utils.get_combined_ver_str(only_version_numbers=True))
        pos -= 20

        # draw actual operator title and message if shown
        if _Show3DViewReportOperator.is_shown():

            blf.size(0, 12, 72)
            glColor3f(1, 1, 1)
            blf.shadow(0, 5, 0, 0, 0, 1)

            if _Show3DViewReportOperator.get_title() != "":
                blf.position(0, 20, pos, 0)
                blf.draw(0, _Show3DViewReportOperator.get_title())
                pos -= 15

            blf.enable(0, blf.SHADOW)
            for line in _Show3DViewReportOperator.get_lines():

                # finish printing if running out of space
                if pos - 60 < 0:
                    blf.position(0, 20, pos, 0)
                    blf.draw(0, "...")
                    break

                blf.position(0, 20, pos, 0)
                if "ERROR" in line:
                    blf.shadow(0, 5, 0.5, 0., 0, 1)
                elif "WARNING" in line:
                    blf.shadow(0, 5, 0.3, 0.15, 0, 1)

                blf.draw(0, line)
                pos -= 15

            blf.disable(0, blf.SHADOW)

        # draw control buttons if controls are enabled
        if _Show3DViewReportOperator.has_controls():

            # draw close button
            glColor3f(.4, .4, .4)
            glBegin(GL_POLYGON)
            glVertex3f(_OP_consts.View3DReport.CLOSE_BTN_AREA[0], region.height - _OP_consts.View3DReport.CLOSE_BTN_AREA[2], 0)
            glVertex3f(_OP_consts.View3DReport.CLOSE_BTN_AREA[1], region.height - _OP_consts.View3DReport.CLOSE_BTN_AREA[2], 0)
            glVertex3f(_OP_consts.View3DReport.CLOSE_BTN_AREA[1], region.height - _OP_consts.View3DReport.CLOSE_BTN_AREA[3], 0)
            glVertex3f(_OP_consts.View3DReport.CLOSE_BTN_AREA[0], region.height - _OP_consts.View3DReport.CLOSE_BTN_AREA[3], 0)
            glEnd()

            # draw hide button
            glBegin(GL_POLYGON)
            glVertex3f(_OP_consts.View3DReport.HIDE_BTN_AREA[0], region.height - _OP_consts.View3DReport.HIDE_BTN_AREA[2], 0)
            glVertex3f(_OP_consts.View3DReport.HIDE_BTN_AREA[1], region.height - _OP_consts.View3DReport.HIDE_BTN_AREA[2], 0)
            glVertex3f(_OP_consts.View3DReport.HIDE_BTN_AREA[1], region.height - _OP_consts.View3DReport.HIDE_BTN_AREA[3], 0)
            glVertex3f(_OP_consts.View3DReport.HIDE_BTN_AREA[0], region.height - _OP_consts.View3DReport.HIDE_BTN_AREA[3], 0)
            glEnd()

            # gather texts and positions
            close_btn_text_pos = _OP_consts.View3DReport.CLOSE_BTN_TEXT_POS[int(not _Show3DViewReportOperator.is_shown())]
            close_btn_text = _OP_consts.View3DReport.CLOSE_BTN_TEXT[int(not _Show3DViewReportOperator.is_shown())]

            hide_btn_text_pos = _OP_consts.View3DReport.HIDE_BTN_TEXT_POS[int(not _Show3DViewReportOperator.is_shown())]
            hide_btn_text = _OP_consts.View3DReport.HIDE_BTN_TEXT[int(not _Show3DViewReportOperator.is_shown())]

            blf.size(0, 15, 72)

            # draw close button text
            glColor3f(1, 1, 1)
            blf.position(0, close_btn_text_pos[0], region.height - close_btn_text_pos[1], 0)
            blf.draw(0, close_btn_text)

            # draw hide button text
            blf.position(0, hide_btn_text_pos[0], region.height - hide_btn_text_pos[1], 0)
            blf.draw(0, hide_btn_text)