投稿

原型 トーラス円周 3つ y軸 方向

イメージ
  # コレクションを作成 import bpy collection_name = "torus y軸 3つ" if collection_name not in bpy.data.collections:     zionad_collection = bpy.data.collections.new(collection_name)     bpy.context.scene.collection.children.link(zionad_collection) else:     zionad_collection = bpy.data.collections[collection_name] # 3つのトーラス円周 平行移動 離れ度合い調整 import bpy import mathutils import math zion_y_hanare = 1 zion_x_hanare = 0 zion_z_hanare = 0 zion_heikou_idou = (0, 0, 0) # 外接円の半径とトーラスの minor 半径 RADIUS = 1.0 MINOR_RADIUS = 0.05 # トーラスを作成する関数 def create_torus(x, y, z):     # Meshデータの作成     mesh = bpy.data.meshes.new("Torus")     # 頂点を生成する     verts = []     for i in range(32):         theta = 2 * math.pi * i / 32         for j in range(32):             phi = 2 * math.pi * j / 32             x1 = (RADIUS + MINOR_RADIUS * math.cos(...

原型 トーラス円周 3つ x軸 方向

イメージ
import bpy import math import mathutils # 外接円の半径とトーラスの minor 半径 RADIUS = 1.0 MINOR_RADIUS = 0.05 # トーラスを作成する関数 def create_torus(x, y, z):     # Meshデータの作成     mesh = bpy.data.meshes.new("Torus")     # 頂点を生成する     verts = []     for i in range(32):         theta = 2 * math.pi * i / 32         for j in range(32):             phi = 2 * math.pi * j / 32             x1 = (RADIUS + MINOR_RADIUS * math.cos(phi)) * math.cos(theta)             y1 = (RADIUS + MINOR_RADIUS * math.cos(phi)) * math.sin(theta)             z1 = MINOR_RADIUS * math.sin(phi)             verts.append((x1, y1, z1))     # 面を生成する     faces = []     for i in range(32):         for j in range(32):             v1...

原型 立方体を 基準に 3つの平行な正方形

イメージ
  Blender Pythonスクリプトで、y=-1, 0, 1の3つの位置にあるx=0、z=0を中心とした正方形を作成 # コレクションを作成 import bpy collection_name = "正方形 3つ" if collection_name not in bpy.data.collections:     zionad_collection = bpy.data.collections.new(collection_name)     bpy.context.scene.collection.children.link(zionad_collection) else:     zionad_collection = bpy.data.collections[collection_name] import bpy # 正方形の中心 center = (0, 0, 0) # 正方形の大きさ size = 2.0 # 正方形の座標 square_vertices = [     (center[0] - size/2, center[1], center[2] - size/2),     (center[0] + size/2, center[1], center[2] - size/2),     (center[0] + size/2, center[1], center[2] + size/2),     (center[0] - size/2, center[1], center[2] + size/2) ] square_edges = [(0,1), (1,2), (2,3), (3,0)] square_faces = [(0,1,2,3)] # 正方形を作成する関数 def create_square(x, y, z):     # Meshデータの作成     mesh = bpy.data.meshes.new("Square")     # 座標を変換して、正方形をx,y,zの位置に移動     vert...

原型 立方体の対角線 面と立体と 辺長さ 3種類

イメージ
  # コレクションを作成 import bpy # コレクションを作成 collection_name = "円柱" if collection_name not in bpy.data.collections:     zionad_collection = bpy.data.collections.new(collection_name)     bpy.context.scene.collection.children.link(zionad_collection) else:     zionad_collection = bpy.data.collections[collection_name] # A, B, Cそれぞれのコレクションを作成 for c in ["A", "B", "C"]:     child_collection_name = f"{collection_name}_{c}"     if child_collection_name not in bpy.data.collections:         child_collection = bpy.data.collections.new(child_collection_name)         zionad_collection.children.link(child_collection)     else:         child_collection = bpy.data.collections[child_collection_name] 長さで 分けて 2長さと 2√2長さと 2√3長さで オブジェクト名を分類 以下のように、円柱の長さを判定し、オブジェクト名の先頭に"Length_"とつけて、それぞれ"2.0", "2sqrt2", "2sqrt3"に分類して連番をつける 注意点として、円柱の長さは計算誤差があるため、上記のようにabs(distance - 長さ)での比較では、誤差を許容できる範囲内におさまるよう...