Beispiel #1
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()
Beispiel #2
0
    def draw(self):
        context = bpy.context
        scene = context.scene
        view = context.area.spaces.active

        if context.mode != self.last_mode:
            self.last_mode = context.mode
            self.cleanup()

        if view.viewport_shade != 'TEXTURED':
            return

        bgl.glPushAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS)
        bgl.glShadeModel(bgl.GL_SMOOTH)

        for obj in context.visible_objects:
            if (obj.type == 'MESH' and
                obj.data.edges and not
                obj.data.polygons and not
                # obj.select and not
                obj == context.edit_object):

                cache = self.obj_cache.get(hash(obj))
                if cache is None:
                    cache = LineObjCache()
                    self.obj_cache[hash(obj)] = cache
                cache.draw(self, obj)

        bgl.glPopAttrib()
Beispiel #3
0
 def draw(self):
     width = render.getWindowWidth()
     height = render.getWindowHeight()
     
     # 2D Projection
     bgl.glMatrixMode(bgl.GL_PROJECTION)
     bgl.glLoadIdentity()
     bgl.glOrtho(0, width, height, 0, -1, 1)
     bgl.glMatrixMode(bgl.GL_MODELVIEW)
     bgl.glLoadIdentity()
     
     # 2D Shading
     bgl.glDisable(bgl.GL_CULL_FACE)
     bgl.glDisable(bgl.GL_LIGHTING)
     bgl.glDisable(bgl.GL_DEPTH_TEST)
     bgl.glShadeModel(bgl.GL_SMOOTH)
     
     # Line antialias
     bgl.glEnable(bgl.GL_LINE_SMOOTH)
     bgl.glHint(bgl.GL_LINE_SMOOTH_HINT, bgl.GL_NICEST)
     
     # 2D Blending (Alpha)
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
     
     if len(self.controls.values()) <= 0: return
     
     ctrls = sorted(self.controls.values(), key=lambda x: x.zorder)
     for c in ctrls:
         c.draw()
Beispiel #4
0
    def draw(self):
        width = render.getWindowWidth()
        height = render.getWindowHeight()

        # 2D Projection
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadIdentity()
        bgl.glOrtho(0, width, height, 0, -1, 1)
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glLoadIdentity()

        # 2D Shading
        bgl.glDisable(bgl.GL_CULL_FACE)
        bgl.glDisable(bgl.GL_LIGHTING)
        bgl.glDisable(bgl.GL_DEPTH_TEST)
        bgl.glShadeModel(bgl.GL_SMOOTH)

        # Line antialias
        bgl.glEnable(bgl.GL_LINE_SMOOTH)
        bgl.glHint(bgl.GL_LINE_SMOOTH_HINT, bgl.GL_NICEST)

        # 2D Blending (Alpha)
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

        if len(self.controls.values()) <= 0: return

        ctrls = sorted(self.controls.values(), key=lambda x: x.zorder)
        for c in ctrls:
            c.draw()
Beispiel #5
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 crosshairs():
    """
    Show crosshais in Manipulation Mode
    Use the OpenGL-Wrapper to draw the image
    """

    imageHeight = windowHeight * 0.05
    imageWidth = imageHeight

    x = windowWidth * 0.5 - imageWidth / 2
    y = windowHeight * 0.5 - imageHeight / 2

    gl_position = [[x, y], [x + imageWidth, y],
                   [x + imageWidth, y + imageHeight], [x, y + imageHeight]]

    view_buf = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
    view = view_buf.to_list() if hasattr(view_buf,
                                         "to_list") else view_buf.list
    # Save the state
    bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
    # Disable depth test so we always draw over things
    bgl.glDisable(bgl.GL_DEPTH_TEST)
    # Disable lighting so everything is shadless
    bgl.glDisable(bgl.GL_LIGHTING)
    # Unbinding the texture prevents BGUI frames from somehow picking up on
    # color of the last used texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)
    # Make sure we're using smooth shading instead of flat
    bgl.glShadeModel(bgl.GL_SMOOTH)
    # Setup the matrices
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, view[2], 0, view[3])
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()

    bgl.glEnable(bgl.GL_TEXTURE_2D)
    # Enable alpha blending
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    # Bind the texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, crosshairs_id)
    # Draw the textured quad
    bgl.glColor4f(1, 1, 1, 1)
    bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glPolygonOffset(1.0, 1.0)
    bgl.glBegin(bgl.GL_QUADS)
    for i in range(4):
        bgl.glTexCoord2f(texco[i][0], texco[i][1])
        bgl.glVertex2f(gl_position[i][0], gl_position[i][1])
    bgl.glEnd()
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

    bgl.glPopMatrix()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPopMatrix()
    bgl.glPopAttrib()
