Skip to content

Commit 271a103

Browse files
authored
Merge pull request #20366 from manthrax/fix-raycast-line-interleavedbufferattribute
Line: Add support for interleaved geometries in raycast().
2 parents fbea62b + 9fb4bb7 commit 271a103

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/objects/Line.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
128128
const vEnd = new Vector3();
129129
const interSegment = new Vector3();
130130
const interRay = new Vector3();
131-
const step = ( this && this.isLineSegments ) ? 2 : 1;
131+
const step = this.isLineSegments ? 2 : 1;
132132

133133
if ( geometry.isBufferGeometry ) {
134134

135135
const index = geometry.index;
136136
const attributes = geometry.attributes;
137-
const positions = attributes.position.array;
137+
const positionAttr = attributes.position;
138138

139139
if ( index !== null ) {
140140

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

148-
vStart.fromArray( positions, a * 3 );
149-
vEnd.fromArray( positions, b * 3 );
148+
vStart.fromBufferAttribute( positionAttr, a );
149+
vEnd.fromBufferAttribute( positionAttr, b );
150150

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

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

176176
} else {
177177

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

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

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

0 commit comments

Comments
 (0)