-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
209 lines (191 loc) · 6.5 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
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
html, body {
margin:0;
padding:0;
}
h4 {
margin: 0;
font-size: 1.1em;
text-shadow: 0 0 2px rgba(0, 0, 0, 0.3);
text-align: left;
margin-bottom: 3px;
margin-top: 3px;
border-bottom: 1px solid #ddd;
}
div.container {
position: relative;
width: 1000px;
}
canvas {
position: absolute;
background: black;
top: 0;
left: 300px;
width: 800px;
height: 600px;
-webkit-box-shadow: 0 0 10px #000;
-moz-box-shadow: 0 0 10px #000;
}
.controls {
position: absolute;
top:0;
left:0;
width: 200px;
height: 600px;
font-size: 0.8em;
}
ul.predefined-fn {
margin: 0;
padding: 0;
}
ul.predefined-fn code {
display: none;
}
ul.predefined-fn li {
display: block;
cursor: pointer;
margin: 1px;
background: #ccc;
border 1px solid #555;
font-weight: bold;
color: #fff;
padding: 3px;
}
.error {
background-color: #fcc;
}
</style>
<script id="shader-fs" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
varying vec4 vcolor;
varying vec3 lightWeighting;
void main(){
gl_FragColor = vec4(vcolor.rgb * lightWeighting, vcolor.a);
}
</script>
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 position;
attribute vec3 normal;
uniform vec4 color;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 normalMatrix;
uniform bool enableLighting;
uniform vec3 ambientColor;
uniform vec3 directionalColor;
uniform vec3 lightingDirection;
varying vec4 vcolor;
varying vec3 lightWeighting;
void main(void) {
if(!enableLighting) {
lightWeighting = vec3(1.0, 1.0, 1.0);
} else {
vec4 transformedNormal = normalMatrix * vec4(normal, 1.0);
float directionalLightWeighting = max(dot(transformedNormal.xyz, lightingDirection), 0.0);
lightWeighting = ambientColor + directionalColor * directionalLightWeighting;
}
vcolor = color;
gl_Position = projectionMatrix * viewMatrix * vec4( position, 1.0 );
}
</script>
<!-- Stuff pulled from ThreeJS -->
<script type="text/javascript" src="three.js/Three.js"></script>
<script type="text/javascript" src="sample2.js"> </script>
<script type="text/javascript" src="three.js/core/Vector3.js"></script>
<script type="text/javascript" src="three.js/core/Vector4.js"></script>
<script type="text/javascript" src="three.js/core/Matrix4.js"></script>
<script type="text/javascript" src="three.js/cameras/Camera.js"></script>
<!-- Model (Grid, Balls) Workers and WebGL methods -->
<script type="text/javascript" src="Grid.js"></script>
<script type="text/javascript" src="WebGLUtils.js"></script>
<script type="text/javascript" src="WorkerGroup.js"></script>
<!-- The Example -->
<script type="text/javascript" src="isosurface.js"></script>
</head>
<body onload="load();">
<div class="container">
<div class="controls">
<h4>Options</h4>
<table>
<tr>
<td>Enable time</td>
<td><input type="checkbox" id="enable-time" /></td>
</tr>
<tr>
<td>Auto rotate</td>
<td><input type="checkbox" id="auto-rotate" checked="checked" /></td>
</tr>
<tr>
<td>Isolevel</td>
<td>
<input type="number" id="isolevel" value="0.05" />
</td>
</tr>
<tr>
<td colspan="2">
<br /><br />
<h4>Predefined Functions</h4>
<ul class="predefined-fn">
<li data-isolevel="120">brain
<code>
x = Math.floor(x);
y = Math.floor(y);
z = Math.floor(z);
return sample[x][y][z];
</code>
</li>
<li data-isolevel="0">Gyroid
<code>
var cos = Math.cos,
sin = Math.sin,
abs = Math.abs,
r = x * x + y * y + z * z,
ti = abs(sin(t / 100000)) / 10 + 0.06,
v = ti * r;
return (cos(x / v) * sin(y / v) + cos(y / v) * sin(z / v) + cos(z / v) * sin(x / v) + 1.0) - 0.1 * (1 - 0.016 * (r - 10 / r));
</code>
</li>
<li data-isolevel="7">Metaballs
<code>
var cos = Math.cos,
sin = Math.sin,
abs = Math.abs,
ti = abs(sin(t / 2000)) / 1.5,
idx = [[1, 1, 1], [1, -1, 1], [-1, -1, 1], [-1, 1, 1], [1, 1, -1], [1, -1, -1], [-1, -1, -1]],
acum = 0;
for (var i = 0, l = idx.length; l > i; i++) {
var id = idx[i],
x0 = id[0] * ti,
y0 = id[1] * ti,
z0 = id[2] * ti;
acum += 1 / (((x - x0) * (x - x0) + (y - y0) * (y - y0) + (z - z0) * (z - z0)) || 1);
}
return acum;
</code>
</li>
</ul>
<br /><br />
<h4>fn (x, y, z, t?)</h4>
<textarea id="fn" rows="20" cols="25">
var cos = Math.cos,
sin = Math.sin,
sqrt = Math.sqrt,
r = 0.2,
R = 0.8,
val = sqrt( x * x + y * y + z * z );
return (R - val) * (R - val) + z * z;
</textarea>
</td>
</tr>
</table>
</div>
<canvas id="viz" width="800" height="600"></canvas>
</div>
</body>
</html>