Beispiel #7
0
def crosshairs():
    """
    Show crosshais in Manipulation Mode
    Use the OpenGL-Wrapper to draw the image
    """
    
    imageHeight = windowHeight * 0.05
    imageWidth = imageHeight

    x = windowWidth * 0.5 - imageWidth/2
    y = windowHeight * 0.5 - imageHeight/2
    
    gl_position = [[x, y],[x+imageWidth, y],[x+imageWidth, y+imageHeight],[x, y+imageHeight]]
    
    view_buf = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
    view = view_buf.to_list() if hasattr(view_buf, "to_list") else view_buf.list
    # Save the state
    bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)      
    # Disable depth test so we always draw over things
    bgl.glDisable(bgl.GL_DEPTH_TEST)   
    # Disable lighting so everything is shadless
    bgl.glDisable(bgl.GL_LIGHTING)   
    # Unbinding the texture prevents BGUI frames from somehow picking up on
    # color of the last used texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)      
    # Make sure we're using smooth shading instead of flat
    bgl.glShadeModel(bgl.GL_SMOOTH)
    # Setup the matrices
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, view[2], 0, view[3])
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    
    bgl.glEnable(bgl.GL_TEXTURE_2D)
    # Enable alpha blending
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    # Bind the texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, crosshairs_id)
    # Draw the textured quad
    bgl.glColor4f(1, 1, 1, 1)
    bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glPolygonOffset(1.0, 1.0)
    bgl.glBegin(bgl.GL_QUADS)
    for i in range(4):
       bgl.glTexCoord2f(texco[i][0], texco[i][1])
       bgl.glVertex2f(gl_position[i][0], gl_position[i][1])
    bgl.glEnd()
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

    bgl.glPopMatrix()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPopMatrix()
    bgl.glPopAttrib()
Beispiel #8
0
def cursor_history_draw(cls, context):
    cc = context.scene.cursor_history

    draw = 0
    if hasattr(cc, "historyDraw"):
        draw = cc.historyDraw
    if hasattr(cc, "historyEnabled"):
        if (not cc.historyEnabled[0]):
            draw = 0

    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
        p2 = Vector(CursorAccess.getCursor())
        pp = None
        pn = None
        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 == -1):
                pp = Vector(cc.historyLocation[ix])
            if (ix_rel == 1):
                pn = Vector(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()

        # Distance of last step
        y = 10
        if (pn):
            bgl.glColor4f(1, 0, 0, PHI_INV)
            location = region3d_get_2d_coordinates(context, p2)
            blf.size(0, 10, 72)  # Prevent font size to randomly change.
            d = (p2 - pn).length
            blf.position(0, location[0] + 10, location[1] + y, 0)
            blf.draw(0, str(round(d, PRECISION)))
            y = y + 10
        if (pp):
            bgl.glColor4f(0, 0, 0, PHI_INV)
            location = region3d_get_2d_coordinates(context, p2)
            blf.size(0, 10, 72)  # Prevent font size to randomly change.
            d = (p2 - pp).length
            blf.position(0, location[0] + 10, location[1] + y, 0)
            blf.draw(0, str(round(d, PRECISION)))
def cursor_history_draw(cls,context):
    cc = context.scene.cursor_history

    draw = 0
    if hasattr(cc, "historyDraw"):
        draw = cc.historyDraw
    if hasattr(cc, "historyEnabled"):
        if(not cc.historyEnabled[0]):
            draw = 0

    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
        p2 = Vector(CursorAccess.getCursor())
        pp = None
        pn = None
        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==-1):
                pp = Vector(cc.historyLocation[ix])
            if(ix_rel==1):
                pn = Vector(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()
        
        # Distance of last step
        y=10
        if(pn):
            bgl.glColor4f(1, 0, 0, PHI_INV)
            location=region3d_get_2d_coordinates(context, p2)
            blf.size(0, 10, 72)  # Prevent font size to randomly change.
            d = (p2-pn).length
            blf.position(0, location[0]+10, location[1]+y, 0)
            blf.draw(0, str(round(d,PRECISION)))
            y = y + 10;
        if(pp):
            bgl.glColor4f(0, 0, 0, PHI_INV)
            location=region3d_get_2d_coordinates(context, p2)
            blf.size(0, 10, 72)  # Prevent font size to randomly change.
            d = (p2-pp).length
            blf.position(0, location[0]+10, location[1]+y, 0)
            blf.draw(0, str(round(d,PRECISION)))
def color_placing():
    """
    Draw the green rectangle via OpenGL-Wrapper
    """
    imageHeight = windowHeight * 0.05
    imageWidth = imageHeight

    x = windowWidth * 0.5 - imageWidth / 2
    y = windowHeight * 0.5 - imageHeight / 2

    gl_position = [[x, y], [x + imageWidth, y],
                   [x + imageWidth, y + imageHeight], [x, y + imageHeight]]

    view_buf = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
    view = view_buf.to_list() if hasattr(view_buf,
                                         "to_list") else view_buf.list
    # Save the state
    bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
    # Disable depth test so we always draw over things
    bgl.glDisable(bgl.GL_DEPTH_TEST)
    # Disable lighting so everything is shadless
    bgl.glDisable(bgl.GL_LIGHTING)
    # Make sure we're using smooth shading instead of flat
    bgl.glShadeModel(bgl.GL_SMOOTH)
    # Setup the matrices
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, view[2], 0, view[3])
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()

    # Enable alpha blending
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    # Draw the colored quad
    bgl.glColor4f(0, 1, 0, 0.25)
    bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glPolygonOffset(1.0, 1.0)
    bgl.glBegin(bgl.GL_QUADS)
    for i in range(4):
        bgl.glTexCoord2f(texco[i][0], texco[i][1])
        bgl.glVertex2f(gl_position[i][0], gl_position[i][1])
    bgl.glEnd()

    bgl.glPopMatrix()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPopMatrix()
    bgl.glPopAttrib()
    def drawPath(self):
        """
        Draw ray on screen.
        """
        bgl.glColor4f(0.8, 0.8, 0.9, 0.01)
        bgl.glLineWidth(0.01)

        bgl.glBegin(bgl.GL_LINES)
        bgl.glVertex3f(self.p1[0], self.p1[1], self.p1[2])
        bgl.glVertex3f(self.p2[0], self.p2[1], self.p2[2])
        bgl.glEnd()

        bgl.glNormal3f(0.0, 0.0, 1.0)
        bgl.glShadeModel(bgl.GL_SMOOTH)
