2023年7月25日火曜日
20230727 aaa コレクショ 作成
20230726 円周 3つ 改造 5 √3 1
import bpy
import bmesh # Import the bmesh module
# 円の半径
radius = 6.0
# 3つの円の位置(指定地に配置する座標)を修正
positions = [
(-12, 0, 0),
(0, 0, 0),
(12, 0, 0)
]
# 3つの色を用意(より薄い青)
colors = [
(0.4, 0.8, 1.0, 1.0),
(0.3, 0.6, 1.0, 1.0),
(0.2, 0.4, 1.0, 1.0)
]
# 3つの円を作成し、位置と色を設定
for i, (position, color) in enumerate(zip(positions, colors)):
# 新しいメッシュを作成
mesh = bpy.data.meshes.new(f"CircleMesh_{i}")
obj = bpy.data.objects.new(f"Circle_{i}", mesh)
# シーンに追加
scene = bpy.context.scene
scene.collection.objects.link(obj)
# メッシュを作成
bm = bmesh.new()
bmesh.ops.create_circle(bm, cap_ends=True, cap_tris=False, segments=64, radius=radius)
bm.to_mesh(mesh)
bm.free()
# オブジェクトの位置を設定
obj.location = position
# マテリアルを作成しオブジェクトに割り当てる
mat = bpy.data.materials.new(name=f"Material_{i}")
mat.use_nodes = False # ノードを使用しない
mat.diffuse_color = color
obj.data.materials.append(mat)
20230726 基本 球体ポイント
blender python
指定した位置に 球体を作る
球体半径 0.1
球体中心位置は
z=0の
(x,y)=
-1,1
0,1
1,1
-1,0
0,0
1,0
-1,-1
0,-1
1,-1
import bpy
def create_sphere(x, y, z, radius):
bpy.ops.mesh.primitive_uv_sphere_add(location=(x, y, z), radius=radius)
positions = [
(-1, 1),
(0, 1),
(1, 1),
(-1, 0),
(0, 0),
(1, 0),
(-1, -1),
(0, -1),
(1, -1)
]
sphere_radius = 0.1
z_position = 0
for pos in positions:
x, y = pos[0], pos[1]
create_sphere(x, y, z_position, sphere_radius)
Z=0 で
000を中心とする半径1の円
20230726 中点連結定理 正三角形4つ
blender python
1辺 4長さの正三角形を
まず 大きい正三角形を作る
頂点 000
底辺 y=√3
import bpy
import math
# 新しいメッシュオブジェクトを作成
mesh = bpy.data.meshes.new('EquilateralTriangle')
obj = bpy.data.objects.new('EquilateralTriangle', mesh)
# オブジェクトをシーンに追加
scene = bpy.context.scene
scene.collection.objects.link(obj)
# 頂点座標を計算
a = 4.0 # 辺の長さ
h = (math.sqrt(3) / 2) * a # 高さ
vertices = [
(0, 0, 0),
(a / 2, -h, 0),
(-a / 2, -h, 0),
]
# 面を定義
faces = [(0, 1, 2)]
# メッシュに頂点と面を設定
mesh.from_pydata(vertices, [], faces)
# オブジェクトを選択
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
import bpy import math # 新しいメッシュオブジェクトを作成 mesh = bpy.data.meshes.new('EquilateralTriangle') obj = bpy.data.objects.new('EquilateralTriangle', mesh) # オブジェクトをシーンに追加 scene = bpy.context.scene scene.collection.objects.link(obj) # 頂点座標を計算 a = 4.0 # 辺の長さ h = (math.sqrt(3) / 2) * a # 高さ vertices = [ (0, 0, 0), (a / 2, -h, 0), (-a / 2, -h, 0), ] # 面を定義 faces = [(0, 1, 2)] # メッシュに頂点と面を設定 mesh.from_pydata(vertices, [], faces) # オブジェクトを選択 bpy.context.view_layer.objects.active = obj obj.select_set(True)
4つの正三角形 辺長さ2で 作る
2023年7月23日日曜日
20230724 窓面 追加
import bpy
# List of collection names
collection_names = [
"窓面 Z=+48"
]
# Function to create a new collection
def create_collection(name):
collection = bpy.data.collections.new(name)
bpy.context.scene.collection.children.link(collection)
return collection
# Create collections
for name in collection_names:
create_collection(name)
"窓面 Z=+60"
"窓面 Z=+48"
"窓面 Z=+72"
blender python
球体 複数を
正方形の周囲に等間隔で配置する
球体半径 0.3
球体 40個
正方形中心 xyz=0,0,60
正方形の1辺 12
import bpy
import math
# 球体の半径
radius = 0.3
# 正方形の中心座標
square_center = (0, 0, 60)
# 正方形の1辺の長さ
side_length = 12.0
# 球体の個数
num_spheres = 40
# 等間隔に配置する角度の計算
angle_step = 2 * math.pi / num_spheres
# 球体を等間隔に配置
for i in range(num_spheres):
angle = i * angle_step
x = square_center[0] + (side_length / 2) * math.cos(angle)
y = square_center[1] + (side_length / 2) * math.sin(angle)
bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, location=(x, y, square_center[2]))
import bpy
import math
# 球体の半径
radius = 0.3
# 正方形の中心座標
square_center = (0, 0, 72)
# 正方形の1辺の長さ
side_length = 12.0
# 球体の個数
num_spheres = 40
# 等間隔に配置する角度の計算
angle_step = 2 * math.pi / num_spheres
# 球体を等間隔に配置
for i in range(num_spheres):
angle = i * angle_step
x = square_center[0] + (side_length / 2) * math.cos(angle)
y = square_center[1] + (side_length / 2) * math.sin(angle)
bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, location=(x, y, square_center[2]))
import bpy
import math
# 球体の半径
radius = 0.3
# 正方形の中心座標
square_center = (0, 0, 48)
# 正方形の1辺の長さ
side_length = 12.0
# 球体の個数
num_spheres = 40
# 等間隔に配置する角度の計算
angle_step = 2 * math.pi / num_spheres
# 球体を等間隔に配置
for i in range(num_spheres):
angle = i * angle_step
x = square_center[0] + (side_length / 2) * math.cos(angle)
y = square_center[1] + (side_length / 2) * math.sin(angle)
bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, location=(x, y, square_center[2]))
球体 半径0.5
球体中心 000
20230724 railcar
コレクションだけを作って
”railcars"
"red points"
"pink points"
"railcar Z=-12"
"railcar Z=0"
20230724 mon カメラ配置テスト
コレクションだけを作って
”railcars"
"red points"
"pink points"
blender python
カメラを配置して
カメラの向きは xyz=000
位置は 円周上
円周は 半径1 中心000
等間隔に16台カメラ配置して
コレクションを作って入れて
名前は 円周上の角度で
import bpy
import math
import mathutils
# カメラの数
num_cameras = 16
# 円周の半径
radius = 5.0
# 被写体の位置
target_location = mathutils.Vector((0, 0, 0))
# コレクションを作成
collection_name = "CameraCollection"
if collection_name not in bpy.data.collections:
bpy.data.collections.new(collection_name)
bpy.context.scene.collection.children.link(bpy.data.collections[collection_name])
# 円周上にカメラを等間隔に配置
for i in range(num_cameras):
angle = 2 * math.pi * i / num_cameras
x = radius * math.cos(angle)
y = radius * math.sin(angle)
z = 0.0 # カメラの高さを調整する場合は適宜変更してください
# カメラを作成
bpy.ops.object.camera_add(location=(x, y, z))
camera = bpy.context.object
# 被写体の位置への方向ベクトルを計算
direction = (target_location - camera.location).normalized()
# カメラの向きを設定(180度回転)
camera.rotation_euler = direction.to_track_quat('Z', 'Y').to_euler()
camera.rotation_euler[2] += math.radians(180)
# カメラの名前を角度に設定
camera.name = f"Camera_{i:02d}_{math.degrees(angle):.2f}deg"
カメラを 3秒ごとに 切替えて
正方形を作る
1辺 12
中心
000
-12、0、0
+12.0.0
import bpy
import math
# 正方形の1辺の長さ
side_length = 12.0
# 3つの正方形の位置(指定地に配置する座標)
positions = [
(0, 0, 0),
(-12, 0, 0),
(12, 0, 0)
]
# 3つの色を用意(指定の色)
colors = [(0.0, 0.0, 0.4, 1.0), # 赤
(0.0, 0.0, 0.6, 1.0), # 緑
(0.0, 0.0, 0.8, 1.0)] # 青
# 3つの正方形を作成し、位置と色を設定
for i, (position, color) in enumerate(zip(positions, colors)):
# 新しいメッシュを作成
mesh = bpy.data.meshes.new(f"SquareMesh_{i}")
obj = bpy.data.objects.new(f"Square_{i}", mesh)
# シーンに追加
scene = bpy.context.scene
scene.collection.objects.link(obj)
# メッシュの頂点を設定
vertices = [
(side_length / 2, side_length / 2, 0),
(-side_length / 2, side_length / 2, 0),
(-side_length / 2, -side_length / 2, 0),
(side_length / 2, -side_length / 2, 0)
]
mesh.from_pydata(vertices, [], 0, 1, 2, 3)
# オブジェクトの位置を設定
obj.location = position
# マテリアルを作成しオブジェクトに割り当てる
mat = bpy.data.materials.new(name=f"Material_{i}")
mat.use_nodes = False # ノードを使用しない
mat.diffuse_color = color
obj.data.materials.append(mat)
import bpy
import math
# 正方形の1辺の長さ
side_length = 12.0
# 3つの正方形の位置(指定地に配置する座標)
positions = [
(0, 0, 0),
(-6, 0, 0),
(6, 0, 0)
]
# 3つの正方形を作成し、位置を設定
for i, position in enumerate(positions):
# 新しいメッシュを作成
mesh = bpy.data.meshes.new(f"SquareMesh_{i}")
obj = bpy.data.objects.new(f"Square_{i}", mesh)
# シーンに追加
scene = bpy.context.scene
scene.collection.objects.link(obj)
# メッシュの頂点を設定
vertices = [
(side_length / 2, side_length / 2, 0),
(-side_length / 2, side_length / 2, 0),
(-side_length / 2, -side_length / 2, 0),
(side_length / 2, -side_length / 2, 0)
]
mesh.from_pydata(vertices, [], [[0, 1, 2, 3]])
# オブジェクトをアクティブにする
bpy.context.view_layer.objects.active = obj
# メッシュをアクティブにしてオブジェクトモードに切り替え
bpy.ops.object.mode_set(mode="OBJECT")
# オブジェクトの位置を設定
obj.location = position


