多年前本人开始从事三维动画方面的学习,后学习了PHP,发现可以通过PHP动态生成VRML文档,有点类似于Generator动态生成Flash的方式。
由于VRML博大精深,这里只介绍一个简单的例子,还可以将各种VRML结点存入数据库中,这样的虚拟现实网页将……,爽!
下面是源程序。注意:在服务器上,要将让PHP处理wrl格式的文档,否则后果将是没有任何虚拟现实。本源程序直接存成wrl文件,在浏览器中要安装插件,可以到我的另一个主页上去下载:http://go.163.com/~sjtucaocao/
1 header("Content-type: application/x-vrml");$txt="#VRML V2.0 utf8
2
3DEF leftBox Transform
4{
5translation -5 0 0
6children
7[
8Shape
9{
10appearance Appearance
11{
12material Material
13{
14diffuseColor 1 0 0
15}
16}
17geometry Box{}
18}
19DEF SphereChild Shape
20{
21appearance Appearance
22{
23material Material
24{
25diffuseColor 1 0 1
26}
27}
28geometry Sphere
29{
30radius 1.2
31}
32}
33]
34}
35
36DEF rightBox Transform
37{
38translation 5 0 0
39children
40[
41Shape
42{
43appearance Appearance
44{
45material Material
46{
47diffuseColor 0 0 1
48}
49}
50geometry Box{}
51}
52]
53}
54
55DEF onoff Transform
56{
57translation 0 -1 0
58children
59[
60Shape
61{
62appearance Appearance
63{
64material Material
65{
66diffuseColor 0 1 0
67}
68}
69geometry Box{}
70}
71DEF TS TouchSensor{}
72]
73}
74
75DEF S Script
76{
77eventIn SFBool isActive
78eventOut MFNode child
79field MFNode testNode USE SphereChild
80url
81"javascript:
82function isActive(value)
83{
84if (value)
85{
86child=testNode;
87}
88}
89"
90}
91
92ROUTE TS.isActive TO S.isActive
93ROUTE S.child TO leftBox.removeChildren
94ROUTE S.child TO rightBox.addChildren";echo $txt;