function clip(quads) { if (config.show_texture) { return quads; } const tl = screen_to_canvas({'x': 0, 'y': 0}); const br = screen_to_canvas({'x': 0, 'y': canvas.height}); const x1 = tl.x; const y1 = tl.y; const x2 = br.x; const y2 = br.y; const result = { 'count': 0, }; if (quads.count === 0) { return result; } let i0 = -1; let i1 = -1; for (let i = 0; i < quads.start.length - 1; ++i) { const index = quads.start[i]; const next = quads.start[i + 1]; const left = quads.pos[index]; const top = quads.pos[index + 1]; const bottom = top + quads.size[index + 1]; const right = quads.pos[next - 2] + quads.size[next - 2]; if (bottom < y1) { if (i < quads.start.length / 2 - 2) { const index_ahead = quads.start[i * 2]; const top_ahead = quads.pos[index_ahead + 1]; const bottom_ahead = top_ahead + quads.size[index_ahead + 1]; if (bottom_ahead < y1) { i *= 2; continue; } } } if (bottom < y1 || right < x1) { continue; } if (top > y2) { i1 = quads.start[i + 1]; break; } if (i0 === -1) { i0 = index; } } result.pos = quads.pos.subarray(i0, i1); result.size = quads.size.subarray(i0, i1); result.color = quads.color.subarray(i0 * 2, i1 * 2); result.uv = quads.uv.subarray(i0, i1); result.count = (i1 - i0) / 2; result.uploaded = false; return result; }