Skip to content

Commit

Permalink
Add tests showing AVERAGE spit failure
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Jul 12, 2019
1 parent 2fa1b30 commit e5fd25b
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions test/AverageSplit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import * as THREE from 'three';
import { MeshBVH, acceleratedRaycast, computeBoundsTree, disposeBoundsTree, CENTER, SAH, AVERAGE } from '../src/index.js';
import fs from 'fs';
import path from 'path';

const dataPath = path.resolve( __dirname, './data/points.bin' );
const buffer = fs.readFileSync( dataPath );
const points = new Float32Array( buffer.buffer, buffer.byteOffset, buffer.byteLength / 4 );

THREE.Mesh.prototype.raycast = acceleratedRaycast;
THREE.BufferGeometry.prototype.computeBoundsTree = computeBoundsTree;
THREE.BufferGeometry.prototype.disposeBoundsTree = disposeBoundsTree;

describe( 'AVERAGE Points Raycast', () => {

let geometry = null;
let mesh = null;
let raycaster = null;
beforeEach( () => {

geometry = new THREE.BufferGeometry();
geometry.addAttribute( 'position', new THREE.BufferAttribute( points, 3 ) );
geometry.computeVertexNormals();

mesh = new THREE.Mesh( geometry );

raycaster = new THREE.Raycaster();
raycaster.firstHitOnly = true;

const x = 101086.2438562272;
const y = 99421.40510391879;
raycaster.set( new THREE.Vector3( x, y, - 1000 ), new THREE.Vector3( 0, 0, 1 ) );

} );

it( 'should collide against the geometry with CENTER split', () => {

geometry.boundsTree = new MeshBVH( geometry, {
strategy: CENTER,
maxDepth: 64,
maxLeafTris: 16
} );

const res1 = raycaster.intersectObject( mesh );

geometry.boundsTree = null;
const res2 = raycaster.intersectObject( mesh );

expect( res1 ).toEqual( res2 );

} );

it( 'should collide against the geometry with SAH split', () => {

geometry.boundsTree = new MeshBVH( geometry, {
strategy: SAH,
maxDepth: 64,
maxLeafTris: 16
} );

const res1 = raycaster.intersectObject( mesh );

geometry.boundsTree = null;
const res2 = raycaster.intersectObject( mesh );

expect( res1 ).toEqual( res2 );

} );

it( 'should collide against the geometry with AVERAGE split', () => {

geometry.boundsTree = new MeshBVH( geometry, {
strategy: AVERAGE,
maxDepth: 64,
maxLeafTris: 16
} );

const res1 = raycaster.intersectObject( mesh );

geometry.boundsTree = null;
const res2 = raycaster.intersectObject( mesh );

res1.length && delete res1[ 0 ].object;
res2.length && delete res2[ 0 ].object;

expect( res1 ).toEqual( res2 );

} );

} );
Binary file added test/data/points.bin
Binary file not shown.

0 comments on commit e5fd25b

Please sign in to comment.