當前位置: 首頁>>代碼示例>>Python>>正文


Python batch.batch_for_shader方法代碼示例

本文整理匯總了Python中gpu_extras.batch.batch_for_shader方法的典型用法代碼示例。如果您正苦於以下問題:Python batch.batch_for_shader方法的具體用法?Python batch.batch_for_shader怎麽用?Python batch.batch_for_shader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gpu_extras.batch的用法示例。


在下文中一共展示了batch.batch_for_shader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: update

# 需要導入模塊: from gpu_extras import batch [as 別名]
# 或者: from gpu_extras.batch import batch_for_shader [as 別名]
def update(self, x, y):
        
        area_height = self.get_area_height()
        
        self.x_screen = x
        self.y_screen = y
                
        indices = ((0, 1, 2), (0, 2, 3))

        y_screen_flip = area_height - self.y_screen

        # bottom left, top left, top right, bottom right
        vertices = (
                    (self.x_screen, y_screen_flip), 
                    (self.x_screen, y_screen_flip - self.height), 
                    (self.x_screen + self.width, y_screen_flip - self.height),
                    (self.x_screen + self.width, y_screen_flip))
                    
        self.shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
        self.batch_panel = batch_for_shader(self.shader, 'TRIS', {"pos" : vertices}, indices=indices) 
開發者ID:jayanam,項目名稱:bl_ui_widgets,代碼行數:22,代碼來源:bl_ui_widget.py

示例2: draw_2d_point

# 需要導入模塊: from gpu_extras import batch [as 別名]
# 或者: from gpu_extras.batch import batch_for_shader [as 別名]
def draw_2d_point(point_x, point_y, p_size=4, p_col=(1.0,1.0,1.0,1.0)):
    bgl.glEnable(bgl.GL_BLEND)
    #bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
    #bgl.glLineWidth(2)

    bgl.glPointSize(p_size)
    coords = ((point_x, point_y), (point_x, point_y))
    batch = batch_for_shader(shader2d, 'POINTS', {"pos": coords})
    shader2d.bind()
    shader2d.uniform_float("color", (p_col[0], p_col[1], p_col[2], p_col[3]))
    batch.draw(shader2d)
    # bgl.glBegin(bgl.GL_POINTS)
    # bgl.glColor4f(p_col[0], p_col[1], p_col[2], p_col[3])
    # bgl.glVertex2f(point_x, point_y)
    # bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND) 
開發者ID:mifth,項目名稱:mifthtools,代碼行數:21,代碼來源:mi_widget_curve.py

示例3: draw_rect_2d

# 需要導入模塊: from gpu_extras import batch [as 別名]
# 或者: from gpu_extras.batch import batch_for_shader [as 別名]
def draw_rect_2d(positions, color):
    """Draw 2D rectangle with given color. Use it to draw in SpaceView3D on 'POST_PIXEL'.

    :param positions: 2D position in the region, that we want to draw to.
    :type positions: tuple(int, int)
    :param color: RGBA of rectangle
    :type color: tuple(float, float, float, float)
    """
    shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
    batch = batch_for_shader(
        shader, 'TRI_FAN',
        {
            "pos": positions,
        },
    )
    shader.bind()
    shader.uniform_float("color", color)
    batch.draw(shader) 
開發者ID:SCSSoftware,項目名稱:BlenderTools,代碼行數:20,代碼來源:primitive.py

示例4: draw_rect

# 需要導入模塊: from gpu_extras import batch [as 別名]
# 或者: from gpu_extras.batch import batch_for_shader [as 別名]
def draw_rect(x, y, width, height, color):
    xmax = x + width
    ymax = y + height
    points = [[x, y],  # [x, y]
              [x, ymax],  # [x, y]
              [xmax, ymax],  # [x, y]
              [xmax, y],  # [x, y]
              ]
    indices = ((0, 1, 2), (2, 3, 0))

    shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
    batch = batch_for_shader(shader, 'TRIS', {"pos": points}, indices=indices)

    shader.bind()
    shader.uniform_float("color", color)
    bgl.glEnable(bgl.GL_BLEND)
    batch.draw(shader) 
