Fix Hullhider.

This commit is contained in:
Lixfel
2024-12-11 15:03:32 +01:00
parent c308a06e6b
commit 429e2f86aa
@@ -47,6 +47,7 @@ public class Hull {
private final Region region; private final Region region;
private final boolean groundVisible; private final boolean groundVisible;
private final IntVector primaryDirection; private final IntVector primaryDirection;
private final IntVector[] directions;
private final IntVector[] branchDirections; private final IntVector[] branchDirections;
private final BitSet occluding; private final BitSet occluding;
@@ -65,10 +66,14 @@ public class Hull {
this.occluding = new BitSet(region.volume()); this.occluding = new BitSet(region.volume());
this.visibility = new BitSet(region.volume()); this.visibility = new BitSet(region.volume());
branchDirections = IntStream.range(0, 27) directions = IntStream.range(0, 27)
.mapToObj(v -> new IntVector(v%3 -1, (v/3)%3 -1, v/9 -1)) .mapToObj(v -> new IntVector(v%3 -1, (v/3)%3 -1, v/9 -1))
.filter(v -> v.sqLength() > 0)
.filter(v -> v.sqLength() <= 2)
.toArray(IntVector[]::new);
branchDirections = Arrays.stream(directions)
.filter(v -> v.x*primaryDirection.x + v.y*primaryDirection.y + v.z*primaryDirection.z >= 0) // Not pointing away from primary direction .filter(v -> v.x*primaryDirection.x + v.y*primaryDirection.y + v.z*primaryDirection.z >= 0) // Not pointing away from primary direction
.filter(v -> v.x*v.x + v.y*v.y + v.z*v.z == 2) // Diagonal .filter(v -> v.sqLength() == 2) // Diagonal
.toArray(IntVector[]::new); .toArray(IntVector[]::new);
} }
@@ -162,9 +167,9 @@ public class Hull {
return; return;
List<IntVector> uncovered = new ArrayList<>(); List<IntVector> uncovered = new ArrayList<>();
int directions = visibilityDirections.remove(id); int visibleDirections = visibilityDirections.remove(id);
for(IntVector direction : branchDirections) { for(IntVector direction : directions) {
if((directionId(direction) & directions) != 0) if((directionId(direction) & visibleDirections) != 0)
updateBlocks(uncovered, root, direction); updateBlocks(uncovered, root, direction);
} }
@@ -293,6 +298,10 @@ public class Hull {
return add(v.x, v.y, v.z); return add(v.x, v.y, v.z);
} }
public int sqLength() {
return x*x + y*y + z*z;
}
@Override @Override
public int hashCode() { public int hashCode() {
return y << 24 ^ x << 12 ^ z; return y << 24 ^ x << 12 ^ z;