2023年10月9日月曜日

20231010b 地球自転の 東京 京都 博多




blender python
コレクションだけを作る

Torus radius 1.0
Torus radius 2.0
Ball radius 0.07
Ball radius 0.03
Ball long radius 0.05



import bpy

# コレクション名のリスト
collection_names = ["Torus radius 1.0", "Torus radius 2.0", "Ball radius 0.07", "Ball radius 0.03"]

# コレクションを作成
for name in collection_names:
    new_collection = bpy.data.collections.new(name)
    bpy.context.scene.collection.children.link(new_collection)








半径0.3の球体
中心 10,0,0
中心 10,10,0

名前は t=0太陽 t=1太陽 

透明度 20%
alpha blend


import bpy

# 球体1の中心座標
center1 = (10, 0, 0)

# 球体2の中心座標
center2 = (10, 10, 0)

# 球体の半径
radius = 0.3

# 透明度
alpha = 0.2

# 球体1を作成
bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, location=center1)

# 作成した球体1のオブジェクトを取得
sphere1 = bpy.context.active_object

# オブジェクトの名前を設定
sphere1.name = "t=0太陽"

# マテリアルを作成または取得
if sphere1.data.materials:
    material1 = sphere1.data.materials[0]
else:
    material1 = bpy.data.materials.new(name="太陽マテリアル1")
    sphere1.data.materials.append(material1)

# 透明度を設定
material1.use_nodes = True
nodes1 = material1.node_tree.nodes
shader1 = nodes1.get("Principled BSDF")
shader1.inputs["Alpha"].default_value = alpha  # 透明度を設定
material1.blend_method = 'BLEND'  # Alpha Blendモードに設定

# 球体2を作成
bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, location=center2)

# 作成した球体2のオブジェクトを取得
sphere2 = bpy.context.active_object

# オブジェクトの名前を設定
sphere2.name = "t=1太陽"

# マテリアルを作成または取得
if sphere2.data.materials:
    material2 = sphere2.data.materials[0]
else:
    material2 = bpy.data.materials.new(name="太陽マテリアル2")
    sphere2.data.materials.append(material2)

# 透明度を設定
material2.use_nodes = True
nodes2 = material2.node_tree.nodes
shader2 = nodes2.get("Principled BSDF")
shader2.inputs["Alpha"].default_value = alpha  # 透明度を設定
material2.blend_method = 'BLEND'  # Alpha Blendモードに設定








light を sun で 
位置 10,0,0        光線の方向を 10,10,0 
位置 10,10,0      光線の方向を 10,10,0 


import bpy

# 太陽光源1を作成
bpy.ops.object.light_add(type='SUN', location=(10, 0, 0))

# 作成した太陽光源1のオブジェクトを取得
sun_light1 = bpy.context.active_object

# 太陽光源1の名前を設定
sun_light1.name = "太陽光源1"

# 光線の方向を設定
sun_light1.rotation_euler = (0, 0, 0)  # 光線の方向を(10, 10, 0)に向ける

# 太陽光源2を作成
bpy.ops.object.light_add(type='SUN', location=(10, 10, 0))

# 作成した太陽光源2のオブジェクトを取得
sun_light2 = bpy.context.active_object

# 太陽光源2の名前を設定
sun_light2.name = "太陽光源2"

# 光線の方向を設定
sun_light2.rotation_euler = (0, 0, 0)  # 光線の方向を(10, 10, 0)に向ける





2つ円柱を作る 半径0.1
000で 長さ2で作って x軸に 90度回転
移動させる 1,0,0 名前は t=0線路レール
移動させる 1,10,0 名前は t=1線路レール


import bpy

import math


# 円柱の半径

radius = 0.1


# 円柱の長さ

length = 2.0


# ステップ数(t=0とt=1)

steps = [(1, 0, 0, "t=0線路レール"), (1, 10, 0, "t=1線路レール")]


