球体の動かし 20240424

 

 

blender 4.1 python

変数値となる行は 冒頭に出す

 

"代表_球体半径" =  0.01

main_sphere_radius = "代表_球体半径"

このような形にする

 

 

代表_球体半径 の初期位置は

変数値 (-1,0,0) と (1,0,0)の中間位置とする

 

 

 

代表_球体を 初期位置から 

(5,0,0)へ動かす そこから

(-5,0,0)へ動かす そこから

(0,0,0)へ動かすアニメを作る

 

キーフレーム設定とかも忘れずに

 

 

球体1は 

import bpy
import math

# Define the speed multiplier for desired speeds (adjust as needed)
speed_up = 2.0  # Adjust this value to change the overall speed

# Define the waypoints for each sphere
waypoints = [
    [(0, 0, 0), (3, 0, 0), (0, 0, 0)],     # Waypoints for sphere 1
    [(0, 0, 0), (3, 0, -3), (0, 0, 0)],    # Waypoints for sphere 2
    [(0, 0, 0), (3, 3, -3), (0, 0, 0)]     # Waypoints for sphere 3
]

# Set the representative sphere radius
bpy.context.scene["MainSphereRadius"] = 0.15
main_sphere_radius = bpy.context.scene["MainSphereRadius"]

# Create spheres with different speeds and waypoints
for i, waypoints_list in enumerate(waypoints):
    # Create a sphere and place it at the initial position
    bpy.ops.mesh.primitive_uv_sphere_add(radius=main_sphere_radius, location=(0, 0, 0))
    main_sphere = bpy.context.active_object
    
    # Append speed value to sphere name
    main_sphere.name += f"_Speed{speed_up}".replace(".", "_")
    
    # Animation settings
    frames_per_segment = 200  # Total frames per movement segment
    
    # Calculate the total distance to cover between waypoints
    total_distance = sum(math.sqrt*1
    
    # Calculate the number of frames needed to cover the total distance at the specified speed
    num_frames = int(total_distance / (speed_up * frames_per_segment))
    
    # Set keyframes for sphere movement
    current_frame = 0
    for j in range(len(waypoints_list) - 1):
        start_position = waypoints_list[j]
        end_position = waypoints_list[j + 1]
        
        # Calculate the distance between waypoints
        segment_distance = math.sqrt*2
        
        # Interpolate positions and set keyframes
        for frame in range(segment_frames):
            t = frame / (segment_frames - 1)
            position = (
                start_position[0] + (end_position[0] - start_position[0]) * t,
                start_position[1] + (end_position[1] - start_position[1]) * t,
                start_position[2] + (end_position[2] - start_position[2]) * t
            )
            
            main_sphere.location = position
            main_sphere.keyframe_insert(data_path="location", index=-1, frame=current_frame)
            current_frame += 1
    
    # Set the end frame of the animation
    bpy.context.scene.frame_end = current_frame - 1

# Play the animation
bpy.ops.screen.animation_play()

を2回繰り返す

球体2は

 

 

作り直す

 

「球体x」方向は 経由地を

0,0,0 to 3,0,0 to 0,0,0 to 3,0,0 to 0,0,0

 

「球体xy」方向は 経由地を

0,0,0 to 3,-3,0 to 0,6,0 to 3,9,0 to 0,0,0

 

「球体xyz」方向は 経由地を

0,0,0 to 3,-3,-3 to 0,-6,-6 to 3,-9,-0 to 0,0,0

 

 

 

「球体x」が 経由地それぞれを通過するフレーム時に

その他の球体が それぞれの経由地を同時通過する

 

だから 経由地と経由地の距離から 表示移動速度を計算して

描画する

*1:waypoints_list[j+1][0] - waypoints_list[j][0])**2 +
                                   (waypoints_list[j+1][1] - waypoints_list[j][1])**2 +
                                   (waypoints_list[j+1][2] - waypoints_list[j][2])**2)
                         for j in range(len(waypoints_list) - 1

*2:end_position[0] - start_position[0])**2 +
                                     (end_position[1] - start_position[1])**2 +
                                     (end_position[2] - start_position[2])**2)
        
        # Calculate the number of frames needed for this segment
        segment_frames = int(segment_distance / (speed_up * frames_per_segment