Beispiel #12
0
def color_placing():
    """
    Draw the green rectangle via OpenGL-Wrapper
    """
    imageHeight = windowHeight * 0.05
    imageWidth = imageHeight

    x = windowWidth * 0.5 - imageWidth/2
    y = windowHeight * 0.5 - imageHeight/2
    
    gl_position = [[x, y],[x+imageWidth, y],[x+imageWidth, y+imageHeight],[x, y+imageHeight]]
    
    view_buf = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
    view = view_buf.to_list() if hasattr(view_buf, "to_list") else view_buf.list
    # Save the state
    bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)      
    # Disable depth test so we always draw over things
    bgl.glDisable(bgl.GL_DEPTH_TEST)   
    # Disable lighting so everything is shadless
    bgl.glDisable(bgl.GL_LIGHTING)   
    # Make sure we're using smooth shading instead of flat
    bgl.glShadeModel(bgl.GL_SMOOTH)
    # Setup the matrices
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, view[2], 0, view[3])
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    
    
    # Enable alpha blending
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    # Draw the colored quad
    bgl.glColor4f(0, 1, 0, 0.25)
    bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glPolygonOffset(1.0, 1.0)
    bgl.glBegin(bgl.GL_QUADS)
    for i in range(4):
       bgl.glTexCoord2f(texco[i][0], texco[i][1])
       bgl.glVertex2f(gl_position[i][0], gl_position[i][1])
    bgl.glEnd()

    bgl.glPopMatrix()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPopMatrix()
    bgl.glPopAttrib()
    def drawPath(self):
        """
        Draw ray on screen.
        """
        bgl.glColor4f(0.8,0.8,0.9,0.01)
        bgl.glLineWidth(0.01)

        bgl.glBegin(bgl.GL_LINES)
        bgl.glVertex3f(self.p1[0],self.p1[1],self.p1[2])
        bgl.glVertex3f(self.p2[0],self.p2[1],self.p2[2])
        bgl.glEnd()

        bgl.glNormal3f(0.0,0.0,1.0)
        bgl.glShadeModel(bgl.GL_SMOOTH);
Beispiel #14
0
def vicon_small_tri_right_draw(x, y, w, h, alpha=1.0):
    cx = x + w / 2 - 4
    cy = y + w / 2
    d = w / 5
    d2 = w / 7

    pts = ((cx - d2, cy + d), (cx - d2, cy - d), (cx + d2, cy))

    bgl.glColor4f(0.2, 0.2, 0.2, alpha)

    shademodel = vagl.Buffer('int', 0, bgl.GL_SHADE_MODEL)
    bgl.glShadeModel(bgl.GL_SMOOTH)
    bgl.glBegin(bgl.GL_TRIANGLES)
    bgl.glVertex2f(*pts[0])
    bgl.glVertex2f(*pts[1])
    bgl.glVertex2f(*pts[2])
    bgl.glEnd()
    bgl.glShadeModel(shademodel)
