need that grid to not interconnect itself with lines when appears on canvas. fixt that…
- User
need that grid to not interconnect itself with lines when appears on canvas. fixt that snap to grid functionality to point with mouse and attach new line to build wireframe model.:
} .green-dot { position: absolute; width: 5px; height: 5px; background-color: lime; border-radius: 50%; pointer-events: none; z-index:0; }const ctx = canvas.getContext('2d'); const vmcMenu = document.getElementById('vmc-menu');
const vertices = [ [0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0], [0, 0, 1], [0, 1, 1], [1, 1, 1], [1, 0, 1], ];
const edges = [ [0, 1], [1, 2], [2, 3], [3, 0], [0, 4], [1, 5], [2, 6], [3, 7], [4, 5], [5, 6], [6, 7], [7, 4], ];
const scale = 0.025; const zoom = 1; const offsetX = 0.5; const offsetY = 0.5;
let angleX = 0; let angleY = 0; let angleZ = 0; let bestIndex = -1; let bestDistance = Infinity; let startNewEdgeIndex = -1; let isMouseDown = false; let prevMousePos = null; const gridSpacing = 50; const gridPoints = []; let displayGrid = true; function roundToGrid(value) { return Math.round(value / gridSpacing) * gridSpacing; }
function snapToGrid(x, y) { return { x: roundToGrid(x - canvas.getBoundingClientRect().left), y: roundToGrid(y - canvas.getBoundingClientRect().top) }; }// Red Dot const redDot = document.getElementById('red-dot'); const greenDotContainer = document.getElementById('green-dot'); document.body.appendChild(greenDotContainer);
function addEdge(event) { if (bestIndex === -1) return; if (startNewEdgeIndex === -1) { const snapped = snapToGrid(window.event.clientX, window.event.clientY); const { x, y } = reverseProject([snapped.x, snapped.y], canvas.height * scale, offsetX, offsetY, zoom); vertices.push([x, y, 0]); startNewEdgeIndex = vertices.length - 1; } else { edges.push([startNewEdgeIndex, bestIndex]); startNewEdgeIndex = -1; } } function reverseProject(coordinates, scale, offsetX, offsetY, zoom) { const [x, y] = coordinates; return [ (x - canvas.width / 2) / (zoom * scale) + offsetX, (y - canvas.height / 2) / (zoom * scale) + offsetY, ]; }// Remove Edge document.getElementById('remove-edge').addEventListener('click', () => { if (bestIndex === -1) return; edges.forEach((edge, index) => { if (edge.includes(bestIndex)) { edges.splice(index, 1); } }); });
function rotateX(angle) { const c = Math.cos(angle); const s = Math.sin(angle); return [ [1, 0, 0], [0, c, -s], [0, s, c], ]; }
function rotateY(angle) { const c = Math.cos(angle); const s = Math.sin(angle); return [ [c, 0, s], [0, 1, 0], [-s, 0, c], ]; }
function rotateZ(angle) { const c = Math.cos(angle); const s = Math.sin(angle); return [ [c, -s, 0], [s, c, 0], [0, 0, 1], ]; }
function project(vertex, scale, offsetX, offsetY, zoom) { const [x, y, z] = vertex; const posX = (x - offsetX) * scale; const posY = (y - offsetY) * scale; const posZ = z * scale;
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.