背景

 背景の設定はBackgroundノードで行います。

Background

 VRMLでは、背景を次のように定義しています。

 Backgroundノードの定義形式を次に示します。


Background { 
  eventIn      SFBool   set_bind
  exposedField MFFloat  groundAngle  []     
  exposedField MFColor  groundColor  []
  exposedField MFString backUrl      []
  exposedField MFString bottomUrl    []
  exposedField MFString frontUrl     []
  exposedField MFString leftUrl      []
  exposedField MFString rightUrl     []
  exposedField MFString topUrl       []
  exposedField MFFloat  skyAngle     [] 
  exposedField MFColor  skyColor     0 0 0
  eventOut     SFBool   isBound
}


skyColorフィールドとskyAngleフィールド
skyColorフィールドで空の色を指定します。
空の角度は、天頂が 0、地平線(水平線)がπ/2 (90°)、 天底がπ(180°)で表されます。
skyAngleフィールドで、0〜πの角度を(順に大きくなるように)与えると、 その角度の同心円にskyColorフィールドで指定した色が順番に対応して 付けられ、同心円間は内挿された色になります。
skyAngleフィールドでは0とπは省略できますが、 指定されているのと同じです。
skyAngleフィールドの角度とskyColorフィールドの色は 順番に対応しますが、 色の指定の方が多いと残りは無視され、角度の指定の方が多いと 最後の色が繰り返し使われます。
groundColorフィールドとgroundAngleフィールド
groundColorフィールドで地面の色を指定します。
地面の角度は、天底が 0、 地平線がπ/2 (90°)で表されます。
groundAngleフィールドで、0〜π/2 の角度を(順に大きくなるように) 与えると、その角度の同心円にgroundColorフィールドで指定した色が 順番に対応して付けられ、同心円間は内挿された色になります。
groundAngleフィールドでは 0 は省略できますが、 指定されているのと同じです。
π/2 を指定すると地平線まで地面が現れますが、 最後の角度の指定がπ/2 より小さい場合は 地面はその角度までになります(代わりに空が見えます)。
groundAngleフィールドの角度とgroundColorフィールドの色は 順番に対応しますが、 色の指定の方が多いと残りは無視され、角度の指定の方が多いと 最後の色が繰り返し使われます。
backUrl、bottomUrl、frontUrl、leftUrl、rightUrl、topUrlフィールド
これらのフィールドで、背景の立方体の各面に貼り付ける イメージファイルのURLを指定します。
フィールドでイメージファイルが指定されていない面は、 面が存在せず、空や地面が見えています。

Backgroundの例

空と地面

 skyColorフィールドとskyAngleフィールドおよびgroundColorフィールドとgroundAngleフィールドを指定した例を示します。

地面が地平線まで

 この例では地面は地平線まで定義されています。VRMLブラウザでビューポイントの位置を変えて空や地面がどのように見えるのか試してみてください。


#VRML V2.0 utf8
#background1.wrl

#背景 地面が 地平線(90°)まで
Background { 
  skyAngle [ 0.785  1.3  1.57  2.07 ]
  skyColor [ 0.6 0.6 1, 0.7 0.7 1, 0.8 0.8 1, 0.9 0.9 1, 1 1 1 ] 
  groundAngle [ 0.35  0.785  1.20  1.57 ]    #ground --> horizon
  groundColor [0.4 0.2 0.2, 0.4 0.3 0.3, 0.4 0.4 0.4, 0.4 0.5 0.5, 0.4 0.6 0.6] }

#視点
Viewpoint { description "horison" position 0 0 0 }
Viewpoint { description "zenith" position 0.0 0.0 0 orientation -1 0 0  -1.57 }
Viewpoint { description "nadir" position 0.0 0.0 0 orientation -1 0 0  1.57 }

地面が地平線まで (クリックすると上の例がVRMLブラウザに表示されます)


地面が地平線より下

 この例では地面は地平線より下の位置まで定義されています。VRMLブラウザでビューポイントの位置を変えて空や地面がどのように見えるのか試してみてください。


