xZ平面の 額縁 写真の縦にする 狛犬
import bpy
# コレクションを作成
collection_name = "写真 xz 正方形"
if collection_name not in bpy.data.collections:
sphere_collection = bpy.data.collections.new(collection_name)
bpy.context.scene.collection.children.link(sphere_collection)
else:
sphere_collection = bpy.data.collections[collection_name]
import bpy
zion_name = "狛犬"
shashin = "C:/aaa 2023 dondon/aaa2023いつもの/test_image/komainu20230415sat.jpg"
# 正方形を作成
bpy.ops.mesh.primitive_plane_add(size=60, enter_editmode=False, align='WORLD', location=(0,0,0))
square_obj = bpy.context.active_object
# オブジェクトに名前を付ける
obj = bpy.context.active_object
obj.name = zion_name
# マテリアルを作成
material = bpy.data.materials.new(name="ImageMaterial")
material.use_nodes = True
square_obj.data.materials.append(material)
square_obj.active_material = material
# テクスチャイメージを読み込む
img_path = shashin
tex = bpy.data.images.load(img_path)
# テクスチャノードを作成し、マテリアルに接続する
tex_node = material.node_tree.nodes.new("ShaderNodeTexImage")
tex_node.image = tex
tex_node.location = (-400, 0)
output_node = material.node_tree.nodes["Material Output"]
material.node_tree.links.new(tex_node.outputs[0], output_node.inputs[0])
# オブジェクトをXZ平面に回転する
square_obj.rotation_euler = (1.5708, 0, 0)
そして、この "my_square_obj" オブジェクトをコレクションに追加するには、次のようにします。
scssmy_collection = bpy.data.collections.new("My Collection")
bpy.context.scene.collection.children.link(my_collection)
my_collection.objects.link(my_square_obj)
ここで、新しいコレクションを "My Collection" という名前で作成し、それに "my_square_obj" オブジェクトを追加しています。
import bpy
# オブジェクトを作成
bpy.ops.mesh.primitive_cube_add()
# オブジェクトに名前を付ける
obj = bpy.context.active_object
obj.name = "MyCube"
ここでは、primitive_cube_add()
関数で立方体オブジェクトを作成し、bpy.context.active_object
でアクティブなオブジェクトを取得しています。そして、obj.name = "MyCube"
でオブジェクトの名前を"MyCube"に設定しています。