Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- index.html +50 -46
index.html
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
|
| 2 |
-
<!-- index.html -->
|
| 3 |
<!DOCTYPE html>
|
| 4 |
<html lang="en">
|
| 5 |
<head>
|
|
@@ -24,14 +23,28 @@
|
|
| 24 |
const file1 = document.getElementById("file1").files[0];
|
| 25 |
const file2 = document.getElementById("file2").files[0];
|
| 26 |
|
| 27 |
-
if (!file1
|
| 28 |
-
alert("Please select
|
| 29 |
return;
|
| 30 |
}
|
| 31 |
|
| 32 |
-
const
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
async function sendFile(file) {
|
|
@@ -44,57 +57,48 @@
|
|
| 44 |
return await res.json();
|
| 45 |
}
|
| 46 |
|
| 47 |
-
function
|
| 48 |
const traces = [];
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
const [nx, ny, nz] = g.normal;
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
traces.push({
|
| 65 |
type: 'scatter3d',
|
| 66 |
mode: 'lines',
|
| 67 |
-
x: [
|
| 68 |
-
|
| 69 |
-
z: [z, z + nz],
|
| 70 |
-
line: { color: colorNormal, width: 3 }
|
| 71 |
});
|
| 72 |
}
|
| 73 |
-
|
| 74 |
-
for (const c of data.constraints) {
|
| 75 |
-
const g1 = data.geometry[c.from];
|
| 76 |
-
const g2 = data.geometry[c.to];
|
| 77 |
-
if (g1 && g2) {
|
| 78 |
-
const [x1, y1, z1] = g1.base_point;
|
| 79 |
-
const [x2, y2, z2] = g2.base_point;
|
| 80 |
-
traces.push({
|
| 81 |
-
type: 'scatter3d',
|
| 82 |
-
mode: 'lines',
|
| 83 |
-
x: [x1, x2], y: [y1, y2], z: [z1, z2],
|
| 84 |
-
line: { color: 'green', dash: 'dot', width: 2 }
|
| 85 |
-
});
|
| 86 |
-
}
|
| 87 |
-
}
|
| 88 |
}
|
| 89 |
|
| 90 |
-
|
| 91 |
-
addAssembly(data2, 'purple', 'orange', 'File B');
|
| 92 |
-
|
| 93 |
-
Plotly.newPlot('plot', traces, {
|
| 94 |
-
margin: { t: 30 },
|
| 95 |
-
scene: { aspectmode: 'data' },
|
| 96 |
-
title: '3D Assembly Viewer'
|
| 97 |
-
});
|
| 98 |
}
|
| 99 |
</script>
|
| 100 |
</body>
|
|
|
|
| 1 |
|
|
|
|
| 2 |
<!DOCTYPE html>
|
| 3 |
<html lang="en">
|
| 4 |
<head>
|
|
|
|
| 23 |
const file1 = document.getElementById("file1").files[0];
|
| 24 |
const file2 = document.getElementById("file2").files[0];
|
| 25 |
|
| 26 |
+
if (!file1 && !file2) {
|
| 27 |
+
alert("Please select at least one file.");
|
| 28 |
return;
|
| 29 |
}
|
| 30 |
|
| 31 |
+
const traces = [];
|
| 32 |
+
|
| 33 |
+
if (file1) {
|
| 34 |
+
const data1 = await sendFile(file1);
|
| 35 |
+
traces.push(...extractTraces(data1, 'File A', 'red', 'blue'));
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
if (file2) {
|
| 39 |
+
const data2 = await sendFile(file2);
|
| 40 |
+
traces.push(...extractTraces(data2, 'File B', 'purple', 'orange'));
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
Plotly.newPlot('plot', traces, {
|
| 44 |
+
margin: { t: 30 },
|
| 45 |
+
scene: { aspectmode: 'data' },
|
| 46 |
+
title: '3D Assembly Viewer'
|
| 47 |
+
});
|
| 48 |
}
|
| 49 |
|
| 50 |
async function sendFile(file) {
|
|
|
|
| 57 |
return await res.json();
|
| 58 |
}
|
| 59 |
|
| 60 |
+
function extractTraces(data, prefix, baseColor, normalColor) {
|
| 61 |
const traces = [];
|
| 62 |
|
| 63 |
+
for (const [tag, g] of Object.entries(data.geometry)) {
|
| 64 |
+
const [x, y, z] = g.base_point;
|
| 65 |
+
const [nx, ny, nz] = g.normal;
|
|
|
|
| 66 |
|
| 67 |
+
traces.push({
|
| 68 |
+
type: 'scatter3d',
|
| 69 |
+
mode: 'markers+text',
|
| 70 |
+
x: [x], y: [y], z: [z],
|
| 71 |
+
marker: { color: baseColor, size: 5 },
|
| 72 |
+
text: [`${prefix}: ${g.label || tag}`],
|
| 73 |
+
textposition: 'top center'
|
| 74 |
+
});
|
| 75 |
+
|
| 76 |
+
traces.push({
|
| 77 |
+
type: 'scatter3d',
|
| 78 |
+
mode: 'lines',
|
| 79 |
+
x: [x, x + nx],
|
| 80 |
+
y: [y, y + ny],
|
| 81 |
+
z: [z, z + nz],
|
| 82 |
+
line: { color: normalColor, width: 3 }
|
| 83 |
+
});
|
| 84 |
+
}
|
| 85 |
|
| 86 |
+
for (const c of data.constraints) {
|
| 87 |
+
const g1 = data.geometry[c.from];
|
| 88 |
+
const g2 = data.geometry[c.to];
|
| 89 |
+
if (g1 && g2) {
|
| 90 |
+
const [x1, y1, z1] = g1.base_point;
|
| 91 |
+
const [x2, y2, z2] = g2.base_point;
|
| 92 |
traces.push({
|
| 93 |
type: 'scatter3d',
|
| 94 |
mode: 'lines',
|
| 95 |
+
x: [x1, x2], y: [y1, y2], z: [z1, z2],
|
| 96 |
+
line: { color: 'green', dash: 'dot', width: 2 }
|
|
|
|
|
|
|
| 97 |
});
|
| 98 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
}
|
| 100 |
|
| 101 |
+
return traces;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
}
|
| 103 |
</script>
|
| 104 |
</body>
|