開發者ID:LuxCoreRender,項目名稱:BlendLuxCore,代碼行數:19,代碼來源:viewport.py

示例5: draw_line

# 需要導入模塊: from gpu_extras import batch [as 別名]
# 或者: from gpu_extras.batch import batch_for_shader [as 別名]
def draw_line(shader, start, end, color=(1.0, 1.0, 1.0, 1.0)):
    """Draws a line using two Vector-based points"""
    batch = batch_for_shader(shader, "LINES", {"pos": (start, end)})

    shader.bind()
    shader.uniform_float("color", color)
    batch.draw(shader) 
開發者ID:GDQuest,項目名稱:blender-power-sequencer,代碼行數:9,代碼來源:draw.py

示例6: draw_rectangle

# 需要導入模塊: from gpu_extras import batch [as 別名]
# 或者: from gpu_extras.batch import batch_for_shader [as 別名]
def draw_rectangle(shader, origin, size, color=(1.0, 1.0, 1.0, 1.0)):
    vertices = (
        (origin.x, origin.y),
        (origin.x + size.x, origin.y),
        (origin.x, origin.y + size.y),
        (origin.x + size.x, origin.y + size.y),
    )
    indices = ((0, 1, 2), (2, 1, 3))
    batch = batch_for_shader(shader, "TRIS", {"pos": vertices}, indices=indices)
    shader.bind()
    shader.uniform_float("color", color)
    batch.draw(shader) 
開發者ID:GDQuest,項目名稱:blender-power-sequencer,代碼行數:14,代碼來源:draw.py

示例7: draw_triangle

# 需要導入模塊: from gpu_extras import batch [as 別名]
# 或者: from gpu_extras.batch import batch_for_shader [as 別名]
def draw_triangle(shader, point_1, point_2, point_3, color=(1.0, 1.0, 1.0, 1.0)):
    vertices = (point_1, point_2, point_3)
    indices = ((0, 1, 2),)
    batch = batch_for_shader(shader, "TRIS", {"pos": vertices}, indices=indices)
    shader.bind()
    shader.uniform_float("color", color)
    batch.draw(shader) 
開發者ID:GDQuest,項目名稱:blender-power-sequencer,代碼行數:9,代碼來源:draw.py

示例8: draw_3d

# 需要導入模塊: from gpu_extras import batch [as 別名]
# 或者: from gpu_extras.batch import batch_for_shader [as 別名]
def draw_3d(coords, gtype, rgba, context):
    """Draw Pivot Point Graphics.

    Note:
        Draws either Lines Points, or Tris using defined shader

    Args:
        coords: Input Coordinates List
        gtype: Graphic Type
        rgba: Colour in RGBA format
        context: Blender bpy.context instance.

    Returns:
        Nothing.
    """

    batch = batch_for_shader(SHADER, gtype, {"pos": coords})

    try:
        if coords is not None:
            bgl.glEnable(bgl.GL_BLEND)
            SHADER.bind()
            SHADER.uniform_float("color", rgba)
            batch.draw(SHADER)
    except:
        raise PDT_ShaderError 
開發者ID:Clockmender,項目名稱:Precision-Drawing-Tools,代碼行數:28,代碼來源:pdt_functions.py

示例9: onscreen_gem_table

