2023年6月21日水曜日

20230622 光円錐

 




blendeer python でスクリプト書き出す








000を中心に 半径1のトーラス マイナー半径 0.02 を z=-1に描く

0、0、0.1を中心に 半径1-0.01のトーラス マイナー半径 0.02 を z=ー0.9に描く

0、0、0.2を中心に 半径1-0.02のトーラス マイナー半径 0.02 を z=ー0.8に描く


これを繰り返し z=0 まで トーラスを複数描く


import bpy

import math


center_x = 0.0

center_y = 0.0

minor_radius = 0.02

z = -1.0

z_increment = 0.1

num_toruses = 11


for i in range(num_toruses):

    major_radius = 1.0 - (i * 0.1)

    bpy.ops.mesh.primitive_torus_add(

        align='WORLD',

        location=(center_x, center_y, z),

        rotation=(0, 0, 0),

        major_radius=major_radius,

        minor_radius=minor_radius,

        major_segments=48,

        minor_segments=12

    )


    torus_obj = bpy.context.object

    bpy.context.view_layer.objects.active = torus_obj

    bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS', center='BOUNDS')


    z += z_increment






今度は 

z=0から Z=1に トーラスを11個描く

半径が 0から 0.1ずつ大きくする


この11個のトーラスに future torus 0.0 から 1.0の連番で名前を付ける



import bpy

import math


center_x = 0.0

center_y = 0.0

minor_radius = 0.02

z = 0.0

z_increment = 1.0 / 10.0  # Zの増分を計算

num_toruses = 11


for i in range(num_toruses):

    major_radius = i * 0.1  # 半径を0から0.1ずつ増加させる

    bpy.ops.mesh.primitive_torus_add(

        align='WORLD',

        location=(center_x, center_y, z),

        rotation=(0, 0, 0),

        major_radius=major_radius,

        minor_radius=minor_radius,

        major_segments=48,

        minor_segments=12

    )


    torus_obj = bpy.context.object

    bpy.context.view_layer.objects.active = torus_obj

    bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS', center='BOUNDS')


    # トーラスに名前を付ける

    torus_obj.name = "FutureTorus" + str(round(major_radius, 1))


    z += z_increment








今度は 

z=0から Z=-1に トーラスを11個描く

半径が 0から 0.1ずつ大きくする

この11個のトーラスに past torus -0.0 から -1.0 の連番で名前を付ける




import bpy

import math


center_x = 0.0

center_y = 0.0

minor_radius = 0.02

z = 0.0

z_decrement = -1.0 / 10.0  # Zの減分を計算

num_toruses = 11


for i in range(num_toruses):

    major_radius = i * 0.1  # 半径を0から0.1ずつ増加させる

    bpy.ops.mesh.primitive_torus_add(

        align='WORLD',

        location=(center_x, center_y, z),

        rotation=(0, 0, 0),

        major_radius=major_radius,

        minor_radius=minor_radius,

        major_segments=48,

        minor_segments=12

    )


    torus_obj = bpy.context.object

    bpy.context.view_layer.objects.active = torus_obj

    bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS', center='BOUNDS')


    # トーラスに名前を付ける

    torus_obj.name = "PastTorus" + str(round(-major_radius, 1))


    z += z_decrement




コレクション名を 作る


Future torus

Past torus

+5 Future torus

+5 Past torus

-5 Future torus

-5 Past torus


6つ作る



import bpy


collection_names = ["Future torus", "Past torus", "+5 Future torus", "+5 Past torus", "-5 Future torus", "-5 Past torus"]


for collection_name in collection_names:

    new_collection = bpy.data.collections.new(collection_name)

    bpy.context.scene.collection.children.link(new_collection)




 x軸に +5 移動させて 名前を +5 PastTorus で連番に


以下を x軸に +5  移動させて 連番名を +5 Future torus にして

以下を x軸に ー5  移動させて 連番名を -5 Future torus にして


2023年6月20日火曜日

20230620 繰り返しの 頭の中の光線



blender python で


0,-10,0 と

0,10,0 を 両端とする


円柱を 太さ 0.1 で作る

 

BlenderのPythonを使用して、太さ0.1の円柱を座標(0, -10, 0)と(0, 10, 0)を両端として作成するには、以下のコードを使用します。



円柱が 描かれていない

円柱の中心は 0,0,0


円柱の中心が原点(0, 0, 0)であるように修正します。以下のコードを使用して、

BlenderのPythonで太さ0.1の円柱を中心(0, 0, 0)で作成



最初から やりなし 長さ 20の 円柱を 作る 

太さは 0.05


円柱の中心は 0,0,0

円柱の中心軸は y軸に 重なる


円柱の中心軸の両端は

0,-10,0 と

0,10,0


import bpy


# Set up the scene

bpy.context.scene.cursor.location = (0, 0, 0)

bpy.context.scene.cursor.rotation_euler = (0, 0, 0)


# Create a new mesh object

bpy.ops.mesh.primitive_cylinder_add(

    vertices=32,    # Number of vertices

    radius=0.05,     # Radius of the cylinder

    depth=20,       # Length of the cylinder

    location=(0, 0, 0),    # Center of the cylinder

    rotation=(1.5708, 0, 0)    # Rotate 90 degrees around the X-axis

)


# Rename the object

