Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +47 -27
templates/index.html
CHANGED
@@ -43,13 +43,15 @@
|
|
43 |
<!-- Three.js Point Cloud Script -->
|
44 |
<script>
|
45 |
let scene, camera, renderer, points, raycaster, mouse, hoveredPoint = null;
|
|
|
46 |
const pointDetails = document.getElementById('point-details');
|
47 |
|
48 |
function initPointCloud(parts) {
|
|
|
49 |
scene = new THREE.Scene();
|
50 |
-
camera = new THREE.PerspectiveCamera(75,
|
51 |
-
renderer = new THREE.WebGLRenderer({ canvas:
|
52 |
-
renderer.setSize(
|
53 |
|
54 |
const positions = [];
|
55 |
const colors = [];
|
@@ -72,47 +74,67 @@
|
|
72 |
|
73 |
camera.position.z = 100;
|
74 |
raycaster = new THREE.Raycaster();
|
|
|
75 |
mouse = new THREE.Vector2();
|
76 |
|
|
|
|
|
|
|
77 |
animate();
|
78 |
}
|
79 |
|
80 |
function animate() {
|
81 |
requestAnimationFrame(animate);
|
82 |
-
points.rotation.y += 0.005;
|
83 |
renderer.render(scene, camera);
|
84 |
}
|
85 |
|
|
|
|
|
|
|
|
|
|
|
86 |
function onMouseMove(event) {
|
87 |
const rect = renderer.domElement.getBoundingClientRect();
|
88 |
mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
|
89 |
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
hoveredPoint = part;
|
98 |
-
pointDetails.innerHTML = `
|
99 |
-
<div class="text-gray-200">
|
100 |
-
<strong>Category:</strong> ${part.category}<br>
|
101 |
-
<strong>Node ID:</strong> ${part.node_id}<br>
|
102 |
-
<strong>Parent Path:</strong> ${part.parent_path}<br>
|
103 |
-
<strong>Level:</strong> ${part.level}<br>
|
104 |
-
<strong>Location:</strong> Lines ${part.location[0]} to ${part.location[1]}<br>
|
105 |
-
<strong>Vector:</strong> [${part.vector.join(', ')}]<br>
|
106 |
-
<strong>Code:</strong><pre class="text-xs text-gray-300">${part.source}</pre>
|
107 |
-
</div>
|
108 |
-
`;
|
109 |
-
}
|
110 |
} else {
|
111 |
-
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
}
|
114 |
}
|
115 |
|
|
|
|
|
|
|
|
|
116 |
function togglePointCloud() {
|
117 |
const canvas = document.getElementById('point-cloud');
|
118 |
const table = document.getElementById('results-table');
|
@@ -121,12 +143,10 @@
|
|
121 |
table.style.display = 'none';
|
122 |
if (!scene && window.parts) {
|
123 |
initPointCloud(window.parts);
|
124 |
-
document.addEventListener('mousemove', onMouseMove);
|
125 |
}
|
126 |
} else {
|
127 |
canvas.style.display = 'none';
|
128 |
table.style.display = 'block';
|
129 |
-
document.removeEventListener('mousemove', onMouseMove);
|
130 |
}
|
131 |
}
|
132 |
</script>
|
|
|
43 |
<!-- Three.js Point Cloud Script -->
|
44 |
<script>
|
45 |
let scene, camera, renderer, points, raycaster, mouse, hoveredPoint = null;
|
46 |
+
let isDragging = false, previousMousePosition = { x: 0, y: 0 };
|
47 |
const pointDetails = document.getElementById('point-details');
|
48 |
|
49 |
function initPointCloud(parts) {
|
50 |
+
const canvas = document.getElementById('point-cloud');
|
51 |
scene = new THREE.Scene();
|
52 |
+
camera = new THREE.PerspectiveCamera(75, canvas.offsetWidth / 400, 0.1, 1000);
|
53 |
+
renderer = new THREE.WebGLRenderer({ canvas: canvas, alpha: true });
|
54 |
+
renderer.setSize(canvas.offsetWidth, 400);
|
55 |
|
56 |
const positions = [];
|
57 |
const colors = [];
|
|
|
74 |
|
75 |
camera.position.z = 100;
|
76 |
raycaster = new THREE.Raycaster();
|
77 |
+
raycaster.params.Points.threshold = 5; // Increase sensitivity
|
78 |
mouse = new THREE.Vector2();
|
79 |
|
80 |
+
canvas.addEventListener('mousedown', onMouseDown);
|
81 |
+
canvas.addEventListener('mousemove', onMouseMove);
|
82 |
+
canvas.addEventListener('mouseup', onMouseUp);
|
83 |
animate();
|
84 |
}
|
85 |
|
86 |
function animate() {
|
87 |
requestAnimationFrame(animate);
|
|
|
88 |
renderer.render(scene, camera);
|
89 |
}
|
90 |
|
91 |
+
function onMouseDown(event) {
|
92 |
+
isDragging = true;
|
93 |
+
previousMousePosition = { x: event.clientX, y: event.clientY };
|
94 |
+
}
|
95 |
+
|
96 |
function onMouseMove(event) {
|
97 |
const rect = renderer.domElement.getBoundingClientRect();
|
98 |
mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
|
99 |
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
|
100 |
|
101 |
+
if (isDragging) {
|
102 |
+
const deltaX = event.clientX - previousMousePosition.x;
|
103 |
+
const deltaY = event.clientY - previousMousePosition.y;
|
104 |
+
points.rotation.y += deltaX * 0.005;
|
105 |
+
points.rotation.x += deltaY * 0.005;
|
106 |
+
previousMousePosition = { x: event.clientX, y: event.clientY };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
} else {
|
108 |
+
raycaster.setFromCamera(mouse, camera);
|
109 |
+
const intersects = raycaster.intersectObject(points);
|
110 |
+
if (intersects.length > 0) {
|
111 |
+
const index = intersects[0].index;
|
112 |
+
const part = window.parts.find(p => p.pointIndex === index * 3);
|
113 |
+
if (part && hoveredPoint !== part) {
|
114 |
+
hoveredPoint = part;
|
115 |
+
pointDetails.innerHTML = `
|
116 |
+
<div class="text-gray-200">
|
117 |
+
<strong>Category:</strong> ${part.category}<br>
|
118 |
+
<strong>Node ID:</strong> ${part.node_id}<br>
|
119 |
+
<strong>Parent Path:</strong> ${part.parent_path}<br>
|
120 |
+
<strong>Level:</strong> ${part.level}<br>
|
121 |
+
<strong>Location:</strong> Lines ${part.location[0]} to ${part.location[1]}<br>
|
122 |
+
<strong>Vector:</strong> [${part.vector.join(', ')}]<br>
|
123 |
+
<strong>Code:</strong><pre class="text-xs text-gray-300">${part.source}</pre>
|
124 |
+
</div>
|
125 |
+
`;
|
126 |
+
}
|
127 |
+
} else {
|
128 |
+
hoveredPoint = null;
|
129 |
+
pointDetails.innerHTML = '<p class="text-gray-400">Hover over a point to see details</p>';
|
130 |
+
}
|
131 |
}
|
132 |
}
|
133 |
|
134 |
+
function onMouseUp() {
|
135 |
+
isDragging = false;
|
136 |
+
}
|
137 |
+
|
138 |
function togglePointCloud() {
|
139 |
const canvas = document.getElementById('point-cloud');
|
140 |
const table = document.getElementById('results-table');
|
|
|
143 |
table.style.display = 'none';
|
144 |
if (!scene && window.parts) {
|
145 |
initPointCloud(window.parts);
|
|
|
146 |
}
|
147 |
} else {
|
148 |
canvas.style.display = 'none';
|
149 |
table.style.display = 'block';
|
|
|
150 |
}
|
151 |
}
|
152 |
</script>
|