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










2023年10月3日火曜日

20231004 選択したオブジェクトを回転させる













blender python
 選択したオブジェクトを回転させる








このスクリプトでは、rotation_timeを10秒に設定しています。これにより、1回転するのに10秒かかり、30秒のアニメーション内で3回転します。適宜この値を変更して、希望するアニメーション速度に調整してください。


import bpy
import math

# ユーザーが選択したオブジェクトを取得
selected_objects = bpy.context.selected_objects

# アニメーションの長さ(秒)
animation_length = 30

# 1回転するのにかかる時間(秒)
rotation_time = 10

# 1秒あたりの回転角度を計算
rotation_angle_per_sec = 360 / rotation_time

# アニメーションを設定
for obj in selected_objects:
    # アクティブなオブジェクトに設定
    bpy.context.view_layer.objects.active = obj
    
    # 初期フレームを設定
    bpy.context.scene.frame_start = 1
    
    # アニメーションの最終フレームを設定
    bpy.context.scene.frame_end = int(animation_length * bpy.context.scene.render.fps)
    
    # 回転のキーフレームを設定
    obj.rotation_euler = (0, math.radians(0), 0)
    obj.keyframe_insert(data_path="rotation_euler", frame=1)
    obj.rotation_euler = (0, math.radians(rotation_angle_per_sec * animation_length), 0)
    obj.keyframe_insert(data_path="rotation_euler", frame=bpy.context.scene.frame_end)







2023年9月28日木曜日

20230929 観測と観察の 正面 視線距離



blender python 


トーラスを作る

半径1 薄い青

マイナー半径 0.05

RGBA 4値で 色を付ける










import bpy


# トーラスを作成

bpy.ops.mesh.primitive_torus_add(

    align='WORLD',

    location=(0, 0, 0),    # トーラスの中心の座標

    rotation=(0, 0, 0),    # トーラスの回転

    major_radius=2,        # 半径

    minor_radius=0.03      # マイナー半径

)


# トーラスの名前を設定

torus_object = bpy.context.active_object

torus_object.name = "Torus_radius=2"  # 名前を設定


# トーラスのマテリアルを作成

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

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


# 色を指定(RGBA) - もう少し濃い水色

material.diffuse_color = (0.2, 0.4, 1, 1)


# トーラスにマテリアルを割り当て

torus_object.data.materials.append(material)






import bpy

import math


# 半径

radius = 2


# 正六角形の頂点座標を計算

vertices = []

for i in range(6):

    angle = i * math.pi / 3  # 60度ごとに頂点を配置

    x = radius * math.cos(angle)

    y = radius * math.sin(angle)

    z = 0

    vertices.append((x, y, z))


# 新しいメッシュを作成

mesh = bpy.data.meshes.new(name="正六角形_r=2_mesh")

obj = bpy.data.objects.new("正六角形_r=2", mesh)


# メッシュデータに頂点座標を設定

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


# シーンに追加

scene = bpy.context.scene

scene.collection.objects.link(obj)


# オブジェクトをアクティブに設定

bpy.context.view_layer.objects.active = obj

obj.select_set(True)


# マテリアルを作成

material = bpy.data.materials.new(name="水色Material")

material.use_nodes = False

material.diffuse_color = (0.5, 0.8, 1.0, 1.0)  # RGBA


# オブジェクトにマテリアルを割り当て

obj.data.materials.append(material)





2023年8月28日月曜日

20230828 光時計 追加 minus側







 

 

 

 

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

 

import bpy

 

# List of collection names

collection_names = [ 

"光時計 +y",

 "光時計 -y",

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

 

 

 

 

 

 


2023年8月26日土曜日

20230827 カメラ動かし練習

20230827 カメラ動かし練習



blender python 


カメラを作る


curve で 円を作る 半径3

カメラを object contraint で

curve円周上を動かす アニメ


位置 000に track to する

カメラ位置を follow path で 円周にする










 

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