1
- import { FileLoader , Loader , LoaderUtils } from 'three' ;
1
+ import { FileLoader , Loader , LoaderUtils , MathUtils } from 'three' ;
2
2
3
3
type ICallBack = ( args ?: any ) => void ;
4
4
type PCDData = 'ascii' | 'binary_compressed' | 'binary' ;
@@ -182,8 +182,8 @@ class PCDLoader extends Loader {
182
182
const position = [ ] ;
183
183
// const normal = [];
184
184
const color = [ ] ;
185
- const intensity = [ ] ;
186
-
185
+ let intensity = [ ] ;
186
+ let maxIntensity = - Infinity ;
187
187
// ascii
188
188
189
189
let N = 1 ;
@@ -218,12 +218,16 @@ class PCDLoader extends Loader {
218
218
}
219
219
if ( offset . i !== undefined ) {
220
220
// [...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 ) ;
222
224
// });
223
225
}
224
226
if ( offset . intensity !== undefined ) {
225
227
// [...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 ) ;
227
231
// });
228
232
}
229
233
// if (offset.normal_x !== undefined) {
@@ -323,9 +327,13 @@ class PCDLoader extends Loader {
323
327
}
324
328
325
329
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 ) ;
327
333
} 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 ) ;
329
337
}
330
338
331
339
if ( offset . rgb !== undefined ) {
@@ -341,7 +349,9 @@ class PCDLoader extends Loader {
341
349
// }
342
350
}
343
351
}
344
-
352
+ if ( maxIntensity > 255 || maxIntensity < 2 ) {
353
+ intensity = intensity . map ( ( i ) => MathUtils . mapLinear ( i , 0 , maxIntensity , 0 , 255 ) ) ;
354
+ }
345
355
// build geometry
346
356
return {
347
357
position,
0 commit comments