Skip to content

Commit 4f28c50

Browse files
authored
WebGPURenderer: Fix wireframe rendering for BatchedMesh. (mrdoob#32955)
1 parent e226c91 commit 4f28c50

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/renderers/common/Geometries.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import DataMap from './DataMap.js';
22
import { AttributeType } from './Constants.js';
3-
import { arrayNeedsUint32 } from '../../utils.js';
43

54
import { Uint16BufferAttribute, Uint32BufferAttribute } from '../../core/BufferAttribute.js';
65

@@ -77,7 +76,7 @@ function getWireframeIndex( geometry ) {
7776

7877
}
7978

80-
const attribute = new ( arrayNeedsUint32( indices ) ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
79+
const attribute = new ( geometryPosition.count >= 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
8180
attribute.version = getWireframeVersion( geometry );
8281
attribute.__id = getWireframeId( geometry );
8382

src/renderers/webgpu/WebGPUBackend.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1596,14 +1596,22 @@ class WebGPUBackend extends Backend {
15961596

15971597
}
15981598

1599+
let bytesPerElement = ( hasIndex === true ) ? index.array.BYTES_PER_ELEMENT : 1;
1600+
1601+
if ( material.wireframe ) {
1602+
1603+
bytesPerElement = object.geometry.attributes.position.count > 65535 ? 4 : 2;
1604+
1605+
}
1606+
15991607
for ( let i = 0; i < drawCount; i ++ ) {
16001608

16011609
const count = drawInstances ? drawInstances[ i ] : 1;
16021610
const firstInstance = count > 1 ? 0 : i;
16031611

16041612
if ( hasIndex === true ) {
16051613

1606-
passEncoderGPU.drawIndexed( counts[ i ], count, starts[ i ] / index.array.BYTES_PER_ELEMENT, 0, firstInstance );
1614+
passEncoderGPU.drawIndexed( counts[ i ], count, starts[ i ] / bytesPerElement, 0, firstInstance );
16071615

16081616
} else {
16091617

0 commit comments

Comments
 (0)