cone だった
円錐中心位置を cylinder_middle x,y,z
円錐頂点 cylinder_top
円錐底面中心 cylinder_bottom とする
以下を スクリプト冒頭で 数値変更できるようにする
円錐長さ(高さ) 指定 2.0
円錐半径 2.0
円錐頂点位置 xyz=(0,0,0)
import bpy
import math
# 円錐のパラメーター
cone_height = 2.0 # 円錐の高さ
cone_radius = 2.0 # 円錐の半径
cone_top_position = (0, 0, 0) # 円錐の頂点位置
# 円錐の底面中心位置を計算
cone_bottom_position = (cone_top_position[0], cone_top_position[1], cone_top_position[2] - cone_height)
# 円錐を作成
bpy.ops.mesh.primitive_cone_add(radius1=cone_radius, depth=cone_height, location=cone_bottom_position)
# 作成した円錐のオブジェクトを取得
cone_object = bpy.context.active_object
# 円錐の名前を設定
cone_object.name = "Cone"
# 選択をクリア
bpy.ops.object.select_all(action='DESELECT')
# 円錐の頂点を選択
cone_object.select_set(True)
bpy.context.view_layer.objects.active = cone_object
# 円錐の頂点位置を移動
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.transform.translate(value=cone_top_position)
bpy.ops.object.mode_set(mode='OBJECT')
cone_top_position = (0, 0, 0) # 円錐の頂点位置
これから z軸成分
cone_height = 2.0 # 円錐の高さ
これを引き算して
円錐中心を 計算して使う
import bpy
import math
# 円錐のパラメーター
cone_height = 2.0 # 円錐の高さ
cone_radius = 2.0 # 円錐の半径
cone_top_position = (0, 0, 0) # 円錐の頂点位置
# 円錐中心位置の計算
cone_center = (cone_top_position[0], cone_top_position[1], cone_top_position[2] - cone_height/2)
# 円錐を作成
bpy.ops.mesh.primitive_cone_add(radius1=cone_radius, depth=cone_height, location=cone_center)
# 作成した円錐のオブジェクトを取得
cone_object = bpy.context.active_object
# 円錐の名前を設定
cone_object.name = "Cone"
# 選択をクリア
bpy.ops.object.select_all(action='DESELECT')
# 円錐の頂点を選択
cone_object.select_set(True)
bpy.context.view_layer.objects.active = cone_object
# 円錐の頂点位置を移動
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.transform.translate(value=cone_top_position)
bpy.ops.object.mode_set(mode='OBJECT')
円錐中央を 000 二移動して
y軸を回転軸にして 90/360 回転
開店後に 元の位置に戻す
import bpy
import math
# 円錐のパラメーター
cone_height = 2.0 # 円錐の高さ
cone_radius = 2.0 # 円錐の半径
cone_top_position = (0, 0, 0) # 円錐の頂点位置
# 初期の中心位置を計算
initial_center = (cone_top_position[0], cone_top_position[1], cone_top_position[2] - cone_height / 2)
# 回転角度と軸の設定
rotation_angle_degrees = 90 # 回転角度(度)
rotation_axis = 'Y' # 回転軸(X, Y, Z のいずれか)
# 円錐を作成
bpy.ops.mesh.primitive_cone_add(radius1=cone_radius, depth=cone_height, location=cone_top_position)
# 作成した円錐のオブジェクトを取得
cone_object = bpy.context.active_object
# 円錐の名前を設定
cone_object.name = "Cone"
# 円錐の中心位置を保存
initial_cone_center = cone_top_position
# 選択をクリア
bpy.ops.object.select_all(action='DESELECT')
# 円錐のオブジェクトを選択
cone_object.select_set(True)
bpy.context.view_layer.objects.active = cone_object
# 初期中心位置からの相対位置を計算
relative_position = initial_center - initial_cone_center
# 円錐の原点を移動してから回転
bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_VOLUME') # 円錐の中心を原点に設定
if rotation_axis == 'X':
bpy.context.active_object.rotation_euler.x += math.radians(rotation_angle_degrees)
elif rotation_axis == 'Y':
bpy.context.active_object.rotation_euler.y += math.radians(rotation_angle_degrees)
elif rotation_axis == 'Z':
bpy.context.active_object.rotation_euler.z += math.radians(rotation_angle_degrees)
# 初期中心位置に戻す
bpy.context.active_object.location = initial_center
円柱の中心 cylinder_middle
円柱の上面中心が 円錐中心に固定
円柱の中心軸は
円錐の中心軸と いつも重なる
z=-10に
0,0-10を中心にする正方形
20x20 を作って
上面を 濃いGreen
下面を 灰色にして
0,、0,10に太陽を設置して