import bpy
import math
z_axis = (0, 0, 1)
z_rotation_speed = 0.1 # 1秒間に回転する角度
z_rotation_speed_rad = math.radians(z_rotation_speed) # ラジアンに変換
z_rotation_duration = 360 / z_rotation_speed # 1回転するのにかかる時間(秒)
# 大きい球体を作成
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, location=(0, 0, 0))
large_sphere = bpy.context.active_object
# 大きい球体にマテリアルを割り当てる
material = bpy.data.materials.new(name="Material0")
material.diffuse_color = (1.0, 1.0, 1.0, 1.0) # 不透明
material.alpha = 0.1 # 透明度
large_sphere.data.materials.append(material)
# 小さい球体を作成
for i in range(3):
x = math.cos(math.radians(120*i)) * 1
y = math.sin(math.radians(120*i)) * 1
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, enter_editmode=False, location=(x, y, 0))
# 作成した小さい球体を選択する
bpy.ops.object.select_all(action='DESELECT')
for obj in bpy.data.objects:
if obj.name.startswith("SmallSphere"):
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
# アニメーションを作成
animation_data = large_sphere.animation_data_create()
animation = bpy.data.actions.new(name="RotationAction")
animation_data.action = animation
z_rotation_angle = 0
for i in range(10):
z_rotation_angle += 360 # 1周分回転する
z_rotation_time = i * z_rotation_duration # 回転にかかる時間
large_sphere.rotation_mode = 'XYZ'
large_sphere.rotation_euler.z = math.radians(z_rotation_angle)
large_sphere.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time, index=2)
large_sphere.rotation_euler.z = math.radians(z_rotation_angle + z_rotation_speed)
large_sphere.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time + 1, index=2)
for obj in bpy.context.selected_objects:
if obj != large_sphere:
obj.rotation_mode = 'XYZ'
obj.rotation_euler.z = math.radians(z_rotation_angle)
obj.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time, index=2)
obj.rotation_euler.z = math.radians(z_rotation_angle + z_rotation_speed)
obj.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time + 1, index=2)
import bpy
import math
z_axis = (0, 0, 1)
z_rotation_speed = 2 # 1秒間に回転する角度
z_rotation_speed_rad = math.radians(z_rotation_speed) # ラジアンに変換
z_rotation_duration = 360 / z_rotation_speed # 1回転するのにかかる時間(秒)
# 球体を作成
bpy.ops.mesh.primitive_uv_sphere_add(location=(0, 0, 0))
# アニメーションを作成
obj = bpy.context.active_object
animation_data = obj.animation_data_create()
animation = bpy.data.actions.new(name="RotationAction")
animation_data.action = animation
z_rotation_angle = 0
for i in range(10):
z_rotation_angle += 360 # 1周分回転する
z_rotation_time = i * z_rotation_duration # 回転にかかる時間
obj.rotation_mode = 'XYZ'
obj.rotation_euler.z = math.radians(z_rotation_angle)
obj.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time, index=2)
obj.rotation_euler.z = math.radians(z_rotation_angle + z_rotation_speed)
obj.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time + 1, index=2)
色色
import bpy
import math
z_axis = (0, 0, 1)
z_rotation_speed = 0.2 # 1秒間に回転する角度
z_rotation_speed_rad = math.radians(z_rotation_speed) # ラジアンに変換
z_rotation_duration = 360 / z_rotation_speed # 1回転するのにかかる時間(秒)
import bpy
import random
# 球体を作成
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, location=(0, 0, 0))
# マテリアルを作成
materials = []
for i in range(32):
mat = bpy.data.materials.new(name=f"Material{i}")
mat.diffuse_color = (random.random(), random.random(), random.random(), 1.0)
materials.append(mat)
# マテリアルをランダムに割り当てる
obj = bpy.context.active_object
for face in obj.data.polygons:
face.material_index = random.randint(0, 31)
# オブジェクトにマテリアルを割り当てる
for i in range(32):
obj.data.materials.append(materials[i])
# アニメーションを作成
obj = bpy.context.active_object
animation_data = obj.animation_data_create()
animation = bpy.data.actions.new(name="RotationAction")
animation_data.action = animation
z_rotation_angle = 0
for i in range(10):
z_rotation_angle += 360 # 1周分回転する
z_rotation_time = i * z_rotation_duration # 回転にかかる時間
obj.rotation_mode = 'XYZ'
obj.rotation_euler.z = math.radians(z_rotation_angle)
obj.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time, index=2)
obj.rotation_euler.z = math.radians(z_rotation_angle + z_rotation_speed)
obj.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time + 1, index=2)
ああああああああああああああああああ