Example #1
0
 def __exit__(self, type, value, traceback):
     bgl.glEnd()
     # restore opengl defaults
     bgl.glLineWidth(1)
     bgl.glDisable(bgl.GL_BLEND)
     bgl.glEnable(bgl.GL_DEPTH_TEST)
     bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Example #2
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_box(xmin, ymin, w, h, poly=False):
    bgl.glBegin(bgl.GL_QUADS if poly else bgl.GL_LINE_LOOP)
    bgl.glVertex2f(xmin, ymin)
    bgl.glVertex2f(xmin + w, ymin)
    bgl.glVertex2f(xmin + w, ymin + h)
    bgl.glVertex2f(xmin, ymin + h)
    bgl.glEnd()
Example #4
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 #5
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  
Example #6
0
    def draw_index(rgb, rgb2, index, vec, text=''):

        vec_4d = perspective_matrix * vec.to_4d()
        if vec_4d.w <= 0.0:
            return

        x = region_mid_width + region_mid_width * (vec_4d.x / vec_4d.w)
        y = region_mid_height + region_mid_height * (vec_4d.y / vec_4d.w)
        if text:
            index = str(text[0])
        else:
            index = str(index)

        if draw_bg:
            polyline = get_points(index)

            ''' draw polygon '''
            bgl.glColor4f(*rgb2)
            bgl.glBegin(bgl.GL_POLYGON)
            for pointx, pointy in polyline:
                bgl.glVertex2f(pointx+x, pointy+y)
            bgl.glEnd()

        ''' draw text '''
        txt_width, txt_height = blf.dimensions(0, index)
        bgl.glColor4f(*rgb)
        blf.position(0, x - (txt_width / 2), y - (txt_height / 2), 0)
        blf.draw(0, index)
Example #7
0
def vicon_view3d_draw(x, y, w, h, alpha=1.0):
    cx = x + w / 2
    cy = y + h / 2
    d = max(2, h / 3)

    bgl.glColor4f(0.5, 0.5, 0.5, alpha)
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2f(x, cy - d)
    bgl.glVertex2f(x + w, cy - d)
    bgl.glVertex2f(x, cy + d)
    bgl.glVertex2f(x + w, cy + d)

    bgl.glVertex2f(cx - d, y)
    bgl.glVertex2f(cx - d, y + h)
    bgl.glVertex2f(cx + d, y)
    bgl.glVertex2f(cx + d, y + h)
    bgl.glEnd()

    bgl.glColor4f(0.0, 0.0, 0.0, alpha)
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2f(x, cy)
    bgl.glVertex2f(x + w, cy)
    bgl.glVertex2f(cx, y)
    bgl.glVertex2f(cx, y + h)
    bgl.glEnd()
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 #9
0
def draw_callback(self, context):

    scene = context.scene
    x = int(round(context.region.width * 0.01 + (self._t_target - scene.frame_start) * self._ppf))
    string = str(self._t_target)
    string = string[0 : string.index(".") + 3]
    font_id = 0  # XXX, need to find out how best to get this.

    # draw marker
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1, 0, 0, 1)
    bgl.glLineWidth(2)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2i(x, 17)
    bgl.glVertex2i(x, context.region.height)
    bgl.glEnd()

    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)

    # draw frame number
    if self._show_frame_indicator:
        blf.position(font_id, x + 5, 21, 0)
        blf.size(font_id, 12, 72)
        blf.draw(font_id, string)
	def redraw(self):

		drawregion = bpy.context.region

		rv3d = self.rv3ds[drawregion]
		vec = self.originvert.co.copy()
		vec.rotate(self.selobj.matrix_world)
		vec.rotate(self.selobj.matrix_world)
		self.space3d.cursor_location =  vec * self.selobj.matrix_world + self.selobj.matrix_world.to_translation()

		bgl.glColor3f(1.0, 1.0, 0)
		bgl.glBegin(bgl.GL_POLYGON)
		x, y = self.getscreencoords(Vector(self.originvert.co), drawregion, rv3d)
		bgl.glVertex2f(x-2, y-2)
		bgl.glVertex2f(x-2, y+2)
		bgl.glVertex2f(x+2, y+2)
		bgl.glVertex2f(x+2, y-2)
		bgl.glEnd()

		bgl.glColor3f(1, 1, 0.7)
		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glLoadIdentity()
		bgl.gluOrtho2D(0, self.region.width, 0, self.region.height)
		bgl.glMatrixMode(bgl.GL_MODELVIEW)
		bgl.glLoadIdentity()
		blf.position(0, self.region.width/2 - 80, self.region.height - 20, 0)
		blf.size(0, 12, 72)
		blf.draw(0, "FastOrigin :  Enter confirms - ESC cancels")
	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
Example #12
0
def draw_circle_select(m_coords, radius = 16, p_col = (0.7,0.8,1.0,0.6), enabled = False, sub = False):
    if(enabled):
        f_col = p_col
        if sub:
            f_col = (1.0, 0.5, 0.4, 0.6)
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBegin(bgl.GL_POLYGON)
        bgl.glColor4f(f_col[0], f_col[1], f_col[2], f_col[3]/3)

        point_x = m_coords[0]
        point_y = m_coords[1]

        radius = int(radius)

        for x in range(0, radius*2):
            bgl.glVertex2f(point_x + radius * math.cos(x * (360/(radius*2)) / 180 * 3.14159), point_y + radius * math.sin(x * (360/(radius*2)) / 180 * 3.14159))
        bgl.glEnd()

        bgl.glBegin(bgl.GL_LINES)
        bgl.glColor4f(f_col[0], f_col[1], f_col[2], f_col[3])
        for x in range(0, radius*2):
            bgl.glVertex2f(point_x + radius * math.cos(x * (360 / (radius * 2)) / 180 * 3.14159),
                           point_y + radius * math.sin(x * (360 / (radius * 2)) / 180 * 3.14159))

        bgl.glEnd()
        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Example #13
0
def cursor_history_draw(cls,context):
    cc = context.scene.cursor_history

    draw = 0
    if hasattr(cc, "historyDraw"):
        draw = cc.historyDraw

    if(draw):
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glShadeModel(bgl.GL_FLAT)
        alpha = 1-PHI_INV
        # History Trace
        if cc.historyPosition[0]<0:
            return
        bgl.glBegin(bgl.GL_LINE_STRIP)
        ccc = 0
        for iii in range(cc.historyWindow+1):
            ix_rel = iii - int(cc.historyWindow / 2)
            ix = cc.historyPosition[0] + ix_rel
            if(ix<0 or ix>=len(cc.historyLocation)):
                continue
            ppp = region3d_get_2d_coordinates(context, cc.historyLocation[ix])
            if(ix_rel<=0):
                bgl.glColor4f(0, 0, 0, alpha)
            else:
                bgl.glColor4f(1, 0, 0, alpha)
            bgl.glVertex2f(ppp[0], ppp[1])
            ccc = ccc + 1
        bgl.glEnd()
 def draw_Cartesian(self):#vertices):
     ob = bpy.context.scene.objects.active.location
     rgn = bpy.context.region
     rv3d = bpy.context.space_data.region_3d
     #bgl.glClear()
     
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glLineWidth(4)    
     bgl.glBegin(bgl.GL_LINE_STRIP)
     v3d = Vector((0, 0, 0))
     v2d = location_3d_to_region_2d(rgn, rv3d, v3d)
     bgl.glVertex2f(*v2d)
     bgl.glColor4f(100, 0.0, 0.0, 1)
     v3d = mathutils.Vector((ob.x,0,0))
     v2d = location_3d_to_region_2d(rgn, rv3d, v3d)
     bgl.glVertex2f(*v2d)
     bgl.glColor4f(0, 100.0, 0.0, 1)
     v3d = mathutils.Vector((ob.x,ob.y,0))
     v2d = location_3d_to_region_2d(rgn, rv3d, v3d)
     bgl.glVertex2f(*v2d)
     bgl.glColor4f(0, 0.0, 100.0, 1)
     v3d = mathutils.Vector((ob.x,ob.y,ob.z))
     v2d = location_3d_to_region_2d(rgn, rv3d, v3d)
     bgl.glVertex2f(*v2d)
     bgl.glEnd()
     bgl.glLineWidth(1)
     bgl.glDisable(bgl.GL_BLEND)
     
     bgl.glColor4f(1, 1, 1, 1)
     self.draw_value(Vector((ob.x/2,0,0)), str(round(ob.x, 2)))
     self.draw_value(Vector((ob.x, ob.y/2, 0)), str(round(ob.y, 2)))
     self.draw_value(Vector((ob.x, ob.y, ob.z/2)), str(round(ob.z, 2)))
Example #15
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)
 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 #17
0
def draw_callback_px(self, context):
    print("mouse points", len(self.mouse_path))

    font_id = 0  # XXX, need to find out how best to get this.

    # draw some text
    blf.position(font_id, 15, 30, 0)
    blf.size(font_id, 20, 72)
    blf.draw(font_id, "Hello Word " + str(len(self.mouse_path)))

    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
    bgl.glLineWidth(2)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for x, y in self.mouse_path:
        bgl.glVertex2i(x, y)

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    def drawPoint(x, y, main=True):
        r = 6 if main else 3

        bgl.glBegin(bgl.GL_LINES)
        bgl.glColor3f(1.0, 1.0, 1.0)
        bgl.glVertex2i(x - r, y)
        bgl.glVertex2i(x - r, y + r)
        bgl.glVertex2i(x - r, y + r)
        bgl.glVertex2i(x, y + r)

        bgl.glVertex2i(x + r, y)
        bgl.glVertex2i(x + r, y - r)
        bgl.glVertex2i(x + r, y - r)
        bgl.glVertex2i(x, y - r)

        bgl.glColor3f(0.0, 0.0, 0.0)
        bgl.glVertex2i(x, y + r)
        bgl.glVertex2i(x + r, y + r)
        bgl.glVertex2i(x + r, y + r)
        bgl.glVertex2i(x + r, y)

        bgl.glVertex2i(x, y - r)
        bgl.glVertex2i(x - r, y - r)
        bgl.glVertex2i(x - r, y - r)
        bgl.glVertex2i(x - r, y)
        bgl.glEnd()
Example #19
0
def draw_callback(self, context):
    mid = int(360 * self.recv / self.fsize)
    cx = 200
    cy = 30
    blf.position(0, 230, 23, 0)
    blf.size(0, 20, 72)
    blf.draw(0, "{0:2d}% of {1}".format(100 * self.recv // self.fsize, self.hfsize))

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.7, 0.7, 0.7, 0.8)
    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
    bgl.glVertex2i(cx, cy)
    for i in range(mid):
        x = cx + 20 * math.sin(math.radians(float(i)))
        y = cy + 20 * math.cos(math.radians(float(i)))
        bgl.glVertex2f(x, y)
    bgl.glEnd()

    bgl.glColor4f(0.0, 0.0, 0.0, 0.6)
    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
    bgl.glVertex2i(cx, cy)
    for i in range(mid, 360):
        x = cx + 20 * math.sin(math.radians(float(i)))
        y = cy + 20 * math.cos(math.radians(float(i)))
        bgl.glVertex2f(x, y)
    bgl.glEnd()

    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Example #20
0
def display_line_between_two_points(region, rv3d, p1_3d, p2_3d):

    bgl.glEnable(bgl.GL_BLEND)

    p1_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, p1_3d)
    p2_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, p2_3d)

    if p1_2d is None:
        p1_2d = (0.0, 0.0)
        p2_2d = (0.0, 0.0)

    col_line_main = addon_settings_graph()['col_line_main']
    col_line_shadow = addon_settings_graph()['col_line_shadow']

    bgl.glColor4f(*col_line_shadow)
    bgl.glLineWidth(1.4)
    bgl.glBegin(bgl.GL_LINE_STRIP) 
    bgl.glVertex2f((p1_2d[0]-1),(p1_2d[1]-1))
    bgl.glVertex2f((p2_2d[0]-1),(p2_2d[1]-1))
    bgl.glEnd()
    bgl.glColor4f(*col_line_main)
    bgl.glLineWidth(1.4)
    bgl.glBegin(bgl.GL_LINE_STRIP) 
    bgl.glVertex2f(*p1_2d)
    bgl.glVertex2f(*p2_2d)
    bgl.glEnd()

    bgl.glDisable(bgl.GL_BLEND)
Example #21
0
 def draw(self, context, render=False):
     if self.image is None:
         return
     bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
     p0 = self.pts[0]
     p1 = self.pts[1]
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glColor4f(*self.colour)
     bgl.glRectf(p0.x, p0.y, p1.x, p1.y)
     self.image.gl_load()
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.image.bindcode[0])
     bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST)
     bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_NEAREST)
     bgl.glEnable(bgl.GL_TEXTURE_2D)
     bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
     # bgl.glColor4f(1, 1, 1, 1)
     bgl.glBegin(bgl.GL_QUADS)
     bgl.glTexCoord2d(0, 0)
     bgl.glVertex2d(p0.x, p0.y)
     bgl.glTexCoord2d(0, 1)
     bgl.glVertex2d(p0.x, p1.y)
     bgl.glTexCoord2d(1, 1)
     bgl.glVertex2d(p1.x, p1.y)
     bgl.glTexCoord2d(1, 0)
     bgl.glVertex2d(p1.x, p0.y)
     bgl.glEnd()
     self.image.gl_free()
     bgl.glDisable(bgl.GL_TEXTURE_2D)
Example #22
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)
    def draw_callback_px(self, context):
        if context.region.id != self.region_id:
            return
        posx = 70
        posy1 = 30
        posy2 = 50
        text_interval = 5
        font_id = 0
        blf.size(font_id, 11, context.user_preferences.system.dpi)
        bgl.glEnable(bgl.GL_BLEND)
        if self.changing_mgtype:
            bgl.glColor4f(1.0, 1.0, 0.0, 1.0)
        else:
            bgl.glColor4f(1.0, 1.0, 1.0, 1.0)

        # draw origin
        bgl.glLineWidth(2)
        radius = path_threthold
        radius2 = radius + 5
        x, y, z = self.path[0]
        bgl.glBegin(bgl.GL_LINES)
        for i in range(4):
            r = math.pi / 2 * i + math.pi / 4
            bgl.glVertex2f(x + radius * math.cos(r), y + radius * math.sin(r))
            bgl.glVertex2f(x + radius2 * math.cos(r),
                           y + radius2 * math.sin(r))
        bgl.glEnd()
        bgl.glLineWidth(1)

        # draw lines
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glLineStipple(1, int(0b101010101010101))  # (factor, pattern)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for v in self.path:
            bgl.glVertex2f(v[0], v[1])
        bgl.glEnd()
        bgl.glLineStipple(1, 1)
        bgl.glDisable(bgl.GL_LINE_STIPPLE)

        # draw txt
        if self.action or self.mgitem:
            x = posx
            for txt in self.action:
                blf.position(font_id, x, posy1, 0)
                blf.draw(font_id, txt)
                text_width, text_height = blf.dimensions(font_id, txt)
                x += text_width + text_interval
            if self.mgitem:
                blf.position(font_id, posx, posy2, 0)
                blf.draw(font_id, self.mgitem.name)
        else:
            #blf.position(font_id, posx, posy2, 0)
            #blf.draw(font_id, '[Mouse Gesture]')
            pass

        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
        blf.size(0, 11, context.user_preferences.system.dpi)
Example #24
0
def draw_texture(x, y, w, h, texture, mode=None):
    mode_bak = bgl.Buffer(bgl.GL_INT, 1)
    bgl.glGetIntegerv(bgl.GL_DRAW_BUFFER, mode_bak)
    if mode is not None:
        bgl.glDrawBuffer(mode)

    bgl.glEnable(bgl.GL_TEXTURE_2D)
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture)

    bgl.glColor4d(1.0, 1.0, 1.0, 1.0)
    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
    bgl.glTexCoord2d(0.0, 0.0)
    bgl.glVertex2i(x, y)
    bgl.glTexCoord2d(1.0, 0.0)
    bgl.glVertex2i(x + w, y)
    bgl.glTexCoord2d(1.0, 1.0)
    bgl.glVertex2i(x + w, y + h)
    bgl.glTexCoord2d(0.0, 1.0)
    bgl.glVertex2i(x, y + h)
    bgl.glEnd()

    bgl.glDisable(bgl.GL_TEXTURE_2D)
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

    if mode is not None:
        bgl.glDrawBuffer(mode_bak[0])
Example #25
0
def draw_polyline_from_3dpoints(context, points_3d, color, thickness, LINE_TYPE):
    '''
    a simple way to draw a line
    slow...becuase it must convert to screen every time
    but allows you to pan and zoom around
    
    args:
        points_3d: a list of tuples representing x,y SCREEN coordinate eg [(10,30),(11,31),...]
        color: tuple (r,g,b,a)
        thickness: integer? maybe a float
        LINE_TYPE:  eg...bgl.GL_LINE_STIPPLE or 
    '''
    points = [location_3d_to_region_2d(context.region, context.space_data.region_3d, loc) for loc in points_3d]
    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.glBegin(bgl.GL_LINE_STRIP)
    for coord in points:  
        bgl.glVertex2f(*coord)  
    
    bgl.glEnd()  
      
    if LINE_TYPE == "GL_LINE_STIPPLE":  
        bgl.glDisable(bgl.GL_LINE_STIPPLE)  
        bgl.glEnable(bgl.GL_BLEND)  # back to uninterupted lines  
        bgl.glLineWidth(1)
    return
