From 26ad8857726d0b21d0ed18bfadb1972cbcf591dc Mon Sep 17 00:00:00 2001 From: goynov Date: Fri, 7 Nov 2025 19:49:36 +0200 Subject: [PATCH] reorder boxes textures in order to work doubleside --- .../InteractiveObjects/PuzzleGame2.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/InteractiveObjects/PuzzleGame2.js b/src/components/InteractiveObjects/PuzzleGame2.js index d04c79b..489d189 100644 --- a/src/components/InteractiveObjects/PuzzleGame2.js +++ b/src/components/InteractiveObjects/PuzzleGame2.js @@ -6,7 +6,6 @@ class PuzzleGame2 { return new Promise(async (resolve, reject)=>{ let w = data.w, h = data.h, wh = w*h; const texture = await engine.loadTexture(data.$go.asset.name); - //texture.encoding = sRGBEncoding; const material = new MeshBasicMaterial({ map: texture }); @@ -66,11 +65,15 @@ class PuzzleGame2 { }; for (let i = 0; i < wh; i++) { - let x = i % w, xp = x / w; - let y = ~~(i / h), yp = y / h; let bg = new BoxGeometry(1, 1, 1); let uv = bg.getAttribute('uv'); + //0-8->R, 8-16->L, 16-24->Top, 24-32->Bottom, 32-40->Front, 40-48->Back + let x = i % w, y = Math.trunc(i / w); + let idxs = [(i+1) % wh, (i+2)%wh, (i+3)%wh, (i+4)%wh, i, y*w + w - x -1] for (let k = 0; k < 6; k++) { + let idx = idxs[k]; + let x = idx % w, y = Math.trunc(idx / w) + let xp = x / w, yp = y / h; //top left uv.array[8 * k] = xp; uv.array[8 * k + 1] = yp + 1 / h; @@ -103,18 +106,17 @@ class PuzzleGame2 { let xc = p[idx] % w, yc = ~~(p[idx] / h); let xl = p[lidx] % w, yl = ~~(p[lidx] / h); if (Math.abs(xc - xl) + Math.abs(yc - yl) == 1) { - aq.add({ + aq.add([{ o: i.object, a: { position: { x: (xl - xc) * d, y: (yl - yc) * d } }, t: .3, m: 'offset' - }); - aq.add({ + },{ o: last, a: { position: { x: (xc - xl) * d, y: (yc - yl) * d } }, t: .3, m: 'offset' - }); + }]); xch(idx, lidx); } } @@ -134,7 +136,7 @@ class PuzzleGame2 { o: c, a: { position: { x: i % w, y: ~~(i / h) } }, t: 1, - f: i == 0 && this.onfinish + f: i == 0 ? this.onfinish : undefined }); }); //engine.dashboard.addPoints(10);