File: threejs.rules

package info (click to toggle)
polymake 3.0r2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 19,752 kB
  • ctags: 30,928
  • sloc: cpp: 151,785; perl: 32,510; ansic: 3,597; java: 2,654; python: 278; makefile: 181; xml: 103; sh: 79
file content (177 lines) | stat: -rw-r--r-- 4,473 bytes parent folder | download
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
#  Copyright (c) 1997-2015
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
#  http://www.polymake.org
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-------------------------------------------------------------------------------


package ThreeJS;

CREDIT threejs
   Three.js is a lightweight cross-browser JavaScript library/API used to create and display animated 3D computer graphics on a Web browser.
   See http://github.com/mrdoob for the source code.

  
# webbrowser
custom $webbrowser;

CONFIGURE_OPT {
   find_program($webbrowser, qw( sensible-browser xdg-open chrome safari firefox ), { prompt => "the web browser" });
}


package ThreeJS::default;

# background color
custom @bgColor = (1, 1, 1);

# background opacity
custom $bgOpacity = 1;

# coordinates of the viewpoint
custom @view_point = (0, 0, 5);

# coordinates of a point on the view axis: default is the origin
custom @view_direction = (0, 0, 0);

# camera orientation: default is y-axis towards zenith
custom @view_up = (0, 1, 0);

# scaling factor
custom $scale = 1;

# camera field of view angle
custom $fov = 75;

# camera near plane
custom $near_plane = .1;

# camera far plane
custom $far_plane = 1000;



package ThreeJS::Viewer;

use ThreeJS;
use BackgroundViewer;
use Visual::Transformation;

# The default behavior is to produce an html output, then open it in a web browser.

use Polymake::Struct [ '@ISA' => 'SimpleViewer' ];

sub file_suffix { ".html" }

sub new {
   unless (defined($webbrowser)) {
      die <<'.';
requires web browser;
please specify the output File option or call reconfigure("common::threejs.rules");
.
   }
   my $self = &_new;
   $self->tempfile->descend_dir;
   $self
}

sub command {
   my ($self, $filename)=@_;

	my $polydir = $Polymake::InstallTop;

   my $outdir = $self->tempfile->dir;
	"cp -R -L $polydir/resources/threejs/js $outdir; $webbrowser $filename 1>/dev/null 2>&1";
}

sub new_drawing {
   my ($self, $title, $vis)=@_;
   $self->SUPER::new_drawing($title);
   if (defined (my $rep=$vis->representative)) {
      $self->graphics->transform=Visual::Transformation->get_transformation_matrix($rep);
   }
   $self;
}

sub append {
   my $self=shift;
   $self->graphics->append(@_);
}


# @category Visualization
# Create a three.js file.
label threejs

# The following are rarely used.
# Much more common are the methods in apps/{graph,polytope,...}/rules/threejs.rules

global_method threejs.geometry: draw(Visual::PointSet, @) {
   my ($self, $PointSet)=@_;
   $self->append(new ThreeJS::PointSet($PointSet));
}

global_method threejs.geometry: draw(Visual::Wire, @) {
   my ($self, $G)=@_;
   $self->append(new ThreeJS::Wire($G));
}

global_method threejs.geometry: draw(Visual::Polygon, @) {
   my ($self, $P)=@_;
   $self->append(new ThreeJS::Solid($P));
}

global_method threejs.geometry: draw(Visual::Polygons, @) {
   my ($self, $P)=@_;
   $self->append(new ThreeJS::Solid($P));
}


package ThreeJS::File::Writer;
import Visual::FileWriter;

sub file_suffix { ".html" }

sub new_drawing {
   my ($self, $title, $vis)=@_;
   if (defined (my $rep=$vis->representative)) {
      $self->graphics->transform=Visual::Transformation->get_transformation_matrix($rep);
   }
   $self->title=$title;
   $self;
}

sub DESTROY { }


package application;

# @Category Visualization
# Produce an html file with given visual objects.
# @param Visual::Object vis_obj object to display
#
# @option String File "filename" or "AUTO"
#
#  For the file name you can use any expression allowed for the ''open'' function,
#  including "-" for terminal output, "&HANDLE" for an already opened file handle,
#  or "| program" for a pipe.  Real file names are automatically completed with the ''.html'' suffix if needed.
#
#  An automatically generated file name is displayed in the verbose mode.
user_function threejs(Visual::Object+, { File => undef }) {
   visualize_explicit(@_, "ThreeJS");
}


# Local Variables:
# mode: perl
# cperl-indent-level:3
# End: