-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
246 lines (218 loc) · 7.06 KB
/
test.html
File metadata and controls
246 lines (218 loc) · 7.06 KB
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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="./coi-serviceworker.js"></script>
<style>
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
.container {
display: inline-flex;
flex-wrap: wrap;
}
.stack-direction {
flex-direction: row;
}
.hori {
display: flex;
flex-direction: row;
justify-content: space-around;
flex-wrap: wrap;
}
.hide {
visibility: hidden;
}
main {
margin: 8px;
border: 1px solid black;
}
nav ul {
list-style-type: none;
padding: 0;
}
nav ul li {
margin-bottom: 8px;
}
nav ul li a {
display: block;
text-decoration: none;
color: #000000;
background-color: #C0C0C0;
padding: 5px 10px 5px 10px;
}
nav ul li a:hover {
background-color:#FFC13B;
}
label {
position: relative;
}
[type="radio"] {
position: absolute;
opacity: 0;
}
[type="radio"]+span {
padding: 8px 18px;
cursor: pointer;
border-radius: 5px;
margin: 2px;
}
[type="radio"]:not(:checked)+span {
border: 1px solid #dfdfd7;
background: #e9eae4;
}
[type="radio"]:not(:checked)+span:hover {
background: #eee;
}
[type="radio"]:checked+span {
background: #369ff4;
border-color: #369ff4;
color: #fff;
}
@media screen and (max-width: 800px) {
.stack-direction {
flex-direction: column;
}
ul > li {
display: inline-block;
}
nav, main {
}
}
</style>
</head>
<body>
<section class="container stack-direction">
<nav>
<p>Testing</p>
<ul>
<li id="triangle"><a href="#">Triangle</a></li>
<li id="figure"><a href="#">Figure</a></li>
<li id="pyramid"><a href="#">Pyramid</a></li>
<li id="pyramidTri"><a href="#">Pyramid(Tri)</a></li>
<li id="pyramidCreased"><a href="#">Pyramid Creased</a></li>
<li id="pyramidTriCreased"><a href="#">Pyramid(tri) Creased</a></li>
<li id="loopCubeSemi"><a href="#">Loop Cube Semisharp</a></li>
</ul>
</nav>
<main>
<div id="selectSubdivision" class="hori hide">
<div class="hori">
<label name="triSubd"><input type="radio" id="loop" name="triSubd" value="loop" checked><span>Loop</span></label>
<label name="triSubd"><input type="radio" id="butterfly" name="triSubd" value="mbfly"><span>MBFly</span></label>
<label id="cc"><input type="radio" checked><span>Catmull-Clark</span></label>
</div>
<div>
<label><input type="radio" id="subd0" name="subLevel" value="0" checked><span>0</span></label>
<label><input type="radio" id="subd1" name="subLevel" value="1"><span>1</span></label>
<label><input type="radio" id="subd2" name="subLevel" value="2"><span>2</span></label>
<label><input type="radio" id="subd3" name="subLevel" value="3"><span>3</span></label>
<label><input type="radio" id="subd4" name="subLevel" value="4"><span>4</span></label>
<label><input type="radio" id="subd5" name="subLevel" value="5"><span>5</span></label>
</div>
</div>
<canvas id="workspace" width="600" height="600"></canvas>
</main>
</section>
<footer>
<p id="geometry"></p>
<p id="performance"></p>
</footer>
</body>
<script type="module">
//import {subdivideCC, subdivideMB, subdivideLoop} from './workers/subdivide.js';
import {subdivideCC, subdivideMB, subdivideLoop} from './subdivide.js';
import {initMain, readFile, setRenderData} from './runner.js';
let subdivideFunc;
let level;
function showTriSubd(triFlag) {
document.getElementById("cc").style.display="none";
const elems = document.querySelectorAll('label[name="triSubd"]');
for (let elem of elems) {
elem.style.display="block";
}
level = 0;
subdivideFunc = subdivideLoop;
document.getElementById("loop").checked = true;
document.getElementById("subd0").checked = true;
}
function showCC() {
document.getElementById("cc").style.display="block";
const elems = document.querySelectorAll('label[name="triSubd"]');
for (let elem of elems) {
elem.style.display="none";
}
level = 0;
subdivideFunc = subdivideCC;
document.getElementById("subd0").checked = true;
}
const gl = document.getElementById("workspace").getContext("webgl2");
initMain(gl);
const log = document.getElementById("geometry");
const counter = document.getElementById("performance");
// select between loop/mbfly
let elems = document.querySelectorAll('input[name="triSubd"]');
for (let elem of elems) {
elem.addEventListener("change", function(evt){
if (this.value === "loop") {
subdivideFunc = subdivideLoop;
doSubdivision(level);
}
if (this.value === "mbfly") {
subdivideFunc = subdivideMB;
doSubdivision(level);
}
});
}
elems = document.querySelectorAll('input[name="subLevel"]');
for (let elem of elems) {
elem.addEventListener("change", function(evt){
let value = parseInt(this.value);
if (value >=0 && value < 6) {
level = value;
doSubdivision(level);
}
});
}
let source; // to be used for subdivision and rendering purpose
function doSubdivision(level) {
subdivideFunc(source, level).then(([subd, text])=> {
// now setRenderData
let start = Date.now();
setRenderData(subd);
text += "(computeRender: " + (Date.now()-start) + ")\n";
log.textContent = subd.stat();
counter.textContent = text;
});
}
function bindMenu(id, url, options, camera) {
let button = document.getElementById(id);
button.addEventListener("click", (ev)=>{
document.getElementById("selectSubdivision").classList.add("hide");
if (options.subd === "tri") { // triangle subdivision
showTriSubd(true);
} else { // polygon subdivision
showCC();
}
readFile(url, options, camera).then((subd)=>{
source = subd;
log.textContent = subd.stat();
document.getElementById("selectSubdivision").classList.remove("hide");
});
counter.textContent = "";
});
}
const tri = {tri: true, subd: "tri", zUp: true};
const cc = {tri: false, subd: "cc", zUp: true};
bindMenu("triangle", "./meshes/testing/triangle.obj", tri, {position: [0, 1, 3]});
bindMenu("figure", "./meshes/testing/figure.obj ", tri, {position: [0, 2, 10]});
bindMenu("pyramid", "meshes/testing/pyramid.obj", cc, {position: [0, 1, 6]});
bindMenu("pyramidTri", "./meshes/testing/pyramid_tri.obj", tri, {position: [0, 1, 6]});
bindMenu("pyramidCreased", "./meshes/testing/pyramid_creased.obj", cc, {position: [0, 1, 6]});
bindMenu("pyramidTriCreased", "./meshes/testing/pyramid_creased_tri.obj", tri, {position: [0, 1, 6]});
bindMenu("loopCubeSemi", "./meshes/testing/loop_cubes_semisharp.obj", tri, {position: [0, 3, 4]});
</script>
</html>