2023年8月4日金曜日

テスト



import bpy

import math


# 小数の桁数を指定

decimal_places = 1

# 図形の大きさ

size = 0.3


def create_plane_at_position(position, width, height, name, x, y, z):

    # 平面を作成(指定した座標に)

    bpy.ops.mesh.primitive_plane_add(size=1, location=position)

    plane = bpy.context.active_object


    # 幅と高さを設定

    plane.scale = (width, height, 1)


    # マテリアルを作成

    material = bpy.data.materials.new(name="Material_" + name)

    plane.data.materials.append(material)


    # マテリアルの設定

    material.use_nodes = False

    material.diffuse_color = (0.0, 1.0, 0.0, 1.0)  # 緑色 (R:0.0, G:1.0, B:0.0, A:1.0)


    # オブジェクトの名前を設定

    formatted_name = "{} ({:.{}f}, {:.{}f}, {:.{}f})".format(name, x, decimal_places, y, decimal_places, z, decimal_places)

    plane.name = formatted_name


def create_cone_or_circle_at_position(position, radius, height, name, x, y, z):

    if position == (0, 0, 0):

        # (0, 0, 0) の場合は円を作成

        bpy.ops.mesh.primitive_circle_add(radius=radius, location=position)

        obj = bpy.context.active_object

    else:

        # それ以外の場合は円錐を作成

        bpy.ops.mesh.primitive_cone_add(vertices=32, radius1=radius, radius2=0, depth=height, location=position)

        obj = bpy.context.active_object


        # 円錐の底面中心を (0, 0, 0) から遠ざける向きを計算

        direction = math.atan2(position[1], position[0])

        distance = math.sqrt(position[0]**2 + position[1]**2 + position[2]**2)

        angle = math.acos(position[2] / distance)

        obj.rotation_euler = (angle + math.pi, 0, direction + math.pi / 2)  # Y軸回りに90度回転


    # マテリアルを作成

    material = bpy.data.materials.new(name="Material_" + name)

    obj.data.materials.append(material)


    # マテリアルの設定

    material.use_nodes = False

    material.diffuse_color = (1.0, 0.0, 0.0, 1.0)  # 赤色 (R:1.0, G:0.0, B:0.0, A:1.0)


    # オブジェクトの名前を設定

    formatted_name = "{} ({:.{}f}, {:.{}f}, {:.{}f})".format(name, x, decimal_places, y, decimal_places, z, decimal_places)

    obj.name = formatted_name


# 円周上に等間隔に12個の図形を作成

radius = 3.0  # 半径

center_x = 0.0  # 中心のX座標

center_y = 0.0  # 中心のY座標

num_objects = 24  # 図形の個数


for i in range(num_objects):

    angle = i * (2 * math.pi / num_objects)  # 等間隔の角度

    x = center_x + radius * math.cos(angle)

    y = center_y + radius * math.sin(angle)

    z = 0


    position = (x, y, z)

    plane_name = "地図位置"

    obj_name = "事象情報"

    

    create_plane_at_position(position, size, size, plane_name, x, y, z)

    create_cone_or_circle_at_position(position, math.sqrt(2) * size / 2, size / 2, obj_name, x, y, z)





 

基本系 配布 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 





20230804  円錐の向きを 指定 改良



import bpy

import math

import mathutils


# 小数の桁数を指定

decimal_places = 1

# 図形の大きさ

size = 0.3


def create_plane_at_position(position, width, height, name, x, y, z):

    # 平面を作成(指定した座標に)

    bpy.ops.mesh.primitive_plane_add(size=1, location=position)

    plane = bpy.context.active_object


    # 幅と高さを設定

    plane.scale = (width, height, 1)


    # マテリアルを作成

    material = bpy.data.materials.new(name="Material_" + name)

    plane.data.materials.append(material)


    # マテリアルの設定

    material.use_nodes = False

    material.diffuse_color = (0.0, 1.0, 0.0, 1.0)  # 緑色 (R:0.0, G:1.0, B:0.0, A:1.0)


    # オブジェクトの名前を設定

    formatted_name = "{} ({:.{}f}, {:.{}f}, {:.{}f})".format(name, x, decimal_places, y, decimal_places, z, decimal_places)

    plane.name = formatted_name


