2023年4月6日木曜日

立方体を作成し、その縦の4つの辺に円柱を配置するBlender Pythonスクリプト

 

















import bpy
import bmesh
from mathutils import Vector

# 立方体の作成
bpy.ops.mesh.primitive_cube_add(size=2)
cube = bpy.context.active_object

# 縦の辺の端点座標
start_points = [(1, 1, -1), (1, -1, -1), (-1, -1, -1), (-1, 1, -1)]
end_points = [(1, 1, 1), (1, -1, 1), (-1, -1, 1), (-1, 1, 1)]

# 円柱の半径と高さ
radius = 0.1
height = 2

# 縦の辺に円柱を配置する
for start, end in zip(start_points, end_points):
    direction = Vector(end) - Vector(start)
    location = (Vector(start) + direction/2).to_tuple()
    length = direction.length
    bpy.ops.mesh.primitive_cylinder_add(radius=radius, depth=length, location=location)
    cylinder = bpy.context.active_object

    # 円柱を回転させる
    up = Vector((0, 0, 1))
    rot_axis = up.cross(direction)
    if rot_axis.length > 0:
        rot_angle = up.angle(direction)
        cylinder.rotation_mode = 'AXIS_ANGLE'
        cylinder.rotation_axis_angle = (rot_axis.to_tuple(), rot_angle)

    # 円柱を親オブジェクトに設定
    cylinder.parent = cube






blender python で 円柱 半径0.1を使って


立方体を描いて

12本の円柱で







blender python で トーラスで半径0.1を使って

正方形を描いて

6つ


位置は 

-30,30,-30

30,30,-30

-30,-30,-30

30,-30,-30 が 1つの正方形


これを立方体の1つの正方形として

残り5つの正方形も描いて


スクリプト全体のコード



改良中 y=-30 中心 円周への球体36個

できた y= -30 中心で z=0平面移動  import bpy import math zion_collection_name = "線路レール 観察者" # コレクションを作成する col = bpy.data.collections.new(zio...