diff --git a/src/clients/reconstruction-client.js b/src/clients/reconstruction-client.js index 3e4cae49..cdc6c278 100644 --- a/src/clients/reconstruction-client.js +++ b/src/clients/reconstruction-client.js @@ -22,6 +22,7 @@ import { distanceFloats2Canvas, depthFloats2Canvas, } from '../generators/sg-debug.js'; +import { destructurePointCloud } from '../utils/point-cloud.js'; // @@ -462,7 +463,11 @@ export async function getPointCloud(blob, { }); if (res.ok) { const headers = Object.fromEntries(res.headers.entries()); - const arrayBuffer = await res.arrayBuffer(); + + // This will probably be handled server-side eventually. + const _arrayBuffer = await res.arrayBuffer(); + const arrayBuffer = destructurePointCloud(_arrayBuffer).points; + return { headers, arrayBuffer, @@ -516,4 +521,4 @@ export function pointCloudArrayBufferToColorAttributeArray(labelImageData, uint8 // none } } -} \ No newline at end of file +} diff --git a/src/utils/point-cloud.js b/src/utils/point-cloud.js new file mode 100644 index 00000000..3e5f8dd4 --- /dev/null +++ b/src/utils/point-cloud.js @@ -0,0 +1,39 @@ +import { pointCloudFullStride } from '../zine/zine-constants.js' + + +/** + * Destructure a point cloud into its component parts. + */ +export function destructurePointCloud(arrayBuffer) { + const numPoints = arrayBuffer.byteLength / pointCloudFullStride; + const points = new Float32Array(numPoints * 3); + const colors = new Uint8Array(numPoints * 3); + const intensities = new Uint8Array(numPoints); + const classifications = new Uint8Array(numPoints); + const dataView = new DataView(arrayBuffer); + + let pointIndex = 0; + let colorIndex = 0; + let intensityIndex = 0; + let classificationIndex = 0; + + for (let i = 0; i < arrayBuffer.byteLength; i += pointCloudFullStride) { + points[pointIndex++] = dataView.getFloat32(i, true); + points[pointIndex++] = dataView.getFloat32(i + 4, true); + points[pointIndex++] = dataView.getFloat32(i + 8, true); + + colors[colorIndex++] = arrayBuffer[i + 12]; + colors[colorIndex++] = arrayBuffer[i + 13]; + colors[colorIndex++] = arrayBuffer[i + 14]; + + intensities[intensityIndex++] = arrayBuffer[i + 15]; + classifications[classificationIndex++] = arrayBuffer[i + 16]; + } + + return { + points: points.buffer, + colors: colors.buffer, + intensities: intensities.buffer, + classifications: classifications.buffer, + }; +} diff --git a/src/zine b/src/zine index 0f31982b..ccfb4037 160000 --- a/src/zine +++ b/src/zine @@ -1 +1 @@ -Subproject commit 0f31982b9bc3ec848ce82d25a9383d5034f38439 +Subproject commit ccfb403754cd0f94a1c410dbda26dc37d33c5aab