From f28ce791e25e93c9c6550ffd93dff1dbd8d483d9 Mon Sep 17 00:00:00 2001 From: guhao Date: Tue, 16 May 2023 10:34:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BC=BA=E5=BA=A6=E5=85=BC=E5=AE=B90-1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../packages/pc-render/loader/PCDLoader.ts | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/frontend/pc-tool/src/packages/pc-render/loader/PCDLoader.ts b/frontend/pc-tool/src/packages/pc-render/loader/PCDLoader.ts index 392f53b0..af1b12b0 100644 --- a/frontend/pc-tool/src/packages/pc-render/loader/PCDLoader.ts +++ b/frontend/pc-tool/src/packages/pc-render/loader/PCDLoader.ts @@ -1,4 +1,4 @@ -import { FileLoader, Loader, LoaderUtils } from 'three'; +import { FileLoader, Loader, LoaderUtils, MathUtils } from 'three'; type ICallBack = (args?: any) => void; type PCDData = 'ascii' | 'binary_compressed' | 'binary'; @@ -182,8 +182,8 @@ class PCDLoader extends Loader { const position = []; // const normal = []; const color = []; - const intensity = []; - + let intensity = []; + let maxIntensity = -Infinity; // ascii let N = 1; @@ -218,12 +218,16 @@ class PCDLoader extends Loader { } if (offset.i !== undefined) { // [...Array(N)].forEach((e) => { - intensity.push(parseFloat(line[offset.i])); + const _i = parseFloat(line[offset.i]); + intensity.push(_i); + maxIntensity = Math.max(_i, maxIntensity); // }); } if (offset.intensity !== undefined) { // [...Array(N)].forEach((e) => { - intensity.push(parseFloat(line[offset.intensity])); + const _i = parseFloat(line[offset.intensity]); + intensity.push(_i); + maxIntensity = Math.max(_i, maxIntensity); // }); } // if (offset.normal_x !== undefined) { @@ -323,9 +327,13 @@ class PCDLoader extends Loader { } if (offset.i !== undefined) { - intensity.push(dataview.getFloat32(row + offset.i, this.littleEndian)); + const _i = dataview.getFloat32(row + offset.i, this.littleEndian); + intensity.push(_i); + maxIntensity = Math.max(_i, maxIntensity); } else if (offset.intensity !== undefined) { - intensity.push(dataview.getFloat32(row + offset.intensity, this.littleEndian)); + const _i = dataview.getFloat32(row + offset.intensity, this.littleEndian); + intensity.push(_i); + maxIntensity = Math.max(_i, maxIntensity); } if (offset.rgb !== undefined) { @@ -341,7 +349,9 @@ class PCDLoader extends Loader { // } } } - + if (maxIntensity > 255 || maxIntensity < 2) { + intensity = intensity.map((i) => MathUtils.mapLinear(i, 0, maxIntensity, 0, 255)); + } // build geometry return { position,