2023年3月24日金曜日

配布用 光時計筒の移動とカメラアイ 改造20230325 修飾1

aaa

2023年3月21日火曜日
円柱 原型 Z軸 方向 end_frame = start_frame + 600


2023年3月25日土曜日
こまごま 部品 列挙 blender python














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

# Create the minus sphere
minus_sphere = bpy.ops.mesh.primitive_uv_sphere_add(radius=2.0, location=(-30.0, 0.0, 0.0))
minus_sphere_obj = bpy.context.active_object
minus_sphere_obj.name = "Floor_Sphere_minus"

# Create the plus sphere
plus_sphere = bpy.ops.mesh.primitive_uv_sphere_add(radius=2.0, location=(30.0, 0.0, 0.0))
plus_sphere_obj = bpy.context.active_object
plus_sphere_obj.name = "Floor_Sphere_plus"

# Create the cylinder
cylinder = bpy.ops.mesh.primitive_cylinder_add(radius=1.0, depth=60.0, location=(0.0, 0.0, 0.0))
cylinder_obj = bpy.context.active_object
cylinder_obj.name = "Zion_Cylinder"



# 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, 0.0)
end_pos = (-30.0, 0.0, 0.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))

# Set the speed multiplier
vvv_velocity = 1.0

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

# 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 = "床_光時計筒"

# 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


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

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

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


#######################################





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

# Create the minus sphere
minus_sphere = bpy.ops.mesh.primitive_uv_sphere_add(radius=2.0, location=(-30.0, 0.0, 30.0))
minus_sphere_obj = bpy.context.active_object
minus_sphere_obj.name = "Top_Sphere_minus"

# Create the plus sphere
plus_sphere = bpy.ops.mesh.primitive_uv_sphere_add(radius=2.0, location=(30.0, 0.0, 30.0))
plus_sphere_obj = bpy.context.active_object
plus_sphere_obj.name = "Top_Sphere_plus"

# Create the cylinder
cylinder = bpy.ops.mesh.primitive_cylinder_add(radius=1.0, depth=1.0, location=(0.0, 0.0, 30.0))
cylinder_obj = bpy.context.active_object
cylinder_obj.name = "Top_Cylinder"



# 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, 30.0)
end_pos = (-30.0, 0.0, 30.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))

# Set the speed multiplier
vvv_velocity = 1.0

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

# 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 = "天井光時計筒"

# 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


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

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

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



#################################











# ボール 事象情報 拡散速度 円柱 移動速度と おんなじ






import bpy
import math


zion_collection_name = "ボール 事象情報 拡散速度"

# コレクションを作成する
col = bpy.data.collections.new(zion_collection_name)
bpy.context.scene.collection.children.link(col)






# Create the fall down sphere

import bpy
import math

# Create the fall down sphere
fall_down_sphere = bpy.ops.mesh.primitive_uv_sphere_add(radius=2.0, location=(0.0, 0.0, 60.0))
fall_down_sphere_obj = bpy.context.active_object
fall_down_sphere_obj.name = "fall_down_Sphere"



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

# Define the start and end positions
start_pos = (0.0, 0.0, 60.0)
end_pos = (0.0, 0.0, 0.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))

# Set the speed multiplier
vvv_velocity = 1.0

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

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

# 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





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

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

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











# 奥行きボール 事象情報 拡散速度 円柱 移動速度と おんなじ






import bpy
import math


zion_collection_name = "奥行きボール 事象情報 拡散速度"

# コレクションを作成する
col = bpy.data.collections.new(zion_collection_name)
bpy.context.scene.collection.children.link(col)






# Create the fall down sphere

import bpy
import math

# Create the fall down sphere
fall_down_sphere = bpy.ops.mesh.primitive_uv_sphere_add(radius=2.0, location=(0.0, 60.0, 0.0))
fall_down_sphere_obj = bpy.context.active_object
fall_down_sphere_obj.name = "奥行き_Sphere"



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

# Define the start and end positions
start_pos = (0.0, 60.0, 0.0)
end_pos = (0.0, 0.0, 0.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))

# Set the speed multiplier
vvv_velocity = 1.0

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

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

# 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





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

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

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




















等速半球 16個 ボール


https://timeblender.blogspot.com/2023/03/blog-post_50.html



コッチの方が 速度一定 ちゃんと計算してる





#  等速半球面からの ボール






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

# 目標位置を指定する
zion_target = Vector((0, 0, 0))

# ラストフレームを指定する
zion_last_frame = 100

# 速度を計算する関数
def calculate_speed(distance, duration):
    return distance / duration

# オブジェクトを作成する関数
def create_sphere(location, radius):
    bpy.ops.mesh.primitive_uv_sphere_add(location=location, radius=radius)

# アニメーションを設定する関数
def set_animation(obj, start_frame, end_frame, target_location, speed):
    distance = (target_location - obj.location).length
    duration = distance / speed
    for frame in range(start_frame, end_frame+1):
        t = (frame - start_frame) / duration
        obj.location = obj.location.lerp(target_location, t)
        obj.keyframe_insert(data_path="location", frame=frame)

