diff options
author | mano-wii <germano.costa@ig.com.br> | 2018-12-25 17:03:45 +0300 |
---|---|---|
committer | mano-wii <germano.costa@ig.com.br> | 2018-12-25 17:04:17 +0300 |
commit | 8185b187aa0ec1696641e05a10f4c7c84c644afc (patch) | |
tree | 1a428dbece843e2f52ac82173dda162859d2252f /mesh_snap_utilities_line | |
parent | c8931d77ad6f6e040cfa9b4b9c17460d2d00d8c5 (diff) |
mesh_snap_utilities: don't initialize gpu and numpy at module level
Diffstat (limited to 'mesh_snap_utilities_line')
-rw-r--r-- | mesh_snap_utilities_line/common_classes.py | 44 | ||||
-rw-r--r-- | mesh_snap_utilities_line/snap_context_l/mesh_drawing.py | 28 |
2 files changed, 60 insertions, 12 deletions
diff --git a/mesh_snap_utilities_line/common_classes.py b/mesh_snap_utilities_line/common_classes.py index b3465fae..1c6d75db 100644 --- a/mesh_snap_utilities_line/common_classes.py +++ b/mesh_snap_utilities_line/common_classes.py @@ -17,8 +17,6 @@ import bpy import bgl -import gpu -import numpy as np from .common_utilities import snap_utilities @@ -29,6 +27,8 @@ class SnapDrawn(): perpendicular_color, constrain_shift_color, axis_x_color, axis_y_color, axis_z_color): + import gpu + self.out_color = out_color self.face_color = face_color self.edge_color = edge_color @@ -57,32 +57,53 @@ class SnapDrawn(): def batch_line_strip_create(self, coords): - vbo = gpu.types.GPUVertBuf(self._format_pos, len = len(coords)) + from gpu.types import ( + GPUVertBuf, + GPUBatch, + ) + + vbo = GPUVertBuf(self._format_pos, len = len(coords)) vbo.attr_fill(0, data = coords) - batch_lines = gpu.types.GPUBatch(type = "LINE_STRIP", buf = vbo) + batch_lines = GPUBatch(type = "LINE_STRIP", buf = vbo) return batch_lines def batch_lines_smooth_color_create(self, coords, colors): - vbo = gpu.types.GPUVertBuf(self._format_pos_and_color, len = len(coords)) + from gpu.types import ( + GPUVertBuf, + GPUBatch, + ) + + vbo = GPUVertBuf(self._format_pos_and_color, len = len(coords)) vbo.attr_fill(0, data = coords) vbo.attr_fill(1, data = colors) - batch_lines = gpu.types.GPUBatch(type = "LINES", buf = vbo) + batch_lines = GPUBatch(type = "LINES", buf = vbo) return batch_lines def batch_triangles_create(self, coords): - vbo = gpu.types.GPUVertBuf(self._format_pos, len = len(coords)) + from gpu.types import ( + GPUVertBuf, + GPUBatch, + ) + + vbo = GPUVertBuf(self._format_pos, len = len(coords)) vbo.attr_fill(0, data = coords) - batch_tris = gpu.types.GPUBatch(type = "TRIS", buf = vbo) + batch_tris = GPUBatch(type = "TRIS", buf = vbo) return batch_tris def batch_point_get(self): if self._batch_point is None: - vbo = gpu.types.GPUVertBuf(self._format_pos, len = 1) + from gpu.types import ( + GPUVertBuf, + GPUBatch, + ) + vbo = GPUVertBuf(self._format_pos, len = 1) vbo.attr_fill(0, ((0.0, 0.0, 0.0),)) - self._batch_point = gpu.types.GPUBatch(type = "POINTS", buf = vbo) + self._batch_point = GPUBatch(type = "POINTS", buf = vbo) return self._batch_point def draw(self, type, location, list_verts_co, vector_constrain, prevloc): + import gpu + # draw 3d point OpenGL in the 3D View bgl.glEnable(bgl.GL_BLEND) gpu.matrix.push() @@ -150,6 +171,7 @@ class SnapDrawn(): gpu.matrix.pop() def draw_elem(self, snap_obj, bm, elem): + import gpu from bmesh.types import( BMVert, BMEdge, @@ -164,6 +186,8 @@ class SnapDrawn(): if isinstance(elem, BMVert): if elem.link_edges: + import numpy as np + color = self.vert_color edges = np.empty((len(elem.link_edges), 2), [("pos", "f4", 3), ("color", "f4", 4)]) edges["pos"][:, 0] = elem.co 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 0b0b099c..76b9a1d4 100644 --- a/mesh_snap_utilities_line/snap_context_l/mesh_drawing.py +++ b/mesh_snap_utilities_line/snap_context_l/mesh_drawing.py @@ -18,9 +18,7 @@ import bgl import bmesh -import numpy as np from mathutils import Matrix -import gpu def load_shader(shadername): from os import path @@ -30,6 +28,8 @@ def load_shader(shadername): 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') me.vertices.foreach_get("co", verts_co) verts_co.shape = (-1, 3) @@ -40,6 +40,8 @@ def get_mesh_vert_co_array(me): def get_bmesh_vert_co_array(bm): tot_vco = len(bm.verts) if tot_vco: + import numpy as np + return np.array([v.co for v in bm.verts], 'f4') return None @@ -48,6 +50,8 @@ def get_mesh_tri_verts_array(me): me.calc_loop_triangles() len_triangles = len(me.loop_triangles) if len_triangles: + import numpy as np + tris = np.empty(len_triangles * 3, 'i4') me.loop_triangles.foreach_get("vertices", tris) tris.shape = (-1, 3) @@ -56,6 +60,8 @@ def get_mesh_tri_verts_array(me): def get_bmesh_tri_verts_array(bm): + import numpy as np + l_tri_layer = bm.faces.layers.int.get("l_tri") if l_tri_layer is None: l_tri_layer = bm.faces.layers.int.new("l_tri") @@ -81,6 +87,8 @@ def get_bmesh_tri_verts_array(bm): def get_mesh_edge_verts_array(me): tot_edges = len(me.edges) if tot_edges: + import numpy as np + edge_verts = np.empty(tot_edges * 2, 'i4') me.edges.foreach_get("vertices", edge_verts) edge_verts.shape = tot_edges, 2 @@ -92,11 +100,14 @@ def get_bmesh_edge_verts_array(bm): bm.edges.ensure_lookup_table() 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 None def get_mesh_loosevert_array(me, edges): + import numpy as np + verts = np.arange(len(me.vertices)) mask = np.in1d(verts, edges, invert=True) @@ -110,6 +121,7 @@ def get_mesh_loosevert_array(me, edges): 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 None @@ -150,6 +162,8 @@ class _Mesh_Arrays(): else: #TODO + import numpy as np + self.verts_co = np.zeros((1,3), 'f4') self.looseverts = np.zeros(1, 'i4') @@ -193,6 +207,7 @@ class GPU_Indices_Mesh(): return import atexit + import gpu # Make sure we only registered the callback once. atexit.unregister(cls.end_opengl) @@ -211,6 +226,7 @@ class GPU_Indices_Mesh(): @staticmethod def set_ModelViewMatrix(MV): + import gpu gpu.matrix.load_matrix(MV) @@ -242,6 +258,8 @@ class GPU_Indices_Mesh(): update = True; if update: + import gpu + self.draw_tris = draw_tris self.draw_edges = draw_edges self.draw_verts = draw_verts @@ -378,6 +396,8 @@ class GPU_Indices_Mesh(): def gpu_Indices_enable_state(): + import gpu + GPU_Indices_Mesh.init_opengl() gpu.matrix.push() gpu.matrix.push_projection() @@ -386,6 +406,8 @@ def gpu_Indices_enable_state(): def gpu_Indices_restore_state(): + import gpu + gpu.matrix.pop() gpu.matrix.pop_projection() @@ -406,6 +428,8 @@ def gpu_Indices_use_clip_planes(rv3d, value): def gpu_Indices_set_ProjectionMatrix(P): + import gpu + gpu.matrix.load_projection_matrix(P) GPU_Indices_Mesh.P[:] = P |