Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.js - can't render cube on Mapbox GL JS custom WebGL layer

I'm trying to render the cube using this example: Add a 3D model.

Example work up to 117 version on three.js. Since 118 version example doesn't work: cube disappears immediately after page refresh. I studied changelog and most noticeable change is that since v118 three.js uses WebGL2 as default render engine. So I changed code to use WebGL1, but still cube disappears.

  this.renderer = new THREE.WebGL1Renderer({
  canvas: map.getCanvas(),
  context: gl,
  antialias: true
});

Here is codepen to reproduce the problem. (reload page to see the cube for a moment)

like image 433
microspace Avatar asked Nov 07 '22 05:11

microspace


1 Answers

I had the same issue, but it was resolved by replacing renderer.state.reset() in the render() function with renderer.resetState() which was introduced in r124 and improved in r126.

Mapbox example has also been updated.

like image 172
nagix Avatar answered Nov 15 '22 06:11

nagix