2023年8月6日日曜日

20230807 円周に 正方形 8枚 貼る















 

 

 

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

 

import bpy

 

# List of collection names

collection_names = [ 

"8つの正面",

 "円板",

"abcdefg",

"abcdefg",

"abcdefg",

"abcdefg"

 

]

 

# 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


半径1の円を作る
中心 000
xy平面に 存在する


正方形 辺長さ 2を
8個 作る

正方形の中心位置は
半径1の円周に 等間隔
この正方形は xy平面に平行ではなく
xy平面に 直角 で存在する


BlenderのPythonを使用して、半径1の円を中心(0, 0, 0)に作成し、その円周上に等間隔でXY平面に直角に存在する辺長さ2の正方形を8つ作成する方法を示します


import bpy import math # 半径1の円を作成 radius = 1.0 bpy.ops.mesh.primitive_circle_add(vertices=32, radius=radius, location=(0, 0, 0)) circle = bpy.context.active_object # 8つの正方形を作成 num_squares = 8 angle_step = 360.0 / num_squares for i in range(num_squares): angle_rad = math.radians(i * angle_step) x = math.cos(angle_rad) y = math.sin(angle_rad) # 正方形の中心位置を計算 center = (x * radius, y * radius, 0) # 正方形の辺長さ edge_length = 2.0 # 正方形を作成 bpy.ops.mesh.primitive_plane_add(size=edge_length, location=center) square = bpy.context.active_object # 正方形をXY平面に直角に回転 square.rotation_euler[0] = math.radians(90) # X軸周りの回転 square.rotation_euler[2] = angle_rad # Z軸周りの回転 # 円オブジェクトを選択解除 circle.select_set(False)










20230806 1辺 4の正方形に写真を貼る

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













https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/image.html






blender python



正方形を作る 

1辺 4長さ

zx平面に作る

正方形 中心000


import bpy


# 正方形の1辺の長さ

side_length = 4.0


# 正方形の中心座標

center_x = 0.0

center_z = 0.0


# 頂点座標を計算

half_side = side_length / 2

vertices = [

    (center_x - half_side, 0, center_z - half_side),

    (center_x - half_side, 0, center_z + half_side),

    (center_x + half_side, 0, center_z + half_side),

    (center_x + half_side, 0, center_z - half_side)

]


# メッシュを作成

mesh = bpy.data.meshes.new(name="SquareMesh")

mesh.from_pydata(vertices, [], [(0, 1, 2, 3)])

mesh.update()


# オブジェクトを作成してシーンに追加

obj = bpy.data.objects.new("SquareObject", mesh)

bpy.context.collection.objects.link(obj)


# 表示更新

bpy.context.view_layer.update()





選択した正方形オブジェクトをZ軸周りに90度回転させる手順を以下に示します。

Blender内で正方形オブジェクトを手動で選択した状態で、

Pythonスクリプトを使用して回転させることができます。










 

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





test

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



import bpy
import math


# オブジェクトを作成
bpy.ops.mesh.primitive_torus_add(
    align='WORLD',
    location=(0, 0, 0),
    rotation=(0, 0, 0),
    major_radius=1,
    minor_radius=0.06,
    major_segments=48,
    minor_segments=12
)

# オブジェクトを選択
obj = bpy.context.active_object

# オブジェクト名を変更
obj.name = "MyTorus"





import bpy

import math


def create_sphere_at_position(position, color, name):

    # 半径を設定

    radius = 0.15


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

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

    sphere = bpy.context.active_object


    # マテリアルを作成

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

    sphere.data.materials.append(material)


    # マテリアルの設定

    material.use_nodes = False

    material.diffuse_color = color


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

    sphere.name = name


# 球体の作成する線分の両端の位置を指定

start_position = (-1, 0, -1)

end_position = (0, 0, 0)

num_spheres = 5


# 球体を等間隔で作成

for i in range(num_spheres):

    t = i / (num_spheres - 1)  # 0から1の範囲で等間隔になるように計算

    x_position = start_position[0] + t * (end_position[0] - start_position[0])

    y_position = start_position[1] + t * (end_position[1] - start_position[1])

    z_position = start_position[2] + t * (end_position[2] - start_position[2])

    color = (1.0, 0, 1.0, 1.0)  # ピンクの色 (R:1.0, G:0, B:1.0, A:1.0)

    name = f"point({x_position:.2f}, {y_position:.2f}, {z_position:.2f})"

    create_sphere_at_position((x_position, y_position, z_position), color, name)

















import bpy
import math

def create_sphere_at_position(position, color, name):
    # 半径を設定
    radius = 0.1

    # 球を作成(指定した座標に)
    bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, location=position)
    sphere = bpy.context.active_object

    # マテリアルを作成
    material = bpy.data.materials.new(name="Material_" + name)
    sphere.data.materials.append(material)

    # マテリアルの設定
    material.use_nodes = False
    material.diffuse_color = color

    # オブジェクトの名前を設定
    sphere.name = name

