写真 貼り テスト
import bpy
import math
def create_circle_on_plane(plane, color, use_texture=False):
# ... (Rest of the function remains unchanged) ...
# xy plane - 0, 191, 255 (Deep Sky Blue)
create_circle_on_plane("XY", (0/255, 191/255, 255/255, 1.0))
# yz plane - (255, 105, 180)
create_circle_on_plane("YZ", (255/255, 105/255, 180/255, 1.0))
# zx plane - 薄緑 (Light Green) - (144, 238, 144)
create_circle_on_plane("ZX", (144/255, 238/255, 144/255, 1.0))
# Assign image texture to the specified plane (XY) and leave the others with their original color
image_path = r"C:\aaa 2023 dondon\aaa2023いつもの\blende_gazou\test 貼り付け 2023\2023-08-03_09h12_22.png" # Replace with the path to your image
image_texture = bpy.data.images.load(image_path)
for plane in ["XY", "YZ", "ZX"]:
material_name = "Circle_Material_" + plane
material = bpy.data.materials[material_name]
material.use_nodes = True
bsdf_node = material.node_tree.nodes.get('Principled BSDF')
if plane == "XY":
texture_node = material.node_tree.nodes.new(type='ShaderNodeTexImage')
texture_node.image = image_texture
material.node_tree.links.new(bsdf_node.inputs['Base Color'], texture_node.outputs['Color'])
else:
# Reset the color for other circles to their original color
material.diffuse_color = bpy.context.scene.cursor.color
To achieve the desired behavior of setting the texture only for the circle with the color (1, 0, 0) and leaving the rest with the original color specified, you can modify the script as follows:
pythonimport bpy
import math
def create_circle_on_plane(plane, color, use_texture=False):
# ... (Rest of the function remains unchanged) ...
# xy plane - 0, 191, 255 (Deep Sky Blue)
create_circle_on_plane("XY", (0/255, 191/255, 255/255, 1.0))
# yz plane - (255, 105, 180)
create_circle_on_plane("YZ", (255/255, 105/255, 180/255, 1.0))
# zx plane - 薄緑 (Light Green) - (144, 238, 144)
create_circle_on_plane("ZX", (144/255, 238/255, 144/255, 1.0))
# Assign image texture to the specified plane (XY) and leave the others with their original color
image_path = r"C:\aaa 2023 dondon\aaa2023いつもの\blende_gazou\test 貼り付け 2023\2023-08-03_09h12_22.png" # Replace with the path to your image
image_texture = bpy.data.images.load(image_path)
for plane in ["XY", "YZ", "ZX"]:
material_name = "Circle_Material_" + plane
material = bpy.data.materials[material_name]
material.use_nodes = True
bsdf_node = material.node_tree.nodes.get('Principled BSDF')
if plane == "XY":
texture_node = material.node_tree.nodes.new(type='ShaderNodeTexImage')
texture_node.image = image_texture
material.node_tree.links.new(bsdf_node.inputs['Base Color'], texture_node.outputs['Color'])
else:
# Reset the color for other circles to their original color
material.diffuse_color = bpy.context.scene.cursor.color
In this modified code, I added a use_texture
parameter to the create_circle_on_plane
function, which defaults to False
. If use_texture
is set to True
, it will apply the texture to the XY plane (1, 0, 0). For other planes (YZ and ZX), it will reset their color to the original color specified in the create_circle_on_plane
function. The bpy.context.scene.cursor.color
holds the original color value for circles other than XY.
You can control the behavior by setting use_texture=True
when calling the function for the XY plane, like this:
python# xy plane - 1, 0, 0 (Red) - Apply texture
create_circle_on_plane("XY", (1, 0, 0, 1.0), use_texture=True)
# yz plane - (255, 105, 180)
create_circle_on_plane("YZ", (255/255, 105/255, 180/255, 1.0))
# zx plane - 薄緑 (Light Green) - (144, 238, 144)
create_circle_on_plane("ZX", (144/255, 238/255, 144/255, 1.0))
This way, the XY plane will have the image texture applied, and the other planes will retain their original colors.
import bpy
import math
def create_circle_on_plane(plane, color):
# Set the circle's radius and center
radius = 1
center = (0, 0, 0)
# Create a new mesh circle with filled ngon
bpy.ops.mesh.primitive_circle_add(radius=radius, location=center, fill_type='NGON')
# Rename the circle object
circle_obj = bpy.context.active_object
circle_obj.name = "Circle_" + plane
# Check if the material already exists, otherwise create a new one
material_name = "Circle_Material_" + plane
if material_name not in bpy.data.materials:
material = bpy.data.materials.new(name=material_name)
else:
material = bpy.data.materials[material_name]
# Assign the color to the material
material.use_nodes = False
material.diffuse_color = color
# Create a material slot and assign the material to the circle object
if not circle_obj.data.materials:
circle_obj.data.materials.append(material)
else:
circle_obj.data.materials[0] = material
if plane == "YZ":
# Swap Y and Z components of the vertices for YZ plane
for vertex in circle_obj.data.vertices:
temp_y = vertex.co.y
vertex.co.y = vertex.co.z
vertex.co.z = temp_y
# Z-axis rotation (90 degrees) for YZ plane
rotation_angle = math.radians(90)
bpy.context.view_layer.objects.active = circle_obj
bpy.ops.transform.rotate(value=rotation_angle, orient_axis='Z')
elif plane == "ZX":
# Swap Y and Z components of the vertices for ZX plane
for vertex in circle_obj.data.vertices:
temp_y = vertex.co.y
vertex.co.y = vertex.co.z
vertex.co.z = temp_y
# UV Unwrapping
bpy.context.view_layer.objects.active = circle_obj
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.uv.unwrap(method='ANGLE_BASED', margin=0.001)
bpy.ops.object.mode_set(mode='OBJECT')
# xy plane - 0, 191, 255 (Deep Sky Blue)
create_circle_on_plane("XY", (0/255, 191/255, 255/255, 1.0))
# yz plane - (255, 105, 180)
create_circle_on_plane("YZ", (255/255, 105/255, 180/255, 1.0))
# zx plane - 薄緑 (Light Green) - (144, 238, 144)
create_circle_on_plane("ZX", (144/255, 238/255, 144/255, 1.0))
# Assign image texture to the planes
image_path = r"C:\aaa 2023 dondon\aaa2023いつもの\blende_gazou\test 貼り付け 2023\2023-08-03_09h12_22.png" # Replace with the path to your image
image_texture = bpy.data.images.load(image_path)
for plane in ["XY", "YZ", "ZX"]:
material_name = "Circle_Material_" + plane
material = bpy.data.materials[material_name]
material.use_nodes = True
bsdf_node = material.node_tree.nodes.get('Principled BSDF')
texture_node = material.node_tree.nodes.new(type='ShaderNodeTexImage')
texture_node.image = image_texture
material.node_tree.links.new(bsdf_node.inputs['Base Color'], texture_node.outputs['Color'])
import bpy
import math
def create_circle_on_plane(plane, color):
# Set the circle's radius and center
radius = 1
center = (0, 0, 0)
# Create a new mesh circle with filled ngon
bpy.ops.mesh.primitive_circle_add(radius=radius, location=center, fill_type='NGON')
# Rename the circle object
circle_obj = bpy.context.active_object
circle_obj.name = "Circle_" + plane
# Check if the material already exists, otherwise create a new one
material_name = "Circle_Material_" + plane
if material_name not in bpy.data.materials:
material = bpy.data.materials.new(name=material_name)
else:
material = bpy.data.materials[material_name]
# Assign the color to the material
material.use_nodes = False
material.diffuse_color = color
# Create a material slot and assign the material to the circle object
if not circle_obj.data.materials:
circle_obj.data.materials.append(material)
else:
circle_obj.data.materials[0] = material
if plane == "YZ":
# Swap Y and Z components of the vertices for YZ plane
for vertex in circle_obj.data.vertices:
temp_y = vertex.co.y
vertex.co.y = vertex.co.z
vertex.co.z = temp_y
# Z-axis rotation (90 degrees) for YZ plane
rotation_angle = math.radians(90)
bpy.context.view_layer.objects.active = circle_obj
bpy.ops.transform.rotate(value=rotation_angle, orient_axis='Z')
elif plane == "ZX":
# Swap Y and Z components of the vertices for ZX plane
for vertex in circle_obj.data.vertices:
temp_y = vertex.co.y
vertex.co.y = vertex.co.z
vertex.co.z = temp_y
# UV Unwrapping
bpy.context.view_layer.objects.active = circle_obj
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.uv.unwrap(method='ANGLE_BASED', margin=0.001)
bpy.ops.object.mode_set(mode='OBJECT')
# xy plane - 0, 191, 255 (Deep Sky Blue)
create_circle_on_plane("XY", (0/255, 191/255, 255/255, 1.0))
# yz plane - (255, 105, 180)
create_circle_on_plane("YZ", (255/255, 105/255, 180/255, 1.0))
# zx plane - 薄緑 (Light Green) - (144, 238, 144)
create_circle_on_plane("ZX", (144/255, 238/255, 144/255, 1.0))
# Assign image texture to the planes
image_path = "C:\aaa 2023 dondon\aaa2023いつもの\blende_gazou\test 貼り付け 2023\2023-08-03_09h12_22.png" # Replace with the path to your image
image_texture = bpy.data.images.load(image_path)
for plane in ["XY", "YZ", "ZX"]:
material_name = "Circle_Material_" + plane
material = bpy.data.materials[material_name]
material.use_nodes = True
bsdf_node = material.node_tree.nodes.get('Principled BSDF')
texture_node = material.node_tree.nodes.new(type='ShaderNodeTexImage')
texture_node.image = image_texture
material.node_tree.links.new(bsdf_node.inputs['Base Color'], texture_node.outputs['Color'])
基本系 配布 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
以下 ChatGPT との対話 修正記録 と メモ・ノート
ああああああああああああああああああああああああああああああああああああああああああああ