2023年4月10日月曜日

アニメが 再生する方法 検討と 半径 球体が 球体を回る 


# アニメーションを再生する

import bpy

bpy.ops.screen.animation_play()


bpy.ops.screen.animation_play()は、BlenderのGUIからの操作をエミュレートするためのコマンドであり、バッチ処理で使用することはできません。代わりに、以下のようにPythonコードでアニメーションを再生することができます。


import bpy


# アニメーションの再生範囲を設定

bpy.context.scene.frame_start = 1

bpy.context.scene.frame_end = 100


# アニメーションを再生

for frame in range(bpy.context.scene.frame_start, bpy.context.scene.frame_end + 1):

    bpy.context.scene.frame_set(frame)


このコードでは、frame_startとframe_endでアニメーションの再生範囲を設定し、forループで各フレームの処理を行うことでアニメーションを再生しています。これを使って、あなたのアニメーションを再生することができます。



以下の方法もあります:


bpy.context.scene.frame_current = 1というコードを実行し、現在のフレームをアニメーションの最初のフレームに設定します。その後、bpy.ops.screen.animation_play()を実行することで、アニメーションを再生できます。


bpy.ops.screen.animation_play()の代わりに、bpy.ops.screen.animation_play(reverse=False, sync=False)を実行することで、アニメーションを逆再生しないようにし、他のアプリケーションやプロセスとの同期を無効にします。


bpy.context.scene.frame_current = bpy.context.scene.frame_startを実行し、現在のフレームをアニメーションの最初のフレームに設定し、bpy.ops.render.render(animation=True)を実行することで、アニメーションを再生し、レンダリングを同時に実行できます。




import bpy

import math

from mathutils import Vector


# 半径を設定

radius = 1


# 球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(radius=radius)

sphere = bpy.context.active_object

# アニメーションを開始する

bpy.ops.screen.animation_play()



# 初期フレームを取得

start_frame = bpy.context.scene.frame_current


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

def animate_sphere(scene):

    # 現在のフレーム数を取得

    current_frame = bpy.context.scene.frame_current


    # 球体を回転する角度を計算

    angle = (current_frame - start_frame) * 2 * math.pi / 200


    # 球体の位置を更新

    x = radius * math.cos(angle)

    y = radius * math.sin(angle)

    z = 0

    location = Vector((x, y, z))

    sphere.location = location


    # 球体を回転

    sphere.rotation_euler[2] = angle


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

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


# アニメーション再生前に現在のフレームをアニメーションの最初のフレームに設定する

bpy.context.scene.frame_current = bpy.context.scene.frame_start


# アニメーションを再生する関数

def play_animation():

    # アニメーション再生後に現在のフレームをアニメーションの最初のフレームに設定する

    bpy.context.scene.frame_current = bpy.context.scene.frame_start


    # 現在のフレームをアニメーションの最初のフレームに設定

    bpy.context.scene.frame_current = bpy.context.scene.frame_start


    # アニメーションを再生

    bpy.ops.screen.animation_play()


# ファイルが起動したときにアニメーションを再生する

if __name__ == "__main__":

    play_animation()








import bpy

import math


from mathutils import Vector


# 半径を設定

radius = 1


# 球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(radius=radius)

sphere = bpy.context.active_object


# 初期フレームを取得

start_frame = bpy.context.scene.frame_current


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

def animate_sphere(scene):

    # 現在のフレーム数を取得

    current_frame = bpy.context.scene.frame_current


    # 球体を回転する角度を計算

    angle = (current_frame - start_frame) * 2 * math.pi / 200


    # 球体の位置を更新

    x = radius * math.cos(angle)

    y = radius * math.sin(angle)

    z = 0

    location = Vector((x, y, z))

    sphere.location = location


    # 球体を回転

    sphere.rotation_euler[2] = angle


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

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



# アニメーションの再生範囲を設定

bpy.context.scene.frame_start = 1

bpy.context.scene.frame_end = 600








import bpy

import math



from mathutils import Vector



# 半径を設定

radius = 1



# 球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(radius=radius)

sphere = bpy.context.active_object



# 初期フレームを取得

start_frame = bpy.context.scene.frame_current



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

def animate_sphere(scene):

    # 現在のフレーム数を取得

    current_frame = bpy.context.scene.frame_current



    # 球体を回転する角度を計算

    angle = (current_frame - start_frame) * 2 * math.pi / 100



    # 球体の位置を更新

    x = radius * math.cos(angle)

    y = radius * math.sin(angle)

    z = 0

    location = Vector((x, y, z))

    sphere.location = location



    # 球体を回転

    sphere.rotation_euler[2] = angle



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

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



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

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