Просмотр исходного кода

BatchedMesh: Add `getGeometryRangeAt` (#29409)

* BatchedMesh: Add getGeometryRangeAt

Co-authored-by: Luigi Denora <luigidenora@users.noreply.github.com>

* Fix eslint error

Co-authored-by: Luigi Denora <luigidenora@users.noreply.github.com>

* Doc changed

* Add optional target

---------

Co-authored-by: Luigi Denora <luigidenora@users.noreply.github.com>
Andrea Gargaro 1 год назад
Родитель
Сommit
ab23d7be00
2 измененных файлов с 33 добавлено и 3 удалено
  1. 16 3
      docs/api/en/objects/BatchedMesh.html
  2. 17 0
      src/objects/BatchedMesh.js

+ 16 - 3
docs/api/en/objects/BatchedMesh.html

@@ -167,8 +167,21 @@
 		<p>
 			[page:Integer instanceId]: The id of an instance to get the visibility state of.
 		</p>
-		<p>Get whether the given instance is marked as "visible" or not.</p>
-		
+		<p>Get whether the given instance is marked as "visible" or not.</p>		
+
+		<h3>
+			[method:Object getGeometryRangeAt]( [param:Integer geometryId], [param:Object target] )
+		</h3>
+		<p>
+			[page:Integer geometryId]: The id of the geometry to get the range of.
+		</p>
+		<p>
+			[page:Object target]: Optional target object to copy the range in to.
+		</p>
+		<p>Get the range representing the subset of triangles related to the attached geometry, indicating the starting offset and count, or `null` if invalid.</p>
+		<p>Return an object of the form:</p>
+		<code>{ start: Integer, count: Integer }</code>
+	
 		<h3>
 			[method:Integer getGeometryIdAt]( [param:Integer instanceId] )
 		</h3>
@@ -176,7 +189,7 @@
 			[page:Integer instanceId]: The id of an instance to get the geometryIndex of.
 		</p>
 		<p>Get the geometryIndex of the defined instance.</p>
-	
+
 		<h3>
 			[method:undefined setColorAt]( [param:Integer instanceId], [param:Color color] )
 		</h3>

+ 17 - 0
src/objects/BatchedMesh.js

@@ -881,6 +881,23 @@ class BatchedMesh extends Mesh {
 
 	}
 
+	getGeometryRangeAt( geometryId, target = {} ) {
+
+		if ( geometryId < 0 || geometryId >= this._geometryCount ) {
+
+			return null;
+
+		}
+
+		const drawRange = this._drawRanges[ geometryId ];
+
+		target.start = drawRange.start;
+		target.count = drawRange.count;
+
+		return target;
+
+	}
+
 	raycast( raycaster, intersects ) {
 
 		const drawInfo = this._drawInfo;

粤ICP备19079148号