diff --git a/src/info/ata4/bspsrc/modules/entity/EntitySource.java b/src/info/ata4/bspsrc/modules/entity/EntitySource.java index 907d1c3e..17d7f5a4 100644 --- a/src/info/ata4/bspsrc/modules/entity/EntitySource.java +++ b/src/info/ata4/bspsrc/modules/entity/EntitySource.java @@ -351,8 +351,6 @@ public void writeDetails() { if (config.detailMerge) { Queue> detailBrushes = new ArrayDeque<>(); Map detailBrushIndices = new HashMap<>(); - Vector3f vex = new Vector3f(config.detailMergeThresh, - config.detailMergeThresh, config.detailMergeThresh); // add all detail brushes to queue for (int i = 0; i < bsp.brushes.size(); i++) { @@ -371,9 +369,6 @@ public void writeDetails() { // get bounding box of the detail brush AABB bounds = BrushUtils.getBounds(bsp, brush); - // expand bb so it can touch the bbs of other brushes - bounds.expand(vex); - detailBrushes.add(new ImmutablePair<>(brush, bounds)); detailBrushIndices.put(brush, i); } @@ -387,7 +382,7 @@ public void writeDetails() { detailBrushClump.add(detailBrush1); // move all touching brushes from the queue to this clump - clumpBrushes(detailBrushes, detailBrushClump, detailBrush1); + clumpBrushes(detailBrushes, detailBrushClump, detailBrush1, config.detailMergeThresh); // write brush clump as func_detail to VMF writer.start("entity"); @@ -444,16 +439,20 @@ public void writeDetails() { * * @param src global brush collection * @param dst clumped brush collection + * @param thresh touching threshold * @param target search brush */ - private void clumpBrushes(Collection> src, Collection> dst, Pair target) { + private void clumpBrushes(Collection> src, Collection> dst, Pair target, float thresh) { + // expand bb so it can touch the bbs of other brushes + AABB targetBounds = target.getRight().expand(thresh); + Iterator> iter = src.iterator(); while (iter.hasNext()) { // get next brush Pair other = iter.next(); // is it touching the target brush? - if (other.getRight().intersectsWith(target.getRight())) { + if (other.getRight().intersectsWith(targetBounds)) { // put it to destination collection dst.add(other); @@ -461,7 +460,7 @@ private void clumpBrushes(Collection> src, Collection this.min.y && that.min.y < this.max.y && that.max.z > this.min.z && that.min.z < this.max.z; } - - public void include(AABB that) { - min = min.min(that.min); - max = max.max(that.max); + + public AABB include(AABB that) { + return new AABB(min.min(that.min), max.max(that.max)); + } + + public AABB expand(Vector3f v) { + return new AABB(min.sub(v), max.add(v)); } - public void expand(Vector3f v) { - min = min.sub(v); - max = max.add(v); + public AABB expand(float e) { + return expand(new Vector3f(e, e, e)); } @Override