2023年4月7日金曜日

2つの逆さ円錐 スクリプト 改造中

 

import bpy

from mathutils import Vector


zion_object = "逆さ円錐 300上昇"


radius = 60 # 半径を設定する

height = 60 # 高さを設定する

distance_per_frame = 0.1 # 移動する距離を指定する


# 円錐を作成する

def create_cone():

    bpy.ops.mesh.primitive_cone_add(radius1=0, radius2=radius, depth=height)

    cone = bpy.context.object

    cone.name = zion_object

    cone.location = Vector((0, 0, -height/2)) # 初期位置を設定する

    cone.active_material = bpy.data.materials.new(name="zion_material")

    cone.active_material.use_nodes = True

    node_tree = cone.active_material.node_tree

    nodes = node_tree.nodes

    links = node_tree.links

    diffuse = nodes["Principled BSDF"]

    diffuse.inputs['Base Color'].default_value = (0.10980392156862745, 0.6352941176470588, 0.6980392156862745, 0.002)


    return cone


cone = create_cone()


# 再生時間を設定する

bpy.context.scene.frame_start = 0

bpy.context.scene.frame_end = 600


# 時間を表すフレーム数の初期値を設定する

frame_num = 0


# 毎フレーム呼び出される関数

def animate_cone(scene):

    global frame_num, cone


    if frame_num < 300:

        # 現在のフレーム数から円錐の位置を計算する

        z = frame_num * distance_per_frame

        cone.location = Vector((0, 0, -height/2 + z))


    # フレーム数を1増やす

    frame_num += 1


    if frame_num == 300:

        # 円錐を停止する

        cone.location = Vector((0, 0, height/2))


    if frame_num >= 640:

        # 円錐を削除する

        bpy.data.objects.remove(cone, do_unlink=True)

        # 新しい円錐を作成する

        cone = create_cone()

        # フレーム数を初期化する

        frame_num = 0


# フレーム更新のコールバック関数を登録する

bpy.app.handlers.frame_change_pre.append(animate_cone)


























import bpy

import math

from mathutils import Vector


zion_speed_round = 0.0 # 回転速度を設定する(0にすることで回転停止)

radius = 60 # 半径を設定する

height = 60 # 高さを設定する

distance_per_frame = 0.1 # 移動する距離を指定する


# 円錐を作成する

bpy.ops.mesh.primitive_cone_add(radius1=0, radius2=radius, depth=height)

cone = bpy.context.object

cone.name = "Cone"


# 時間を表すフレーム数の初期値を設定する

frame_num = 0


# フレーム数が減少するかどうかのフラグ

reverse_flag = False


# 毎フレーム呼び出される関数

def animate_cone(scene):

    global frame_num

    global reverse_flag


    # 逆再生時はフレーム数を逆に数える

    if scene.frame_current < scene.frame_previous:

        reverse_flag = not reverse_flag


    # 位置を計算する

    if not reverse_flag:

        # 正方向にアニメーションする場合

        z = frame_num * distance_per_frame

    else:

        # 逆方向にアニメーションする場合

        z = (scene.frame_end - frame_num) * distance_per_frame

    cone.location = Vector((0, 0, z))


    # 円錐を回転する

    cone.rotation_euler[2] += zion_speed_round


    # フレーム数を増減する

    if not reverse_flag:

        frame_num += 1

        if frame_num >= scene.frame_end:

            frame_num = scene.frame_end - 1

            reverse_flag = True

    else:

        frame_num -= 1

        if frame_num <= scene.frame_start:

            frame_num = scene.frame_start + 1

            reverse_flag = False


# フレーム更新のコールバック関数を登録する

bpy.app.handlers.frame_change_pre.append(animate_cone)










 


2つの逆さ円錐 スクリプト


 


# 再生時間を設定する

bpy.context.scene.frame_end = 640 # 再生時間を設定する


# 円錐を描画するフレーム数を指定する

last_frame = 300


# 毎フレーム呼び出される関数

def animate_cone(scene):

    global frame_num


    # 描画を停止するフレームに達した場合、アニメーションを停止する

    if frame_num >= last_frame:

        bpy.ops.screen.animation_cancel(restore_frame=False)




import bpy

from mathutils import Vector


zion_object = "逆さ円錐 300上昇"


zion_speed_round = 0.0  # 回転速度を設定する

radius = 60  # 半径を設定する

height = 60  # 高さを設定する

distance_per_frame = 0.1  # 移動する距離を指定する


# 円錐を作成する

bpy.ops.mesh.primitive_cone_add(radius1=0, radius2=radius, depth=height)

cone = bpy.context.object

cone.name = zion_object

cone.location = Vector((0, 0, -height/2))  # 初期位置を設定する

cone.active_material = bpy.data.materials.new(name="zion_material")

cone.active_material.use_nodes = True

node_tree = cone.active_material.node_tree

nodes = node_tree.nodes

links = node_tree.links

diffuse = nodes["Principled BSDF"]

diffuse.inputs['Base Color'].default_value = (0.2, 0.8, 0.5, 0.3)




# 時間を表すフレーム数の初期値を設定する

frame_num = 0


# 毎フレーム呼び出される関数

def animate_cone(scene):

    global frame_num


    # 現在のフレーム数から円錐の位置を計算する

    z = frame_num * distance_per_frame

    if z <= height:

        cone.location = Vector((0, 0, -height/2 + z))

    else:

        cone.location = Vector((0, 0, height/2))


    # 円錐を回転する

    cone.rotation_euler[2] += zion_speed_round


    # フレーム数を1増やす

    frame_num += 1


  新のコールバック関数を登録する

bpy.app.handlers.frame_change_pre.append(animate_cone)

 





import bpy

from mathutils import Vector


zion_object = "逆さ円錐 600上昇"


zion_speed_round = 0.1 # 回転速度を設定する

radius = 60 # 半径を設定する

height = 60 # 高さを設定する

distance_per_frame = 0.1 # 移動する距離を指定する


# 円錐を作成する

bpy.ops.mesh.primitive_cone_add(radius1=0, radius2=radius, depth=height)

cone = bpy.context.object

cone.name = zion_object

cone.location = Vector((0, 0, -height/2)) # 初期位置を設定する

cone.active_material = bpy.data.materials.new(name="zion_material")

cone.active_material.use_nodes = True

node_tree = cone.active_material.node_tree

nodes = node_tree.nodes

links = node_tree.links

diffuse = nodes["Principled BSDF"]

diffuse.inputs['Base Color'].default_value = (0.6, 0.7, 1.0, 0.5)


# 再生時間を設定する

bpy.context.scene.frame_end = 640


# 時間を表すフレーム数の初期値を設定する

frame_num = 0


# 毎フレーム呼び出される関数

def animate_cone(scene):

    global frame_num


    # 現在のフレーム数から円錐の位置を計算する

    z = frame_num * distance_per_frame

    if z <= height:

        cone.location = Vector((0, 0, -height/2 + z))

    else:

        cone.location = Vector((0, 0, height/2))


    # 円錐を回転する

    cone.rotation_euler[2] += zion_speed_round


    # フレーム数を1増やす

    frame_num += 1


    # 指定フレーム数まで達したらアニメーションを停止する

    if frame_num >= 600:

        bpy.ops.screen.animation_cancel(restore_frame=False)


# フレーム更新のコールバック関数を登録する

bpy.app.handlers.frame_change_pre.append(animate_cone)


# 再生時間を設定する

bpy.context.scene.frame_end = 600












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

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