PNTSLoader.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { PNTSLoaderBase } from '../base/PNTSLoaderBase.js';
  2. import { Points, PointsMaterial, BufferGeometry, BufferAttribute, DefaultLoadingManager } from 'three';
  3. export class PNTSLoader extends PNTSLoaderBase {
  4. constructor( manager = DefaultLoadingManager ) {
  5. super();
  6. this.manager = manager;
  7. }
  8. parse( buffer ) {
  9. const result = super.parse( buffer );
  10. const { featureTable } = result;
  11. // global semantics
  12. const POINTS_LENGTH = featureTable.getData( 'POINTS_LENGTH' );
  13. // RTC_CENTER
  14. // QUANTIZED_VOLUME_OFFSET
  15. // QUANTIZED_VOLUME_SCALE
  16. // CONSTANT_RGBA
  17. // BATCH_LENGTH
  18. const POSITION = featureTable.getData( 'POSITION', POINTS_LENGTH, 'FLOAT', 'VEC3' );
  19. const RGB = featureTable.getData( 'RGB', POINTS_LENGTH, 'UNSIGNED_BYTE', 'VEC3' );
  20. // POSITION_QUANTIZED
  21. // RGBA
  22. // RGB565
  23. // NORMAL
  24. // NORMAL_OCT16P
  25. // BATCH_ID
  26. if ( POSITION === null ) {
  27. throw new Error( 'PNTSLoader : POSITION_QUANTIZED feature type is not supported.' );
  28. }
  29. const geometry = new BufferGeometry();
  30. geometry.setAttribute( 'position', new BufferAttribute( POSITION, 3, false ) );
  31. const material = new PointsMaterial();
  32. material.size = 2;
  33. material.sizeAttenuation = false;
  34. if ( RGB !== null ) {
  35. geometry.setAttribute( 'color', new BufferAttribute( RGB, 3, true ) );
  36. material.vertexColors = true;
  37. }
  38. const object = new Points( geometry, material );
  39. result.scene = object;
  40. return result;
  41. }
  42. }