for step in steps:

    # 円柱を作成

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


    # 作成した円柱のオブジェクトを取得

    cylinder = bpy.context.active_object


    # X軸に90度回転

    cylinder.rotation_euler.x += math.radians(90)


    # 移動させる

    cylinder.location = (step[0], step[1], step[2])


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

    cylinder.name = step[3]





半径1の球体
中心000
中心0,10,0
名前は t=0地球   t=1 地球





 

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





20231010a 光行差の望遠鏡







コレクションだけを作る

Torus radius 1.0
Torus radius 2.0
Ball radius 0.07
Ball radius 0.03
Ball long radius 0.05

import bpy

# コレクション名のリスト
collection_names = ["Torus radius 1.0", "Torus radius 2.0", "Ball radius 0.07", "Ball radius 0.03"]

# コレクションを作成
for name in collection_names:
    new_collection = bpy.data.collections.new(name)
    bpy.context.scene.collection.children.link(new_collection)










blender pyhton


21個の球体を 等間隔に作る
球体半径 0.01
(-1,-2,0)から (1,2,0)


import bpy
import math


# 球体の数と半径を指定
num_spheres = 21
radius = 0.07

# 球体を作成する位置の範囲を指定
start_point = (-1, -2, 0)
end_point = (1, 2, 0)

# 21個の球体を作成
for i in range(num_spheres):
    # 位置を計算
    t = i / (num_spheres - 1)  # 0から1までの範囲で分割
    x = start_point[0] + t * (end_point[0] - start_point[0])
    y = start_point[1] + t * (end_point[1] - start_point[1])
    z = start_point[2] + t * (end_point[2] - start_point[2])

    # 球体を作成
    bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, location=(x, y, z))
    sphere = bpy.context.object

    # オブジェクト名に連番とXYZの位置情報を組み合わせて設定
    sphere.name = f"球体{i+1}_X{x:.2f}_Y{y:.2f}_Z{z:.2f}"






トーラスを21個作る

メジャー半径 1.0
マイナー半径 0.05


原点000で トーラスを作る
x軸で90度回転

トーラス中心を等間隔で
(-1,-2,0)から (1,2,0)

オブジェクト名に トーラスのメジャー半径を加える


import bpy
import math

# トーラスのパラメータ
major_radius = 2.0
minor_radius = 0.05
num_toruses = 21

# トーラスの中心を配置する範囲
start_position = (-1, -2, 0)
end_position = (1, 2, 0)

# トーラスの間隔を計算
spacing_x = (end_position[0] - start_position[0]) / (num_toruses - 1)
spacing_y = (end_position[1] - start_position[1]) / (num_toruses - 1)

# 21個のトーラスを作成して配置
for i in range(num_toruses):
    x_position = start_position[0] + i * spacing_x
    y_position = start_position[1] + i * spacing_y
    torus = bpy.ops.mesh.primitive_torus_add(
        align='WORLD',
        location=(x_position, y_position, start_position[2]),
        rotation=(math.radians(90), 0, 0),
        major_radius=major_radius,
        minor_radius=minor_radius,
        major_segments=48,
        minor_segments=12
    )
    
    # トーラスのオブジェクト名にメジャー半径を加える
    bpy.context.object.name = f"トーラス_{major_radius}"







blender pyhton


21個の球体を 等間隔に作る
球体半径 0.01
(-1,-2,0)から (1,2,0)


import bpy
import math


# 球体の数と半径を指定
num_spheres = 41
radius = 0.05

# 球体を作成する位置の範囲を指定
start_point = (-2, -4, 0)
end_point = (2, 4, 0)

# 41個の球体を作成
for i in range(num_spheres):
    # 位置を計算
    t = i / (num_spheres - 1)  # 0から1までの範囲で分割
    x = start_point[0] + t * (end_point[0] - start_point[0])
    y = start_point[1] + t * (end_point[1] - start_point[1])
    z = start_point[2] + t * (end_point[2] - start_point[2])

    # 球体を作成
    bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, location=(x, y, z))
    sphere = bpy.context.object

    # オブジェクト名に連番とXYZの位置情報を組み合わせて設定
    sphere.name = f"球体{i+1}_X{x:.2f}_Y{y:.2f}_Z{z:.2f}"










