@@ -18,13 +18,17 @@ function buildColorTexture( color ) {
1818
1919function ViewportPathtracer ( renderer ) {
2020
21+ let generator = null ;
2122 let pathtracer = null ;
2223 let quad = null ;
24+ let hdr = null ;
2325
2426 function init ( scene , camera ) {
2527
2628 if ( pathtracer === null ) {
2729
30+ generator = new PathTracingSceneGenerator ( ) ;
31+
2832 pathtracer = new PathTracingRenderer ( renderer ) ;
2933 pathtracer . setSize ( renderer . domElement . offsetWidth , renderer . domElement . offsetHeight ) ;
3034 pathtracer . alpha = true ;
@@ -42,7 +46,14 @@ function ViewportPathtracer( renderer ) {
4246 pathtracer . material . backgroundBlur = scene . backgroundBlurriness ;
4347 pathtracer . reset ( ) ;
4448
45- const generator = new PathTracingSceneGenerator ( ) ;
49+ // TOFIX: If the scene is empty the generator crashes so we render a tiny cube (:
50+
51+ if ( scene . children . length === 0 ) {
52+
53+ scene = new THREE . Mesh ( new THREE . BoxGeometry ( 0.0001 , 0.0001 , 0.0001 ) ) ;
54+
55+ }
56+
4657 const { bvh, textures, materials, lights } = generator . generate ( scene ) ;
4758
4859 const ptGeometry = bvh . geometry ;
@@ -88,7 +99,14 @@ function ViewportPathtracer( renderer ) {
8899
89100 if ( environment && environment . isTexture === true ) {
90101
91- ptMaterial . envMapInfo . updateFrom ( scene . environment ) ;
102+ // Avoid calling envMapInfo() with the same hdr
103+
104+ if ( scene . environment !== hdr ) {
105+
106+ ptMaterial . envMapInfo . updateFrom ( scene . environment ) ;
107+ hdr = scene . environment ;
108+
109+ }
92110
93111 } else {
94112
0 commit comments