[Bf-extensions-cvs] [8c8df3e3] master: Snap_Utilities_Line: support 3d view clip planes

Germano Cavalcante noreply at git.blender.org
Mon Aug 16 19:01:54 CEST 2021


Commit: 8c8df3e36974c000ffb6b11c40c0e017902e98d7
Author: Germano Cavalcante
Date:   Mon Aug 16 13:46:11 2021 -0300
Branches: master
https://developer.blender.org/rBA8c8df3e36974c000ffb6b11c40c0e017902e98d7

Snap_Utilities_Line: support 3d view clip planes

Elements that are not visible due to clip planes are ignored in the
main operation.

===================================================================

M	mesh_snap_utilities_line/__init__.py
M	mesh_snap_utilities_line/snap_context_l/mesh_drawing.py
M	mesh_snap_utilities_line/snap_context_l/shaders/ID_color_vert.glsl

===================================================================

diff --git a/mesh_snap_utilities_line/__init__.py b/mesh_snap_utilities_line/__init__.py
index 98f88e76..0b1b7a15 100644
--- a/mesh_snap_utilities_line/__init__.py
+++ b/mesh_snap_utilities_line/__init__.py
@@ -21,8 +21,8 @@
 bl_info = {
     "name": "Snap_Utilities_Line",
     "author": "Germano Cavalcante",
-    "version": (6, 9, 23),
-    "blender": (2, 93, 0),
+    "version": (6, 9, 3),
+    "blender": (3, 0, 0),
     "location": "View3D > TOOLS > Line Tool",
     "description": "Extends Blender Snap controls",
     "doc_url" : "https://blenderartists.org/t/cad-snap-utilities",
diff --git a/mesh_snap_utilities_line/snap_context_l/mesh_drawing.py b/mesh_snap_utilities_line/snap_context_l/mesh_drawing.py
index d05becec..bd324afd 100644
--- a/mesh_snap_utilities_line/snap_context_l/mesh_drawing.py
+++ b/mesh_snap_utilities_line/snap_context_l/mesh_drawing.py
@@ -211,12 +211,13 @@ class GPU_Indices_Mesh():
         atexit.unregister(cls.end_opengl)
         atexit.register(cls.end_opengl)
 
-        cls.shader = gpu.types.GPUShader(load_shader("ID_color_vert.glsl"),
-                load_shader("ID_color_frag.glsl"),)
-        #cls.unif_use_clip_planes =
-        #cls.shader.uniform_from_name('use_clip_planes')
-        #cls.unif_clip_plane = cls.shader.uniform_from_name('clip_plane')
+        cls.shader = gpu.types.GPUShader(
+            load_shader("ID_color_vert.glsl"),
+            load_shader("ID_color_frag.glsl"),
+            defines="#define USE_CLIP_PLANES\n")
+
         cls.unif_offset = cls.shader.uniform_from_name('offset')
+        cls.use_clip_planes = False
 
 
     def __init__(self, depsgraph, obj, draw_tris, draw_edges, draw_verts):
@@ -332,8 +333,12 @@ class GPU_Indices_Mesh():
         gpu.matrix.push()
         gpu.matrix.push_projection()
         gpu.matrix.multiply_matrix(ob_mat)
+
+        self.shader.bind()
+        if GPU_Indices_Mesh.use_clip_planes:
+            self.shader.uniform_float("ModelMatrix", ob_mat)
+
         if self.draw_tris:
-            self.shader.bind()
             self.shader.uniform_int("offset", (index_offset,))
             self.batch_tris.draw(self.shader)
             index_offset += len(self.tri_verts)
@@ -359,7 +364,6 @@ class GPU_Indices_Mesh():
             gpu.matrix.load_projection_matrix(winmat)
 
         if self.draw_edges:
-            self.shader.bind()
             self.shader.uniform_int("offset", (index_offset,))
             #bgl.glLineWidth(3.0)
             self.batch_edges.draw(self.shader)
@@ -367,7 +371,6 @@ class GPU_Indices_Mesh():
             index_offset += len(self.edge_verts)
 
         if self.draw_verts:
-            self.shader.bind()
             self.shader.uniform_int("offset", (index_offset,))
             self.batch_lverts.draw(self.shader)
 
@@ -427,17 +430,17 @@ def gpu_Indices_restore_state():
 
 
 def gpu_Indices_use_clip_planes(rv3d, value):
-    pass #TODO
-    #if rv3d.use_clip_planes:
-        #planes = bgl.Buffer(bgl.GL_FLOAT, (6, 4), rv3d.clip_planes)
-
-        #_store_current_shader_state(PreviousGLState)
-        #GPU_Indices_Mesh.init_opengl()
-        #bgl.glUseProgram(GPU_Indices_Mesh.shader.program)
-        #bgl.glUniform1i(GPU_Indices_Mesh.unif_use_clip_planes, value)
+    GPU_Indices_Mesh.init_opengl()
+    shader = GPU_Indices_Mesh.shader
+    shader.bind()
+    if value and rv3d.use_clip_planes:
+        GPU_Indices_Mesh.use_clip_planes = True
+        planes = gpu.types.Buffer('FLOAT', (6, 4), rv3d.clip_planes)
+        shader.uniform_vector_float(shader.uniform_from_name("clip_plane"), planes, 4, 4)
+    else:
+        GPU_Indices_Mesh.use_clip_planes = False
 
-        #bgl.glUniform4fv(GPU_Indices_Mesh.unif_clip_plane, 4, planes)
+    shader.uniform_bool("use_clip_planes", (GPU_Indices_Mesh.use_clip_planes,))
 
-        #_restore_shader_state(PreviousGLState)
 def gpu_Indices_mesh_cache_clear():
     GPU_Indices_Mesh._Hash.clear()
diff --git a/mesh_snap_utilities_line/snap_context_l/shaders/ID_color_vert.glsl b/mesh_snap_utilities_line/snap_context_l/shaders/ID_color_vert.glsl
index fa0afec6..6fb7cbb9 100644
--- a/mesh_snap_utilities_line/snap_context_l/shaders/ID_color_vert.glsl
+++ b/mesh_snap_utilities_line/snap_context_l/shaders/ID_color_vert.glsl
@@ -1,7 +1,7 @@
 uniform mat4 ModelViewProjectionMatrix;
 
 #ifdef USE_CLIP_PLANES
-uniform mat4 ModelViewMatrix;
+uniform mat4 ModelMatrix;
 uniform bool use_clip_planes;
 uniform vec4 clip_plane[4];
 out vec4 clip_distance;
@@ -13,7 +13,7 @@ void main()
 {
 #ifdef USE_CLIP_PLANES
 	if (use_clip_planes) {
-		vec4 g_pos = ModelViewMatrix * vec4(pos, 1.0);
+		vec4 g_pos = ModelMatrix * vec4(pos, 1.0);
 
 		for (int i = 0; i != 4; i++) {
 			clip_distance[i] = dot(clip_plane[i], g_pos);



More information about the Bf-extensions-cvs mailing list