2023年8月4日金曜日

20230804 長い円錐で 向き指定









import bpy

import mathutils

import math


# 円周の中心座標

center_x = 0

center_y = 0

center_z = 0


# 円周の半径

radius = 3


# 円錐の高さ

cone_height = 3


# 円周に配置する円錐の数

num_cones = 12


# 円周上の点を計算する

theta_values = [2 * math.pi * i / num_cones for i in range(num_cones)]

circle_points = [(center_x + radius * math.cos(theta), center_y + radius * math.sin(theta), center_z) for theta in theta_values]


# 円錐を配置する関数

def place_cone(position, direction):

    bpy.ops.mesh.primitive_cone_add(vertices=32, radius1=0.2, depth=cone_height, location=position)

    cone = bpy.context.active_object

    bpy.context.view_layer.objects.active = cone


    # 向きを設定

    cone.rotation_euler = direction


# 円錐を配置

for point in circle_points:

    # 円周上の点から(0, 0, 3)への方向を計算

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

    target_vector = mathutils.Vector((point[0] - center_x, point[1] - center_y, center_z + cone_height))

    direction_rotation = target_vector.to_track_quat('Z', 'Y').to_euler()

    

    # 180度回転させる

    direction_rotation[2] += math.radians(180)

    

    place_cone(point, direction_rotation)







import bpy

import mathutils

import math


# 円周の中心座標

center_x = 0

center_y = 0

center_z = 0


# 円周の半径

radius = 3


# 円錐の高さ

cone_height = 0.6


# 円周に配置する円錐の数

num_cones = 12


# 円錐の底面が遠くなる位置を定義(例えば、X=2, Y=2, Z=2の場合)

target_x = 0

target_y = 0

target_z = 2


# 円周上の点を計算する

theta_values = [2 * math.pi * i / num_cones for i in range(num_cones)]

circle_points = [(center_x + radius * math.cos(theta), center_y + radius * math.sin(theta), center_z) for theta in theta_values]


# 円錐を配置する関数

def place_cone(position, direction):

    bpy.ops.mesh.primitive_cone_add(vertices=32, radius1=0.2, depth=cone_height, location=position)

    cone = bpy.context.active_object

    bpy.context.view_layer.objects.active = cone


    # 向きを設定

    cone.rotation_euler = direction


# 円錐を配置

for point in circle_points:

    # (0, 0, 0)への方向を計算

    target_vector = mathutils.Vector((target_x - point[0], target_y - point[1], target_z - point[2]))

    direction_rotation = target_vector.to_track_quat('Z', 'Y').to_euler()


    # 位置を調整して円錐の底面が指定した位置に配置されるようにする

    position = mathutils.Vector((point[0] + target_vector.x, point[1] + target_vector.y, point[2] + target_vector.z))


    place_cone(position, direction_rotation)
















 

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





テスト



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