diff --git a/app/src/main/java/com/google/ar/core/examples/java/common/framework/physics/BoundingBoxVisitor.java b/app/src/main/java/com/google/ar/core/examples/java/common/framework/physics/BoundingBoxVisitor.java index 371ab9f..91feb2b 100644 --- a/app/src/main/java/com/google/ar/core/examples/java/common/framework/physics/BoundingBoxVisitor.java +++ b/app/src/main/java/com/google/ar/core/examples/java/common/framework/physics/BoundingBoxVisitor.java @@ -13,15 +13,15 @@ private ArrayList bsStack = new ArrayList(); // オブジェクトの階層毎のBoundingSphereのスタック private String partName = null; // 部品を指定する場合に使う private boolean inPart = false; - + public BoundingBoxVisitor() { partName = null; } - + public BoundingBoxVisitor(String partName) { this.partName = partName; } - + public void preVisit(Object3D obj) { pushTransform(obj); if (partName != null && obj.name.equals(partName)) { @@ -42,12 +42,12 @@ if (obj.bs == null) { obj.bs = obb.getBoundingSphere(); } - + obb = (OBB)obb.clone(); BoundingSphere bs = (BoundingSphere)obj.bs.clone(); for (int i = stackList.size() - 1; i >= 0; i--) { obb.transform(stackList.get(i)); - bs.transform(stackList.get(i)); + if (i >= stackList.size() - 4) bs.transform(stackList.get(i)); } if (partName == null || partName.length() == 0 || inPart) { obbList.add(obb); // Transform3Dを適応させたBoundsをboundsListに追加 @@ -72,12 +72,16 @@ stackTop--; } if (obj.bs != null && stackTop >= 0) { + BoundingSphere bs = (BoundingSphere)obj.bs.clone(); + for (int i = stackList.size() - 1; i >= stackList.size() - 4; i--) { + bs.transform(stackList.get(i)); + } if (bsStack.get(stackTop) == null) { // その階層の最初のオブジェクトの場合、nullを置き換え - bsStack.set(stackTop, obj.bs); + bsStack.set(stackTop, bs); } else { // その階層の2番目以降のオブジェクトの場合、結合 - bsStack.get(stackTop).combine(obj.bs); + bsStack.get(stackTop).combine(bs); } } }