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軸 穴の36球体


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


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





円周の 平行移動 x軸


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




# 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((1, 0, 0)) # X軸方向に移動する場合


            sphere.location += Vector((direction[0], 0, 0)) * 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)







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

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