Skip to content

Commit

Permalink
Fix cast function generation
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Mar 2, 2021
1 parent f5d41ab commit 11f8d11
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
35 changes: 14 additions & 21 deletions scripts/generate-cast-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,6 @@ const path = require( 'path' );
// a function definition so we can replace that with local variable definitions we need.
function replaceUnneededCode( str ) {

str = str.replace(
/if \( [^)]*node.continueGeneration \)(.|\n|\r)*?}[\r|\n]/mg,
match => {

if ( match.indexOf( '/* skip */' ) !== - 1 ) {

return '';

} else {

return 'let stride2Offset = stride4Offset * 2, ' +
'float32Array = _float32Array, ' +
'uint16Array = _uint16Array, ' +
'uint32Array = _uint32Array;\n';

}

}

);

str = str.replace( /function intersectRay\((.|[\r\n])*?}[\r|\n]/mg, '' );

str = str.replace( /import { arrayToBox.*?;[\r\n]/g, '' );
Expand Down Expand Up @@ -152,6 +131,20 @@ function replaceFunctionNames( str ) {
}
);

str = str.replace(
new RegExp( `\n(.+?)${ orNames }.+? {`, 'gm' ),
match => {

const whitespace = match.match( /^\s+/ )[ 0 ];
return match + '\n' + whitespace + '\t' +
'let stride2Offset = stride4Offset * 2, ' +
'float32Array = _float32Array, ' +
'uint16Array = _uint16Array, ' +
'uint32Array = _uint32Array;\n';

}
);

return str;

}
Expand Down
6 changes: 4 additions & 2 deletions src/castFunctionsBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export function raycastFirstBuffer( stride4Offset, mesh, raycaster, ray ) {

export const shapecastBuffer = ( function () {

let stride2Offset = stride4Offset * 2, float32Array = _float32Array, uint16Array = _uint16Array, uint32Array = _uint32Array;

const _triangle = new SeparatingAxisTriangle();
const _cachedBox1 = new Box3();
const _cachedBox2 = new Box3();
Expand Down Expand Up @@ -192,8 +194,6 @@ export const shapecastBuffer = ( function () {

}

let stride2Offset = stride4Offset * 2, float32Array = _float32Array, uint16Array = _uint16Array, uint32Array = _uint32Array;

const isLeaf = ! /* node count */ ( uint16Array[ stride2Offset + 15 ] !== 0xffff );
if ( isLeaf && intersectsTriangleFunc ) {

Expand Down Expand Up @@ -327,6 +327,8 @@ export const shapecastBuffer = ( function () {

export const intersectsGeometryBuffer = ( function () {

let stride2Offset = stride4Offset * 2, float32Array = _float32Array, uint16Array = _uint16Array, uint32Array = _uint32Array;

const triangle = new SeparatingAxisTriangle();
const triangle2 = new SeparatingAxisTriangle();
const cachedMesh = new Mesh();
Expand Down

0 comments on commit 11f8d11

Please sign in to comment.