2023年5月10日水曜日

20230511 bbb 球体 回転 球体表面 3つの球体

保存すると回転 開始しない



import bpy

import math


zion_kaiten = 0.2  # 回転速度(秒あたりの度数)


# 大きな球体を作成

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

sphere = bpy.context.object


# 大きな球体のマテリアルにアルファブレンドを設定

sphere.data.materials.append(bpy.data.materials.new(name="SphereMaterial"))

sphere.data.materials[0].use_nodes = True

nodes = sphere.data.materials[0].node_tree.nodes

nodes["Principled BSDF"].inputs["Alpha"].default_value = 0.1


# 小さな球体の頂点を作成し、色を設定

vertices = []

colors = [(0, 0, 1, 1), (1, 0, 0, 1), (0, 1, 0, 1)]  # 青、赤、緑


angle = 2 * math.pi / 3  # 120度をラジアンに変換


for i in range(3):

    x = math.cos(i * angle)

    y = math.sin(i * angle)

    z = 0

    

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=(x, y, z))

    vertex = bpy.context.object

    

    # 小さな球体の色を設定

    vertex.data.materials.append(bpy.data.materials.new(name="VertexMaterial"))

    vertex.data.materials[0].diffuse_color = colors[i]

    

    vertices.append(vertex)


# アニメーションのための設定

rotation_angle = 0

rotation_speed = math.radians(zion_kaiten)  # ラジアンに変換


def rotate_objects(scene):

    global rotation_angle


    # 大きな球体と小さな球体をアクティブにする

    bpy.context.view_layer.objects.active = sphere

    sphere.select_set(True)

    for vertex in vertices:

        bpy.context.view_layer.objects.active = vertex

        vertex.select_set(True)

    

    # オブジェクトをZ軸周りに回転する

    bpy.ops.transform.rotate(value=rotation_speed, orient_axis='Z')


    rotation_angle += math.degrees(rotation_speed)


# アニメーションを実行する

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


# トーラスを作成

bpy.ops.mesh.primitive_torus_add(

    align='WORLD',

    location=(0, 0, 0),

    rotation=(0, 0, 0),

    major_radius=1,

    minor_radius=0.05

)

torus = bpy.context.object


# トーラスのアニメーションのための設定

torus_rotation_angle = 0

torus_rotation_speed = math.radians(zion_kaiten)  # ラジアンに変換


def rotate_torus(scene):

    global torus_rotation_angle


    bpy.context.view










#原型 色なし


import bpy

import math


zion_kaiten = 0.2  # Rotation speed in degrees per second


# Create the sphere

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

sphere = bpy.context.object


# Create the vertices of the equilateral triangle

vertices = []

angle = 2 * math.pi / 3  # 120 degrees in radians


for i in range(3):

    x = math.cos(i * angle)

    y = math.sin(i * angle)

    z = 0

    

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=(x, y, z))

    vertex = bpy.context.object

    vertices.append(vertex)


# Set up rotation animation

rotation_angle = 0

rotation_speed = math.radians(zion_kaiten)  # Convert to radians per second


def rotate_z_axis(scene):

    global rotation_angle


    # Activate the sphere and the vertices

    bpy.context.view_layer.objects.active = sphere

    sphere.select_set(True)

    for vertex in vertices:

        bpy.context.view_layer.objects.active = vertex

        vertex.select_set(True)

    

    # Rotate the objects around the z-axis

    bpy.ops.transform.rotate(value=rotation_speed, orient_axis='Z')


    rotation_angle += math.degrees(rotation_speed)


# Run the animation

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









#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa



import bpy
import math

zion_kaiten = 0.2  # Rotation speed in degrees per second

# Create the sphere
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, location=(0, 0, 0))
sphere = bpy.context.object

# Set alpha blending for the large sphere
sphere.data.materials.append(bpy.data.materials.new(name="SphereMaterial"))
sphere.data.materials[0].use_nodes = True
nodes = sphere.data.materials[0].node_tree.nodes
nodes["Principled BSDF"].inputs["Alpha"].default_value = 0.1

# Create the vertices of the equilateral triangle and color the small spheres
vertices = []
colors = [(0, 0, 1, 1), (1, 0, 0, 1), (0, 1, 0, 1)]  # Blue, Red, Green

angle = 2 * math.pi / 3  # 120 degrees in radians

for i in range(3):
    x = math.cos(i * angle)
    y = math.sin(i * angle)
    z = 0
    
    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=(x, y, z))
    vertex = bpy.context.object
    
    # Set color for the small sphere
    vertex.data.materials.append(bpy.data.materials.new(name="VertexMaterial"))
    vertex.data.materials[0].diffuse_color = colors[i]
    
    vertices.append(vertex)

# Set up rotation animation
rotation_angle = 0
rotation_speed = math.radians(zion_kaiten)  # Convert to radians per second

def rotate_z_axis(scene):
    global rotation_angle

    # Activate the sphere and the vertices
    bpy.context.view_layer.objects.active = sphere
    sphere.select_set(True)
    for vertex in vertices:
        bpy.context.view_layer.objects.active = vertex
        vertex.select_set(True)
    
    # Rotate the objects around the z-axis
    bpy.ops.transform.rotate(value=rotation_speed, orient_axis='Z')

    rotation_angle += math.degrees(rotation_speed)

# Run the animation
bpy.app.handlers.frame_change_pre.append(rotate_z_axis)





