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 天前
NumPy深度解析|Python数值计算的基石,告别低效for循环
开发语言·人工智能·python·程序人生·numpy·量化投资
大鹏的NLP博客2 天前
目标检测中的 AP 计算:单调包络与 NumPy 双重翻转
目标检测·numpy·ap
chde2Wang4 天前
numpy学习3
学习·numpy
MoRanzhi12034 天前
第 9 篇 · 数值计算与图像处理:NumPy、SciPy、Pillow
图像处理·python·数值计算·numpy·pillow·信号处理·scipy
chde2Wang4 天前
numpy学习2
学习·numpy
databook5 天前
从循环到向量化:NumPy提速的7个关键思维
python·数据分析·numpy
53488736abcdefg7 天前
Anaconda+Jupyter+NumPy
jupyter·numpy·anaconda
chde2Wang8 天前
numpy学习
numpy·大数据比赛
TechEdu2026068 天前
[人工智能]Python11:NumPy 源代码、软件架构与软件流程
人工智能·numpy
databook10 天前
什么是范数?用 NumPy 动手算一遍就明白了
python·数学·numpy