Garrett Johnson 5 年之前
父节点
当前提交
5778128e27
共有 3 个文件被更改,包括 35 次插入8 次删除
  1. 12 0
      src/base/I3DMLoaderBase.js
  2. 6 4
      src/base/PNTSLoaderBase.js
  3. 17 4
      src/utilities/FeatureTable.js

+ 12 - 0
src/base/I3DMLoaderBase.js

@@ -61,8 +61,20 @@ export class I3DMLoaderBase {
 
 		// Feature Table
 		const featureTableStart = 32;
+		const featureTable = new FeatureTable( buffer, featureTableStart, featureTableJSONByteLength, featureTableBinaryByteLength );
 
 		// Batch Table
+		const BATCH_ID = featureTable.getData( 'BATCH_ID', 'UNSIGNED_SHORT' );
+		let maxBatchId = - 1;
+		for ( let i = 0, l = BATCH_ID.length; i < l; i ++ ) {
+
+			maxBatchId = Math.max( BATCH_ID[ i ], maxBatchId );
+
+		}
+
+		const batchLength = maxBatchId === - 1 ? 0 : maxBatchId + 1;
+		const batchTableStart = featureTableStart + featureTableJSONByteLength + featureTableBinaryByteLength;
+		const batchTable = new BatchTable( buffer, batchLength, batchTableStart, batchTableJSONByteLength, batchTableBinaryByteLength );
 
 		const glbStart = batchTableStart + batchTableJSONByteLength + batchTableBinaryByteLength;
 		const bodyBytes = new Uint8Array( buffer, glbStart, byteLength - glbStart );

+ 6 - 4
src/base/PNTSLoaderBase.js

@@ -1,6 +1,8 @@
 // PNTS File Format
 // https://github.com/CesiumGS/3d-tiles/blob/master/specification/TileFormats/PointCloud/README.md
 
+import { BatchTable } from "../utilities/FeatureTable";
+
 export class I3DMLoaderBase {
 
 	constructor() {
@@ -56,12 +58,12 @@ export class I3DMLoaderBase {
 
 		// Feature Table
 		const featureTableStart = 28;
-
-		// TODO
+		const featureTable = new FeatureTable( buffer, featureTableStart, featureTableJSONByteLength, featureTableBinaryByteLength );
 
 		// Batch Table
-
-		// TODO
+		const batchLength = featureTable.getData( 'BATCH_LENGTH' ) || 0;
+		const batchTableStart = featureTableStart + featureTableJSONByteLength + featureTableBinaryByteLength;
+		const batchTable = new BatchTable( buffer, batchLength, batchTableStart, batchTableJSONByteLength, batchTableBinaryByteLength );
 
 		return {
 			version,

+ 17 - 4
src/utilities/FeatureTable.js

@@ -29,9 +29,16 @@ export class FeatureTable {
 
 	}
 
-	getData( key, count, type = null, componentType = null ) {
+	getData( key, count, defaultComponentType = null, defaultType = null ) {
 
 		const header = this.header;
+
+		if ( ! ( key in header ) ) {
+
+			return null;
+
+		}
+
 		const feature = header[ key ];
 		if ( ! ( feature instanceof Object ) ) {
 
@@ -45,8 +52,14 @@ export class FeatureTable {
 
 			const { buffer, binOffset, binLength } = this;
 			const byteOffset = feature.byteOffset || 0;
-			const featureType = type || feature.type;
-			const featureComponentType = componentType || feature.componentType;
+			const featureType = feature.type || defaultType;
+			const featureComponentType = feature.componentType || defaultComponentType;
+
+			if ( 'type' in feature && defaultType && feature.type !== defaultType) {
+
+				throw new Error( 'FeatureTable: Specified type does not match expected type.' );
+
+			}
 
 			let stride;
 			switch ( featureType ) {
@@ -133,7 +146,7 @@ export class BatchTable extends FeatureTable {
 
 	}
 
-	getData( key, type = null, componentType = null ) {
+	getData( key, componentType = null, type = null ) {
 
 		return this.getData( key, this.batchSize, type, componentType );