2023年7月31日月曜日

20230801b 3x3x3 立方体 箱庭



blender python 


立方体を作る

中心は 000

1辺 20


メッシュ

マテリアル

透明度 10%

ものすごい薄い水色







import bpy


# 立方体の1辺の長さを設定

side_length = 20


# 透明度を設定(0.0から1.0の間で設定。0.0は完全に透明、1.0は完全に不透明)

transparency = 0.1


# 立方体を作成

bpy.ops.mesh.primitive_cube_add(size=side_length, location=(0, 0, 0))

cube = bpy.context.active_object


# マテリアルを作成

material = bpy.data.materials.new(name="TransparentMaterial")

cube.data.materials.append(material)


# マテリアルの設定

material.use_nodes = True

nodes = material.node_tree.nodes

bsdf_node = nodes["Principled BSDF"]

transparent_node = nodes.new(type='ShaderNodeBsdfTransparent')

mix_shader_node = nodes.new(type='ShaderNodeMixShader')


# ノードの接続

material.node_tree.links.new(bsdf_node.outputs['BSDF'], mix_shader_node.inputs[1])

material.node_tree.links.new(transparent_node.outputs['BSDF'], mix_shader_node.inputs[2])

material.node_tree.links.new(mix_shader_node.outputs['Shader'], material.node_tree.nodes['Material Output'].inputs['Surface'])


# 透明度を設定

bsdf_node.inputs["Base Color"].default_value = (0.5, 0.8, 1.0, 1.0)  # 薄い水色 (R:0.5, G:0.8, B:1.0, A:1.0)

mix_shader_node.inputs[0].default_value = transparency  # 透明度を設定


# 透明な影を設定(オブジェクトが影を落とすが、影が見えなくなります)

cube.cycles.is_shadow_catcher = True






 

基本系 配布 001 単位円 torus と xyz軸 円柱

https://drive.google.com/file/d/1adh0pC0n5MUfaPnsQcab8CnTvHu_JqLg/view?usp=drive_link

 

基本系 配布 002 単位2長さ balls

https://drive.google.com/file/d/1vyg5oFWmw_TK8nwp5TmVSfLH94I6rTaY/view?usp=drive_link

 

基本系 配布 003 単位2長さ balls 光時計セット 

https://drive.google.com/file/d/1u2Rn_nVBcewe39Vokua9C5n25cdivyyL/view?usp=drive_link

 

blender 基本系 配布 カタログ 2023 - zionad_mainのブログ https://mokuji000zionad.hatenablog.com/entry/2023/07/31/095208 





数字変更 20230801b 半径1の円 移動複製





名前は 小数2桁まで表示 


   center = (0, 0, 0)

   center = (1, 0, 0)

   center = ((3**0.5)/2, 0, 0)

   center = (2, 0, 0)

   center = (-1, 0, 0)






import bpy

import math


def create_circle_on_plane(plane, color):

    # Set the circle's radius and center

    radius = 1

    center = (0.5, 0, 0)


    # Create a new mesh circle with filled ngon

    bpy.ops.mesh.primitive_circle_add(radius=radius, location=center, fill_type='NGON')


    # Rename the circle object with the rounded position

    rounded_center = tuple(round(coord, 2) for coord in center)

    circle_obj = bpy.context.active_object

    circle_obj.name = "Circle_" + plane + "_({:.2f}, {:.2f}, {:.2f})".format(*rounded_center)


    # Check if the material already exists, otherwise create a new one

    material_name = "Circle_Material_" + plane

    if material_name not in bpy.data.materials:

        material = bpy.data.materials.new(name=material_name)

    else:

        material = bpy.data.materials[material_name]


    # Assign the color to the material

    material.use_nodes = False

    material.diffuse_color = color


    # Create a material slot and assign the material to the circle object

    if not circle_obj.data.materials:

        circle_obj.data.materials.append(material)

    else:

        circle_obj.data.materials[0] = material


    if plane == "YZ":

        # Swap Y and Z components of the vertices for YZ plane

        for vertex in circle_obj.data.vertices:

            temp_y = vertex.co.y

            vertex.co.y = vertex.co.z

            vertex.co.z = temp_y


        # Z-axis rotation (90 degrees) for YZ plane

        rotation_angle = math.radians(90)

        bpy.context.view_layer.objects.active = circle_obj

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

    elif plane == "ZX":

        # Swap Y and Z components of the vertices for ZX plane

        for vertex in circle_obj.data.vertices:

            temp_y = vertex.co.y

            vertex.co.y = vertex.co.z

            vertex.co.z = temp_y