# (0.5, 0, 1) の位置に球体を作成
create_sphere_at_position((0.5, 0, 1), (1.0, 0, 1.0, 1.0), "point(0.50, 0, 1)")

# (1, 0, 1) の位置に球体を作成
create_sphere_at_position((1, 0, 1), (1.0, 0, 1.0, 1.0), "point(1.00, 0, 1)")


///


参考に


球体半径 0.15で

 (-1, 0, -1) から

(0,0,0)

に 等間隔で 5個の球体を作成 






 

基本系 配布 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年8月4日金曜日

20230805a 円周 植栽

円周 植栽


テクスチャー作成では、配布サイト

https://vook.vc/n/5755


https://styly.cc/ja/tips/blender-modeling-start4/#


Blender2.9 平面オブジェクトに画像テクスチャを貼り付ける方法






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

import bpy


# List of collection names

collection_names = [

    "土台",


   "単位円 torus",

   "単位円 torus",

   "単位円 torus",

   "単位円 torus",

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









blender python

xy平面に 半径1、半径2の円を作る

名前 "円板 dodai”

円中心 000


xy平面に 1辺2、1辺4の正方形を作る

名前 "正方形 dodai”

円中心 000


写真を貼れるように

メッシュと マテリアル設定して







import bpy

import math


# Function to create a circle

def create_circle(name, radius, center):

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

    obj = bpy.context.active_object

    obj.name = name

    return obj


# Function to create a square

def create_square(name, side_length, center):

    vertices = [(-side_length/2, -side_length/2, 0),

                (side_length/2, -side_length/2, 0),

                (side_length/2, side_length/2, 0),

                (-side_length/2, side_length/2, 0)]


    edges = [(0, 1), (1, 2), (2, 3), (3, 0)]


    faces = [(0, 1, 2, 3)]


    mesh = bpy.data.meshes.new(name)

    obj = bpy.data.objects.new(name, mesh)


    bpy.context.collection.objects.link(obj)


    mesh.from_pydata(vertices, edges, faces)

    mesh.update()


    obj.location = center

    return obj


# Clear existing objects (optional)

bpy.ops.object.select_all(action='SELECT')

bpy.ops.object.delete()


# Create circles

radius1 = 1

radius2 = 2

center = (0, 0, 0)


circle1 = create_circle("円板 dodai 1", radius1, center)

circle2 = create_circle("円板 dodai 2", radius2, center)


# Create squares

side_length1 = 2

side_length2 = 4


square1 = create_square("正方形 dodai 1", side_length1, center)

square2 = create_square("正方形 dodai 2", side_length2, center)


# Add material with image texture to the objects

def add_image_texture(obj, image_path):

    mat = bpy.data.materials.new(name="Image Material")

    obj.data.materials.append(mat)

    mat.use_nodes = True


    nodes = mat.node_tree.nodes

    principled_bsdf = nodes.get("Principled BSDF")


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

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

    texture_node.image = texture


    mat.node_tree.links.new(texture_node.outputs["Color"], principled_bsdf.inputs["Base Color"])


# Replace "image_path" with the actual path to your image file.

image_path = "path/to/your/image.png"


add_image_texture(circle1, image_path)

add_image_texture(circle2, image_path)

add_image_texture(square1, image_path)

add_image_texture(square2, "C:\\aaa 2023 dondon\\aaa2023いつもの\\blende_gazou\\test 貼り付け 2023\\20230801 渋谷_HIT_Lemon 2.png")





























 

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

# 円周の中心座標
center_x = 0
center_y = 0
center_z = 0

# 円周の半径
radius = 3

# 円周に配置する円錐の数
num_cones = 12

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

# 円周上の点を計算する
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=3, location=position)
    cone = bpy.context.active_object
    bpy.context.view_layer.objects.active = cone

    # 向きを設定
    cone.rotation_euler = direction

# トーラスを描く関数
def draw_torus():
    bpy.ops.mesh.primitive_torus_add(location=(center_x, center_y, center_z), align='WORLD', major_radius=radius+0.0, minor_radius=0.1)

# 円錐を配置
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()

    # 円錐の配置
    place_cone(point, direction_rotation)

# トーラスの描画
draw_torus()








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





 

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

import math


# 円周の中心座標

center_x = 0

center_y = 0

center_z = 0


# 円周の半径

radius = 3


# 円錐の高さ

cone_height = 3


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

num_cones = 12


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

target_x = 2

target_y = 2

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


# トーラスを描く関数

def draw_torus(position):

    bpy.ops.mesh.primitive_torus_add(location=position, align='WORLD', major_radius=radius, minor_radius=0.2)


# 円錐を配置とトーラスの描画

for point in circle_points:

    # トーラスの描画

    draw_torus(point)


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


    # 円錐の配置

    place_cone(point, 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 





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