Advanced Uses of VRML2
![]()
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
$mimeType = $ENV{'CONTENT_TYPE'};
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$form{$name} = $value;
}
sub vrml2_Group_begin {
local($groupName) = @_;
print "Group{\n";
print "\tchildren [\n";
}
sub vrml2_Group_end {
print "\t]";
print "}\n";
}
sub vrml2_Box {
local ($boxname, $xs, $ys, $zs) =@_;
print <<"EOT";
Box {
size $xs $ys $zs
}
EOT
}
sub vrml2_Tet {
local($tetname, $height, $baseScale) = @_;
$vec3_height=&ret_vec3(0.0,$height,0.0);
$z_vec1=(0.707*$baseScale);
$x_vec2=(0.612*$baseScale);
$z_vec2=(0.354*$baseScale);
$vec3_base1=&ret_vec3(0.0,0.0,$z_vec1);
$vec3_base2=&ret_vec3($x_vec2, 0.0,"-$z_vec1");
$vec3_base3=&ret_vec3("-$x_vec2",0.0,"-$z_vec2");
print<<"EOT";
Shape {
geometry IndexedFaceSet {
coord Coordinate {
point [
$vec3_height,
$vec3_base1,
$vec3_base2,
$vec3_base3,
]
}
coordIndex [
0, 1, 2, -1,
0, 3, 1, -1,
0, 2, 3, -1,
1, 3, 2, -1,
]
solid FALSE
}
}
EOT
}
sub vrml2_Xform_begin {
local($XformName, $vec3_trans, $aa4_rotation, $vec3_scaleF, $aa4_scaleO, $vec3_center) = @_;
print "Transform {\n";
print "\ttranslation $vec3_trans\n";
print "\trotation $aa4_rotation\n";
print "\tscale $vec3_scaleF\n";
print "\tcenter $vec3_center\n";
print "\tchildren [\n";
}
sub vrml2_Xform_end {
print "\t]\n";
print "},\n";
}
Source
![]()
Clay Graham - (clay@sgi.com)
VRML Architect