Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit f56fc43

Browse files
author
Lucas Crane
authored
Fix incorrect BVH (#93)
* move centroid check * add reflecting material that tests bvh * better comment
1 parent 1e51e88 commit f56fc43

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

scenes/renderer-test/main.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,32 @@ function init() {
196196
model.add(mesh);
197197
}
198198

199+
let unreadyMat;
200+
{
201+
// Create a test (non-buffer) Geometry
202+
const geo = new THREE.BoxGeometry(20, 6, 6);
203+
const mat = new THREE.MeshStandardMaterial();
204+
mat.roughness = 0.2;
205+
mat.metalness = 0.0;
206+
mat.color.set(0x993311);
207+
unreadyMat = mat;
208+
const mesh = new THREE.Mesh(geo, mat);
209+
mesh.position.set(0, 3, 30);
210+
model.add(mesh);
211+
}
212+
213+
// background mirror
214+
// verifies BVH used in reflections
215+
{
216+
const geo = new THREE.PlaneBufferGeometry(40, 16);
217+
const mat = new THREE.MeshStandardMaterial();
218+
mat.roughness = 0.0;
219+
mat.metalness = 1.0;
220+
const mesh = new THREE.Mesh(geo, mat);
221+
mesh.position.set(0, 8, 40);
222+
model.add(mesh);
223+
}
224+
199225
// ground plane
200226
{
201227
const geo = new THREE.PlaneBufferGeometry(1000, 1000);
@@ -219,20 +245,6 @@ function init() {
219245
model.add(mesh);
220246
}
221247

222-
let unreadyMat;
223-
{
224-
// Create a test (non-buffer) Geometry
225-
const geo = new THREE.BoxGeometry(6, 6, 6);
226-
const mat = new THREE.MeshStandardMaterial();
227-
mat.roughness = 0.2;
228-
mat.metalness = 0.0;
229-
mat.color.set(0x993311);
230-
unreadyMat = mat;
231-
const mesh = new THREE.Mesh(geo, mat);
232-
mesh.position.set(0, 3, 30);
233-
model.add(mesh);
234-
}
235-
236248
scene.add(model);
237249

238250
THREE.DefaultLoadingManager.onLoad = () => {

src/renderer/bvhAccel.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ function recursiveBuild(primitiveInfo, start, end) {
149149
}
150150
const dim = maximumExtent(centroidBounds);
151151

152-
if (centroidBounds.max[dim] === centroidBounds.min[dim]) {
153-
return makeLeafNode(primitiveInfo.slice(start, end), bounds);
154-
}
155152

156153
let mid = Math.floor((start + end) / 2);
157154

@@ -167,7 +164,11 @@ function recursiveBuild(primitiveInfo, start, end) {
167164
// surface area heuristic method
168165
if (nPrimitives <= 4) {
169166
nthElement(primitiveInfo, (a, b) => a.center[dim] < b.center[dim], start, end, mid);
167+
} else if (centroidBounds.max[dim] === centroidBounds.min[dim]) {
168+
// can't split primitives based on centroid bounds. terminate.
169+
return makeLeafNode(primitiveInfo.slice(start, end), bounds);
170170
} else {
171+
171172
const buckets = [];
172173
for (let i = 0; i < 12; i++) {
173174
buckets.push({

0 commit comments

Comments
 (0)