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)
# 再生時間を設定する
bpy.context.scene.frame_end = 600
# 時間を表すフレーム数の初期値を設定する
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 >= 300:
bpy.ops.screen.animation_cancel(restore_frame=False)
# フレーム更新のコールバック関数を登録する
bpy.app.handlers.frame_change_pre.append(animate_cone)
ああああああああああああああああああああああああああああ
# 再生時間を設定する
bpy.context.scene.frame_end = 600 # 再生時間を設定する
# 円錐を描画するフレーム数を指定する
last_frame = 300
# 毎フレーム呼び出される関数
def animate_cone(scene):
global frame_num
# 描画を停止するフレームに達した場合、アニメーションを停止する
if frame_num >= last_frame:
bpy.ops.screen.animation_cancel(restore_frame=False)