Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line: Add support for interleaved geometries in raycast(). #20366

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/objects/Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
const vEnd = new Vector3();
const interSegment = new Vector3();
const interRay = new Vector3();
const step = ( this && this.isLineSegments ) ? 2 : 1;
const step = this.isLineSegments ? 2 : 1;

if ( geometry.isBufferGeometry ) {

const index = geometry.index;
const attributes = geometry.attributes;
const positions = attributes.position.array;
const positionAttr = attributes.position;

if ( index !== null ) {

Expand All @@ -145,8 +145,8 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
const a = indices[ i ];
const b = indices[ i + 1 ];

vStart.fromArray( positions, a * 3 );
vEnd.fromArray( positions, b * 3 );
vStart.fromBufferAttribute( positionAttr, a );
vEnd.fromBufferAttribute( positionAttr, b );

const distSq = _ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );

Expand Down Expand Up @@ -175,10 +175,10 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), {

} else {

for ( let i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
for ( let i = 0, l = positionAttr.count - 1; i < l; i += step ) {

vStart.fromArray( positions, 3 * i );
vEnd.fromArray( positions, 3 * i + 3 );
vStart.fromBufferAttribute( positionAttr, i );
vEnd.fromBufferAttribute( positionAttr, i + 1 );

const distSq = _ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );

Expand Down