-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperf_evaluation.html
More file actions
412 lines (365 loc) · 13.7 KB
/
perf_evaluation.html
File metadata and controls
412 lines (365 loc) · 13.7 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bookmarking – Euclidean Accuracy & Performance</title>
<!-- X3DOM runtime -->
<script src="https://www.x3dom.org/download/1.8.2/x3dom.js"></script>
<link rel="stylesheet" href="https://www.x3dom.org/download/1.8.2/x3dom.css" />
<style>
body {
text-align: center;
font-family: Arial, Helvetica, sans-serif;
margin: 0;
padding: 20px;
background: #f4f4f4;
}
x3d {
width: 900px;
height: 600px;
border: 2px solid #000;
margin: 0 auto 20px;
}
button {
margin: 5px;
padding: 10px 15px;
font-size: 14px;
cursor: pointer;
border: none;
border-radius: 5px;
background: #007bff;
color: #fff;
transition: background 0.3s;
}
button:hover {
background: #0056b3;
}
.controls {
position: absolute;
top: 95%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
max-width: 400px;
background: rgba(255,255,255,0.8);
padding: 15px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
z-index: 999;
}
textarea {
width: 300px;
height: 100px;
margin-top: 10px;
padding: 5px;
border: 1px solid #ccc;
border-radius: 5px;
font-family: monospace;
font-size: 12px;
resize: none;
}
#distanceContainer {
margin-top: 10px;
font-weight: bold;
color: #d9534f; /* bootstrap danger red */
}
/* modal styles (unchanged) */
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background: rgba(0,0,0,0.5);
}
.modal-content {
background: #fff;
margin: 10% auto;
padding: 20px;
border-radius: 10px;
width: 80%;
max-width: 600px;
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
position: relative;
}
.modal-content textarea {
width: 100%;
height: 300px;
font-family: monospace;
font-size: 13px;
padding: 10px;
}
.close-btn {
position: absolute;
top: 10px;
right: 15px;
color: #aaa;
font-size: 24px;
font-weight: bold;
cursor: pointer;
}
.close-btn:hover {
color: #000;
}
#thumbnailPreview,
#applyModalThumbnail {
display: block;
max-width: 300px;
margin-top: 10px;
border: 1px solid #ccc;
}
#applyModal .modal-content button {
width: 100px;
}
</style>
</head>
<body>
<h1 style="margin:20px 0;font-size:24px;color:#333">
X3D Bookmarking Example with Roanoke City Model
</h1>
<!-- 3-D SCENE -->
<x3d id="x3dElement">
<scene>
<WorldInfo title="Roanoke City Model"
info="Built 2025, (c) Virginia Tech"
ageRestriction="18"
license="CC-BY-4.0"></WorldInfo>
<!-- skybox -->
<Background backUrl="nz.png" bottomUrl="ny.png" frontUrl="pz.png"
leftUrl="nx.png" rightUrl="px.png" topUrl="py.png"></Background>
<!-- default viewpoint -->
<Viewpoint DEF="AnimatedViewpoint"
position="947.60547 358.48150 114.24887"
orientation="-0.12102 0.99012 0.07078 1.38605"
description="Animated Street View"></Viewpoint>
<!-- external model -->
<Inline url="./3d_file/test.x3d"></Inline>
<!-- ground -->
<Transform translation="0 270 0">
<Shape>
<Appearance>
<Material diffuseColor="0.5 0.5 0.5"></Material>
</Appearance>
<IndexedFaceSet coordIndex="0 1 2 3 -1" solid="false">
<Coordinate point="-5000 0 -5000 5000 0 -5000 5000 0 5000 -5000 0 5000"></Coordinate>
</IndexedFaceSet>
</Shape>
</Transform>
<!-- simple animation plumbing -->
<TimeSensor DEF="SceneTimer" loop="false"></TimeSensor>
<PositionInterpolator DEF="ScenePositionInterp"></PositionInterpolator>
<OrientationInterpolator DEF="SceneOrientationInterp"></OrientationInterpolator>
<ROUTE fromNode="SceneTimer" fromField="fraction_changed"
toNode="ScenePositionInterp" toField="set_fraction"></ROUTE>
<ROUTE fromNode="SceneTimer" fromField="fraction_changed"
toNode="SceneOrientationInterp" toField="set_fraction"></ROUTE>
<ROUTE fromNode="ScenePositionInterp" fromField="value_changed"
toNode="AnimatedViewpoint" toField="set_position"></ROUTE>
<ROUTE fromNode="SceneOrientationInterp" fromField="value_changed"
toNode="AnimatedViewpoint" toField="set_orientation"></ROUTE>
</scene>
</x3d>
<!-- UI -->
<div class="controls">
<button onclick="generateBookmark()">Generate Bookmark</button>
<button onclick="applyBookmark()">Apply Bookmark</button><br>
<textarea id="bookmarkData" placeholder="Bookmark JSON here…"></textarea>
<div id="distanceContainer">Distance Error: —</div>
</div>
<!-- performance readout -->
<div id="perfContainer" style="margin-top:8px;font-size:13px;color:#555">
Performance: —
</div>
<!-- modals (unchanged markup) -->
<div id="bookmarkModal" class="modal">
<div class="modal-content">
<span class="close-btn" onclick="closeModal()">×</span>
<h2>Generated Bookmark</h2>
<textarea readonly id="bookmarkModalText"></textarea>
<p id="copyStatus" style="color:green;margin-top:10px;font-weight:bold"></p>
<img id="thumbnailPreview" alt="Thumbnail Preview">
</div>
</div>
<div id="applyModal" class="modal">
<div class="modal-content">
<span class="close-btn" onclick="closeApplyModal()">×</span>
<h2>Preview Bookmark</h2>
<img id="applyModalThumbnail" alt="Bookmark thumbnail preview">
<div style="margin-top:20px">
<button onclick="confirmApply()">Apply</button>
<button onclick="closeApplyModal()">Cancel</button>
</div>
</div>
</div>
<script>
/* ───────────────────────── helpers ───────────────────────── */
function getRuntime() {
return document.getElementById("x3dElement").runtime;
}
// compute Euclidean distance and orientation difference
function showDistance(expectedPos, expectedOrient) {
const runtime = getRuntime();
const inv = runtime.viewMatrix().inverse();
// position error
const pos = inv.e3();
const dx = pos.x - expectedPos[0];
const dy = pos.y - expectedPos[1];
const dz = pos.z - expectedPos[2];
const d = Math.hypot(dx, dy, dz);
// orientation error
const currQ = new x3dom.fields.Quaternion();
currQ.setValue(inv);
const [, currAngle] = currQ.toAxisAngle();
const expAngle = expectedOrient[3];
let diff = Math.abs(currAngle - expAngle);
if (diff > Math.PI) diff = 2 * Math.PI - diff;
const angleDeg = diff * (180 / Math.PI);
document.getElementById("distanceContainer").textContent =
`Distance Error: ${d.toFixed(3)} m, Orientation Error: ${angleDeg.toFixed(2)}°`;
}
/* ───────────────────────── modal utils ───────────────────────── */
function closeModal() {
document.getElementById("bookmarkModal").style.display = "none";
document.getElementById("copyStatus").textContent = "";
}
function closeApplyModal() {
document.getElementById("applyModal").style.display = "none";
window._currentBookmark = null;
}
/* ───────────────────────── thumbnail helper ───────────────────────── */
function compressDataURI(dataURI, maxWidth = 300, quality = 0.7) {
return new Promise(res => {
const img = new Image();
img.onload = () => {
const scale = maxWidth / img.width;
const canvas = document.createElement("canvas");
canvas.width = maxWidth;
canvas.height = img.height * scale;
canvas.getContext("2d").drawImage(img, 0, 0, canvas.width, canvas.height);
res(canvas.toDataURL("image/jpeg", quality));
};
img.src = dataURI;
});
}
/* ───────────────────────── bookmark generation ───────────────────────── */
async function generateBookmark() {
const t0 = performance.now();
const runtime = getRuntime();
const vpMatrix = runtime.viewMatrix().inverse();
const posQuat = vpMatrix.e3();
const quat = new x3dom.fields.Quaternion();
quat.setValue(vpMatrix);
const [axis, angle] = quat.toAxisAngle();
const vp = runtime.viewpoint();
const fov = vp.getFieldOfView();
const zNear = vp.getNear();
const zFar = vp.getFar();
const navType = runtime.navigationType();
const navSpeed = runtime.speed();
const wi = document.querySelector("WorldInfo");
const sceneMeta = {
title: wi?.getAttribute("title") ?? "",
info: wi?.getAttribute("info") ?? "",
ageRestriction: wi?.getAttribute("ageRestriction") ?? "none",
licenses: wi?.getAttribute("license") ?? ""
};
const rawURI = runtime.getScreenshot();
const thumbnailURI = await compressDataURI(rawURI, 300, 0.7);
const bookmark = {
camera: {
position: [posQuat.x, posQuat.y, posQuat.z],
orientation: [axis.x, axis.y, axis.z, angle],
fieldOfView: fov,
zNear: zNear,
zFar: zFar
},
navigation: { type: navType, speed: navSpeed },
metadata: {
annotation: "Generated viewpoint",
timestamp: new Date().toISOString(),
author: "User",
application: "X3DOM Bookmarking v1.2",
thumbnail: thumbnailURI,
licenses: sceneMeta.licenses,
ageRestriction: sceneMeta.ageRestriction,
scene: { title: sceneMeta.title, info: sceneMeta.info }
}
};
const str = JSON.stringify(bookmark, null, 2);
const t1 = performance.now();
const size = new TextEncoder().encode(str).length;
document.getElementById("perfContainer").textContent =
`Generated in ${(t1 - t0).toFixed(1)} ms · ${size} bytes`;
document.getElementById("bookmarkData").value = str;
document.getElementById("bookmarkModalText").value = str;
document.getElementById("thumbnailPreview").src = thumbnailURI;
document.getElementById("bookmarkModal").style.display = "block";
navigator.clipboard.writeText(str)
.then(() => document.getElementById("copyStatus").textContent = "✅ Bookmark copied!")
.catch(() => document.getElementById("copyStatus").textContent = "⚠️ Copy failed.");
}
/* ───────────────────────── bookmark application ───────────────────────── */
function applyBookmark() {
const tParseStart = performance.now();
let bookmark;
try {
bookmark = JSON.parse(document.getElementById("bookmarkData").value);
} catch (e) {
console.error(e);
alert("Invalid bookmark data!");
return;
}
const tParseEnd = performance.now();
window._currentBookmark = bookmark;
window._parseTime = tParseEnd - tParseStart;
if (bookmark.metadata?.thumbnail) {
document.getElementById("applyModalThumbnail").src = bookmark.metadata.thumbnail;
}
document.getElementById("applyModal").style.display = "block";
}
function confirmApply() {
const tApplyStart = performance.now();
const bookmark = window._currentBookmark;
if (!bookmark) return closeApplyModal();
const runtime = getRuntime();
const cam = bookmark.camera;
// create a temporary viewpoint so we can bind to it
const vp = document.createElement("Viewpoint");
vp.setAttribute("position", cam.position.join(" "));
vp.setAttribute("orientation", cam.orientation.join(" "));
vp.setAttribute("fieldOfView", cam.fieldOfView);
vp.setAttribute("zNear", cam.zNear);
vp.setAttribute("zFar", cam.zFar);
document.querySelector("scene").appendChild(vp);
// wait one frame, bind, then measure
runtime.exitFrame = () => {
vp.setAttribute("bind", "true");
runtime.exitFrame = () => {};
setTimeout(() => {
showDistance(cam.position, cam.orientation);
const tApplyEnd = performance.now();
const tParse = window._parseTime?.toFixed(1);
const tBind = (tApplyEnd - tApplyStart).toFixed(1);
document.getElementById("perfContainer").textContent =
`Parsed in ${tParse} ms · Applied in ${tBind} ms`;
}, 0);
};
if (bookmark.navigation) {
runtime.navigationType(bookmark.navigation.type);
runtime.speed(bookmark.navigation.speed);
}
closeApplyModal();
alert("✅ Bookmark applied!");
}
/* ───────────────────────── global modal click-off ───────────────────────── */
window.onclick = e => {
if (e.target === document.getElementById("bookmarkModal")) closeModal();
if (e.target === document.getElementById("applyModal")) closeApplyModal();
};
</script>
</body>
</html>