Browse Source

Add load typescript definitions

Garrett Johnson 5 years ago
parent
commit
eba9f90909
4 changed files with 103 additions and 0 deletions
  1. 1 0
      example/pntsExample.js
  2. 21 0
      src/base/CMPTLoaderBase.d.ts
  3. 16 0
      src/base/PNTSLoaderBase.d.ts
  4. 65 0
      src/three/PNTSLoader.js

+ 1 - 0
example/pntsExample.js

@@ -66,6 +66,7 @@ function init() {
 		.load( 'https://raw.githubusercontent.com/CesiumGS/3d-tiles-samples/master/tilesets/TilesetWithRequestVolume/points.pnts' )
 		.then( res => {
 
+			console.log( res );
 			scene.add( res.scene );
 
 		} );

+ 21 - 0
src/base/CMPTLoaderBase.d.ts

@@ -0,0 +1,21 @@
+interface TileInfo {
+
+	type : String;
+	buffer : Uint8Array;
+	version : String;
+
+}
+
+export interface CMPTBaseResult {
+
+	version : String;
+	tiles : Array< TileInfo >;
+
+}
+
+export class CMPTLoaderBase {
+
+	load( url : String ) : Promise< CMPTBaseResult >;
+	parse( buffer : ArrayBuffer ) : CMPTBaseResult;
+
+}

+ 16 - 0
src/base/PNTSLoaderBase.d.ts

@@ -0,0 +1,16 @@
+import { FeatureTable, BatchTable } from '../utilities/FeatureTable';
+
+export interface PNTSBaseResult {
+
+	version : String;
+	featureTable: FeatureTable;
+	batchTable : BatchTable;
+
+}
+
+export class PNTSLoaderBase {
+
+	load( url : string ) : Promise< PNTSBaseResult >;
+	parse( buffer : ArrayBuffer ) : PNTSBaseResult;
+
+}

+ 65 - 0
src/three/PNTSLoader.js

@@ -0,0 +1,65 @@
+import { PNTSLoaderBase } from '../base/PNTSLoaderBase.js';
+import { Points, PointsMaterial, BufferGeometry, BufferAttribute } from 'three';
+
+export class PNTSLoader extends PNTSLoaderBase {
+
+	constructor( manager ) {
+
+		super();
+		this.manager = manager;
+
+	}
+
+	parse( buffer ) {
+
+		const result = super.parse( buffer );
+		const { featureTable } = result;
+		window.data = result
+
+		// global semantics
+		const POINTS_LENGTH = featureTable.getData( 'POINTS_LENGTH' );
+
+		// RTC_CENTER
+		// QUANTIZED_VOLUME_OFFSET
+		// QUANTIZED_VOLUME_SCALE
+		// CONSTANT_RGBA
+		// BATCH_LENGTH
+
+		const POSITION = featureTable.getData( 'POSITION', POINTS_LENGTH, 'FLOAT', 'VEC3' );
+		const RGB = featureTable.getData( 'RGB', POINTS_LENGTH, 'UNSIGNED_BYTE', 'VEC3' );
+
+		// POSITION_QUANTIZED
+		// RGBA
+		// RGB565
+		// NORMAL
+		// NORMAL_OCT16P
+		// BATCH_ID
+
+		if ( POSITION === null ) {
+
+			throw new Error( 'PNTSLoader : POSITION_QUANTIZED feature type is not supported.' );
+
+		}
+
+		const geometry = new BufferGeometry();
+		geometry.setAttribute( 'position', new BufferAttribute( POSITION, 3, false ) );
+
+		const material = new PointsMaterial();
+		material.size = 2;
+		material.sizeAttenuation = false;
+
+		if ( RGB !== null ) {
+
+			geometry.setAttribute( 'color', new BufferAttribute( RGB, 3, true ) );
+			material.vertexColors = true;
+
+		}
+
+		const object = new Points( geometry, material );
+		result.scene = object;
+
+		return result;
+
+	}
+
+}