Beispiel #15
0
def vicon_small_tri_right_draw(x, y, w, h, alpha=1.0):
    cx = x + w / 2 - 4
    cy = y + w / 2
    d = w / 5
    d2 = w / 7

    pts = ((cx - d2, cy + d),
           (cx - d2, cy - d),
           (cx + d2, cy))

    bgl.glColor4f(0.2, 0.2, 0.2, alpha)

    shademodel = vagl.Buffer('int', 0, bgl.GL_SHADE_MODEL)
    bgl.glShadeModel(bgl.GL_SMOOTH)
    bgl.glBegin(bgl.GL_TRIANGLES)
    bgl.glVertex2f(*pts[0])
    bgl.glVertex2f(*pts[1])
    bgl.glVertex2f(*pts[2])
    bgl.glEnd()
    bgl.glShadeModel(shademodel)
Beispiel #16
0
def draw_callback_wc_view(context):
    gta_tools = bpy.context.scene.gta_tools
    global wc_state
    if wc_state.check_suspend(): return

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glShadeModel(bgl.GL_SMOOTH)

    # Mark Active VG Position
    if gta_tools.weight_props.mark_bone:
        active_bone_pos = get_acive_bone()
        bgl.glPointSize(10.0)
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
        bgl.glVertex3f(*active_bone_pos)
        bgl.glEnd()

    # Show Weight Color
    if gta_tools.weight_props.weight_color or gta_tools.weight_props.mark_unweighted:
        #if ditect_update(): update_vw()  # maybe removed, later
        #wc_state.check_update()
        check_update()
        bgl.glPointSize(gta_tools.weight_props.weight_size)
        bgl.glBegin(bgl.GL_POINTS)
        for vw in wc_state.vws:
            if (gta_tools.weight_props.weight_calc_margin < vw[1]):
                if gta_tools.weight_props.weight_color:
                    bgl.glColor4f(*get_heat4f(
                        vw[1], gta_tools.weight_props.weight_alpha))
                    bgl.glVertex3f(*vw[0])
            elif gta_tools.weight_props.weight_calc_margin < -vw[1]:
                if gta_tools.weight_props.mark_unweighted:
                    bgl.glColor4f(1.0, 0.0, 1.0,
                                  gta_tools.weight_props.weight_alpha)
                    bgl.glVertex3f(*vw[0])
        bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Beispiel #17
0
def vicon_disclosure_tri_down_draw(x, y, w, h, alpha=1.0):
    cx = x + w / 2
    cy = y + w / 2
    d = w / 3
    d2 = w / 5

    pts = ((cx + d, cy + d2), (cx - d, cy + d2), (cx, cy - d2))

    shademodel = vagl.Buffer('int', 0, bgl.GL_SHADE_MODEL)
    bgl.glShadeModel(bgl.GL_SMOOTH)
    bgl.glBegin(bgl.GL_TRIANGLES)
    bgl.glColor4f(0.8, 0.8, 0.8, alpha)
    bgl.glVertex2f(*pts[0])
    bgl.glVertex2f(*pts[1])
    bgl.glColor4f(0.3, 0.3, 0.3, alpha)
    bgl.glVertex2f(*pts[2])
    bgl.glEnd()
    bgl.glShadeModel(shademodel)

    bgl.glColor4f(0.0, 0.0, 0.0, 1)
    viconutil_draw_lineloop_smooth(pts)
Beispiel #18
0
    def draw(self, context):
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_LINE_SMOOTH)
        bgl.glLineWidth(1.0)
        bgl.glShadeModel(bgl.GL_SMOOTH)

        self.set_font_size(context)

        menu = self.menu
        menu.rect = [None] * 4
        for i, item in enumerate(menu.current_items):
            if item:
                item.rect = [None] * 4
                item.icon_box_rect, item.text_box_rect = self.calc_item_rect(
                    i, item.label, item.icon)

        self.draw_active_item_background()
        self.draw_guid_lines()
        self.draw_titles()
        self.draw_items()
        # self.draw_arrow()
        self.draw_tooltip(context)
Beispiel #19
0
def vicon_disclosure_tri_down_draw(x, y, w, h, alpha=1.0):
    cx = x + w / 2
    cy = y + w / 2
    d = w / 3
    d2 = w / 5

    pts = ((cx + d, cy + d2),
           (cx - d, cy + d2),
           (cx, cy - d2))

    shademodel = vagl.Buffer('int', 0, bgl.GL_SHADE_MODEL)
    bgl.glShadeModel(bgl.GL_SMOOTH)
    bgl.glBegin(bgl.GL_TRIANGLES)
    bgl.glColor4f(0.8, 0.8, 0.8, alpha)
    bgl.glVertex2f(*pts[0])
    bgl.glVertex2f(*pts[1])
    bgl.glColor4f(0.3, 0.3, 0.3, alpha)
    bgl.glVertex2f(*pts[2])
    bgl.glEnd()
    bgl.glShadeModel(shademodel)

    bgl.glColor4f(0.0, 0.0, 0.0, 1)
    viconutil_draw_lineloop_smooth(pts)
