[Bf-extensions-cvs] [8b7de161] master: add_advanced_objects: Delaunay use scipy.spatial when present 18x faster
Stephen Leger
noreply at git.blender.org
Sun Jun 18 03:58:33 CEST 2017
Commit: 8b7de16183c7d0f9afd1d3174b0da19f963b1ab3
Author: Stephen Leger
Date: Sun Jun 18 03:57:19 2017 +0200
Branches: master
https://developer.blender.org/rBA8b7de16183c7d0f9afd1d3174b0da19f963b1ab3
add_advanced_objects: Delaunay use scipy.spatial when present 18x faster
===================================================================
M add_advanced_objects_panels/delaunay_voronoi.py
===================================================================
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
More information about the Bf-extensions-cvs
mailing list