-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
407 lines (343 loc) · 18.9 KB
/
Copy pathindex.html
File metadata and controls
407 lines (343 loc) · 18.9 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Point Cloud Depth Evaluator</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
'accent-teal': '#14b8a6',
'accent-orange': '#ff5733',
'panel-dark': '#0b0f19',
}
}
}
}
</script>
<style>
body { margin: 0; overflow: hidden; background-color: #05070c; font-family: 'Inter', sans-serif; color: #f1f5f9; }
#canvas-container { width: 100vw; height: 100vh; display: block; position: absolute; top: 0; left: 0; z-index: 1; }
#ui-layer { position: absolute; z-index: 10; pointer-events: none; width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: space-between; }
.glass-panel { pointer-events: auto; backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border: 1px solid rgba(20, 184, 166, 0.15); }
input[type="file"]::file-selector-button {
background-color: #14b8a6; color: #05070c; border: none; padding: 0.4rem 0.8rem;
border-radius: 0.375rem; cursor: pointer; transition: all 0.2s; font-weight: 600; font-size: 0.75rem;
}
input[type="file"]::file-selector-button:hover { background-color: #2dd4bf; transform: translateY(-1px); }
.measurement-label {
position: absolute; background: rgba(11, 15, 25, 0.9); color: #14b8a6;
padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 700;
pointer-events: none; transform: translate(-50%, -50%);
border: 1px solid rgba(255, 87, 51, 0.4); box-shadow: 0 4px 12px rgba(0,0,0,0.5);
z-index: 20; font-family: monospace;
}
</style>
</head>
<body>
<div id="ui-layer" class="p-4">
<div class="glass-panel bg-panel-dark/80 w-80 p-5 rounded-xl shadow-2xl flex flex-col gap-5">
<div class="flex items-center justify-between border-b border-teal-950 pb-3">
<h1 class="text-sm font-bold tracking-wider text-accent-teal uppercase flex items-center gap-2">
<span class="w-2 h-2 rounded-full bg-accent-orange animate-pulse"></span>
Depth Cloud Analyzer
</h1>
<span id="point-count" class="text-[10px] font-mono bg-teal-950/50 px-2 py-0.5 rounded text-teal-400">0 pts</span>
</div>
<div>
<label class="block text-[10px] font-semibold text-gray-400 uppercase tracking-widest mb-1.5">Import Depth Asset</label>
<input type="file" id="file-input" accept=".glb,.gltf" class="block w-full text-xs text-gray-400 cursor-pointer"/>
</div>
<div>
<div class="flex justify-between items-center mb-1">
<label class="text-[10px] font-semibold text-gray-400 uppercase tracking-widest">Point Size Evaluator</label>
<span id="size-val" class="text-xs font-mono text-accent-teal">0.020</span>
</div>
<input type="range" id="slider-size" min="0.001" max="0.1" step="0.001" value="0.02" class="w-full h-1 bg-gray-800 rounded-lg appearance-none cursor-pointer accent-accent-teal"/>
</div>
<div class="flex flex-col gap-2.5 pt-2">
<button id="btn-measure" class="flex justify-between items-center bg-slate-900/60 hover:bg-slate-900 text-xs font-medium py-2.5 px-4 rounded-lg transition-all border border-gray-800 hover:border-accent-teal/40">
<span class="flex items-center gap-2 tracking-wide">
<svg class="w-3.5 h-3.5 text-accent-teal" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.121 14.121L19 19m-7-7l7-7m-7 7l-2.879 2.879M12 12L9.121 9.121m0 5.758a3 3 0 10-4.243-4.243 3 3 0 004.243 4.243z"></path></svg>
Ray-Intercept Snap
</span>
<span class="flex h-2 w-2 relative">
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-accent-orange opacity-75 hidden" id="measure-ping"></span>
<span class="relative inline-flex rounded-full h-2 w-2 bg-gray-600" id="measure-dot"></span>
</span>
</button>
<button id="btn-clear" class="text-center text-gray-400 hover:text-accent-orange bg-transparent hover:bg-accent-orange/5 text-xs font-medium py-2 px-4 rounded-lg transition-all border border-transparent hover:border-accent-orange/20">
Clear Diagnostics
</button>
</div>
</div>
<div class="glass-panel bg-panel-dark/60 self-start px-4 py-2 rounded-lg text-[11px] font-mono text-gray-400 max-w-md border border-teal-950/30">
<span class="text-accent-teal">Status:</span> <span id="status-text">Awaiting Asset Injection...</span>
</div>
</div>
<div id="labels-container"></div>
<div id="canvas-container"></div>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.160.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
// --- Core Environment Engine ---
const container = document.getElementById('canvas-container');
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.001, 1000);
camera.position.set(1, 1, 2);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
container.appendChild(renderer.domElement);
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
// --- System State ---
let currentPointCloud = null;
let globalPointSize = 0.02;
let isMeasuring = false;
const diagnosticObjects = [];
const labels = [];
let currentPoints = [];
// --- Precision Hover/Snap Indicator Setup ---
// Marker radius = (Size * 3) / 2 to keep diameter at exactly 3x the size configuration
const previewGeo = new THREE.SphereGeometry(1, 16, 16);
const previewMat = new THREE.MeshBasicMaterial({ color: 0xff5733, transparent: true, opacity: 0.7, depthTest: false });
const previewMarker = new THREE.Mesh(previewGeo, previewMat);
previewMarker.visible = false;
previewMarker.renderOrder = 1000;
scene.add(previewMarker);
// --- Dynamic Sizing Controller ---
function updateMarkerScales() {
// Scale factors applied uniformly based on configuration state
const targetRadius = (globalPointSize * 3) / 2;
previewMarker.scale.setScalar(targetRadius);
diagnosticObjects.forEach(obj => {
if (obj.isMarkerSphere) {
obj.scale.setScalar(targetRadius);
}
});
}
// --- UI / Control Handlers ---
const sliderSize = document.getElementById('slider-size');
const sizeVal = document.getElementById('size-val');
sliderSize.addEventListener('input', (e) => {
globalPointSize = parseFloat(e.target.value);
sizeVal.textContent = globalPointSize.toFixed(3);
if (currentPointCloud) {
currentPointCloud.material.size = globalPointSize;
}
updateMarkerScales();
});
const btnMeasure = document.getElementById('btn-measure');
const measureDot = document.getElementById('measure-dot');
const measurePing = document.getElementById('measure-ping');
const statusText = document.getElementById('status-text');
btnMeasure.addEventListener('click', () => {
isMeasuring = !isMeasuring;
if (isMeasuring) {
btnMeasure.classList.add('border-accent-orange/40', 'text-accent-orange', 'bg-accent-orange/5');
measureDot.classList.replace('bg-gray-600', 'bg-accent-orange');
measurePing.classList.remove('hidden');
statusText.textContent = "Intercept Mode Active: Hover to reveal vertices, Click to drop node.";
} else {
btnMeasure.classList.remove('border-accent-orange/40', 'text-accent-orange', 'bg-accent-orange/5');
measureDot.classList.replace('bg-accent-orange', 'bg-gray-600');
measurePing.classList.add('hidden');
previewMarker.visible = false;
statusText.textContent = "Analytical Sandbox Stable.";
currentPoints = [];
}
});
document.getElementById('btn-clear').addEventListener('click', clearDiagnostics);
// --- Asset Parsing Pipeline ---
const loader = new GLTFLoader();
document.getElementById('file-input').addEventListener('change', (event) => {
const file = event.target.files[0];
if (!file) return;
statusText.textContent = "Deconstructing GLB matrix structural data...";
const url = URL.createObjectURL(file);
loader.load(url, (gltf) => {
if (currentPointCloud) scene.remove(currentPointCloud);
clearDiagnostics();
let extractedGeometry = null;
let totalVertices = 0;
// Traverse and convert elements natively to point structures
gltf.scene.traverse((child) => {
if (child.isPoints) {
extractedGeometry = child.geometry.clone();
} else if (child.isMesh && !extractedGeometry) {
// Structural conversion logic for mesh payloads
extractedGeometry = child.geometry.clone();
}
});
if (extractedGeometry) {
totalVertices = extractedGeometry.attributes.position.count;
document.getElementById('point-count').textContent = `${totalVertices.toLocaleString()} pts`;
const ptsMaterial = new THREE.PointsMaterial({
color: 0xffffff,
size: globalPointSize,
sizeAttenuation: true,
transparent: true,
opacity: 0.85,
vertexColors: extractedGeometry.attributes.color ? true : false
});
currentPointCloud = new THREE.Points(extractedGeometry, ptsMaterial);
// Center architecture bounding space
const box = new THREE.Box3().setFromObject(currentPointCloud);
const center = box.getCenter(new THREE.Vector3());
const size = box.getSize(new THREE.Vector3());
currentPointCloud.position.sub(center);
scene.add(currentPointCloud);
// Dynamic calibration adjustments
const maxDim = Math.max(size.x, size.y, size.z);
globalPointSize = maxDim * 0.008; // Auto-calculate optimized starting scale
sliderSize.value = globalPointSize;
sizeVal.textContent = globalPointSize.toFixed(3);
currentPointCloud.material.size = globalPointSize;
updateMarkerScales();
// Adjust visual targeting frame
const fov = camera.fov * (Math.PI / 180);
let cameraZ = Math.abs(maxDim / 2 / Math.tan(fov / 2));
camera.position.set(cameraZ * 0.7, cameraZ * 0.6, cameraZ * 1.1);
camera.near = maxDim / 500;
camera.far = maxDim * 100;
camera.updateProjectionMatrix();
controls.target.set(0,0,0);
controls.update();
statusText.textContent = `Successfully computed point matrix. Max Boundary: ${maxDim.toFixed(3)} units.`;
} else {
statusText.textContent = "Failed Calibration: No valid vertex data resolved.";
}
URL.revokeObjectURL(url);
}, undefined, (err) => {
statusText.textContent = "Critical Parsing Interrupt Error.";
console.error(err);
});
});
// --- Ray-Intercept & Hover Processing Engine ---
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
function executeRaycast(event) {
if (!currentPointCloud) return null;
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
// Dynamic adaptation threshold linked directly to the cloud size profile
raycaster.params.Points.threshold = globalPointSize * 0.75;
const intersects = raycaster.intersectObject(currentPointCloud, true);
if (intersects.length > 0) {
const intersect = intersects[0];
const index = intersect.index;
const targetPos = new THREE.Vector3();
targetPos.fromBufferAttribute(currentPointCloud.geometry.attributes.position, index);
targetPos.applyMatrix4(currentPointCloud.matrixWorld);
return targetPos;
}
return null;
}
// Live Pointer Tracking (Hover state verification)
window.addEventListener('pointermove', (event) => {
if (!isMeasuring || !currentPointCloud) return;
const snappedPoint = executeRaycast(event);
if (snappedPoint) {
previewMarker.position.copy(snappedPoint);
previewMarker.visible = true;
} else {
previewMarker.visible = false;
}
});
// Intercept Commit Handler (Click to confirm node connection)
container.addEventListener('pointerdown', (event) => {
if (!isMeasuring || !currentPointCloud) return;
if (event.button !== 0) return; // Left click execution profile only
const snappedPoint = executeRaycast(event);
if (snappedPoint) {
dropDiagnosticNode(snappedPoint);
}
});
function dropDiagnosticNode(point) {
const targetRadius = (globalPointSize * 3) / 2;
const markerGeo = new THREE.SphereGeometry(1, 16, 16);
const markerMat = new THREE.MeshBasicMaterial({ color: 0xff5733, depthTest: false });
const markerNode = new THREE.Mesh(markerGeo, markerMat);
markerNode.isMarkerSphere = true; // State system tag
markerNode.scale.setScalar(targetRadius);
markerNode.renderOrder = 1001;
markerNode.position.copy(point);
scene.add(markerNode);
diagnosticObjects.push(markerNode);
currentPoints.push(point);
if (currentPoints.length === 2) {
const traceMat = new THREE.LineBasicMaterial({ color: 0x14b8a6, linewidth: 2, depthTest: false });
const traceGeo = new THREE.BufferGeometry().setFromPoints(currentPoints);
const evaluationTrace = new THREE.Line(traceGeo, traceMat);
evaluationTrace.renderOrder = 999;
scene.add(evaluationTrace);
diagnosticObjects.push(evaluationTrace);
const realWorldDistance = currentPoints[0].distanceTo(currentPoints[1]);
const mathematicalMidpoint = new THREE.Vector3().addVectors(currentPoints[0], currentPoints[1]).multiplyScalar(0.5);
generateHUDLabel(realWorldDistance, mathematicalMidpoint);
currentPoints = []; // Flush tracking container
statusText.textContent = `Metric Distance Resolved: ${realWorldDistance.toFixed(5)} units.`;
}
}
function generateHUDLabel(distance, trackingVector) {
const div = document.createElement('div');
div.className = 'measurement-label';
div.textContent = `${distance.toFixed(5)} U`;
document.getElementById('labels-container').appendChild(div);
labels.push({ element: div, position: trackingVector });
}
function clearDiagnostics() {
diagnosticObjects.forEach(obj => scene.remove(obj));
diagnosticObjects.length = 0;
labels.forEach(lbl => lbl.element.remove());
labels.length = 0;
currentPoints = [];
previewMarker.visible = false;
statusText.textContent = "Diagnostic registers purged.";
}
function syncHUDLabels() {
labels.forEach(label => {
const projectionVector = label.position.clone();
projectionVector.project(camera);
if (projectionVector.z > 1) {
label.element.style.display = 'none';
return;
}
label.element.style.display = 'block';
const coordinateX = (projectionVector.x * 0.5 + 0.5) * window.innerWidth;
const coordinateY = (projectionVector.y * -0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${coordinateX}px`;
label.element.style.top = `${coordinateY}px`;
});
}
// --- Render Coordination Loop ---
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
function pipelineTick() {
requestAnimationFrame(pipelineTick);
controls.update();
syncHUDLabels();
renderer.render(scene, camera);
}
pipelineTick();
</script>
</body>
</html>