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
from mathutils import Vector
from math import radians

zion_collection_name = "光時計たくさんcylinders"

# Create the collection
col = bpy.data.collections.new(zion_collection_name)
bpy.context.scene.collection.children.link(col)

# Set target location
target_location = Vector((-600, 0, 0))

# Set cylinder properties
cylinder_radius = 1
cylinder_depth = 180

# 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

# Set initial x locations and intervals
initial_x = range(-90, 3001, 100)

# Create cylinder objects and set locations
for i, x in enumerate(initial_x):
    initial_location = Vector((x, 0, 0))
    bpy.ops.mesh.primitive_cylinder_add(radius=cylinder_radius, depth=cylinder_depth)
    cylinder = bpy.context.object
    cylinder.location = initial_location
    cylinder.name = f"cylinder_{x}"


    # Rotate cylinder by 90 degrees around the y-axis
    cylinder.rotation_euler.rotate_axis('Y', radians(0))

    # Calculate speeds based on initial distances
    chousei_kijyun = 1000
    distances = [math.sqrt(sum([(a - b) ** 2 for a, b in zip(loc, target_location)])) for loc in [initial_location]]
    speeds = [1.0 * (chousei_kijyun / distance) if distance > 0 else 0 for distance in distances]

    # Set animation keyframes
    last_frame = 1000
    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[0], distance)
            cylinder.keyframe_insert(data_path="location", frame=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...