fix that shit...

This commit is contained in:
glazenbol
2026-03-26 13:42:52 +01:00
parent 783286cedf
commit ff58292273
+18 -13
View File
@@ -1,6 +1,5 @@
import p5 from "p5"; import p5 from "p5";
import io from "socket.io-client"; import io from "socket.io-client";
import UPNG from "upng-js";
const socket = io("http://localhost:3000"); const socket = io("http://localhost:3000");
const params = { const params = {
@@ -38,6 +37,7 @@ const sketch = (p) => {
const tileCols = Math.ceil(imageW / tileW); const tileCols = Math.ceil(imageW / tileW);
const tileRows = Math.ceil(imageH / tileH); const tileRows = Math.ceil(imageH / tileH);
const tileCount = tileCols * tileRows; const tileCount = tileCols * tileRows;
const aleph = 0; // to fix tile gaps
let gl; let gl;
let texArray; let texArray;
let shaderProgram; let shaderProgram;
@@ -69,14 +69,14 @@ const sketch = (p) => {
const w = Math.min(tileW, imageW - x); const w = Math.min(tileW, imageW - x);
const h = Math.min(tileH, imageH - y); const h = Math.min(tileH, imageH - y);
promises.push( promises.push(
fetch(`assets/img/tiles/tile_x${x}_y${y}_w${w}_h${h}.png`) p
.then((res) => res.arrayBuffer()) .loadImage(`assets/img/tiles/tile_x${x}_y${y}_w${w}_h${h}.png`)
.then((buffer) => { .then((img) => {
const img = UPNG.decode(buffer); img.loadPixels();
console.log( let pixels = new Uint8Array(img.width * img.height);
`img.data.length: ${img.data.length}, img.width: ${img.width}, img.height: ${img.height}`, for (let i = 0; i < img.pixels.length; i++) {
); pixels[i] = img.pixels[i * 4];
}
const i = row * tileCols + column; const i = row * tileCols + column;
gl.texSubImage3D( gl.texSubImage3D(
gl.TEXTURE_2D_ARRAY, gl.TEXTURE_2D_ARRAY,
@@ -89,7 +89,7 @@ const sketch = (p) => {
1, 1,
gl.RED, gl.RED,
gl.UNSIGNED_BYTE, gl.UNSIGNED_BYTE,
img.data, pixels,
); );
n_downloaded++; n_downloaded++;
console.log( console.log(
@@ -185,7 +185,7 @@ const sketch = (p) => {
function drawTiles(x, y, width, height) { function drawTiles(x, y, width, height) {
// clear screen // clear screen
p.background(0); p.background(p.color(1, 0, 0, 0));
p.shader(shaderProgram); p.shader(shaderProgram);
// p.ortho(0, p.width, -p.height, 0); // p.ortho(0, p.width, -p.height, 0);
@@ -208,8 +208,13 @@ const sketch = (p) => {
const currentLayer = row * tileCols + col; const currentLayer = row * tileCols + col;
// Tell shader which layer to sample // Tell shader which layer to sample
shaderProgram.setUniform("uLayer", currentLayer); shaderProgram.setUniform("uLayer", currentLayer);
p.noStroke();
p.rect(col * tileW, row * tileH, tileW, tileH); p.rect(
col * tileW - aleph,
row * tileH - aleph,
tileW + 2 * aleph,
tileH + 2 * aleph,
);
// p.rect(0, 0, tileW, tileH); // p.rect(0, 0, tileW, tileH);
} }
} }