Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Created July 5, 2021 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattdesl/3f81b85dd46e170b3a58906136cf4a03 to your computer and use it in GitHub Desktop.
Save mattdesl/3f81b85dd46e170b3a58906136cf4a03 to your computer and use it in GitHub Desktop.
// Project 3D points to 2D
const vertices2D = vertices.map(p => project(p));
// Draw each cell
for (let cell of cells) {
// Get the 2D points that define this triangle or quad
const points2D = cell.map(idx => vertices2D[idx]);
// Draw this polygon
context.beginPath();
for (let [x, y] of points2D) {
context.lineTo(x, y);
}
context.closePath();
context.stroke();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment