Pushpak21 commited on
Commit
bf9cc73
·
verified ·
1 Parent(s): 263ff10

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +30 -19
index.html CHANGED
@@ -15,9 +15,13 @@
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
  <div id="plot"></div>
19
 
20
  <script>
 
 
 
21
  async function uploadFiles() {
22
  const file1 = document.getElementById("file1").files[0];
23
  const file2 = document.getElementById("file2").files[0];
@@ -27,19 +31,20 @@
27
  return;
28
  }
29
 
30
- const traces = [];
 
31
 
32
  if (file1) {
33
  const data1 = await sendFile(file1);
34
- traces.push(...extractTraces(data1, 'File A', 'red', 'blue'));
35
  }
36
 
37
  if (file2) {
38
  const data2 = await sendFile(file2);
39
- traces.push(...extractTraces(data2, 'File B', 'purple', 'orange'));
40
  }
41
 
42
- Plotly.newPlot('plot', traces, {
43
  margin: { t: 30 },
44
  scene: { aspectmode: 'data' },
45
  title: '3D Assembly Viewer'
@@ -57,13 +62,11 @@
57
  }
58
 
59
  function extractTraces(data, prefix, baseColor, normalColor) {
60
- const traces = [];
61
-
62
  for (const [tag, g] of Object.entries(data.geometry)) {
63
  const [x, y, z] = g.base_point;
64
  const [nx, ny, nz] = g.normal;
65
 
66
- traces.push({
67
  type: 'scatter3d',
68
  mode: 'markers+text',
69
  x: [x], y: [y], z: [z],
@@ -72,15 +75,15 @@
72
  textposition: 'top center'
73
  });
74
 
75
- // Commented out normal lines (blue/orange) as per request
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) {
@@ -89,7 +92,7 @@
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],
@@ -97,9 +100,17 @@
97
  });
98
  }
99
  }
 
100
 
101
- return traces;
 
 
 
 
 
 
 
102
  }
103
  </script>
104
  </body>
105
- </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</label>
19
  <div id="plot"></div>
20
 
21
  <script>
22
+ let allTraces = [];
23
+ let normalTraces = [];
24
+
25
  async function uploadFiles() {
26
  const file1 = document.getElementById("file1").files[0];
27
  const file2 = document.getElementById("file2").files[0];
 
31
  return;
32
  }
33
 
34
+ allTraces = [];
35
+ normalTraces = [];
36
 
37
  if (file1) {
38
  const data1 = await sendFile(file1);
39
+ extractTraces(data1, 'File A', 'red', 'blue');
40
  }
41
 
42
  if (file2) {
43
  const data2 = await sendFile(file2);
44
+ extractTraces(data2, 'File B', 'purple', 'orange');
45
  }
46
 
47
+ Plotly.newPlot('plot', [...allTraces], {
48
  margin: { t: 30 },
49
  scene: { aspectmode: 'data' },
50
  title: '3D Assembly Viewer'
 
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;
67
  const [nx, ny, nz] = g.normal;
68
 
69
+ allTraces.push({
70
  type: 'scatter3d',
71
  mode: 'markers+text',
72
  x: [x], y: [y], z: [z],
 
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) {
 
92
  if (g1 && g2) {
93
  const [x1, y1, z1] = g1.base_point;
94
  const [x2, y2, z2] = g2.base_point;
95
+ allTraces.push({
96
  type: 'scatter3d',
97
  mode: 'lines',
98
  x: [x1, x2], y: [y1, y2], z: [z1, z2],
 
100
  });
101
  }
102
  }
103
+ }
104
 
105
+ function toggleNormals() {
106
+ const checked = document.getElementById("showNormals").checked;
107
+ const update = normalTraces.map(trace => ({ ...trace, visible: checked }));
108
+ Plotly.react('plot', [...allTraces, ...update], {
109
+ margin: { t: 30 },
110
+ scene: { aspectmode: 'data' },
111
+ title: '3D Assembly Viewer'
112
+ });
113
  }
114
  </script>
115
  </body>
116
+ </html>