-
Notifications
You must be signed in to change notification settings - Fork 0
/
jaaps_povray.pl
executable file
·829 lines (692 loc) · 28.1 KB
/
jaaps_povray.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(setsid);
use MIME::Lite;
use CGI;
use Math::Trig;
# Change to the working directory
chdir('/var/www/localhost/htdocs/render_data/') or
die 'Unable to change diretory: ', $?, "\n";
my $CUT_NUM = 8;
my $CUT_NUM_DISP = 5;
my $SESSID = get_session_id();
$SIG{CHLD} = "IGNORE";
my $mail_host = '127.0.0.1';
my $from_address = pack('H*', '5477697374792052656e64657265' .
'72203c7477697374795f72656e64657265' .
'72406272616e646f6e656e72696768742e6e65743e');
my $to_address; # will be filled in
my $cc_address; # unused
my $bcc_address = pack('H*', '7477697374795f72656e646572657' .
'2406272616e646f6e656e72696768742e6e6574');
my $subject = 'Twisty puzzle render job';
my $body;
#my $base_url = 'http://www.brandonenright.net/cgi-bin/jaaps_povray.pl';
my $base_url = 'http://127.0.0.1/cgi-bin/jaaps_povray.pl';
my @url_args;
my %replacements;
my $MAX_SHAPE_NUM = 65;
my $MAX_CUT_NUM = 46;
my $MAX_COLOR_NUM = 20;
# The shapes in order of appearance
my @shapes = (
{('num' => -1, 'name' => '-- Smooth Solids --')},
{('num' => 0, 'name' => 'Sphere')},
{('num' => -2, 'name' => '-- Platonic Solids --')},
{('num' => 1, 'name' => 'Tetrahedron')},
{('num' => 2, 'name' => 'Cube')},
{('num' => 3, 'name' => 'Octahedron')},
{('num' => 5, 'name' => 'Dodecahedron')},
{('num' => 6, 'name' => 'Icosahedron')},
{('num' => -3, 'name' => '-- Catalan Solids --')},
{('num' => 4, 'name' => 'Rhombic Dodecahedron')},
{('num' => 7, 'name' => 'Rhombic Triacontahedron')},
{('num' => 11, 'name' => 'Triakis Tetrahedron')},
{('num' => 12, 'name' => 'Tetrakis Hexahedron')},
{('num' => 8, 'name' => 'Triakis Octahedron')},
{('num' => 17, 'name' => 'Triakis Icosahedron')},
{('num' => 10, 'name' => 'Deltoidal Hexecontahedron')},
{('num' => 9, 'name' => 'Deltoidal Icositetrahedron')},
{('num' => 18, 'name' => 'Pentagonal Hexecontahedron (dextro)')},
{('num' => 19, 'name' => 'Pentagonal Hexecontahedron (laevo)')},
{('num' => 13, 'name' => 'Pentagonal Icositetrahedron (dextro)')},
{('num' => 14, 'name' => 'Pentagonal Icositetrahedron (laevo)')},
{('num' => 15, 'name' => 'Disdyakis Dodecahedron')},
{('num' => 20, 'name' => 'Disdyakis Triacontahedron')},
{('num' => 16, 'name' => 'Pentakis Dodecahedron')},
{('num' => -4, 'name' => '-- Dipyramids --')},
{('num' => 21, 'name' => 'Triangular Dipyramid')},
{('num' => 22, 'name' => 'Pentagonal Dipyramid')},
{('num' => 23, 'name' => 'Hexagonal Dipyramid')},
{('num' => 24, 'name' => 'Heptagonal Dipyramid')},
{('num' => 25, 'name' => 'Octagonal Dipyramid')},
{('num' => -5, 'name' => '-- Trapezohedra --')},
{('num' => 26, 'name' => 'Tetragonal Trapezohedron')},
{('num' => 27, 'name' => 'Pentagonal Trapezohedron')},
{('num' => 28, 'name' => 'Hexagonal Trapezohedron')},
{('num' => 29, 'name' => 'Heptagonal Trapezohedron')},
{('num' => 30, 'name' => 'Octagonal Trapezohedron')},
{('num' => -6, 'name' => '-- Prisms and Antiprisms --')},
{('num' => 56, 'name' => 'Triangular Prism (Square Sides)')},
{('num' => 57, 'name' => 'Pentagonal Prism (Square Sides)')},
{('num' => 58, 'name' => 'Hexagonal Prism (Square Sides)')},
{('num' => 59, 'name' => 'Heptagonal Prism (Square Sides)')},
{('num' => 60, 'name' => 'Octagonal Prism (Square Sides)')},
{('num' => 61, 'name' => 'Square Antiprism')},
{('num' => 62, 'name' => 'Pentagonal Antiprism')},
{('num' => 63, 'name' => 'Hexagonal Antiprism')},
{('num' => 64, 'name' => 'Heptagonal Antiprism')},
{('num' => 65, 'name' => 'Octagonal Antiprism')},
{('num' => 34, 'name' => 'Triangular Prism (Equidistant Faces)')},
{('num' => 35, 'name' => 'Pentagonal Prism (Equidistant Faces)')},
{('num' => 36, 'name' => 'Hexagonal Prism (Equidistant Faces)')},
{('num' => 37, 'name' => 'Heptagonal Prism (Equidistant Faces)')},
{('num' => 38, 'name' => 'Octagonal Prism (Equidistant Faces)')},
{('num' => -7, 'name' => '-- Archimedean Solids --')},
{('num' => 43, 'name' => 'Truncated Tetrahedron')},
{('num' => 41, 'name' => 'Cuboctahedron')},
{('num' => 45, 'name' => 'Truncated Cube')},
{('num' => 48, 'name' => 'Snub Cube (dextro)')},
{('num' => 49, 'name' => 'Snub Cube (laevo)')},
{('num' => 46, 'name' => 'Rhombicuboctahedron')},
{('num' => 44, 'name' => 'Truncated Octahedron')},
{('num' => 47, 'name' => 'Truncated Cuboctahedron')},
{('num' => 51, 'name' => 'Truncated Dodecahedron')},
{('num' => 42, 'name' => 'Icosidodecahedron')},
{('num' => 54, 'name' => 'Snub Dodecahedron (dextro)')},
{('num' => 55, 'name' => 'Snub Dodecahedron (laevo)')},
{('num' => 50, 'name' => 'Truncated Icosahedron')},
{('num' => 52, 'name' => 'Rhombicosidodecahedron')},
{('num' => 53, 'name' => 'Truncated Icosidodecahedron')},
{('num' => -8, 'name' => '-- Other Solids --')},
{('num' => 31, 'name' => 'Trapezo-Rhombic Dodecahedron')},
{('num' => 32, 'name' => 'Pseudo-Deltoidal Icositetrahedron')},
{('num' => 33, 'name' => 'Trapezo-Rhombic Triacontahedron')},
{('num' => 39, 'name' => 'Truncated Cube (Equidistant Faces)')},
{('num' => 40, 'name' => 'Truncated Dodecahedron (Equidistant Faces)')},
);
# The cuts in order of appearance
my @cuts = (
{('num' => -1, 'name' => '-- Platonic Geometries --')},
{('num' => 1, 'name' => 'Tetrahedron')},
{('num' => 41, 'name' => 'Tetrahedron (Corners)')},
{('num' => 2, 'name' => 'Cube')},
{('num' => 3, 'name' => 'Octahedron')},
{('num' => 5, 'name' => 'Dodecahedron')},
{('num' => 6, 'name' => 'Icosahedron')},
{('num' => -2, 'name' => '-- Catalan Geometries --')},
{('num' => 4, 'name' => 'Rhombic Dodecahedron')},
{('num' => 7, 'name' => 'Rhombic Triacontahedron')},
{('num' => 11, 'name' => 'Triakis Tetrahedron')},
{('num' => 12, 'name' => 'Tetrakis Hexahedron')},
{('num' => 8, 'name' => 'Triakis Octahedron')},
{('num' => 17, 'name' => 'Triakis Icosahedron')},
{('num' => 10, 'name' => 'Deltoidal Hexecontahedron')},
{('num' => 9, 'name' => 'Deltoidal Icositetrahedron')},
{('num' => 18, 'name' => 'Pentagonal Hexecontahedron (dextro)')},
{('num' => 19, 'name' => 'Pentagonal Hexecontahedron (laevo)')},
{('num' => 13, 'name' => 'Pentagonal Icositetrahedron (dextro)')},
{('num' => 14, 'name' => 'Pentagonal Icositetrahedron (laevo)')},
{('num' => 15, 'name' => 'Disdyakis Dodecahedron')},
{('num' => 20, 'name' => 'Disdyakis Triacontahedron')},
{('num' => 16, 'name' => 'Pentakis Dodecahedron')},
{('num' => -3, 'name' => '-- Dipyramidal Geometries --')},
{('num' => 21, 'name' => 'Triangular Dipyramid')},
{('num' => 22, 'name' => 'Pentagonal Dipyramid')},
{('num' => 23, 'name' => 'Hexagonal Dipyramid')},
{('num' => 24, 'name' => 'Heptagonal Dipyramid')},
{('num' => 25, 'name' => 'Octagonal Dipyramid')},
{('num' => -4, 'name' => '-- Trapezohedral Geometries --')},
{('num' => 26, 'name' => 'Tetragonal Trapezohedron')},
{('num' => 27, 'name' => 'Pentagonal Trapezohedron')},
{('num' => 28, 'name' => 'Hexagonal Trapezohedron')},
{('num' => 29, 'name' => 'Heptagonal Trapezohedron')},
{('num' => 30, 'name' => 'Octagonal Trapezohedron')},
{('num' => -5, 'name' => '-- Prismatic Geometries --')},
{('num' => 34, 'name' => 'Dihedral Cuts (Top & Bottom Faces)')},
{('num' => 35, 'name' => 'Triangular Prism (Side Faces)')},
{('num' => 36, 'name' => 'Square Prism (Side Faces)')},
{('num' => 37, 'name' => 'Pentagonal Prism (Side Faces)')},
{('num' => 38, 'name' => 'Hexagonal Prism (Side Faces)')},
{('num' => 39, 'name' => 'Heptagonal Prism (Side Faces)')},
{('num' => 40, 'name' => 'Octagonal Prism (Side Faces)')},
{('num' => 42, 'name' => 'Square Antiprism (Side Faces)')},
{('num' => 43, 'name' => 'Pentagonal Antiprism (Side Faces)')},
{('num' => 44, 'name' => 'Hexagonal Antiprism (Side Faces)')},
{('num' => 45, 'name' => 'Heptagonal Antiprism (Side Faces)')},
{('num' => 46, 'name' => 'Octagonal Antiprism (Side Faces)')},
{('num' => -6, 'name' => '-- Other Geometries --')},
{('num' => 31, 'name' => 'Trapezo-Rhombic Dodecahedron')},
{('num' => 32, 'name' => 'Pseudo-Deltoidal Icositetrahedron')},
{('num' => 33, 'name' => 'Trapezo-Rhombic Triacontahedron')},
);
my $cgi_var = new CGI;
print $cgi_var->header('text/html');
print $cgi_var->start_html('Twisty Renderer -- Jaap\'s Spheres in POV-Ray');
sub html_warn {
my $warnstr = shift;
print '<p><b><h3><font color="red">Warning: ', $warnstr,
'</font></h3></b></p>', "\n";
}
sub is_float_range {
my $f = shift;
my $min = shift;
my $max = shift;
return 0 unless ($f =~ m/^-?\d*\.?\d*$/);
return 0 unless ($f =~ m/\d/);
return 0 unless ($f >= $min);
return 0 unless ($f <= $max);
return 1;
}
sub is_int_range {
my $f = shift;
my $min = shift;
my $max = shift;
return 0 unless ($f =~ m/^\d+$/);
return 0 unless ($f >= $min);
return 0 unless ($f <= $max);
return 1;
}
########
if (defined $cgi_var->param('action_button')) {
if ($cgi_var->param('action_button') eq 'Reset') {
$cgi_var->delete_all();
}
}
print $cgi_var->start_form();
print $cgi_var->h3('Define Shape:');
print '<p><b>Base shape:</b> ',
$cgi_var->scrolling_list('base_shape',
[map {$_->{'num'}} @shapes],
['5'],
1, 0,
{map {$_->{'num'} => $_->{'name'}} @shapes},
undef), "\n";
print ' <b>Shape Material:</b> ',
$cgi_var->scrolling_list('usermat',
[0,
1,
2,
3,
4,
5],
['0'],
1, 0,
{0=>'White Clay',
1=>'Graphite',
2=>'Gold',
3=>'Pink Alabaster',
4=>'White Marble',
5=>'Polished Cherry Wood',
}, undef), "\n";
print '</p>', "\n";
print '<p>';
print $cgi_var->checkbox('crosssection', '', 'on',
'Slice shape in half for cross-sectional view'), "\n";
print '</p>', "\n";
print '<hr />', "\n";
print $cgi_var->h3('Define Scene:');
print '<p><b>Rotate Shape (x, y, z):</b> ',
$cgi_var->textfield('rot_x', '-20', 3, 5), ' ',
$cgi_var->textfield('rot_y', '25', 3, 5), ' ',
$cgi_var->textfield('rot_z', '-8', 3, 5), "\n";
print ' <b>Background:</b> ',
$cgi_var->scrolling_list('userbg',
[0,
1,
2],
['0'],
1, 0,
{0=>'Black',
1=>'White',
2=>'Sky'}, undef), "\n";
print '</p>', "\n";
print '<hr />', "\n";
print $cgi_var->h3('Define Cuts:');
print '<p><b>Cut Thickness:</b> ',
$cgi_var->scrolling_list('cut_width',
[1,
2,
3,
4,
5],
['3'],
1, 0,
{1=>'1 (Thin)',
2=>'2',
3=>'3 (Normal)',
4=>'4',
5=>'5 (Thick)'}, undef), "\n";
print '</p>', "\n";
for (my $i = 0; $i < $CUT_NUM_DISP; $i++) {
print '<p>--</p>', "\n";
print '<p><b>Cut #', $i, ':</b> ';
if ($i == 0) {
print $cgi_var->checkbox('use_' . $i, 'checked', 'on', 'Use'),
}
else {
print $cgi_var->checkbox('use_' . $i, '', 'on', 'Use'),
}
print ' ', $cgi_var->scrolling_list('sym_' . $i,
[map {$_->{'num'}} @cuts],
['5'],
1, 0,
{map {$_->{'num'} =>
$_->{'name'}} @cuts},
undef);
print ' at depth';
print ' ', $cgi_var->textfield('depth_' . $i, '200', 7, 7);
print ' ', $cgi_var->scrolling_list('type_' . $i,
[1,
2],
['1'],
1, 0,
{1=>'Jaap\'s [0 .. 300]',
2=>'Degrees from center [0 .. 90]'},
undef);
print ' with apex at';
print ' ', $cgi_var->textfield('apex_' . $i, '0', 5, 5);
print ' ', $cgi_var->scrolling_list('color_' . $i,
[0 .. $MAX_COLOR_NUM],
[$i],
1, 0,
{0=>'Red',
1=>'Green',
2=>'Blue',
3=>'Yellow',
4=>'BlueViolet',
5=>'Coral',
6=>'MediumTurquoise',
7=>'SpringGreen',
8=>'Magenta',
9=>'Maroon',
10=>'YellowGreen',
11=>'Orange',
12=>'OrangeRed',
13=>'SeaGreen',
14=>'SummerSky',
15=>'NeonBlue',
16=>'White',
17=>'Black',
18=>'MediumSlateBlue',
19=>'MediumSpringGreen',
20=>'Scarlet',
}, 0);
print '</p>', "\n";
print '<p><b>Rotate Cuts (x, y, z):</b> ',
$cgi_var->textfield('rotc_x_' . $i, '0', 6, 8), ' ',
$cgi_var->textfield('rotc_y_' . $i, '0', 6, 8), ' ',
$cgi_var->textfield('rotc_z_' . $i, '0', 6, 8),
' <b>Translate Cuts (x, y, z):</b>',
$cgi_var->textfield('transc_x_' . $i, '0', 6, 8), ' ',
$cgi_var->textfield('transc_y_' . $i, '0', 6, 8), ' ',
$cgi_var->textfield('transc_z_' . $i, '0', 6, 8),
'</p>', "\n";
}
print '<hr />', "\n";
print $cgi_var->checkbox('zoomcam', '', 'on',
'Zoom camera for better precision'), "\n";
print '<p>', "\n";
print $cgi_var->submit('action_button', 'Fast Preview');
print ' ';
print $cgi_var->submit('action_button', 'Medium Preview');
print ' ';
print $cgi_var->submit('action_button', 'Slow Preview');
print '</p>', "\n";
print '<p>', "\n";
print $cgi_var->submit('action_button', 'Submit High Resolution Render Job'),
' <b>Email address to receive results (required):</b> ',
$cgi_var->textfield('render_email', '[email protected]',
20, 50);
print '</p>', "\n";
print '<hr />', "\n";
print $cgi_var->submit('action_button', 'Reset');
print $cgi_var->end_form();
if (defined $cgi_var->param('action_button')) {
my $action = 'quick';
if ($cgi_var->param('action_button') eq 'Fast Preview') {
$action = 'fast';
}
if ($cgi_var->param('action_button') eq 'Medium Preview') {
$action = 'medium';
}
if ($cgi_var->param('action_button') eq 'Slow Preview') {
$action = 'slow';
}
if ($cgi_var->param('action_button') eq
'Submit High Resolution Render Job') {
$action = 'job';
}
# Parse the base shape settings
# base shape
unless ((defined scalar $cgi_var->param('base_shape')) &&
(is_int_range($cgi_var->param('base_shape'),
0, $MAX_SHAPE_NUM) == 1)) {
html_warn('Base shape malformed.');
$replacements{'TEXTSHAPE'} = 5;
}
else {
$replacements{'TEXTSHAPE'} = $cgi_var->param('base_shape');
push @url_args, 'base_shape=' . $cgi_var->param('base_shape');
}
# Material
unless ((defined scalar $cgi_var->param('usermat')) &&
(is_int_range($cgi_var->param('usermat'),
0, 5) == 1)) {
html_warn('Material malformed.');
$replacements{'TEXTUSERMAT'} = '0';
}
else {
$replacements{'TEXTUSERMAT'} = $cgi_var->param('usermat');
push @url_args, 'usermat=' . $cgi_var->param('usermat');
}
# Cross section view
if ((defined scalar $cgi_var->param('crosssection')) &&
($cgi_var->param('crosssection') eq 'on')) {
$replacements{'TEXTCROSSSECTION'} = '1';
push @url_args, 'crosssection=' . $cgi_var->param('crossesection');
}
else {
$replacements{'TEXTCROSSSECTION'} = '0';
}
foreach my $dir ('x', 'y', 'z') {
# rotate by direction $dir
unless ((defined scalar $cgi_var->param('rot_' . $dir)) &&
(is_float_range($cgi_var->param('rot_' . $dir),
-360, 360) == 1)) {
html_warn('Rotate ' . $dir . ' must be in the range [-360, 360]');
$replacements{'TEXTROT' . uc($dir)} = '0';
}
else {
$replacements{'TEXTROT' . uc($dir)} =
$cgi_var->param('rot_' . $dir);
push @url_args, 'rot_' . $dir . '=' .
$cgi_var->param('rot_' . $dir);
}
}
# Cut width
unless ((defined scalar $cgi_var->param('cut_width')) &&
(is_int_range($cgi_var->param('cut_width'),
1, 5) == 1)) {
html_warn('Cut thickness malformed.');
$replacements{'TEXTCUTWIDTH'} = '0.015';
}
else {
$replacements{'TEXTCUTWIDTH'} = 0.005 * $cgi_var->param('cut_width');
push @url_args, 'cut_width=' . $cgi_var->param('cut_width');
}
# Background
unless ((defined scalar $cgi_var->param('userbg')) &&
(is_int_range($cgi_var->param('userbg'),
0, 2) == 1)) {
html_warn('Background malformed.');
$replacements{'TEXTUSERBG'} = '0';
}
else {
$replacements{'TEXTUSERBG'} = $cgi_var->param('userbg');
push @url_args, 'userbg=' . $cgi_var->param('userbg');
}
# Camera
if ((defined scalar $cgi_var->param('zoomcam')) &&
($cgi_var->param('zoomcam') eq 'on')) {
$replacements{'TEXTZOOMCAM'} = '1';
push @url_args, 'zoomcam=' . $cgi_var->param('zoomcam');
}
else {
$replacements{'TEXTZOOMCAM'} = '0';
}
#print 'got action: ', $action, "\n";
for (my $i = 0; $i < $CUT_NUM; $i++) {
$replacements{'TEXT_CUT_' . $i} = '{1, -1, 0, 0, 0, 0, 0, 0, 0, 0}';
my $jdepth = 0;
if ((defined scalar $cgi_var->param('use_' . $i)) &&
($cgi_var->param('use_' . $i) eq 'on')) {
push @url_args, 'use_' . $i . '=' . $cgi_var->param('use_' . $i);
unless ((defined scalar $cgi_var->param('sym_' . $i)) &&
(is_int_range($cgi_var->param('sym_' . $i),
1, $MAX_CUT_NUM) == 1)) {
html_warn('Cut ' . $i . ' -- symmetry malformed.');
next;
}
push @url_args, 'sym_' . $i . '=' . $cgi_var->param('sym_' . $i);
unless ((defined scalar $cgi_var->param('type_' . $i)) &&
(is_int_range($cgi_var->param('type_' . $i),
1, 2) == 1)) {
html_warn('Cut Type ' . $i . ' -- type not defined.');
next;
}
push @url_args, 'type_' . $i . '=' . $cgi_var->param('type_' . $i);
if ($cgi_var->param('type_' . $i) == 1) {
unless ((defined scalar $cgi_var->param('depth_' . $i)) &&
(is_float_range($cgi_var->param('depth_' . $i),
0, 300) == 1)) {
html_warn('Cut ' . $i . ' -- depth malformed ' .
'(must be in the range [0, 300]).');
next;
}
$jdepth = $cgi_var->param('depth_' . $i);
}
if ($cgi_var->param('type_' . $i) == 2) {
unless ((defined scalar $cgi_var->param('depth_' . $i)) &&
(is_float_range($cgi_var->param('depth_' . $i),
0, 90) == 1)) {
html_warn('Cut ' . $i . ' -- depth angle malformed ' .
'(must be in the range [0, 90]).');
next;
}
$jdepth = (sin(deg2rad(90.0 - $cgi_var->param('depth_' . $i)))
* 300.0);
}
push @url_args, 'depth_' . $i . '=' .
$cgi_var->param('depth_' . $i);
unless ((defined scalar $cgi_var->param('apex_' . $i)) &&
(is_float_range($cgi_var->param('apex_' . $i),
-1000, 1000) == 1)) {
html_warn('Cut ' . $i . ' -- apex malformed ' .
'(must be in the range [-1000, 1000]).');
next;
}
push @url_args, 'apex_' . $i . '=' . $cgi_var->param('apex_' . $i);
unless ((defined scalar $cgi_var->param('color_' . $i)) &&
(is_int_range($cgi_var->param('color_' . $i),
0, $MAX_COLOR_NUM) == 1)) {
html_warn('Cut ' . $i . ' -- color malformed.');
next;
}
push @url_args, 'color_' . $i . '=' .
$cgi_var->param('color_' . $i);
foreach my $dir ('x', 'y', 'z') {
# cuts rotation per dir
unless ((defined scalar $cgi_var->param('rotc_' . $dir . '_' . $i)) &&
(is_float_range($cgi_var->param('rotc_' .
$dir . '_' . $i),
-360, 360) == 1)) {
html_warn('Cuts rotate ' . $dir .
' must be in the range [-360, 360]');
next;
}
push @url_args, 'rotc_' . $dir . '_' . $i . '=' .
$cgi_var->param('rotc_' . $dir . '_' . $i);
# Cuts translation per dir
unless ((defined scalar $cgi_var->param('transc_' . $dir .
'_' . $i)) &&
(is_float_range($cgi_var->param('transc_' .
$dir . '_' . $i),
-1, 1) == 1)) {
html_warn('Cuts translation ' . $dir .
' must be in the range [-1, 1]');
next;
}
push @url_args, 'transc_' . $dir . '_' . $i . '=' .
$cgi_var->param('transc_' . $dir . '_' . $i);
}
$replacements{'TEXT_CUT_' . $i} =
'{' . join(', ', (
$cgi_var->param('sym_' . $i),
$jdepth,
$cgi_var->param('apex_' . $i),
$cgi_var->param('color_' . $i),
$cgi_var->param('rotc_x_' . $i),
$cgi_var->param('rotc_y_' . $i),
$cgi_var->param('rotc_z_' . $i),
$cgi_var->param('transc_x_' . $i),
$cgi_var->param('transc_y_' . $i),
$cgi_var->param('transc_z_' . $i),
)) . '}';
} # end if use
} # end for each cut
my $render_template;
open(RENDERTEMPLATE, '<', 'render_template.txt') or
die 'Unable to open render template: ', $?, ' ', $!, "\n";
{
local $/ = undef;
$render_template = <RENDERTEMPLATE>;
}
close RENDERTEMPLATE;
# Do template replacements
foreach my $replacement (keys %replacements) {
$render_template =~ s/$replacement/$replacements{$replacement}/g;
}
open(POVOUT, '>', $SESSID . '.pov') or
die 'Unable to open pov out: ', $?, ' ', $!, "\n";
print POVOUT $render_template;
close POVOUT;
my $link = 0;
if ($action eq 'fast') {
print '<p><b>Fast preview:</b></p>', "\n";
my $cmd = `./render_fast.sh $SESSID`;
print '<img src="../render_data/fast_', $SESSID, '.png" />', "\n";
$link = 1;
}
elsif ($action eq 'medium') {
print '<p><b>Medium preview:</b></p>', "\n";
my $cmd = `./render_medium.sh $SESSID`;
print '<img src="../render_data/medium_', $SESSID, '.png" />', "\n";
$link = 1;
}
elsif ($action eq 'slow') {
print '<p><b>Slow preview:</b></p>', "\n";
my $cmd = `./render_slow.sh $SESSID`;
print '<img src="../render_data/slow_', $SESSID, '.png" />', "\n";
$link = 1;
}
elsif ($action eq 'job') {
unless ((defined scalar $cgi_var->param('render_email')) &&
($cgi_var->param('render_email') =~
m/^[\w\d._-]{1,40}@[\w\d.-]{3,80}$/) &&
($cgi_var->param('render_email') ne '[email protected]')) {
html_warn('You must provide a valid email address for ' .
'the render results to be sent to you.');
}
else {
$to_address = $cgi_var->param('render_email');
$subject .= ' ' . $SESSID;
if (fork() == 0) {
# I'm the child
close STDOUT;
close STDIN;
close STDERR;
my $sess_id = POSIX::setsid();
my $cmd = `./render_quality.sh $SESSID`;
$body = 'Your rendered image for session ' . $SESSID .
' is attached.' . "\n" . 'URL for configuration: ' .
$base_url . '?' . join('&', @url_args) . "\n";
my $msg;
### Create the multipart container
$msg = MIME::Lite->new(
'From' => $from_address,
'To' => $to_address,
'Bcc' => $bcc_address,
'Subject' => $subject,
'Type' => 'text/plain',
'Data' => $body
) or die 'Error creating multipart container: ', $!, "\n";
$msg->attach(
'Type' => 'image/png',
'Path' => '../render_data/job_' . $SESSID . '.png',
'Filename' => $SESSID . '.png',
'Disposition' => 'attachment'
) or die 'Error attaching image!', $!, "\n";
### Send the Message
MIME::Lite->send('smtp', $mail_host, 'Timeout'=>10);
$msg->send;
exit(0);
}
print '<p><b><font color="#0000ff"><h1>A render job has been ',
'submitted and the results will be emailed to you. ',
'Please allow at least 2 hours for the render to complete.',
'</h1></font></b></p>', "\n";
$link = 1;
}
}
if ($link == 1) {
print '<p><a href="', $base_url, '?', join('&', @url_args), '">',
'Link to current configuration.</a></p>', "\n";
}
}
print '<hr />', "\n";
print $cgi_var->h3('Examples:');
print '<p><a href="', $base_url, '?base_shape=2&sym_0=2&depth_0=100&apex_0=100">Rubik\'s Cube</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=2&sym_0=3&depth_0=0&apex_0=0">Skewb</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=5&sym_0=5&depth_0=186&apex_0=186">Megaminx</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=2&sym_0=4&depth_0=212&apex_0=212">Helicopter Cube</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=2&sym_0=4&depth_0=212.2&apex_0=100">Curvy Copter</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=2&sym_0=4&depth_0=212.2&apex_0=150&use_1=on&sym_1=4&depth_1=240&apex_1=160&color_1=0">Master Curvy Copter</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=2&sym_0=3&depth_0=79.5&apex_0=250">Dreidel Skewb</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=5&sym_0=5&depth_0=44.5&apex_0=280">Dreidel Pentultimate</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=2&cut_width=3&userbg=1&use_0=on&sym_0=2&type_0=1&depth_0=40&apex_0=40&color_0=0&use_1=on&sym_1=2&type_1=1&depth_1=150&apex_1=80&color_1=1&use_2=on&sym_2=2&type_2=1&depth_2=232&apex_2=0&color_2=2&use_3=on&sym_3=2&type_3=1&depth_3=250&apex_3=0&color_3=3">Carl Hoff\'s Real5x5x5</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=7&cut_width=3&userbg=0&use_0=on&sym_0=6&type_0=1&depth_0=15&apex_0=15&color_0=7">Master Chopasaurus Triacontahedron</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=2&cut_width=3&userbg=0&use_0=on&sym_0=2&type_0=1&depth_0=260&apex_0=450&color_0=6&use_1=on&sym_1=2&type_1=1&depth_1=254&apex_1=0&color_1=4">Gelatinbrain\'s 3.1.33</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=2&transc_x_0=0.15&transc_y_0=0.3&transc_z_0=0.45&cut_width=3&userbg=0&use_0=on&sym_0=2&type_0=1&depth_0=100&apex_0=100&color_0=0">Bump Cube</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=2&rotc_x_0=0&rotc_y_0=45&rotc_z_0=0&cut_width=3&userbg=0&use_0=on&sym_0=2&type_0=1&depth_0=100&apex_0=100&color_0=0">Fisher Cube</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=2&rotc_x_0=45&rotc_y_0=-19.3&rotc_z_0=45&cut_width=3&userbg=0&use_0=on&sym_0=2&type_0=1&depth_0=100&apex_0=100&color_0=0">Axis Cube</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=2&rotc_x_0=90&rotc_y_0=125.3&rotc_z_0=135&cut_width=3&userbg=0&use_0=on&sym_0=21&type_0=1&depth_0=160&apex_0=160&color_0=19">David Pitcher\'s Insanity Cubed</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=21&rot_x=-20&rot_y=25&rot_z=-8&cut_width=3&userbg=0&usermat=0&use_0=on&sym_0=21&type_0=1&depth_0=150&apex_0=150&color_0=18&rotc_x_0=0&transc_x_0=0&rotc_y_0=60&transc_y_0=0&rotc_z_0=0&transc_z_0=0&use_1=on&sym_1=35&type_1=1&depth_1=99&apex_1=99&color_1=18&rotc_x_1=0&transc_x_1=0&rotc_y_1=0&transc_y_1=0&rotc_z_1=0&transc_z_1=0">David Pitcher\'s Ultimate Insanity</a></p>', "\n";
print '<p><a href="', $base_url, '?base_shape=57&usermat=0&rot_x=-30&rot_y=25&rot_z=-16&cut_width=5&userbg=0&use_0=on&sym_0=22&type_0=1&depth_0=110&apex_0=50&color_0=15&rotc_x_0=0&transc_x_0=0&rotc_y_0=0&transc_y_0=0&rotc_z_0=0&transc_z_0=0">Greg\'s Pentex</a></p>', "\n";
print '<hr />', "\n";
print $cgi_var->h3('Information:');
print '<p>', "\n";
print 'The cuts are generated by a cone which allows for a range of ',
'curvy or planar cuts. The default (Jaap\'s) depth ranges from 0 (deep ',
'cut) to 300 (shallowest cut). The default cone apex is the center of ',
'of the puzzle (0) which creates curvy cuts whenever the depth isn\'t ',
'also set to 0. You get a planar cut whenever the depth and the apex ',
'are set to the same amount. The apex units are always Jaap\'s depth so ',
'if you use degrees for the cut it will be hard to achieve perfectly ',
'planar cuts without doing some math to figure out what depth the ',
'degrees work out to.', "\n";
print '</p>', "\n";
print '<img src="../render_data/render_cone_apex.png" />', "\n";
print '<p>', "\n";
print 'To prevent interference with the solid when the apex is outside of ',
'the puzzle (outside of the range [-300, 300]) clipping is used.', "\n";
print '</p>', "\n";
print '<img src="../render_data/render_cone_clipping.png" />', "\n";
print '<hr />', "\n";
print $cgi_var->h3('Credits:');
print '<p>Twisty Renderer is based on Jaap Scherphuis\'s ',
'<a href="http://www.jaapsch.net/puzzles/sphere.htm">',
'Sphere Symmetry Applet</a>. The POV-Ray code to do the rendering was ',
'originally written by ',
'<a href="http://twistypuzzles.com/forum/memberlist.php',
'?mode=viewprofile&u=6109">Stef-n</a>. Much of the analysis of which ',
'polyhedra to include was done by Matt Galla. ',
'Many of the polyhedra would not have been possible to impliment without ',
'David McCooey\'s <a href="http://dmccooey.com/polyhedra/">',
'Visual Polyhedra</a> site. ',
'The web interface is by Brandon Enright.</p>',
"\n";
print '<p>All bugs, inqueries, and complaints should be directed to Brandon ',
'at <twisty_renderer atsymbol brandonenright.net></p>', "\n";
print '<hr />', "\n";
print '<p>Session id: ', $SESSID, '</p>', "\n";
print $cgi_var->end_html();
sub get_session_id {
open(URANDOM, '<', '/dev/urandom') or
die 'Unable to open urandom: ', $?, "\n";
my $rand;
read(URANDOM, $rand, 16);
close URANDOM;
return unpack('H*', $rand);
}