Skip to content

Commit 18e5b52

Browse files
committed
Bounding box generator fixes
Skip exporting bounding box-only group into bedrock geo
1 parent 4a05651 commit 18e5b52

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

js/formats/bedrock/bedrock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ window.calculateVisibleBox = calculateVisibleBox;
938938
function compileGroup(g) {
939939
if (g.type !== 'group' || g.export == false) return;
940940
if (!settings.export_empty_groups.value && !g.children.find(child => child.export)) return;
941+
if (g.children.length && g.children.allAre(c => c instanceof BoundingBox)) return;
941942
//Bone
942943
var bone = {}
943944
bone.name = g.name

js/modeling/generate_bounding_box.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,19 @@ BARS.defineActions(() => {
107107
for (let x = start[0]; x < end[0]; x++) {
108108
for (let z = start[2]; z < end[2]; z++) {
109109
for (let y = start[1]; y < end[1]; y++) {
110-
point.set(x+0.5, y+0.5, z+0.5);
111-
let in_shape = aabbs.some(box => box.containsPoint(point));
110+
point.set(x+0.46, y+0.46, z+0.46);
111+
let in_shape: any = aabbs.find(box => box.containsPoint(point));
112112
if (!in_shape && rotated_cubes.length) {
113113
raycaster.ray.origin.copy(point);
114-
in_shape = rotated_cubes.some(cube => {
114+
in_shape = rotated_cubes.find(cube => {
115115
let intersects = raycaster.intersectObject(cube.mesh);
116-
return intersects.length % 2 == 1;
116+
let intersection_points = [];
117+
for (let intersect of intersects) {
118+
if (!intersection_points.some(p => p.equals(intersect.point))) {
119+
intersection_points.push(intersect.point);
120+
}
121+
}
122+
return intersection_points.length % 2 == 1;
117123
})
118124
}
119125
matrix.set(x, y, z, !!in_shape);
@@ -246,6 +252,8 @@ BARS.defineActions(() => {
246252
}
247253
}
248254
}
255+
256+
// Grow
249257
for (let _i = 0; _i < grow_iterations; _i++) {
250258
let keys = Object.keys(matrix.values);
251259
let key = keys.findLast(key => matrix.values[key] == true);
@@ -280,7 +288,7 @@ BARS.defineActions(() => {
280288
let bb = new BoundingBox({
281289
from: [box[0], box[1], box[2]],
282290
to: [box[3]+1, box[4]+1, box[5]+1],
283-
color: i,
291+
color: 1,
284292
name: 'bounding_box'
285293
}).addTo().init();
286294
bounding_boxes.push(bb);

0 commit comments

Comments
 (0)