Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix blocks overflowing over the top of octree bounds #1768

Merged
merged 5 commits into from
Sep 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -1443,18 +1443,23 @@ private int calculateOctreeOrigin(Collection<ChunkPosition> chunksToLoad, boolea
zmin *= 16;
zmax *= 16;

int maxDimension = Math.max(yMax - yMin, Math.max(xmax - xmin, zmax - zmin));
int requiredDepth = QuickMath.log2(QuickMath.nextPow2(maxDimension));

int requiredDepth;
if(centerOctree) {
int maxDimension = Math.max(yMax - yMin, Math.max(xmax - xmin, zmax - zmin));
requiredDepth = QuickMath.log2(QuickMath.nextPow2(maxDimension));

int xroom = (1 << requiredDepth) - (xmax - xmin);
int yroom = (1 << requiredDepth) - (yMax - yMin);
int zroom = (1 << requiredDepth) - (zmax - zmin);

origin.set(xmin - xroom / 2, -yroom / 2, zmin - zroom / 2);
} else {
// Note: Math.floorDiv rather than integer division for round toward -infinity
origin.set(xmin, Math.floorDiv(yMin, 16) * 16, zmin);
int yMin16 = yMin & ~0xf; // closest multiple of 16 below yMin
leMaik marked this conversation as resolved.
Show resolved Hide resolved

int maxDimension = Math.max(yMax - yMin16, Math.max(xmax - xmin, zmax - zmin));
requiredDepth = QuickMath.log2(QuickMath.nextPow2(maxDimension));

origin.set(xmin, yMin16, zmin);
}
return requiredDepth;
}
Expand Down