Blender的AI模型delaunay三角化拓扑

https://zhuanlan.zhihu.com/p/459884570
https://devtalk.blender.org/t/delaunay-2d-cdt-robustness/10968/11

python 复制代码
from itertools import cycle, chain
from numpy import arange
import bpy
import bmesh
from mathutils import Vector
from mathutils.geometry import delaunay_2d_cdt

number_of_edges = 100

def generate_edges(number):
    # like this: | | | | | | | |
    x_iter = chain.from_iterable(zip(arange(0, number * 0.1, 0.1), arange(0, number * 0.1, 0.1)))
    vs = [Vector((x, y)) for x, y in zip(x_iter, cycle([0, 1]))]
    es = [(i, i + 1) for i in range(0, number * 2, 2)]
    return vs, es

verts, edges = generate_edges(number_of_edges)
verts += [Vector((-0.1, 0.5)), Vector((number_of_edges * 0.1, 0.5))]
edges += [(number_of_edges * 2, number_of_edges * 2 + 1)]
verts_new, edges_new, faces_new, _, _, _ = delaunay_2d_cdt(verts, edges, [], 2, 1e-5)

print(f'Done intersections: {number_of_edges}')

bm = bmesh.new()
vs = [bm.verts.new(v.to_3d()) for v in verts_new]
[bm.edges.new([vs[i1], vs[i2]]) for i1, i2 in edges_new]
me = bpy.data.meshes.new("InterTest")
bm.to_mesh(me)
bm.free()
obj = bpy.data.objects.new("Intersection test", me)
bpy.context.collection.objects.link(obj)
相关推荐
絆人心2 天前
Python 数据分析核心库:Pandas 与 NumPy 从入门到实战全指南(附电商用户分析完整代码)
python·数据挖掘·数据分析·numpy·pandas·数据处理·电商数据分析
郝学胜-神的一滴2 天前
玩转PyTorch:detach函数破解自动微分张量转numpy难题
人工智能·pytorch·python·深度学习·机器学习·numpy
吃一根烤肠3 天前
NumPy 内置函数与数组运算完全指南
python·numpy
智算菩萨4 天前
【Python图像处理】4 NumPy数组操作与图像矩阵运算
图像处理·python·numpy
数据科学小丫4 天前
数据分析利器 Pandas :apply() 方法 + map() 配对 + 计算描述统计 + 协方差和相关性 + 异常值处理常用方法(基于 python )
python·数据分析·numpy·pandas
理想三旬4 天前
Numpy 数据库
python·机器学习·numpy
β添砖java5 天前
Numpy & Pandas (数据处理教程)(莫烦听课笔记)
numpy·pandas
绛橘色的日落(。・∀・)ノ5 天前
Numpy 第五章 数学函数
numpy
鱼骨不是鱼翅6 天前
Numpy
numpy
乖巧的妹子6 天前
numpy.nan Nan
numpy