完成コード
https://chat.openai.com/share/eeb23cd3-0fc2-43f0-a018-e10c7e905579
正方形をZ=0に設置 あと回転
https://chat.openai.com/share/1224e162-4d47-479b-ac75-28c6fc1cc2bf
透明立方体 1辺10
https://chat.openai.com/share/5efbd5c5-d60a-44d3-8a24-e0c5224e2592
透明球体 半径3
https://chat.openai.com/share/519d6918-10df-4073-9e64-16fa0c4c62ab
https://chat.openai.com/share/88e5eba5-c82a-4ee1-bdb1-49cdfbafb0a0
https://www.youtube.com/watch?v=AxWP1FFpwOQ
import bpy
# 画像ファイルのパスを設定
image_path1 = "C:\\aaa_2024all\\2024copy\\20240502___IMG_0409.PNG"
image_path2 = "C:\\aaa_2024all\\2024copy\\2024-05-02_16h15_38赤丸.png"
# フィルタータイプの辞書を作成
filter_types = {
1: 'NOTHING', # 穴なし??
2: 'NGON', # 多角形??
3: 'TRIFAN' # 三角形の組み合わせ??
}
# 冒頭で中心座標とフィルタータイプを選択
zionad_square_center = (0, 0, 0) # 正方形の中心位置座標を指定
selected_type = 2 # 1: NOTHING, 2: NGON, 3: TRIFAN を選択
num_edges = 4 # 正方形の辺の数は 4 です
# サークルを作成して配置する関数を定義
def create_square(x_coordinate, y_coordinate, z_coordinate, fill_type, num_edges):
"""
与えられた座標に正方形を作成します。
Parameters:
x_coordinate (float): x 座標
y_coordinate (float): y 座標
z_coordinate (float): z 座標
fill_type (str): フィルタータイプ
num_edges (int): 正方形の辺の数
"""
# 正方形を作成
bpy.ops.mesh.primitive_circle_add(radius=1, fill_type=fill_type, vertices=num_edges, location=(x_coordinate, y_coordinate, z_coordinate))
# アクティブなオブジェクトを取得
obj = bpy.context.active_object
# マテリアルを作成
mat = bpy.data.materials.new(name="MyMaterial")
mat.use_nodes = True
nodes = mat.node_tree.nodes
principled_bsdf = nodes.get("Principled BSDF")
output = nodes.get("Material Output")
# 1つ目の画像テクスチャノードを作成
image_texture_node1 = nodes.new(type='ShaderNodeTexImage')
image_texture_node1.image = bpy.data.images.load(image_path1)
# 2つ目の画像テクスチャノードを作成
image_texture_node2 = nodes.new(type='ShaderNodeTexImage')
image_texture_node2.image = bpy.data.images.load(image_path2)
# Texture Coordinate ノードを作成
tex_coord_node = nodes.new(type='ShaderNodeTexCoord')
# Mapping ノードを作成
mapping_node1 = nodes.new(type='ShaderNodeMapping')
mapping_node2 = nodes.new(type='ShaderNodeMapping')
# Geometryノードを作成
geometry_node = nodes.new(type='ShaderNodeNewGeometry')
# MixRGBノードを作成
mix_node = nodes.new(type='ShaderNodeMixRGB')
# Brightness Contrast ノードを作成
bright_node = nodes.new(type='ShaderNodeBrightContrast')
bright_node.inputs['Contrast'].default_value = 0.0 # コントラストをデフォルト値に設定
# Gamma ノードを作成
gamma_node = nodes.new(type='ShaderNodeGamma')
gamma_node.inputs['Gamma'].default_value = 1.0 # ガンマ値をデフォルト値に設定
# マテリアルにノードを追加して設定
obj.data.materials.append(mat)
# マテリアルのノードを接続
links = mat.node_tree.links
links.new(tex_coord_node.outputs['UV'], mapping_node1.inputs['Vector']) # Texture Coordinate ノードの UV を Mapping ノードの Vector に接続
links.new(tex_coord_node.outputs['UV'], mapping_node2.inputs['Vector']) # Texture Coordinate ノードの UV を Mapping ノードの Vector に接続
links.new(mapping_node1.outputs['Vector'], image_texture_node1.inputs['Vector']) # Mapping ノードの Vector を 1つ目の画像テクスチャの Vector に接続
links.new(mapping_node2.outputs['Vector'], image_texture_node2.inputs['Vector']) # Mapping ノードの Vector を 2つ目の画像テクスチャの Vector に接続
links.new(geometry_node.outputs['Backfacing'], mix_node.inputs['Fac']) # GeometryノードのBackfacingをMixRGBノードのFacに接続
links.new(image_texture_node1.outputs['Color'], mix_node.inputs[1]) # 1つ目の画像テクスチャをMixRGBノードのBに接続
links.new(image_texture_node2.outputs['Color'], mix_node.inputs[2]) # 2つ目の画像テクスチャをMixRGBノードのColor 2に接続
links.new(mix_node.outputs[0], bright_node.inputs['Color']) # MixRGBノードの出力をBrightness Contrast ノードのColorに接続
links.new(bright_node.outputs['Color'], gamma_node.inputs['Color']) # Brightness Contrast ノードの出力をGammaノードのColorに接続
links.new(gamma_node.outputs['Color'], principled_bsdf.inputs['Base Color']) # Gammaノードの出力をPrincipled BSDFのBase Colorに接続
links.new(principled_bsdf.outputs['BSDF'], output.inputs['Surface']) # Principled BSDFの出力をマテリアルのSurfaceに接続
# 選択されたフィルタータイプに応じて正方形を作成
fill_type = filter_types[selected_type]
create_square(zionad_square_center[0], zionad_square_center[1], zionad_square_center[2], fill_type, num_edges)