Skip to content

Commit 20e21c4

Browse files
committed
remove some repeated code
1 parent 3f13458 commit 20e21c4

File tree

3 files changed

+27
-101
lines changed

3 files changed

+27
-101
lines changed

src/scripts/Setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as dat from 'three/examples/jsm/libs/dat.gui.module.js'
55
import { DistanceBasedFog } from './rendering/DistanceBasedFog.js'
66
import { UrlParams } from './UrlParams.js'
77
import { gpuInfo } from './additional/gpuInfo.js'
8-
import { World } from './world/World.js'
8+
import { World } from './world/'
99
import { InventoryBar } from './gui/InventoryBar.js'
1010
import { Chat } from './gui/Chat.js'
1111
import { Entities } from './rendering/Entities.js'

src/scripts/world/ChunkMesher.js

Lines changed: 26 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,19 @@ class ChunkMesher {
101101
}
102102

103103
genBlockFace (type, block, pos) {
104-
const uv = this.getUvForFace(block, type)
105-
// prettier-ignore
104+
let uv = this.getUvForFace(block, type)
105+
uv = [
106+
...uv[0],
107+
...uv[2],
108+
...uv[1],
109+
...uv[1],
110+
...uv[2],
111+
...uv[3]
112+
]
113+
const norm = []
114+
for (let i = 0; i < 6; i++) {
115+
norm.push(...this.neighbours[type])
116+
}
106117
switch (type) {
107118
case 'pz':
108119
return {
@@ -114,22 +125,8 @@ class ChunkMesher {
114125
0.5 + pos[0], -0.5 + pos[1], 0.5 + pos[2],
115126
0.5 + pos[0], 0.5 + pos[1], 0.5 + pos[2]
116127
],
117-
norm: [
118-
0, 0, 1,
119-
0, 0, 1,
120-
0, 0, 1,
121-
0, 0, 1,
122-
0, 0, 1,
123-
0, 0, 1
124-
],
125-
uv: [
126-
...uv[0],
127-
...uv[2],
128-
...uv[1],
129-
...uv[1],
130-
...uv[2],
131-
...uv[3]
132-
]
128+
norm,
129+
uv
133130
}
134131
case 'nx':
135132
return {
@@ -141,22 +138,8 @@ class ChunkMesher {
141138
0.5 + pos[0], -0.5 + pos[1], -0.5 + pos[2],
142139
0.5 + pos[0], 0.5 + pos[1], -0.5 + pos[2]
143140
],
144-
norm: [
145-
1, 0, 0,
146-
1, 0, 0,
147-
1, 0, 0,
148-
1, 0, 0,
149-
1, 0, 0,
150-
1, 0, 0
151-
],
152-
uv: [
153-
...uv[0],
154-
...uv[2],
155-
...uv[1],
156-
...uv[1],
157-
...uv[2],
158-
...uv[3]
159-
]
141+
norm,
142+
uv
160143
}
161144
case 'nz':
162145
return {
@@ -168,22 +151,8 @@ class ChunkMesher {
168151
-0.5 + pos[0], -0.5 + pos[1], -0.5 + pos[2],
169152
-0.5 + pos[0], 0.5 + pos[1], -0.5 + pos[2]
170153
],
171-
norm: [
172-
0, 0, -1,
173-
0, 0, -1,
174-
0, 0, -1,
175-
0, 0, -1,
176-
0, 0, -1,
177-
0, 0, -1
178-
],
179-
uv: [
180-
...uv[0],
181-
...uv[2],
182-
...uv[1],
183-
...uv[1],
184-
...uv[2],
185-
...uv[3]
186-
]
154+
norm,
155+
uv
187156
}
188157
case 'px':
189158
return {
@@ -195,22 +164,8 @@ class ChunkMesher {
195164
-0.5 + pos[0], -0.5 + pos[1], 0.5 + pos[2],
196165
-0.5 + pos[0], 0.5 + pos[1], 0.5 + pos[2]
197166
],
198-
norm: [
199-
-1, 0, 0,
200-
-1, 0, 0,
201-
-1, 0, 0,
202-
-1, 0, 0,
203-
-1, 0, 0,
204-
-1, 0, 0
205-
],
206-
uv: [
207-
...uv[0],
208-
...uv[2],
209-
...uv[1],
210-
...uv[1],
211-
...uv[2],
212-
...uv[3]
213-
]
167+
norm,
168+
uv
214169
}
215170
case 'py':
216171
return {
@@ -222,22 +177,8 @@ class ChunkMesher {
222177
-0.5 + pos[0], 0.5 + pos[1], -0.5 + pos[2],
223178
-0.5 + pos[0], 0.5 + pos[1], 0.5 + pos[2]
224179
],
225-
norm: [
226-
0, 1, 0,
227-
0, 1, 0,
228-
0, 1, 0,
229-
0, 1, 0,
230-
0, 1, 0,
231-
0, 1, 0
232-
],
233-
uv: [
234-
...uv[0],
235-
...uv[2],
236-
...uv[1],
237-
...uv[1],
238-
...uv[2],
239-
...uv[3]
240-
]
180+
norm,
181+
uv
241182
}
242183
case 'ny':
243184
return {
@@ -249,22 +190,8 @@ class ChunkMesher {
249190
-0.5 + pos[0], -0.5 + pos[1], 0.5 + pos[2],
250191
-0.5 + pos[0], -0.5 + pos[1], -0.5 + pos[2]
251192
],
252-
norm: [
253-
0, -1, 0,
254-
0, -1, 0,
255-
0, -1, 0,
256-
0, -1, 0,
257-
0, -1, 0,
258-
0, -1, 0
259-
],
260-
uv: [
261-
...uv[0],
262-
...uv[2],
263-
...uv[1],
264-
...uv[1],
265-
...uv[2],
266-
...uv[3]
267-
]
193+
norm,
194+
uv
268195
}
269196
}
270197
}
@@ -486,8 +413,7 @@ class ChunkMesher {
486413
}
487414
} else {
488415
if (
489-
nBlock.boundingBox !== 'block' ||
490-
nBlock.transparent
416+
nBlock.boundingBox !== 'block' || nBlock.transparent
491417
) {
492418
this.addFace(tVertexBuffer, VertexBuffer, side, pos)
493419
}

0 commit comments

Comments
 (0)