• 検索結果がありません。

for item in bpy.context.scene.objects: if item.type == MESH : bpy.context.scene.objects.unlink(item) for item in bpy.data.objects: if item.type == MES

N/A
N/A
Protected

Academic year: 2021

シェア "for item in bpy.context.scene.objects: if item.type == MESH : bpy.context.scene.objects.unlink(item) for item in bpy.data.objects: if item.type == MES"

Copied!
9
0
0

読み込み中.... (全文を見る)

全文

(1)

1

GUI

による操作

1.1

オブジェクトの入力と編集

1.1.1 Smoothing

• Smoothing Object モードで Object Tools → Shading の Smooth を選択する.

ただし,全ての面を滑らかにしてしまうため円筒等を Smoothing すると上下の平坦にしたい面が丸まって しまう.

• Auto Smoothing 角度にしきい値を設定し,なす角度がこの値よりも小さな面同士の間でのみ平滑化を行う.

Object モードで Object Tools→ Shading の Smooth を選択した後,マテリアルの設定の左側にあるアイ コンを選択し Normals の Auto Smooth を選択し,角度の設定を行う.

1.2

レンダーリング

1.2.1 エッジを付ける

post porocessing の Edge を指定することでレンダーリングの結果にエッジの線を追加できる.

1.3

画像出力

1.3.1 画像の保存

レンダリングの後 F3 キーを押す.もしくは下部メニューの Image から保存する.

1.3.2 背景を透明化する

カメラのアイコン (Render タブ) を選択し、hading という項目の Alpha を Sky から Transparent に変更する.

2

Blender + Phyton

2.1

Python

ファイルを指定した Blender の起動方法

test.pyに Python プログラムを記述し,以下のように blender を起動する blender -P test.py

2.2

初期設定

2.2.1 必要なモジュールの import

import os # オペレーティングシステムの機能を呼び出す

import bpy # Python から Blender を操作するためのモジュール import math # 数学関数を使うためのモジュール

(2)

for item in bpy.context.scene.objects: if item.type == ’MESH’:

bpy.context.scene.objects.unlink(item) for item in bpy.data.objects:

if item.type == ’MESH’:

bpy.data.objects.remove(item) for item in bpy.data.meshes:

bpy.data.meshes.remove(item) for item in bpy.data.materials:

bpy.data.materials.remove(item)

2.2.3 World 設定

world = bpy.data.worlds[’World’] # 編集する World の取得 world.horizon_color = (0.0, 0.0, 0.0) world.zenith_color = (0.0, 0.0, 0.0) world.ambient_color = (0.0, 0.0, 0.0) world.light_settings.use_ambient_occlusion = True # 環境光を使う world.light_settings.ao_factor = 0.5 # 環境光の明るさ 2.2.4 シーンの設定 scene = bpy.context.scene scene.render.resolution_x = 1920 # 解像度 scene.render.resolution_y = 1080 # 解像度 scene.render.resolution_percentage = 100 # 解像度 2.2.5 カメラの設定

camera = bpy.data.objects[’Camera’] # 編集する Camera の取得 camera.location = (16, -5.2, 6.5) # カメラの位置 camera.rotation_euler = (1.2, 0, 1.2) # カメラの方向設定 #camera.data.type = ’PERSP’ #camera.data.angle = 1 カメラの方向は X の値を π/2 = 1.57 とすると地面に平行な方向を向き,少し小さくすることで下方を見下ろ すようになる.Z の値を変更することで z 軸を中心にカメラが回転する.Y の値を 0 以外にするとカメラが傾く ことになる.最後の 2 つの機能は不明. 2.2.6 光源の設定

(3)

# キーライト (主となる光源) lamp = bpy.data.objects[’Lamp’] lamp.location = (0, 0, 10) # 位置の指定 (原点の直上) lamp.rotation_euler = (0, 0, 0) # 向きの指定 (直下を向いている) lamp.data.type = ’SPOT’ # スポットライト光源 (他のものでも良い) # ---scene = bpy.context.---scene # ---# 光源の追加.名前を付けておく

lamp_data = bpy.data.lamps.new(name="LampA", type=’POINT’) # 光源オブジェクトの生成.名前を付けておく

lamp_object = bpy.data.objects.new(name="LampA", object_data=lamp_data) # 光源の位置を指定 (後方からの照射) lamp_object.location = (-10.0, -5.0, 5.0) # 光源の明るさ lamp_data.energy = 0.5 # 光源オブジェクトをシーンに追加 scene.objects.link(lamp_object) # ---lamp_data = bpy.data.lamps.new(name="LampB", type=’POINT’)