# xy plane - 0, 191, 255 (Deep Sky Blue)

create_circle_on_plane("XY", (0/255, 191/255, 255/255, 1.0))


# yz plane - (255, 105, 180)

create_circle_on_plane("YZ", (255/255, 105/255, 180/255, 1.0))


# zx plane - 薄緑 (Light Green) - (144, 238, 144)

create_circle_on_plane("ZX", (144/255, 238/255, 144/255, 1.0))










# コレクションを作る 重複の場合 作らない

import bpy


# List of collection names

collection_names = [

 

   "円中心 (0, 0, 0)",

   "円中心 (3^(0.5), 0, 0)",

 "円中心 (0.5, 0, 0)",

 "円中心 (1, 0, 0)",

   "円中心 (2, 0, 0)",

    "xyz 軸 円柱"

]


# Function to create a new collection if it doesn't exist

def create_collection_if_not_exists(name):

    if name not in bpy.data.collections:

        collection = bpy.data.collections.new(name)

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


# Create collections

for name in collection_names:

    create_collection_if_not_exists(name)












 

基本系 配布 001 単位円 torus と xyz軸 円柱

https://drive.google.com/file/d/1adh0pC0n5MUfaPnsQcab8CnTvHu_JqLg/view?usp=drive_link

 

基本系 配布 002 単位2長さ balls

https://drive.google.com/file/d/1vyg5oFWmw_TK8nwp5TmVSfLH94I6rTaY/view?usp=drive_link

 

基本系 配布 003 単位2長さ balls 光時計セット 

https://drive.google.com/file/d/1u2Rn_nVBcewe39Vokua9C5n25cdivyyL/view?usp=drive_link

 

blender 基本系 配布 カタログ 2023 - zionad_mainのブログ https://mokuji000zionad.hatenablog.com/entry/2023/07/31/095208 





半径1の円 メッシュ マテリアル






色代えの  見本


# xy plane - 0, 191, 255 (Deep Sky Blue)
create_circle_on_plane("XY", (0/255, 191/255, 255/255, 1.0))








「配布単品 20230801 半径1の円板 色付き 001.blend」を共有











# 半径1の円板 xy yz zx

import bpy
import math

def create_circle_on_plane(plane, color):
    # Set the circle's radius and center
    radius = 1
    center = (0, 0, 0)

    # Create a new mesh circle with filled ngon
    bpy.ops.mesh.primitive_circle_add(radius=radius, location=center, fill_type='NGON')

    # Rename the circle object
    circle_obj = bpy.context.active_object
    circle_obj.name = "Circle_" + plane

    # Check if the material already exists, otherwise create a new one
    material_name = "Circle_Material_" + plane
    if material_name not in bpy.data.materials:
        material = bpy.data.materials.new(name=material_name)
    else:
        material = bpy.data.materials[material_name]

    # Assign the color to the material
    material.use_nodes = False
    material.diffuse_color = color

    # Create a material slot and assign the material to the circle object
    if not circle_obj.data.materials:
        circle_obj.data.materials.append(material)
    else:
        circle_obj.data.materials[0] = material

    if plane == "YZ":
        # Swap Y and Z components of the vertices for YZ plane
        for vertex in circle_obj.data.vertices:
            temp_y = vertex.co.y
            vertex.co.y = vertex.co.z
            vertex.co.z = temp_y

        # Z-axis rotation (90 degrees) for YZ plane
        rotation_angle = math.radians(90)
        bpy.context.view_layer.objects.active = circle_obj
        bpy.ops.transform.rotate(value=rotation_angle, orient_axis='Z')
    elif plane == "ZX":
        # Swap Y and Z components of the vertices for ZX plane
        for vertex in circle_obj.data.vertices:
            temp_y = vertex.co.y
            vertex.co.y = vertex.co.z
            vertex.co.z = temp_y



# xy plane - 0, 191, 255 (Deep Sky Blue)
create_circle_on_plane("XY", (0/255, 191/255, 255/255, 1.0))

# yz plane - (255, 105, 180)
create_circle_on_plane("YZ", (255/255, 105/255, 180/255, 1.0))

# zx plane - 薄緑 (Light Green) - (144, 238, 144)
create_circle_on_plane("ZX", (144/255, 238/255, 144/255, 1.0))







# コレクションを作る 重複の場合 作らない

import bpy


# List of collection names

collection_names = [

    "単位円 torus",

    "xyz 軸 円柱",

  "xyz 軸 円板",

]


