Smarter translucency sorting #42
+59
-18
@@ -89,25 +89,18 @@ public final class PartitionTree implements SortState.Resortable {
|
||||
return partitionIntersectors(quads, group, collectedCuts);
|
||||
}
|
||||
|
||||
Buckets buckets = bucket(quads, group, axis, planes);
|
||||
|
||||
// gaps between quads that are all parallel would only slice one static leaf into pieces, each gap a trigger
|
||||
// plane: keep just the cuts carrying quads on the plane (some do, else the group itself was parallel)
|
||||
float[] carrying = planesWithQuads(planes, buckets.onPlane);
|
||||
if (carrying.length > 0 && carrying.length < planes.length && allParallel(quads, buckets.slabs)) {
|
||||
planes = carrying;
|
||||
buckets = bucket(quads, group, axis, planes);
|
||||
}
|
||||
|
||||
IntArrayList[] onPlaneLists = buckets.onPlane, slabLists = buckets.slabs;
|
||||
int slabCount = planes.length + 1;
|
||||
IntArrayList[] onPlaneLists = new IntArrayList[planes.length];
|
||||
for (int i = 0; i < planes.length; i++) onPlaneLists[i] = new IntArrayList();
|
||||
IntArrayList[] slabLists = new IntArrayList[slabCount];
|
||||
for (int i = 0; i < slabCount; i++) slabLists[i] = new IntArrayList();
|
||||
|
||||
for (int quad : group) {
|
||||
float lo = quads.boundsMin(quad, axis), hi = quads.boundsMax(quad, axis);
|
||||
|
||||
// slab = number of planes at or below this quad's lo
|
||||
int slab = 0;
|
||||
while (slab < planes.length && planes[slab] <= lo + QuadSet.EPSILON) slab++;
|
||||
|
||||
if (hi - lo <= QuadSet.EPSILON && slab > 0 && Math.abs(planes[slab - 1] - lo) <= QuadSet.EPSILON) {
|
||||
onPlaneLists[slab - 1].add(quad);
|
||||
} else {
|
||||
slabLists[slab].add(quad);
|
||||
}
|
||||
}
|
||||
|
||||
Node[] slabs = new Node[slabCount];
|
||||
for (int i = 0; i < slabCount; i++) {
|
||||
@@ -132,6 +125,54 @@ public final class PartitionTree implements SortState.Resortable {
|
||||
return new Split(axis, planes, slabs, onPlane);
|
||||
}
|
||||
|
||||
private record Buckets(IntArrayList[] onPlane, IntArrayList[] slabs) {}
|
||||
|
||||
/** sorts the group into the quads lying on each plane and those in each slab between the planes */
|
||||
private static Buckets bucket(QuadSet quads, int[] group, int axis, float[] planes) {
|
||||
IntArrayList[] onPlane = new IntArrayList[planes.length];
|
||||
for (int i = 0; i < planes.length; i++) onPlane[i] = new IntArrayList();
|
||||
IntArrayList[] slabs = new IntArrayList[planes.length + 1];
|
||||
for (int i = 0; i <= planes.length; i++) slabs[i] = new IntArrayList();
|
||||
|
||||
for (int quad : group) {
|
||||
float lo = quads.boundsMin(quad, axis), hi = quads.boundsMax(quad, axis);
|
||||
|
||||
// slab = number of planes at or below this quad's lo
|
||||
int slab = 0;
|
||||
while (slab < planes.length && planes[slab] <= lo + QuadSet.EPSILON) slab++;
|
||||
|
||||
if (hi - lo <= QuadSet.EPSILON && slab > 0 && Math.abs(planes[slab - 1] - lo) <= QuadSet.EPSILON) {
|
||||
onPlane[slab - 1].add(quad);
|
||||
} else {
|
||||
slabs[slab].add(quad);
|
||||
}
|
||||
}
|
||||
return new Buckets(onPlane, slabs);
|
||||
}
|
||||
|
||||
private static float[] planesWithQuads(float[] planes, IntArrayList[] onPlane) {
|
||||
FloatArrayList kept = new FloatArrayList(planes.length);
|
||||
for (int i = 0; i < planes.length; i++) {
|
||||
if (!onPlane[i].isEmpty()) kept.add(planes[i]);
|
||||
}
|
||||
return kept.toFloatArray();
|
||||
}
|
||||
|
||||
private static boolean allParallel(QuadSet quads, IntArrayList[] slabs) {
|
||||
int reference = -1;
|
||||
for (IntArrayList slab : slabs) {
|
||||
for (int i = 0; i < slab.size(); i++) {
|
||||
int quad = slab.getInt(i);
|
||||
if (reference < 0) {
|
||||
reference = quad;
|
||||
} else if (Math.abs(quads.normalDot(quad, reference)) < 1 - QuadSet.EPSILON) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static @Nullable Node partitionIntersectors(QuadSet quads, int[] group, FloatArrayList[] collectedCuts) {
|
||||
int n = group.length;
|
||||
if (n > TranslucentSorter.MAX_TOPO_QUADS) return null;
|
||||
|
||||
Reference in new issue
Block a user