# 16個の球体を作成する
spheres = []
for i in range(16):
    angle = 2 * i * math.pi / 16
    x = 600 * math.cos(angle)
    y = 600 * math.sin(angle)
    z = 0
    location = Vector((x, y, z))
    radius = 1
    create_sphere(location, radius)
    obj = bpy.context.active_object
    obj.name = "16_Sphere"  # オブジェクト名を変更
    spheres.append(obj)

# アニメーションを設定する
for i, sphere in enumerate(spheres):
    start_frame = 1
    end_frame = zion_last_frame
    location = sphere.location
    distance = (zion_target - location).length
    speed = calculate_speed(distance, zion_last_frame - start_frame)
    set_animation(sphere, start_frame, end_frame, zion_target, speed)











2023年3月24日金曜日

速度 バラバラ 目標へ 同時着の 円周からの球体

aaa




import bpy
import math
from mathutils import Vector


# 目標位置を指定する
zion_target = Vector((0, 0, 0))

# ラストフレームを指定する
zion_last_frame = 640

# 速度を計算する関数
def calculate_speed(distance, duration):
    return distance / duration


# オブジェクトを作成する関数
def create_sphere(location, radius):
    bpy.ops.mesh.primitive_uv_sphere_add(location=location, radius=radius)


# アニメーションを設定する関数
def set_animation(obj, start_frame, end_frame, target_location, speed):
    distance = (target_location - obj.location).length
    duration = distance / speed
    for frame in range(start_frame, end_frame+1):
        t = (frame - start_frame) / duration
        obj.location = obj.location.lerp(target_location, t)
        obj.keyframe_insert(data_path="location", frame=frame)


# 16個の球体を作成する
spheres = []
for i in range(16):
    angle = 2 * i * math.pi / 16
    z = 30 * math.cos(angle)
    y = 30 * math.sin(angle)
    x = 0
    location = Vector((x, y, z))
    radius = 1
    create_sphere(location, radius)
    obj = bpy.context.active_object
    spheres.append(obj)


# アニメーションを設定する
for i, sphere in enumerate(spheres):
    start_frame = 1
    end_frame = zion_last_frame
    location = sphere.location
    distance = (zion_target - location).length
    speed = calculate_speed(distance, zion_last_frame - start_frame)
    set_animation(sphere, start_frame, end_frame, zion_target, speed)






























# オブジェクトを作成する関数
def create_sphere(location, radius, name):
    bpy.ops.mesh.primitive_uv_sphere_add(location=location, radius=radius)
    obj = bpy.context.active_object
    obj.name = name

# 16個の球体を作成する
for i in range(16):
    angle = 2 * i * math.pi / 16
    z = 60 * math.cos(angle)
    y = 60 * math.sin(angle)
    x = 0
    location = (x, y, z)
    radius = 1
    name = "16_Sphere{}".format(i)
    create_sphere(location, radius, name)
    obj = bpy.context.active_object
    set_animation(obj, 1, 640, (0, 0, 0))







カメラ位置の球体を 透明にするテスト



import bpy
import math


# Create the Floor_CamSphere
Floor_CamSphere = bpy.ops.mesh.primitive_uv_sphere_add(radius=2.0, location=(0.0, -30.0, 0.0))
Floor_CamSphere = bpy.context.active_object

# Create transparent material
transparent_mat = bpy.data.materials.new(name="TransparentMat")
transparent_mat.use_nodes = True
nodes = transparent_mat.node_tree.nodes
links = transparent_mat.node_tree.links
transparent_node = nodes.get("Principled BSDF")
transparent_node.inputs["Base Color"].default_value = (1.0, 0.8, 0.8, 0.0)  # Set to light pink
transparent_node.inputs["Alpha"].default_value = 0.0  # Set transparency to 0
transparent_output_node = nodes.get("Material Output")
links.new(transparent_node.outputs["BSDF"], transparent_output_node.inputs["Surface"])

# Assign material to object
Floor_CamSphere.data.materials.append(transparent_mat)
















# Create the Floor_CamSphere

Floor_CamSphere = bpy.ops.mesh.primitive_uv_sphere_add(radius=2.0, location=(0.0, -30.0, 0.0))
Floor_CamSphere = bpy.context.active_object


# Create transparent material
transparent_mat = bpy.data.materials.new(name="TransparentMat")
transparent_mat.use_nodes = True
nodes = transparent_mat.node_tree.nodes
links = transparent_mat.node_tree.links
transparent_node = nodes.get("Principled BSDF")
transparent_node.inputs["Base Color"].default_value = (0.0, 0.0, 0.0, 0.0)
transparent_output_node = nodes.get("Material Output")
links.new(transparent_node.outputs["BSDF"], transparent_output_node.inputs["Surface"])

# Assign material to object
Floor_CamSphere.data.materials.append(transparent_mat)
















# import bpy

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

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

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




import bpy

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

# アクティブなフレームを650に設定する
scene.frame_set(650)











aaa































# Add a camera and set its position
cam_data = bpy.data.cameras.new('Camera')
cam = bpy.data.objects.new('Camera', cam_data)
bpy.context.scene.collection.objects.link(cam)
cam.location = (0.0, -30.0, 0.0)



# 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 = "床_光時計筒"

# 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









bbb

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

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