-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.html
372 lines (303 loc) · 13.9 KB
/
default.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
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
<!doctype html>
<html lang="en">
<head>
<title>Test CARCAS model viewer</title>
<meta charset="utf-8">
<meta name="description" content="Testing new features for the CARCAS model viewer.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link type="text/css" href="./styles.css" rel="stylesheet"/>
<!-- OPTIONAL: The :focus-visible polyfill removes the focus ring for some input types -->
<!-- <script src="https://unpkg.com/[email protected]/dist/focus-visible.js" defer></script> -->
</head>
<body>
<style>
#controls {
position: absolute;
top: 16px;
left: 16px;
max-width: unset;
transform: unset;
pointer-events: auto;
}
.dot{
display: block;
width: 12px;
height: 12px;
border-radius: 50%;
border: none;
box-sizing: border-box;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
background: #fff;
pointer-events: none;
--min-hotspot-opacity: 0;
}
.dim{
background: #fff;
border-radius: 4px;
border: none;
box-sizing: border-box;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
color: rgba(0, 0, 0, 0.8);
display: block;
font-family: Futura, Helvetica Neue, sans-serif;
font-size: 18px;
font-weight: 700;
max-width: 128px;
overflow-wrap: break-word;
padding: 0.5em 1em;
position: absolute;
width: max-content;
height: max-content;
transform: translate3d(-50%, -50%, 0);
pointer-events: none;
--min-hotspot-opacity: 0;
}
.dimensionLineContainer{
pointer-events: none;
display: block;
}
.dimensionLine{
stroke: #16a5e6;
stroke-width: 2;
stroke-dasharray: 2;
}
.show{
--min-hotspot-opacity: 1;
}
.hide{
display: none;
}
/* This keeps child nodes hidden while the element loads */
:not(:defined) > * {
display: none;
}
</style>
<!-- <model-viewer> HTML element -->
<!-- can't tell if bounds="tight" does anything -->
<model-viewer id="dimension-demo"
ar ar-modes="webxr scene-viewer quick-look"
ar-scale="fixed"
min-camera-orbit="-180deg 0deg auto"
max-camera-orbit="180deg 180deg auto"
shadow-intensity="1"
camera-controls touch-action="pan-y"
src="../sheep/sheep_mm.glb"
alt="A 3D model of a sheep."
environment-image="neutral"
poster="../sheep/poster.webp"
bounds="tight">
<!-- <model-viewer bounds="tight" id="dimension-demo" src="lizard.glb" ar ar-modes="webxr scene-viewer quick-look" camera-controls environment-image="neutral" poster="poster.webp" shadow-intensity="1"> -->
<div class="progress-bar hide" slot="progress-bar">
<div class="update-bar"></div>
</div>
<button slot="ar-button" id="ar-button">
View in your space
</button>
<div id="ar-prompt">
<img src="ar_hand_prompt.png">
</div>
<!-- Place hotstops on some corners of the viewport
as endpoints for dimension lines.
Also place midpoints for dimension labels as hotspots. -->
<button slot="hotspot-dot+X-Y+Z" class="dot" data-position="1 -1 1" data-normal="1 0 0"></button>
<button slot="hotspot-dim+X-Y" class="dim" data-position="1 -1 0" data-normal="1 0 0"></button>
<button slot="hotspot-dot+X-Y-Z" class="dot" data-position="1 -1 -1" data-normal="1 0 0"></button>
<button slot="hotspot-dim+X-Z" class="dim" data-position="1 0 -1" data-normal="1 0 0"></button>
<button slot="hotspot-dot+X+Y-Z" class="dot" data-position="1 1 -1" data-normal="0 1 0"></button>
<button slot="hotspot-dim+Y-Z" class="dim" data-position="0 1 -1" data-normal="0 1 0"></button>
<button slot="hotspot-dim-Y+Z" class="dim" data-position="0 -1 1" data-normal="0 -1 0"></button>
<button slot="hotspot-dot-X+Y-Z" class="dot" data-position="-1 1 -1" data-normal="0 1 0"></button>
<button slot="hotspot-dim-X-Z" class="dim" data-position="-1 0 -1" data-normal="-1 0 0"></button>
<button slot="hotspot-dot-X-Y-Z" class="dot" data-position="-1 -1 -1" data-normal="-1 0 0"></button>
<button slot="hotspot-dim-X-Y" class="dim" data-position="-1 -1 0" data-normal="-1 0 0"></button>
<button slot="hotspot-dot-X-Y+Z" class="dot" data-position="-1 -1 1" data-normal="-1 0 0"></button>
<!-- Create the six dimension lines that we will draw (only 3 at a time) -->
<svg id="dimLines" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" class="dimensionLineContainer">
<line class="dimensionLine"></line>
<line class="dimensionLine"></line>
<line class="dimensionLine"></line>
<line class="dimensionLine"></line>
<line class="dimensionLine"></line>
<line class="dimensionLine"></line>
</svg>
<div id="controls" class="dim">
<!-- Drop down menu for model file. Notice ../ allows you to move up a directory. -->
<label for="src">Animal:</label>
<select id="src">
<option value="../sheep/sheep_mm.glb">Sheep</option>
<option value="../horse/horse_mm.glb">Horse</option>
<option value="../goat/goat_mm.glb">Goat</option>
</select><br>
<!-- Radio button for cms to inches -->
<input type="radio" id="cms" name="user-units" value="cms" checked>
<label for="cms">Centimeters</label>
<input type="radio" id="inches" name="user-units" value="inches">
<label for="inches">Inches</label><br>
<!-- Checkbox for showing dimensions -->
<label for="show-dimensions">Show Dimensions:</label>
<input id="show-dimensions" type="checkbox" checked>
</div>
</model-viewer>
<script type="module">
const modelViewer = document.querySelector('#dimension-demo');
modelViewer.querySelector('#src').addEventListener('input', (event) => {
modelViewer.src = event.target.value;
});
// Only show dimensions if box is checked
const checkbox = modelViewer.querySelector('#show-dimensions');
function setVisibility(element) {
if (checkbox.checked) {
element.classList.remove('hide');
} else {
element.classList.add('hide');
}
}
checkbox.addEventListener('change', () => {
setVisibility(modelViewer.querySelector('#dimLines'));
modelViewer.querySelectorAll('button').forEach((hotspot) => {
setVisibility(hotspot);
});
});
// Give each line a start and end point,
// Use the midpoint to check for visibility
// update svg
function drawLine(svgLine, dotHotspot1, dotHotspot2, dimensionHotspot) {
if (dotHotspot1 && dotHotspot2) {
svgLine.setAttribute('x1', dotHotspot1.canvasPosition.x);
svgLine.setAttribute('y1', dotHotspot1.canvasPosition.y);
svgLine.setAttribute('x2', dotHotspot2.canvasPosition.x);
svgLine.setAttribute('y2', dotHotspot2.canvasPosition.y);
// use provided optional hotspot to tie visibility of this svg line to
if (dimensionHotspot && !dimensionHotspot.facingCamera) {
svgLine.classList.add('hide');
}
else {
svgLine.classList.remove('hide');
}
}
}
const dimLines = modelViewer.querySelectorAll('line');
const renderSVG = () => {
drawLine(dimLines[0], modelViewer.queryHotspot('hotspot-dot+X-Y+Z'), modelViewer.queryHotspot('hotspot-dot+X-Y-Z'), modelViewer.queryHotspot('hotspot-dim+X-Y'));
drawLine(dimLines[1], modelViewer.queryHotspot('hotspot-dot+X-Y-Z'), modelViewer.queryHotspot('hotspot-dot+X+Y-Z'), modelViewer.queryHotspot('hotspot-dim+X-Z'));
// drawLine(dimLines[2], modelViewer.queryHotspot('hotspot-dot+X+Y-Z'), modelViewer.queryHotspot('hotspot-dot-X+Y-Z')); // always visible
drawLine(dimLines[2], modelViewer.queryHotspot('hotspot-dot+X+Y-Z'), modelViewer.queryHotspot('hotspot-dot-X+Y-Z'), modelViewer.queryHotspot('hotspot-dim+Y-Z'));
drawLine(dimLines[3], modelViewer.queryHotspot('hotspot-dot-X-Y+Z'), modelViewer.queryHotspot('hotspot-dot+X-Y+Z'), modelViewer.queryHotspot('hotspot-dim-Y+Z'));
drawLine(dimLines[4], modelViewer.queryHotspot('hotspot-dot-X+Y-Z'), modelViewer.queryHotspot('hotspot-dot-X-Y-Z'), modelViewer.queryHotspot('hotspot-dim-X-Z'));
drawLine(dimLines[5], modelViewer.queryHotspot('hotspot-dot-X-Y-Z'), modelViewer.queryHotspot('hotspot-dot-X-Y+Z'), modelViewer.queryHotspot('hotspot-dim-X-Y'));
};
modelViewer.addEventListener('camera-change', renderSVG);
// Set the positions of all the hotspots on page load
modelViewer.addEventListener('load', () => {
const center = modelViewer.getBoundingBoxCenter();
const size = modelViewer.getDimensions();
const x2 = size.x / 2;
const y2 = size.y / 2;
const z2 = size.z / 2;
modelViewer.updateHotspot({
name: 'hotspot-dot+X-Y+Z',
position: `${center.x + x2} ${center.y - y2} ${center.z + z2}`
});
modelViewer.updateHotspot({
name: 'hotspot-dim+X-Y',
position: `${center.x + x2} ${center.y - y2} ${center.z}`
});
modelViewer.updateHotspot({
name: 'hotspot-dot+X-Y-Z',
position: `${center.x + x2} ${center.y - y2} ${center.z - z2}`
});
modelViewer.updateHotspot({
name: 'hotspot-dim+X-Z',
position: `${center.x + x2} ${center.y} ${center.z - z2}`
});
modelViewer.updateHotspot({
name: 'hotspot-dot+X+Y-Z',
position: `${center.x + x2} ${center.y + y2} ${center.z - z2}`
});
modelViewer.updateHotspot({
name: 'hotspot-dim+Y-Z',
position: `${center.x} ${center.y + y2} ${center.z - z2}`
});
modelViewer.updateHotspot({
name: 'hotspot-dot-X+Y-Z',
position: `${center.x - x2} ${center.y + y2} ${center.z - z2}`
});
modelViewer.updateHotspot({
name: 'hotspot-dim-X-Z',
position: `${center.x - x2} ${center.y} ${center.z - z2}`
});
modelViewer.updateHotspot({
name: 'hotspot-dot-X-Y-Z',
position: `${center.x - x2} ${center.y - y2} ${center.z - z2}`
});
modelViewer.updateHotspot({
name: 'hotspot-dim-X-Y',
position: `${center.x - x2} ${center.y - y2} ${center.z}`
});
modelViewer.updateHotspot({
name: 'hotspot-dot-X-Y+Z',
position: `${center.x - x2} ${center.y - y2} ${center.z + z2}`
});
modelViewer.updateHotspot({
name: 'hotspot-dim-Y+Z',
position: `${center.x} ${center.y - y2} ${center.z + z2}`
});
renderSVG();
});
// Add the text in appropriate units based off of the radio button
// The load event sets the text upon page load
// The change event reruns the code every time a user selects a different
// choice on any of the menu/radio/checkbox.
// size of model viewer is in meters by default
const toInchesConversion = 39.3701 // Add more decimal places for higher precision!
function drawLabels(size) {
if(document.getElementById('cms').checked == true) {
modelViewer.querySelector('button[slot="hotspot-dim+X-Y"]').textContent =
`${(size.z * 100).toFixed(1)} cm`;
modelViewer.querySelector('button[slot="hotspot-dim+X-Z"]').textContent =
`${(size.y * 100).toFixed(1)} cm`;
modelViewer.querySelector('button[slot="hotspot-dim+Y-Z"]').textContent =
`${(size.x * 100).toFixed(1)} cm`;
modelViewer.querySelector('button[slot="hotspot-dim-X-Z"]').textContent =
`${(size.y * 100).toFixed(1)} cm`;
modelViewer.querySelector('button[slot="hotspot-dim-X-Y"]').textContent =
`${(size.z * 100).toFixed(1)} cm`;
modelViewer.querySelector('button[slot="hotspot-dim-Y+Z"]').textContent =
`${(size.x * 100).toFixed(1)} cm`;
} else {
modelViewer.querySelector('button[slot="hotspot-dim+X-Y"]').textContent =
`${(size.z * toInchesConversion).toFixed(1)} in`;
modelViewer.querySelector('button[slot="hotspot-dim+X-Z"]').textContent =
`${(size.y * toInchesConversion).toFixed(1)} in`;
modelViewer.querySelector('button[slot="hotspot-dim+Y-Z"]').textContent =
`${(size.x * toInchesConversion).toFixed(1)} in`;
modelViewer.querySelector('button[slot="hotspot-dim-X-Z"]').textContent =
`${(size.y * toInchesConversion).toFixed(1)} in`;
modelViewer.querySelector('button[slot="hotspot-dim-X-Y"]').textContent =
`${(size.z * toInchesConversion).toFixed(1)} in`;
modelViewer.querySelector('button[slot="hotspot-dim-Y+Z"]').textContent =
`${(size.x * toInchesConversion).toFixed(1)} in`;
}
}
modelViewer.addEventListener('load', () => {
const center = modelViewer.getBoundingBoxCenter();
const size = modelViewer.getDimensions();
const x2 = size.x / 2;
const y2 = size.y / 2;
const z2 = size.z / 2;
drawLabels(size);
});
modelViewer.addEventListener('change', () => {
const center = modelViewer.getBoundingBoxCenter();
const size = modelViewer.getDimensions();
const x2 = size.x / 2;
const y2 = size.y / 2;
const z2 = size.z / 2;
drawLabels(size);
});
</script>
<!-- <script src="script.js"></script> -->
<!-- Loads <model-viewer> for browsers: -->
<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
</body>
</html>