由于vrml博大精深,这里只介绍一个简单的例子,还可以将各种vrml结点存入数据库中,下面是源程序。注意:在服务器上,要将让php处理wrl格式的文档,否则后果将是没有任何虚拟现实。
<?php header("content-type: application/x-vrml");$txt="#vrml v2.0 utf8
def leftbox transform
{
translation -5 0 0
children
[
shape
{
appearance appearance
{
material material
{
diffusecolor 1 0 0
}
}
geometry box{}
}
def spherechild shape
{
appearance appearance
{
material material
{
diffusecolor 1 0 1
}
}
geometry sphere
{
radius 1.2
}
}
]
}
def rightbox transform
{
translation 5 0 0
children
[
shape
{
appearance appearance
{
material material
{
diffusecolor 0 0 1
}
}
geometry box{}
}
]
}
def onoff transform
{
translation 0 -1 0
children
[
shape
{
appearance appearance
{
material material
{
diffusecolor 0 1 0
}
}
geometry box{}
}
def ts touchsensor{}
]
}
def s script
{
eventin sfbool isactive
eventout mfnode child
field mfnode testnode use spherechild
url
"javascript:
function isactive(value)
{
if (value)
{
child=testnode;
}
}
"
}
route ts.isactive to s.isactive
route s.child to leftbox.removechildren
route s.child to rightbox.addchildren";echo $txt;
?>