import bpy
import math
# 1つ目の球体を作成する
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.5, enter_editmode=False, location=(0, 0, 0))
obj1 = bpy.context.active_object
# 1つ目の球体にマテリアルを設定する
mat1 = bpy.data.materials.new(name="SphereMat1")
mat1.use_nodes = True
nodes = mat1.node_tree.nodes
principled_bsdf = nodes.get("Principled BSDF")
principled_bsdf.inputs[0].default_value = (1, 0, 0, 1)
principled_bsdf.inputs[7].default_value = 0.5
obj1.data.materials.append(mat1)
# 1つ目の球体を移動する
frames = 20 * bpy.context.scene.render.fps
for i in range(frames):
obj1.location = ((120 / frames) * i - 60, 0, 0)
obj1.keyframe_insert(data_path="location", frame=i)
# 2つ目の球体を作成する
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.5, enter_editmode=False, location=(0, 0, 0))
obj2 = bpy.context.active_object
# 2つ目の球体にマテリアルを設定する
mat2 = bpy.data.materials.new(name="SphereMat2")
mat2.use_nodes = True
nodes = mat2.node_tree.nodes
principled_bsdf = nodes.get("Principled BSDF")
principled_bsdf.inputs[0].default_value = (1, 0, 0, 1)
principled_bsdf.inputs[7].default_value = 0.5
obj2.data.materials.append(mat2)
# 2つ目の球体を移動する
for i in range(frames):
obj2.location = ((-120 / frames) * i + 60, 0, 0)
obj2.keyframe_insert(data_path="location", frame=i)
bbb