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)
相关推荐
广州景颐光电4 天前
3种NumPy向量化实测:光源数据处理从2.3秒压到12.3ms
numpy
梅雅达编程笔记5 天前
零基础学 Python 第14章 | 模块、包与第三方库
开发语言·python·django·numpy·pandas
梅雅达编程笔记5 天前
零基础学 Python 第15章 | 类与对象:面向对象编程入门
开发语言·python·django·numpy·pandas
pulinzt6 天前
Tableau的基础使用
数据库·numpy
梅雅达编程笔记7 天前
编程启蒙|Scratch 转 Python 系列第9天:字典/哈希表积木双向对照(AI大模型参数配置表实战)
开发语言·人工智能·python·numpy·pandas
汤姆小白9 天前
08-应用部署
人工智能·python·机器学习·numpy·transformer
汤姆小白10 天前
02-Tokenizer原理与实现
人工智能·python·机器学习·numpy
汤姆小白10 天前
01-环境搭建与项目导览
人工智能·python·机器学习·numpy
CS创新实验室11 天前
NumPy数组的C风格和Fortran风格
c语言·开发语言·numpy
梅雅达编程笔记11 天前
零基础学 Python 第7章 | 字典 dict:键值对存储
开发语言·python·beautifulsoup·numpy·pandas