def cursor_delta_draw(cls,context):
    cc = context.scene.cursor_control

    draw = 0
    if hasattr(cc, "deltaLocationDraw"):
        draw = cc.deltaLocationDraw
    if hasattr(cc, "deltaEnabled"):
        if(not cc.deltaEnabled[0]):
            draw = 0

    if not draw:
        return
        
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glShadeModel(bgl.GL_FLAT)
    alpha = 1-PHI_INV
    
    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])

    c = Vector(CursorAccess.getCursor())
    p1 = c + Vector(cc.deltaVector)
    locationC = region3d_get_2d_coordinates(context, c)
    location = region3d_get_2d_coordinates(context, p1)
    bgl.glColor4f(0, 1, 1, alpha)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2f(locationC[0], locationC[1])
    bgl.glVertex2f(location[0], location[1])
    bgl.glEnd()

    #bgl.glColor4f(0, 1, 1, alpha)
    bgl.glBegin(bgl.GL_LINE_LOOP)
    for i in range(14):
        bgl.glVertex2f(location[0]+offset[i][0], location[1]+offset[i][1])
    bgl.glEnd()

    # Crosshair
    offset2 = 20
    offset = 5
    #bgl.glColor4f(0, 1, 1, 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()

    # distance to cursor
    blf.size(0, 10, 72)  # Prevent font size to randomly change.
    d = Vector(cc.deltaVector).length
    blf.position(0, location[0]+10, location[1]+10, 0)
    blf.draw(0, str(round(d,PRECISION)))
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()
Beispiel #22
0
def draw_callback_wg_view(context):
    gta_tools = bpy.context.scene.gta_tools
    global wg_state
    if 'VIEW_3D' != bpy.context.space_data.type: return
    if 'EDIT' != bpy.context.active_object.mode: return

    draw_size = gta_tools.weight_props.wg_line_size
    draw_alpha = gta_tools.weight_props.wg_line_alpha

    if "PLANE" == gta_tools.weight_props.grad_contour:
        if wg_state.enabled[1]:
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glShadeModel(bgl.GL_SMOOTH)

            # 1st Point
            col_1st = get_heat4f(gta_tools.weight_props.grad_range[0],
                                 draw_alpha)
            col_2nd = get_heat4f(gta_tools.weight_props.grad_range[1],
                                 draw_alpha)
            loc_1st = wg_state.cur_loc[1]
            bgl.glPointSize(draw_size)
            bgl.glBegin(bgl.GL_POINTS)
            bgl.glColor4f(*col_1st)
            bgl.glVertex3f(*loc_1st)
            bgl.glEnd()

            if wg_state.enabled[2]:
                # 2nd Point
                loc_2nd = wg_state.cur_loc[2]
                bgl.glPointSize(draw_size)
                bgl.glBegin(bgl.GL_POINTS)
                bgl.glColor4f(*col_2nd)
                bgl.glVertex3f(*loc_2nd)
                bgl.glEnd()

            else:
                loc_2nd = bpy.context.scene.cursor_location

            q = get_heat4f_line(
                [gta_tools.weight_props.grad_range[0], loc_1st],
                [gta_tools.weight_props.grad_range[1], loc_2nd], draw_alpha)
            bgl.glLineWidth(draw_size)
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for i in q:
                bgl.glColor4f(*i[2])
                bgl.glVertex3f(*i[1])
            bgl.glEnd()

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

    else:
        if wg_state.enabled[0]:
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glEnable(bgl.GL_LINE_STIPPLE)
            bgl.glShadeModel(bgl.GL_SMOOTH)

            # Gradient Center
            if wg_state.enabled[0]:
                if wg_state.enabled[1]:
                    col_center = (0.5, 0.5, 0.5, draw_alpha)
                else:
                    col_center = (1.0, 1.0, 1.0, draw_alpha)
                loc_center = wg_state.cur_loc[0]
                bgl.glPointSize(draw_size)
                bgl.glBegin(bgl.GL_POINTS)
                bgl.glColor4f(*col_center)
                bgl.glVertex3f(*loc_center)
                bgl.glEnd()

                # 1st Point
                if wg_state.enabled[1]:
                    loc_1st = wg_state.cur_loc[1]
                    bgl.glPointSize(draw_size)
                    bgl.glBegin(bgl.GL_POINTS)
                    bgl.glColor4f(*col_center)
                    bgl.glVertex3f(*loc_1st)
                    bgl.glEnd()
                else:
                    loc_1st = bpy.context.scene.cursor_location

                bgl.glLineWidth(1.0)
                bgl.glLineStipple(1, 0xcccc)
                bgl.glBegin(bgl.GL_LINE_STRIP)
                bgl.glColor4f(*col_center)
                bgl.glVertex3f(*loc_center)
                bgl.glVertex3f(*loc_1st)
                bgl.glEnd()

                # 2nd Point
                if wg_state.enabled[1]:
                    col_2nd = get_heat4f(gta_tools.weight_props.grad_range[1],
                                         draw_alpha)
                    if wg_state.enabled[2]:
                        loc_2nd = wg_state.cur_loc[2]
                        bgl.glPointSize(draw_size)
                        bgl.glBegin(bgl.GL_POINTS)
                        bgl.glColor4f(*col_2nd)
                        bgl.glVertex3f(*loc_2nd)
                        bgl.glEnd()
                    else:
                        loc_2nd = bpy.context.scene.cursor_location

                    col_mid = get_heat4f(gta_tools.weight_props.grad_range[0],
                                         draw_alpha)
                    loc_mid = calc_midpoint(loc_center, loc_1st, loc_2nd)

                    bgl.glLineWidth(1.0)
                    bgl.glLineStipple(1, 0xcccc)
                    bgl.glBegin(bgl.GL_LINE_STRIP)
                    bgl.glColor4f(*col_center)
                    bgl.glVertex3f(*loc_center)
                    bgl.glVertex3f(*loc_mid)
                    bgl.glEnd()

                    bgl.glPointSize(draw_size)
                    bgl.glBegin(bgl.GL_POINTS)
                    bgl.glColor4f(*col_mid)
                    bgl.glVertex3f(*loc_mid)
                    bgl.glEnd()

                    q = get_heat4f_line(
                        [gta_tools.weight_props.grad_range[0], loc_mid],
                        [gta_tools.weight_props.grad_range[1], loc_2nd],
                        draw_alpha)
                    bgl.glLineWidth(draw_size)
                    bgl.glLineStipple(1, 0xffff)
                    bgl.glBegin(bgl.GL_LINE_STRIP)
                    for i in q:
                        bgl.glColor4f(*i[2])
                        bgl.glVertex3f(*i[1])
                    bgl.glEnd()

            # restore opengl defaults
            bgl.glLineWidth(1)
            bgl.glDisable(bgl.GL_LINE_STIPPLE)
            bgl.glDisable(bgl.GL_BLEND)
            bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Beispiel #23