2023年10月8日日曜日

20231009 レイヤー トーラス 高さ違い





「配布 20231009b 集合 ベン図 002.blend」を共有






正三角形の中心を 000にして
3頂点の位置を 書き出して


the coordinates for a regular triangle with side length 2 and center at the origin:

  1. Vertex A: (1, 0)
  2. Vertex B: (-1, 0)
  3. Vertex C: (0, √3)

These coordinates represent the vertices of an equilateral triangle with side length 2, centered at the origin (0,








blender python で

3つの頂点を トーラスの中心にして
半径3で マイナー半径0.1 描いて


import bpy
import math

# 3つの頂点の座標を設定
vertices = [(1, 0, 0), (-1, 0, 0), (0, math.sqrt(3), 0)]

for vertex in vertices:
    # メッシュの作成
    mesh = bpy.data.meshes.new(name="CustomTorusMesh")
    obj = bpy.data.objects.new("CustomTorus", mesh)

    # シーンに追加
    bpy.context.scene.collection.objects.link(obj)

    # メッシュオブジェクトをアクティブに設定
    bpy.context.view_layer.objects.active = obj
    obj.select_set(True)

    # オブジェクトモードに切り替え
    bpy.ops.object.mode_set(mode='OBJECT')

    # トーラスの作成
    bpy.ops.mesh.primitive_torus_add(
        align='WORLD',
        location=vertex,  # トーラスの中心座標
        rotation=(0, 0, 0),
        major_radius=1,
        minor_radius=0.1,
        major_segments=48,
        minor_segments=12
    )










import bpy
import math

# 3つの頂点の座標を設定
vertices = [(1, 0, 0), (-1, 0, 0), (0, math.sqrt(3), 0)]

for vertex in vertices:
    # メッシュの作成
    mesh = bpy.data.meshes.new(name="CustomTorusMesh")
    obj = bpy.data.objects.new("CustomTorus", mesh)

    # シーンに追加
    bpy.context.scene.collection.objects.link(obj)

    # メッシュオブジェクトをアクティブに設定
    bpy.context.view_layer.objects.active = obj
    obj.select_set(True)

    # オブジェクトモードに切り替え
    bpy.ops.object.mode_set(mode='OBJECT')

    # トーラスの作成
    bpy.ops.mesh.primitive_torus_add(
        align='WORLD',
        location=vertex,  # トーラスの中心座標
        rotation=(0, 0, 0),
        major_radius=2,
        minor_radius=0.1,
        major_segments=48,
        minor_segments=12
    )




以上の トーラスを

z=1
Z=0
Z=-1に 作って





import bpy
import math

# 3つの頂点の座標を設定
vertices = [(1, 0, 1), (-1, 0, 0), (0, math.sqrt(3), -1)]

# 3つのトーラスを作成
for vertex in vertices:
    # メッシュの作成
    mesh = bpy.data.meshes.new(name="CustomTorusMesh")
    obj = bpy.data.objects.new("CustomTorus", mesh)

    # シーンに追加
    bpy.context.scene.collection.objects.link(obj)

    # メッシュオブジェクトをアクティブに設定
    bpy.context.view_layer.objects.active = obj
    obj.select_set(True)

    # オブジェクトモードに切り替え
    bpy.ops.object.mode_set(mode='OBJECT')

    # トーラスの作成
    bpy.ops.mesh.primitive_torus_add(
        align='WORLD',
        location=vertex,  # トーラスの中心座標
        rotation=(0, 0, 0),
        major_radius=2,
        minor_radius=0.1,
        major_segments=48,
        minor_segments=12
    )

# 3つのトーラスを z=1, z=0, z=-1 に配置
for i, obj in enumerate(bpy.data.objects['CustomTorus']):
    obj.location.z = i - 1










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





 

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





20231009 ボロメオの輪










「配布 20231011 ボロメオの輪 only 004.blend」を共有






正四面体 作成


blender python 

正四面体の中心が (0, 0, 0) にあり、かつ少なくとも一つの面が zx 平面に平行




import bpy
import math

# シーンのクリア
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_by_type(type='MESH')
bpy.ops.object.delete()



























z=0平面に描かれたトーラス、かつその中心が原点(0, 0, 0)にあるようなスクリプト



import bpy
import math

# シーンのクリア
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_by_type(type='MESH')
bpy.ops.object.delete()

# トーラスの作成(z=0平面に描く)
bpy.ops.mesh.primitive_torus_add(
    align='WORLD',
    location=(0, 0, 0.1),  # z=0.1に設定
    rotation=(0, 0, 0),
    major_radius=2,  # x軸方向に伸ばす
    minor_radius=0.1,  # マイナー半径を0.1に設定
    mode='MAJOR_MINOR',
    abso_major_rad=2,
    abso_minor_rad=0.1,
    major_segments=48,
    minor_segments=12
)

# トーラスを選択状態にする
torus = bpy.context.active_object
torus.select_set(True)
bpy.context.view_layer.objects.active = torus

# トーラスをy軸方向に2だけ伸ばす
bpy.ops.transform.resize(value=(1, 2, 1))


zy




import bpy
import math

# 選択されているオブジェクトを取得
selected_objects = bpy.context.selected_objects

# 選択されている各オブジェクトに対して y 軸周りに90度回転を適用
for obj in selected_objects:
    bpy.context.view_layer.objects.active = obj  # アクティブなオブジェクトに設定
    bpy.ops.transform.rotate(value=math.radians(90), orient_axis='Y')




import bpy
import math

# 選択されているオブジェクトを取得
selected_objects = bpy.context.selected_objects

# 選択されている各オブジェクトに対して z 軸周りに90度回転を適用
for obj in selected_objects:
    bpy.context.view_layer.objects.active = obj  # アクティブなオブジェクトに設定
    bpy.ops.transform.rotate(value=math.radians(90), orient_axis='Z')









import bpy
import math

# 選択されているオブジェクトを取得
selected_objects = bpy.context.selected_objects

# 選択されている各オブジェクトに対して y 軸周りに90度回転を適用
for obj in selected_objects:
    bpy.context.view_layer.objects.active = obj  # アクティブなオブジェクトに設定
    bpy.ops.transform.rotate(value=math.radians(90), orient_axis='Y')

# 選択されている各オブジェクトに対して z 軸周りに90度回転を適用
for obj in selected_objects:
    bpy.context.view_layer.objects.active = obj  # アクティブなオブジェクトに設定
    bpy.ops.transform.rotate(value=math.radians(90), orient_axis='Z')










import bpy
import math

# トーラスをy軸周りに90度回転
bpy.ops.transform.rotate(value=math.radians(90), orient_axis='y')


# トーラスをz軸周りに45度回転
bpy.ops.transform.rotate(value=math.radians(45), orient_axis='Z')


# トーラスを平行移動
bpy.ops.transform.translate(value=(1, 2, 0))
















Can You Make Borromean Rings In Real-Life? https://youtu.be/2CsJOswZvGc?si=0K2REgradiYpcliU



Borromean rings https://youtu.be/rM8teT4n6D8?si=NtZSFG6bY2cpem8P





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





 

基本系 配布 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年10月7日土曜日

20231008 十字の立方体











import bpy

# 十字の長さ
cross_length = 2

# 十字の幅
cross_width = 0.2

# 十字を描く関数
def draw_cross():
    # 十字の縦線を描く
    bpy.ops.mesh.primitive_cube_add(size=cross_length, location=(0, 0, 0))
    vertical_line = bpy.context.object
    vertical_line.scale[1] = cross_width
    vertical_line.name = "vertical_line"
    
    # 十字の横線を描く
    bpy.ops.mesh.primitive_cube_add(size=cross_length, location=(0, 0, 0))
    horizontal_line = bpy.context.object
    horizontal_line.scale[0] = cross_width
    horizontal_line.name = "horizontal_line"
    
    # 十字のもう1つの方向の線を描く
    bpy.ops.mesh.primitive_cube_add(size=cross_length, location=(0, 0, 0))
    depth_line = bpy.context.object
    depth_line.scale[2] = cross_width
    depth_line.name = "depth_line"
    
    # オレンジの色を設定
    orange_material = bpy.data.materials.new(name="オレンジ")
    orange_material.diffuse_color = (1, 0.5, 0, 1)  # RGB値でオレンジ色を設定
    vertical_line.data.materials.append(orange_material)
    horizontal_line.data.materials.append(orange_material)
    depth_line.data.materials.append(orange_material)

# 十字を描く
draw_cross()







十字の幅を0.04に設定し、現在の色の補色になるように調整



import bpy

# 十字の長さ
cross_length = 2

# 十字の幅
cross_width = 0.04

# 補色を計算する関数
def calculate_complementary_color(color):
    # 色の補色を計算
    complementary_color = (1.0 - color[0], 1.0 - color[1], 1.0 - color[2], 1.0)
    return complementary_color

# 十字を描く関数
def draw_cross():
    # 十字の縦線を描く
    bpy.ops.mesh.primitive_cube_add(size=cross_length, location=(0, 0, 0))
    vertical_line = bpy.context.object
    vertical_line.scale[1] = cross_width
    vertical_line.name = "vertical_line"
    
    # 十字の横線を描く
    bpy.ops.mesh.primitive_cube_add(size=cross_length, location=(0, 0, 0))
    horizontal_line = bpy.context.object
    horizontal_line.scale[0] = cross_width
    horizontal_line.name = "horizontal_line"
    
    # 十字のもう1つの方向の線を描く
    bpy.ops.mesh.primitive_cube_add(size=cross_length, location=(0, 0, 0))
    depth_line = bpy.context.object
    depth_line.scale[2] = cross_width
    depth_line.name = "depth_line"
    
    # 現在の色の補色を計算
    current_color = bpy.context.scene.world.node_tree.nodes['Background'].inputs['Color'].default_value
    complementary_color = calculate_complementary_color(current_color)
    
    # 補色を設定
    for obj in [vertical_line, horizontal_line, depth_line]:
        complementary_material = bpy.data.materials.new(name="補色")
        complementary_material.diffuse_color = complementary_color[:3]  # RGB値で補色を設定
        obj.data.materials.append(complementary_material)

# 十字を描く
draw_cross()






import bpy

# 立方体の辺の長さ
cube_size = 2

# 透明度が20%の水色で立方体を作成する関数
def create_cube():
    bpy.ops.mesh.primitive_cube_add(size=cube_size, location=(0, 0, 0))
    cube = bpy.context.object
    cube.name = "立方体"
    
    # 透明度が20%の水色のマテリアルを作成
    material = bpy.data.materials.new(name="水色透明")
    material.diffuse_color = (0, 0.5, 1, 0.2)  # RGBA値で水色と透明度を設定
    cube.data.materials.append(material)

# 立方体を作成
create_cube()








boolean






円柱 3つ



import bpy

# 円柱のパラメータ
cylinder_radius = 0.1  # 半径
cylinder_height = 2.0  # 高さ

# 円柱を作成する関数
def create_cylinder(rotation):
    bpy.ops.mesh.primitive_cylinder_add(radius=cylinder_radius, depth=cylinder_height, location=(0, 0, 0), rotation=rotation)
    cylinder = bpy.context.object
    cylinder.name = "円柱"
    return cylinder

# 姿勢を指定して円柱を作成
# x軸回転で作成
create_cylinder((1.5708, 0, 0))  # 1.5708 ラジアンは90度

# y軸回転で作成
create_cylinder((0, 1.5708, 0))  # 1.5708 ラジアンは90度

# z軸回転で作成
create_cylinder((0, 0, 1.5708))  # 1.5708 ラジアンは90度







import bpy

# 円柱のパラメータ
cylinder_radius = 0.1  # 半径
cylinder_height = 0.4  # 高さ

# 円柱を作成する関数
def create_cylinder(location, rotation):
    bpy.ops.mesh.primitive_cylinder_add(radius=cylinder_radius, depth=cylinder_height, location=location, rotation=rotation)
    cylinder = bpy.context.object
    cylinder.name = "円柱"
    return cylinder

# 姿勢を指定して円柱を作成
# x軸回転で作成
create_cylinder((0, 0, 0), (1.5708, 0, 0))  # 1.5708 ラジアンは90度

# y軸回転で作成
create_cylinder((0, 0, 0), (0, 1.5708, 0))  # 1.5708 ラジアンは90度

# z軸回転で作成
create_cylinder((0, 0, 0), (0, 0, 1.5708))  # 1.5708 ラジアンは90度





import bpy

# 円柱のパラメータ
cylinder_radius = 0.1  # 半径
cylinder_height = 0.4  # 高さ

# 円柱を作成する関数
def create_cylinder(location, rotation):
    bpy.ops.mesh.primitive_cylinder_add(radius=cylinder_radius, depth=cylinder_height, location=location, rotation=rotation)
    cylinder = bpy.context.object
    cylinder.name = "円柱"
    return cylinder

# 姿勢を指定して円柱を作成
# x軸回転で作成
create_cylinder((-1, 0, 0), (1.5708, 0, 0))  # 1.5708 ラジアンは90度

# y軸回転で作成
create_cylinder((-1, 0, 0), (0, 1.5708, 0))  # 1.5708 ラジアンは90度

# z軸回転で作成
create_cylinder((-1, 0, 0), (0, 0, 1.5708))  # 1.5708 ラジアンは90度



import bpy

# 円柱のパラメータ
cylinder_radius = 0.1  # 半径
cylinder_height = 0.4  # 高さ

# 円柱を作成する関数
def create_cylinder(location, rotation):
    bpy.ops.mesh.primitive_cylinder_add(radius=cylinder_radius, depth=cylinder_height, location=location, rotation=rotation)
    cylinder = bpy.context.object
    cylinder.name = "円柱"
    return cylinder

# 姿勢を指定して円柱を作成
# x軸回転で作成
create_cylinder((1, 0, 0), (1.5708, 0, 0))  # 1.5708 ラジアンは90度

# y軸回転で作成
create_cylinder((1, 0, 0), (0, 1.5708, 0))  # 1.5708 ラジアンは90度

# z軸回転で作成
create_cylinder((1, 0, 0), (0, 0, 1.5708))  # 1.5708 ラジアンは90度








@@@@@@@@@@@@@
捨て



blender python 


python blender  で 斜投影 の 見本を作って

Blenderを使用してPythonで斜投影の見本を作成するには、BlenderのPython APIを使用して3Dオブジェクトを作成し、適切な光源やカメラの設定を行います。以下は、簡単な例です。

まず、Blenderをスクリプトで制御できるようにするために、BlenderのPython APIをインポートします。そして、適切なカメラ、ライト、オブジェクトを作成し、斜投影を設定します。


import bpy
import math

# シーンのクリア
bpy.ops.wm.read_factory_settings(use_empty=True)

# メッシュの作成
bpy.ops.mesh.primitive_cube_add(size=2)

# カメラの作成
bpy.ops.object.camera_add(enter_editmode=False, align='VIEW', location=(0, -5, 3), rotation=(math.radians(60), 0, math.radians(45)))

# ライトの作成
bpy.ops.object.light_add(type='SUN', location=(2, -5, 5))
bpy.context.object.data.energy = 2.0

# 斜投影の設定
bpy.context.scene.camera.data.type = 'ORTHO'
bpy.context.scene.camera.data.ortho_scale = 3.0
bpy.context.scene.render.image_settings.file_format = 'PNG'
bpy.context.scene.render.filepath = "//output.png"

# レ



立方体の正方形の面に
幅 0.2 で 十字 cross を描いて




blender python

立方体 1辺2
中心 000

立方体を 厚さ 0 幅0.2のテープで
正方形 6面に
上下左右前後に貼る

正方形の中央に クロス croos になるように













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





 

基本系 配布 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年10月5日木曜日

20231006 立方体 頂点に 球体





blender python 


立方体を作る

辺長さ 2

000

透明なGreen



立方体8つの頂点を 球体の中心とする

球体を8つ作る 半径 0.05








import bpy


# シーンをクリア

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

bpy.ops.object.select_by_type(type='MESH')

bpy.ops.object.delete()


# 立方体を作成

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


# 立方体を薄いエメラルドグリーンにする

bpy.context.object.data.materials.append(bpy.data.materials.new(name="TranslucentEmerald"))

material = bpy.context.object.data.materials[-1]

material.use_nodes = True

material.node_tree.nodes["Principled BSDF"].inputs["Base Color"].default_value = (0.0, 1.0, 0.0, 0.2)  # Emerald Green with alpha = 0.2


# 球体を作成して頂点に配置

for vertex in bpy.context.object.data.vertices:

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=vertex.co)