# 需要導入模塊: from gpu_extras import batch [as 別名]
# 或者: from gpu_extras.batch import batch_for_shader [as 別名]
def onscreen_gem_table(self, x, y, color=(0.95, 0.95, 0.95, 1.0), is_viewport=True):
        gamma = self.gamma_correction if is_viewport else lambda x: x
        color = gamma(color)

        fontid = 1
        blf.size(fontid, self.prefs.view_font_size_report, 72)
        blf.color(fontid, *color)

        _, font_h = blf.dimensions(fontid, "Row Height")
        font_baseline = font_h * 0.4
        font_row_height = font_h * 2
        box_size = font_h * 1.5
        y += font_baseline

        for row, color in self.gems_fmt:
            y -= font_row_height

            shader.bind()
            shader.uniform_float("color", color)
            batch_font = batch_for_shader(shader, "TRI_FAN", {"pos": self.rect_coords(x, y, box_size, box_size)})
            batch_font.draw(shader)

            blf.position(fontid, x + font_row_height, y + font_baseline, 0.0)
            blf.draw(fontid, row)

        return y 
開發者ID:mrachinskiy,項目名稱:jewelcraft,代碼行數:28,代碼來源:onscreen_text.py

示例10: draw_3d_polyline

# 需要導入模塊: from gpu_extras import batch [as 別名]
# 或者: from gpu_extras.batch import batch_for_shader [as 別名]
def 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)

    coords = [(point[0], point[1], point[2]) for point in points]
    batch = batch_for_shader(shader3d, 'LINE_STRIP', {"pos": coords})
    shader3d.bind()
    shader3d.uniform_float("color", (p_col[0], p_col[1], p_col[2], p_col[3]))
    batch.draw(shader3d)

    # bgl.glBegin(bgl.GL_LINE_STRIP)
    # bgl.glColor4f(p_col[0], p_col[1], p_col[2], p_col[3])
    # 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) 
開發者ID:mifth,項目名稱:mifthtools,代碼行數:30,代碼來源:mi_widget_curve.py

示例11: draw_trajectory

# 需要導入模塊: from gpu_extras import batch [as 別名]
# 或者: from gpu_extras.batch import batch_for_shader [as 別名]
def draw_trajectory():
    context = bpy.context
    data = bpy.data
    draw_trajectories = context.scene.projectile_settings.draw_trajectories

    if draw_trajectories == 'all':
        emitters = [ob for ob in data.objects if ob.projectile_props.is_emitter]
    else:
        # Only draw selected
        emitters = [ob for ob in context.selected_objects if ob.projectile_props.is_emitter]

    # Generate a list of all coordinates for all trajectories
    coordinates = []
    for emitter in emitters:
        coordinates += calculate_trajectory(context, emitter)

    # Draw all trajectories
    shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
    batch = batch_for_shader(shader, 'LINES', {"pos": coordinates})

    shader.bind()
    shader.uniform_float("color", (1, 1, 1, 1))

    batch.draw(shader)

# A global to determine if the property is set from the UI to avoid recursion 
開發者ID:natecraddock,項目名稱:projectile,代碼行數:28,代碼來源:utils.py

示例12: create_batches

# 需要導入模塊: from gpu_extras import batch [as 別名]
# 或者: from gpu_extras.batch import batch_for_shader [as 別名]
def create_batches(self, context, mouse_input):

        ox = context.scene.cursor_offset_x
        oy = context.scene.cursor_offset_y

        self.y_off = 50 + oy

        if context.scene.h_dock == "0":
            self.x_off = 14 + ox
        elif context.scene.h_dock == "1":
            self.x_off = context.region.width - 100 - ox

        # Follow cursor
        elif context.scene.h_dock == "3":
            self.x_off = mouse_input.mouse_x - 35 + ox
            self.y_off = mouse_input.mouse_y - 100 - oy
        else:
            self.x_off = ((context.region.width - self.width_all) / 2.0) - 1

        # bottom left, top left, top right, bottom right
        self.vertices_left   = ((self.x_off,      20 + self.y_off), (self.x_off,      50 + self.y_off), (self.x_off + 20, 50 + self.y_off), (self.x_off + 20, 20 + self.y_off))
        self.vertices_right  = ((self.x_off + 50, 20 + self.y_off), (self.x_off + 50, 50 + self.y_off), (self.x_off + 70, 50 + self.y_off), (self.x_off + 70, 20 + self.y_off))
        self.vertices_middle = ((self.x_off + 30, 30 + self.y_off), (self.x_off + 30, 50 + self.y_off), (self.x_off + 40, 50 + self.y_off), (self.x_off + 40, 30 + self.y_off))
        self.shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')

        self.batch_left_button   = batch_for_shader(self.shader, 'TRIS', {"pos" : self.vertices_left},   indices = self.indices)
        self.batch_right_button  = batch_for_shader(self.shader, 'TRIS', {"pos" : self.vertices_right},  indices = self.indices)
        self.batch_middle_button = batch_for_shader(self.shader, 'TRIS', {"pos" : self.vertices_middle}, indices = self.indices) 