0
def draw_rounded_box(x,
                     y,
                     w,
                     h,
                     round_radius,
                     poly=False,
                     shade_color_top=None,
                     shade_color_bottom=None):
    def circle_verts_num(r):
        """描画に最適な?円の頂点数を求める"""
        n = 32
        threshold = 2.0  # pixcel
        while True:
            if r * 2 * math.pi / n > threshold:
                return n
            n -= 4
            if n < 1:
                return 1

    num = circle_verts_num(round_radius)
    n = int(num / 4) + 1
    pi = math.pi
    angle = pi * 2 / num
    use_shade = shade_color_top and shade_color_bottom
    if use_shade:
        glColorFunc = getattr(bgl, 'glColor' + str(len(shade_color_top)) + 'f')

        def set_color(yco):
            f1 = (yco - y) / h
            f2 = 1.0 - f1
            col = [
                a * f1 + b * f2
                for a, b in zip(shade_color_top, shade_color_bottom)
            ]
            glColorFunc(*col)

        shade_model = Buffer('int', 0, bgl.GL_SHADE_MODEL)
        bgl.glShadeModel(bgl.GL_SMOOTH)
    if poly:
        bgl.glBegin(bgl.GL_QUAD_STRIP)
        x0 = x + round_radius
        x1 = x + w - round_radius
        for y0, a0, a1 in ((y, pi * 1.5, pi * 1.5), (y + h, pi, 0.0)):
            for i in range(n):
                if y0 == y:
                    yco = y0 + round_radius + round_radius * math.sin(a0)
                else:
                    yco = y0 - round_radius + round_radius * math.sin(a0)
                if use_shade:
                    set_color(yco)
                bgl.glVertex2f(x0 + round_radius * math.cos(a0), yco)
                bgl.glVertex2f(x1 + round_radius * math.cos(a1), yco)
                a0 -= angle
                a1 += angle
        bgl.glEnd()
    else:
        bgl.glBegin(bgl.GL_LINE_LOOP)
        for x0, y0, a in ((x + round_radius, y + round_radius, pi),
                          (x + w - round_radius, y + round_radius, pi * 1.5),
                          (x + w - round_radius, y + h - round_radius, 0.0),
                          (x + round_radius, y + h - round_radius, pi * 0.5)):
            for i in range(n):
                xco = x0 + round_radius * math.cos(a)
                yco = y0 + round_radius * math.sin(a)
                if use_shade:
                    set_color(yco)
                bgl.glVertex2f(xco, yco)
                a += angle
        bgl.glEnd()
    if use_shade:
        bgl.glShadeModel(shade_model)
