2023年3月27日月曜日

aaa









import bpy
import math
from math import radians

radius = 15
depth = 0
vertices = 60
zion_number = 15
zion_x = 30.0

create_single_disk = False

if create_single_disk:
    disk_locations = [(zion_x, 0.0, 15.0)]
    object_names = ['えんばん']
    rotation_enabled = {'z': True, 'y': True}
else:
    disk_locations = [
        (zion_x, 0.0, 0.0),
        (zion_x, 0.0, zion_number),
        (zion_x, 0.0, -zion_number),
        (zion_x, -zion_number, 0.0),
        (zion_x, zion_number, 0.0)
    ]
    object_names = ['cylinder1', 'cylinder2', 'cylinder3', 'cylinder4', 'cylinder5']
    z_rotation_enabled = {'cylinder1': True, 'cylinder2': True, 'cylinder3': True, 'cylinder4': True, 'cylinder5': True}
    y_rotation_enabled = {'cylinder1': False, 'cylinder2': False, 'cylinder3': False, 'cylinder4': False, 'cylinder5': False}

for i, location in enumerate(disk_locations):
    x, y, z = location
    bpy.ops.mesh.primitive_cylinder_add(radius=radius, depth=depth, vertices=vertices, enter_editmode=False, align='WORLD', location=(x, y, z))
    cylinder = bpy.context.object
    cylinder.name = object_names[i]
    cylinder.rotation_euler = (radians(90), radians(0), radians(0))

    if not create_single_disk:
        if z_rotation_enabled[object_names[i]]:
            bpy.ops.object.mode_set(mode='EDIT')
            bpy.ops.mesh.select_all(action='SELECT')
            bpy.ops.transform.rotate(value=radians(90), orient_axis='Z', orient_type='GLOBAL')
            bpy.ops.object.mode_set(mode='OBJECT')
        
        cylinder.rotation_euler.y = radians(90) if y_rotation_enabled[object_names[i]] else radians(0)






# Set start and end frames
start_frame = 1
end_frame = start_frame + 600

# Define the start and end positions
start_pos = (30.0, 0.0, 15.0)
end_pos = (-30.0, 0.0, 15.0)

# Calculate the distance between start_pos and end_pos
distance = abs(math.sqrt((end_pos[0]-start_pos[0])**2 + (end_pos[1]-start_pos[1])**2 + (end_pos[2]-start_pos[2])**2))



chousei = 1 / distance # 斜め進みと flame の関係?

# Calculate the velocity required to move the sphere at a constant speed
velocity = (end_frame - start_frame) * vvv_velocity * chousei





# Move the sphere and cylinder from start_pos to end_pos at a constant speed
for i in range(start_frame, end_frame + 1):
    bpy.context.scene.frame_set(i)
    bpy.context.object.location = tuple(s + (e-s)*((i-start_frame)*velocity/distance) for s,e in zip(start_pos, end_pos))
    bpy.context.object.keyframe_insert(data_path="location", index=-1)
    bpy.context.object.keyframe_insert(data_path="scale", index=-1)

# Stop the sphere and cylinder from moving after reaching the end position
bpy.context.scene.frame_set(end_frame)
bpy.context.object.keyframe_insert(data_path="location", index=-1)
bpy.context.object.keyframe_insert(data_path="scale", index=-1)

# Set the waiting period
wait_frames = 30
end_frame += wait_frames

# Set the current frame to the end_frame
current_frame = end_frame

# Keep the sphere and cylinder at the end position and repeat the animation
repeat_frames = end_frame + 200
while True:
    current_frame += 1
    
    # Insert a keyframe at the current frame for the sphere and cylinder's location and scale
    bpy.context.scene.frame_set(current_frame)
    bpy.context.object.location = end_pos
    bpy.context.object.keyframe_insert(data_path="location", index=-1)
    bpy.context.object.keyframe_insert(data_path="scale", index=-1)
    
    # Stop the loop if current_frame reaches repeat_frames
    if current_frame == repeat_frames:
        break




# Add a camera and set its position
cam_data = bpy.data.cameras.new('Camera')
cam_data.lens = 600.0  # set focal length to 50mm (zoomed in)
cam = bpy.data.objects.new('Camera', cam_data)
bpy.context.scene.collection.objects.link(cam)
cam.location = (0.0, -30.0, 0.0)

cam.name = "Cam_upper_光時計筒"


# Add a track constraint to the camera to follow the sphere
track_constraint = cam.constraints.new(type='TRACK_TO')
track_constraint.target = bpy.context.object
track_constraint.track_axis



# import bpy

# アクティブなシーンを取得する
scene = bpy.context.scene

# 開始フレームを1に設定する
scene.frame_start = 1

# 終了フレームを640に設定する
scene.frame_end = 640








































bbb

連番 007 未来光円錐 過去光円錐 円周中心からの球体放出

aaa 参考 2023年3月26日日曜日 製作 002b 未来光円錐の方向 線路レールで https://ia2023sha.blogspot.com/2023/03/002b.html import bpy import math zion_co...