lamp_object = bpy.data.objects.new(name="LampB", object_data=lamp_data) lamp_object.location = (-15.0, 0.0, 5.0) # 後方からの照明

lamp_data.energy = 0.5

scene.objects.link(lamp_object)

# ---lamp_data = bpy.data.lamps.new(name="LampC", type=’POINT’)

lamp_object = bpy.data.objects.new(name="LampC", object_data=lamp_data) lamp_object.location = (10.0, -5.0, 5.0) # 前方からの照明

lamp_data.energy = 0.5

scene.objects.link(lamp_object)

#

---光源のタイプには (POINT, SUN, SPOT, HEMI, AREA) が選べる.POINT 以外は方向を調整する.

2.2.7 材料の用意 materials = [] materials.append(bpy.data.materials.new(’Color0’)) # 材料 (Color0) の生成 materials[0].diffuse_color = (0,0,1) # RGB による色指定 materials.append(bpy.data.materials.new(’Color1’)) materials[1].diffuse_color = (0,1,0) 材料設定の詳細は後で記述する

(4)

2.2.8 物体の追加 • 直方体 bpy.ops.mesh.primitive_cube_add(location=(0, 0, -0.5)) # 位置を指定して直方体を作成 bpy.ops.transform.resize(value=(5.0,2.0,0.5)) # 直方体の大きさの変更 bpy.context.object.data.materials.append(materials[0]) # 直方体の材料の設定 • 円柱 bpy.ops.mesh.primitive_cylinder_add(location=(0,0,0),radius=0.5,depth=1.0) bpy.context.object.data.materials.append(materials[0]) • 正多角柱 正多角柱は円柱の頂点を減らすことで生成できる.以下に正六角柱の例を示す. bpy.ops.mesh.primitive_cylinder_add(location=(0,0,0),radius=0.5,depth=0.3,vertices=6) bpy.context.object.data.materials.append(materials[0]) • 多面体 以下に曲がり導波路の例を示す.x 方向の導波路長を 10.0 導波路の幅と高さをそれぞれ 1.0,0.5 とする.また, 導波路底面の z 方向位置を 0.0 とし,導波路中心が原点を通るようにしている. nx = 20 Lx = 10.0; verts = [] faces = [] for i in range (0, nx+1): x = Lx/nx*i-5 y = -0.5+math.cos(math.pi*i/nx) z = 0.0 verts.append((x,y,z)) y += 1.0 verts.append((x,y,z)) z += 0.5 verts.append((x,y,z)) y -= 1.0 verts.append((x,y,z))

for i in range (0, nx): faces.append((4*i+1,4*i+5,4*i+4,4*i+0)) for i in range (0, nx): faces.append((4*i+1,4*i+2,4*i+6,4*i+5)) for i in range (0, nx): faces.append((4*i+2,4*i+3,4*i+7,4*i+6))

(5)

faces.append((0,3,2,1))

faces.append((4*nx,4*nx+1,4*nx+2,4*nx+3))

mesh = bpy.data.meshes.new("Guide")

object = bpy.data.objects.new("Guide", mesh)

object.location = (0,0,0) bpy.context.scene.objects.link(object) mesh.from_pydata(verts,[],faces) mesh.update(calc_edges=True) mesh.materials.append(materials[1]) まず頂点の座標を設定し,頂点から面 (ここでは長方形) を生成する.その後,メッシュオブジェクトを生成し 位置を指定しシーンに追加する.このメッシュと先に作成してある頂点,面のデータを関係付け,エッジの情報を 更新する.最後に材料の情報を与える. この実行結果は以下のようになる.ただし,この結果では基板とフィルムを追加している. 同様にして任意の構造を作成できる.以下にボウタイアンテナの作成画像を示す.

(6)

