Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +45 -13
index.html
CHANGED
|
@@ -15,7 +15,7 @@
|
|
| 15 |
<input type="file" id="file1" accept=".txt"> File A<br>
|
| 16 |
<input type="file" id="file2" accept=".txt"> File B<br><br>
|
| 17 |
<button onclick="uploadFiles()">Visualize</button>
|
| 18 |
-
<label><input type="checkbox" id="showNormals" onchange="toggleNormals()"> Show Normal Vectors</label>
|
| 19 |
<div id="plot"></div>
|
| 20 |
|
| 21 |
<script>
|
|
@@ -61,6 +61,46 @@
|
|
| 61 |
return await res.json();
|
| 62 |
}
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
function extractTraces(data, prefix, baseColor, normalColor) {
|
| 65 |
for (const [tag, g] of Object.entries(data.geometry)) {
|
| 66 |
const [x, y, z] = g.base_point;
|
|
@@ -75,15 +115,7 @@
|
|
| 75 |
textposition: 'top center'
|
| 76 |
});
|
| 77 |
|
| 78 |
-
normalTraces.push(
|
| 79 |
-
type: 'scatter3d',
|
| 80 |
-
mode: 'lines',
|
| 81 |
-
x: [x, x + nx],
|
| 82 |
-
y: [y, y + ny],
|
| 83 |
-
z: [z, z + nz],
|
| 84 |
-
line: { color: normalColor, width: 3 },
|
| 85 |
-
visible: false
|
| 86 |
-
});
|
| 87 |
}
|
| 88 |
|
| 89 |
for (const c of data.constraints) {
|
|
@@ -104,8 +136,8 @@
|
|
| 104 |
|
| 105 |
function toggleNormals() {
|
| 106 |
const checked = document.getElementById("showNormals").checked;
|
| 107 |
-
const
|
| 108 |
-
Plotly.react('plot', [...allTraces, ...
|
| 109 |
margin: { t: 30 },
|
| 110 |
scene: { aspectmode: 'data' },
|
| 111 |
title: '3D Assembly Viewer'
|
|
@@ -113,4 +145,4 @@
|
|
| 113 |
}
|
| 114 |
</script>
|
| 115 |
</body>
|
| 116 |
-
</html>
|
|
|
|
| 15 |
<input type="file" id="file1" accept=".txt"> File A<br>
|
| 16 |
<input type="file" id="file2" accept=".txt"> File B<br><br>
|
| 17 |
<button onclick="uploadFiles()">Visualize</button>
|
| 18 |
+
<label><input type="checkbox" id="showNormals" onchange="toggleNormals()"> Show Normal Vectors (Planes)</label>
|
| 19 |
<div id="plot"></div>
|
| 20 |
|
| 21 |
<script>
|
|
|
|
| 61 |
return await res.json();
|
| 62 |
}
|
| 63 |
|
| 64 |
+
function createPlaneTrace(x, y, z, nx, ny, nz, color) {
|
| 65 |
+
const size = 0.5;
|
| 66 |
+
let ux = 1, uy = 0, uz = 0;
|
| 67 |
+
if (Math.abs(nx) < 0.9) {
|
| 68 |
+
ux = 0; uy = 1; uz = 0;
|
| 69 |
+
}
|
| 70 |
+
let vx = ny * uz - nz * uy;
|
| 71 |
+
let vy = nz * ux - nx * uz;
|
| 72 |
+
let vz = nx * uy - ny * ux;
|
| 73 |
+
const len = Math.sqrt(vx**2 + vy**2 + vz**2);
|
| 74 |
+
vx /= len; vy /= len; vz /= len;
|
| 75 |
+
const wx = ny * vz - nz * vy;
|
| 76 |
+
const wy = nz * vx - nx * vz;
|
| 77 |
+
const wz = nx * vy - ny * vx;
|
| 78 |
+
|
| 79 |
+
const planePoints = [];
|
| 80 |
+
for (let dx of [-1, 1]) {
|
| 81 |
+
for (let dy of [-1, 1]) {
|
| 82 |
+
planePoints.push([
|
| 83 |
+
x + dx * vx * size + dy * wx * size,
|
| 84 |
+
y + dx * vy * size + dy * wy * size,
|
| 85 |
+
z + dx * vz * size + dy * wz * size
|
| 86 |
+
]);
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
return {
|
| 91 |
+
type: 'mesh3d',
|
| 92 |
+
x: planePoints.map(p => p[0]),
|
| 93 |
+
y: planePoints.map(p => p[1]),
|
| 94 |
+
z: planePoints.map(p => p[2]),
|
| 95 |
+
i: [0, 0],
|
| 96 |
+
j: [1, 2],
|
| 97 |
+
k: [2, 3],
|
| 98 |
+
opacity: 0.5,
|
| 99 |
+
color: color,
|
| 100 |
+
visible: false
|
| 101 |
+
};
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
function extractTraces(data, prefix, baseColor, normalColor) {
|
| 105 |
for (const [tag, g] of Object.entries(data.geometry)) {
|
| 106 |
const [x, y, z] = g.base_point;
|
|
|
|
| 115 |
textposition: 'top center'
|
| 116 |
});
|
| 117 |
|
| 118 |
+
normalTraces.push(createPlaneTrace(x, y, z, nx, ny, nz, normalColor));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
}
|
| 120 |
|
| 121 |
for (const c of data.constraints) {
|
|
|
|
| 136 |
|
| 137 |
function toggleNormals() {
|
| 138 |
const checked = document.getElementById("showNormals").checked;
|
| 139 |
+
const updatedTraces = normalTraces.map(t => ({ ...t, visible: checked }));
|
| 140 |
+
Plotly.react('plot', [...allTraces, ...updatedTraces], {
|
| 141 |
margin: { t: 30 },
|
| 142 |
scene: { aspectmode: 'data' },
|
| 143 |
title: '3D Assembly Viewer'
|
|
|
|
| 145 |
}
|
| 146 |
</script>
|
| 147 |
</body>
|
| 148 |
+
</html>
|