開發者ID:jayanam,項目名稱:shortcut_VUr,代碼行數:30,代碼來源:scv_draw_util.py

示例13: draw

# 需要導入模塊: from gpu_extras import batch [as 別名]
# 或者: from gpu_extras.batch import batch_for_shader [as 別名]
def draw(self, uniforms, space_3d):
        """Dispatches drawing for the buffer by creating and drawing batch.

        :param uniforms: list of uniforms tuples to be sent to shader
        :type uniforms: collections.Iterable[(str, type, bytearray, int, int)]
        :param space_3d: space 3D data of viewport to which buffers should be drawn
        :type space_3d: bpy.types.SpaceView3D
        """

        # nothing to draw really
        if not self.has_entries():
            return

        # triangles are not drawn into wireframe views
        if self.__type == _Buffer.Types.TRIS and space_3d.shading.type == 'WIREFRAME':
            return

        self.__bgl_callback(self.__bgl_callback_param_before)

        # bind shader
        self.__shader.bind()

        # fill the uniforms to binded shader
        for uniform_name, uniform_type, uniform_data, uniform_length, uniform_count in uniforms:
            uniform_loc = self.__shader.uniform_from_name(uniform_name)
            if uniform_type == float:
                self.__shader.uniform_vector_float(uniform_loc, uniform_data, uniform_length, uniform_count)
            elif uniform_type == int:
                self.__shader.uniform_vector_int(uniform_loc, uniform_data, uniform_length, uniform_count)
            else:
                raise TypeError("Invalid uniform type: %s" % uniform_type)

        # create batch and dispatch draw
        batch = batch_for_shader(self.__shader, self.__draw_type, self.__data)
        batch.draw(self.__shader)

        self.__bgl_callback(self.__bgl_callback_param_after) 
開發者ID:SCSSoftware,項目名稱:BlenderTools,代碼行數:39,代碼來源:primitive.py

示例14: draw_line2d

# 需要導入模塊: from gpu_extras import batch [as 別名]
# 或者: from gpu_extras.batch import batch_for_shader [as 別名]
def draw_line2d(x1, y1, x2, y2, width, color):
    coords = (
        (x1, y1), (x2, y2))

    indices = (
        (0, 1),)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_LINE_SMOOTH)

    shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
    batch = batch_for_shader(shader, 'LINES', {"pos": coords}, indices=indices)
    shader.bind()
    shader.uniform_float("color", color)
    batch.draw(shader) 
開發者ID:LuxCoreRender,項目名稱:BlendLuxCore,代碼行數:16,代碼來源:viewport.py

示例15: draw_lines

# 需要導入模塊: from gpu_extras import batch [as 別名]
# 或者: from gpu_extras.batch import batch_for_shader [as 別名]
def draw_lines(vertices, indices, color):
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_LINE_SMOOTH)
    bgl.glLineWidth(2)

    shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
    batch = batch_for_shader(shader, 'LINES', {"pos": vertices}, indices=indices)
    shader.bind()
    shader.uniform_float("color", color)
    batch.draw(shader) 
開發者ID:LuxCoreRender,項目名稱:BlendLuxCore,代碼行數:12,代碼來源:viewport.py


注:本文中的gpu_extras.batch.batch_for_shader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。