浏览代码

Merge pull request #121 from NASA-AMMOS/batch-table-use

Add batch table example use
Garrett Johnson 4 年之前
父节点
当前提交
13d7d111b6
共有 1 个文件被更改,包括 40 次插入0 次删除
  1. 40 0
      README.md

+ 40 - 0
README.md

@@ -168,6 +168,46 @@ function renderLoop() {
 renderLoop();
 ```
 
+## Read Batch Id and Batch Table Data
+
+How to find the batch id and batch table associated with a mesh and read the data.
+
+```js
+const tilesRenderer = new TilesRenderer( './path/to/tileset.json' );
+
+// ...checking intersections...
+
+const intersects = raycaster.intersectObject( scene, true );
+if ( intersects.length ) {
+
+	const { face, object } = intersects[ 0 ];
+	const batchidAttr = object.geometry.getAttribute( '_batchid' );
+
+	if ( batchidAttr ) {
+
+		// Traverse the parents to find the batch table.
+		let batchTableObject = object;
+		while ( ! batchTableObject.batchTable ) {
+
+			batchTableObject = batchTableObject.parent;
+
+		}
+
+		// Log the batch data
+		const batchTable = batchTableObject.batchTable;
+		const hoveredBatchid = batchidAttr.getX( face.a );
+		const batchData = batchTable.getData( 'BatchTableKey' );
+		if ( batchData ) {
+
+			console.log( batchData[ hoveredBatchid ] );
+
+		}
+
+	}
+	
+}
+```
+
 # API
 
 ## TilesRenderer