配布 20230806 光時計 天井位置 床面位置
import bpy
import math
def create_sphere_at_position(position, color, name):
# 半径を設定
radius = 0.1
# 球を作成(指定した座標に)
bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, location=position)
sphere = bpy.context.active_object
# マテリアルを作成
material = bpy.data.materials.new(name="Material_" + name)
sphere.data.materials.append(material)
# マテリアルの設定
material.use_nodes = False
material.diffuse_color = color
# オブジェクトの名前を設定
sphere.name = name
# (0.5, 0, 1) の位置に球体を作成
create_sphere_at_position((0.5, 0, 1), (1.0, 0, 1.0, 1.0), "point(0.50, 0, 1)")
# (1, 0, 1) の位置に球体を作成
create_sphere_at_position((1, 0, 1), (1.0, 0, 1.0, 1.0), "point(1.00, 0, 1)")
# (√2/2, 0, 1) の位置に球体を作成
x = round(math.sqrt(2)/2, 2)
create_sphere_at_position((x, 0, 1), (1.0, 0, 1.0, 1.0), f"point({x:.2f}, 0, 1)")
# (√3/2, 0, 1) の位置に球体を作成
y = round(math.sqrt(3)/2, 2)
create_sphere_at_position((y, 0, 1), (1.0, 0, 1.0, 1.0), f"point({y:.2f}, 0, 1)")
point(0.50, 0, 1) および point(1.00, 0, 1) のように、
名称が小数点以下2桁になります
import bpy
import math
def create_sphere_at_position(position, color, name):
# 半径を設定
radius = 0.1
# 球を作成(指定した座標に)
bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, location=position)
sphere = bpy.context.active_object
# マテリアルを作成
material = bpy.data.materials.new(name="Material_" + name)
sphere.data.materials.append(material)
# マテリアルの設定
material.use_nodes = False
material.diffuse_color = color
# オブジェクトの名前を設定
sphere.name = name
# 球体を作成
create_sphere_at_position((0.5, 0, 0), (1.0, 0, 1.0, 1.0), "point(0.50, 0, 0)")
create_sphere_at_position((1, 0, 0), (1.0, 0, 1.0, 1.0), "point(1.00, 0, 0)")
x = round(math.sqrt(2)/2, 2)
create_sphere_at_position((x, 0, 0), (1.0, 0, 1.0, 1.0), f"point({x:.2f}, 0, 0)")
y = round(math.sqrt(3)/2, 2)
create_sphere_at_position((y, 0, 0), (1.0, 0, 1.0, 1.0), f"point({y:.2f}, 0, 0)")
# コレクションを作る 重複の場合 作らない
import bpy
# List of collection names
collection_names = [
"天井 光時計",
"床面 光時計",
#"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)
mokuji000zionad.hatenablog.com
https://mokuji000zionad.hatenablog.com/entry/2023/07/29/215136