Skip to content

Commit 6ce6749

Browse files
committed
Merge remote-tracking branch 'origin/dev' into dev
2 parents 805153c + 695afa6 commit 6ce6749

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

frontend/pc-tool/src/packages/pc-render/loader/PCDLoader.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FileLoader, Loader, LoaderUtils } from 'three';
1+
import { FileLoader, Loader, LoaderUtils, MathUtils } from 'three';
22

33
type ICallBack = (args?: any) => void;
44
type PCDData = 'ascii' | 'binary_compressed' | 'binary';
@@ -182,8 +182,8 @@ class PCDLoader extends Loader {
182182
const position = [];
183183
// const normal = [];
184184
const color = [];
185-
const intensity = [];
186-
185+
let intensity = [];
186+
let maxIntensity = -Infinity;
187187
// ascii
188188

189189
let N = 1;
@@ -218,12 +218,16 @@ class PCDLoader extends Loader {
218218
}
219219
if (offset.i !== undefined) {
220220
// [...Array(N)].forEach((e) => {
221-
intensity.push(parseFloat(line[offset.i]));
221+
const _i = parseFloat(line[offset.i]);
222+
intensity.push(_i);
223+
maxIntensity = Math.max(_i, maxIntensity);
222224
// });
223225
}
224226
if (offset.intensity !== undefined) {
225227
// [...Array(N)].forEach((e) => {
226-
intensity.push(parseFloat(line[offset.intensity]));
228+
const _i = parseFloat(line[offset.intensity]);
229+
intensity.push(_i);
230+
maxIntensity = Math.max(_i, maxIntensity);
227231
// });
228232
}
229233
// if (offset.normal_x !== undefined) {
@@ -323,9 +327,13 @@ class PCDLoader extends Loader {
323327
}
324328

325329
if (offset.i !== undefined) {
326-
intensity.push(dataview.getFloat32(row + offset.i, this.littleEndian));
330+
const _i = dataview.getFloat32(row + offset.i, this.littleEndian);
331+
intensity.push(_i);
332+
maxIntensity = Math.max(_i, maxIntensity);
327333
} else if (offset.intensity !== undefined) {
328-
intensity.push(dataview.getFloat32(row + offset.intensity, this.littleEndian));
334+
const _i = dataview.getFloat32(row + offset.intensity, this.littleEndian);
335+
intensity.push(_i);
336+
maxIntensity = Math.max(_i, maxIntensity);
329337
}
330338

331339
if (offset.rgb !== undefined) {
@@ -341,7 +349,9 @@ class PCDLoader extends Loader {
341349
// }
342350
}
343351
}
344-
352+
if (maxIntensity > 255 || maxIntensity < 2) {
353+
intensity = intensity.map((i) => MathUtils.mapLinear(i, 0, maxIntensity, 0, 255));
354+
}
345355
// build geometry
346356
return {
347357
position,

0 commit comments

Comments
 (0)