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

Commit

Permalink
Fix incorrect BVH (#93)
Browse files Browse the repository at this point in the history
* move centroid check

* add reflecting material that tests bvh

* better comment
  • Loading branch information
Lucas Crane authored May 9, 2020
1 parent 1e51e88 commit f56fc43
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
40 changes: 26 additions & 14 deletions scenes/renderer-test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,32 @@ function init() {
model.add(mesh);
}

let unreadyMat;
{
// Create a test (non-buffer) Geometry
const geo = new THREE.BoxGeometry(20, 6, 6);
const mat = new THREE.MeshStandardMaterial();
mat.roughness = 0.2;
mat.metalness = 0.0;
mat.color.set(0x993311);
unreadyMat = mat;
const mesh = new THREE.Mesh(geo, mat);
mesh.position.set(0, 3, 30);
model.add(mesh);
}

// background mirror
// verifies BVH used in reflections
{
const geo = new THREE.PlaneBufferGeometry(40, 16);
const mat = new THREE.MeshStandardMaterial();
mat.roughness = 0.0;
mat.metalness = 1.0;
const mesh = new THREE.Mesh(geo, mat);
mesh.position.set(0, 8, 40);
model.add(mesh);
}

// ground plane
{
const geo = new THREE.PlaneBufferGeometry(1000, 1000);
Expand All @@ -219,20 +245,6 @@ function init() {
model.add(mesh);
}

let unreadyMat;
{
// Create a test (non-buffer) Geometry
const geo = new THREE.BoxGeometry(6, 6, 6);
const mat = new THREE.MeshStandardMaterial();
mat.roughness = 0.2;
mat.metalness = 0.0;
mat.color.set(0x993311);
unreadyMat = mat;
const mesh = new THREE.Mesh(geo, mat);
mesh.position.set(0, 3, 30);
model.add(mesh);
}

scene.add(model);

THREE.DefaultLoadingManager.onLoad = () => {
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/bvhAccel.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ function recursiveBuild(primitiveInfo, start, end) {
}
const dim = maximumExtent(centroidBounds);

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

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

Expand All @@ -167,7 +164,11 @@ function recursiveBuild(primitiveInfo, start, end) {
// surface area heuristic method
if (nPrimitives <= 4) {
nthElement(primitiveInfo, (a, b) => a.center[dim] < b.center[dim], start, end, mid);
} else if (centroidBounds.max[dim] === centroidBounds.min[dim]) {
// can't split primitives based on centroid bounds. terminate.
return makeLeafNode(primitiveInfo.slice(start, end), bounds);
} else {

const buckets = [];
for (let i = 0; i < 12; i++) {
buckets.push({
Expand Down

0 comments on commit f56fc43

Please sign in to comment.