Blender mesh 创建点线面 uOQ-CPcaqMo AxazJi3x6js
任务:创建一个半径为2圆环,圆环上均布32个点,显示为点或者线。
1. 点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| import bpy
import math
import pprint
vert_count = 32 angle_step = math.tau / vert_count radius = 2
vert_coordinates = list()
for i in range(vert_count):
current_angle = angle_step * i
x = radius * math.cos(current_angle) y = radius * math.sin(current_angle)
bpy.ops.mesh.primitive_ico_sphere_add(radius=0.05, location=(x, y, 0))
vert_coordinates.append((x, y, 0))
pprint.pprint(vert_coordinates)
|
2. 线
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| import bpy
import math import pprint
def get_circle_verts(vert_count, radius): angle_step = math.tau / vert_count
vert_coordinates = list()
for i in range(vert_count):
current_angle = angle_step * i
x = radius * math.cos(current_angle) y = radius * math.sin(current_angle)
vert_coordinates.append((x, y, 0))
return vert_coordinates
def create_circle_mesh(coordinates, vert_count): verts = coordinates faces = [] edges = []
for i in range(vert_count - 1): current_vert_index = i next_vert_index = i + 1 edges.append((current_vert_index, next_vert_index))
edges.append((vert_count - 1, 0))
mesh_data = bpy.data.meshes.new("circle_data") mesh_data.from_pydata(verts, edges, faces)
mesh_obj = bpy.data.objects.new("circle_object", mesh_data)
bpy.context.collection.objects.link(mesh_obj)
vert_count = 32 radius = 2
coordinates = get_circle_verts(vert_count, radius)
mesh_obj = create_circle_mesh(coordinates, vert_count)
|
Final Code:
circle_mesh_part_1 https://gist.github.com/CGArtPython/6e98beb424b6c58bbda0469b2c0434a9
circle_mesh_part_2 https://gist.github.com/CGArtPython/a4dff81d8c233601759dffd48917f296
ref:
Beginner Blender Python Exercise: Circle mesh from scratch
https://www.youtube.com/watch?v=uOQ-CPcaqMo
https://www.youtube.com/watch?v=AxazJi3x6js