2023年4月8日土曜日

ニュートン bball 色付き 幻想ボールから

 

最初に定義されたzion_object_name変数は、球体オブジェクトの名前として使用されているため、変更するとエラーが発生する可能性があります。その場合は、sphere = bpy.data.objects["幻想 ball 上昇"]のように、直接オブジェクト名を使用して球体オブジェクトを取得することができます。




import bpy

from math import sin, cos, pi


zion_object_name = "幻想 斜め下降"


# 設定可能な変数

start_pos = (0, 0, 30)  # 開始位置

end_pos = (-30, 0, 0)  # 終了位置

radius = 2.0  # 半径

animation_frames = 600  # アニメーションの再生時間(フレーム数)


# 球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, enter_editmode=False, align='WORLD', location=start_pos)

sphere = bpy.context.object

sphere.name = zion_object_name  # オブジェクトの名前を変更


# アニメーションを再生するたびに呼び出される関数

def animate_sphere(scene):

    global sphere

    

    # 現在のフレームにおける球体の位置を計算する

    frame = scene.frame_current

    pos_x = start_pos[0] - ((start_pos[0] - end_pos[0]) / animation_frames) * frame

    pos_y = start_pos[1] - ((start_pos[1] - end_pos[1]) / animation_frames) * frame

    pos_z = start_pos[2] - ((start_pos[2] - end_pos[2]) / animation_frames) * frame

    sphere.location = (pos_x, pos_y, pos_z)


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

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


# アニメーションの再生時間を設定する

bpy.context.scene.frame_end = animation_frames


# スクリプトを実行する前にフレームを初期化する

bpy.context.scene.frame_set(0)


# 球体を青色で少し白っぽくする処理

mat = bpy.data.materials.new(name="BlueWhite")

mat.use_nodes = True

mat.node_tree.nodes["Principled BSDF"].inputs[0].default_value = (0.15, 0.3, 0.8, 1) # 青色

mat.node_tree.nodes["Principled BSDF"].inputs[7].default_value = 0.2 # 白さを調整

sphere.data.materials.append(mat)





import bpy

from math import sin, cos, pi


zion_object_name = "幻想 水平 移動"


# 設定可能な変数

start_pos = (0, 0, 0)  # 開始位置

end_pos = (-30, 0, 0)  # 終了位置

radius = 2.0  # 半径

animation_frames = 600  # アニメーションの再生時間(フレーム数)


# 球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, enter_editmode=False, align='WORLD', location=start_pos)

sphere = bpy.context.object

sphere.name = zion_object_name  # オブジェクトの名前を変更


# アニメーションを再生するたびに呼び出される関数

def animate_sphere(scene):

    global sphere

    

    # 現在のフレームにおける球体の位置を計算する

    frame = scene.frame_current

    pos_x = start_pos[0] - ((start_pos[0] - end_pos[0]) / animation_frames) * frame

    pos_y = start_pos[1] - ((start_pos[1] - end_pos[1]) / animation_frames) * frame

    pos_z = start_pos[2] - ((start_pos[2] - end_pos[2]) / animation_frames) * frame

    sphere.location = (pos_x, pos_y, pos_z)


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

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


# アニメーションの再生時間を設定する

bpy.context.scene.frame_end = animation_frames


# スクリプトを実行する前にフレームを初期化する

bpy.context.scene.frame_set(0)


# 球体を青色で少し白っぽくする処理

mat = bpy.data.materials.new(name="BlueWhite")

mat.use_nodes = True

mat.node_tree.nodes["Principled BSDF"].inputs[0].default_value = (0.15, 0.3, 0.8, 1) # 青色

mat.node_tree.nodes["Principled BSDF"].inputs[7].default_value = 0.2 # 白さを調整

sphere.data.materials.append(mat)









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

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