Beispiel #24
0
def draw_rounded_box(x, y, w, h, round_radius, poly=False,
                     shade_color_top=None, shade_color_bottom=None):
    def circle_verts_num(r):
        """描画に最適な?円の頂点数を求める"""
        n = 32
        threshold = 2.0  # pixcel
        while True:
            if r * 2 * math.pi / n > threshold:
                return n
            n -= 4
            if n < 1:
                return 1

    num = circle_verts_num(round_radius)
    n = int(num / 4) + 1
    pi = math.pi
    angle = pi * 2 / num
    use_shade = shade_color_top and shade_color_bottom
    if use_shade:
        glColorFunc = getattr(bgl, 'glColor' + str(len(shade_color_top)) + 'f')
        def set_color(yco):
            f1 = (yco - y) / h
            f2 = 1.0 - f1
            col = [a * f1 + b * f2
                   for a, b in zip(shade_color_top, shade_color_bottom)]
            glColorFunc(*col)
        shade_model = Buffer('int', 0, bgl.GL_SHADE_MODEL)
        bgl.glShadeModel(bgl.GL_SMOOTH)
    if poly:
        bgl.glBegin(bgl.GL_QUAD_STRIP)
        x0 = x + round_radius
        x1 = x + w - round_radius
        for y0, a0, a1 in ((y, pi * 1.5, pi * 1.5), (y + h, pi, 0.0)):
            for i in range(n):
                if y0 == y:
                    yco = y0 + round_radius + round_radius * math.sin(a0)
                else:
                    yco = y0 - round_radius + round_radius * math.sin(a0)
                if use_shade:
                    set_color(yco)
                bgl.glVertex2f(x0 + round_radius * math.cos(a0), yco)
                bgl.glVertex2f(x1 + round_radius * math.cos(a1), yco)
                a0 -= angle
                a1 += angle
        bgl.glEnd()
    else:
        bgl.glBegin(bgl.GL_LINE_LOOP)
        for x0, y0, a in ((x + round_radius, y + round_radius, pi),
                          (x + w - round_radius, y + round_radius, pi * 1.5),
                          (x + w - round_radius, y + h - round_radius, 0.0),
                          (x + round_radius, y + h - round_radius, pi * 0.5)):
            for i in range(n):
                xco = x0 + round_radius * math.cos(a)
                yco = y0 + round_radius * math.sin(a)
                if use_shade:
                    set_color(yco)
                bgl.glVertex2f(xco, yco)
                a += angle
        bgl.glEnd()
    if use_shade:
        bgl.glShadeModel(shade_model)
Beispiel #25
0
def status_image():
    """
    Show the corrensponding Image for the status
    """
    imageHeight = windowHeight * 0.075
    imageWidth = imageHeight

    x = windowWidth * 0.35 - imageWidth/2
    y = windowHeight * 0.45 - imageHeight/2
    
    gl_position = [[x, y],[x+imageWidth, y],[x+imageWidth, y+imageHeight],[x, y+imageHeight]]

    cam = logic.getCurrentScene().active_camera

    # get the suffix of the human to reference the right objects
    suffix = cam.name[-4:] if cam.name[-4] == "." else ""

    hand = objects['Hand_Grab.R' + suffix]

    # select the right Image
    if hand["selected"]:
        tex_id = closed_id
    else:
        tex_id = open_id

    
    view_buf = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
    view = view_buf.to_list() if hasattr(view_buf, "to_list") else view_buf.list
    # Save the state
    bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)      
    # Disable depth test so we always draw over things
    bgl.glDisable(bgl.GL_DEPTH_TEST)   
    # Disable lighting so everything is shadless
    bgl.glDisable(bgl.GL_LIGHTING)   
    # Unbinding the texture prevents BGUI frames from somehow picking up on
    # color of the last used texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)      
    # Make sure we're using smooth shading instead of flat
    bgl.glShadeModel(bgl.GL_SMOOTH)
    # Setup the matrices
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, view[2], 0, view[3])
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    
    
    bgl.glEnable(bgl.GL_TEXTURE_2D)
    # Enable alpha blending
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    # Bind the texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, tex_id)
    # Draw the textured quad
    bgl.glColor4f(1, 1, 1, 1)
    bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glPolygonOffset(1.0, 1.0)
    bgl.glBegin(bgl.GL_QUADS)
    for i in range(4):
       bgl.glTexCoord2f(texco[i][0], texco[i][1])
       bgl.glVertex2f(gl_position[i][0], gl_position[i][1])
    bgl.glEnd()
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

    bgl.glPopMatrix()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPopMatrix()
    bgl.glPopAttrib()
