reorder boxes textures in order to work doubleside
This commit is contained in:
@@ -6,7 +6,6 @@ class PuzzleGame2 {
|
|||||||
return new Promise(async (resolve, reject)=>{
|
return new Promise(async (resolve, reject)=>{
|
||||||
let w = data.w, h = data.h, wh = w*h;
|
let w = data.w, h = data.h, wh = w*h;
|
||||||
const texture = await engine.loadTexture(data.$go.asset.name);
|
const texture = await engine.loadTexture(data.$go.asset.name);
|
||||||
//texture.encoding = sRGBEncoding;
|
|
||||||
const material = new MeshBasicMaterial({
|
const material = new MeshBasicMaterial({
|
||||||
map: texture
|
map: texture
|
||||||
});
|
});
|
||||||
@@ -66,11 +65,15 @@ class PuzzleGame2 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (let i = 0; i < wh; i++) {
|
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 bg = new BoxGeometry(1, 1, 1);
|
||||||
let uv = bg.getAttribute('uv');
|
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++) {
|
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
|
//top left
|
||||||
uv.array[8 * k] = xp;
|
uv.array[8 * k] = xp;
|
||||||
uv.array[8 * k + 1] = yp + 1 / h;
|
uv.array[8 * k + 1] = yp + 1 / h;
|
||||||
@@ -103,18 +106,17 @@ class PuzzleGame2 {
|
|||||||
let xc = p[idx] % w, yc = ~~(p[idx] / h);
|
let xc = p[idx] % w, yc = ~~(p[idx] / h);
|
||||||
let xl = p[lidx] % w, yl = ~~(p[lidx] / h);
|
let xl = p[lidx] % w, yl = ~~(p[lidx] / h);
|
||||||
if (Math.abs(xc - xl) + Math.abs(yc - yl) == 1) {
|
if (Math.abs(xc - xl) + Math.abs(yc - yl) == 1) {
|
||||||
aq.add({
|
aq.add([{
|
||||||
o: i.object,
|
o: i.object,
|
||||||
a: { position: { x: (xl - xc) * d, y: (yl - yc) * d } },
|
a: { position: { x: (xl - xc) * d, y: (yl - yc) * d } },
|
||||||
t: .3,
|
t: .3,
|
||||||
m: 'offset'
|
m: 'offset'
|
||||||
});
|
},{
|
||||||
aq.add({
|
|
||||||
o: last,
|
o: last,
|
||||||
a: { position: { x: (xc - xl) * d, y: (yc - yl) * d } },
|
a: { position: { x: (xc - xl) * d, y: (yc - yl) * d } },
|
||||||
t: .3,
|
t: .3,
|
||||||
m: 'offset'
|
m: 'offset'
|
||||||
});
|
}]);
|
||||||
xch(idx, lidx);
|
xch(idx, lidx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,7 +136,7 @@ class PuzzleGame2 {
|
|||||||
o: c,
|
o: c,
|
||||||
a: { position: { x: i % w, y: ~~(i / h) } },
|
a: { position: { x: i % w, y: ~~(i / h) } },
|
||||||
t: 1,
|
t: 1,
|
||||||
f: i == 0 && this.onfinish
|
f: i == 0 ? this.onfinish : undefined
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
//engine.dashboard.addPoints(10);
|
//engine.dashboard.addPoints(10);
|
||||||
|
|||||||
Reference in New Issue
Block a user