def create_cone_or_circle_at_position(position, radius, height, name, x, y, z, cone_direction=(0, 0, 1)):

    if position == (0, 0, 0):

        # (0, 0, 0) の場合は円を作成

        bpy.ops.mesh.primitive_circle_add(radius=radius, location=position)

        obj = bpy.context.active_object

    else:

        # それ以外の場合は円錐を作成

        bpy.ops.mesh.primitive_cone_add(vertices=32, radius1=radius, radius2=0, depth=height, location=position)

        obj = bpy.context.active_object


        # 円錐の底面中心を指定の方向に向ける

        direction = mathutils.Vector(cone_direction).normalized()

        z_axis = mathutils.Vector((0, 0, 1))

        rotation_quat = z_axis.rotation_difference(direction)

        obj.rotation_mode = 'QUATERNION'

        obj.rotation_quaternion = rotation_quat


    # マテリアルを作成

    material = bpy.data.materials.new(name="Material_" + name)

    obj.data.materials.append(material)


    # マテリアルの設定

    material.use_nodes = False

    material.diffuse_color = (1.0, 0.0, 0.0, 1.0)  # 赤色 (R:1.0, G:0.0, B:0.0, A:1.0)


    # オブジェクトの名前を設定

    formatted_name = "{} ({:.{}f}, {:.{}f}, {:.{}f})".format(name, x, decimal_places, y, decimal_places, z, decimal_places)

    obj.name = formatted_name


# 円周上に等間隔に12個の図形を作成

radius = 3.0  # 半径

center_x = 1.0  # 中心のX座標

center_y = 2.0  # 中心のY座標

num_objects = 12  # 図形の個数


for i in range(num_objects):

    angle = i * (2 * math.pi / num_objects)  # 等間隔の角度

    x = center_x + radius * math.cos(angle)

    y = center_y + radius * math.sin(angle)

    z = 0


    position = (x, y, z)

    plane_name = "地図位置"

    obj_name = "事象情報"

    cone_direction = (1, 1, 1)  # 円錐の向きを指定 (X, Y, Z)


    create_plane_at_position(position, size, size, plane_name, x, y, z)

    create_cone_or_circle_at_position(position, math.sqrt(2) * size / 2, size / 2, obj_name, x, y, z, cone_direction)









 

基本系 配布 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 





20230804 000に進む 事象情報








import bpy

import math


# 小数の桁数を指定

decimal_places = 1

# 図形の大きさ

size = 0.3


def create_plane_at_position(position, width, height, name, x, y, z):

    # 平面を作成(指定した座標に)

    bpy.ops.mesh.primitive_plane_add(size=1, location=position)

    plane = bpy.context.active_object


    # 幅と高さを設定

    plane.scale = (width, height, 1)


    # マテリアルを作成

    material = bpy.data.materials.new(name="Material_" + name)

    plane.data.materials.append(material)


    # マテリアルの設定

    material.use_nodes = False

    material.diffuse_color = (0.0, 1.0, 0.0, 1.0)  # 緑色 (R:0.0, G:1.0, B:0.0, A:1.0)


    # オブジェクトの名前を設定

    formatted_name = "{} ({:.{}f}, {:.{}f}, {:.{}f})".format(name, x, decimal_places, y, decimal_places, z, decimal_places)

    plane.name = formatted_name


