20240331 テーブル

 

blender 4.0  python

テーブルを 作って

 

 

2x2の テーブル平面 暑さ 0.2

テーブルの脚を4つ 作って 長さ1 

4つの脚は 円柱 半径0.3

 

 

 

 

 

 

 

 

 

import bpy
import math

# コレクションを作成
legs_collection = bpy.data.collections.new("テーブル脚")
bpy.context.scene.collection.children.link(legs_collection)

# 円柱のパラメータ設定
leg_radius = 0.3
leg_height = 1
leg_locations = [(x, y, 0) for x, y in [(-1, -1), (-1, 1), (1, -1), (1, 1)]]  # テーブルの各角に脚を置く

# 円柱を描画し、コレクションに追加
for loc in leg_locations:
    bpy.ops.mesh.primitive_cylinder_add(radius=leg_radius, depth=leg_height, location=loc)
    obj = bpy.context.object
    obj.name = "テーブル脚"
    legs_collection.objects.link(obj)

# 選択をクリア
bpy.ops.object.select_all(action='DESELECT')

 

 

 

数値は変更できるように

冒頭に書き出して

 

円柱の底面高さ cylinder_bottom

円柱の上面高さ cylindeer_top 

で Z軸の値 設定してから

円柱の中心高さを 自動計算して

 

その後にスクリプト実行

 

cylinder_bottom = 0 means  z=0
cylinder_top = 1 means z=1

これから自動計算して

 

leg_height = cylinder_top - cylinder_bottom