Example #26
0
def draw_arc(center, radius, axis, angle_min, angle_max, local_transf_mat=None):
    base_axis = mathutils.Vector((0, 0, 1))
    axis = mathutils.Vector(axis)
    dot = base_axis.dot(axis)
    cross = base_axis.cross(axis)
    axis_rotation = mathutils.Matrix.Rotation(math.acos(dot), 4, cross)

    bgl.glBegin(bgl.GL_LINE_STRIP)

    phi_range = wrap_2pi(angle_max - angle_min)

    points = []

    co_from = calc_circ_coords(center, radius, axis_rotation, angle_min, local_transf_mat)
    bgl.glVertex3f(co_from.x, co_from.y, co_from.z)
    points.append(co_from)

    for i in range(1, NUM_SECTORS + 1):
        i *= 2 * math.pi / NUM_SECTORS
       
        if i < phi_range:
            co = calc_circ_coords(center, radius, axis_rotation, i + angle_min, local_transf_mat)
            bgl.glVertex3f(co.x, co.y, co.z)
            points.append(co)

    co_to = calc_circ_coords(center, radius, axis_rotation, angle_max, local_transf_mat)
    bgl.glVertex3f(co_to.x, co_to.y, co_to.z)
    points.append(co_to)

    bgl.glEnd()

    return points
Example #27
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 #28
0
    def post_view_callback(self, context):
        start = self.vertex_co
        normal_size = context.tool_settings.normal_size
        view_3d_theme = context.user_preferences.themes['Default'].view_3d

        default_color = view_3d_theme.split_normal
        highlight_color = [0.25, 1.0, 0.56]

        # Draw all normals of selected vertex.
        bgl.glBegin(bgl.GL_LINES)
        bgl.glColor3f(*default_color)
        bgl.glLineWidth(1)
        for n in self.normals:
            end = start + Vector(n) * normal_size
            bgl.glVertex3f(*start)
            bgl.glVertex3f(*end)
        bgl.glEnd()

        # Highlight selected normal.
        bgl.glColor3f(*highlight_color)
        bgl.glLineWidth(2)
        bgl.glBegin(bgl.GL_LINES)
        end = start + Vector(self.normals[self.normals_idx]) * normal_size
        bgl.glVertex3f(*start)
        bgl.glVertex3f(*end)
        bgl.glEnd()
Example #29
0
def draw_polyline_from_points(context, points, color, thickness, LINE_TYPE):
    '''
    a simple way to draw a line
    args:
        points: a list of tuples representing x,y SCREEN coordinate eg [(10,30),(11,31),...]
        color: tuple (r,g,b,a)
        thickness: integer? maybe a float
        LINE_TYPE:  eg...bgl.GL_LINE_STIPPLE or 
    '''
    
    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)
    
    current_width = bgl.GL_LINE_WIDTH
    bgl.glColor4f(*color)
    bgl.glLineWidth(thickness)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    
    for coord in points:  
        bgl.glVertex2f(*coord)  
    
    bgl.glEnd()  
    bgl.glLineWidth(1)  
    if LINE_TYPE == "GL_LINE_STIPPLE":  
        bgl.glDisable(bgl.GL_LINE_STIPPLE)  
        bgl.glEnable(bgl.GL_BLEND)  # back to uninterupted lines  
      
    return
	def drawCurvePoints(self):
		#Draw Lines between Control Points

		bgl.glEnable(bgl.GL_POINT_SMOOTH)
		bgl.glColor3d(0,1,0)
		bgl.glPointSize(3)
		bgl.glBegin(bgl.GL_POINTS)

		for i in range(len(self.curvePoints)):
			tup = self.curvePoints[i].to_tuple()
			bgl.glVertex3f( *tup )
		bgl.glEnd()

		bgl.glLineWidth(1)
		bgl.glColor3f(0,.5,0)
		bgl.glBegin(bgl.GL_LINES)
		'''
		for i in range(0, len(self.curvePoints)-1):
			if i%(self.tesselate+1) != self.tesselate:
				tup = self.curvePoints[i]
				tup1 = self.curvePoints[i+1]
				bgl.glVertex3f( *tup )
				bgl.glVertex3f( *tup1 )
		'''
		for i in range(0, len(self.curvePoints)-1):
			tup = self.curvePoints[i].to_tuple()
			tup1 = self.curvePoints[i+1].to_tuple()
			bgl.glVertex3f(tup[0], tup[1], tup[2])
			bgl.glVertex3f(tup1[0], tup1[1], tup1[2])
		bgl.glEnd()
Example #31
0
def draw_polygon_object(mat,
                        vertices,
                        faces,
                        face_color,
                        draw_faces,
                        draw_wires,
                        wire_lines=None,
                        wire_color=(0, 0, 0),
                        face_transforms=None,
                        wire_transforms=None):
    """
    Draw a collider polygon object. It takes matrix, vertices (coordinates),
    faces (vertex index references), face color (RGB), faces drawing state (bool),
    wires drawing state (bool) and optional values wire lines (list of lists
    of vertex positions resulting in closed lines), wire color (RGB),
    face transformations (list of vertex indices)
    and wire transformations (list of vertex indices).
    :param mat:
    :param vertices:
    :param faces:
    :param face_color:
    :param draw_faces:
    :param draw_wires:
    :param wire_lines:
    :param wire_color:
    :param face_transforms:
    :param wire_transforms:
    :return:
    """
    if draw_faces:
        for face in faces:
            glBegin(GL_POLYGON)
            glColor3f(face_color[0], face_color[1], face_color[2])
            for vert in face:
                if face_transforms:
                    trans = mat
                    for transformation in face_transforms:
                        if vert in transformation[1]:
                            trans = trans * transformation[0]
                    glVertex3f(*(trans * Vector(vertices[vert])))
                else:
                    glVertex3f(*(mat * Vector(vertices[vert])))
            glEnd()
    if draw_wires:
        if wire_lines:

            # DRAW CUSTOM LINES
            vert_i_global = 0
            for line in wire_lines:
                # glLineWidth(2.0)
                glEnable(GL_LINE_STIPPLE)
                glBegin(GL_LINES)
                glColor3f(wire_color[0], wire_color[1], wire_color[2])

                for vert_i, vert1 in enumerate(line):
                    if vert_i + 1 < len(line):
                        vert2 = line[vert_i + 1]
                    else:
                        continue

                    # SEPARATE PART TRANSFORMATIONS
                    if wire_transforms:
                        trans1 = trans2 = mat
                        for transformation in wire_transforms:
                            if vert_i_global in transformation[1]:
                                trans1 = trans1 * transformation[0]
                            if vert_i_global + 1 in transformation[1]:
                                trans2 = trans2 * transformation[0]
                        glVertex3f(*(trans1 * Vector(vert1)))
                        glVertex3f(*(trans2 * Vector(vert2)))
                    else:
                        glVertex3f(*(mat * Vector(vert1)))
                        glVertex3f(*(mat * Vector(vert2)))
                    vert_i_global += 1
                vert_i_global += 1
                glEnd()
                glDisable(GL_LINE_STIPPLE)
                # glLineWidth(1.0)
        else:
            for face in faces:
                # glLineWidth(2.0)
                glEnable(GL_LINE_STIPPLE)
                glBegin(GL_LINES)
                glColor3f(wire_color[0], wire_color[1], wire_color[2])
                for vert_i, vert1 in enumerate(face):
                    if vert_i + 1 == len(face):
                        vert2 = face[0]
                    else:
                        vert2 = face[vert_i + 1]
                    if face_transforms:
                        trans1 = mat
                        trans2 = mat
                        vec1 = Vector(vertices[vert1])
                        vec2 = Vector(vertices[vert2])
                        for transformation in face_transforms:
                            if vert1 in transformation[1]:
                                trans1 = trans1 * transformation[0]
                            if vert2 in transformation[1]:
                                trans2 = trans2 * transformation[0]
                        glVertex3f(*(trans1 * vec1))
                        glVertex3f(*(trans2 * vec2))
                    else:
                        glVertex3f(*(mat * Vector(vertices[vert1])))
                        glVertex3f(*(mat * Vector(vertices[vert2])))
                glEnd()
                glDisable(GL_LINE_STIPPLE)
                # glLineWidth(1.0)
    if 0:  # DEBUG: draw points from faces geometry
        glPointSize(3.0)
        glBegin(GL_POINTS)
        glColor3f(0.5, 0.5, 1)
        for vertex_i, vertex in enumerate(vertices):
            vec = Vector(vertex)
            if face_transforms:
                trans = mat
                for transformation in face_transforms:
                    if vertex_i in transformation[1]:
                        trans = trans * transformation[0]
                glVertex3f(*(trans * vec))
            else:
                glVertex3f(*(mat * vec.to_3d()))
        glEnd()
        glPointSize(1.0)
    if 0:  # DEBUG: draw points from lines geometry
        if wire_lines:
            glPointSize(3.0)
            glBegin(GL_POINTS)
            glColor3f(1, 0, 0.5)
            vert_i_global = 0
            for line in wire_lines:
                for vert_i, vertex in enumerate(line):
                    if vert_i + 1 < len(line):
                        vec = Vector(vertex)
                    else:
                        continue
                    if wire_transforms:
                        trans = mat
                        for transformation in wire_transforms:
                            if vert_i_global in transformation[1]:
                                trans = trans * transformation[0]
                        glVertex3f(*(trans * vec.to_3d()))
                    else:
                        glVertex3f(*(mat * vec.to_3d()))
                    vert_i_global += 1
                vert_i_global += 1
            glEnd()
            glPointSize(1.0)
