2023年8月12日土曜日

20230813 トーラス円周 細いの 名前付き 小数点 2桁









import bpy

import math


# zion_radius の値

#zion_radius = (3**(0.5))/2

zion_radius = (2**(0.5))/2



# 初期設定

torus_major_radius = zion_radius  # トーラスのメジャー半径

torus_minor_radius = 0.01  # トーラスのマイナー半径

sphere_radius = 0.07  # 球体の半径

animation_duration = 20  # アニメーションの時間(秒)

frame_rate = bpy.context.scene.render.fps

clockwise = True  # 時計回り: False, 反時計回り: True


# トーラスを作成

bpy.ops.mesh.primitive_torus_add(align='WORLD', major_radius=torus_major_radius, minor_radius=torus_minor_radius, location=(0, 0, 0))  # 描画開始位置

torus = bpy.context.active_object


# 球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, location=(0, zion_radius, 0))  # 描画開始位置

sphere = bpy.context.active_object


# 球体をトーラスにリンク設定

sphere.parent = torus


# トーラスの名前を設定

torus_name = f"Torus_{zion_radius:.2f}_radius"

torus.name = torus_name


# ゴール時間を設定

goal_frame = animation_duration * frame_rate


# アニメーションを設定

for frame in range(1, goal_frame + 1):

    bpy.context.scene.frame_set(frame)

    

    # トーラスを回転させる

    angle = 2 * math.pi * (frame / (animation_duration * frame_rate))

    if clockwise:

        angle = -angle

    torus.rotation_euler.z = angle

    torus.keyframe_insert(data_path="rotation_euler", frame=frame)


# アウトライナで全てのオブジェクトを選択解除

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


# endを530フレームに設定

bpy.context.scene.frame_end = 530






 

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





20230813 正方形




import bpy


# 正方形の1辺の長さ

side_length = 2.0


# 正方形の中心座標

center = (0, 0, 0)


# 正方形を作成