# ス










20231006 




 

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

20231005 立方体と 光線

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



blender python


1x1x1の 立方体を作る

中心 000



import bpy


# 新しいメッシュオブジェクトを作成

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


# オブジェクトを選択状態にする

obj = bpy.context.active_object

bpy.context.view_layer.objects.active = obj

obj.select_set(True)









この立方体を通過する
長さ3の円柱 半径 0.03を

ランダムに 10本描く

import bpy

import random

from mathutils import Vector


# 選択されているオブジェクトをクリア

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

bpy.ops.object.select_by_type(type='MESH')

bpy.ops.object.delete()


# 立方体を作成

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

cube = bpy.context.active_object


# 円柱を10本ランダムに描く

for _ in range(10):

    # ランダムな位置を生成

    random_position = Vector((random.uniform(-0.5, 0.5), random.uniform(-0.5, 0.5), random.uniform(-0.5, 0.5)))


    # 円柱を作成

    bpy.ops.mesh.primitive_cylinder_add(radius=0.03, depth=3, location=random_position)


# 立方体を選択

cube.select_set(True)

bpy.context.view_layer.objects.active = cube






円柱をランダムに回転させ、方向を変える




import bpy

import random

from mathutils import Vector, Euler


# 選択されているオブジェクトをクリア

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

