Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <mail@jlucke.com>2019-02-05 19:04:33 +0300
committerJacques Lucke <mail@jlucke.com>2019-02-05 19:04:33 +0300
commit8e3a51e4e4e668283668aafa4c88c03a9af7f06d (patch)
tree06016ff261c933464596140d4475fb8cb8f9b407 /object_scatter
parent6f0deb3b89dd17458d0079bd97b183758fb4e80e (diff)
fix Object Scatter addon in background mode
Diffstat (limited to 'object_scatter')
-rw-r--r--object_scatter/operator.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/object_scatter/operator.py b/object_scatter/operator.py
index 49a3052d..30916ca5 100644
--- a/object_scatter/operator.py
+++ b/object_scatter/operator.py
@@ -34,8 +34,6 @@ from bpy_extras.view3d_utils import (
region_2d_to_origin_3d
)
-uniform_color_shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
-
# Modal Operator
################################################################
@@ -352,14 +350,15 @@ box_indices = (
box_vertices = tuple(Vector(vertex) * 0.5 for vertex in box_vertices)
def draw_matrices_batches(batches):
- uniform_color_shader.bind()
- uniform_color_shader.uniform_float("color", (0.4, 0.4, 1.0, 0.3))
+ shader = get_uniform_color_shader()
+ shader.bind()
+ shader.uniform_float("color", (0.4, 0.4, 1.0, 0.3))
bgl.glEnable(bgl.GL_BLEND)
bgl.glDepthMask(bgl.GL_FALSE)
for batch in batches:
- batch.draw(uniform_color_shader)
+ batch.draw(shader)
bgl.glDisable(bgl.GL_BLEND)
bgl.glDepthMask(bgl.GL_TRUE)
@@ -375,18 +374,20 @@ def create_batch_for_matrices(matrices, base_scale):
coords.extend((matrix @ vertex for vertex in scaled_box_vertices))
indices.extend(tuple(index + offset for index in element) for element in box_indices)
- batch = batch_for_shader(uniform_color_shader, 'TRIS', {"pos" : coords}, indices = indices)
+ batch = batch_for_shader(get_uniform_color_shader(),
+ 'TRIS', {"pos" : coords}, indices = indices)
return batch
def draw_line_strip_batch(batch, color, thickness=1):
+ shader = get_uniform_color_shader()
bgl.glLineWidth(thickness)
- uniform_color_shader.bind()
- uniform_color_shader.uniform_float("color", color)
- batch.draw(uniform_color_shader)
+ shader.bind()
+ shader.uniform_float("color", color)
+ batch.draw(shader)
def create_line_strip_batch(coords):
- return batch_for_shader(uniform_color_shader, 'LINE_STRIP', {"pos" : coords})
+ return batch_for_shader(get_uniform_color_shader(), 'LINE_STRIP', {"pos" : coords})
def draw_text(location, text, size=15, color=(1, 1, 1, 1)):
@@ -495,6 +496,9 @@ def get_max_object_side_length(objects):
max(obj.dimensions[2] for obj in objects)
)
+def get_uniform_color_shader():
+ return gpu.shader.from_builtin('3D_UNIFORM_COLOR')
+
# Registration
###############################################