cylinder_obj = bpy.context.object

cylinder_obj.name = "Cylinder"





球体を 指定の場所に作る

球体の半径は 0.2


球体の位置は 

0,-1,0

0,1,0

0.5,-1,0

0.5,1.0

1,-1,0

1,1.0



球体の名前は

球(0,-1,0)


のように 名付ける





import bpy


# Define the positions of the spheres

positions = [

    (0, -1, 0),

    (0, 1, 0),

    (0.5, -1, 0),

    (0.5, 1.0, 0),

    (1, -1, 0),

    (1, 1.0, 0)

]


# Create spheres at the specified positions

for pos in positions:

    bpy.ops.mesh.primitive_uv_sphere_add(

        segments=32,    # Number of segments

        ring_count=16,  # Number of rings

        radius=0.2,     # Radius of the sphere

        location=pos    # Position of the sphere

    )

    # Rename each sphere based on its position

    sphere_obj = bpy.context.object

    sphere_obj.name = f"Sphere ({pos[0]},{pos[1]},{pos[2]})"




  (0, 0, 0),

    (0, 0, 1),

    (0, 0, 0.5)



(0, 0, 1),

    (0.5,0,  1),

    (1, 0, 1)





import bpy


# Create sphere at (0, -1, 0)

bpy.ops.mesh.primitive_uv_sphere_add(

    segments=32,    # Number of segments

    ring_count=16,  # Number of rings

    radius=0.2,     # Radius of the sphere

    location=(0, -1, 0)    # Position of the sphere

)


# Rename the sphere

sphere1_obj = bpy.context.object

sphere1_obj.name = "Sphere (0,-1,0)"


# Create sphere at (0, 1, 0)

bpy.ops.mesh.primitive_uv_sphere_add(

    segments=32,    # Number of segments

    ring_count=16,  # Number of rings

    radius=0.2,     # Radius of the sphere

    location=(0, 1, 0)    # Position of the sphere

)


# Rename the sphere

sphere2_obj = bpy.context.object

sphere2_obj.name = "Sphere (0,1,0)"






000 を 中心とする

1辺2の立方体を作る






2023年6月14日水曜日

20230615 thu 室内から窓面 窓面の外の線路 3つの時刻表示 



blender pythonで 


000を 半球の中心にして

半径1 で 描く





import bpy


# Create a new sphere mesh

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


# Select the sphere object

sphere_obj = bpy.context.object

sphere_obj.select_set(True)

bpy.context.view_layer.objects.active = sphere_obj


# Enter Edit Mode for the sphere

bpy.ops.object.mode_set(mode='EDIT')


# Deselect all vertices

bpy.ops.mesh.select_all(action='DESELECT')


# Select the vertices in the upper half of the sphere

bpy.ops.mesh.select_3d_cursor(location=(0, 0, 0))

bpy.ops.mesh.select_circle(x_axis=True, radius=1, location=(0, 0, 0), normal=(0, 0, -1), use_extend=False)


# Delete the selected vertices

bpy.ops.mesh.delete(type='VERT')


# Exit Edit Mode for the sphere

bpy.ops.object.mode_set(mode='OBJECT')


# Set the origin to the center of the modified sphere

bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS')







blender pythonで 


000を 立方体の中心にして

辺の長さ 2



2023年6月3日土曜日

20230604 sun 球体と 3つの線路

 







blender python で スクリプト全体を コードを「code block」の形式で示す


半径1の球体

中心 0,0,0


半径√2の球体

中心 0,0,0


半径√3の球体

中心 0,0,0



大きい球体から


透明 青

透明 ミドリ

透明 赤 


オブヘクト名を 付ける

sphere √3B

sphere √2G

sphere 1 R


RGBA で 色を設定する


マテリアル プロパティ

alpha 15%

blend mode を alpha blend 選択 



コレクション 名を 球体√  を作る

オブジェクトを入れるが リンクを作らない


オブジェクトをリンクなしで

コレクションに移動



2023年5月22日月曜日

20230523 グローブ ジャングル

 



import bpy

import math


# 球体を作成する

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


# yz平面にトーラスを作成する

bpy.ops.mesh.primitive_torus_add(

    align='WORLD',

    location=(0, 0, 0),

    rotation=(math.radians(90), 0, 0),

    major_radius=0.9,

    minor_radius=0.1,

    major_segments=48,

    minor_segments=12

)


# zx平面にトーラスを作成する

bpy.ops.mesh.primitive_torus_add(

    align='WORLD',

    location=(0, 0, 0),

    rotation=(0, math.radians(90), 0),

    major_radius=0.9,

    minor_radius=0.1,

    major_segments=48,

    minor_segments=12

)


# xy平面にトーラスを作成する

bpy.ops.mesh.primitive_torus_add(

    align='WORLD',

    location=(0, 0, 0),

    rotation=(0, 0, 0),

    major_radius=0.9,

    minor_radius=0.1,

    major_segments=48,

    minor_segments=12

)


2023年5月11日木曜日

20230512 球体2つ  16 x 32 = 512

 





配布 blenderzionad


配布 20230512 球体表面ランダム 002 球体2つ.blend

https://drive.google.com/file/d/1SfV7Lc8CL5PY6Y53iCTjwgQCo7ZMIhO9/view?usp=share_link



2回 実行して 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)





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)