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:
authorStephen Leger <stephen@3dservices.ch>2017-06-18 04:57:19 +0300
committerStephen Leger <stephen@3dservices.ch>2017-06-18 04:57:49 +0300
commit8b7de16183c7d0f9afd1d3174b0da19f963b1ab3 (patch)
tree225263f306af0c24c9fedb6be5420b1745b234d0 /add_advanced_objects_panels
parent14d1bb0983725143df5e5115905b186fec39f697 (diff)
add_advanced_objects: Delaunay use scipy.spatial when present 18x faster
Diffstat (limited to 'add_advanced_objects_panels')
-rw-r--r--add_advanced_objects_panels/delaunay_voronoi.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/add_advanced_objects_panels/delaunay_voronoi.py b/add_advanced_objects_panels/delaunay_voronoi.py
index 0537bf6f..92cd0dad 100644
--- a/add_advanced_objects_panels/delaunay_voronoi.py
+++ b/add_advanced_objects_panels/delaunay_voronoi.py
@@ -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