、中心が(0, -30, 0)にある円周上に36個の球体を作成し、それらを中心点に向かって移動させるものです。
このスクリプトを実行すると、中心が(0, -30, 0)にある円周上に36個の球体が作成され、それらが中心点に向かって移動します。移動に使用される速度は、距離に比例して調整されています。また、アニメーションのフレーム数は100に設定されていますが、必要に応じて変更することができます。
y=-30の xy平面の円周のママ
import bpy
import math
from mathutils import Vector
# Set sphere radius and segments
sphere_radius = 1
sphere_segments = 32
# Set the number of spheres to create
num_spheres = 36
# Set the radius of the circle and the height of the center point
circle_radius = 30
center_height = -30
# Calculate the angle between each sphere
angle_between_spheres = math.radians(360 / num_spheres)
# Create sphere objects and set locations
for i in range(num_spheres):
# Calculate the location of the sphere on the circle
x = circle_radius * math.cos(angle_between_spheres * i)
y = center_height
z = circle_radius * math.sin(angle_between_spheres * i)
location = Vector((x, y, z))
# Create a sphere and set its location
bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, segments=sphere_segments)
sphere = bpy.context.object
sphere.location = location
sphere.name = f"Sphere_{i}"
# Set animation keyframes
last_frame = 100
for frame in range(last_frame+1):
distance = (location - Vector((0, center_height, 0))).length
if distance > 0.01:
direction = (Vector((0, center_height, 0)) - location).normalized()
sphere.location += direction * min(0.1 * distance, 1.0)
sphere.keyframe_insert(data_path="location", frame=frame)
-60円周から -30 収束 y軸になったもの
調整速度があっていないだろう
import bpy
import math
from mathutils import Vector
# Set initial locations
initial_locations = []
for i in range(0, 360, 10):
x = 30 * math.cos(math.radians(i))
y = -30
z = 30 * math.sin(math.radians(i))
initial_locations.append(Vector((x, y, z)) + Vector((0, -30, 0))) # 中心を変更
# Set sphere radius and segments
sphere_radius = 1
sphere_segments = 32
# Calculate speeds based on initial distances from target
chousei_kijyun = 30
distances = [loc.length for loc in initial_locations]
speeds = [0.1 * (chousei_kijyun / distance) if distance > 0 else 0 for distance in distances]
# Create sphere objects and set locations
for i, initial_location in enumerate(initial_locations):
bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, segments=sphere_segments)
sphere = bpy.context.object
sphere.location = initial_location
sphere.name = f"Sphere_{i}"
# Set animation keyframes
last_frame = 1000
for frame in range(last_frame+1):
distance = (initial_location - Vector((0, -30, 0))).length
if distance > 0.01:
direction = (Vector((0, -30, 0)) - initial_location).normalized()
sphere.location += direction * min(speeds[i], distance)
sphere.keyframe_insert(data_path="location", frame=frame)
# Function to set the number of frames
def set_frame_range(start_frame, end_frame):
bpy.context.scene.frame_start = start_frame
bpy.context.scene.frame_end = end_frame
# Example: set the number of frames to 1000
set_frame_range(1, 1000)