#!/usr/local/bin/perl # VRML-Editor # A simple forms-based VRML editor implemented with HTML and Perl # cgi-lib.pl from Chapter 27 require("/usr/local/sources/cgi-lib.pl"); # function from cgi-lib.pl to unescape and extract name-value pairs # from form data &ReadParse; # Now return a VRML document print "Content-type: x-world/x-vrml\n\n"; print "#VRML V1.0 ascii\n\n"; # access settings for each object for ($count=1; $count<4; $count++) { $radius = $in{"radius$count"}; if ($radius>0) { # generate VRML for a separator node to contain the shape print "DEF shape$count Separator \{\n"; # add a transform node if overlap mode is off if (($in{'Overlap'} ne "On") && ($count>1)) { transform($in{'transform'}+($radius*4)); } # now build the specified shape print " Material \{emissiveColor 1 1 1 \}\n"; print " $in{\"shape$count\"} "; if ($in{"shape$count"} eq "Sphere") { print "\{ radius $radius \}\n\}\n"; } else { print "\{ radius $radius height $in{\"height$count\"}\}\n\}\n"; } } } exit 0; sub transform { # apply a tranform node to each shape # move the shapes four radii plus distance specified by user local($distance)=pop(@_); print "Transform \{ translation $distance $distance $distance \}\n"; }