bpy.ops.mesh.primitive_plane_add(

    size=side_length,

    enter_editmode=False,

    align='WORLD',

    location=center,

    scale=(1, 1, 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 





20230813 トーラス円周



blender python


トーラスを作る

中心 000

torus_major_radius = 1.0

torus_minor_radius = 0.01


半径 1と

半径 √3/2




import bpy

import math


zion_radius = (3**(0.5))/2


# 初期設定

torus_major_radius = zion_radius  # トーラスのメジャー半径

torus_minor_radius = 0.01  # トーラスのマイナー半径

sphere_radius = 0.07  # 球体の半径

animation_duration = 20  # アニメーションの時間(秒)

frame_rate = bpy.context.scene.render.fps

clockwise = True  # 時計回り: False, 反時計回り: True


# トーラスを作成

bpy.ops.mesh.primitive_torus_add(align='WORLD', major_radius=torus_major_radius, minor_radius=torus_minor_radius, location=(0, 0, 0))  # 描画開始位置

torus = bpy.context.active_object


# 球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, location=(0,zion_radius,0))  # 描画開始位置

sphere = bpy.context.active_object


# 球体をトーラスにリンク設定

sphere.parent = torus


# ゴール時間を設定

goal_frame = animation_duration * frame_rate


# アニメーションを設定

for frame in range(1, goal_frame + 1):

    bpy.context.scene.frame_set(frame)

    

    # トーラスを回転させる

    angle = 2 * math.pi * (frame / (animation_duration * frame_rate))

    if clockwise:

        angle = -angle

    torus.rotation_euler.z = angle

    torus.keyframe_insert(data_path="rotation_euler", frame=frame)


# アウトライナで全てのオブジェクトを選択解除

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


# endを530フレームに設定

bpy.context.scene.frame_end = 530





import bpy

import math


zion_radius = 1


# 初期設定

torus_major_radius = zion_radius  # トーラスのメジャー半径

torus_minor_radius = 0.01  # トーラスのマイナー半径

sphere_radius = 0.07  # 球体の半径

animation_duration = 20  # アニメーションの時間(秒)

frame_rate = bpy.context.scene.render.fps

clockwise = True  # 時計回り: False, 反時計回り: True


# トーラスを作成

bpy.ops.mesh.primitive_torus_add(align='WORLD', major_radius=torus_major_radius, minor_radius=torus_minor_radius, location=(0, 0, 0))  # 描画開始位置

torus = bpy.context.active_object


# 球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, location=(0,zion_radius,0))  # 描画開始位置

sphere = bpy.context.active_object


# 球体をトーラスにリンク設定

sphere.parent = torus


# ゴール時間を設定

goal_frame = animation_duration * frame_rate


# アニメーションを設定

for frame in range(1, goal_frame + 1):

    bpy.context.scene.frame_set(frame)

    

    # トーラスを回転させる

    angle = 2 * math.pi * (frame / (animation_duration * frame_rate))

    if clockwise:

        angle = -angle

    torus.rotation_euler.z = angle

    torus.keyframe_insert(data_path="rotation_euler", frame=frame)


# アウトライナで全てのオブジェクトを選択解除

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


# endを530フレームに設定

bpy.context.scene.frame_end = 530



 

 

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

 

import bpy

 

# List of collection names

collection_names = [ 

"(√3)/2 rail",

 "(√2)/2 rail",

"(1)rail",

"(0)rail",

"細い Torus 円周",

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

 

 

 


















 







 

 




 

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





20230812   立方体 11個を作る rail 用






blender python 



立方体 11個を 作る

立方体 大きさ 1辺 0.04



立方体 中心を

(-1,1,0)から

(1,1,0)に 等間隔に配置



import bpy

import math


# 立方体の数と大きさ

cube_count = 11

cube_size = 0.04


# 立方体の中心の配置範囲

start_x, start_y, start_z = -1, 1, 0

end_x, end_y, end_z = 1, 1, 0


# 間隔の計算

spacing = (end_x - start_x) / (cube_count - 1)


# 立方体を作成する関数

def create_cube_at_position(position):

    bpy.ops.mesh.primitive_cube_add(size=cube_size, location=position)

    cube = bpy.context.active_object

    return cube


# 立方体を等間隔に配置

for i in range(cube_count):

    x = start_x + i * spacing

    y = start_y

    z = start_z

    

    position = (x, y, z)

    create_cube_at_position(position)







import bpy

import math


# 立方体の数と大きさ

cube_count = 11

cube_size = 0.04


# 立方体の中心の配置範囲

start_x, start_z = -1, 0

end_x, end_z = 1, 0


# y成分を固定

y = math.sqrt(2) / 2


# 間隔の計算

spacing = (end_x - start_x) / (cube_count - 1)


# 立方体を作成する関数

def create_cube_at_position(position):

    bpy.ops.mesh.primitive_cube_add(size=cube_size, location=position)

    cube = bpy.context.active_object

    return cube


# 立方体を等間隔に配置

for i in range(cube_count):

    x = start_x + i * spacing

    z = start_z

    

    position = (x, y, z)

    create_cube_at_position(position)




import bpy

import math


# 立方体の数と大きさ

cube_count = 11

cube_size = 0.04


# 立方体の中心の配置範囲

start_x, start_z = -1, 0

end_x, end_z = 1, 0


# y成分を固定

y = math.sqrt(3) / 2


# 間隔の計算

spacing = (end_x - start_x) / (cube_count - 1)


# 立方体を作成する関数

def create_cube_at_position(position):

    bpy.ops.mesh.primitive_cube_add(size=cube_size, location=position)

    cube = bpy.context.active_object

    return cube


# 立方体を等間隔に配置

for i in range(cube_count):

    x = start_x + i * spacing

    z = start_z

    

    position = (x, y, z)

    create_cube_at_position(position)







import bpy

import math


# 立方体の数と大きさ

cube_count = 11

cube_size = 0.04


# 立方体の中心の配置範囲

start_x, start_z = -1, 0

end_x, end_z = 1, 0


# y成分を固定

y = 0


# 間隔の計算

spacing = (end_x - start_x) / (cube_count - 1)


# 立方体を作成する関数

def create_cube_at_position(position):

    bpy.ops.mesh.primitive_cube_add(size=cube_size, location=position)

    cube = bpy.context.active_object

    return cube


# 立方体を等間隔に配置

for i in range(cube_count):

    x = start_x + i * spacing

    z = start_z

    

    position = (x, y, z)

    create_cube_at_position(position)











 

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

20230811 円周中心の球体







blender python


球体を作る

半径0.1

中心000


名前 球体(x,y,z)





bing


import bpy


# Set the radius and location of the sphere

radius = 0.1

location = (0, 0, 0)


# Create a new mesh with the given radius

mesh = bpy.data.meshes.new("Sphere")

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

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


# Set the name of the sphere object

sphere = bpy.context.active_object

sphere.name = "Sphere({},{},{})".format(*location)




import bpy


# 球体の半径と中心座標を設定

radius = 0.1

center = (0, 0, 0)


# 球体を作成

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


# 球体のオブジェクトを取得

sphere = bpy.context.active_object


# 名前を設定

sphere.name = "球体({}, {}, {})".format(center[0], center[1], center[2])






 

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





20230810 再編集 球体1つを動かす





「単品配布 20230810 基本系 単位円 円周と直径を動く 4つの球体.blend」を共有

https://drive.google.com/file/d/1plIzByxW5Fd7unj8oWjuW4j-7eFsWqbT/view?usp=sharing




import bpy


# 初期設定

radius = 0.07

start_position = (-1, 0, 0)

end_position = (1, 0, 0)

animation_duration = 10  # 移動アニメーションの時間(秒)

stop_duration = 0  # 停止アニメーションの時間(秒)

repeat_count = 5  # アニメーションの繰り返し回数


# フレーム数を設定

bpy.context.scene.frame_end = (animation_duration + stop_duration) * repeat_count * bpy.context.scene.render.fps


# 球体を作成

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

sphere = bpy.context.active_object


# アニメーションを設定

for repeat in range(repeat_count):

    for frame in range(int((repeat * (animation_duration + stop_duration) * bpy.context.scene.render.fps)) + 1,

                       int(((repeat + 1) * (animation_duration + stop_duration) * bpy.context.scene.render.fps)) + 1):

        bpy.context.scene.frame_set(frame)

        x_offset = (frame - repeat * (animation_duration + stop_duration) * bpy.context.scene.render.fps) * (

                    2.0 / (animation_duration * bpy.context.scene.render.fps))

        sphere.location.x = start_position[0] + x_offset

        sphere.keyframe_insert(data_path="location", frame=frame)


# アウトライナで全てのオブジェクトを選択解除

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





import bpy


# 初期設定

radius = 0.07

start_position = (1, 0, 0)

end_position = (-1, 0, 0)

animation_duration = 10  # 移動アニメーションの時間(秒)

stop_duration = 0  # 停止アニメーションの時間(秒)

repeat_count = 5  # アニメーションの繰り返し回数


# フレーム数を設定

bpy.context.scene.frame_end = (animation_duration + stop_duration) * repeat_count * bpy.context.scene.render.fps


# 球体を作成

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

sphere = bpy.context.active_object


# アニメーションを設定

for repeat in range(repeat_count):

    for frame in range(int((repeat * (animation_duration + stop_duration) * bpy.context.scene.render.fps)) + 1,

                       int(((repeat + 1) * (animation_duration + stop_duration) * bpy.context.scene.render.fps)) + 1):

        bpy.context.scene.frame_set(frame)

        x_offset = (frame - repeat * (animation_duration + stop_duration) * bpy.context.scene.render.fps) * (

                    2.0 / (animation_duration * bpy.context.scene.render.fps))

        sphere.location.x = start_position[0] + x_offset

        sphere.keyframe_insert(data_path="location", frame=frame)


# アウトライナで全てのオブジェクトを選択解除

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








2023年8月9日水曜日

20230810  2x2正方形で 電車が 進行方向に進む 3枚画像

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






















import bpy


# 画像のパス

image_path = "C:\\atest\\atest_20161230_train_matsuyama.jpg"


# 3つの正方形の平面を作成

for i in range(3):

    bpy.ops.mesh.primitive_plane_add(size=1, enter_editmode=False, align='WORLD', location=(i * 2, 0, 0))

    plane = bpy.context.object


    # マテリアルを作成

    material = bpy.data.materials.new(name=f"Image Material {i}")

    plane.data.materials.append(material)


    # マテリアルに画像を追加

    if material.node_tree is None:

        material.use_nodes = True


    nodes = material.node_tree.nodes

    node_tree = material.node_tree


    # プリンシプル BSDF ノードを取得

    bsdf_node = nodes.get("Principled BSDF")


    # 画像テクスチャノードを作成

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

    texture_node.location = (-300, 0)

    texture_node.image = bpy.data.images.load(image_path)


    # 出力ノードを取得

    output_node = nodes.get("Material Output")


    # ノードを接続

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

    node_tree.links.new(output_node.inputs["Surface"], bsdf_node.outputs["BSDF"])


# レンダリングのための設定

render = bpy.context.scene.render

render.engine = 'CYCLES'  # Cycles レンダーエンジンを使用

render.image_settings.file_format = 'PNG'  # 出力フォーマットをPNGに設定


# レンダリング実行

bpy.ops.render.render(write_still=True)














 

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