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

WebGPURenderer: Fix wireframe rendering for `BatchedMesh`. (#32955)

Michael Herzog 2 недель назад
Родитель
Сommit
4f28c50058
2 измененных файлов с 10 добавлено и 3 удалено
  1. 1 2
      src/renderers/common/Geometries.js
  2. 9 1
      src/renderers/webgpu/WebGPUBackend.js

+ 1 - 2
src/renderers/common/Geometries.js

@@ -1,6 +1,5 @@
 import DataMap from './DataMap.js';
 import DataMap from './DataMap.js';
 import { AttributeType } from './Constants.js';
 import { AttributeType } from './Constants.js';
-import { arrayNeedsUint32 } from '../../utils.js';
 
 
 import { Uint16BufferAttribute, Uint32BufferAttribute } from '../../core/BufferAttribute.js';
 import { Uint16BufferAttribute, Uint32BufferAttribute } from '../../core/BufferAttribute.js';
 
 
@@ -77,7 +76,7 @@ function getWireframeIndex( geometry ) {
 
 
 	}
 	}
 
 
-	const attribute = new ( arrayNeedsUint32( indices ) ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
+	const attribute = new ( geometryPosition.count >= 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
 	attribute.version = getWireframeVersion( geometry );
 	attribute.version = getWireframeVersion( geometry );
 	attribute.__id = getWireframeId( geometry );
 	attribute.__id = getWireframeId( geometry );
 
 

+ 9 - 1
src/renderers/webgpu/WebGPUBackend.js

@@ -1596,6 +1596,14 @@ class WebGPUBackend extends Backend {
 
 
 				}
 				}
 
 
+				let bytesPerElement = ( hasIndex === true ) ? index.array.BYTES_PER_ELEMENT : 1;
+
+				if ( material.wireframe ) {
+
+					bytesPerElement = object.geometry.attributes.position.count > 65535 ? 4 : 2;
+
+				}
+
 				for ( let i = 0; i < drawCount; i ++ ) {
 				for ( let i = 0; i < drawCount; i ++ ) {
 
 
 					const count = drawInstances ? drawInstances[ i ] : 1;
 					const count = drawInstances ? drawInstances[ i ] : 1;
@@ -1603,7 +1611,7 @@ class WebGPUBackend extends Backend {
 
 
 					if ( hasIndex === true ) {
 					if ( hasIndex === true ) {
 
 
-						passEncoderGPU.drawIndexed( counts[ i ], count, starts[ i ] / index.array.BYTES_PER_ELEMENT, 0, firstInstance );
+						passEncoderGPU.drawIndexed( counts[ i ], count, starts[ i ] / bytesPerElement, 0, firstInstance );
 
 
 					} else {
 					} else {
 
 

粤ICP备19079148号