def create_cone_or_circle_at_position(position, radius, height, name, x, y, z):

    if position == (0, 0, 0):

        # (0, 0, 0) の場合は円を作成

        bpy.ops.mesh.primitive_circle_add(radius=radius, location=position)

        obj = bpy.context.active_object

    else:

        # それ以外の場合は円錐を作成

        bpy.ops.mesh.primitive_cone_add(vertices=32, radius1=radius, radius2=0, depth=height, location=position)

        obj = bpy.context.active_object


        # 円錐の底面中心を (0, 0, 0) から遠ざける向きを計算

        direction = math.atan2(position[1], position[0])

        distance = math.sqrt(position[0]**2 + position[1]**2 + position[2]**2)

        angle = math.acos(position[2] / distance)

        obj.rotation_euler = (angle + math.pi, 0, direction + math.pi / 2)  # Y軸回りに90度回転


    # マテリアルを作成

    material = bpy.data.materials.new(name="Material_" + name)

    obj.data.materials.append(material)


    # マテリアルの設定

    material.use_nodes = False

    material.diffuse_color = (1.0, 0.0, 0.0, 1.0)  # 赤色 (R:1.0, G:0.0, B:0.0, A:1.0)


    # オブジェクトの名前を設定

    formatted_name = "{} ({:.{}f}, {:.{}f}, {:.{}f})".format(name, x, decimal_places, y, decimal_places, z, decimal_places)

    obj.name = formatted_name


# 円周上に等間隔に12個の図形を作成

radius = 3.0  # 半径

center_x = 1.0  # 中心のX座標

center_y = 2.0  # 中心のY座標

num_objects = 12  # 図形の個数


for i in range(num_objects):

    angle = i * (2 * math.pi / num_objects)  # 等間隔の角度

    x = center_x + radius * math.cos(angle)

    y = center_y + radius * math.sin(angle)

    z = 0


    position = (x, y, z)

    plane_name = "地図位置"

    obj_name = "事象情報"

    

    create_plane_at_position(position, size, size, plane_name, x, y, z)

    create_cone_or_circle_at_position(position, math.sqrt(2) * size / 2, size / 2, obj_name, x, y, z)





 

基本系 配布 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 





20230804 事象情報 円錐で表現














import bpy

import math


# 小数の桁数を指定

decimal_places = 1


def create_plane_at_position(position, width, height, name, x, y, z):

    # 平面を作成(指定した座標に)

    bpy.ops.mesh.primitive_plane_add(size=1, location=position)

    plane = bpy.context.active_object


    # 幅と高さを設定

    plane.scale = (width, height, 1)


    # マテリアルを作成

    material = bpy.data.materials.new(name="Material_" + name)

    plane.data.materials.append(material)


    # マテリアルの設定

    material.use_nodes = False

    material.diffuse_color = (0.0, 1.0, 0.0, 1.0)  # 緑色 (R:0.0, G:1.0, B:0.0, A:1.0)


    # オブジェクトの名前を設定

    formatted_name = "{} ({:.{}f}, {:.{}f}, {:.{}f})".format(name, x, decimal_places, y, decimal_places, z, decimal_places)

    plane.name = formatted_name


def create_cone_or_circle_at_position(position, radius, height, name, x, y, z):

    if position == (0, 0, 0):

        # (0, 0, 0) の場合は円を作成

        bpy.ops.mesh.primitive_circle_add(radius=radius, location=position)

        obj = bpy.context.active_object

    else:

        # それ以外の場合は円錐を作成

        bpy.ops.mesh.primitive_cone_add(vertices=32, radius1=radius, radius2=0, depth=height, location=position)

        obj = bpy.context.active_object


        # 円錐の底面中心を (0, 0, 0) から遠ざける向きを計算

        direction = math.atan2(position[1], position[0])

        distance = math.sqrt(position[0]**2 + position[1]**2 + position[2]**2)

        angle = math.acos(position[2] / distance)

        obj.rotation_euler = (angle + math.pi, 0, direction + math.pi / 2)  # Y軸回りに90度回転


    # マテリアルを作成

    material = bpy.data.materials.new(name="Material_" + name)

    obj.data.materials.append(material)


    # マテリアルの設定

    material.use_nodes = False

    material.diffuse_color = (1.0, 0.0, 0.0, 1.0)  # 赤色 (R:1.0, G:0.0, B:0.0, A:1.0)


    # オブジェクトの名前を設定

    formatted_name = "{} ({:.{}f}, {:.{}f}, {:.{}f})".format(name, x, decimal_places, y, decimal_places, z, decimal_places)

    obj.name = formatted_name


# 正方形の面と円錐または円を作成

size = 0.3  # 正方形の一辺の長さ

spacing = 1.0  # 1間隔の大きさ


