1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package makamys.neodymium.renderer;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import makamys.neodymium.Config;
import makamys.neodymium.renderer.ChunkMesh.Flags;
public class CullableMeshCollection {
private ChunkMesh[] meshes = new ChunkMesh[QuadNormal.values().length];
public CullableMeshCollection(int x, int y, int z, Flags flags, int quadCount, List<MeshQuad> quads, int pass) {
if(Config.cullFaces) {
for(QuadNormal normal : QuadNormal.values()) {
List<MeshQuad> normalQuads = quads.stream().filter(q -> MeshQuad.isValid(q) && q.normal == normal).collect(Collectors.toList());
if(!normalQuads.isEmpty()) {
putMeshWithNormal(normal, new ChunkMesh(x, y, z, flags, normalQuads.size(), normalQuads, pass));
getMeshWithNormal(normal).normal = normal;
}
}
} else {
putMeshWithNormal(QuadNormal.NONE, new ChunkMesh(x, y, z, flags, quadCount, quads, pass));
}
}
public ChunkMesh getMeshWithNormal(QuadNormal normal) {
return meshes[normal.ordinal()];
}
public void putMeshWithNormal(QuadNormal normal, ChunkMesh mesh) {
meshes[normal.ordinal()] = mesh;
}
public List<ChunkMesh> getMeshes() {
return Arrays.asList(meshes);
}
public void destroy() {
for(ChunkMesh mesh : meshes) {
if(mesh != null) mesh.destroy();
}
}
public boolean isVisible() {
for(ChunkMesh mesh : meshes) {
if(mesh != null && mesh.visible) return true;
}
return false;
}
}
|