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ループで各フレームの処理を行うことでアニメーションを再生しています。これを使って、あなたのアニメーションを再生することができます。


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

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