for i in range(-5, 6):  # -5から5までの座標に作成

    x = i * spacing

    y = 0

    z = 0


    position = (x, y, z)

    plane_name = "地図位置"

    obj_name = "事象情報"

    

    create_plane_at_position(position, size, size, plane_name, x, y, z)

    create_cone_or_circle_at_position(position, math.sqrt(2) * size / 2, size / 2, obj_name, x, y, z)








 

基本系 配布 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 





20230804 地図の地面相当の正方形











import bpy


def create_plane_at_position(position, width, height, name):

    # 平面を作成(指定した座標に)

    bpy.ops.mesh.primitive_plane_add(size=1, location=position)

    plane = bpy.context.active_object


    # 幅と高さを設定

    plane.scale = (width, height, 1)


    # マテリアルを作成

    material = bpy.data.materials.new(name="Material_" + name)

    plane.data.materials.append(material)


    # マテリアルの設定

    material.use_nodes = False

    material.diffuse_color = (0.0, 1.0, 0.0, 1.0)  # 緑色 (R:0.0, G:1.0, B:0.0, A:1.0)


    # オブジェクトの名前を設定

    plane.name = name


# 正方形の面を複数作成

size = 0.3  # 正方形の一辺の長さ

spacing = 1.0  # 1間隔の大きさ


for i in range(-5, 6):  # -5から5までの座標に作成

    create_plane_at_position((i * spacing, 0, 0), size, size, f"square_face_{i}")






2023年8月2日水曜日

20230803a 写真 貼り テスト


写真 貼り テスト













import bpy

import math


def create_circle_on_plane(plane, color, use_texture=False):

    # ... (Rest of the function remains unchanged) ...


# 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))


# Assign image texture to the specified plane (XY) and leave the others with their original color

image_path = r"C:\aaa 2023 dondon\aaa2023いつもの\blende_gazou\test 貼り付け 2023\2023-08-03_09h12_22.png"  # Replace with the path to your image

image_texture = bpy.data.images.load(image_path)


for plane in ["XY", "YZ", "ZX"]:

    material_name = "Circle_Material_" + plane

    material = bpy.data.materials[material_name]

    material.use_nodes = True

    bsdf_node = material.node_tree.nodes.get('Principled BSDF')


    if plane == "XY":

        texture_node = material.node_tree.nodes.new(type='ShaderNodeTexImage')

        texture_node.image = image_texture

        material.node_tree.links.new(bsdf_node.inputs['Base Color'], texture_node.outputs['Color'])

    else:

        # Reset the color for other circles to their original color

        material.diffuse_color = bpy.context.scene.cursor.color











2023年8月1日火曜日

point 球体より ちょい大きい四角形 平面 床面



Blenderでは半径を持つ2次元の面を直接作成することはできません。2次元の面を作成するには、代わりに幅と高さを持つ平面を作成する必要があります。


以下は、半径0.3の平面を座標(-1, 0, 0)と(1, 0, 0)に作成するスクリプトです。








import bpy


def create_plane_at_position(position, width, height, name):

    # 平面を作成(指定した座標に)

    bpy.ops.mesh.primitive_plane_add(size=1, location=position)

    plane = bpy.context.active_object


    # 幅と高さを設定

    plane.scale = (width, height, 1)


    # マテリアルを作成

    material = bpy.data.materials.new(name="Material_" + name)

    plane.data.materials.append(material)


    # マテリアルの設定

    material.use_nodes = False

    material.diffuse_color = (0.0, 1.0, 0.0, 1.0)  # 緑色 (R:0.0, G:1.0, B:0.0, A:1.0)


    # オブジェクトの名前を設定

    plane.name = name


# 平面を作成(座標(-1, 0, 0)、幅0.6、高さ0.6)

create_plane_at_position((-1, 0, 0), 0.3, 0.3, "cheer1")


# 平面を作成(座標(1, 0, 0)、幅0.6、高さ0.6)

create_plane_at_position((1, 0, 0), 0.3, 0.3, "cheer2")




このスクリプトを実行すると、座標(-1, 0, 0)と(1, 0, 0)に幅と高さが0.3の緑色の平面が作成されます。幅と高さを調整することで、平面の大きさを変更できます。



 

基本系 配布 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