2023年4月11日火曜日

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


できた y= -30 中心で z=0平面移動 


import bpy

import math


zion_collection_name = "線路レール 観察者"


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

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

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




import bpy

import math


zion_collection_name = "土台"


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

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

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



boolean

https://shion-no-yahiro.com/boolean/




y=0 で たぶん 円周への放出 成功

 このスクリプトは、z=0平面上にある半径30の円周の中心を放出位置として、36個の球体を放出します。また、放出された球体は、z=0平面上の円周上を等速で移動します。ただし、放出する球体の速度は、放出位置から円周の中心までの距離に反比例するように決定されます。また、アニメーションのフレーム数は1000フレームに設定されています。



import bpy

import math

from mathutils import Vector


# Set initial locations

radius = 30

initial_locations = []

for i in range(36):

    angle = math.radians(i * 10)

    x = radius * math.cos(angle)

    y = radius * math.sin(angle)

    z = 0

    initial_locations.append(Vector((x, y, z)))


# 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, 0, 0))).length

        if distance > 0.01:

            direction = (Vector((0, 0, 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)







中心を 000にして  (Vector((0, -30, 0)) - initial_location) 失敗


、中心が(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)





2023年4月10日月曜日

y=-30 から 円周状(じょう)に 放出 球体

 



Sure! Here's the modified script to set the emission point (0, -30, 0) as the center of a circle and emit 36 sphere objects with a radius of 1, located at equal intervals of 10 degrees on the circumference of the circle, with the same speed as in the original script:


x軸とz軸を交換する部分を含めたスクリプトの例です。







y= -30 kara 球体





import bpy

import math

from mathutils import Vector


# Set target location

target_location = Vector((0, 0, 0))


# Set initial locations

initial_locations = [Vector((0, -30, 0))]


# Set sphere radius and segments

sphere_radius = 2

sphere_segments = 32


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

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 * (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


    if i == 0:

        sphere.name = "1秒前 x0方向"

    else:

        sphere.name = "Real ball x=+60"


    # Set animation keyframes

    last_frame = 1000

    for frame in range(last_frame+1):

        distance = (target_location - sphere.location).length


        if distance > 0.01:

            direction = (target_location - sphere.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)








import bpy

import math

from mathutils import Vector



# Set target location

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



# Set initial locations

initial_locations = [Vector((0, -30, 0))]



# Set sphere radius and segments

sphere_radius = 2

sphere_segments = 32



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

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 * (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



    if i == 0:

        sphere.name = "1秒前 x -30方向"

    else:

        sphere.name = "Real ball x=+60"



    # Set animation keyframes

    last_frame = 1000

    for frame in range(last_frame+1):

        distance = (target_location - sphere.location).length



        if distance > 0.01:

            direction = (target_location - sphere.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)










import bpy

import math

from mathutils import Vector



# Set target location

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



# Set initial locations

initial_locations = [Vector((0, -30, 0))]



# Set sphere radius and segments

sphere_radius = 2

sphere_segments = 32



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

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 * (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



    if i == 0:

        sphere.name = "1秒前 x +30方向"

    else:

        sphere.name = "Real ball x=+60"



    # Set animation keyframes

    last_frame = 1000

    for frame in range(last_frame+1):

        distance = (target_location - sphere.location).length



        if distance > 0.01:

            direction = (target_location - sphere.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)





ファイルから アニメ 再生 可能になったみたい その原型

 


import bpy

import math

from mathutils import Vector


# Set target location

target_location = Vector((0, 0, 60))


# Set initial location and radius

initial_location = Vector((0, 0, 0))

sphere_radius = 2


# Create sphere object

bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, location=initial_location)

sphere = bpy.context.object


# Set animation keyframes

start_frame = 1

end_frame = 600

for frame in range(start_frame, end_frame+1):

    # Calculate angle based on current frame

    angle = (frame - start_frame) * 2 * math.pi / 200


    # Calculate new sphere location

    x = target_location.x + sphere_radius * math.cos(angle)

    y = target_location.y + sphere_radius * math.sin(angle)

    z = target_location.z

    sphere.location = Vector((x, y, z))


    # Set rotation

    sphere.rotation_euler[2] = angle


    # Insert keyframe

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

    sphere.keyframe_insert(data_path="rotation_euler", frame=frame)


# Set the number of frames

bpy.context.scene.frame_start = start_frame

bpy.context.scene.frame_end = end_frame


アニメが 再生する方法 検討と 半径 球体が 球体を回る 


# アニメーションを再生する

import bpy

bpy.ops.screen.animation_play()


bpy.ops.screen.animation_play()は、BlenderのGUIからの操作をエミュレートするためのコマンドであり、バッチ処理で使用することはできません。代わりに、以下のようにPythonコードでアニメーションを再生することができます。


import bpy


# アニメーションの再生範囲を設定

bpy.context.scene.frame_start = 1

bpy.context.scene.frame_end = 100


# アニメーションを再生

for frame in range(bpy.context.scene.frame_start, bpy.context.scene.frame_end + 1):

    bpy.context.scene.frame_set(frame)


このコードでは、frame_startとframe_endでアニメーションの再生範囲を設定し、forループで各フレームの処理を行うことでアニメーションを再生しています。これを使って、あなたのアニメーションを再生することができます。


x^2+y^2+z^2 = zion_distance

 


blender python で frame 毎に 進む距離を

x^2+y^2+z^2 = zion_distance 

と定義して Pythonスクリプト



Blender Pythonで、

各フレームでオブジェクトを移動する距離を

zion_distanceで定義し、

その距離だけオブジェクトを移動するスクリプト




import bpy

from mathutils import Vector


# 初期位置を取得

start_pos = bpy.context.active_object.location

# 初期フレームを取得

start_frame = bpy.context.scene.frame_current


def move_object():

    # 現在のフレームを取得

    current_frame = bpy.context.scene.frame_current

    # オブジェクトを移動する距離を計算

    zion_distance = (current_frame - start_frame)**2

    # 移動ベクトルを作成

    move_vector = Vector((zion_distance, zion_distance, zion_distance))

    # オブジェクトを移動

    bpy.context.active_object.location = start_pos + move_vector


# フレームを進める

for frame in range(start_frame, bpy.context.scene.frame_end+1):

    bpy.context.scene.frame_set(frame)

    move_object()


Blender Pythonでx^2+y^2+z^2 = r^2の球体を、

フレーム0から600で拡大するスクリプト


-30 y から 線路レールへの リアルボール テスト

動いた




 import bpy

from mathutils import Vector


# Set sphere radius

sphere_radius = 1


# Set target location

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


# Set initial location and movement direction for sphere

initial_location = Vector((0, 0, 0))

movement_direction = (target_location - initial_location).normalized()


# Create sphere and set location

bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius)

sphere = bpy.context.object

sphere.name = "Sphere"

sphere.location = initial_location


# Animate sphere

num_frames = 1000

movement_speed = 0.1

for frame in range(num_frames):

    distance = (target_location - sphere.location).length

    if distance > 0.01:

        direction = movement_direction

        sphere.location += direction * min(movement_speed, distance)

        sphere.keyframe_insert(data_path="location", frame=frame+1)





2023年4月9日日曜日

円柱 複数改造

 


import bpy

import math


zion_collection_name = "光時計たくさん"


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

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

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



import bpy

import math

zion_collection_name = "土台"

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

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

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

電車列車から見える 円柱 複数も

光時計 たくさん



import bpy

import math


zion_collection_name = "光時計たくさん"


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

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

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



import bpy

import math

zion_collection_name = "土台"

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

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

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





円錐 りんごの木

import bpy

import math

from mathutils import Vector

from math import radians


# Create collection

zion_collection_name = "cone"

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

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


# Set target location

target_location = Vector((-600, 0, 30)) # heiko idou taksa


# Set initial location

initial_locations = [Vector((0, 0, 30))]


# Set cone properties

cone_radius = 60

cone_depth = 60


# Calculate speeds based on initial distances

chousei_kijyun = 60

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

speeds = [0.1 * distance / chousei_kijyun if distance > 0 else 0 for distance in distances]


# Create cone objects and set locations

for i, initial_location in enumerate(initial_locations):

    bpy.ops.mesh.primitive_cone_add(radius1=cone_radius, radius2=0, depth=cone_depth)

    cone = bpy.context.object

    cone.location = initial_location

    cone.name = "cone"


    # Rotate cone by 180 degrees around the x-axis

    cone.rotation_euler.rotate_axis('X', radians(0))


    # Set animation keyframes

    last_frame = 600

    for frame in range(last_frame+1):

        distance = (target_location - cone.location).length

        if distance > 0.01:

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

            cone.location += direction * min(speeds[i], distance)

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


# 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)


2023年4月8日土曜日

円錐平行 移動 線路も 移動で 座標系の 動きを再現の一歩

逆さ円錐 動く 再生でも 位置修正中




import bpy

from mathutils import Vector


# 設定可能な変数

zion_object_name = "逆さ円錐 600上昇"  # 円錐オブジェクトの名前

radius = 60  # 円錐の半径

height = 60  # 円錐の高さ

distance_per_frame = 0.1  # 円錐の移動距離

animation_frames = 1000  # アニメーションの再生時間(フレーム数)

wait_frames = 40  # アニメーション再生完了後の待機時間(フレーム数)

zion_stop =600 * 0.1

zion_saibyouga = 30


# 円錐を作成する

def create_cone():

    bpy.ops.mesh.primitive_cone_add(radius1=0, radius2=radius, depth=height)

    cone = bpy.context.object

    cone.name = zion_object_name

    cone.location = Vector((0, 0, 0))  # 初期位置を設定する


 


# アニメーションのキーフレームを設定する

for i in range(animation_frames):

    frame = i + 1


    # キーフレームごとの円錐の位置を設定する

    zion_pos = Vector((0, 0, (i+1)*distance_per_frame))

    cone.location = zion_pos


    # キーフレームを設定する

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


# アニメーション再生後の待機時間を設定する

for i in range(wait_frames):

    frame = animation_frames + i + 1

    cone.keyframe_insert(data_path="location", frame=frame, index=-1)


Real ball kaizouchu

 


import bpy

import math


zion_collection_name = "Real ball"


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

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

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







import bpy

import math

from mathutils import Vector


# Set target location

target_location = Vector((0, 0, 60))


# Set initial locations

initial_locations = [Vector((-30, 0, 0)), Vector((30, 0, 0))]


# Set sphere radius and segments

sphere_radius = 2

sphere_segments = 32


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

chousei_kijyun = 60

distances = [math.sqrt(sum([(a - b) ** 2 for a, b in zip(loc, target_location)])) 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


    if i == 0:

        sphere.name = "Real ball x=-30"

    else:

        sphere.name = "Real ball x=+30"


    # Set animation keyframes

    last_frame = 1000

    for frame in range(last_frame+1):

        distance = (target_location - sphere.location).length


        if distance > 0.01:

            direction = (target_location - sphere.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)


線路レール用の円柱





import bpy

import math

from mathutils import Vector

from math import radians


zion_collection_name = "cylinder "


# Create the collection

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

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


# Set target location

target_location = Vector((0, 0, 60))


# Set initial locations

initial_locations = [ Vector((0, 0, 0))]


# Set cylinder properties

cylinder_radius = 1

cylinder_depth = 120


# Calculate speeds based on initial distances

chousei_kijyun = 60

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

speeds = [0.1 * distance / chousei_kijyun if distance > 0 else 0 for distance in distances]


# Create cylinder objects and set locations

for i, initial_location in enumerate(initial_locations):

    bpy.ops.mesh.primitive_cylinder_add(radius=cylinder_radius, depth=cylinder_depth)

    cylinder = bpy.context.object

    cylinder.location = initial_location

    cylinder.name = "線路 rail"


    # Rotate cylinder by 90 degrees around the y-axis

    cylinder.rotation_euler.rotate_axis('Y', radians(90))


    # Set animation keyframes

    last_frame = 600

    for frame in range(last_frame+1):

        distance = (target_location - cylinder.location).length

        if distance > 0.01:

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

            cylinder.location += direction * min(speeds[i], distance)

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


# 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)


幻 球体




import bpy

import math

from mathutils import Vector


# Set target location

target_location = Vector((0, 0, 60))


# Set initial locations

initial_locations = [Vector((-30, 0, 0)), Vector((30, 0, 0))]


# Set sphere radius and segments

sphere_radius = 2

sphere_segments = 32


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

chousei_kijyun = 60

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

speeds = [0.1 * distance / chousei_kijyun 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


    if i == 0:

        sphere.name = "幻 ball x=-30"

    else:

        sphere.name = "幻 ball x=+30"


    # Set animation keyframes

    last_frame = 600

    for frame in range(last_frame+1):

        distance = (target_location - sphere.location).length


        if distance > 0.01:

            direction = (target_location - sphere.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)


追いつかない トーラス

 




import bpy

import math

from mathutils import Vector


# Set target location

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


# Set initial locations

initial_locations = [ Vector((0, 0, -34))]


# Set torus properties

torus_major_radius = 60

torus_minor_radius = 2


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

chousei_kijyun = 60

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

speeds = [0.1 * distance / chousei_kijyun if distance > 0 else 0 for distance in distances]


# Create torus objects and set locations

for i, initial_location in enumerate(initial_locations):

    bpy.ops.mesh.primitive_torus_add(major_radius=torus_major_radius, minor_radius=torus_minor_radius)

    torus = bpy.context.object

    torus.location = initial_location



torus = bpy.context.object

torus.name = "torus 追いつかない"



    # Set animation keyframes

last_frame = 600

    for frame in range(last_frame+1):

        distance = (target_location - torus.location).length

        if distance > 0.01:

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

            torus.location += direction * min(speeds[i], distance)

            torus.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


# 例: フレーム数を100に変更する場合

set_frame_range(1, 1000)





2つのトーラス frame 600 で 追いつく






import bpy

import math

from mathutils import Vector


# Set target location

target_location = Vector((0, 0, 60))


# Set initial locations

initial_locations = [Vector((0, 0, 0)), Vector((0, 0, -30))]


# Set torus properties

torus_major_radius = 60

torus_minor_radius = 1


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

chousei_kijyun = 60

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

speeds = [0.1 * distance / chousei_kijyun if distance > 0 else 0 for distance in distances]


# Create torus objects and set locations

for i, initial_location in enumerate(initial_locations):

    bpy.ops.mesh.primitive_torus_add(major_radius=torus_major_radius, minor_radius=torus_minor_radius)

    torus = bpy.context.object

    torus.location = initial_location


    # Set animation keyframes

    last_frame = 600

    for frame in range(last_frame+1):

        distance = (target_location - torus.location).length

        if distance > 0.01:

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

            torus.location += direction * min(speeds[i], distance)

            torus.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


# 例: フレーム数を100に変更する場合

set_frame_range(1, 1000)




再生anime 可能 円錐からトーラス改良中

import bpy

import math

from mathutils import Vector


# Set target location

target_location = Vector((0, 0, 60))


# Set initial locations

initial_locations = [Vector((0, 0, -30)), Vector((0, 10, -30)), Vector((10, 0, -30)), Vector((0, -10, -30)), Vector((-10, 0, -30))]


# Set torus properties

torus_major_radius = 30

torus_minor_radius = 10


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

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 * distance / chousei_kijyun if distance > 0 else 0 for distance in distances]


# Create torus objects and set locations

for i, initial_location in enumerate(initial_locations):

    bpy.ops.mesh.primitive_torus_add(major_radius=torus_major_radius, minor_radius=torus_minor_radius)

    torus = bpy.context.object

    torus.location = initial_location


    # Set animation keyframes

    last_frame = 600

    for frame in range(last_frame+1):

        distance = (target_location - torus.location).length

        if distance > 0.01:

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

            torus.location += direction * min(speeds[i], distance)

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


再生アニメ ファイルからでも 動く 原型 らしい

 


import bpy

from mathutils import Vector

import math


# Set target location

target_location = Vector((0, 0, 60))


# Set initial location

initial_location = Vector((60, 0, 0))


# Set sphere properties

radius = 2


# Calculate the distance between the target location and the initial location

distance = (target_location - initial_location).length


# Calculate the speed of the sphere for each frame

speeds = [0.0] * 600

for i in range(600):

    if i < 300:

        speeds[i] = 0.2 * (i / 300)

    else:

        speeds[i] = 0.2 + 0.8 * ((i - 300) / 300)


# Create sphere object and set location

bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, enter_editmode=False, location=initial_location)

sphere = bpy.context.object


# Set animation keyframes

for frame in range(600):

    # Calculate the direction from the sphere's current location to the target location

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

    

    # Calculate the distance between the sphere's current location and the target location

    distance = (target_location - sphere.location).length

    

    # Move the sphere based on its speed and direction

    sphere.location += direction * speeds[frame] * distance

    

    # Set keyframe for sphere location

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


逆さ円錐用 ボール位置 幻想速度

 

import bpy
import math


zion_collection_name = "幻想 速度"

# コレクションを作成する
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((0, 0, 60))


# 初期位置のリスト

initial_locations = [

    Vector((30, 0, 0)),

    Vector((60, 0, 0)),

    Vector((0, 0, 0)),

    Vector((-30, 0, 0)),

    Vector((-60, 0, 0))

]


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

chousei_kijyun = 60

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

speeds = [0.1 * distance / chousei_kijyun if distance > 0 else 0 for distance in 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=3, 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)







逆さ円錐 ミンコフスキー型  ファイルからでも再生anime できる

 



import bpy

from mathutils import Vector


# Set target location

target_location = Vector((0, 0, 60))


# Set initial location

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


# Set cone properties

cone_radius = 60

cone_height = 60


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


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 * distance / chousei_kijyun if distance > 0 else 0 for distance in distances]






# Create cone object and set location

bpy.ops.mesh.primitive_cone_add(radius1=0, radius2=cone_radius, depth=cone_height)

cone = bpy.context.object

cone.location = initial_location


# Set animation keyframes

last_frame = 600

for frame in range(last_frame+1):

    distance = (target_location - cone.location).length

    if distance > 0.01:

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

        cone.location += direction * min(0.1, distance)

        cone.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()






bpy.context.scene.frame_set(1)

 

  1. スクリプトを修正して、アニメーションを再生する前に、以下のように現在のフレームをアニメーション開始時のフレームに設定します。
scss
bpy.context.scene.frame_set(1)

これにより、アニメーションを再生する前に、現在のフレームがアニメーションの開始時に設定されます。

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

 


import bpy

import math


zion_collection_name = "速度一定 Sphere Z軸"


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


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

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


幻想 Z軸 球体 20230409 sun カメラ追跡 付き


import bpy

import math


zion_collection_name = "幻想 Sphere Z軸"


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


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

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


Z軸 球体 速度制限 20230409 sun

 

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

from mathutils import Vector


# 球体の中心位置リストを作成する

centers = []

for i in range(5):

    z = -30 + i*15

    centers.append(Vector((0, 0, z)))


# 目標位置を指定する

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


# フレーム数を指定する

last_frame = 600


# 移動する距離を指定する

distance_per_frame = 0.1


# スフィアの作成

for center in centers:

    bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, location=center)

    sphere_obj = bpy.context.active_object

    sphere_obj.name = "Sphere Z軸" + str(centers.index(center))


# アニメーションの作成

for frame in range(last_frame+1):

    for obj in bpy.data.objects:

        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(distance_per_frame, 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()



20230409 sun # Z軸 分布 球体 原型


# Z軸 分布 球体


import bpy

from mathutils import Vector


# 球体の中心位置リストを作成する

centers = []

for i in range(5):

    z = -30 + i*15

    centers.append(Vector((0, 0, z)))


# 目標位置を指定する

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


# フレーム数を指定する

last_frame = 600


# 移動する距離を指定する

distance_per_frame = 0.1


# スフィアの作成

for center in centers:

    bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, location=center)


# アニメーションの作成

for frame in range(last_frame+1):

    for index, obj in enumerate(bpy.data.objects):

        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(distance_per_frame, distance)

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




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

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