domlysz / BlenderGIS

Blender addons to make the bridge between Blender and geographic data
GNU General Public License v3.0
7.66k stars 1.35k forks source link

Native delaunay triangulation available in daily build ! #209

Open s-leger opened 4 years ago

s-leger commented 4 years ago

Hi just want to share a great news, Howardt pushed constrained delaunay triangulation in 2.80 daily ! https://docs.blender.org/api/blender2.8/mathutils.geometry.html#mathutils.geometry.delaunay_2d_cdt

domlysz commented 4 years ago

Very good new ! thanks Stephen for sharing this !

domlysz commented 4 years ago

Hi Stephen, did you try this function? any snippet ? can't get it to works, got an obscure TypeError.

s-leger commented 4 years ago
# What output looks like.
# 0 => triangles with convex hull.
# 1 => triangles inside constraints.
# 2 => the input constraints, intersected.
# 3 => like 2 but with extra edges to make valid BMesh faces.

from mathutils.geometry import delaunay_2d_cdt
import random
# shuffle verts
random.shuffle(verts)
v2d = [v.to_2d() for v in verts]
overts, edges, faces, orig_verts, orig_edges, orig_faces = \
    delaunay_2d_cdt(v2d, [], [], 0, 0.00001)
# Note: verts indices may change to integer instead of list with single item
verts = [verts[i[0]] for i in orig_verts]
domlysz commented 4 years ago

Many thanks, finally I made it work but I don't really understand the output type : 0 works as expected 1 return only a set of points 2 and 3 cause a seg fault

domlysz commented 4 years ago

now ready for 2.81 https://github.com/domlysz/BlenderGIS/commit/71209232ce657607be89ec1937ef62b27a02a88b

s-leger commented 4 years ago

yep doc still spare, must ask howardt for exact meaning of arguments

domlysz commented 4 years ago

TODO add option for constrained triangulation (if I can get it to work!)