# Function to create a new collection if it doesn't exist

def create_collection_if_not_exists(name):

    if name not in bpy.data.collections:

        collection = bpy.data.collections.new(name)

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


# Create collections

for name in collection_names:

    create_collection_if_not_exists(name)








2023年7月30日日曜日

20230731b 光時計セット 追加 円板 メッシュ マテリアル


ああああああ




blender python 


xy平面に 円を作って
半径 1
円の中心 000


色を付けたい
メッシュ 作った?
マテリアルは?


import bpy

# Set the circle's radius and center
radius = 1
center = (0, 0, 0)

# Create a new mesh circle with filled ngon
bpy.ops.mesh.primitive_circle_add(radius=radius, location=center, fill_type='NGON')

# Rename the circle object
circle_obj = bpy.context.active_object
circle_obj.name = "Circle_XY"

# Set the color for the circle
color = (0.8, 0.2, 0.3)  # Use RGB values (range 0.0 to 1.0)
material_name = "Circle_Material"

# Check if the material already exists, otherwise create a new one
if material_name not in bpy.data.materials:
    material = bpy.data.materials.new(name=material_name)
else:
    material = bpy.data.materials[material_name]

# Assign the color to the material
material.use_nodes = False
material.diffuse_color = color

# Create a material slot and assign the material to the circle object
if not circle_obj.data.materials:
    circle_obj.data.materials.append(material)
else:
    circle_obj.data.materials[0] = material








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




#半径1の円板 xy yz zx

import bpy
import math

def create_circle_on_plane(plane, color):
    # Set the circle's radius and center
    radius = 1
    center = (0, 0, 0)

    # Create a new mesh circle with filled ngon
    bpy.ops.mesh.primitive_circle_add(radius=radius, location=center, fill_type='NGON')

    # Rename the circle object
    circle_obj = bpy.context.active_object
    circle_obj.name = "Circle_" + plane

    # Check if the material already exists, otherwise create a new one
    material_name = "Circle_Material_" + plane
    if material_name not in bpy.data.materials:
        material = bpy.data.materials.new(name=material_name)
    else:
        material = bpy.data.materials[material_name]

    # Assign the color to the material
    material.use_nodes = False
    material.diffuse_color = color

    # Create a material slot and assign the material to the circle object
    if not circle_obj.data.materials:
        circle_obj.data.materials.append(material)
    else:
        circle_obj.data.materials[0] = material

    if plane == "YZ":
        # Swap Y and Z components of the vertices for YZ plane
        for vertex in circle_obj.data.vertices:
            temp_y = vertex.co.y
            vertex.co.y = vertex.co.z
            vertex.co.z = temp_y

        # Z-axis rotation (90 degrees) for YZ plane
        rotation_angle = math.radians(90)
        bpy.context.view_layer.objects.active = circle_obj
        bpy.ops.transform.rotate(value=rotation_angle, orient_axis='Z')
    elif plane == "ZX":
        # Swap Y and Z components of the vertices for ZX plane
        for vertex in circle_obj.data.vertices:
            temp_y = vertex.co.y
            vertex.co.y = vertex.co.z
            vertex.co.z = temp_y

# xy plane - 薄青 (Light Blue)
create_circle_on_plane("XY", (0.2, 0.2, 0.9, 1.0))

# yz plane - 淡赤 (Light Red)
create_circle_on_plane("YZ", (0.8, 0.2, 0.1, 1.0))

# zx plane - 薄緑 (Light Green)
create_circle_on_plane("ZX", (0.1, 0.9, 0.3, 1.0))








2023731a 21個 球体 等間隔 2単位長さ

a



# コレクションを作る 重複の場合 作らない

import bpy


# List of collection names

collection_names = [


  "axis_x_balls",

   "axis_y_balls",

    "axis_z_balls",


"ba_X=0.5 balls", 

"ba_X=1 balls",

 "ba_(√3)/2 balls",



    "xyz 軸 balls"

]


# Function to create a new collection if it doesn't exist

def create_collection_if_not_exists(name):

    if name not in bpy.data.collections:

        collection = bpy.data.collections.new(name)

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


# Create collections

for name in collection_names:

    create_collection_if_not_exists(name)








blender python


21個の球体を作る

球体の大きさ0.06

指定位置の間に等間隔に配置する


(x,y,z)

=(0,1、0)から

(0,-1、0)


連番で名前をつける "ba_a連番(0,1、0)(0,-1、0)ball”

位置は 小数点1桁まで表示



連番で名前をつける "ba_a連番(0,1、0)(0,-1、0)ball”

