import bpy
import math
from mathutils import Vector
# 目標位置を指定する
zion_target = Vector((0, 30, 0))
# ラストフレームを指定する
zion_last_frame = 200
# 速度を計算する関数
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 = 1
# 目標位置を指定する
zion_target = Vector((0, 30, 0))
# ラストフレームを指定する
zion_last_frame = 200
# オブジェクトを作成する関数
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 = zion_speed / distance
set_animation(sphere, start_frame, end_frame, zion_target, speed)
目標位置を zion_target =(x,y.z) のように指定できる行を入れたい
zion_target =(0,0,0)
bbb
import bpy
import math
from mathutils import Vector
# 速度を指定する
zion_speed = 1
# 目標位置を指定する
zion_target = Vector((0, 30, 0))
# オブジェクトを作成する関数
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
distance = (zion_target - location).length
speed = zion_speed / distance
set_animation(sphere, start_frame, end_frame, zion_target, speed)
bbb