@@ -7,33 +7,34 @@ import { OrbitControls } from "three-stdlib";
77import { Select , SelectChangeEvent , MenuItem } from "@mui/material" ;
88
99function parsePointCloud2 ( msg : any ) : THREE . Points {
10- const { data, point_step, fields } = msg ;
10+ const { data, point_step, is_bigendian , fields } = msg ;
1111 const positions : number [ ] = [ ] ;
1212 const colors : number [ ] = [ ] ;
13+ const littleEndian = ! is_bigendian ;
1314
1415 const fieldMap = Object . fromEntries (
1516 fields . map ( ( f : any ) => [ f . name , f . offset ] )
1617 ) ;
1718 const dv = new DataView ( data . buffer , data . byteOffset , data . byteLength ) ;
1819
1920 for ( let i = 0 ; i < data . length ; i += point_step ) {
20- const x = dv . getFloat32 ( i + fieldMap [ "x" ] , true ) ;
21- const y = dv . getFloat32 ( i + fieldMap [ "y" ] , true ) ;
22- const z = dv . getFloat32 ( i + fieldMap [ "z" ] , true ) ;
21+ const x = dv . getFloat32 ( i + fieldMap [ "x" ] , littleEndian ) ;
22+ const y = dv . getFloat32 ( i + fieldMap [ "y" ] , littleEndian ) ;
23+ const z = dv . getFloat32 ( i + fieldMap [ "z" ] , littleEndian ) ;
2324
2425 if ( ! Number . isFinite ( x ) || ! Number . isFinite ( y ) || ! Number . isFinite ( z ) )
2526 continue ;
2627
2728 positions . push ( x , y , z ) ;
2829
2930 if ( "rgba" in fieldMap ) {
30- const rgba = dv . getUint32 ( i + fieldMap [ "rgba" ] , true ) ;
31+ const rgba = dv . getUint32 ( i + fieldMap [ "rgba" ] , littleEndian ) ;
3132 const r = ( rgba >> 24 ) & 0xff ;
3233 const g = ( rgba >> 16 ) & 0xff ;
3334 const b = ( rgba >> 8 ) & 0xff ;
3435 colors . push ( r / 255 , g / 255 , b / 255 ) ;
3536 } else if ( "rgb" in fieldMap ) {
36- const rgb = dv . getUint32 ( i + fieldMap [ "rgb" ] , true ) ;
37+ const rgb = dv . getUint32 ( i + fieldMap [ "rgb" ] , littleEndian ) ;
3738 const r = ( rgb >> 16 ) & 0xff ;
3839 const g = ( rgb >> 8 ) & 0xff ;
3940 const b = rgb & 0xff ;
0 commit comments