From 971985dfae2d7c496787a5df5f7211fef206fc34 Mon Sep 17 00:00:00 2001 From: William Chilcote Date: Sat, 14 Sep 2024 19:05:31 -0700 Subject: [PATCH] Blend depth seams --- script.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/script.js b/script.js index 36ce2d4..9291bfc 100644 --- a/script.js +++ b/script.js @@ -161,6 +161,7 @@ function applyDepthDistortion(geometry, depthMap) { const positionAttribute = geometry.attributes.position; const uv = geometry.attributes.uv; + // Apply depth distortion to all vertices for (let i = 0; i < positionAttribute.count; i++) { const x = positionAttribute.getX(i); const y = positionAttribute.getY(i); @@ -178,6 +179,23 @@ function applyDepthDistortion(geometry, depthMap) { positionAttribute.setXYZ(i, x * distortionFactor, y * distortionFactor, z * distortionFactor); } + // Synchronize seam vertices to remove the gap + const widthSegments = geometry.parameters.widthSegments; + const heightSegments = geometry.parameters.heightSegments; + + for (let phi = 0; phi <= heightSegments; phi++) { + const firstIndex = phi * (widthSegments + 1); + const lastIndex = firstIndex + widthSegments; + + // Get the position from the first vertex in the ring + const x = positionAttribute.getX(firstIndex); + const y = positionAttribute.getY(firstIndex); + const z = positionAttribute.getZ(firstIndex); + + // Set the position of the last vertex in the ring to match the first + positionAttribute.setXYZ(lastIndex, x, y, z); + } + positionAttribute.needsUpdate = true; }