Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-addons
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-addons
Commits
8185b187
Commit
8185b187
authored
6 years ago
by
mano-wii
Browse files
Options
Downloads
Patches
Plain Diff
mesh_snap_utilities: don't initialize gpu and numpy at module level
parent
c8931d77
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mesh_snap_utilities_line/common_classes.py
+34
-10
34 additions, 10 deletions
mesh_snap_utilities_line/common_classes.py
mesh_snap_utilities_line/snap_context_l/mesh_drawing.py
+26
-2
26 additions, 2 deletions
mesh_snap_utilities_line/snap_context_l/mesh_drawing.py
with
60 additions
and
12 deletions
mesh_snap_utilities_line/common_classes.py
+
34
−
10
View file @
8185b187
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
mesh_snap_utilities_line/snap_context_l/mesh_drawing.py
+
26
−
2
View file @
8185b187
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment