基本立体としては,通常,直方体(立方体を含む),円柱,円錐,多角柱,多角錐, 球,トーラス,正多面体などがあります.これらの基本立体はそれぞれに寸法を決める パラメータが定義されます.例えば直方体では縦・横・高さの3つ,円柱では底面の 半径と高さの2つ,球では半径の1つ,といった具合です.こうしたパラメータを指定 して生成した形状を空間内の適切な位置に配置します.
3次元CADなどの形状モデラでは,こうした基本立体の間の集合演算(和,積,差)などを 行うことができて複雑な形状を作成することができますが,表示のみを対象とした ソフトウェアでは,基本的には立体の重ね合わせのみを行います.
基本立体で表現できない形状に関しては,次の面の集まりで表現することができます. ここでは面は辺が線分で構成される多角形(polygon)とします.多角形はそれを構成する 頂点の並びで表現できますので,多角形の表現は頂点の座標や,頂点の番号を順に記述 することが行われます.コンピュータグラフィックスの世界では,頂点の順番の向きは 面の表側からみたときの反時計回り(CCW)が使用されることが多いことは覚えておいた 方がよいでしょう.
VRMLで定義された世界をウェブブラウザで見るためには,専用のプラグインが 必要です.今回の演習で使用しているノートPCには
VRMLを体験する最もシンプルなプログラムを作成してみましょう. Windowsのメモ帳などのエディタを使って次を内容を含むファイルを 作成してみましょう.ファイル名はCone1.wrlです.
#VRML V2.0 utf8
Shape{
geometry Cone{ }
}
画面に三角錐(コーン)が表示されたと思います.(Cone1.wrl)
ただ,色も何もついていないので,次のような定義をしたファイルCone2.wrl
を作成してみます.
#VRML V2.0 utf8
Shape{
appearance
Appearance { material Material
{ diffuseColor 0 1 0 } }
geometry Cone{ bottomRadius 1
height 2 side
TRUE bottom TRUE} }
}
これで色が付きました.パラメータを色々と変えてどのように変化するかを
確かめて見てください.(Cone2.wrl)
もう少し込み入った例を挙げます.
#VRML V2.0 utf8
NavigationInfo {type ["EXAMINE","ANY"]}
Background {
groundColor 0.000000 0.000000 0.000000
skyColor 0.000000 0.000000 0.000000
}
DirectionalLight {
intensity 1.000000
ambientIntensity 0.200000
color 1.000000 1.000000 1.000000
direction -0.691714 -0.691714 -0.207514
}
Viewpoint {
position 2.000000 2.000000 3.000000
orientation -0.637495 0.745885 -0.193018 0.771213
description "current camera"
}
Transform {
translation 0 0 0
rotation 0 0 1 0
scale 0.001000 0.001000 0.001000
children [
Transform {
translation 0 0 0
rotation 0 0 1 0
scale 1 1 1
children [
Shape {
appearance Appearance {
material Material {
specularColor 1 1 1
diffuseColor 1.000000 1.000000 1.000000
ambientIntensity 0
transparency 0.000000
shininess 0.200000
emissiveColor 0 0 0
}
}
geometry IndexedFaceSet {
ccw FALSE
solid FALSE
creaseAngle 3.14
coord Coordinate {
point [
700.000000 700.000000 -550.000000, # 0
700.000000 0.000000 -550.000000, # 1
700.000000 700.000000 550.000000, # 2
700.000000 0.000000 550.000000, # 3
700.000000 700.000000 550.000000, # 4
700.000000 0.000000 550.000000, # 5
-850.000000 700.000000 550.000000, # 6
-850.000000 0.000000 550.000000, # 7
-850.000000 700.000000 550.000000, # 8
-850.000000 0.000000 550.000000, # 9
-850.000000 700.000000 -550.000000, # 10
-850.000000 0.000000 -550.000000, # 11
-850.000000 700.000000 -550.000000, # 12
-850.000000 0.000000 -550.000000, # 13
700.000000 700.000000 -550.000000, # 14
700.000000 0.000000 -550.000000, # 15
]
}
coordIndex [
2, 3, 1, 0, -1,
6, 7, 5, 4, -1,
10, 11, 9, 8, -1,
14, 15, 13, 12, -1,
]
}
}
]
}
]
}
# End of the file
4つの面で構成される立体が表示されたと思います.
(FourFaces.wrl)
ここで記述されていることがどういう意味なのかは,VRMLの文法に
ついて記したWEBサイトを参照してください.
ファイル Example.wrl
#VRML V2.0 utf8
Viewpoint {
position 10 0 10
orientation 0 1 0 0.8
}
Background {
skyAngle[1.8]
skyColor[0.3 0.6 0.8]
groundColor [0.2 0.5 0.6]
}
Transform {
translation 0 0 0
children [
Transform {
translation -1 0 0
children [
Shape{
appearance
Appearance { material Material
{ diffuseColor 0 1 0 } }
geometry Cone{ bottomRadius 1
height 2
side TRUE
bottom TRUE }
}]
}
Transform {
translation 1 0 0
children [
Shape{
appearance
Appearance { material Material
{ diffuseColor 1 0 0 } }
geometry Box{ size 1.3 1.4 2 }
}]}
Inline{url "./FourFacesb.wrl"}
]
}
ファイル FourFaceb.wrl
#VRML V2.0 utf8
Transform {
translation 0 3 0
rotation 0 0 1 0
scale 0.001000 0.001000 0.001000
children [
Transform {
translation 0 0 0
rotation 0 0 1 0
scale 1 1 1
children [
Shape {
appearance Appearance {
material Material {
specularColor 1 0.5 1
diffuseColor 1.000000 0.500000 1.000000
ambientIntensity 0
transparency 0.000000
shininess 0.200000
emissiveColor 0 0 0
}
}
geometry IndexedFaceSet {
ccw FALSE
solid FALSE
creaseAngle 3.14
coord Coordinate {
point [
700.000000 700.000000 -550.000000, # 0
700.000000 0.000000 -550.000000, # 1
700.000000 700.000000 550.000000, # 2
700.000000 0.000000 550.000000, # 3
700.000000 700.000000 550.000000, # 4
700.000000 0.000000 550.000000, # 5
-850.000000 700.000000 550.000000, # 6
-850.000000 0.000000 550.000000, # 7
-850.000000 700.000000 550.000000, # 8
-850.000000 0.000000 550.000000, # 9
-850.000000 700.000000 -550.000000, # 10
-850.000000 0.000000 -550.000000, # 11
-850.000000 700.000000 -550.000000, # 12
-850.000000 0.000000 -550.000000, # 13
700.000000 700.000000 -550.000000, # 14
700.000000 0.000000 -550.000000, # 15
]
}
coordIndex [
2, 3, 1, 0, -1,
6, 7, 5, 4, -1,
10, 11, 9, 8, -1,
14, 15, 13, 12, -1,
]
}
}
]
}
]
}
このExample.wrlをブラウザに読み込む,FourFacesb.wrlで定義された形状が
Inlineという命令によって取り込まれています.
(Example.wrl)
これによって複数のファイルに定義されているVRMLの形状を1つのシーングラフに
まとめることができます.配置や照明などをいろいろと変化させてみましょう.