あああああああああああああああああああああああああああああ





z=0 に 000を中心とする半径1のトーラス

マイナー半径0.05 を作成し 追加し


これも 大きい球体に追随させる








import bpy

import math


zion_kaiten = 0.2  # Rotation speed in degrees per second


# Create the sphere

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

sphere = bpy.context.object


# Set alpha blending for the large sphere

sphere.data.materials.append(bpy.data.materials.new(name="SphereMaterial"))

sphere.data.materials[0].use_nodes = True

nodes = sphere.data.materials[0].node_tree.nodes

nodes["Principled BSDF"].inputs["Alpha"].default_value = 0.1


# Create the vertices of the equilateral triangle and color the small spheres

vertices = []

colors = [(0, 0, 1, 1), (1, 0, 0, 1), (0, 1, 0, 1)]  # Blue, Red, Green


angle = 2 * math.pi / 3  # 120 degrees in radians


for i in range(3):

    x = math.cos(i * angle)

    y = math.sin(i * angle)

    z = 0

    

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=(x, y, z))

    vertex = bpy.context.object

    

    # Set color for the small sphere

    vertex.data.materials.append(bpy.data.materials.new(name="VertexMaterial"))

    vertex.data.materials[0].diffuse_color = colors[i]

    

    vertices.append(vertex)


# Set up rotation animation for the spheres

rotation_angle = 0

rotation_speed = math.radians(zion_kaiten)  # Convert to radians per second


def rotate_z_axis(scene):

    global rotation_angle


    # Activate the sphere and the vertices

    bpy.context.view_layer.objects.active = sphere

    sphere.select_set(True)

    for vertex in vertices:

        bpy.context.view_layer.objects.active = vertex

        vertex.select_set(True)

    

    # Rotate the objects around the z-axis

    bpy.ops.transform.rotate(value=rotation_speed, orient_axis='Z')


    rotation_angle += math.degrees(rotation_speed)


# Run the animation for the spheres

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


# Create the torus

bpy.ops.mesh.primitive_torus_add(

    align='WORLD',

    location=(0, 0, 0),

    rotation=(0, 0, 0),

    major_radius=1,

    minor_radius=0.05

)

torus = bpy.context.object


# Set up rotation animation for the torus

def rotate_torus(scene):

    global rotation_angle


    # Activate the torus

    bpy.context.view_layer.objects.active = torus

    torus.select_set(True)

    

    # Rotate the torus around the z-axis

    bpy.ops.transform.rotate(value=rotation_speed, orient_axis='Z')


# Run the animation for the torus

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


っっっっっっっっっっっっっっっっっっっっっっっっっっっz


import bpy


# カメラの位置を変更する

bpy.data.objects['Camera'].location = (0, 0, 20)

# ライトの位置を変更する

bpy.data.objects['Light'].location = (0, 0, 30)




# 小さな球体 独立 z軸回転


import bpy

import math


zion_kaiten = 0.2  # Rotation speed in degrees per second


# Create the sphere

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

sphere = bpy.context.object


# Set alpha blending for the large sphere

sphere.data.materials.append(bpy.data.materials.new(name="SphereMaterial"))

sphere.data.materials[0].use_nodes = True

nodes = sphere.data.materials[0].node_tree.nodes

nodes["Principled BSDF"].inputs["Alpha"].default_value = 0.1


# Create the vertices of the equilateral triangle and color the small spheres

vertices = []

colors = [(0, 0, 1, 1), (1, 0, 0, 1), (0, 1, 0, 1)]  # Blue, Red, Green


angle = 2 * math.pi / 3  # 120 degrees in radians


for i in range(3):

    x = math.cos(i * angle)

    y = math.sin(i * angle)

    z = 0

    

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=(x, y, z))

    vertex = bpy.context.object

    

    # Set color for the small sphere

    vertex.data.materials.append(bpy.data.materials.new(name="VertexMaterial"))

    vertex.data.materials[0].diffuse_color = colors[i]

    

    vertices.append(vertex)


# Set up rotation animation for the small spheres

rotation_angles = [0, 120, 240]

rotation_speed = math.radians(zion_kaiten)  # Convert to radians per second


def rotate_spheres(scene):

    global rotation_angles


    for i, vertex in enumerate(vertices):

        bpy.context.view_layer.objects.active = vertex

        vertex.select_set(True)

        

        bpy.ops.transform.rotate(value=rotation_speed, orient_axis='Z', center_override=(0, 0, 0))

        

        rotation_angles[i] += math.degrees(rotation_speed)


# Run the animation for the small spheres

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


# Set up rotation animation for the torus

torus_rotation_angle = 0

torus_rotation_speed = math.radians(zion_kaiten)  # Convert to radians per second


def rotate_torus(scene):

    global torus_rotation_angle


    bpy.context.view_layer.objects.active = torus

    torus.select_set(True)


    bpy.ops.transform.rotate(value=torus_rotation_speed, orient_axis='Z', center_override=(0, 0, 0))


    torus_rotation_angle += math.degrees(torus_rotation_speed)


# Create the torus

bpy.ops.mesh.primitive_torus_add(

    align='WORLD',

    location=(0, 0, 0),

    rotation=(0, 0, 0),

    major_radius=1,

    minor_radius=0.05

)

torus = bpy.context.object


# Run the animation for the torus

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