For reproduction: Primitive Restart Index with Line Strip - JSFiddle - Code Playground
Since r163
you can safely do this for all instances of THREE.Line
since WebGL 1 is no longer supported by WebGLRenderer
. And since PRIMITIVE_RESTART_FIXED_INDEX
is always enabled with WebGL 2 (see WebGL 2.0 Specification), there is no further configuration required.
Full code:
import * as THREE from 'three';
let renderer, scene, camera;
init();
render();
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.set( 0, 0, 4 );
const geometry = new THREE.BufferGeometry();
const positionAttribute = new THREE.Float32BufferAttribute( [
- 1, 1, 0,
- 1, - 1, 0,
0, 1, 0,
0, - 1, 0,
1, 1, 0,
1, - 1, 0
], 3 );
// 65535 is the restart index for Uint16
const index = new THREE.Uint16BufferAttribute( [ 0, 1, 2, 65535, 3, 4, 5 ], 1 );
geometry.setAttribute( 'position', positionAttribute );
geometry.setIndex( index );
const material = new THREE.LineBasicMaterial( { color: 0xffffff } );
const mesh = new THREE.Line( geometry, material );
scene.add( mesh );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setPixelRatio( window.devicePixelRatio );
document.body.appendChild( renderer.domElement );
}
function render() {
renderer.render( scene, camera );
}