成功 Z軸90度回転
import bpy
import math
# 円柱の高さ
height = 1.0
# 円板を配置する位置
disk_locations = [
(30.0, 0.0, 0.0),
(30.0, 0.0, 15.0),
(30.0, 0.0, -15.0),
(30.0, -15.0, 0.0),
(30.0, 15.0, 0.0)
]
# Z軸に回転するかどうかのフラグ
rotate_enabled = True
# 5つの円柱を生成する
for i, location in enumerate(disk_locations):
# 円柱を生成する
bpy.ops.mesh.primitive_cylinder_add(radius=15.0, depth=height, location=location)
if rotate_enabled:
# 円柱を回転する
bpy.context.object.rotation_euler = (math.pi/2, 0, math.pi/2)
# オブジェクト名を設定する
bpy.context.object.name = f"Disk_{i+1}"
成功2? z と y
import bpy
import math
disk_locations = [
(30.0, 0.0, 0.0),
(30.0, 0.0, 15.0),
(30.0, 0.0, -15.0),
(30.0, -15.0, 0.0),
(30.0, 15.0, 0.0)
]
for i, loc in enumerate(disk_locations):
# create cylinder
bpy.ops.mesh.primitive_cylinder_add(
vertices=32,
radius=15.0,
depth=2.0,
location=loc
)
# rotate around z-axis by 90 degrees
bpy.context.active_object.rotation_euler[2] = math.radians(90)
# rotate around y-axis by 90 degrees
bpy.context.active_object.rotation_euler[1] = math.radians(90)
# rename object
bpy.context.active_object.name = f"enban{i+1}"
# 円板を配置する位置と回転角度
disk_locations = [
(30.0, 0.0, 0.0), # 1つ目の円板はx=30に配置
(0.0, 0.0, 30.0), # 2つ目の円板はz=30に配置
(0.0, -30.0, 0.0), # 3つ目の円板はy=-30に配置
(-30.0, 0.0, 0.0), # 4つ目の円板はx=-30に配置
(0.0, 0.0, -30.0) # 5つ目の円板はz=-30に配置
]
円板を配置する位置
(30.0, 0.0, 0.0),
(30.0, 0.0, 15.0),
(30.0, 0.0, -15.0)
(30.0, -15.0, 0.0),
(30.0, 15.0, 0.0),
以下を参考 同じに blender python 常にスクリプト全文を書いて
bpy.context.object.location[0] = -30.0 # X座標
bpy.context.object.location[1] = 0.0 # Y座標
bpy.context.object.location[2] = 15.0 # Z座標
bpy.context.object.location[0] = -30.0 # X座標
bpy.context.object.location[1] = 15.0 # Y座標
bpy.context.object.location[2] = 0.0 # Z座標
bpy.context.object.location[0] = -30.0 # X座標
bpy.context.object.location[1] = -15.0 # Y座標
bpy.context.object.location[2] = 0.0 # Z座標
bpy.context.object.location[0] = -30.0 # X座標
bpy.context.object.location[1] = 0.0 # Y座標
bpy.context.object.location[2] = -15.0 # Z座標
bpy.context.object.location[0] = 0.0 # X座標
bpy.context.object.location[1] = 0.0 # Y座標
bpy.context.object.location[2] = 0.0 # Z座標
5つの円板を書いて
5つの位置は 今書いた位置で
参考にしたスクリプトの位置は 見本だから無視して
スクリプト内の回転の指示は そのまま守って
5つの円板の オブジェクト名を連番で作って
冒頭に配置して
import bpy
import math
#円柱を作成する
bpy.ops.mesh.primitive_cylinder_add(radius=15, depth=0)
#作成されたオブジェクトを取得する
obj = bpy.context.object
#オブジェクトの位置を変更する
obj.location = (0, 0, 15)
#オブジェクトを選択状態にする
bpy.context.view_layer.objects.active = obj
import bpy
from math import radians
# 回転させる軸を選択する
zion_xyz = 'xana'
# オブジェクトに名前を付ける
bpy.context.object.name = "えんばん光時計"
# 円錐の位置を変更する
bpy.context.object.location[0] = -30.0 # X座標
bpy.context.object.location[1] = 0.0 # Y座標
bpy.context.object.location[2] = 0.0 # Z座標
if zion_xyz == 'xana':
# 軸を中心に90度回転させる
bpy.context.object.rotation_euler[0] = radians(0)
bpy.context.object.rotation_euler[1] = radians(90)
bpy.context.object.rotation_euler[2] = radians(0)
# X軸方向に伸ばす
bpy.context.object.scale[0] = 1
bpy.context.object.scale[1] = 1
bpy.context.object.scale[2] = 1
elif zion_xyz == 'yana':
# 軸を中心に90度回転させる
bpy.context.object.rotation_euler[0] = radians(90)
bpy.context.object.rotation_euler[1] = radians(0)
bpy.context.object.rotation_euler[2] = radians(0)
# Y軸方向に伸ばす
bpy.context.object.scale[0] = 1
bpy.context.object.scale[1] = 1
bpy.context.object.scale[2] = 1
elif zion_xyz == 'zana':
# Z軸を中心に90度回転させる
bpy.context.object.rotation_euler[0] = radians(0)
bpy.context.object.rotation_euler[1] = radians(0)
bpy.context.object.rotation_euler[2] = radians(0)
# Z軸方向に伸ばす
bpy.context.object.scale[0] = 1
bpy.context.object.scale[1] = 1
bpy.context.object.scale[2] = 1
else:
print('Invalid rotation axis selected.')
# Set the speed multiplier
vvv_velocity = 0.01 # 現在の速度調整
# Set start and end frames
start_frame = 1
end_frame = start_frame + 600
# Define the start and end positions
start_pos = (30.0, 0.0, 15.0)
end_pos = (-30.0, 0.0, 15.0)
# Calculate the distance between start_pos and end_pos
distance = abs(math.sqrt((end_pos[0]-start_pos[0])**2 + (end_pos[1]-start_pos[1])**2 + (end_pos[2]-start_pos[2])**2))
chousei = 1 / distance # 斜め進みと flame の関係?
# Calculate the velocity required to move the sphere at a constant speed
velocity = (end_frame - start_frame) * vvv_velocity * chousei
# Move the sphere and cylinder from start_pos to end_pos at a constant speed
for i in range(start_frame, end_frame + 1):
bpy.context.scene.frame_set(i)
bpy.context.object.location = tuple(s + (e-s)*((i-start_frame)*velocity/distance) for s,e in zip(start_pos, end_pos))
bpy.context.object.keyframe_insert(data_path="location", index=-1)
bpy.context.object.keyframe_insert(data_path="scale", index=-1)
# Stop the sphere and cylinder from moving after reaching the end position
bpy.context.scene.frame_set(end_frame)
bpy.context.object.keyframe_insert(data_path="location", index=-1)
bpy.context.object.keyframe_insert(data_path="scale", index=-1)
# Set the waiting period
wait_frames = 30
end_frame += wait_frames
# Set the current frame to the end_frame
current_frame = end_frame
# Keep the sphere and cylinder at the end position and repeat the animation
repeat_frames = end_frame + 200
while True:
current_frame += 1
# Insert a keyframe at the current frame for the sphere and cylinder's location and scale
bpy.context.scene.frame_set(current_frame)
bpy.context.object.location = end_pos
bpy.context.object.keyframe_insert(data_path="location", index=-1)
bpy.context.object.keyframe_insert(data_path="scale", index=-1)
# Stop the loop if current_frame reaches repeat_frames
if current_frame == repeat_frames:
break
# Add a camera and set its position
cam_data = bpy.data.cameras.new('Camera')
cam_data.lens = 600.0 # set focal length to 50mm (zoomed in)
cam = bpy.data.objects.new('Camera', cam_data)
bpy.context.scene.collection.objects.link(cam)
cam.location = (0.0, -30.0, 0.0)
cam.name = "Cam_upper_えんばん光時計"
# Add a track constraint to the camera to follow the sphere
track_constraint = cam.constraints.new(type='TRACK_TO')
track_constraint.target = bpy.context.object
track_constraint.track_axis
# import bpy
# アクティブなシーンを取得する
scene = bpy.context.scene
# 開始フレームを1に設定する
scene.frame_start = 1
# 終了フレームを640に設定する
scene.frame_end = 640
bbb