円柱を斜めにできないので 11個の球体で 斜線を描く
collection_name = "斜めストロボ 2,0,-2"
# コレクションを作成
import bpy
collection_name = "斜めストロボ 2,0,-2"
if collection_name not in bpy.data.collections:
zionad_collection = bpy.data.collections.new(collection_name)
bpy.context.scene.collection.children.link(zionad_collection)
else:
zionad_collection = bpy.data.collections[collection_name]
import bpy
import math
import mathutils
zion_number = 11
zion_radius = 0.1
zion_sx = 2
zion_sy = 0
zion_sz = -2
zion_ex = 0
zion_ey = 0
zion_ez = 0
# オブジェクト名を指定
obj_prefix = "sphere"
# 半径を指定
radius = zion_radius
# 2つの座標を指定
p1 = mathutils.Vector((zion_sx, zion_sy, zion_sz ))
p2 = mathutils.Vector((zion_ex, zion_ey, zion_ez ))
# 2点間の距離を計算
distance = (p2 - p1).length
# 球体の個数を指定
num_spheres = zion_number
# 等間隔の距離を計算
spacing = distance / (num_spheres - 1)
# 球体を生成
for i in range(num_spheres):
# 座標を計算
position = (p2 - p1).normalized() * spacing * i + p1
# 球体を作成
obj_name = obj_prefix + str(i)
bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, enter_editmode=False, location=position)
obj = bpy.context.active_object
obj.name = obj_name
# collection_name = "斜めストロボ 0,3**(1/2),-2"
# コレクションを作成
import bpy
collection_name = "斜めストロボ 0,3**(1/2),-2"
if collection_name not in bpy.data.collections:
zionad_collection = bpy.data.collections.new(collection_name)
bpy.context.scene.collection.children.link(zionad_collection)
else:
zionad_collection = bpy.data.collections[collection_name]
import bpy
import math
import mathutils
# オブジェクト名を指定
obj_prefix = "sphere"
# 半径を指定
radius = 0.1
# 2つの座標を指定
p1 = mathutils.Vector((0, 3**(1/2), -3**(1/2)))
p2 = mathutils.Vector((0, 0, 0))
# 2点間の距離を計算
distance = (p2 - p1).length
# 球体の個数を指定
num_spheres = 11
# 等間隔の距離を計算
spacing = distance / (num_spheres - 1)
# 球体を生成
for i in range(num_spheres):
# 座標を計算
position = (p2 - p1).normalized() * spacing * i + p1
# 球体を作成
obj_name = obj_prefix + str(i)
bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, enter_editmode=False, location=position)
obj = bpy.context.active_object
obj.name = obj_name
# 太陽と カメラを加える
import bpy
# Add a camera
bpy.ops.object.camera_add(location=(0, 0, 0))
camera = bpy.context.object
camera.name = "Camera"
camera.location = (0, 0, 10)
# Add a Sun lamp
bpy.ops.object.light_add(type='SUN', location=(0, 0, 0))
sun = bpy.context.object
sun.name = "Sun"
sun.location = (0, 5, 10)
# カメラの位置を変更する
import bpy
bpy.data.objects['Camera'].location = (0, 0, 8)
# ライトの位置を変更する
bpy.data.objects['Sun'].location = (0, 5, 8)
# カメラの位置を変更する
import bpy
bpy.data.objects['Camera'].location = (0, 0, 10)
# ライトの位置を変更する
bpy.data.objects['Sun'].location = (0, 5, 10)
以下は 原型 ああああああああああああ
# 11個の球体で 斜線を描く
import bpy
import mathutils
# オブジェクト名を指定
obj_name = "spheres"
# 半径を指定
radius = 0.1
# 2つの座標を指定
p1 = mathutils.Vector((2, 0, -2))
p2 = mathutils.Vector((0, 0, 0))
# 2点間の距離を計算
distance = (p2 - p1).length
# 回転を計算
direction = (p2 - p1).normalized()
up = mathutils.Vector((0, 0, 1))
rotation = up.rotation_difference(direction).to_euler()
# 11個の球体の座標を計算
spheres = []
for i in range(11):
t = i / 10
center = p1 + t * (p2 - p1)
sphere = bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, enter_editmode=False, location=center)
bpy.context.object.name = f"{obj_name}_{i}"
spheres.append(sphere)
# 座標を回転
for sphere in spheres:
sphere.rotate(rotation)
# メッシュを結合し、オブジェクトを作成
bpy.ops.object.select_all(action='DESELECT')
bpy.context.view_layer.objects.active = None
bpy.context.view_layer.objects.active = bpy.data.objects[f"{obj_name}_0"]
bpy.ops.object.join()
bpy.context.object.name = obj_name
bpy.ops.object.shade_smooth()
別のChatGPTで 同じこと
# 11個の球体で 斜線を描く 別のChatGPTで 同じこと
import bpy
import math
import mathutils
# オブジェクト名を指定
obj_prefix = "sphere"
# 半径を指定
radius = 0.1
# 球体の個数を指定
num_spheres = 11
# 等間隔の距離を計算
spacing = (num_spheres - 1) * radius * 2 / 10
# 球体を生成
for i in range(num_spheres):
# 座標を計算
x = (i - (num_spheres - 1) / 2) * spacing
y = 0
z = 0
# 球体を作成
obj_name = obj_prefix + str(i)
bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, enter_editmode=False, location=(x, y, z))
obj = bpy.context.active_object
obj.name = obj_name