Example #32
0
def draw_boundings(self, context):
    for obj in bpy.data.objects:
        if obj.type == 'MESH' and obj.data.b4w_override_boundings:

            bounding_box = obj.data.b4w_boundings

            min_x = bounding_box.min_x
            max_x = bounding_box.max_x
            min_y = bounding_box.min_y
            max_y = bounding_box.max_y
            min_z = bounding_box.min_z
            max_z = bounding_box.max_z

            x_width = max_x - min_x
            y_width = max_y - min_y
            z_width = max_z - min_z

            cen = [0] * 3
            cen[0] = (max_x + min_x) / 2
            cen[1] = (max_y + min_y) / 2
            cen[2] = (max_z + min_z) / 2

            wm = obj.matrix_world

            if context.window_manager.b4w_draw_bound_box:
                bgl.glEnable(bgl.GL_BLEND)
                bgl.glLineWidth(2)
                # set colour
                bgl.glColor4f(0.5, 1.0, 1.0, 1.0)

                # draw boundings
                bgl.glBegin(bgl.GL_LINE_STRIP)
                co = mathutils.Vector((min_x, min_y, min_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                co = mathutils.Vector((max_x, min_y, min_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                co = mathutils.Vector((max_x, max_y, min_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                co = mathutils.Vector((min_x, max_y, min_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                bgl.glEnd()

                bgl.glBegin(bgl.GL_LINE_STRIP)
                co = mathutils.Vector((min_x, min_y, max_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                co = mathutils.Vector((min_x, min_y, min_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                co = mathutils.Vector((min_x, max_y, min_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                co = mathutils.Vector((min_x, max_y, max_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                bgl.glEnd()

                bgl.glBegin(bgl.GL_LINE_STRIP)
                co = mathutils.Vector((max_x, min_y, max_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                co = mathutils.Vector((min_x, min_y, max_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                co = mathutils.Vector((min_x, max_y, max_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                co = mathutils.Vector((max_x, max_y, max_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                bgl.glEnd()

                bgl.glBegin(bgl.GL_LINE_STRIP)
                co = mathutils.Vector((max_x, max_y, min_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                co = mathutils.Vector((max_x, max_y, max_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                co = mathutils.Vector((max_x, min_y, max_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                co = mathutils.Vector((max_x, min_y, min_z))
                co = wm * co
                bgl.glVertex3f(co[0], co[1], co[2])
                bgl.glEnd()
                bgl.glLineWidth(1)

            if context.window_manager.b4w_draw_bound_sphere:
                #draw spehere
                bgl.glColor4f(1.0, 0.5, 1.0, 1.0)

                r = math.sqrt(x_width * x_width + y_width * y_width +
                              z_width * z_width) / 2
                draw_elipse(cen, r, (1, 0, 0), 1, wm)
                draw_elipse(cen, r, (0, 1, 0), 1, wm)
                draw_elipse(cen, r, (0, 0, 1), 1, wm)

                bgl.glDisable(bgl.GL_BLEND)

            if context.window_manager.b4w_draw_bound_ellipsoid:

                #draw ellipsoid
                bgl.glColor4f(1.0, 1.0, 0.5, 1.0)

                sq3 = math.sqrt(3) / 2

                draw_elipse(cen, sq3 * z_width, (1, 0, 0), y_width / z_width,
                            wm)
                draw_elipse(cen, sq3 * x_width, (0, 1, 0), z_width / x_width,
                            wm)
                draw_elipse(cen, sq3 * x_width, (0, 0, 1), y_width / x_width,
                            wm)

                bgl.glDisable(bgl.GL_BLEND)
Example #33
0
    def draw_to_viewport(view_min, view_max, show_extra, label_counter,
                         tilegrid, sprytile_data, cursor_loc, region, rv3d,
                         middle_btn, context):
        """Draw the offscreen texture into the viewport"""

        # Prepare some data that will be used for drawing
        grid_size = SprytileGui.loaded_grid.grid
        tile_sel = SprytileGui.loaded_grid.tile_selection
        padding = SprytileGui.loaded_grid.padding
        margin = SprytileGui.loaded_grid.margin
        is_pixel = sprytile_utils.grid_is_single_pixel(SprytileGui.loaded_grid)

        # Draw work plane
        SprytileGui.draw_work_plane(grid_size, sprytile_data, cursor_loc,
                                    region, rv3d, middle_btn)

        # Setup GL for drawing the offscreen texture
        bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, SprytileGui.texture)
        # Backup texture settings
        old_mag_filter = Buffer(bgl.GL_INT, 1)
        glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
                            old_mag_filter)

        old_wrap_S = Buffer(GL_INT, 1)
        old_wrap_T = Buffer(GL_INT, 1)

        glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, old_wrap_S)
        glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, old_wrap_T)

        # Set texture filter
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER,
                            bgl.GL_NEAREST)
        bgl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
        bgl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
        bgl.glEnable(bgl.GL_TEXTURE_2D)
        bgl.glEnable(bgl.GL_BLEND)

        # Draw the preview tile
        if middle_btn is False:
            SprytileGui.draw_preview_tile(context, region, rv3d)

        # Calculate actual view size
        view_size = int(view_max.x - view_min.x), int(view_max.y - view_min.y)

        # Save the original scissor box, and then set new scissor setting
        scissor_box = bgl.Buffer(bgl.GL_INT, [4])
        bgl.glGetIntegerv(bgl.GL_SCISSOR_BOX, scissor_box)
        bgl.glScissor(
            int(view_min.x) + scissor_box[0],
            int(view_min.y) + scissor_box[1], view_size[0], view_size[1])

        # Draw the tile select UI
        SprytileGui.draw_tile_select_ui(view_min, view_max, view_size,
                                        SprytileGui.tex_size, grid_size,
                                        tile_sel, padding, margin, show_extra,
                                        is_pixel)

        # restore opengl defaults
        bgl.glScissor(scissor_box[0], scissor_box[1], scissor_box[2],
                      scissor_box[3])
        bgl.glLineWidth(1)
        bgl.glTexParameteriv(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER,
                             old_mag_filter)
        bgl.glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, old_wrap_S)
        bgl.glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, old_wrap_T)

        # Draw label
        font_id = 0
        font_size = 16
        pad = 5
        if label_counter > 0:
            import math

            def ease_out_circ(t, b, c, d):
                t /= d
                t -= 1
                return c * math.sqrt(1 - t * t) + b

            box_pad = font_size + (pad * 2)
            fade = label_counter
            fade = ease_out_circ(fade, 0, SprytileGui.label_frames,
                                 SprytileGui.label_frames)
            fade /= SprytileGui.label_frames

            bgl.glColor4f(0.0, 0.0, 0.0, 0.75 * fade)
            bgl.glBegin(bgl.GL_QUADS)
            uv = [(0, 0), (0, 1), (1, 1), (1, 0)]
            vtx = [(view_min.x, view_max.y),
                   (view_min.x, view_max.y + box_pad),
                   (view_max.x, view_max.y + +box_pad),
                   (view_max.x, view_max.y)]
            for i in range(4):
                glTexCoord2f(uv[i][0], uv[i][1])
                glVertex2f(vtx[i][0], vtx[i][1])
            bgl.glEnd()

            bgl.glColor4f(1.0, 1.0, 1.0, 1.0 * fade)
            blf.size(font_id, font_size, 72)

            x_pos = view_min.x + pad
            y_pos = view_max.y + pad

            label_string = "%dx%d" % (tilegrid.grid[0], tilegrid.grid[1])
            if tilegrid.name != "":
                label_string = "%s - %s" % (label_string, tilegrid.name)
            blf.position(font_id, x_pos, y_pos, 0)
            blf.draw(font_id, label_string)
        if tilegrid.grid[0] == 1 and tilegrid.grid[1] == 1:
            size_text = "%dx%d" % (tile_sel[2], tile_sel[3])
            blf.size(font_id, font_size, 72)
            size = blf.dimensions(font_id, size_text)
            x_pos = view_max.x - size[0] - pad
            y_pos = view_max.y + pad
            blf.position(font_id, x_pos, y_pos, 0)
            blf.draw(font_id, size_text)

        bgl.glDisable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_TEXTURE_2D)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Example #34
0
    def draw_tile_select_ui(view_min, view_max, view_size, tex_size, grid_size,
                            tile_selection, padding, margin, show_extra,
                            is_pixel):
        # Draw the texture quad
        bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
        bgl.glBegin(bgl.GL_QUADS)
        uv = [(0, 0), (0, 1), (1, 1), (1, 0)]
        vtx = [(view_min.x, view_min.y), (view_min.x, view_max.y),
               (view_max.x, view_max.y), (view_max.x, view_min.y)]
        for i in range(4):
            glTexCoord2f(uv[i][0], uv[i][1])
            glVertex2f(vtx[i][0], vtx[i][1])
        bgl.glEnd()

        # Not drawing tile grid overlay
        if show_extra is False:
            return

        # Translate the gl context by grid matrix
        scale_factor = (view_size[0] / tex_size[0], view_size[1] / tex_size[1])

        # Setup to draw grid into viewport
        offset_matrix = Matrix.Translation((view_min.x, view_min.y, 0))
        grid_matrix = sprytile_utils.get_grid_matrix(SprytileGui.loaded_grid)
        grid_matrix = Matrix.Scale(scale_factor[0], 4, Vector(
            (1, 0, 0))) * Matrix.Scale(scale_factor[1], 4, Vector(
                (0, 1, 0))) * grid_matrix
        calc_matrix = offset_matrix * grid_matrix
        matrix_vals = [calc_matrix[j][i] for i in range(4) for j in range(4)]
        grid_buff = bgl.Buffer(bgl.GL_FLOAT, 16, matrix_vals)
        glPushMatrix()
        glLoadIdentity()
        glLoadMatrixf(grid_buff)
        glDisable(GL_TEXTURE_2D)

        glLineWidth(1)

        if is_pixel is False:
            glColor4f(0.0, 0.0, 0.0, 0.5)
            # Draw the grid
            cell_size = (grid_size[0] + padding[0] * 2 + margin[1] + margin[3],
                         grid_size[1] + padding[1] * 2 + margin[0] + margin[2])
            x_divs = ceil(tex_size[0] / cell_size[0])
            y_divs = ceil(tex_size[1] / cell_size[1])
            x_end = x_divs * cell_size[0]
            y_end = y_divs * cell_size[1]
            for x in range(x_divs + 1):
                x_pos = (x * cell_size[0])
                glBegin(GL_LINES)
                glVertex2f(x_pos, 0)
                glVertex2f(x_pos, y_end)
                glEnd()
            for y in range(y_divs + 1):
                y_pos = (y * cell_size[1])
                glBegin(GL_LINES)
                glVertex2f(0, y_pos)
                glVertex2f(x_end, y_pos)
                glEnd()

        if SprytileGui.is_selecting or (is_pixel and tile_selection[2] == 1
                                        or tile_selection[3] == 1):
            sel_min, sel_max = SprytileGui.get_sel_bounds(
                grid_size, padding, margin, tile_selection[0],
                tile_selection[1], tile_selection[2], tile_selection[3])
            glColor4f(1.0, 1.0, 1.0, 1.0)
            SprytileGui.draw_selection(sel_min, sel_max, 0)

        glPopMatrix()
def DRAW_Overlay(self, context):

    np_print('DRAW_Overlay_START',';','NP020PL.flag = ', NP020PL.flag)

    flag = NP020PL.flag
    helper = NP020PL.helper
    region = bpy.context.region
    rv3d = bpy.context.region_data
    rw = region.width
    rh = region.height
    co2d = view3d_utils.location_3d_to_region_2d(region, rv3d, helper.location)
    frompoints = NP020PL.frompoints
    topoints = NP020PL.topoints


    col_line_main = (1.0, 1.0, 1.0, 1.0)
    col_line_shadow = (0.1, 0.1, 0.1, 0.25)

    #greys:
    mark_col_A = (0.25, 0.25, 0.25, 1.0)
    mark_col_B = (0.5, 0.5, 0.5, 1.0)
    mark_col_C = (0.75, 0.75, 0.75, 1.0)

    #marins
    mark_col_A = (0.25, 0.35, 0.4, 1.0)
    mark_col_B = (0.5, 0.6, 0.65, 1.0)
    mark_col_C = (0.67, 0.77, 0.82, 1.0)

    # writing the dots for recwidget widget at center of scene:

    r = 12
    angstep = 20
    psize = 25
    pofsetx = 15
    pofsety = 15
    fsize = 20
    fofsetx = -8
    fofsety = -7



    widget_circle = construct_circle_2d(r, angstep)


    if flag == 'RUNTRANSF0':
        instruct = 'place start for point a'
        keys_aff = 'LMB - select, CTRL - snap, ENT - change snap'
        keys_neg = 'RMB, ESC - quit'
        frompoints[0] = helper.location

    elif flag == 'RUNTRANST0':
        instruct = 'place target for point a'
        keys_aff = 'LMB - select, CTRL - snap, ENT - change snap, MMB - lock axis, NUMPAD - value'
        keys_neg = 'RMB, ESC - quit'
        topoints[0] = helper.location

    elif flag == 'RUNTRANSF1':
        instruct = 'place start for point b'
        keys_aff = 'LMB - select, CTRL - snap, ENT - change snap, MMB - lock axis, NUMPAD - value, RMB - align A (translate)'
        keys_neg = 'ESC - quit'
        frompoints[1] = helper.location

    elif flag == 'RUNTRANST1':
        instruct = 'place target for point b'
        keys_aff = 'LMB - select, CTRL - snap, ENT - change snap, MMB - lock axis, NUMPAD - value, RMB - align A (translate)'
        keys_neg = 'ESC - quit'
        topoints[1] = helper.location

    elif flag == 'RUNTRANSF2':
        instruct = 'place start for point c'
        keys_aff = 'LMB - select, CTRL - snap, ENT - change snap, MMB - lock axis, NUMPAD - value, RMB - align AB (translate, rotate)'
        keys_neg = 'ESC - quit'
        frompoints[2] = helper.location

    elif flag == 'RUNTRANST2':
        instruct = 'place target for point c'
        keys_aff = 'LMB - select, CTRL - snap, ENT - change snap, MMB - lock axis, NUMPAD - value, RMB - align AB (translate, rotate)'
        keys_neg = 'ESC - quit'
        topoints[2] = helper.location


    # ON-SCREEN INSTRUCTIONS:


    keys_nav = ''

    display_instructions(region, rv3d, instruct, keys_aff, keys_nav, keys_neg)


    # LINE:

    for i, frompoint in enumerate(frompoints):
        topoint = topoints[i]
        if frompoint != None and topoint != None:
            bgl.glColor4f(*col_line_shadow)
            bgl.glLineWidth(1.4)
            bgl.glBegin(bgl.GL_LINE_STRIP)
            frompoint = view3d_utils.location_3d_to_region_2d(region, rv3d, frompoint)
            topoint = view3d_utils.location_3d_to_region_2d(region, rv3d, topoint)
            bgl.glVertex2f((frompoint[0] - 1), (frompoint[1] - 1))
            bgl.glVertex2f((topoint[0] - 1), (topoint[1] - 1))
            bgl.glEnd()

            bgl.glColor4f(*col_line_main)
            bgl.glLineWidth(1.4)
            bgl.glBegin(bgl.GL_LINE_STRIP)
            bgl.glVertex2f(*frompoint)
            bgl.glVertex2f(*topoint)
            bgl.glEnd()


    # drawing of markers:
    i = 0
    for point in frompoints:
        if point != None:
            point = view3d_utils.location_3d_to_region_2d(region, rv3d, point)
            point[0] = point[0] + pofsetx
            point[1] = point[1] + pofsety
            widget = []
            for co in widget_circle:
                c = [0.0, 0.0]
                c[0] = co[0] + point[0] + pofsetx
                c[1] = co[1] + point[1] + pofsety
                widget.append(c)
            bgl.glEnable(bgl.GL_BLEND)
            if i == 0:
                bgl.glColor4f(*mark_col_A)
                mark = "A"
            elif i == 1:
                bgl.glColor4f(*mark_col_B)
                mark = "B"
            elif i == 2:
                bgl.glColor4f(*mark_col_C)
                mark = "C"

            '''
            bgl.glLineWidth(1)
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for co in widget:
                bgl.glVertex2f(*co)
            bgl.glVertex2f(*widget[len(widget) - 1])
            bgl.glEnd()
            bgl.glBegin(bgl.GL_TRIANGLE_FAN)
            for co in widget:
                bgl.glVertex2f(*co)
            bgl.glEnd()
            '''
            font_id = 0
            bgl.glEnable(bgl.GL_POINT_SMOOTH)
            bgl.glPointSize(psize)
            bgl.glBegin(bgl.GL_POINTS)
            bgl.glVertex2f(*point)
            bgl.glEnd()
            bgl.glDisable(bgl.GL_POINT_SMOOTH)

            bgl.glColor4f(1.0, 1.0, 1.0, 0.75)
            blf.size(font_id, fsize, 72)
            blf.position(font_id, point[0] + fofsetx, point[1] + fofsety, 0)
            blf.draw(font_id, mark)
            i = i + 1

    i = 0
    for point in topoints:
        if point != None:
            point = view3d_utils.location_3d_to_region_2d(region, rv3d, point)
            point[0] = point[0] + pofsetx
            point[1] = point[1] + pofsety
            widget = []
            for co in widget_circle:
                c = [0.0, 0.0]
                c[0] = co[0] + point[0] + pofsetx
                c[1] = co[1] + point[1] + pofsety
                widget.append(c)
            bgl.glEnable(bgl.GL_BLEND)
            if i == 0:
                bgl.glColor4f(*mark_col_A)
                mark = "A'"
            elif i == 1:
                bgl.glColor4f(*mark_col_B)
                mark = "B'"
            elif i == 2:
                bgl.glColor4f(*mark_col_C)
                mark = "C'"
            '''
            bgl.glLineWidth(1)
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for co in widget:
                bgl.glVertex2f(*co)
            bgl.glVertex2f(*widget[len(widget) - 1])
            bgl.glEnd()
            bgl.glBegin(bgl.GL_TRIANGLE_FAN)
            for co in widget:
                bgl.glVertex2f(*co)
            bgl.glEnd()
            '''
            font_id = 0
            bgl.glEnable(bgl.GL_POINT_SMOOTH)
            bgl.glPointSize(psize)
            bgl.glBegin(bgl.GL_POINTS)
            bgl.glVertex2f(*point)
            bgl.glEnd()
            bgl.glDisable(bgl.GL_POINT_SMOOTH)

            bgl.glColor4f(1.0, 1.0, 1.0, 0.75)
            blf.size(font_id, fsize, 72)
            blf.position(font_id, point[0] + fofsetx, point[1] + fofsety, 0)
            blf.draw(font_id, mark)
            i = i + 1


    #ENDING:

    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Example #36
0
def DRAW_DisplayCage(self, context):

    flag = NP020PS.flag
    flag = 'DISPLAY'
    cage3d = NP020PS.cage3d
    cross3d = NP020PS.cross3d
    c3d = NP020PS.c3d

    region = context.region
    rv3d = context.region_data
    cage2d = copy.deepcopy(cage3d)
    cross2d = copy.deepcopy(cross3d)

    for co in cage3d.items():
        #np_print(co[0])
        cage2d[co[0]] = view3d_utils.location_3d_to_region_2d(
            region, rv3d, co[1])
    for co in cross3d.items():
        cross2d[co[0]] = view3d_utils.location_3d_to_region_2d(
            region, rv3d, co[1])
    c2d = view3d_utils.location_3d_to_region_2d(region, rv3d, c3d)

    points = copy.deepcopy(cage2d)
    points.update(cross2d)

    # DRAWING START:
    bgl.glEnable(bgl.GL_BLEND)

    if flag == 'DISPLAY':
        instruct = 'select a handle'
        keys_aff = 'LMB - confirm, CTRL - force proportional, SHIFT - force central, TAB - apply scale / rotation'
        keys_nav = ''
        keys_neg = 'ESC - quit'

    if self.flag_con:
        mark_col = (1.0, 0.5, 0.0, 1.0)
    else:
        mark_col = (0.3, 0.6, 1.0, 1.0)

    # ON-SCREEN INSTRUCTIONS:

    display_instructions(region, rv3d, instruct, keys_aff, keys_nav, keys_neg)

    sensor = 60
    self.mode = None
    co2d = mathutils.Vector(self.co2d)
    distmin = mathutils.Vector(co2d - c2d).length

    # Hover markers - detection
    for co in points.items():
        dist = mathutils.Vector(co2d - co[1]).length
        if dist < distmin:
            distmin = dist
            if distmin < sensor:
                self.mode = co[0]
                self.hoverco = co[1]

    # Drawing the graphical representation of scale cage, calculated from selection's bound box:
    if self.mode == None:
        bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
        bgl.glLineWidth(1.4)
    else:
        bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
        bgl.glLineWidth(1.0)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2f(*cage2d[0])
    bgl.glVertex2f(*cage2d[1])
    bgl.glVertex2f(*cage2d[2])
    bgl.glVertex2f(*cage2d[3])
    bgl.glVertex2f(*cage2d[0])
    bgl.glEnd()
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2f(*cage2d[4])
    bgl.glVertex2f(*cage2d[5])
    bgl.glVertex2f(*cage2d[6])
    bgl.glVertex2f(*cage2d[7])
    bgl.glVertex2f(*cage2d[4])
    bgl.glEnd()
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2f(*cage2d[0])
    bgl.glVertex2f(*cage2d[4])
    bgl.glEnd()
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2f(*cage2d[1])
    bgl.glVertex2f(*cage2d[5])
    bgl.glEnd()
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2f(*cage2d[2])
    bgl.glVertex2f(*cage2d[6])
    bgl.glEnd()
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2f(*cage2d[3])
    bgl.glVertex2f(*cage2d[7])
    bgl.glEnd()
    bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
    bgl.glLineWidth(1.0)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2f(*cross2d['xmin'])
    bgl.glVertex2f(*cross2d['xmax'])
    bgl.glEnd()
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2f(*cross2d['ymin'])
    bgl.glVertex2f(*cross2d['ymax'])
    bgl.glEnd()
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2f(*cross2d['zmin'])
    bgl.glVertex2f(*cross2d['zmax'])
    bgl.glEnd()
    #bgl.glDepthRange(0,0)
    bgl.glColor4f(0.35, 0.65, 1.0, 1.0)
    bgl.glPointSize(9)
    bgl.glBegin(bgl.GL_POINTS)
    for [a, b] in cross2d.values():
        bgl.glVertex2f(a, b)
    bgl.glEnd()
    bgl.glEnable(bgl.GL_POINT_SMOOTH)
    bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
    bgl.glPointSize(11)
    bgl.glBegin(bgl.GL_POINTS)
    for co in cage2d.items():
        if len(str(co[0])) == 1:
            bgl.glVertex2f(*co[1])
    bgl.glEnd()
    bgl.glDisable(bgl.GL_POINT_SMOOTH)

    markers = {}
    markers[0] = (points[0], points[10], points[40], points[0], points[30],
                  points[40], points[0], points[10], points[30])
    markers[1] = (points[1], points[10], points[15], points[1], points[12],
                  points[15], points[1], points[10], points[12])
    markers[2] = (points[2], points[12], points[26], points[2], points[23],
                  points[26], points[2], points[12], points[23])
    markers[3] = (points[3], points[30], points[37], points[3], points[23],
                  points[37], points[3], points[30], points[23])
    markers[4] = (points[4], points[45], points[47], points[4], points[40],
                  points[47], points[4], points[40], points[45])
    markers[5] = (points[5], points[45], points[56], points[5], points[15],
                  points[56], points[5], points[15], points[45])
    markers[6] = (points[6], points[26], points[67], points[6], points[56],
                  points[67], points[6], points[26], points[56])
    markers[7] = (points[7], points[37], points[67], points[7], points[47],
                  points[67], points[7], points[37], points[47])
    markers['xmin'] = (points[0], points[3], points[7], points[4], points[0])
    markers['xmax'] = (points[1], points[2], points[6], points[5], points[1])
    markers['ymin'] = (points[0], points[1], points[5], points[4], points[0])
    markers['ymax'] = (points[2], points[3], points[7], points[6], points[2])
    markers['zmin'] = (points[0], points[1], points[2], points[3], points[0])
    markers['zmax'] = (points[4], points[5], points[6], points[7], points[4])

    pivot = {}
    if self.flag_cenpivot:
        pivot[0] = c2d
        pivot[1] = c2d
        pivot[2] = c2d
        pivot[3] = c2d
        pivot[4] = c2d
        pivot[5] = c2d
        pivot[6] = c2d
        pivot[7] = c2d
        pivot['xmin'] = c2d
        pivot['xmax'] = c2d
        pivot['ymin'] = c2d
        pivot['ymax'] = c2d
        pivot['zmin'] = c2d
        pivot['zmax'] = c2d
    else:
        pivot[0] = points[6]
        pivot[1] = points[7]
        pivot[2] = points[4]
        pivot[3] = points[5]
        pivot[4] = points[2]
        pivot[5] = points[3]
        pivot[6] = points[0]
        pivot[7] = points[1]
        pivot['xmin'] = points['xmax']
        pivot['xmax'] = points['xmin']
        pivot['ymin'] = points['ymax']
        pivot['ymax'] = points['ymin']
        pivot['zmin'] = points['zmax']
        pivot['zmax'] = points['zmin']

    np_print('self.mode = ', self.mode)
    fields = False
    field_contours = False
    pivots = True
    pivot_lines = True
    if fields:
        # Hover markers - fields
        bgl.glColor4f(0.65, 0.85, 1.0, 0.35)
        for mark in markers.items():
            if mark[0] == self.mode:
                #if type(mark[0]) is not str:
                #bgl.glColor4f(1.0, 1.0, 1.0, 0.3)
                bgl.glBegin(bgl.GL_TRIANGLE_FAN)
                for x, y in mark[1]:
                    bgl.glVertex2f(x, y)
                bgl.glEnd()

    if field_contours:
        # Hover markers - contours
        bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
        bgl.glLineWidth(1.2)
        for mark in markers.items():
            if mark[0] == self.mode:
                if type(mark[0]) is not str:
                    #bgl.glColor4f(0.3, 0.6, 1.0, 0.5)
                    bgl.glColor4f(1.0, 1.0, 1.0, 0.75)
                    bgl.glLineWidth(1.0)
                bgl.glBegin(bgl.GL_LINE_STRIP)
                for x, y in mark[1]:
                    bgl.glVertex2f(x, y)
                bgl.glEnd()

    # Hover markers - pivot

    bgl.glEnable(bgl.GL_POINT_SMOOTH)

    bgl.glColor4f(*mark_col)
    bgl.glPointSize(12)
    for p in pivot.items():
        if p[0] == self.mode:
            if pivots:
                bgl.glBegin(bgl.GL_POINTS)
                #np_print(p[1])
                bgl.glVertex2f(*p[1])
                bgl.glEnd()

            if pivot_lines:
                bgl.glLineWidth(1.0)
                #bgl.glEnable(bgl.GL_LINE_STIPPLE)
                bgl.glBegin(bgl.GL_LINE_STRIP)
                bgl.glVertex2f(*points[self.mode])
                bgl.glVertex2f(*p[1])
                bgl.glEnd()
                #bgl.glDisable(bgl.GL_LINE_STIPPLE)

    if self.flag_cenpivot:
        bgl.glColor4f(1.0, 0.5, 0.0, 1.0)
        bgl.glPointSize(12)
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glVertex2f(*c2d)
        bgl.glEnd()

    bgl.glDisable(bgl.GL_POINT_SMOOTH)

    # Hover markers - points
    bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
    bgl.glPointSize(16)
    for mark in markers.items():
        if mark[0] == self.mode:
            if type(mark[0]) is not str:
                bgl.glColor4f(*mark_col)
                bgl.glEnable(bgl.GL_POINT_SMOOTH)
                bgl.glPointSize(18)
            bgl.glBegin(bgl.GL_POINTS)
            bgl.glVertex2f(*points[self.mode])
            bgl.glEnd()
            bgl.glColor4f(*mark_col)
            bgl.glPointSize(12)
            if type(mark[0]) is not str:
                bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
                bgl.glEnable(bgl.GL_POINT_SMOOTH)
                bgl.glPointSize(14)
            bgl.glBegin(bgl.GL_POINTS)
            bgl.glVertex2f(*points[self.mode])
            bgl.glEnd()
            bgl.glDisable(bgl.GL_POINT_SMOOTH)

    if self.flag_force:
        flash_size = 7
        flash = [[0, 0], [2, 2], [1, 2], [2, 4], [0, 2], [1, 2], [0, 0]]
        for co in flash:
            co[0] = round(
                (co[0] * flash_size), 0) + self.co2d[0] + flash_size * 2
            co[1] = round(
                (co[1] * flash_size), 0) + self.co2d[1] - flash_size * 2

        bgl.glColor4f(0.95, 0.95, 0.0, 1.0)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for i, co in enumerate(flash):
            if i in range(0, 3): bgl.glVertex2f(*co)
        bgl.glEnd()
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for i, co in enumerate(flash):
            if i in range(3, 6): bgl.glVertex2f(*co)
        bgl.glEnd()
        bgl.glColor4f(1.0, 0.7, 0.0, 1.0)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for co in flash:
            bgl.glVertex2f(*co)
        bgl.glEnd()

    # Restore opengl defaults
    bgl.glDisable(bgl.GL_POINTS)
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Example #37
0
def Draw_hdr_callback(self, context):

    if context.area != Hdr.view3d_area:
        return
    elif context.area.type == 'PROPERTIES' and \
            context.space_data.context != 'WORLD':
        return

    # Check if window area has changed for sticky zoom
    theHdr = Hdr.object[0]
    if Hdr.region.width < Hdr.saved_region_width:
        diff = Hdr.saved_region_width - Hdr.region.width
        if theHdr.origin.x + theHdr.width > Hdr.saved_region_width:
            if theHdr.origin.x > 0:
                theHdr.origin.x -= diff
            else:
                theHdr.width -= diff
        else:
            if Hdr.toolProps is not None:
                if Hdr.toolProps.width > Hdr.toolProps_width:
                    theHdr.origin.x -= diff
                Hdr.toolProps_width = Hdr.toolProps.width
            if theHdr.origin.x < 0:
                theHdr.origin.x += diff
    else:
        diff = Hdr.region.width - Hdr.saved_region_width
        if theHdr.width > Hdr.saved_region_width:
            theHdr.width += diff
        else:
            if Hdr.toolProps is not None:
                if Hdr.toolProps.width < Hdr.toolProps_width:
                    theHdr.origin.x += diff
                Hdr.toolProps_width = Hdr.toolProps.width
    theHdr.set_dimensions(theHdr.width)
    Hdr.saved_region_width = Hdr.region.width

    zAzim = theHdr.width / 2
    azimFac = zAzim / 180
    zElev = theHdr.height / 2
    elevFac = zElev / 90
    crossChange = True

    if not Hdr.action == 'PAN':
        x = Hdr.mouse.x
        y = Hdr.mouse.y
        if x < theHdr.origin.x or x > theHdr.origin.x + theHdr.width:
            crossChange = False
            x = 0
        else:
            testBoundary = theHdr.origin.x + theHdr.width
            if testBoundary < Hdr.region.width:
                rightBoundary = testBoundary
            else:
                rightBoundary = Hdr.region.width
            if x > rightBoundary:
                crossChange = False
                x = rightBoundary
        cX = x - zAzim - theHdr.origin.x

        if azimFac:
            newAzimuth = cX / azimFac
        else:
            newAzimuth = 0.0

        if y < theHdr.origin.y or y < 0:
            crossChange = False
            y = 0
        elif y > theHdr.origin.y + theHdr.height:
            crossChange = False
            y = theHdr.origin.y + theHdr.height
        cY = y - zElev - theHdr.origin.y

        if elevFac:
            newElevation = cY / elevFac
        else:
            newElevation = 0.0

        if newElevation == Hdr.elevation and newAzimuth == Hdr.azimuth:
            crossChange = False
        else:
            Hdr.elevation = newElevation
            Hdr.azimuth = newAzimuth
    else:
        if Hdr.grab.offset.x < Hdr.grab.spot.x:
            off = Hdr.grab.spot.x - Hdr.grab.offset.x
            theHdr.origin.x -= off
        else:
            off = Hdr.grab.offset.x - Hdr.grab.spot.x
            theHdr.origin.x += off
        if Hdr.grab.offset.y < Hdr.grab.spot.y:
            off = Hdr.grab.spot.y - Hdr.grab.offset.y
            theHdr.origin.y -= off
        else:
            off = Hdr.grab.offset.y - Hdr.grab.spot.y
            theHdr.origin.y += off
        Hdr.grab.spot.x = Hdr.mouse.x
        Hdr.grab.spot.y = Hdr.mouse.y

    Lx = theHdr.origin.x
    Ly = theHdr.origin.y

    # ---------------------
    # Draw a textured quad
    # ---------------------

    bgl.glEnable(bgl.GL_BLEND)
    if Hdr.glImage.bindcode == 0:
        Hdr.load_gl_image()
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, Hdr.glImage.bindcode)
    bgl.glEnable(bgl.GL_TEXTURE_2D)
    bgl.glColor4f(1.0, 1.0, 1.0, Hdr.object[0].opacity)
    bgl.glBegin(bgl.GL_QUADS)
    bgl.glTexCoord2f(0.0, 0.0)
    bgl.glVertex2f(Lx, Ly)
    bgl.glTexCoord2f(1.0, 0.0)
    bgl.glVertex2f(Lx + theHdr.width, Ly)
    bgl.glTexCoord2f(1.0, 1.0)
    bgl.glVertex2f(Lx + theHdr.width, Ly + theHdr.height)
    bgl.glTexCoord2f(0.0, 1.0)
    bgl.glVertex2f(Lx, theHdr.height + Ly)
    bgl.glEnd()
    bgl.glDisable(bgl.GL_TEXTURE_2D)

    # ---------------------
    # draw the crosshair
    # ---------------------
    x = theHdr.width / 2.0
    if crossChange and not Hdr.lockCrosshair:
        Sun.SP.HDR_azimuth = degToRad(newAzimuth + 180)
    azimuth = ((radToDeg(Sun.SP.HDR_azimuth) - 180) * x / 180.0) + x

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_LINES)
    bgl.glLineWidth(1.0)
    alpha = 0.8
    color = (0.4, 0.4, 0.4, alpha)
    bgl.glColor4f(color[0], color[1], color[2], color[3])
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2f(Lx + azimuth, Ly)
    bgl.glVertex2f(Lx + azimuth, Ly + theHdr.height)
    bgl.glEnd()

    y = theHdr.height / 2.0
    if crossChange and not Hdr.lockCrosshair:
        Sun.SP.HDR_elevation = newElevation
    elevation = (Sun.SP.HDR_elevation * y / 90.0) + y

    bgl.glColor4f(color[0], color[1], color[2], color[3])
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2f(Lx, Ly + elevation)
    bgl.glVertex2f(Lx + theHdr.width, Ly + elevation)
    bgl.glEnd()

    # ---------------------
    # draw the border
    # ---------------------
    bgl.glDisable(bgl.GL_BLEND)
    color = (0.6, 0.6, .6, 1.0)
    bgl.glColor4f(color[0], color[1], color[2], color[3])
    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glVertex2f(Lx, Ly)
    bgl.glVertex2f(Lx + theHdr.width, Ly)
    bgl.glVertex2f(Lx + theHdr.width, Ly + theHdr.height)
    bgl.glVertex2f(Lx, theHdr.height + Ly)
    bgl.glVertex2f(Lx, Ly)
    bgl.glEnd()

    bgl.glLineWidth(1.0)
    bgl.glDisable(bgl.GL_LINES)
    bgl.glFlush()
Example #38
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
    link = sc.screencast_keys_link

    pos_x, pos_y = getDisplayLocation(context)
    if link == True:
        offset_x = pos_x
    else:
        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 = sc.screencast_keys_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] = [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)
        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 = [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 #39
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])
def draw_callback_px(self, context):
    font_id = 0  # XXX, need to find out how best to get this.
    screenPointsMomentum = []
    screenPointsImpulses = []
    screenPointsCOM = []
    screenPointsAngularMomentum = []
    screenPointsFreefallPath = []
    for i in range(0, len(context.scene.momentum_trail.centerOfMasses)):
        centerOfMassPath = context.scene.momentum_trail.centerOfMasses[i]
        momentumVectorsForObj = context.scene.momentum_trail.momentumVectors[i]
        momentumImpulsesForObj = context.scene.momentum_trail.momentumImpulses[
            i]
        angularMomentumsForObj = context.scene.momentum_trail.angularMomentum[
            i]

        #create set of lines for momentum vectors
        for j in range(0, len(centerOfMassPath)):
            com = centerOfMassPath[j]
            moVecEnd = com + (
                momentumVectorsForObj[j] *
                context.scene.momentum_trail.momentum_vector_scale)
            comPoint = world_to_screen(context, com)
            screenPointsCOM.append(comPoint)
            screenPointsMomentum.append(comPoint)
            screenPointsMomentum.append(world_to_screen(context, moVecEnd))

        #create set of lines for impulses
        for j in range(0, len(momentumImpulsesForObj)):
            com = centerOfMassPath[j]
            impulseVecEnd = com + (
                momentumImpulsesForObj[j] *
                context.scene.momentum_trail.momentum_vector_scale)
            screenPointsImpulses.append(world_to_screen(context, com))
            screenPointsImpulses.append(world_to_screen(
                context, impulseVecEnd))

        #create set of lines for angular momentum
        for j in range(0, len(centerOfMassPath)):
            com = centerOfMassPath[j]
            moVecEnd = com + (
                angularMomentumsForObj[j] *
                context.scene.momentum_trail.momentum_vector_scale)
            screenPointsAngularMomentum.append(world_to_screen(context, com))
            screenPointsAngularMomentum.append(
                world_to_screen(context, moVecEnd))

    bgl.glEnable(bgl.GL_BLEND)

    #draw center of masses
    if context.scene.momentum_trail.showCOM:
        bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
        bgl.glPointSize(4)
        bgl.glBegin(bgl.GL_POINTS)
        for x, y in screenPointsCOM:
            bgl.glVertex2i(int(x), int(y))
        bgl.glEnd()

    #draw momentum vectors
    if context.scene.momentum_trail.showMomentum:
        bgl.glColor4f(1.0, 0.0, 0.0, 0.5)
        bgl.glLineWidth(2)
        bgl.glBegin(bgl.GL_LINES)
        for x, y in screenPointsMomentum:
            bgl.glVertex2i(int(x), int(y))
        bgl.glEnd()

    #draw impulse vectors
    if context.scene.momentum_trail.showImpulse:
        bgl.glColor4f(1.0, 1.0, 0.0, 0.5)
        bgl.glBegin(bgl.GL_LINES)
        for x, y in screenPointsImpulses:
            bgl.glVertex2i(int(x), int(y))
        bgl.glEnd()

    #mark current frame with a brighter dot
    if hasattr(context.scene.momentum_trail, "frameNums"):
        if len(context.scene.momentum_trail.frameNums) > 0:
            if context.scene.frame_current >= context.scene.momentum_trail.frameNums[
                    0][0] and context.scene.frame_current <= context.scene.momentum_trail.frameNums[
                        0][-1]:
                idx = context.scene.frame_current - context.scene.momentum_trail.frameNums[
                    0][0]
                bgl.glPointSize(6)
                bgl.glColor4f(1.0, .8, .8, 0.8)
                bgl.glBegin(bgl.GL_POINTS)
                bgl.glVertex2i(int(screenPointsCOM[idx][0]),
                               int(screenPointsCOM[idx][1]))
                bgl.glEnd()

    if context.scene.momentum_trail.showAngularMomentum:
        bgl.glColor4f(0.0, 1.0, 0.0, 0.5)
        bgl.glBegin(bgl.GL_LINES)
        for x, y in screenPointsAngularMomentum:
            bgl.glVertex2i(int(x), int(y))
        bgl.glEnd()

    if context.scene.momentum_trail.showFreefallPath:
        print("doing freefall path")

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Example #41
0
def Draw_map_callback(self, context):

    if context.area != Map.view3d_area:
        return
    elif context.area.type == 'PROPERTIES' and \
        context.space_data.context != 'WORLD':
        return

    # Check if window area has changed for sticky zoom
    theMap = Map.object[0]
    if Map.region.width < Map.saved_region_width:
        diff = Map.saved_region_width - Map.region.width
        if theMap.origin.x + theMap.width > Map.saved_region_width:
            if theMap.origin.x > 0:
                theMap.origin.x -= diff
            else:
                theMap.width -= diff
        else:
            if Map.toolProps is not None:
                if Map.toolProps.width > Map.toolProps_width:
                    theMap.origin.x -= diff
                Map.toolProps_width = Map.toolProps.width
            if theMap.origin.x < 0:
                theMap.origin.x += diff
    else:
        diff = Map.region.width - Map.saved_region_width
        if theMap.width > Map.saved_region_width:
            theMap.width += diff
        else:
            if Map.toolProps is not None:
                if Map.toolProps.width < Map.toolProps_width:
                    theMap.origin.x += diff
                Map.toolProps_width = Map.toolProps.width
    theMap.set_dimensions(theMap.width)
    Map.saved_region_width = Map.region.width

    # Latitude and longitude are set to an equidistant
    # cylindrical projection with lat/long 0/0 exactly
    # in the middle of the image.

    zLong = theMap.width / 2
    longFac = zLong / 180
    zLat = theMap.height / 2
    latFac = zLat / 90
    crossChange = True

    if not Map.action == 'PAN':
        x = Map.mouse.x
        y = Map.mouse.y
        if x < theMap.origin.x or x > theMap.origin.x + theMap.width:
            crossChange = False
            x = 0
        else:
            testBoundary = theMap.origin.x + theMap.width
            if testBoundary < Map.region.width:
                rightBoundary = testBoundary
            else:
                rightBoundary = Map.region.width
            if x > rightBoundary:
                crossChange = False
                x = rightBoundary
        cX = x - zLong - theMap.origin.x

        if longFac:
            newLongitude = cX / longFac
        else:
            newLongitude = 0.0

        if y < theMap.origin.y or y < 0:
            crossChange = False
            y = 0
        elif y > theMap.origin.y + theMap.height:
            crossChange = False
            y = theMap.origin.y + theMap.height
        cY = y - zLat - theMap.origin.y

        if latFac:
            newLatitude = cY / latFac
        else:
            newLatitude = 0.0

        if newLatitude == Map.latitude and newLongitude == Map.longitude:
            crossChange = False
        else:
            Map.latitude = newLatitude
            Map.longitude = newLongitude
    else:
        if Map.grab.offset.x < Map.grab.spot.x:
            off = Map.grab.spot.x - Map.grab.offset.x
            theMap.origin.x -= off
        else:
            off = Map.grab.offset.x - Map.grab.spot.x
            theMap.origin.x += off
        if Map.grab.offset.y < Map.grab.spot.y:
            off = Map.grab.spot.y - Map.grab.offset.y
            theMap.origin.y -= off
        else:
            off = Map.grab.offset.y - Map.grab.spot.y
            theMap.origin.y += off
        Map.grab.spot.x = Map.mouse.x
        Map.grab.spot.y = Map.mouse.y

    Lx = theMap.origin.x
    Ly = theMap.origin.y

    # ---------------------
    # Draw a textured quad
    # ---------------------

    if not Map.textureless:
        bgl.glEnable(bgl.GL_BLEND)
        if Map.glImage.bindcode == 0:
            Map.load_gl_image()
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, Map.glImage.bindcode)
        bgl.glEnable(bgl.GL_TEXTURE_2D)
        bgl.glColor4f(1.0, 1.0, 1.0, Map.object[0].opacity)
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glTexCoord2f(0.0, 0.0)
        bgl.glVertex2f(Lx, Ly)
        bgl.glTexCoord2f(1.0, 0.0)
        bgl.glVertex2f(Lx + theMap.width, Ly)
        bgl.glTexCoord2f(1.0, 1.0)
        bgl.glVertex2f(Lx + theMap.width, Ly + theMap.height)
        bgl.glTexCoord2f(0.0, 1.0)
        bgl.glVertex2f(Lx, theMap.height + Ly)
        bgl.glEnd()
        bgl.glDisable(bgl.GL_TEXTURE_2D)

    # -----------------------
    # Output text for stats
    # -----------------------
    if Map.action == 'TIME' or Map.action == 'DAY' or Map.showInfo:
        Map.show_text_in_viewport(Map.object[1])

    # ---------------------
    # draw the crosshair
    # ---------------------
    x = theMap.width / 2.0
    if crossChange and not Map.lockCrosshair:
        if Map.action != 'Y':
            Sun.SP.Longitude = newLongitude
    longitude = (Sun.SP.Longitude * x / 180.0) + x

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_LINES)
    bgl.glLineWidth(1.0)
    alpha = 1.0 if Map.action == 'Y' else 0.5
    color = (0.894, 0.741, .510, alpha)
    bgl.glColor4f(color[0], color[1], color[2], color[3])
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2f(Lx + longitude, Ly)
    bgl.glVertex2f(Lx + longitude, Ly + theMap.height)
    bgl.glEnd()

    y = theMap.height / 2.0
    if crossChange and not Map.lockCrosshair:
        if Map.action != 'X':
            Sun.SP.Latitude = newLatitude
    latitude = (Sun.SP.Latitude * y / 90.0) + y

    alpha = 1.0 if Map.action == 'X' else 0.5
    color = (0.894, 0.741, .510, alpha)
    bgl.glColor4f(color[0], color[1], color[2], color[3])
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2f(Lx, Ly + latitude)
    bgl.glVertex2f(Lx + theMap.width, Ly + latitude)
    bgl.glEnd()

    # ---------------------
    # draw the border
    # ---------------------
    bgl.glDisable(bgl.GL_BLEND)
    color = (0.6, 0.6, .6, 1.0)
    bgl.glColor4f(color[0], color[1], color[2], color[3])
    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glVertex2f(Lx, Ly)
    bgl.glVertex2f(Lx + theMap.width, Ly)
    bgl.glVertex2f(Lx + theMap.width, Ly + theMap.height)
    bgl.glVertex2f(Lx, theMap.height + Ly)
    bgl.glVertex2f(Lx, Ly)
    bgl.glEnd()

    if not Sun.ShowRiseSet or not Map.lineWidth:
        bgl.glDisable(bgl.GL_LINES)
        bgl.glFlush()
        return

    if Map.action == 'G':
        draw_text_region()

    # ------------------------
    # draw the sunrise, sunset
    # ------------------------

    def draw_angled_line(color, angle, bx, by):
        x = math.cos(angle) * radius
        y = math.sin(angle) * radius
        bgl.glColor4f(color[0], color[1], color[2], color[3])
        bgl.glBegin(bgl.GL_LINES)
        bgl.glVertex2f(bx, by)
        bgl.glVertex2f(bx + x, by + y)
        bgl.glEnd()

    px = Lx + longitude
    py = Ly + latitude

    radius = 30 + Map.lineWidth * 10
    if Sun.RiseSetOK and Map.lineWidth:
        color = (0.2, 0.6, 1.0, 0.9)
        angle = -(degToRad(Sun.Sunrise.azimuth) - math.pi / 2)
        bgl.glLineWidth(Map.lineWidth)
        draw_angled_line(color, angle, px, py)

        color = (0.86, 0.18, 0.18, 0.9)
        angle = -(degToRad(Sun.Sunset.azimuth) - math.pi / 2)
        draw_angled_line(color, angle, px, py)

    # ------------------------
    # draw current time line
    # ------------------------

    if Map.textureless:
        phi = degToRad(Sun.AzNorth) * -1
    else:
        phi = degToRad(Sun.Azimuth) * -1
    x = math.sin(phi) * math.sin(-Sun.Theta) * (radius + 10)
    y = math.sin(Sun.Theta) * math.cos(phi) * (radius + 10)
    night = (0.24, 0.29, 0.94, 0.9)
    day = (0.85, 0.77, 0.60, 0.9)
    if Sun.SolarNoon.elevation < 0.0:
        color = night
    elif Sun.Elevation >= Sun.Sunrise.elevation:
        if Sun.Time >= Sun.Sunset.time and \
            Sun.Elevation <= Sun.Sunset.elevation:
            color = night
        else:
            color = day
    else:
        color = night
    bgl.glLineWidth(Map.lineWidth + 1.0)

    bgl.glColor4f(color[0], color[1], color[2], color[3])
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2f(px, py)
    bgl.glVertex2f(px + x, py + y)
    bgl.glEnd()
    bgl.glLineWidth(1.0)
    bgl.glDisable(bgl.GL_LINES)
    bgl.glFlush()
Example #42
0
def draw_callback_px_box(self, context):
    wm = context.window_manager
    sc = context.scene

    if not wm.screencast_keys_keys:
        return

    font_size = sc.screencast_keys_font_size
    mouse_size = sc.screencast_keys_mouse_size

    if sc.screencast_keys_mouse_position == 'right':
        mouse_size = 25

    box_draw = sc.screencast_keys_box_draw
    pos_x, pos_y = getDisplayLocation(context)

    # get text-width/height to resize the box
    blf.size(0, sc.screencast_keys_font_size, 72)
    box_width, box_height = sc.screencast_keys_box_width, 0
    final = 0
    row_count = 0
    box_hide = sc.screencast_keys_box_hide
    label_time_max = sc.screencast_keys_fade_time

    for i in range(len(self.key)):
        label_time = time.time() - self.time[i]

        if label_time < label_time_max:  # only display key-presses of last 4 seconds
            box_width, box_height = getBoundingBox(box_width, box_height,
                                                   self.key[i])
            row_count += 1
            final = i + 1
            box_hide = False
        else:
            break

    # Got the size right, now draw box using proper colors
    box_color_r, box_color_g, box_color_b, box_color_alpha = sc.screencast_keys_box_color

    if box_draw and not box_hide:
        padding_x = 16
        padding_y = 12
        x0 = max(0, pos_x - padding_x)
        y0 = max(0, pos_y - padding_y)
        x1 = pos_x + box_width + mouse_size * MOUSE_RATIO * 1.3 + padding_x
        y1 = pos_y + max(mouse_size, font_size * row_count) + padding_y
        positions = [[x0, y0], [x0, y1], [x1, y1], [x1, y0]]
        settings = [[bgl.GL_QUADS, min(0.0, box_color_alpha)],
                    [bgl.GL_LINE_LOOP,
                     min(0.0, box_color_alpha)]]

        for mode, box_alpha in settings:
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glBegin(mode)
            bgl.glColor4f(box_color_r, box_color_g, box_color_b,
                          box_color_alpha)
            for v1, v2 in positions:
                bgl.glVertex2f(v1, v2)
            bgl.glEnd()

    if sc.screencast_keys_show_operator:
        draw_last_operator(context, pos_x, pos_y)

    if sc.screencast_keys_timer_show:
        draw_timer(context, pos_x, pos_y)

    # get rid of status texts that aren't displayed anymore
    self.key = self.key[:final]
    self.time = self.time[:final]
Example #43
0
def draw_callback_px(self, context):
    wm = context.window_manager
    sc = context.scene
    if not wm.screencast_keys_keys:
        return

    font_size = sc.screencast_keys_font_size
    mouse_size = sc.screencast_keys_mouse_size
    link = sc.screencast_keys_link
    pos_x, pos_y = getDisplayLocation(context)

    # draw text in the 3d-view
    # ========================
    blf.size(0, sc.screencast_keys_font_size, 72)
    r, g, b = sc.screencast_keys_color
    final = 0
    row_count = len(self.key)

    keypos_x = pos_x
    if link == True:
        keypos_x += mouse_size * MOUSE_RATIO * 1.3
    shift = 0
    if mouse_size > font_size * row_count:
        shift = (mouse_size - font_size * row_count) / 2

    text_width, text_height = 0, 0
    row_count = 0
    alpha = 1.0
    for i in range(len(self.key)):
        label_time = time.time() - self.time[i]
        if label_time < 2:  # only display key-presses of last 2 seconds

            keypos_y = pos_y + shift + font_size * (i + 0.1)

            blf.position(0, keypos_x, keypos_y, 0)
            alpha = min(1.0, max(0.0, 2 * (2 - label_time)))
            bgl.glColor4f(r, g, b, alpha)
            blf.draw(0, self.key[i])
            text_width, text_height = getBoundingBox(text_width, text_height,
                                                     self.key[i])
            row_count += 1
            final = i
        else:
            break

    # get rid of status texts that aren't displayed anymore
    self.key = self.key[:final + 1]
    self.time = self.time[:final + 1]

    # draw graphical representation of the mouse
    # ==========================================
    if sc.screencast_keys_mouse == 'icon':
        for shape in ["mouse", "left_button", "middle_button", "right_button"]:
            draw_mouse(context, shape, "outline", 0.5)
        final = 0

        for i in range(len(self.mouse)):
            click_time = time.time() - self.mouse_time[i]
            if click_time < 2:
                shape = map_mouse_event(self.mouse[i])
                if shape:
                    alpha = min(1.0, max(0.0, 2 * (2 - click_time)))
                    draw_mouse(context, shape, "filled", alpha)
                final = i
            else:
                break

    # get rid of mouse clicks that aren't displayed anymore
    self.mouse = self.mouse[:final + 1]
    self.mouse_time = self.mouse_time[:final + 1]

    # Draw border (if enabled)
    # ========================
    if link == True and row_count > 0:
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glLineWidth(2)
        bgl.glColor4f(r, g, b, 0.2)
        drawRectangle(pos_x, pos_y,
                      text_width + mouse_size * MOUSE_RATIO * 1.3,
                      max(mouse_size, font_size * row_count), 4)
        bgl.glEnd()
        bgl.glBegin(bgl.GL_LINES)
        bgl.glColor4f(r, g, b, alpha)
        drawRectangle(pos_x, pos_y,
                      text_width + mouse_size * MOUSE_RATIO * 1.3,
                      max(mouse_size, font_size * row_count), 4)
        bgl.glEnd()
Example #44
0
    def draw_2D(self, context):
        settings = common_utilities.get_settings()
        region, r3d = context.region, context.space_data.region_3d
        mx = self.mx
        mxnorm = matrix_normal(mx)

        color_inactive = settings.theme_colors_mesh[settings.theme]
        color_selection = settings.theme_colors_selection[settings.theme]
        color_active = settings.theme_colors_active[settings.theme]

        color_frozen = settings.theme_colors_frozen[settings.theme]
        color_warning = settings.theme_colors_warning[settings.theme]

        bgl.glEnable(bgl.GL_POINT_SMOOTH)

        color_handle = (color_inactive[0], color_inactive[1],
                        color_inactive[2], 1.00)
        color_border = (color_inactive[0], color_inactive[1],
                        color_inactive[2], 1.00)
        color_fill = (color_inactive[0], color_inactive[1], color_inactive[2],
                      0.20)

        if self.fsm_mode == 'sketch' and self.sketch:
            # Draw smoothing line (end of sketch to current mouse position)
            common_drawing_px.draw_polyline_from_points(
                context, [self.sketch_curpos, self.sketch[-1][0]],
                color_active, 1, "GL_LINE_SMOOTH")

            # Draw sketching stroke
            common_drawing_px.draw_polyline_from_points(
                context, [co[0] for co in self.sketch], color_selection, 2,
                "GL_LINE_STIPPLE")

        if self.fsm_mode in {'scale tool', 'rotate tool'}:
            # Draw a scale/rotate line from tool origin to current mouse position
            common_drawing_px.draw_polyline_from_points(
                context, [self.action_center, self.mode_pos], (0, 0, 0, 0.5),
                1, "GL_LINE_STIPPLE")

        bgl.glLineWidth(1)

        if self.fsm_mode == 'brush scale tool':
            # scaling brush size
            self.sketch_brush.draw(context,
                                   color=(1, 1, 1, .5),
                                   linewidth=1,
                                   color_size=(1, 1, 1, 1))
        elif self.fsm_mode not in {'grab tool', 'scale tool', 'rotate tool'
                                   } and not self.is_navigating:
            # draw the brush oriented to surface
            ray, hit = common_utilities.ray_cast_region2d_bvh(
                region, r3d, self.cur_pos, mesh_cache['bvh'], self.mx,
                settings)
            hit_p3d, hit_norm, hit_idx = hit
            if hit_idx != None:  # and not self.hover_ed:
                #hit_p3d = mx * hit_p3d
                #hit_norm = mxnorm * hit_norm
                common_drawing_px.draw_circle(context, hit_p3d,
                                              hit_norm.normalized(),
                                              self.stroke_radius,
                                              (1, 1, 1, .5))

            if self.fsm_mode == 'sketch' and self.sketch:
                ray, hit = common_utilities.ray_cast_region2d_bvh(
                    region, r3d, self.sketch[0][0], mesh_cache['bvh'], self.mx,
                    settings)
                hit_p3d, hit_norm, hit_idx = hit
                if hit_idx != None:
                    #hit_p3d = mx * hit_p3d
                    #hit_norm = mxnorm * hit_norm
                    common_drawing_px.draw_circle(context, hit_p3d,
                                                  hit_norm.normalized(),
                                                  self.stroke_radius,
                                                  (1, 1, 1, .5))

        if self.hover_ed and False:  #EXTEND  to display hoverable edges
            color = (color_selection[0], color_selection[1],
                     color_selection[2], 1.00)
            common_drawing_px.draw_bmedge(context, self.hover_ed,
                                          self.dest_obj.matrix_world, 2, color)

        if self.act_gedge:
            if settings.show_segment_count:
                bgl.glColor4f(*color_active)
                self.draw_gedge_info(self.act_gedge, context)

        if self.act_gpatch:
            if settings.show_segment_count:
                bgl.glColor4f(*color_active)
                self.draw_gpatch_info(self.act_gpatch, context)

        if True:
            txt = 'v:%d e:%d s:%d p:%d' % (len(
                self.polystrips.gverts), len(
                    self.polystrips.gedges), len(self.polystrips.gedgeseries),
                                           len(self.polystrips.gpatches))
            txt_width, txt_height = blf.dimensions(0, txt)

            bgl.glEnable(bgl.GL_BLEND)

            bgl.glColor4f(0, 0, 0, 0.8)
            bgl.glBegin(bgl.GL_QUADS)
            bgl.glVertex2f(0, 0)
            bgl.glVertex2f(10 + txt_width, 0)
            bgl.glVertex2f(10 + txt_width, 10 + txt_height)
            bgl.glVertex2f(0, 10 + txt_height)
            bgl.glEnd()

            bgl.glColor4f(1, 1, 1, 1)
            blf.position(0, 5, 5, 0)
            blf.draw(0, txt)
Example #45
0
def draw_callback_px(self, context):

    font_id = 0
    alpha = context.scene.pt_custom_props.a
    font_size = context.scene.pt_custom_props.fs

    bgl.glColor4f(0.0, 0.6, 1.0, alpha)
    bgl.glPointSize(4.0)
    bgl.glBegin(bgl.GL_POINTS)
    bgl.glVertex2f(pt_buf.x, pt_buf.y)
    bgl.glEnd()
    bgl.glDisable(bgl.GL_BLEND)

    # -- -- -- -- location 3d
    if context.scene.pt_custom_props.b2 == True:
        mloc3d = region_2d_to_location_3d(context.region, context.space_data.region_3d, Vector((pt_buf.x, pt_buf.y)), pt_buf.depth_location)
        blf.position(font_id, pt_buf.x + 15, pt_buf.y - 15, 0)
        blf.size(font_id, font_size, context.user_preferences.system.dpi)
        blf.draw(font_id, '(' + str(round(mloc3d[0], 4)) + ', ' + str(round(mloc3d[1], 4)) + ', ' + str(round(mloc3d[2], 4)) + ')')

    n = len(pt_buf.list_m_loc_3d)
    if n != 0:

        # -- -- -- -- add points
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glPointSize(4.0)
        bgl.glBegin(bgl.GL_POINTS)
        for i in pt_buf.list_m_loc_3d:
            loc_0 = location_3d_to_region_2d(context.region, context.space_data.region_3d, i)
            bgl.glVertex2f(loc_0[0], loc_0[1])
        bgl.glEnd()
        bgl.glDisable(bgl.GL_BLEND)

        # -- -- -- -- text next to the mouse
        m_loc_3d = region_2d_to_location_3d(context.region, context.space_data.region_3d, Vector((pt_buf.x, pt_buf.y)), pt_buf.depth_location)
        vec0 = pt_buf.list_m_loc_3d[-1] - m_loc_3d
        blf.position(font_id, pt_buf.x + 15, pt_buf.y + 15, 0)
        blf.size(font_id, font_size, context.user_preferences.system.dpi)
        blf.draw(font_id, str(round(vec0.length, 4)))

        # -- -- -- -- angle first after mouse
        if n >= 2:
            vec1 = pt_buf.list_m_loc_3d[-2] - pt_buf.list_m_loc_3d[-1]
            if vec0.length == 0.0 or vec1.length == 0.0:
                pass
            else:
                ang = vec0.angle(vec1)

                if round(degrees(ang), 2) == 180.0:
                    text_0 = '0.0'
                elif round(degrees(ang), 2) == 0.0:
                    text_0 = '180.0'
                else:
                    text_0 = str(round(degrees(ang), 2))

                loc_4 = location_3d_to_region_2d(context.region, context.space_data.region_3d, pt_buf.list_m_loc_3d[-1])
                bgl.glColor4f(0.0, 1.0, 0.525, alpha)
                blf.position(font_id, loc_4[0] + 10, loc_4[1] + 10, 0)
                blf.size(font_id, font_size, context.user_preferences.system.dpi)
                blf.draw(font_id, text_0 + '')

        bgl.glLineStipple(4, 0x5555)
        bgl.glEnable(bgl.GL_LINE_STIPPLE)      # enable line stipple

        bgl.glColor4f(0.0, 0.6, 1.0, alpha)
        # -- -- -- -- draw line between last point and mouse
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBegin(bgl.GL_LINES)
        loc_1 = location_3d_to_region_2d(context.region, context.space_data.region_3d, pt_buf.list_m_loc_3d[-1])
        bgl.glVertex2f(loc_1[0], loc_1[1])
        bgl.glVertex2f(pt_buf.x, pt_buf.y)
        bgl.glEnd()
        bgl.glDisable(bgl.GL_BLEND)

        # -- -- -- -- draw lines between points
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for j in pt_buf.list_m_loc_3d:
            loc_2 = location_3d_to_region_2d(context.region, context.space_data.region_3d, j)
            bgl.glVertex2f(loc_2[0], loc_2[1])
        bgl.glEnd()
        bgl.glDisable(bgl.GL_BLEND)

        bgl.glDisable(bgl.GL_LINE_STIPPLE)      # disable line stipple

        # -- -- -- -- draw line length between points
        if context.scene.pt_custom_props.b1 == True:
            for k in range(n - 1):
                loc_3 = location_3d_to_region_2d(context.region, context.space_data.region_3d, (pt_buf.list_m_loc_3d[k] + pt_buf.list_m_loc_3d[(k + 1) % n]) * 0.5)
                blf.position(font_id, loc_3[0] + 10, loc_3[1] + 10, 0)
                blf.size(font_id, font_size, context.user_preferences.system.dpi)
                blf.draw(font_id, str(round((pt_buf.list_m_loc_3d[k] - pt_buf.list_m_loc_3d[(k + 1) % n]).length, 4)))

        # -- -- -- -- draw all angles
        if context.scene.pt_custom_props.b0 == True:
            for h in range(n - 1):
                if n >= 2:
                    if h == 0:
                        pass
                    else:
                        vec_ = pt_buf.list_m_loc_3d[h] - pt_buf.list_m_loc_3d[(h - 1) % n]
                        if vec_.length == 0.0:
                            pass
                        else:
                            ang = vec_.angle(pt_buf.list_m_loc_3d[h] - pt_buf.list_m_loc_3d[(h + 1) % n])
                            if round(degrees(ang)) == 0.0:
                                pass
                            else:
                                loc_4 = location_3d_to_region_2d(context.region, context.space_data.region_3d, pt_buf.list_m_loc_3d[h])
                                bgl.glColor4f(0.0, 1.0, 0.525, alpha)
                                blf.position(font_id, loc_4[0] + 10, loc_4[1] + 10, 0)
                                blf.size(font_id, font_size, context.user_preferences.system.dpi)
                                blf.draw(font_id, str(round(degrees(ang), 2)) + '')

    # -- -- -- -- tool on / off
    bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
    blf.position(font_id, 150, 10, 0)
    blf.size(font_id, 20, context.user_preferences.system.dpi)
    blf.draw(font_id, 'Draw On')
Example #46
0
def display_cursor_badge(co2d, symbol, badge_mode, message_main, message_aux,
                         aux_num, aux_str):

    display_badge = addon_settings_graph('display_badge')
    size_badge = addon_settings_graph('size_badge')
    col_bg_fill_main_run = addon_settings_graph('col_bg_fill_main_run')
    col_bg_fill_main_nav = addon_settings_graph('col_bg_fill_main_nav')
    col_bg_fill_aux = addon_settings_graph('col_bg_fill_aux')
    col_bg_fill_square = addon_settings_graph('col_bg_fill_square')
    col_bg_line_symbol = addon_settings_graph('col_bg_line_symbol')
    col_bg_font_main = addon_settings_graph('col_bg_font_main')
    col_bg_font_aux = addon_settings_graph('col_bg_font_aux')

    if badge_mode == 'RUN':
        col_bg_fill_main = col_bg_fill_main_run
    elif badge_mode == 'NAV':
        col_bg_fill_main = col_bg_fill_main_nav

    if display_badge:
        font_id = 0
        square = [[17, 30], [17, 40], [27, 40], [27, 30]]
        rectangle = [[27, 30], [27, 40], [67, 40], [67, 30]]
        ipx = 29
        ipy = 33
        for co in square:
            co[0] = round(
                (co[0] * size_badge), 0) - (size_badge * 10) + co2d[0]
            co[1] = round(
                (co[1] * size_badge), 0) - (size_badge * 25) + co2d[1]
        for co in rectangle:
            co[0] = round(
                (co[0] * size_badge), 0) - (size_badge * 10) + co2d[0]
            co[1] = round(
                (co[1] * size_badge), 0) - (size_badge * 25) + co2d[1]
        for co in symbol:
            co[0] = round(
                (co[0] * size_badge), 0) - (size_badge * 10) + co2d[0]
            co[1] = round(
                (co[1] * size_badge), 0) - (size_badge * 25) + co2d[1]

        ipx = round((ipx * size_badge), 0) - (size_badge * 10) + co2d[0]
        ipy = round((ipy * size_badge), 0) - (size_badge * 25) + co2d[1]
        ipsize = int(round((6 * size_badge), 0))

        bgl.glEnable(bgl.GL_BLEND)

        bgl.glColor4f(*col_bg_fill_square)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for x, y in square:
            bgl.glVertex2f(x, y)
        bgl.glEnd()

        bgl.glColor4f(*col_bg_fill_main)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for x, y in rectangle:
            bgl.glVertex2f(x, y)
        bgl.glEnd()

        bgl.glColor4f(*col_bg_line_symbol)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x, y in symbol:
            bgl.glVertex2f(x, y)
        bgl.glEnd()

        bgl.glColor4f(*col_bg_font_main)
        blf.position(font_id, ipx, ipy, 0)
        blf.size(font_id, ipsize, 72)
        blf.draw(font_id, message_main)

        if message_aux != None:

            bgl.glColor4f(*col_bg_fill_aux)
            bgl.glBegin(bgl.GL_TRIANGLE_FAN)
            if aux_num == None and aux_str == None:
                rectangle = [[17, 30], [17, 40], [67, 40], [67, 30]]
                for co in rectangle:
                    co[0] = round(
                        (co[0] * size_badge), 0) - (size_badge * 10) + co2d[0]
                    co[1] = round(
                        (co[1] * size_badge), 0) - (size_badge * 25) + co2d[1]
            for x, y in rectangle:
                if aux_num == None and aux_str == None:
                    bgl.glVertex2f(x, (y - (size_badge * 10)))
                    np_print('111111111111')
                elif aux_num != None:
                    bgl.glVertex2f(x, y - (size_badge * 35))
                    np_print('222222222222')
                elif aux_str != None:
                    bgl.glVertex2f(x, y - (size_badge * 25))
                    np_print('3333333333333')
            bgl.glEnd()

            bgl.glColor4f(*col_bg_font_aux)
            if aux_num == None and aux_str == None:
                blf.position(font_id, ipx, ipy - (size_badge * 10), 0)
            elif aux_num != None:
                blf.position(font_id, ipx, ipy - (size_badge * 35), 0)
            elif aux_str != None:
                blf.position(font_id, ipx, ipy - (size_badge * 25), 0)
            blf.size(font_id, ipsize, 72)
            blf.draw(font_id, message_aux)

        if aux_num != None:
            bgl.glColor4f(*col_bg_font_aux)
            blf.position(font_id, ipx, int(ipy - size_badge * 25), 0)
            blf.size(font_id, int(size_badge * 24), 72)
            blf.draw(font_id, aux_num)

        if aux_str != None:
            bgl.glColor4f(*col_bg_font_aux)
            blf.position(font_id, ipx, int(ipy - size_badge * 15), 0)
            blf.size(font_id, ipsize, 72)
            blf.draw(font_id, aux_num)
        '''
        if step == 'continuous':
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for x, y in dots1:
                bgl.glVertex2f(x, y)
            bgl.glEnd()
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for x, y in dots2:
                bgl.glVertex2f(x, y)
            bgl.glEnd()
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for x, y in dots3:
                bgl.glVertex2f(x, y)
            bgl.glEnd()
        '''
        bgl.glDisable(bgl.GL_BLEND)
Example #47
0
def render_opengl(self, context):
    from math import ceil

    layers = []
    scene = context.scene
    for x in range(0, 20):
        if scene.layers[x] is True:
            layers.extend([x])

    objlist = context.scene.objects
    render_scale = scene.render.resolution_percentage / 100

    width = int(scene.render.resolution_x * render_scale)
    height = int(scene.render.resolution_y * render_scale)

    # I cant use file_format becuase the pdf writer needs jpg format
    # the file_format returns 'JPEG' not 'JPG'
    #     file_format = context.scene.render.image_settings.file_format.lower()
    ren_path = bpy.path.abspath(bpy.context.scene.render.filepath) + ".jpg"

    #     if len(ren_path) > 0:
    #         if ren_path.endswith(os.path.sep):
    #             initpath = os.path.realpath(ren_path) + os.path.sep
    #         else:
    #             (initpath, filename) = os.path.split(ren_path)
    #         outpath = os.path.join(initpath, "ogl_tmp.png")
    #     else:
    #         self.report({'ERROR'}, "Invalid render path")
    #         return False

    img = get_render_image(ren_path)

    if img is None:
        self.report({'ERROR'}, "Invalid render path:" + ren_path)
        return False

    tile_x = 240
    tile_y = 216
    row_num = ceil(height / tile_y)
    col_num = ceil(width / tile_x)

    cut4 = (col_num * tile_x * 4) - width * 4
    totpixel4 = width * height * 4

    viewport_info = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, viewport_info)

    img.gl_load(0, bgl.GL_NEAREST, bgl.GL_NEAREST)

    # 2.77 API change
    if bpy.app.version >= (2, 77, 0):
        tex = img.bindcode[0]
    else:
        tex = img.bindcode

    if context.scene.name in bpy.data.images:
        old_img = bpy.data.images[context.scene.name]
        old_img.user_clear()
        bpy.data.images.remove(old_img)

    img_result = bpy.data.images.new(context.scene.name, width, height)

    tmp_pixels = [1] * totpixel4

    #---------- Loop for all tiles
    for row in range(0, row_num):
        for col in range(0, col_num):
            buffer = bgl.Buffer(bgl.GL_FLOAT, width * height * 4)
            bgl.glDisable(
                bgl.GL_SCISSOR_TEST
            )  # if remove this line, get blender screenshot not image
            bgl.glViewport(0, 0, tile_x, tile_y)

            bgl.glMatrixMode(bgl.GL_PROJECTION)
            bgl.glLoadIdentity()

            # defines ortographic view for single tile
            x1 = tile_x * col
            y1 = tile_y * row
            bgl.gluOrtho2D(x1, x1 + tile_x, y1, y1 + tile_y)

            # Clear
            bgl.glClearColor(0.0, 0.0, 0.0, 0.0)
            bgl.glClear(bgl.GL_COLOR_BUFFER_BIT | bgl.GL_DEPTH_BUFFER_BIT)

            bgl.glEnable(bgl.GL_TEXTURE_2D)
            bgl.glBindTexture(bgl.GL_TEXTURE_2D, tex)

            # defines drawing area
            bgl.glBegin(bgl.GL_QUADS)

            bgl.glColor3f(1.0, 1.0, 1.0)
            bgl.glTexCoord2f(0.0, 0.0)
            bgl.glVertex2f(0.0, 0.0)

            bgl.glTexCoord2f(1.0, 0.0)
            bgl.glVertex2f(width, 0.0)

            bgl.glTexCoord2f(1.0, 1.0)
            bgl.glVertex2f(width, height)

            bgl.glTexCoord2f(0.0, 1.0)
            bgl.glVertex2f(0.0, height)

            bgl.glEnd()

            for obj in objlist:
                if obj.mv.type == 'VISDIM_A':
                    for x in range(0, 20):
                        if obj.layers[x] is True:
                            if x in layers:
                                opengl_dim = obj.mv.opengl_dim
                                if not opengl_dim.hide:
                                    draw_dimensions(context, obj, opengl_dim,
                                                    None, None)
                            break

            #---------- copy pixels to temporary area
            bgl.glFinish()
            bgl.glReadPixels(0, 0, width, height, bgl.GL_RGBA, bgl.GL_FLOAT,
                             buffer)  # read image data
            for y in range(0, tile_y):
                # final image pixels position
                p1 = (y * width * 4) + (row * tile_y * width *
                                        4) + (col * tile_x * 4)
                p2 = p1 + (tile_x * 4)
                # buffer pixels position
                b1 = y * width * 4
                b2 = b1 + (tile_x * 4)

                if p1 < totpixel4:  # avoid pixel row out of area
                    if col == col_num - 1:  # avoid pixel columns out of area
                        p2 -= cut4
                        b2 -= cut4

                    tmp_pixels[p1:p2] = buffer[b1:b2]

    img_result.pixels = tmp_pixels[:]
    img.gl_free()

    img.user_clear()
    bpy.data.images.remove(img)
    os.remove(ren_path)
    bgl.glEnable(bgl.GL_SCISSOR_TEST)

    #---------- restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)

    if img_result is not None:
        return img_result
Example #48
0
def display_instructions(region, rv3d, instruct, keys_aff, keys_nav, keys_neg):

    userpref = bpy.context.preferences
    system = userpref.system
    rwtools = 0
    rwui = 0

    np_print(system.use_region_overlap)

    if system.use_region_overlap:
        area = bpy.context.area
        np_print('GO', area.regions)
        for r in area.regions:
            if r.type == 'TOOLS':
                rwtools = r.width
            elif r.type == 'UI':
                rwui = r.width

    np_print('rwtools', rwtools, 'rwui', rwui)
    field_keys_y = 46
    field_keys_x = 80
    rw = region.width
    rh = region.height
    np_print('rw, rh', rw, rh)

    expand = False
    crop = False

    len_aff_max = rw - 140 - rwtools - rwui
    len_aff = len(keys_aff) * 5
    len_neg = len(keys_neg) * 5
    len_ins = len(instruct) * 18
    if len_aff > len_aff_max: expand = True

    rw_min = 480
    rh_min = 280
    if rw - rwtools - rwui < rw_min or rh < rh_min: crop = True

    version = '020'
    font_id = 0

    keys_aff_1 = copy.deepcopy(keys_aff)
    keys_aff_2 = ' '
    if expand:
        keys_aff_1 = ''
        keys_aff_2 = ''
        np_print('len(keys_aff)', len(keys_aff))
        stop = 0
        for i in range(0, len(keys_aff) - 1):
            #np_print(keys_aff[i])
            if keys_aff[i] == ',' and i * 5 <= len_aff_max and i > stop:
                stop = i
        np_print('stop', stop)
        for i in range(0, stop + 1):
            keys_aff_1 = keys_aff_1 + keys_aff[i]
        for i in range(stop + 2, len(keys_aff)):
            keys_aff_2 = keys_aff_2 + keys_aff[i]
        np_print(keys_aff_1)
        np_print(keys_aff_2)

    field_keys_aff_1 = [[field_keys_x + rwtools, field_keys_y + 21],
                        [field_keys_x + rwtools, field_keys_y + 39],
                        [rw - int(field_keys_x / 2) - rwui, field_keys_y + 39],
                        [rw - int(field_keys_x / 2) - rwui, field_keys_y + 21]]
    field_keys_aff_2 = copy.deepcopy(field_keys_aff_1)
    field_keys_neg = [[field_keys_x + rwtools, field_keys_y],
                      [field_keys_x + rwtools, field_keys_y + 18],
                      [rw - int(field_keys_x / 2) - rwui, field_keys_y + 18],
                      [rw - int(field_keys_x / 2) - rwui, field_keys_y]]
    if expand:
        field_keys_aff_2 = copy.deepcopy(field_keys_neg)
        field_keys_neg = [
            [field_keys_x + rwtools, field_keys_y - 21],
            [field_keys_x + rwtools, field_keys_y - 3],
            [rw - int(field_keys_x / 2) - rwui, field_keys_y - 3],
            [rw - int(field_keys_x / 2) - rwui, field_keys_y - 21]
        ]

    size_font_np = 25
    size_font_instruct = 21
    size_font_keys = 11
    len_np_ins = len_ins + int(size_font_np * 2.1)

    pos_font_np_x = (rw - len_np_ins / 2) / 2 + rwtools / 2 - rwui / 2
    pos_font_np_y = 150
    if crop: pos_font_np_y = 75
    pos_font_instruct_x = pos_font_np_x + int(size_font_np * 2.1)
    pos_font_instruct_y = pos_font_np_y + 4
    pos_font_keys_aff_1_x = field_keys_x + 8 + rwtools
    pos_font_keys_aff_1_y = field_keys_y + 26
    pos_font_keys_aff_2_x = copy.deepcopy(pos_font_keys_aff_1_x)
    pos_font_keys_aff_2_y = copy.deepcopy(pos_font_keys_aff_1_y)
    pos_font_keys_nav_x = field_keys_x + 8 + rwtools
    pos_font_keys_nav_y = field_keys_y + 5
    pos_font_keys_neg_x = rw - 52 - len_neg - rwui
    np_print('len_neg', len_neg)
    np_print('pos_font_keys_neg_x', pos_font_keys_neg_x)
    pos_font_keys_neg_y = field_keys_y + 5
    if expand:
        pos_font_keys_aff_2_x = field_keys_x + 8 + rwtools
        pos_font_keys_aff_2_y = field_keys_y + 5
        pos_font_keys_nav_x = field_keys_x + 8 + rwtools
        pos_font_keys_nav_y = field_keys_y - 16
        pos_font_keys_neg_x = rw - 52 - len_neg - rwui
        pos_font_keys_neg_y = field_keys_y - 16 - rwui

    col_font_np = addon_settings_graph('col_font_np')
    col_font_instruct_main = addon_settings_graph('col_font_instruct_main')
    col_font_instruct_shadow = addon_settings_graph('col_font_instruct_shadow')
    col_font_keys = addon_settings_graph('col_font_keys')
    col_field_keys_aff = addon_settings_graph('col_field_keys_aff')
    col_field_keys_neg = addon_settings_graph('col_field_keys_neg')

    # instructions - NP:

    bgl.glColor4f(*col_font_np)
    blf.size(font_id, size_font_np, 72)
    blf.position(font_id, pos_font_np_x, pos_font_np_y, 0)
    blf.draw(font_id, 'NP')

    blf.enable(font_id, ROTATION)
    ang = radians(90)
    blf.size(font_id, int(size_font_np / 2.2), 72)
    blf.rotation(font_id, ang)
    blf.position(font_id, pos_font_np_x + int(size_font_np * 1.72),
                 pos_font_np_y - 2, 0)
    blf.draw(font_id, version)
    blf.disable(font_id, ROTATION)

    # instructions - instruct:

    bgl.glColor4f(*col_font_instruct_shadow)
    blf.position(font_id, pos_font_instruct_x + 1, pos_font_instruct_y - 1, 0)
    blf.size(font_id, size_font_instruct, 72)
    blf.draw(font_id, instruct)

    bgl.glColor4f(*col_font_instruct_main)
    blf.position(font_id, pos_font_instruct_x, pos_font_instruct_y, 0)
    blf.size(font_id, size_font_instruct, 72)
    blf.draw(font_id, instruct)

    bgl.glDisable(bgl.GL_BLEND)

    # instructions - keys - backdrop fields:

    bgl.glEnable(bgl.GL_BLEND)

    if crop == False:

        bgl.glColor4f(*col_field_keys_aff)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for co in field_keys_aff_1:
            bgl.glVertex2f(*co)
        bgl.glEnd()

        bgl.glColor4f(*col_field_keys_aff)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for co in field_keys_aff_2:
            bgl.glVertex2f(*co)
        bgl.glEnd()

        bgl.glColor4f(*col_field_keys_neg)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for co in field_keys_neg:
            bgl.glVertex2f(*co)
        bgl.glEnd()

        # instructions - keys - writing:

        bgl.glColor4f(*col_font_keys)
        blf.size(font_id, size_font_keys, 72)

        blf.position(font_id, pos_font_keys_aff_1_x, pos_font_keys_aff_1_y, 0)
        blf.draw(font_id, keys_aff_1)

        blf.position(font_id, pos_font_keys_aff_2_x, pos_font_keys_aff_2_y, 0)
        blf.draw(font_id, keys_aff_2)

        blf.position(font_id, pos_font_keys_nav_x, pos_font_keys_nav_y, 0)
        blf.draw(font_id, keys_nav)

        blf.position(font_id, pos_font_keys_neg_x, pos_font_keys_neg_y, 0)
        blf.draw(font_id, keys_neg)
Example #49
0
def display_geowidget(region, rv3d, fac, ro_hor, q, helploc, n, qdef,
                      geowidget_base, geowidget_top, geowidget_rest):

    geowidget_cross = [(0.0, 2.1, 0.0), (0.0, 0.9, 0.0), (-2.1, 0.0, 0.0),
                       (-0.9, 0.0, 0.0)]

    # drawing of geowidget - cross part:
    for i, co in enumerate(geowidget_cross):
        co = Vector(co)
        co = co * fac
        geowidget_cross[i] = co

    geowidget_cross = rotate_graphic(geowidget_cross, ro_hor)
    geowidget_cross = rotate_graphic(geowidget_cross, q)
    geowidget_cross = translate_graphic(geowidget_cross, helploc)

    col_gw_line_cross = addon_settings_graph('col_gw_line_cross')
    col_gw_line_base_free = addon_settings_graph('col_gw_line_base_free')
    col_gw_line_base_lock_x = addon_settings_graph('col_gw_line_base_lock_x')
    col_gw_line_base_lock_y = addon_settings_graph('col_gw_line_base_lock_y')
    col_gw_line_base_lock_z = addon_settings_graph('col_gw_line_base_lock_z')
    col_gw_line_base_lock_arb = addon_settings_graph(
        'col_gw_line_base_lock_arb')
    col_gw_line_all = addon_settings_graph('col_gw_line_all')

    col_gw_fill_base_x = addon_settings_graph('col_gw_fill_base_x')
    col_gw_fill_base_y = addon_settings_graph('col_gw_fill_base_y')
    col_gw_fill_base_z = addon_settings_graph('col_gw_fill_base_z')
    col_gw_fill_base_arb = addon_settings_graph('col_gw_fill_base_arb')

    bgl.glColor4f(*col_gw_line_cross)
    bgl.glLineWidth(1)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for i, co in enumerate(geowidget_cross):
        if i in range(
                0, 2
        ):  # range is always - first as is, second one one higher than last
            #np_print(i)
            co = view3d_utils.location_3d_to_region_2d(region, rv3d, co)
            bgl.glVertex2f(*co)
            geowidget_cross[i] = co
    bgl.glEnd()
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for i, co in enumerate(geowidget_cross):
        if i in range(
                2, 4
        ):  # range is always - first as is, second one one higher than last
            #np_print(i)
            co = view3d_utils.location_3d_to_region_2d(region, rv3d, co)
            bgl.glVertex2f(*co)
            geowidget_cross[i] = co
    bgl.glEnd()

    # drawing of geowidget - base part:

    for i, co in enumerate(geowidget_base):
        co = Vector(co)
        co = co * fac
        geowidget_base[i] = co

    geowidget_base = rotate_graphic(geowidget_base, ro_hor)
    geowidget_base = rotate_graphic(geowidget_base, q)
    geowidget_base = translate_graphic(geowidget_base, helploc)

    n = n.to_tuple()
    n = list(n)
    for i, co in enumerate(n):
        n[i] = abs(round(co, 4))
    np_print('n for color', n)

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(*col_gw_line_base_free)
    bgl.glLineWidth(1)
    if qdef != None:
        if n[0] == 0.0 and n[1] == 0.0 and n[2] == 1.0:
            bgl.glColor4f(*col_gw_line_base_lock_z)
        elif n[0] == 1.0 and n[1] == 0.0 and n[2] == 0.0:
            bgl.glColor4f(*col_gw_line_base_lock_x)
        elif n[0] == 0.0 and n[1] == 1.0 and n[2] == 0.0:
            bgl.glColor4f(*col_gw_line_base_lock_y)
        else:
            bgl.glColor4f(*col_gw_line_base_lock_arb)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for i, co in enumerate(geowidget_base):
        #np_print(i)
        co = view3d_utils.location_3d_to_region_2d(region, rv3d, co)
        bgl.glVertex2f(*co)
        geowidget_base[i] = co
    bgl.glVertex2f(*geowidget_base[0])
    bgl.glEnd()

    bgl.glColor4f(*col_gw_fill_base_arb)
    if n[0] == 0.0 and n[1] == 0.0 and n[2] == 1.0:
        bgl.glColor4f(*col_gw_fill_base_z)
        np_print('go_Z')
    elif n[0] == 1.0 and n[1] == 0.0 and n[2] == 0.0:
        bgl.glColor4f(*col_gw_fill_base_x)
        np_print('go_X')
    elif n[0] == 0.0 and n[1] == 1.0 and n[2] == 0.0:
        bgl.glColor4f(*col_gw_fill_base_y)
        np_print('go_Y')
    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
    for co in geowidget_base:
        bgl.glVertex2f(*co)
    bgl.glEnd()

    # drawing of geowidget - top part:

    if geowidget_top != None:
        for i, co in enumerate(geowidget_top):
            co = Vector(co)
            co = co * fac
            geowidget_top[i] = co

        geowidget_top = rotate_graphic(geowidget_top, ro_hor)
        geowidget_top = rotate_graphic(geowidget_top, q)
        geowidget_top = translate_graphic(geowidget_top, helploc)

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(*col_gw_line_all)
        bgl.glLineWidth(1)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for i, co in enumerate(geowidget_top):
            #np_print(i)
            co = view3d_utils.location_3d_to_region_2d(region, rv3d, co)
            bgl.glVertex2f(*co)
            geowidget_top[i] = co
        bgl.glVertex2f(*geowidget_top[0])
        bgl.glEnd()

    # drawing of geowidget - rest part:

    if geowidget_rest != None:
        for i, co in enumerate(geowidget_rest):
            co = Vector(co)
            co = co * fac
            geowidget_rest[i] = co

        geowidget_rest = rotate_graphic(geowidget_rest, ro_hor)
        geowidget_rest = rotate_graphic(geowidget_rest, q)
        geowidget_rest = translate_graphic(geowidget_rest, helploc)

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(*col_gw_line_all)
        bgl.glLineWidth(1)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for i, co in enumerate(geowidget_rest):
            #np_print(i)
            co = view3d_utils.location_3d_to_region_2d(region, rv3d, co)
            bgl.glVertex2f(*co)
            geowidget_rest[i] = co
        bgl.glVertex2f(*geowidget_rest[0])
        bgl.glEnd()
Example #50
0
def cursor_memory_draw(cls,context):
    cc = context.scene.cursor_memory

    draw = 0
    if hasattr(cc, "savedLocationDraw"):
        draw = cc.savedLocationDraw

    if(draw):
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glShadeModel(bgl.GL_FLAT)
        p1 = Vector(cc.savedLocation)
        location = region3d_get_2d_coordinates(context, p1)
        alpha = 1-PHI_INV
        # Circle
        color = ([0.33, 0.33, 0.33],
            [1, 1, 1],
            [0.33, 0.33, 0.33],
            [1, 1, 1],
            [0.33, 0.33, 0.33],
            [1, 1, 1],
            [0.33, 0.33, 0.33],
            [1, 1, 1],
            [0.33, 0.33, 0.33],
            [1, 1, 1],
            [0.33, 0.33, 0.33],
            [1, 1, 1],
            [0.33, 0.33, 0.33],
            [1, 1, 1])
        offset = ([-4.480736161291701, -8.939966636005579],
            [-0.158097634992133, -9.998750178787843],
            [4.195854066857877, -9.077158622037636],
            [7.718765411993642, -6.357724476147943],
            [9.71288060283854, -2.379065025383466],
            [9.783240669628, 2.070797430975971],
            [7.915909938224691, 6.110513059466902],
            [4.480736161291671, 8.939966636005593],
            [0.15809763499209872, 9.998750178787843],
            [-4.195854066857908, 9.077158622037622],
            [-7.718765411993573, 6.357724476148025],
            [-9.712880602838549, 2.379065025383433],
            [-9.783240669627993, -2.070797430976005],
            [-7.915909938224757, -6.110513059466818])
        bgl.glBegin(bgl.GL_LINE_LOOP)
        for i in range(14):
            bgl.glColor4f(color[i][0], color[i][1], color[i][2], alpha)
            bgl.glVertex2f(location[0]+offset[i][0], location[1]+offset[i][1])
        bgl.glEnd()

        # Crosshair
        offset2 = 20
        offset = 5
        bgl.glColor4f(0, 0, 0, alpha)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glVertex2f(location[0]-offset2, location[1])
        bgl.glVertex2f(location[0]- offset, location[1])
        bgl.glEnd()
        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glVertex2f(location[0]+ offset, location[1])
        bgl.glVertex2f(location[0]+offset2, location[1])
        bgl.glEnd()
        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glVertex2f(location[0], location[1]-offset2)
        bgl.glVertex2f(location[0], location[1]- offset)
        bgl.glEnd()
        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glVertex2f(location[0], location[1]+ offset)
        bgl.glVertex2f(location[0], location[1]+offset2)
        bgl.glEnd()
Example #51
0
    def render_main(self, context, objlist, animation=False):
        # noinspection PyBroadException,PyBroadException
        # Save old info
        scene = context.scene
        render = scene.render
        settings = render.image_settings
        depth = settings.color_depth
        settings.color_depth = '8'
        # noinspection PyBroadException
        try:

            # Get visible layers
            layers = []
            for x in range(0, 20):
                if scene.layers[x] is True:
                    layers.extend([x])

            # --------------------
            # Get resolution
            # --------------------
            render_scale = render.resolution_percentage / 100

            width = int(render.resolution_x * render_scale)
            height = int(render.resolution_y * render_scale)
            # ---------------------------------------
            # Get output path
            # ---------------------------------------
            temp_path = path.realpath(bpy.app.tempdir)
            if len(temp_path) > 0:
                outpath = path.join(temp_path, "archipack_tmp_render.png")
            else:
                self.report({
                    'ERROR'
                }, "Archipack: Unable to save temporary render image. Define a valid temp path"
                            )
                settings.color_depth = depth
                return False

            # Get Render Image
            img = self.get_render_image(outpath)
            if img is None:
                self.report({
                    'ERROR'
                }, "Archipack: Unable to save temporary render image. Define a valid temp path"
                            )
                settings.color_depth = depth
                return False

            # -----------------------------
            # Calculate rows and columns
            # -----------------------------
            tile_x = 240
            tile_y = 216
            row_num = ceil(height / tile_y)
            col_num = ceil(width / tile_x)
            print("Archipack: Image divided in " + str(row_num) + "x" +
                  str(col_num) + " tiles")

            # pixels out of visible area
            cut4 = (col_num * tile_x *
                    4) - width * 4  # pixels aout of drawing area
            totpixel4 = width * height * 4  # total pixels RGBA

            viewport_info = bgl.Buffer(bgl.GL_INT, 4)
            bgl.glGetIntegerv(bgl.GL_VIEWPORT, viewport_info)

            # Load image on memory
            img.gl_load(0, bgl.GL_NEAREST, bgl.GL_NEAREST)

            # 2.77 API change
            if bpy.app.version >= (2, 77, 0):
                tex = img.bindcode[0]
            else:
                tex = img.bindcode

            # --------------------------------------------
            # Create output image (to apply texture)
            # --------------------------------------------
            if "archipack_output" in bpy.data.images:
                out_img = bpy.data.images["archipack_output"]
                if out_img is not None:
                    # out_img.user_clear()
                    bpy.data.images.remove(out_img, do_unlink=True)

            out = bpy.data.images.new("archipack_output", width, height)
            tmp_pixels = [1] * totpixel4

            # --------------------------------
            # Loop for all tiles
            # --------------------------------
            for row in range(0, row_num):
                for col in range(0, col_num):
                    buffer = bgl.Buffer(bgl.GL_FLOAT, width * height * 4)
                    bgl.glDisable(
                        bgl.GL_SCISSOR_TEST
                    )  # if remove this line, get blender screenshot not image
                    bgl.glViewport(0, 0, tile_x, tile_y)

                    bgl.glMatrixMode(bgl.GL_PROJECTION)
                    bgl.glLoadIdentity()

                    # defines ortographic view for single tile
                    x1 = tile_x * col
                    y1 = tile_y * row
                    bgl.gluOrtho2D(x1, x1 + tile_x, y1, y1 + tile_y)

                    # Clear
                    bgl.glClearColor(0.0, 0.0, 0.0, 0.0)
                    bgl.glClear(bgl.GL_COLOR_BUFFER_BIT
                                | bgl.GL_DEPTH_BUFFER_BIT)

                    bgl.glEnable(bgl.GL_TEXTURE_2D)
                    bgl.glBindTexture(bgl.GL_TEXTURE_2D, tex)

                    # defines drawing area
                    bgl.glBegin(bgl.GL_QUADS)

                    bgl.glColor3f(1.0, 1.0, 1.0)
                    bgl.glTexCoord2f(0.0, 0.0)
                    bgl.glVertex2f(0.0, 0.0)

                    bgl.glTexCoord2f(1.0, 0.0)
                    bgl.glVertex2f(width, 0.0)

                    bgl.glTexCoord2f(1.0, 1.0)
                    bgl.glVertex2f(width, height)

                    bgl.glTexCoord2f(0.0, 1.0)
                    bgl.glVertex2f(0.0, height)

                    bgl.glEnd()

                    # -----------------------------
                    # Loop to draw all lines
                    # -----------------------------
                    for o, d in objlist:
                        if o.hide is False:
                            # verify visible layer
                            for x in range(0, 20):
                                if o.layers[x] is True:
                                    if x in layers:
                                        context.scene.objects.active = o
                                        # print("%s: %s" % (o.name, d.manip_stack))
                                        manipulators = d.manip_stack
                                        if manipulators is not None:
                                            for m in manipulators:
                                                if m is not None:
                                                    m.draw_callback(
                                                        m,
                                                        context,
                                                        render=True)
                                    break

                    # -----------------------------
                    # Loop to draw all debug
                    # -----------------------------
                    """
                    if scene.archipack_debug is True:
                        selobj = bpy.context.selected_objects
                        for myobj in selobj:
                            if scene.archipack_debug_vertices is True:
                                draw_vertices(context, myobj, None, None)
                            if scene.archipack_debug_faces is True or scene.archipack_debug_normals is True:
                                draw_faces(context, myobj, None, None)
                    """
                    """
                    if scene.archipack_rf is True:
                        bgl.glColor3f(1.0, 1.0, 1.0)
                        rfcolor = scene.archipack_rf_color
                        rfborder = scene.archipack_rf_border
                        rfline = scene.archipack_rf_line

                        bgl.glLineWidth(rfline)
                        bgl.glColor4f(rfcolor[0], rfcolor[1], rfcolor[2], rfcolor[3])

                        x1 = rfborder
                        x2 = width - rfborder
                        y1 = int(ceil(rfborder / (width / height)))
                        y2 = height - y1
                        draw_rectangle((x1, y1), (x2, y2))
                    """
                    # --------------------------------
                    # copy pixels to temporary area
                    # --------------------------------
                    bgl.glFinish()
                    bgl.glReadPixels(0, 0, width, height, bgl.GL_RGBA,
                                     bgl.GL_FLOAT, buffer)  # read image data
                    for y in range(0, tile_y):
                        # final image pixels position
                        p1 = (y * width * 4) + (row * tile_y * width *
                                                4) + (col * tile_x * 4)
                        p2 = p1 + (tile_x * 4)
                        # buffer pixels position
                        b1 = y * width * 4
                        b2 = b1 + (tile_x * 4)

                        if p1 < totpixel4:  # avoid pixel row out of area
                            if col == col_num - 1:  # avoid pixel columns out of area
                                p2 -= cut4
                                b2 -= cut4

                            tmp_pixels[p1:p2] = buffer[b1:b2]

            # -----------------------
            # Copy temporary to final
            # -----------------------
            out.pixels = tmp_pixels[:]  # Assign image data
            img.gl_free()  # free opengl image memory

            # delete image
            # img.user_clear()
            bpy.data.images.remove(img, do_unlink=True)
            # remove temp file
            remove(outpath)
            # reset
            bgl.glEnable(bgl.GL_SCISSOR_TEST)
            # -----------------------
            # restore opengl defaults
            # -----------------------
            bgl.glLineWidth(1)
            bgl.glDisable(bgl.GL_BLEND)
            bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
            # Saves image
            if out is not None:
                # and (scene.archipack_render is True or animation is True):
                ren_path = bpy.context.scene.render.filepath
                filename = "ap_frame"
                if len(ren_path) > 0:
                    if ren_path.endswith(path.sep):
                        initpath = path.realpath(ren_path) + path.sep
                    else:
                        (initpath, filename) = path.split(ren_path)

                ftxt = "%04d" % scene.frame_current
                outpath = path.realpath(
                    path.join(initpath, filename + ftxt + ".png"))

                self.save_image(outpath, out)

            settings.color_depth = depth
            return True

        except:
            settings.color_depth = depth
            print("Unexpected error:" + str(exc_info()))
            self.report({
                'ERROR'
            }, "Archipack: Unable to create render image. Be sure the output render path is correct"
                        )
            return False
Example #52
0
    def draw_postview(self, context):
        ''' Place drawing code in here '''

        t111 = self.cntrlList[0].to_tuple()

        # sample code to draw corners of cube
        bgl.glEnable(bgl.GL_POINT_SMOOTH)
        bgl.glColor3d(0, 0, 0)
        bgl.glPointSize(3)
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glVertex3f(
            *t111
        )  # Note: *t111 expands elements of tuple as individual parameters
        bgl.glVertex3f(1, -1, 1)
        bgl.glVertex3f(-1, -1, 1)
        bgl.glVertex3f(-1, 1, 1)
        bgl.glVertex3f(1, 1, -1)
        bgl.glVertex3f(1, -1, -1)
        bgl.glVertex3f(-1, -1, -1)
        bgl.glVertex3f(-1, 1, -1)
        bgl.glEnd()

        # sample code to draw top and bottom edges of cube
        bgl.glLineWidth(1)
        bgl.glColor3f(0, 0, 0)
        bgl.glBegin(bgl.GL_LINES)
        bgl.glVertex3f(*t111)
        bgl.glVertex3f(-1, 1, 1)
        bgl.glVertex3f(-1, 1, 1)
        bgl.glVertex3f(-1, -1, 1)
        bgl.glVertex3f(-1, -1, 1)
        bgl.glVertex3f(1, -1, 1)
        bgl.glVertex3f(1, -1, 1)
        bgl.glVertex3f(*t111)

        bgl.glVertex3f(1, 1, -1)
        bgl.glVertex3f(-1, 1, -1)
        bgl.glVertex3f(-1, 1, -1)
        bgl.glVertex3f(-1, -1, -1)
        bgl.glVertex3f(-1, -1, -1)
        bgl.glVertex3f(1, -1, -1)
        bgl.glVertex3f(1, -1, -1)
        bgl.glVertex3f(1, 1, -1)

        bgl.glVertex3f(*t111)
        bgl.glVertex3f(1, 1, -1)
        bgl.glEnd()

        # sample code to show highlighting picked geometry
        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()
    def draw_postview(self, context, mesh, isBaseMesh):
        #mesh = self.mesh #temporary in case we decide it should be named differently
        a1 = 1.0
        a2 = 1.0
        if isBaseMesh and self.sublvl > 0:
            a1 = 0.5
            a2 = .75

        bgl.glEnable(bgl.GL_POINT_SMOOTH)
        bgl.glEnable(bgl.GL_BLEND)

        #draw the vertices
        for v in mesh.vertices:
            if v in self.selected:
                bgl.glColor4d(0.9, 0.5, 0, a2)
                bgl.glPointSize(4)
            else:
                bgl.glColor4d(1, 1, 0, a1)
                bgl.glPointSize(2)

            bgl.glBegin(bgl.GL_POINTS)
            bgl.glVertex3f(*v.co.to_tuple())
            bgl.glEnd()

        bgl.glDepthRange(0.0, 0.9999)
        #draw the edges
        for e in mesh.edges:
            if e in self.selected:
                bgl.glColor4d(0.9, 0.5, 0, a2)
                bgl.glLineWidth(2)
            else:
                bgl.glColor4d(0.5, 0.5, 0, a1)
                bgl.glLineWidth(1)

            bgl.glBegin(bgl.GL_LINES)
            bgl.glVertex3f(*e.v0.co.to_tuple())
            bgl.glVertex3f(*e.v1.co.to_tuple())
            bgl.glEnd()
        bgl.glDepthRange(0.0, 1.0)

        #draw the faces
        bgl.glBegin(bgl.GL_TRIANGLES)

        for f in mesh.faces:
            if f in self.selected:
                bgl.glColor4d(0.6, 0.2, 0, a2)
            else:
                bgl.glColor4d(0.3, 0.3, 0.3, a1)
            a = 0
            b = 1
            c = 2
            for i in range(len(f.lvertices) - 2):
                bgl.glVertex3f(*f.lvertices[a].co.to_tuple())
                bgl.glVertex3f(*f.lvertices[b].co.to_tuple())
                bgl.glVertex3f(*f.lvertices[c].co.to_tuple())
                b += 1
                c += 1

        bgl.glEnd()

        if False:
            bgl.glColor3f(0, 1, 1)
            bgl.glBegin(bgl.GL_LINES)
            for f in mesh.faces:
                p0 = Vector()
                for v in f.lvertices:
                    p0 += v.co
                p0 /= len(f.lvertices)
                p1 = p0 + f.normal * 0.2
                bgl.glVertex3f(*p0)
                bgl.glVertex3f(*p1)
            bgl.glEnd()
Example #54
0
def draw_alpha_controls(self, context):
    """
    Draws the line, 2 boxes, and the control square
    """
    w = context.region.width
    h = context.region.height
    line_width = 2 * (w / 10)
    offset_x = (line_width / 2) - (line_width * self.alpha_init)
    x = self.first_mouse.x + offset_x
    y = self.first_mouse.y + self.pos.y

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(1)

    bgl.glColor4f(0, 1, 1, 1)

    # Numbers
    bgl.glPushMatrix()
    bgl.glTranslatef(x - (w / 10) + self.pos.x, y, 0)
    font_id = 0
    blf.position(font_id, 0, 10, 0)
    blf.size(font_id, 20, 72)
    blf.draw(font_id, str(self.fac))
    bgl.glPopMatrix()

    # The Line
    bgl.glPushMatrix()
    bgl.glTranslatef(x, y, 0)
    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glVertex2f(-w / 10, 0)
    bgl.glVertex2f(w / 10, 0)
    bgl.glEnd()
    bgl.glPopMatrix()

    bgl.glEnable(bgl.GL_POINT_SMOOTH)
    bgl.glPointSize(10)

    # End Squares
    bgl.glPushMatrix()
    bgl.glTranslatef(x, y, 0)
    bgl.glBegin(bgl.GL_POINTS)
    bgl.glVertex2f(-w / 10, 0)
    bgl.glVertex2f(w / 10, 0)
    bgl.glEnd()
    bgl.glPopMatrix()

    # Control Square
    bgl.glColor4f(1, 0, 0, 1)
    bgl.glPushMatrix()
    bgl.glTranslatef(x - (w / 10) + self.pos.x, y, 0)
    bgl.glBegin(bgl.GL_POINTS)
    bgl.glVertex2f(0, 0)
    bgl.glEnd()
    bgl.glPopMatrix()

    bgl.glDisable(bgl.GL_POINT_SMOOTH)
    bgl.glPointSize(1)

    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Example #55
0
def draw_simulation_voxel():
    context = bpy.context
    domain = context.scene.flip_fluid.get_domain_object()
    dprops = context.scene.flip_fluid.get_domain_properties()
    if domain is None:
        return

    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

    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

    minx, maxx = bbox.x, bbox.x + dx
    miny, maxy = bbox.y, bbox.y + dx
    minz, maxz = bbox.z, bbox.z + dx
    voxel_coords = [
        (minx, miny, minz), (maxx, miny, minz), (minx, maxy, minz), (maxx, maxy, minz), 
        (minx, miny, maxz), (maxx, miny, maxz), (minx, maxy, maxz), (maxx, maxy, maxz),
        (minx, miny, minz), (minx, maxy, minz), (maxx, miny, minz), (maxx, maxy, minz),
        (minx, miny, maxz), (minx, maxy, maxz), (maxx, miny, maxz), (maxx, maxy, maxz),
        (minx, miny, minz), (minx, miny, maxz), (maxx, miny, minz), (maxx, miny, maxz),
        (minx, maxy, minz), (minx, maxy, maxz), (maxx, maxy, minz), (maxx, maxy, maxz)
        ]

    active_object = vcu.get_active_object(context)
    view_3d_theme = vcu.get_blender_preferences().themes[0].view_3d
    if domain == active_object:
        color = view_3d_theme.object_active
    elif domain in context.selected_objects:
        color = view_3d_theme.object_selected
    else:
        color = view_3d_theme.wire

    if vcu.is_blender_28():
        shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
        batch = batch_for_shader(shader, 'LINES', {"pos": voxel_coords})
        shader.bind()
        shader.uniform_float("color", (*color, 1.0))
        batch.draw(shader)
    else:
        bgl.glLineWidth(1)
        bgl.glBegin(bgl.GL_LINES)

        bgl.glColor4f(*color, 1.0)
        for c in voxel_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)
Example #56
0
 def _end(self):
     bgl.glEnd()
     bgl.glPopAttrib()
     bgl.glLineWidth(1)
     bgl.glDisable(bgl.GL_BLEND)
     bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Example #57
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.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
        i = 0
        glColor3f(1.0, 1.0, 1.0)
        for x in (-1.0, 1.0):
            for y in (-1.0, 1.0):
                for z in (-1.0, 1.0):
                    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 #58
0
def draw_callback_px(self, context):
    #print("mouse points", len(self.mouse_path))

    #font_id = 0  # XXX, need to find out how best to get this.

    # draw some text
    #blf.position(font_id, 15, 30, 0)
    #blf.size(font_id, 20, 72)
    #blf.draw(font_id, "Hello Word " + str(len(self.mouse_path)))

    image = context.window_manager.love2d3d.image_front  # Image ID
    if image == "":
        return
    self.image = context.blend_data.images[image]  # Get image

    # 50% alpha, 2 pixel width line
    #bgl.glLineWidth(0)
    bgl.glEnable(bgl.GL_BLEND)
    #bgl.glClearColor(0.0, 0.0, 0.0, 0.0);
    #bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    self.image.gl_load()
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.image.bindcode[0])
    bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
    bgl.glEnable(bgl.GL_TEXTURE_2D)
    bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER,
                        bgl.GL_NEAREST)
    bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER,
                        bgl.GL_NEAREST)
    #bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR)
    #bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR)

    #self.image.bind()
    #bgl.glLineWidth(2)

    #    bgl.glBegin(bgl.GL_LINE_STRIP)
    #    for x, y in self.mouse_path:
    #        bgl.glVertex2i(x, y)
    #
    #    bgl.glEnd()
    #camera = context.space_data.camera.location
    #sclip = context.space_data.clip_start
    #eclip = context.space_data.clip_end
    #lens = context.space_data.lens
    #pers = context.region_data.perspective_matrix
    #fovy = math.atan(pers[5]) * 2
    #aspect = pers[5] / pers[0]
    #bgl.gluPerspective(fovy, aspect, sclip, eclip);
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    #print(context.region_data.view_matrix)
    #ob = context.active_object
    #buff = bgl.Buffer(bgl.GL_FLOAT, [4, 4], context.region_data.view_matrix.transposed())
    #buff = bgl.Buffer(bgl.GL_FLOAT, [4, 4], ob.matrix_world.transposed())
    #mat = Matrix.Identity(4)
    mat = Matrix.Translation(context.space_data.cursor_location)
    view_align = context.window_manager.love2d3d.view_align
    if view_align:
        iview = Matrix(
            context.region_data.view_matrix).inverted_safe().to_3x3().to_4x4()
    else:
        iview = Matrix.Identity(4)
    buff = bgl.Buffer(bgl.GL_FLOAT, [4, 4], (mat * iview).transposed())
    bgl.glLoadMatrixf(buff)
    #bgl.glLoadIdentity()
    #camera = context.region_data.view_location
    #bgl.gluLookAt(camera.x, camera.y, camera.z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    #bgl.glLoadIdentity();
    buff = bgl.Buffer(bgl.GL_FLOAT, [4, 4],
                      context.region_data.perspective_matrix.transposed())
    bgl.glLoadMatrixf(buff)

    scale = context.window_manager.love2d3d.scale
    w, h = self.image.size
    w *= scale
    h *= scale
    #lb = location_3d_to_region_2d(context.region, context.space_data.region_3d, (-w / 2.0, 0, -h / 2.0))
    #rb = location_3d_to_region_2d(context.region, context.space_data.region_3d, (w / 2.0, 0, -h / 2.0))
    #rt = location_3d_to_region_2d(context.region, context.space_data.region_3d, (w / 2.0, 0, h / 2.0))
    #lt = location_3d_to_region_2d(context.region, context.space_data.region_3d, (-w / 2.0, 0, h /2.0))
    if view_align:
        lb = Vector((-w / 2.0, -h / 2.0, 0))
        rb = Vector((w / 2.0, -h / 2.0, 0))
        rt = Vector((w / 2.0, h / 2.0, 0))
        lt = Vector((-w / 2.0, h / 2.0, 0))
    else:
        lb = Vector((-w / 2.0, 0, -h / 2.0))
        rb = Vector((w / 2.0, 0, -h / 2.0))
        rt = Vector((w / 2.0, 0, h / 2.0))
        lt = Vector((-w / 2.0, 0, h / 2.0))
    #print(lt)
    bgl.glBegin(bgl.GL_QUADS)
    bgl.glTexCoord2d(0.0, 0.0)
    bgl.glVertex3f(lb.x, lb.y, lb.z)
    bgl.glTexCoord2d(1.0, 0.0)
    bgl.glVertex3f(rb.x, rb.y, lb.z)
    bgl.glTexCoord2d(1.0, 1.0)
    bgl.glVertex3f(rt.x, rt.y, rt.z)
    bgl.glTexCoord2d(0.0, 1.0)
    bgl.glVertex3f(lt.x, lt.y, lt.z)
    bgl.glEnd()
    self.image.gl_free()
    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_TEXTURE_2D)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Example #59
0
def draw_callback_view(self, 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 vars
    zero = Vector((0.0, 0.0, 0.0))
    x_p = Vector((1.0, 0.0, 0.0))
    x_n = Vector((-1.0, 0.0, 0.0))
    y_p = Vector((0.0, 1.0, 0.0))
    y_n = Vector((0.0, -1.0, 0.0))
    z_p = Vector((0.0, 0.0, 1.0))
    z_n = Vector((0.0, 0.0, -1.0))
    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.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
        i = 0
        glColor3f(1.0, 1.0, 1.0)
        for x in (-1.0, 1.0):
            for y in (-1.0, 1.0):
                for z in (-1.0, 1.0):
                    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 #60
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
        if vcu.is_blender_28():
            if 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 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 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 dprops.debug.enabled_debug_grids[2]:
                bgl.glColor4f(*z_color, 1.0)
                for c in z_coords:
                    bgl.glVertex3f(*c)
            if dprops.debug.enabled_debug_grids[1]:
                bgl.glColor4f(*y_color, 1.0)
                for c in y_coords:
                    bgl.glVertex3f(*c)
            if 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)