Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- index.html +78 -52
index.html
CHANGED
|
@@ -7,78 +7,78 @@
|
|
| 7 |
<title>DCM Assembly Visualizer</title>
|
| 8 |
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
|
| 9 |
<style>
|
| 10 |
-
body { font-family: sans-serif; padding: 20px;
|
| 11 |
-
#plot { width: 100%; height: 700px;
|
| 12 |
-
|
| 13 |
</style>
|
| 14 |
</head>
|
| 15 |
<body>
|
| 16 |
<h1>DCM Assembly Visualizer</h1>
|
| 17 |
|
| 18 |
-
<
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
<script>
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
traces.push(...extractTraces(data1, 'red', 'blue'));
|
| 34 |
}
|
| 35 |
|
| 36 |
-
|
| 37 |
-
const data2 = await sendFile(file2);
|
| 38 |
-
traces.push(...extractTraces(data2, 'orange', 'purple'));
|
| 39 |
-
}
|
| 40 |
|
| 41 |
-
Plotly.newPlot('plot',
|
| 42 |
margin: { t: 30 },
|
| 43 |
scene: { aspectmode: 'data' },
|
| 44 |
title: '3D Assembly Viewer'
|
| 45 |
});
|
| 46 |
}
|
| 47 |
|
| 48 |
-
async function sendFile(file) {
|
| 49 |
-
const formData = new FormData();
|
| 50 |
-
formData.append("file", file);
|
| 51 |
-
const res = await fetch("/parse", {
|
| 52 |
-
method: "POST",
|
| 53 |
-
body: formData
|
| 54 |
-
});
|
| 55 |
-
return await res.json();
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
function extractTraces(data, baseColor, normalColor) {
|
| 59 |
-
const traces = [];
|
| 60 |
-
|
| 61 |
for (const [tag, g] of Object.entries(data.geometry)) {
|
| 62 |
const [x, y, z] = g.base_point;
|
| 63 |
const [nx, ny, nz] = g.normal;
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
type: 'scatter3d',
|
| 67 |
-
mode: 'markers+text',
|
| 68 |
x: [x], y: [y], z: [z],
|
| 69 |
marker: { color: baseColor, size: 5 },
|
| 70 |
-
text: [
|
| 71 |
-
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
type: 'scatter3d',
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
}
|
| 83 |
|
| 84 |
for (const c of data.constraints) {
|
|
@@ -87,17 +87,43 @@
|
|
| 87 |
if (g1 && g2) {
|
| 88 |
const [x1, y1, z1] = g1.base_point;
|
| 89 |
const [x2, y2, z2] = g2.base_point;
|
| 90 |
-
|
| 91 |
-
type: 'scatter3d',
|
| 92 |
-
mode: 'lines',
|
| 93 |
x: [x1, x2], y: [y1, y2], z: [z1, z2],
|
| 94 |
-
line: { color: 'green', dash: 'dot', width: 2 }
|
|
|
|
| 95 |
});
|
| 96 |
}
|
| 97 |
}
|
|
|
|
| 98 |
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
</script>
|
| 102 |
</body>
|
| 103 |
</html>
|
|
|
|
| 7 |
<title>DCM Assembly Visualizer</title>
|
| 8 |
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
|
| 9 |
<style>
|
| 10 |
+
body { font-family: sans-serif; padding: 20px; }
|
| 11 |
+
#plot { width: 100%; height: 700px; }
|
| 12 |
+
.controls { width: 200px; margin-right: 20px; }
|
| 13 |
</style>
|
| 14 |
</head>
|
| 15 |
<body>
|
| 16 |
<h1>DCM Assembly Visualizer</h1>
|
| 17 |
|
| 18 |
+
<div style="display: flex;">
|
| 19 |
+
<div class="controls">
|
| 20 |
+
<h3>Controls</h3>
|
| 21 |
+
<div id="partControls"></div>
|
| 22 |
+
<label><input type="checkbox" id="toggleConstraints" checked onchange="toggleConstraints()"> Show Constraints</label>
|
| 23 |
+
</div>
|
| 24 |
+
<div style="flex: 1;">
|
| 25 |
+
<div id="plot"></div>
|
| 26 |
+
</div>
|
| 27 |
+
</div>
|
| 28 |
|
| 29 |
<script>
|
| 30 |
+
let allTraces = [];
|
| 31 |
+
let constraintTraces = [];
|
| 32 |
+
let partMap = {}; // { part: [traceIndices] }
|
| 33 |
|
| 34 |
+
async function drawFromServer() {
|
| 35 |
+
const res = await fetch("/parsed_data.json");
|
| 36 |
+
const payload = await res.json();
|
| 37 |
+
allTraces = [];
|
| 38 |
+
constraintTraces = [];
|
| 39 |
+
partMap = {};
|
| 40 |
|
| 41 |
+
for (const [color, label, data] of payload.files) {
|
| 42 |
+
extractTraces(data, color, label);
|
|
|
|
| 43 |
}
|
| 44 |
|
| 45 |
+
renderPartControls();
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
Plotly.newPlot('plot', [...allTraces, ...constraintTraces], {
|
| 48 |
margin: { t: 30 },
|
| 49 |
scene: { aspectmode: 'data' },
|
| 50 |
title: '3D Assembly Viewer'
|
| 51 |
});
|
| 52 |
}
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
function extractTraces(data, baseColor, normalColor) {
|
|
|
|
|
|
|
| 55 |
for (const [tag, g] of Object.entries(data.geometry)) {
|
| 56 |
const [x, y, z] = g.base_point;
|
| 57 |
const [nx, ny, nz] = g.normal;
|
| 58 |
+
const label = g.label || tag;
|
| 59 |
+
const part = label.split('@').pop()?.split('-')[0] || "unknown";
|
| 60 |
|
| 61 |
+
const baseTrace = {
|
| 62 |
+
type: 'scatter3d', mode: 'markers+text',
|
|
|
|
| 63 |
x: [x], y: [y], z: [z],
|
| 64 |
marker: { color: baseColor, size: 5 },
|
| 65 |
+
text: [label], textposition: 'top center',
|
| 66 |
+
name: `Base: ${label}`
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
const normalTrace = {
|
| 70 |
+
type: 'scatter3d', mode: 'lines',
|
| 71 |
+
x: [x, x + nx], y: [y, y + ny], z: [z, z + nz],
|
| 72 |
+
line: { color: normalColor, width: 2 },
|
| 73 |
+
name: `Normal: ${label}`
|
| 74 |
+
};
|
| 75 |
+
|
| 76 |
+
const baseIndex = allTraces.length;
|
| 77 |
+
allTraces.push(baseTrace);
|
| 78 |
+
allTraces.push(normalTrace);
|
| 79 |
+
|
| 80 |
+
if (!partMap[part]) partMap[part] = [];
|
| 81 |
+
partMap[part].push(baseIndex, baseIndex + 1);
|
| 82 |
}
|
| 83 |
|
| 84 |
for (const c of data.constraints) {
|
|
|
|
| 87 |
if (g1 && g2) {
|
| 88 |
const [x1, y1, z1] = g1.base_point;
|
| 89 |
const [x2, y2, z2] = g2.base_point;
|
| 90 |
+
constraintTraces.push({
|
| 91 |
+
type: 'scatter3d', mode: 'lines',
|
|
|
|
| 92 |
x: [x1, x2], y: [y1, y2], z: [z1, z2],
|
| 93 |
+
line: { color: 'green', dash: 'dot', width: 2 },
|
| 94 |
+
name: `Constraint: ${c.label || ''}`
|
| 95 |
});
|
| 96 |
}
|
| 97 |
}
|
| 98 |
+
}
|
| 99 |
|
| 100 |
+
function renderPartControls() {
|
| 101 |
+
const container = document.getElementById("partControls");
|
| 102 |
+
container.innerHTML = '';
|
| 103 |
+
for (const part in partMap) {
|
| 104 |
+
const id = `part_${part}`;
|
| 105 |
+
container.innerHTML += `<label><input type='checkbox' id='${id}' checked onchange='togglePart("${part}")'> ${part}</label><br>`;
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
function togglePart(part) {
|
| 110 |
+
const indices = partMap[part];
|
| 111 |
+
const visible = document.getElementById(`part_${part}`).checked;
|
| 112 |
+
for (const i of indices) {
|
| 113 |
+
Plotly.restyle('plot', { visible: visible }, [i]);
|
| 114 |
+
}
|
| 115 |
}
|
| 116 |
+
|
| 117 |
+
function toggleConstraints() {
|
| 118 |
+
const show = document.getElementById("toggleConstraints").checked;
|
| 119 |
+
const start = allTraces.length;
|
| 120 |
+
const end = start + constraintTraces.length;
|
| 121 |
+
for (let i = start; i < end; i++) {
|
| 122 |
+
Plotly.restyle('plot', { visible: show }, [i]);
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
drawFromServer();
|
| 127 |
</script>
|
| 128 |
</body>
|
| 129 |
</html>
|