2.2.9 オブジェクトのブール演算 2つのオブジェクトのブール演算を取ることにより,より複雑な構造を表現できる. • 物体の差 以下に六角柱から円柱を抜き取ることで三角格子フォトニック結晶の単位セルを生成する例を示す. # 正六角柱の生成 bpy.ops.mesh.primitive_cylinder_add(location=(0,0,0),radius=0.5,depth=0.3,vertices=6) bpy.context.object.data.materials.append(materials[0]) film_obj = bpy.context.object # 円柱の生成 bpy.ops.mesh.primitive_cylinder_add(location=(0,0,0),radius=0.2,depth=0.4) cyl_obj = bpy.context.object # ブール演算 boolean = film_obj.modifiers.new(’My_Bool’,’BOOLEAN’) boolean.operation = ’DIFFERENCE’ boolean.object = cyl_obj bpy.context.scene.objects.active = film_obj bpy.ops.object.modifier_apply(apply_as=’DATA’, modifier="My_Bool") bpy.context.scene.objects.unlink(cyl_obj) モディファイアを適用する前に対象オブジェクトをアクティブにする必要がある. • 物体の結合

(7)

# 基板 bpy.ops.mesh.primitive_cube_add(location=(0, 0, -0.5)) bpy.ops.transform.resize(value=(5.0,2.0,0.5)) bpy.context.object.data.materials.append(materials[0]) # フィルム bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0.25)) bpy.ops.transform.resize(value=(5.0,2.0,0.25)) bpy.context.object.data.materials.append(materials[1]) rib_obj = bpy.context.object # リブ bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0.75)) bpy.ops.transform.resize(value=(5.0,0.5,0.25)) bpy.context.object.data.materials.append(materials[1]) obj = bpy.context.object # ブール演算 boolean = rib_obj.modifiers.new(’My_Bool’,’BOOLEAN’) boolean.operation = ’UNION’ boolean.object = obj bpy.context.scene.objects.active = rib_obj bpy.ops.object.modifier_apply(apply_as=’DATA’, modifier="My_Bool") bpy.context.scene.objects.unlink(obj) 以下にフォトニック結晶導波路の作成例を示す. aa = 1.0 rr = 0.3*aa ww = aa*math.sqrt(3.0) WW = 10*aa*math.sqrt(3.0)/2 tt = 0.4*aa # 長方形スラブ bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0)) bpy.ops.transform.resize(value=(5.0*aa,WW/2,tt/2)) bpy.context.object.data.materials.append(materials[0]) slab_obj = bpy.context.object

(8)

# 直線導波路 bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0)) bpy.ops.transform.resize(value=(8.0*aa,ww/2,tt/2)) bpy.context.object.data.materials.append(materials[0]) obj = bpy.context.object # ブール演算 boolean = slab_obj.modifiers.new(’My_Bool’,’BOOLEAN’) boolean.operation = ’UNION’ boolean.object = obj bpy.context.scene.objects.active = slab_obj bpy.ops.object.modifier_apply(apply_as=’DATA’, modifier="My_Bool") bpy.context.scene.objects.unlink(obj) for j in range (-5, 6): y = j*aa*math.sqrt(3.0)/2 if j != 0: if j%2 == 0: nm = 1 else: nm = 0 for i in range (-5, 6-nm): if j%2 == 0: x = (i+0.5)*aa else: x = i*aa bpy.ops.mesh.primitive_cylinder_add(location=(x,y,0),radius=rr,depth=2*tt) obj = bpy.context.object # ブール演算 boolean = slab_obj.modifiers.new(’My_Bool’,’BOOLEAN’) boolean.operation = ’DIFFERENCE’ boolean.object = obj bpy.context.scene.objects.active = slab_obj bpy.ops.object.modifier_apply(apply_as=’DATA’, modifier="My_Bool") bpy.context.scene.objects.unlink(obj) この実行結果は以下のようになる.

(9)

参照

関連したドキュメント

Theorem 3.1 implies that (a) any silting subcategory of K b (proj Λ) is the additive closure of a silting object, and (b) any two basic silting objects have the same number

Actually, although the motivation and ideas of the biadjoint triangle theorems came from the original adjoint triangle theorem [2, 20] and its enriched version stated in Section

We see that simple ordered graphs without isolated vertices, with the ordered subgraph relation and with size being measured by the number of edges, form a binary class of

To define the category of sets of which this type of sets is the type of objects requires choosing a second universe of types U 0 and an element u of U 0 such that U = El(u) where El

In the same vein, we can show that the answer to the question of whether a set of generating cofibrations and trivial cofibrations in a locally presentable category really do generate

The example problems studied include the standard overlapping scans, a multiple searcher with multiple objects problem where each searcher is tuned to a specific object type, and

Roberts (0 (( Why Institutions Matter :The New Institutionalism in Political Science, Palgrave ( ) Public Administration Review, vol. Context in Public Policy and

In order to facilitate information exchange, Japan Customs improved rules for information provision to foreign customs administrations based on the tariff reform in March 1998