bpy.ops.object.select_by_type(type='MESH')

bpy.ops.object.delete()


# 立方体を作成

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

cube = bpy.context.active_object


# 円柱を10本ランダムに描く

for _ in range(10):

    # ランダムな位置を生成

    random_position = Vector((random.uniform(-0.5, 0.5), random.uniform(-0.5, 0.5), random.uniform(-0.5, 0.5)))


    # ランダムな回転を生成(オイラー角度)

    random_rotation = Euler((random.uniform(0, 2 * 3.1416), random.uniform(0, 2 * 3.1416), random.uniform(0, 2 * 3.1416)), 'XYZ')


    # 円柱を作成

    bpy.ops.mesh.primitive_cylinder_add(radius=0.03, depth=3, location=random_position, rotation=random_rotation)


# 立方体を選択

cube.select_set(True)

bpy.context.view_layer.objects.active = cube


 


立方体を 水色透明にして




import bpy



# 立方体を作成

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

cube = bpy.context.active_object


# 立方体のマテリアルを作成

mat = bpy.data.materials.new(name="TransparentBlue")

mat.use_nodes = False  # ノードを使用しない


# マテリアルの色を水色に設定

mat.diffuse_color = (0, 0.5, 1, 0.5)  # RGBAの色と透明度


# 立方体にマテリアルを割り当て

cube.data.materials.append(mat)


# 立方体を選択

cube.select_set(True)

bpy.context.view_layer.objects.active = cube