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
8b7de161
Commit
8b7de161
authored
7 years ago
by
Stephen Leger
Browse files
Options
Downloads
Patches
Plain Diff
add_advanced_objects: Delaunay use scipy.spatial when present 18x faster
parent
14d1bb09
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
add_advanced_objects_panels/delaunay_voronoi.py
+35
-0
35 additions, 0 deletions
add_advanced_objects_panels/delaunay_voronoi.py
with
35 additions
and
0 deletions
add_advanced_objects_panels/delaunay_voronoi.py
+
35
−
0
View file @
8b7de161
...
...
@@ -42,6 +42,15 @@ from bpy.types import (
)
from
bpy.props
import
EnumProperty
try
:
from
scipy.spatial
import
Delaunay
import
bmesh
import
numpy
as
np
HAS_SCIPY
=
True
except
:
HAS_SCIPY
=
False
pass
# Globals
# set to True to enable debug_prints
...
...
@@ -122,6 +131,32 @@ class OBJECT_OT_TriangulateButton(Operator):
# move the check into the poll
obj
=
context
.
active_object
if
HAS_SCIPY
:
# Use scipy when present (~18 x faster)
bpy
.
ops
.
object
.
mode_set
(
mode
=
'
EDIT
'
)
bm
=
bmesh
.
from_edit_mesh
(
obj
.
data
)
points_3D
=
[
list
(
v
.
co
)
for
v
in
bm
.
verts
]
points_2D
=
np
.
array
([[
v
[
0
],
v
[
1
]]
for
v
in
points_3D
])
print
(
"
Triangulate
"
+
str
(
len
(
points_3D
))
+
"
points...
"
)
# Triangulate
tri
=
Delaunay
(
points_2D
)
faces
=
tri
.
simplices
.
tolist
()
# Create new mesh structure
print
(
"
Create mesh...
"
)
bpy
.
ops
.
object
.
mode_set
(
mode
=
'
OBJECT
'
)
mesh
=
bpy
.
data
.
meshes
.
new
(
"
TIN
"
)
mesh
.
from_pydata
(
points_3D
,
[],
faces
)
mesh
.
update
(
calc_edges
=
True
)
my
=
bpy
.
data
.
objects
.
new
(
"
TIN
"
,
mesh
)
context
.
scene
.
objects
.
link
(
my
)
my
.
matrix_world
=
obj
.
matrix_world
.
copy
()
obj
.
select
=
False
my
.
select
=
True
context
.
scene
.
objects
.
active
=
my
self
.
report
({
'
INFO
'
},
"
Mesh created (
"
+
str
(
len
(
faces
))
+
"
triangles)
"
)
print
(
"
Total :%s faces %s verts
"
%
(
len
(
faces
),
len
(
points_3D
)))
return
{
'
FINISHED
'
}
# Get points coodinates
r
=
obj
.
rotation_euler
s
=
obj
.
scale
...
...
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