import bpy
import math
from mathutils import Vector
# 速度を指定する
zion_speed = 0.5
# 目標位置を指定する
zion_target = Vector((0, 100, 0))
# 平行移動するかどうかを指定する
parallel = True
# 平行移動量を指定する
parallel_distance = Vector((20, 30, 10)) # ここを変更する
# オブジェクトを作成する関数
def create_sphere(location, radius):
bpy.ops.mesh.primitive_uv_sphere_add(location=location, radius=radius)
# アニメーションを設定する関数
def set_animation(obj, start_frame, end_frame, target_location, speed):
distance = (target_location - obj.location).length
duration = distance / speed
for frame in range(start_frame, end_frame+1):
t = (frame - start_frame) / duration
obj.location = obj.location.lerp(target_location, t)
obj.keyframe_insert(data_path="location", frame=frame)
# 16個の球体を作成する
spheres = []
for i in range(16):
angle = 2 * i * math.pi / 16
x = 30 * math.cos(angle)
y = 30 * math.sin(angle)
z = 0
location = Vector((x, y, z))
radius = 1
create_sphere(location, radius)
obj = bpy.context.active_object
spheres.append(obj)
# アニメーションを設定する
for i, sphere in enumerate(spheres):
start_frame = 1
end_frame = 250
location = sphere.location
if parallel:
target_location = location + parallel_distance
else:
target_location = zion_target
distance = (target_location - location).length
speed = zion_speed / distance
set_animation(sphere, start_frame, end_frame, target_location, speed)
import bpy
import math
from mathutils import Vector
# 速度を指定する
zion_speed = 0.5
# 目標位置を指定する
zion_target = Vector((0, 100, 0))
# 平行移動するかどうかを指定する
parallel = False
# 平行移動量を指定する
parallel_distance = Vector((20, 100, 0)) # ここを変更する
# 新しいパラメータを指定する
num_spheres = 11 # 球体の数
radius = 1 # 球体の半径
spacing = 6 # 球体の間隔
# オブジェクトを作成する関数
def create_sphere(location, radius):
bpy.ops.mesh.primitive_uv_sphere_add(location=location, radius=radius)
# アニメーションを設定する関数
def set_animation(obj, start_frame, end_frame, target_location, speed):
distance = (target_location - obj.location).length
duration = distance / speed
for frame in range(start_frame, end_frame+1):
t = (frame - start_frame) / duration
obj.location = obj.location.lerp(target_location, t)
obj.keyframe_insert(data_path="location", frame=frame)
# 球体を作成する
spheres = []
for i in range(num_spheres):
x = -30 + spacing * i
y = 0
z = 0
location = Vector((x, y, z))
create_sphere(location, radius)
obj = bpy.context.active_object
spheres.append(obj)
# アニメーションを設定する
for i, sphere in enumerate(spheres):
start_frame = 1
end_frame = 250
location = sphere.location
if parallel:
target_location = location + parallel_distance
else:
target_location = zion_target
distance = (target_location - location).length
speed = zion_speed / distance
set_animation(sphere, start_frame, end_frame, target_location, speed)
bbb