import bpy
import math
from mathutils import Vector
# 目標位置を指定する
zion_target = Vector((0, 30, 0))
# ラストフレームを指定する
zion_last_frame = 500
# 速度を計算する関数
def calculate_speed(distance, duration):
return distance / duration
# オブジェクトを作成する関数
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 = zion_last_frame
location = sphere.location
distance = (zion_target - location).length
speed = calculate_speed(distance, zion_last_frame - start_frame)
set_animation(sphere, start_frame, end_frame, zion_target, speed)
import bpy
import math
from mathutils import Vector
# 速度を指定する
zion_speed = 0.5
# 目標位置を指定する
zion_target = Vector((0, -30, 0))
# 平行移動するかどうかを指定する
parallel = False
# 平行移動量を指定する
parallel_distance = Vector((300, 300, 300)) # ここを変更する
# 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 = (x, y, z)
radius = 1
create_sphere(location, radius)
obj = bpy.context.active_object
spheres.append(obj)
# オブジェクトを作成する関数
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)
# アニメーションを設定する
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)
# 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 = (x, y, z)
radius = 1
create_sphere(location, radius)
obj = bpy.context.active_object
spheres.append(obj)
bbb