2023年4月8日土曜日

カメラ付きの テスト 速度 揃え 速度一定

 


import bpy

import math


zion_collection_name = "速度一定 Sphere Z軸"


# コレクションを作成する


col = bpy.data.collections.new(zion_collection_name)

bpy.context.scene.collection.children.link(col)


一応の完成





import bpy

import math

from mathutils import Vector


# 目標位置を指定する

target_location = Vector((-30, 0, 0))


# 初期位置のリスト

initial_locations = [

    Vector((0, 0, 30)),

    Vector((0, 0, 15)),

    Vector((0, 0, 0)),

    Vector((0, 0, -15)),

    Vector((0, 0, -30))

]


# 初期位置との距離から速度を計算する

chousei_kijyun = 30

distances = [math.sqrt(sum([(a - b) ** 2 for a, b in zip(loc, target_location)])) for loc in initial_locations]

speeds = [0.1 for _ in range(len(distances))]


# 球体の作成と初期位置の設定

bpy.ops.object.empty_add(type='PLAIN_AXES')

empty = bpy.context.object

for index, loc in enumerate(initial_locations):

    sphere = bpy.ops.mesh.primitive_uv_sphere_add(radius=1, location=loc)

    obj = bpy.context.object

    obj.name = f"Sphere {index+1}"

    obj.parent = empty


# アニメーションの作成

last_frame = 600

for frame in range(last_frame+1):

    for obj in empty.children:

        if obj.name.startswith("Sphere"):

            distance = (target_location - obj.location).length

            if distance > 0.01:

                direction = (target_location - obj.location).normalized()

                obj.location += direction * min(speeds[int(obj.name[-1])-1], distance)

                obj.keyframe_insert(data_path="location", frame=frame)



import bpy

# フレーム数を変更するための関数
def set_frame_range(start_frame, end_frame):
    bpy.context.scene.frame_start = start_frame
    bpy.context.scene.frame_end = end_frame

# メイン関数
def main():
    # フレームレンジを設定する
    set_frame_range(1, 640)

# スクリプトを実行する
if __name__ == "__main__":
    main()





改良中 y=-30 中心 円周への球体36個

できた y= -30 中心で z=0平面移動  import bpy import math zion_collection_name = "線路レール 観察者" # コレクションを作成する col = bpy.data.collections.new(zio...