連番で名前をつける "ba_b連番(0,1、0)(0,-1、0)ball”

のように 名前を付ける



(x,y,z)

=(0,1、0)から(0,-1、0)


(x,y,z)

=(-1,0、0)から(1,0、0)


(x,y,z)

=(0,0、ー1)から(0,0、1)


(x,y,z)

=(1,1、0)から(1,-1、0)


import bpy


# Function to create a new sphere object and rename it with a sequential number

def create_sphere_object(location, name):

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.06, location=location)

    obj = bpy.context.active_object

    obj.name = name


# Number of spheres to create

num_spheres = 21


# Define the ranges for each axis

ranges = [

    ((0, 1, 0), (0, -1, 0)),

    ((-1, 0, 0), (1, 0, 0)),

    ((0, 0, -1), (0, 0, 1))

]


# Loop through the ranges and create sphere objects with the desired prefixes

prefixes = ["axis_y", "axis_x", "axis_z"]


for i, (start_position, end_position) in enumerate(ranges):

    prefix = prefixes[i]

    step_size = [(end_position[j] - start_position[j]) / (num_spheres - 1) for j in range(3)]

    

    for j in range(num_spheres):

        x = round(start_position[0] + j * step_size[0], 1)

        y = round(start_position[1] + j * step_size[1], 1)

        z = round(start_position[2] + j * step_size[2], 1)

        object_name = f"{prefix}_{str(j+1).zfill(3)}({x},{y},{z})_({x},{-y},{z})_ball"

        create_sphere_object((x, y, z), object_name)






 

基本系 配布 001 単位円 torus と xyz軸 円柱

https://drive.google.com/file/d/1adh0pC0n5MUfaPnsQcab8CnTvHu_JqLg/view?usp=drive_link

 

基本系 配布 002 単位2長さ balls

https://drive.google.com/file/d/1vyg5oFWmw_TK8nwp5TmVSfLH94I6rTaY/view?usp=drive_link

 

基本系 配布 003 単位2長さ balls 光時計セット 

https://drive.google.com/file/d/1u2Rn_nVBcewe39Vokua9C5n25cdivyyL/view?usp=drive_link

 

blender 基本系 配布 カタログ 2023 - zionad_mainのブログ https://mokuji000zionad.hatenablog.com/entry/2023/07/31/095208 





2023年7月29日土曜日

20230730a 単位円を貫く円柱

 


目次 blender 部品 2023 - zionad_mainのブログ

blender 中間部品 イメージ目次 2023

blender 使い方 目次 2023 - zionad_mainのブログ




円柱を作る

長さ 4

中心 000

半径 0.03


x軸

y軸

z軸

合計 3つの円柱を作る











import bpy


# Function to create a cylinder along the specified axis

def create_cylinder(axis, name):

    bpy.ops.mesh.primitive_cylinder_add(vertices=32, radius=0.03, depth=4, location=(0, 0, 0))

    cylinder = bpy.context.object

    if axis == "x":

        cylinder.rotation_euler = (1.5708, 0, 0)  # 90 degrees in radians around X axis

    elif axis == "y":

        cylinder.rotation_euler = (0, 1.5708, 0)  # 90 degrees in radians around Y axis

    cylinder.name = name


# Create cylinders along each axis

create_cylinder("y", "名称X軸円柱")

create_cylinder("x", "名称y軸円柱")

create_cylinder("z", "Z軸円柱")





20230730a 単位円の トーラス

aaaaa 



目次 blender 部品 2023 - zionad_mainのブログ

blender 中間部品 イメージ目次 2023

blender 使い方 目次 2023 - zionad_mainのブログ
















xy平面に描いたトーラスを zx平面と yz平面にも描いて



import bpy


# Function to create a torus in the specified plane

def create_torus(plane):

    bpy.ops.mesh.primitive_torus_add(align='WORLD', location=(0, 0, 0), rotation=(0, 0, 0),

                                     major_radius=1, minor_radius=0.04, major_segments=48, minor_segments=12)

    torus = bpy.context.object

    if plane == "xy":

        torus.rotation_euler = (0, 0, 0)

    elif plane == "zx":

        torus.rotation_euler = (1.5708, 0, 0)  # 90 degrees in radians around X axis

    elif plane == "yz":

        torus.rotation_euler = (0, 1.5708, 0)  # 90 degrees in radians around Y axis

    torus.name = f"Torus {plane.upper()} Plane"


# Create tori in each plane

create_torus("xy")

create_torus("yz")

create_torus("zx")