2023年4月5日水曜日

1個の球体 円周 回転


球体を反対方向に回転させるには、以下の行を修正してください。


lua

Copy code

angle = -2 * i * math.pi / 16

ここで、-2を掛けることで反対方向に回転します。

# 球体 回転 1つ



import bpy

import math

from mathutils import Vector


zion_speed_round = 0.5 # 回転速度を設定する

radius = 30 # 半径を設定する


# 球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(location=Vector((0,0,0)), radius=1)

sphere = bpy.context.active_object

sphere.name = "Sphere"


# 球体を回転する

frame_count = 0

for i in range(1, 10000):

    frame_count += 1

    angle = 2 * math.pi / 100 * frame_count * zion_speed_round

    x = radius * math.cos(angle)

    y = radius * math.sin(angle)

    z = 0

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

    sphere.location = location

    sphere.keyframe_insert(data_path="location", frame=frame_count)


 








import bpy
import math
from mathutils import Vector

zion_speed_round = 1.0 # 回転速度を設定する
radius = 30 # 半径を設定する
distance_per_frame = 0.2 # 移動する距離を指定する

# 球体を作成する
bpy.ops.mesh.primitive_uv_sphere_add(location=Vector((0,0,0)), radius=1)
sphere1 = bpy.context.active_object
sphere1.name = "Sphere1"

# 半周ズレた球体を作成する
bpy.ops.mesh.primitive_uv_sphere_add(location=Vector((0,0,0)), radius=2)
sphere2 = bpy.context.active_object
sphere2.name = "Sphere2"

# 球体を回転する
frame_count = 0
for i in range(1, 10000):
    frame_count += 1
    angle = 2 * math.pi / 100 * frame_count * zion_speed_round
    x1 = radius * math.cos(angle)
    y1 = radius * math.sin(angle)
    z1 = 0
    location1 = Vector((x1, y1, z1))
    sphere1.location = location1
    sphere1.keyframe_insert(data_path="location", frame=frame_count)

    x2 = radius * math.cos(angle + math.pi)
    y2 = radius * math.sin(angle + math.pi)
    z2 = 0
    location2 = Vector((x2, y2, z2))
    sphere2.location = location2
    sphere2.keyframe_insert(data_path="location", frame=frame_count)

    # 球体を移動する
    location1 += Vector((distance_per_frame, 0, 0))
    sphere1.location = location1
    sphere1.keyframe_insert(data_path="location", frame=frame_count)

    location2 += Vector((distance_per_frame, 0, 0))
    sphere2.location = location2
    sphere2.keyframe_insert(data_path="location", frame=frame_count)



半径30の円周軌道を回転する球体に半周ズレて回転する半径2の球体を追加したスクリプト全体のコードです。



import bpy

import math

from mathutils import Vector


zion_speed_round = 1.0 # 回転速度を設定する

radius = 30 # 半径を設定する


# 球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(location=Vector((0,0,0)), radius=1)

sphere1 = bpy.context.active_object

sphere1.name = "Sphere1"


# 半周ズレた球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(location=Vector((0,0,0)), radius=2)

sphere2 = bpy.context.active_object

sphere2.name = "Sphere2"


# 球体を回転する

frame_count = 0

for i in range(1, 10000):

    frame_count += 1

    angle = 2 * math.pi / 100 * frame_count * zion_speed_round

    x1 = radius * math.cos(angle)

    y1 = radius * math.sin(angle)

    z1 = 0

    location1 = Vector((x1, y1, z1))

    sphere1.location = location1

    sphere1.keyframe_insert(data_path="location", frame=frame_count)


    x2 = radius * math.cos(angle + math.pi)

    y2 = radius * math.sin(angle + math.pi)

    z2 = 0

    location2 = Vector((x2, y2, z2))

    sphere2.location = location2

    sphere2.keyframe_insert(data_path="location", frame=frame_count)





# 逆回転 球体2個


import bpy

import math

from mathutils import Vector


zion_speed_round = 1.0 # 回転速度を設定する

radius = 30 # 半径を設定する


# 球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(location=Vector((0,0,0)), radius=1)

sphere1 = bpy.context.active_object

sphere1.name = "Sphere1"


# 半周ズレた球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(location=Vector((0,0,0)), radius=2)

sphere2 = bpy.context.active_object

sphere2.name = "Sphere2"


# 球体を回転する

frame_count = 0

for i in range(1, 10000):

    frame_count += 1

    angle = -2 * math.pi / 100 * frame_count * zion_speed_round

    x1 = radius * math.cos(angle)

    y1 = radius * math.sin(angle)

    z1 = 0

    location1 = Vector((x1, y1, z1))

    sphere1.location = location1

    sphere1.keyframe_insert(data_path="location", frame=frame_count)


    x2 = radius * math.cos(angle + math.pi)

    y2 = radius * math.sin(angle + math.pi)

    z2 = 0

    location2 = Vector((x2, y2, z2))

    sphere2.location = location2

    sphere2.keyframe_insert(data_path="location", frame=frame_count)








#angle = -2 * i * math.pi / 16

#ここで、-2を掛けることで反対方向に回転します。

# 反対周り


import bpy

import math

from mathutils import Vector


zion_speed_round = 0.5 # 回転速度を設定する

radius = 30 # 半径を設定する


# 球体を作成する

bpy.ops.mesh.primitive_uv_sphere_add(location=Vector((0,0,0)), radius=1)

sphere = bpy.context.active_object

sphere.name = "Sphere"


# 球体を回転する

frame_count = 0

for i in range(1, 10000):

    frame_count += 1

    angle = -2 * math.pi / 100 * frame_count * zion_speed_round


    x = radius * math.cos(angle)


    y = radius * math.sin(angle)


    z = 0


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


    sphere.location = location


    sphere.keyframe_insert(data_path="location", frame=frame_count)



 




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

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