From 0f73a9dd9f32431d565f94fe2974a67bf263a7bb Mon Sep 17 00:00:00 2001 From: Tim Deubler Date: Wed, 10 Jul 2024 13:06:27 +0200 Subject: [PATCH] fixed ray intersection on 2d line geometry Signed-off-by: Tim Deubler --- .../webgl/buffer/templates/LineBuffer.ts | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/packages/display/src/displays/webgl/buffer/templates/LineBuffer.ts b/packages/display/src/displays/webgl/buffer/templates/LineBuffer.ts index 80f725f39..e924d1920 100644 --- a/packages/display/src/displays/webgl/buffer/templates/LineBuffer.ts +++ b/packages/display/src/displays/webgl/buffer/templates/LineBuffer.ts @@ -74,10 +74,7 @@ export class LineBuffer extends TemplateBuffer { const scaleByAltitude = buffer.getUniform('u_scaleByAltitude'); const N_SCALE = 1.0 / 8192.0; - - const stride = size * 3; let index; - const m3 = rayCaster.sMat[3]; const m7 = rayCaster.sMat[7]; const m11 = rayCaster.sMat[11]; @@ -93,13 +90,11 @@ export class LineBuffer extends TemplateBuffer { const dy0 = (ny0 & 1) * 2 - 1; ny0 = dy0 * (ny0 >> 1) * N_SCALE; - let x0 = position[i]; - let y0 = position[i + 1]; - let z0 = size == 3 ? -position[i + 2] : 0; + let x0 = position[i++]; + let y0 = position[i++]; + let z0 = size == 3 ? -position[i++] : 0; // convert normalized int16 to float meters (-500m ... +9000m) // z0 = (z0 - 32267.0) * 0.14496292001098665; - - let nx1 = normal[n + 4]; let ny1 = normal[n + 5]; @@ -109,9 +104,10 @@ export class LineBuffer extends TemplateBuffer { const dy1 = (ny1 & 1) * 2 - 1; ny1 = dy1 * (ny1 >> 1) * N_SCALE; - let x1 = position[i + 3]; - let y1 = position[i + 4]; - let z1 = size == 3 ? -position[i + 5] : 0; + + let x1 = position[i++]; + let y1 = position[i++]; + let z1 = size == 3 ? -position[i++] : 0; let nx2 = normal[n + 8]; let ny2 = normal[n + 9]; @@ -122,10 +118,9 @@ export class LineBuffer extends TemplateBuffer { const dy2 = (ny2 & 1) * 2 - 1; ny2 = dy2 * (ny2 >> 1) * N_SCALE; - let x2 = position[i + 6]; - let y2 = position[i + 7]; - let z2 = size == 3 ? -position[i + 8] : 0; - + let x2 = position[i++]; + let y2 = position[i++]; + let z2 = size == 3 ? -position[i++] : 0; const tileX0 = tileX + x0; const tileY0 = tileY + y0; @@ -144,15 +139,12 @@ export class LineBuffer extends TemplateBuffer { t2[1] = tileY + y2 + ny2 * strokeWidth * scaleDZ; t2[2] = z2; - let intersectRayLength = Raycaster.rayIntersectsTriangle( rayOrigin, rayDirection, t0, t1, t2 ); - i += stride; - if (intersectRayLength != null) { if (intersectRayLength <= result.z) { result.z = intersectRayLength;