2023年4月7日金曜日

300から ジャンプ 600から 300戻りの 逆さ円錐



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

        

    elif frame_num < 600:

        # 円錐を待機させる

        cone.location = Vector((0, 0, height/2 - distance_per_frame * (frame_num - 299)))

    

    else:

        # 円錐を削除する

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

        # 新しい円錐を作成する

        cone = create_cone()

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

        frame_num = 0


    # フレーム数を1増やす

    frame_num += 1


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

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


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

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