Beispiel #26
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()
Beispiel #27
0
	def draw(self):
		cam = bge.logic.getCurrentScene().active_camera
		
		self.position[2] += self.speed
		
		# Get some viewport info
		view_buf = bgl.Buffer(bgl.GL_INT, 4)
		bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
		view = view_buf[:]

		if 0:
			# Save the state
			bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)

			# Disable depth test so we always draw over things
			bgl.glDisable(bgl.GL_DEPTH_TEST)

			# Disable lighting so everything is shadless
			bgl.glDisable(bgl.GL_LIGHTING)

			# Unbinding the texture prevents BGUI frames from somehow picking up on
			# color of the last used texture
			bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

			# Make sure we're using smooth shading instead of flat
			bgl.glShadeModel(bgl.GL_SMOOTH)


		# Calculate x and y
		screen_coord = cam.getScreenPosition(self.position)
		x = screen_coord[0] * ras.getWindowWidth()
		y = ras.getWindowHeight() - (screen_coord[1] * ras.getWindowHeight())
		
		# Check to make sure the position isn't behind the camera
		if not cam.pointInsideFrustum(self.position):
			return
	
		# Calculate scale
		distance = cam.getDistanceTo(self.position)
		if 1000 - distance > 0:
			scale = (1000 - distance) / 1000
		else:
			scale = 0

		# Setup the matrices
		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glPushMatrix()
		bgl.glLoadIdentity()
		bgl.gluOrtho2D(0, view[2], 0, view[3])
		bgl.glMatrixMode(bgl.GL_MODELVIEW)
		bgl.glPushMatrix()
		bgl.glLoadIdentity()
		
		# Center the x
		text_width, text_height = blf.dimensions(self.fontid, self.text)
		x -= text_width / 2

			
		# Draw the font if large enough
		if scale:
			blf.size(self.fontid, int(self.pt_size*scale), 72)
			blf.position(self.fontid, x, y, 0)
			blf.draw(self.fontid, self.text)
			
		# Reset the state
		bgl.glPopMatrix()
		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glPopMatrix()
Beispiel #28
0
def cursor_memory_draw(cls, context):
    cc = context.scene.cursor_memory

    draw = 0
    if hasattr(cc, "savedLocationDraw"):
        draw = cc.savedLocationDraw
    if hasattr(cc, "savedLocationEnabled"):
        if (not cc.savedLocationEnabled[0]):
            draw = 0

    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()

        # Distance to cursor
        blf.size(0, 10, 72)  # Prevent font size to randomly change.
        p1 = Vector(cc.savedLocation)
        p2 = Vector(CursorAccess.getCursor())
        d = (p2 - p1).length
        bgl.glColor4f(0, 0, 0, alpha)
        blf.position(0, location[0] + 9, location[1] + 9, 0)
        blf.draw(0, str(round(d, PRECISION)))
        bgl.glColor4f(1, 1, 1, alpha)
        blf.position(0, location[0] + 10, location[1] + 10, 0)
        blf.draw(0, str(round(d, PRECISION)))
def status_image():
    """
    Show the corrensponding Image for the status
    """
    imageHeight = windowHeight * 0.075
    imageWidth = imageHeight

    x = windowWidth * 0.35 - imageWidth / 2
    y = windowHeight * 0.45 - imageHeight / 2

    gl_position = [[x, y], [x + imageWidth, y],
                   [x + imageWidth, y + imageHeight], [x, y + imageHeight]]

    cam = blenderapi.scene().active_camera

    # get the suffix of the human to reference the right objects
    suffix = cam.name[-4:] if cam.name[-4] == "." else ""

    hand = objects['Hand_Grab.R' + suffix]

    # select the right Image
    if hand["selected"]:
        tex_id = closed_id
    else:
        tex_id = open_id

    view_buf = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
    view = view_buf.to_list() if hasattr(view_buf,
                                         "to_list") else view_buf.list
    # Save the state
    bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
    # Disable depth test so we always draw over things
    bgl.glDisable(bgl.GL_DEPTH_TEST)
    # Disable lighting so everything is shadless
    bgl.glDisable(bgl.GL_LIGHTING)
    # Unbinding the texture prevents BGUI frames from somehow picking up on
    # color of the last used texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)
    # Make sure we're using smooth shading instead of flat
    bgl.glShadeModel(bgl.GL_SMOOTH)
    # Setup the matrices
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, view[2], 0, view[3])
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()

    bgl.glEnable(bgl.GL_TEXTURE_2D)
    # Enable alpha blending
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    # Bind the texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, tex_id)
    # Draw the textured quad
    bgl.glColor4f(1, 1, 1, 1)
    bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glPolygonOffset(1.0, 1.0)
    bgl.glBegin(bgl.GL_QUADS)
    for i in range(4):
        bgl.glTexCoord2f(texco[i][0], texco[i][1])
        bgl.glVertex2f(gl_position[i][0], gl_position[i][1])
    bgl.glEnd()
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

    bgl.glPopMatrix()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPopMatrix()
    bgl.glPopAttrib()