Skip to content

Commit c77d0f2

Browse files
committed
Clamp to edges textureAtlas
1 parent 129de77 commit c77d0f2

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

src/scripts/world/AnimatedTextureAtlas.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MeshStandardMaterial, TextureLoader, NearestFilter } from 'three'
1+
import { MeshStandardMaterial, TextureLoader, NearestFilter, NearestMipmapLinearFilter } from 'three'
22

33
class TextureAtlasCreator {
44
constructor (options) {
@@ -23,8 +23,9 @@ class TextureAtlasCreator {
2323
}
2424
const canvasx = document.createElement('canvas')
2525
const ctx = canvasx.getContext('2d')
26-
canvasx.width = this.willSize * 16
27-
canvasx.height = this.willSize * 16
26+
canvasx.width = this.willSize * (16 + 32)
27+
canvasx.height = this.willSize * (16 + 32)
28+
// console.log(this.willSize * (16 + 32))
2829
let toxelX = 1
2930
let toxelY = 1
3031
for (const i in this.textureMapping) {
@@ -40,17 +41,26 @@ class TextureAtlasCreator {
4041
const texmap = this.textureMapping[
4142
`${xd.pref}@${lol.col}@${lol.row}`
4243
]
44+
4345
ctx.drawImage(
4446
this.textureX,
4547
(texmap.x - 1) * 16,
4648
(texmap.y - 1) * 16,
4749
16,
4850
16,
49-
(toxelX - 1) * 16,
50-
(toxelY - 1) * 16,
51+
16 + (toxelX - 1) * (16 + 32),
52+
16 + (toxelY - 1) * (16 + 32),
5153
16,
5254
16
5355
)
56+
const b = ctx.getImageData(16 + (toxelX - 1) * (16 + 32), 16 + (toxelY - 1) * (16 + 32), 16, 16)
57+
for (let j = 16; j > 0; j--) {
58+
ctx.putImageData(b, 16 + (toxelX - 1) * (16 + 32), 16 + (toxelY - 1) * (16 + 32) - j)
59+
ctx.putImageData(b, 16 + (toxelX - 1) * (16 + 32) - j, 16 + (toxelY - 1) * (16 + 32))
60+
ctx.putImageData(b, 16 + (toxelX - 1) * (16 + 32) + j, 16 + (toxelY - 1) * (16 + 32))
61+
ctx.putImageData(b, 16 + (toxelX - 1) * (16 + 32), 16 + (toxelY - 1) * (16 + 32) + j)
62+
}
63+
ctx.putImageData(b, 16 + (toxelX - 1) * (16 + 32), 16 + (toxelY - 1) * (16 + 32))
5464
toxelX++
5565
if (toxelX > this.willSize) {
5666
toxelX = 1
@@ -64,18 +74,27 @@ class TextureAtlasCreator {
6474
(this.textureMapping[i].y - 1) * 16,
6575
16,
6676
16,
67-
(toxelX - 1) * 16,
68-
(toxelY - 1) * 16,
77+
16 + (toxelX - 1) * (16 + 32),
78+
16 + (toxelY - 1) * (16 + 32),
6979
16,
7080
16
7181
)
82+
const b = ctx.getImageData(16 + (toxelX - 1) * (16 + 32), 16 + (toxelY - 1) * (16 + 32), 16, 16)
83+
for (let j = 16; j > 0; j--) {
84+
ctx.putImageData(b, 16 + (toxelX - 1) * (16 + 32), 16 + (toxelY - 1) * (16 + 32) - j)
85+
ctx.putImageData(b, 16 + (toxelX - 1) * (16 + 32) - j, 16 + (toxelY - 1) * (16 + 32))
86+
ctx.putImageData(b, 16 + (toxelX - 1) * (16 + 32) + j, 16 + (toxelY - 1) * (16 + 32))
87+
ctx.putImageData(b, 16 + (toxelX - 1) * (16 + 32), 16 + (toxelY - 1) * (16 + 32) + j)
88+
}
89+
ctx.putImageData(b, 16 + (toxelX - 1) * (16 + 32), 16 + (toxelY - 1) * (16 + 32))
7290
toxelX++
7391
if (toxelX > this.willSize) {
7492
toxelX = 1
7593
toxelY++
7694
}
7795
}
7896
}
97+
// console.log(canvasx.toDataURL())
7998
return canvasx
8099
}
81100

@@ -131,7 +150,7 @@ class AnimatedTextureAtlas {
131150
const t = this.atlasCreator.gen(i).toDataURL()
132151
const tekstura = new TextureLoader().load(t)
133152
tekstura.magFilter = NearestFilter
134-
tekstura.minFilter = NearestFilter
153+
tekstura.minFilter = NearestMipmapLinearFilter
135154
savedTextures.push(tekstura)
136155
}
137156
let tickq = 0

src/scripts/world/ChunkMesher.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,12 @@ class ChunkMesher {
376376
let { x: toxX, y: toxY } = this.blocksMapping[name]
377377
toxX -= 1
378378
toxY -= 1
379-
const x1 = this.q * toxX
380-
const y1 = 1 - this.q * toxY - this.q
381-
const x2 = this.q * toxX + this.q
382-
const y2 = 1 - this.q * toxY
379+
const b = 16 / 1296
380+
const q = 48 / 1296
381+
const x1 = q * toxX + b
382+
const y1 = 1 - q * toxY - q + b
383+
const x2 = x1 + q - 2 * b
384+
const y2 = y1 + q - 2 * b
383385
return [
384386
[x1, y1],
385387
[x1, y2],
@@ -433,10 +435,12 @@ class ChunkMesher {
433435
}
434436
toxX -= 1
435437
toxY -= 1
436-
const x1 = this.q * toxX
437-
const y1 = 1 - this.q * toxY - this.q
438-
const x2 = this.q * toxX + this.q
439-
const y2 = 1 - this.q * toxY
438+
const b = 16 / 1296
439+
const q = 48 / 1296
440+
const x1 = q * toxX + b
441+
const y1 = 1 - q * toxY - q + b
442+
const x2 = x1 + q - 2 * b
443+
const y2 = y1 + q - 2 * b
440444
return [
441445
[x1, y1],
442446
[x1, y2],

src/scripts/world/World.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ const World = class World {
4545
}
4646

4747
updateRenderOrder (cell) {
48-
for (const [k,v] of this.chunkManager.cellMesh) {
48+
for (const [k, v] of this.chunkManager.cellMesh) {
4949
const x = vec3(this.chunkTerrain.strToVec(k))
50-
v.renderOrder=-vec3(...cell).distanceTo(x)
50+
v.renderOrder = -vec3(...cell).distanceTo(x)
5151
}
5252
}
5353

0 commit comments

Comments
 (0)