@@ -129,23 +129,27 @@ class PMREMGenerator {
129
129
* and far planes ensure the scene is rendered in its entirety (the cubeCamera
130
130
* is placed at the origin).
131
131
*/
132
- fromScene ( scene , sigma = 0 , near = 0.1 , far = 100 ) {
132
+ fromScene ( scene , sigma = 0 , near = 0.1 , far = 100 , renderTarget = null ) {
133
+
134
+ this . _setSize ( 256 ) ;
133
135
134
136
if ( this . _hasInitialized === false ) {
135
137
136
138
console . warn ( 'THREE.PMREMGenerator: .fromScene() called before the backend is initialized. Try using .fromSceneAsync() instead.' ) ;
137
139
138
- return this . fromSceneAsync ( scene , sigma , near , far ) ;
140
+ const cubeUVRenderTarget = renderTarget || this . _allocateTargets ( ) ;
141
+
142
+ this . fromSceneAsync ( scene , sigma , near , far , cubeUVRenderTarget ) ;
143
+
144
+ return cubeUVRenderTarget ;
139
145
140
146
}
141
147
142
148
_oldTarget = this . _renderer . getRenderTarget ( ) ;
143
149
_oldActiveCubeFace = this . _renderer . getActiveCubeFace ( ) ;
144
150
_oldActiveMipmapLevel = this . _renderer . getActiveMipmapLevel ( ) ;
145
151
146
- this . _setSize ( 256 ) ;
147
-
148
- const cubeUVRenderTarget = this . _allocateTargets ( ) ;
152
+ const cubeUVRenderTarget = renderTarget || this . _allocateTargets ( ) ;
149
153
cubeUVRenderTarget . depthBuffer = true ;
150
154
151
155
this . _sceneToCubeUV ( scene , near , far , cubeUVRenderTarget ) ;
@@ -164,11 +168,11 @@ class PMREMGenerator {
164
168
165
169
}
166
170
167
- async fromSceneAsync ( scene , sigma = 0 , near = 0.1 , far = 100 ) {
171
+ async fromSceneAsync ( scene , sigma = 0 , near = 0.1 , far = 100 , renderTarget = null ) {
168
172
169
173
if ( this . _hasInitialized === false ) await this . _renderer . init ( ) ;
170
174
171
- return this . fromScene ( scene , sigma , near , far ) ;
175
+ return this . fromScene ( scene , sigma , near , far , renderTarget ) ;
172
176
173
177
}
174
178
@@ -183,7 +187,13 @@ class PMREMGenerator {
183
187
184
188
console . warn ( 'THREE.PMREMGenerator: .fromEquirectangular() called before the backend is initialized. Try using .fromEquirectangularAsync() instead.' ) ;
185
189
186
- return this . fromEquirectangularAsync ( equirectangular , renderTarget ) ;
190
+ this . _setSizeFromTexture ( equirectangular ) ;
191
+
192
+ const cubeUVRenderTarget = renderTarget || this . _allocateTargets ( ) ;
193
+
194
+ this . fromEquirectangularAsync ( equirectangular , cubeUVRenderTarget ) ;
195
+
196
+ return cubeUVRenderTarget ;
187
197
188
198
}
189
199
@@ -210,7 +220,13 @@ class PMREMGenerator {
210
220
211
221
console . warn ( 'THREE.PMREMGenerator: .fromCubemap() called before the backend is initialized. Try using .fromCubemapAsync() instead.' ) ;
212
222
213
- return this . fromCubemapAsync ( cubemap , renderTarget ) ;
223
+ this . _setSizeFromTexture ( cubemap ) ;
224
+
225
+ const cubeUVRenderTarget = renderTarget || this . _allocateTargets ( ) ;
226
+
227
+ this . fromCubemapAsync ( cubemap , renderTarget ) ;
228
+
229
+ return cubeUVRenderTarget ;
214
230
215
231
}
216
232
@@ -278,6 +294,20 @@ class PMREMGenerator {
278
294
279
295
// private interface
280
296
297
+ _setSizeFromTexture ( texture ) {
298
+
299
+ if ( texture . mapping === CubeReflectionMapping || texture . mapping === CubeRefractionMapping ) {
300
+
301
+ this . _setSize ( texture . image . length === 0 ? 16 : ( texture . image [ 0 ] . width || texture . image [ 0 ] . image . width ) ) ;
302
+
303
+ } else { // Equirectangular
304
+
305
+ this . _setSize ( texture . image . width / 4 ) ;
306
+
307
+ }
308
+
309
+ }
310
+
281
311
_setSize ( cubeSize ) {
282
312
283
313
this . _lodMax = Math . floor ( Math . log2 ( cubeSize ) ) ;
@@ -309,15 +339,7 @@ class PMREMGenerator {
309
339
310
340
_fromTexture ( texture , renderTarget ) {
311
341
312
- if ( texture . mapping === CubeReflectionMapping || texture . mapping === CubeRefractionMapping ) {
313
-
314
- this . _setSize ( texture . image . length === 0 ? 16 : ( texture . image [ 0 ] . width || texture . image [ 0 ] . image . width ) ) ;
315
-
316
- } else { // Equirectangular
317
-
318
- this . _setSize ( texture . image . width / 4 ) ;
319
-
320
- }
342
+ this . _setSizeFromTexture ( texture ) ;
321
343
322
344
_oldTarget = this . _renderer . getRenderTarget ( ) ;
323
345
_oldActiveCubeFace = this . _renderer . getActiveCubeFace ( ) ;
0 commit comments