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:
authorGermano Cavalcante <germano.costa@ig.com.br>2022-04-11 19:55:22 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2022-04-11 19:55:36 +0300
commit295fb9b081b2b68af018fb03512edbbec1caab8d (patch)
treeb85d4115e6fef721eb2a591a8268240935a4bcad
parent4d53ec76a3d8b0a72fcc7a795067a159ce6dcd2c (diff)
Cleanup: Mesh Snap Utilities Line: Formating
-rw-r--r--mesh_snap_utilities_line/snap_context_l/mesh_drawing.py90
1 files changed, 49 insertions, 41 deletions
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 e0f95bd1..02bd3f43 100644
--- a/mesh_snap_utilities_line/snap_context_l/mesh_drawing.py
+++ b/mesh_snap_utilities_line/snap_context_l/mesh_drawing.py
@@ -4,17 +4,20 @@ import gpu
import bmesh
from mathutils import Matrix
+
def load_shader(shadername):
from os import path
- with open(path.join(path.dirname(__file__), 'shaders', shadername), 'r') as f:
+
+ with open(path.join(path.dirname(__file__), "shaders", shadername), "r") as f:
return f.read()
+
def get_mesh_vert_co_array(me):
tot_vco = len(me.vertices)
if tot_vco:
import numpy as np
- verts_co = np.empty(len(me.vertices) * 3, 'f4')
+ verts_co = np.empty(len(me.vertices) * 3, "f4")
me.vertices.foreach_get("co", verts_co)
verts_co.shape = (-1, 3)
return verts_co
@@ -26,7 +29,7 @@ def get_bmesh_vert_co_array(bm):
if tot_vco:
import numpy as np
- return np.array([v.co for v in bm.verts], 'f4')
+ return np.array([v.co for v in bm.verts], "f4")
return ()
@@ -36,7 +39,7 @@ def get_mesh_tri_verts_array(me):
if len_triangles:
import numpy as np
- tris = np.empty(len_triangles * 3, 'i4')
+ tris = np.empty(len_triangles * 3, "i4")
me.loop_triangles.foreach_get("vertices", tris)
tris.shape = (-1, 3)
return tris
@@ -52,7 +55,7 @@ def get_bmesh_tri_verts_array(bm):
l_tri_layer = bm.faces.layers.int.new("l_tri")
ltris = bm.calc_loop_triangles()
- tris = np.empty((len(ltris), 3), 'i4')
+ tris = np.empty((len(ltris), 3), "i4")
i = 0
bm.faces.ensure_lookup_table()
@@ -76,7 +79,7 @@ def get_mesh_edge_verts_array(me):
if tot_edges:
import numpy as np
- edge_verts = np.empty(tot_edges * 2, 'i4')
+ edge_verts = np.empty(tot_edges * 2, "i4")
me.edges.foreach_get("vertices", edge_verts)
edge_verts.shape = tot_edges, 2
return edge_verts
@@ -88,7 +91,8 @@ def get_bmesh_edge_verts_array(bm):
edges = [[e.verts[0].index, e.verts[1].index] for e in bm.edges if not e.hide]
if edges:
import numpy as np
- return np.array(edges, 'i4')
+
+ return np.array(edges, "i4")
return ()
@@ -109,14 +113,15 @@ def get_bmesh_loosevert_array(bm):
looseverts = [v.index for v in bm.verts if not (v.link_edges or v.hide)]
if looseverts:
import numpy as np
- return np.array(looseverts, 'i4')
+
+ return np.array(looseverts, "i4")
return ()
-class _Mesh_Arrays():
+class _Mesh_Arrays:
def __init__(self, obj, create_tris, create_edges, create_looseverts):
self.tri_verts = self.edge_verts = self.looseverts = ()
- if obj.type == 'MESH':
+ if obj.type == "MESH":
me = obj.data
if me.is_editmode:
bm = bmesh.from_edit_mesh(me)
@@ -134,6 +139,7 @@ class _Mesh_Arrays():
del bm
else:
import bpy
+
self.verts_co = get_mesh_vert_co_array(me)
if create_tris:
@@ -147,20 +153,19 @@ class _Mesh_Arrays():
self.looseverts = get_mesh_loosevert_array(me, edge_verts)
del edge_verts
-
- else: #TODO
+ else: # TODO
import numpy as np
- self.verts_co = np.zeros((1,3), 'f4')
- self.looseverts = np.zeros(1, 'i4')
+ self.verts_co = np.zeros((1, 3), "f4")
+ self.looseverts = np.zeros(1, "i4")
def __del__(self):
del self.tri_verts, self.edge_verts, self.looseverts
del self.verts_co
-class GPU_Indices_Mesh():
- __slots__ = (\
+class GPU_Indices_Mesh:
+ __slots__ = (
"ob_data",
"draw_tris",
"draw_edges",
@@ -173,7 +178,8 @@ class GPU_Indices_Mesh():
"edge_verts",
"looseverts",
"first_index",
- "users")
+ "users",
+ )
_Hash = {}
shader = None
@@ -200,12 +206,12 @@ class GPU_Indices_Mesh():
cls.shader = gpu.types.GPUShader(
load_shader("ID_color_vert.glsl"),
load_shader("ID_color_frag.glsl"),
- defines="#define USE_CLIP_PLANES\n")
+ defines="#define USE_CLIP_PLANES\n",
+ )
- cls.unif_offset = cls.shader.uniform_from_name('offset')
+ 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):
self.ob_data = obj.original.data
@@ -241,7 +247,9 @@ class GPU_Indices_Mesh():
GPU_Indices_Mesh.init_opengl()
## Init Array ##
- mesh_arrays = _Mesh_Arrays(depsgraph.id_eval_get(obj), draw_tris, draw_edges, draw_verts)
+ mesh_arrays = _Mesh_Arrays(
+ depsgraph.id_eval_get(obj), draw_tris, draw_edges, draw_verts
+ )
if mesh_arrays.verts_co is None:
self.draw_tris = False
@@ -260,16 +268,16 @@ class GPU_Indices_Mesh():
del mesh_arrays
format = gpu.types.GPUVertFormat()
- format.attr_add(id="pos", comp_type='F32', len=3, fetch_mode='FLOAT')
+ format.attr_add(id="pos", comp_type="F32", len=3, fetch_mode="FLOAT")
- vbo = gpu.types.GPUVertBuf(format, len = len(self.verts_co))
+ vbo = gpu.types.GPUVertBuf(format, len=len(self.verts_co))
- vbo.attr_fill(0, data = self.verts_co)
+ vbo.attr_fill(0, data=self.verts_co)
## Create Batch for Tris ##
if len(self.tri_verts) > 0:
- ebo = gpu.types.GPUIndexBuf(type = "TRIS", seq = self.tri_verts)
- self.batch_tris = gpu.types.GPUBatch(type = "TRIS", buf = vbo, elem = ebo)
+ ebo = gpu.types.GPUIndexBuf(type="TRIS", seq=self.tri_verts)
+ self.batch_tris = gpu.types.GPUBatch(type="TRIS", buf=vbo, elem=ebo)
self.batch_tris.program_set(self.shader)
else:
self.draw_tris = False
@@ -277,8 +285,8 @@ class GPU_Indices_Mesh():
## Create Batch for Edges ##
if len(self.edge_verts) > 0:
- ebo = gpu.types.GPUIndexBuf(type = "LINES", seq = self.edge_verts)
- self.batch_edges = gpu.types.GPUBatch(type = "LINES", buf = vbo, elem = ebo)
+ ebo = gpu.types.GPUIndexBuf(type="LINES", seq=self.edge_verts)
+ self.batch_edges = gpu.types.GPUBatch(type="LINES", buf=vbo, elem=ebo)
self.batch_edges.program_set(self.shader)
else:
self.draw_edges = False
@@ -286,14 +294,13 @@ class GPU_Indices_Mesh():
## Create Batch for Loose Verts ##
if len(self.looseverts) > 0:
- ebo = gpu.types.GPUIndexBuf(type = "POINTS", seq = self.looseverts)
- self.batch_lverts = gpu.types.GPUBatch(type = "POINTS", buf = vbo, elem = ebo)
+ ebo = gpu.types.GPUIndexBuf(type="POINTS", seq=self.looseverts)
+ self.batch_lverts = gpu.types.GPUBatch(type="POINTS", buf=vbo, elem=ebo)
self.batch_lverts.program_set(self.shader)
else:
self.draw_verts = False
self.batch_lverts = None
-
def get_tot_elems(self):
tot = 0
if self.draw_tris:
@@ -307,13 +314,11 @@ class GPU_Indices_Mesh():
return tot
-
def set_draw_mode(self, draw_tris, draw_edges, draw_verts):
self.draw_tris = draw_tris and len(self.tri_verts) > 0
self.draw_edges = draw_edges and len(self.edge_verts) > 0
self.draw_verts = draw_verts and len(self.looseverts) > 0
-
def Draw(self, index_offset, ob_mat, depth_offset=0.00005):
self.first_index = index_offset
gpu.matrix.push()
@@ -341,7 +346,7 @@ class GPU_Indices_Mesh():
far_ += depth_offset
near += depth_offset
- range = (far_ - near)
+ range = far_ - near
if is_persp:
winmat[2][2] = -(far_ + near) / range
winmat[2][3] = (-2 * far_ * near) / range
@@ -352,9 +357,9 @@ class GPU_Indices_Mesh():
if self.draw_edges:
self.shader.uniform_int("offset", (index_offset,))
- #bgl.glLineWidth(3.0)
+ # bgl.glLineWidth(3.0)
self.batch_edges.draw(self.shader)
- #bgl.glLineWidth(1.0)
+ # bgl.glLineWidth(1.0)
index_offset += len(self.edge_verts)
if self.draw_verts:
@@ -367,7 +372,6 @@ class GPU_Indices_Mesh():
gpu.matrix.pop()
gpu.matrix.pop_projection()
-
def get_tri_co(self, index):
return self.verts_co[self.tri_verts[index]]
@@ -382,7 +386,6 @@ class GPU_Indices_Mesh():
tri = bmface[l_tri_layer]
return self.verts_co[self.tri_verts[tri : tri + len(bmface.verts) - 2]]
-
def get_tri_verts(self, index):
return self.tri_verts[index]
@@ -404,7 +407,9 @@ class GPU_Indices_Mesh():
del self.looseverts
GPU_Indices_Mesh._Hash.pop(self.ob_data)
- #print('mesh_del', self.obj.name)
+ # print('mesh_del', self.obj.name)
+
+
def gpu_Indices_enable_state(winmat, viewmat):
GPU_Indices_Mesh.init_opengl()
gpu.matrix.push()
@@ -425,12 +430,15 @@ def gpu_Indices_use_clip_planes(rv3d, value):
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("WorldClipPlanes"), planes, 4, 4)
+ planes = gpu.types.Buffer("FLOAT", (6, 4), rv3d.clip_planes)
+ shader.uniform_vector_float(
+ shader.uniform_from_name("WorldClipPlanes"), planes, 4, 4
+ )
else:
GPU_Indices_Mesh.use_clip_planes = False
shader.uniform_bool("use_clip_planes", (GPU_Indices_Mesh.use_clip_planes,))
+
def gpu_Indices_mesh_cache_clear():
GPU_Indices_Mesh._Hash.clear()