-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
226 lines (178 loc) · 5.75 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="./style/style.css">
<link href='https://fonts.googleapis.com/css?family=RobotoDraft:400,500,700,400italic' rel='stylesheet' type='text/css'>
<title>Simple OBJ Viewer</title>
</head>
<script id="vertex-shader" type="x-shader/x-vertex">
attribute vec4 vPosition;
attribute vec4 vNormal;
varying vec4 fColor;
uniform vec4 ambientProduct;
uniform vec4 diffuseProduct;
uniform vec4 specularProduct;
uniform float shininess;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
uniform mat4 projectionMatrix;
uniform vec4 lightPosition;
void main() {
vec3 pos = -(viewMatrix * vPosition).xyz;
// fixed light position
vec3 light = lightPosition.xyz;
vec3 L = normalize( light - pos );
vec3 E = normalize( -pos );
vec3 H = normalize( L + E );
// transform vertex normal into eye coordinates
vec3 N = normalize( (viewMatrix * vNormal).xyz );
// compute terms in the illumination equation
vec4 ambient = ambientProduct;
float Kd = max( dot(L, N), 0.0 );
vec4 diffuse = Kd * diffuseProduct;
float Ks = pow( max(dot(N, H), 0.0), shininess );
vec4 specular = Ks * specularProduct;
if ( dot(L, N) < 0.0 ) {
specular = vec4(0.0, 0.0, 0.0, 1.0);
}
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vPosition;
fColor = ambient + diffuse + specular;
fColor.a = 1.0;
}
</script>
<script id="fragment-shader" type="x-shader/x-fragment">
precision mediump float;
varying vec4 fColor;
void main()
{
gl_FragColor = fColor;
}
</script>
<script id="vertex-shader-frag" type="x-shader/x-vertex">
attribute vec4 vPosition;
attribute vec4 vNormal;
varying vec3 N, L, E;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
uniform mat4 projectionMatrix;
uniform vec4 lightPosition;
void main() {
vec3 pos = -(viewMatrix * vPosition).xyz;
vec3 light = lightPosition.xyz;
L = normalize( light - pos );
E = normalize( -pos );
N = normalize( (viewMatrix * vNormal).xyz );
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vPosition;
}
</script>
<script id="fragment-shader-frag" type="x-shader/x-fragment">
precision mediump float;
uniform vec4 ambientProduct;
uniform vec4 diffuseProduct;
uniform vec4 specularProduct;
uniform float shininess;
varying vec3 N, L, E;
void main() {
vec4 fColor;
vec3 H = normalize( L + E );
vec4 ambient = ambientProduct;
float Kd = max( dot(L, N), 0.1 );
vec4 diffuse = Kd * diffuseProduct;
float Ks = pow( max(dot(N, H), 0.0), shininess );
vec4 specular = Ks * specularProduct;
fColor = ambient + diffuse + specular;
fColor.a = 1.0;
gl_FragColor = fColor;
}
</script>
<script type="text/javascript" src="./libs/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="./libs/webgl-utils.js"></script>
<script type="text/javascript" src="./libs/initShaders.js"></script>
<script type="text/javascript" src="./libs/MV.js"></script>
<script type="text/javascript" src="./js/VirtualTrackBall.js"></script>
<script type="text/javascript" src="./js/Quaternion.js"></script>
<script type="text/javascript" src="./js/Scene.js"></script>
<script type="text/javascript" src="./js/Manipulator.js"></script>
<script type="text/javascript" src="obj-reader.js"></script>
<script type="text/javascript" src="obj-viewer.js"></script>
<body>
<div class="overlay"></div>
<div id="header">
<span class="title">MAC0420-5744</span>
<span class="sub-title">Computer Graphics</span>
<span class="info">Institute of Mathematics and Statistics - University of Sao Paulo <a href="https://www.ime.usp.br/en" target="_blank">>></a></span>
</div>
<div id="sidebar">
<span id="logo"><img src="./style/img/logo.png"></img></span>
<nav>
<dl>
<dt>
<h4>FILE</h4>
<span class="btn-group">
<input type="file" id="files" name="files[]" accept=".obj,"></input>
<button class="btn" id="btn-load-file">Load OBJ file...</button>
<div id="obj-list-container">
<ul id="exp-obj-list"></ul>
</div>
</span>
</dt>
<dt>
<h4>SHADER</h4>
<span class="btn-group">
<button class="btn active" id="shading-vertex">Vertex</button>
<button class="btn" id="shading-fragment">Fragment</button>
</span>
</dt>
<dt>
<h4>MESH</h4>
<span class="btn-group">
<button class="btn active" id="shading-flat">Flat</button>
<button class="btn" id="shading-smooth">Smooth</button>
</span>
</dt>
<dt style="display: none;">
<h4>DRAW</h4>
<span class="btn-group">
<button class="btn active" id="btn-triangles">Triangles</button>
<button class="btn" id="btn-lines">Lines</button>
</span>
</dt>
</dl>
</nav>
</div>
<div id="main">
<canvas id="gl-canvas" tabindex="1">
Oops ... your browser doesn't support the HTML5 canvas element
</canvas>
<div id="manipulator" class="floating">
<span class="title">Manipulator</span>
<div id="m-content-none" class="man-content">
<span class="m-type">NONE</span>
<div>press T to translate, S to scale, R to rotate</div>
</div>
<div id="m-content-rotate" class="man-content">
<span class="m-type">ROTATE</span>
<div>
<div class="m-offset"></div>
<div>press X, Y, or Z to select an axis</div>
</div>
</div>
<div id="m-content-translate" class="man-content">
<span class="m-type">TRANSLATE</span>
<div>
<div class="m-offset"></div>
<div>press X, Y, or Z to select an axis</div>
</div>
</div>
<div id="m-content-scale" class="man-content">
<span class="m-type">SCALE</span>
<div>
<div class="m-offset"></div>
<div>press X, Y, or Z to select an axis</div>
</div>
</div>
</div>
</div>
</body>
</html>