#VRML V2.0 utf8
#background2.wrl

#背景 地面が 70°まで
Background { 
  skyAngle [ 0.785  1.3  1.57  2.07 ]
  skyColor [ 0.6 0.6 1, 0.7 0.7 1, 0.8 0.8 1, 0.9 0.9 1, 1 1 1 ] 
  groundAngle [ 0.35 0.785 1.22  ]    #ground --> 1.22 (70°)
  groundColor [0.4 0.2 0.2, 0.4 0.3 0.3, 0.4 0.4 0.4, 0.4 0.5 0.5,0.4 0.6 0.6]
}

#視点
Viewpoint { description "horison" position 0 0 0 }
Viewpoint { description "zenith" position 0.0 0.0 0 orientation -1 0 0  -1.57 }
Viewpoint { description "nadir" position 0.0 0.0 0 orientation -1 0 0  1.57 }

地面が地平線より下 (クリックすると上の例がVRMLブラウザに表示されます)


立方体の背景

 backUrl、bottomUrl、frontUrl、leftUrl、rightUrl、topUrlフィールドを指定した例を示します。

立方体の背景(全面)

 この例では立方体の全部の面にイメージファイルを貼り付けています。VRMLブラウザでビューポイントの位置を変えて各面がどのように見えるのか試してみてください。


#VRML V2.0 utf8
#background_t1.wrl

#背景   imagefile

Background { 
  frontUrl  "image/sh005.gif"  #赤煉瓦
  backUrl   "image/sh026.gif"  #白ブロック
  leftUrl   "image/sh022.gif"  #緑ブロック
  rightUrl  "image/sy013.gif"  #大理石
  topUrl    "image/se003.gif"  #空
  bottomUrl "image/sh189.gif"  #土
}

#視点
Viewpoint { description "front" position 0 0 0 }  
Viewpoint { description "right" position 0.0 0.0 0 orientation 0 -1 0 1.57 }
Viewpoint { description "back"  position 0.0 0.0 0 orientation 0 -1 0 3.14 }
Viewpoint { description "left"  position 0.0 0.0 0 orientation 0 -1 0 -1.57 }
Viewpoint { description "top" position 0.0 0.0 0 orientation -1 0 0  -1.57 }
Viewpoint { description "bottom" position 0.0 0.0 0 orientation -1 0 0  1.57 }

立方体の背景(全面) (クリックすると上の例がVRMLブラウザに表示されます)


立方体の背景(一部)

 この例では立方体の一部の面にイメージファイルを貼り付けています。VRMLブラウザでビューポイントの位置を変えて各面がどのように見えるのか試してみてください。


#VRML V2.0 utf8
#background_t2.wrl

#背景   imagefile と sky, ground

Background { 
  skyAngle [ 0.785  1.3  1.57  2.07 ]
  skyColor [ 0.6 0.6 1, 0.7 0.7 1, 0.8 0.8 1, 0.9 0.9 1, 1 1 1 ] 
  groundAngle [ 0.35 0.785 1.22  ]    #ground --> 1.22 (70°)
  groundColor [0.4 0.2 0.2, 0.4 0.3 0.3, 0.4 0.4 0.4, 0.4 0.5 0.5,0.4 0.6 0.6]
  backUrl   "image/sh026.gif"  #白ブロック
  leftUrl   "image/sh022.gif"  #緑ブロック
  rightUrl  "image/sy013.gif"  #大理石
}

#視点
Viewpoint { description "front" position 0 0 0 }  
Viewpoint { description "right" position 0.0 0.0 0 orientation 0 -1 0 1.57 }
Viewpoint { description "back"  position 0.0 0.0 0 orientation 0 -1 0 3.14 }
Viewpoint { description "left"  position 0.0 0.0 0 orientation 0 -1 0 -1.57 }
Viewpoint { description "top" position 0.0 0.0 0 orientation -1 0 0  -1.57 }
Viewpoint { description "bottom" position 0.0 0.0 0 orientation -1 0 0  1.57 }

立方体の背景(一部) (クリックすると上の例がVRMLブラウザに表示されます)