📄 ch21.htm
字号:
VRML editors also offer great tools with which you can create
your own worlds. Several tools are available for UNIX and Windows
NT systems. Most of them let you create these worlds with far
more ease than manually edited scripts will. The following tools
are available from the commercial sector:
<UL>
<LI>Ez3d 2.0 from Radiance Software, 1726 Francisco St., Berkeley,
CA 94703. The Ez3d package lets you create VRML 1.0 worlds with
an interactive editor. Support for VRML 2.0 is also listed at
their Web site at <TT><A HREF="http://www.radiance.com/~radiance" tppabs="http://www.radiance.com/~radiance">http://www.radiance.com/~radiance</A></TT>.
<LI>Paragraph home builder by Paragraph International. Their Web
site is <TT><A HREF="http://www.paragraph.com/" tppabs="http://www.paragraph.com/">http://www.paragraph.com</A></TT>.
They offer two ways to create worlds: one using their proprietary
Home Space environment editor and the other by using a VRML plug-in
for Netscape.
<LI><FONT COLOR=#000000>The </FONT>San Diego Supercomputing Center
(SDSC) offers a set of tools (including source code) for VRML
viewers and file creators. Check their web site at <TT><A HREF="http://www.sdsc.edu/EnablingTech/Visualization/vrml" tppabs="http://www.sdsc.edu/EnablingTech/Visualization/vrml">http://www.sdsc.edu/EnablingTech/Visualization/vrml</A></TT>.
<LI><FONT COLOR=#000000>The </FONT>Virtual World Factory from
Aeral systems uses a form-based tool to build VRML worlds. Look
at <TT><A HREF="http://www.aereal.com/" tppabs="http://www.aereal.com/">http://www.aereal.com/</A></TT>
for more information.
</UL>
<H2><A NAME="InsidetheVRMLpmPackage"><B><FONT SIZE=5 COLOR=#FF0000>Inside
the </FONT></B><TT><B><FONT SIZE=5 COLOR=#FF0000 FACE="Courier">VRML.pm</FONT></B></TT><B><FONT SIZE=5 COLOR=#FF0000>
Package</FONT></B></A></H2>
<P>
Let's take a look at how the <TT><FONT FACE="Courier">VRML.pm</FONT></TT>
library is structured. Part of the main file, <TT><FONT FACE="Courier">VRML.pm</FONT></TT>,
is shown in Listing 21.8. Shape nodes are listed in separate files
in the <TT><FONT FACE="Courier">VRML</FONT></TT> subdirectory.
The listing for the <TT><FONT FACE="Courier">Cube.pm</FONT></TT>
file is shown in Listing 21.9. Similar files exist for the <TT><FONT FACE="Courier">Cylinder</FONT></TT>,
<TT><FONT FACE="Courier">Sphere</FONT></TT>, and <TT><FONT FACE="Courier">Cone</FONT></TT>
shapes. The project is still in its infancy and has to be developed
further; however, you have enough here to construct your module
and customize it for your needs.
<HR>
<BLOCKQUOTE>
<B>Listing 21.8. The </B><TT><B><FONT FACE="Courier">VRML.pm</FONT></B></TT><B>
file.<BR>
</B>
</BLOCKQUOTE>
<BLOCKQUOTE>
<TT><FONT FACE="Courier"> 1 package VRML;<BR>
2<BR>
3 require Exporter;<BR>
4 @ISA = (Exporter);<BR>
5<BR>
6 @EXPORT = qw(new,startHeader,<BR>
7 startSeparator,
stopSeparator,<BR>
8 defineMaterial,
startMaterial, stopMaterial,<BR>
9 defineTransform,
startTransform, stopTransform,<BR>
10 diffuseColor,
<BR>
11 definePerspectiveCamera,
<BR>
12 setPointLight,
<BR>
13 putCube,
putCone, putCylinder);<BR>
14 # ----------------------------------------------------------------
<BR>
15 # Internal functions <BR>
16 # ----------------------------------------------------------------
<BR>
17 sub makeNode {<BR>
18 my
($this,$name,$value) = @_;<BR>
19 my
$j;<BR>
20 print
"\n $name {";<BR>
21 foreach
$j (@$value) { print " $j"; }<BR>
22 print
"} # End $name \n";<BR>
23 }
<BR>
24<BR>
25 # ----------------------------------------------------------------
<BR>
26 # Exported functions<BR>
27 # ----------------------------------------------------------------
<BR>
28 sub new {<BR>
29 my
$this = shift;<BR>
30 my
$class = ref($this) || $this;<BR>
31 my
$self = {};<BR>
32 bless
$self, $class;<BR>
33 }<BR>
34<BR>
35 sub startHeader {<BR>
36 my
$this = shift;<BR>
37 print
"#VRML V1.0 ascii\n";<BR>
38 print
"#\n# Created by VRML.pm flag\n#\n";<BR>
39 }<BR>
40<BR>
41 sub startSeparator {<BR>
42 print
"\n Separator {";<BR>
43 }<BR>
44<BR>
45 sub stopSeparator {<BR>
46 print
"\n } # End Separator \n";<BR>
47 }<BR>
48<BR>
49 #<BR>
50 # The delimiters for Material type.<BR>
51 #<BR>
52<BR>
53 sub defineMaterial {<BR>
54 my
$this = shift;<BR>
55 my
%parm = @_;<BR>
56 my
$key, $value, $j;<BR>
57 print
"\n Material {";<BR>
58 while
(($key,$value) = each(%parm)) {<BR>
59 if
(($key eq "ambientColor") ||<BR>
60 ($key eq "diffuseColor") ||<BR>
61 ($key
eq "specularColor") ||<BR>
62 ($key
eq "emmissiveColor") ||<BR>
63 ($key
eq "shininess") ||<BR>
64 ($key
eq "transparency")) {<BR>
65 print
"\n $key";<BR>
66 foreach
$j (@$value) {print " $j"; }<BR>
67 }
# end of if clause<BR>
68 }
# end of while loop<BR>
69 print
"\n} # End Material";<BR>
70 }<BR>
71<BR>
72 sub startMaterial {<BR>
73 print
"\n Material {";<BR>
74 }<BR>
75 sub stopMaterial {<BR>
76 print
"\n } # End Material \n";<BR>
77 }<BR>
78<BR>
79 #<BR>
80 # Perspective Camera<BR>
81 #<BR>
82 sub definePerspectiveCamera {<BR>
83 my
$this = shift;<BR>
84 my
%parm = @_;<BR>
85 my
$key, $value, $j;<BR>
86 print
"\n PerspectiveCamera {";<BR>
87 while
(($key,$value) = each(%parm)) {<BR>
88 if
(($key eq "position") ||<BR>
89 ($key
eq "orientation") ||<BR>
90 ($key
eq "focalDistance") ||<BR>
91 ($key
eq "heightAngle")) {<BR>
92<BR>
93 print
"\n $key";<BR>
94 foreach
$j (@$value) {print " $j"; }<BR>
95<BR>
96 }
<BR>
97 }
<BR>
98 print
"\n } # End PerspectiveCamera";<BR>
99 }<BR>
100<BR>
101 #<BR>
102 # This subroutine prints out the values for the "transform"
node.<BR>
103 #<BR>
104 sub stopTransform {<BR>
105 print
"\n } # End Transform";<BR>
106 }<BR>
107 sub startTransform {<BR>
108 print
"\n Transform {";<BR>
109 }<BR>
110 sub defineTransform {<BR>
111 my $this
= shift;<BR>
112 my
%parm = @_;<BR>
113 my
$key, $value, $j;<BR>
114 print
"\nTransform {";<BR>
115 while
(($key,$value) = each(%parm)) {<BR>
116 if
(($key eq "translation") ||<BR>
117 ($key
eq "rotation") ||<BR>
118 ($key
eq "scaleFactor") ||<BR>
119 ($key
eq "scaleOrientation") ||<BR>
120 ($key
eq "center")) {<BR>
121 print
"\n $key";<BR>
122 foreach
$j (@$value) {print " $j"; }<BR>
123 }
<BR>
124 }
<BR>
125 print
"\n } # End Transform";<BR>
126 }
<BR>
127<BR>
128 sub setPointLight {<BR>
129 my $this
= shift;<BR>
130 my
%parm = @_;<BR>
131 my
$key, $value, $j;<BR>
132 print
"\nPointLight {";<BR>
133 while
(($key,$value) = each(%parm)) {<BR>
134 if
(($key eq "intensity") ||<BR>
135 ($key
eq "on")) {<BR>
136 print
"\n $key $value";<BR>
137  
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -