@@ -13,10 +13,11 @@ import {
13
13
untracked ,
14
14
viewChild ,
15
15
} from '@angular/core' ;
16
- import { extend , injectBeforeRender , injectStore , merge , NgtArgs , NgtGroup , omit , pick } from 'angular-three' ;
16
+ import { extend , injectBeforeRender , injectStore , merge , NgtArgs , NgtThreeElements , omit , pick } from 'angular-three' ;
17
17
import { assertInjector } from 'ngxtension/assert-injector' ;
18
18
import { mergeInputs } from 'ngxtension/inject-inputs' ;
19
- import { CubeCamera , Fog , FogExp2 , Group , HalfFloatType , Texture , WebGLCubeRenderTarget } from 'three' ;
19
+ import * as THREE from 'three' ;
20
+ import { Group } from 'three' ;
20
21
import { NgtsCameraContent } from './camera-content' ;
21
22
22
23
export interface CubeCameraOptions {
@@ -27,16 +28,14 @@ export interface CubeCameraOptions {
27
28
/** Camera far, 1000 */
28
29
far ?: number ;
29
30
/** Custom environment map that is temporarily set as the scenes background */
30
- envMap ?: Texture ;
31
+ envMap ?: THREE . Texture ;
31
32
/** Custom fog that is temporarily set as the scenes fog */
32
- fog ?: Fog | FogExp2 ;
33
+ fog ?: THREE . Fog | THREE . FogExp2 ;
33
34
}
34
35
35
36
export function injectCubeCamera ( options : ( ) => CubeCameraOptions , { injector } : { injector ?: Injector } = { } ) {
36
37
return assertInjector ( injectCubeCamera , injector , ( ) => {
37
38
const store = injectStore ( ) ;
38
- const gl = store . select ( 'gl' ) ;
39
- const scene = store . select ( 'scene' ) ;
40
39
41
40
// backfill the options with default values
42
41
const mergedOptions = merge ( options , { resolution : 256 , near : 0.1 , far : 1000 } , 'backfill' ) ;
@@ -45,8 +44,8 @@ export function injectCubeCamera(options: () => CubeCameraOptions, { injector }:
45
44
const far = pick ( mergedOptions , 'far' ) ;
46
45
47
46
const fbo = computed ( ( ) => {
48
- const fbo = new WebGLCubeRenderTarget ( resolution ( ) ) ;
49
- fbo . texture . type = HalfFloatType ;
47
+ const fbo = new THREE . WebGLCubeRenderTarget ( resolution ( ) ) ;
48
+ fbo . texture . type = THREE . HalfFloatType ;
50
49
return fbo ;
51
50
} ) ;
52
51
@@ -55,26 +54,26 @@ export function injectCubeCamera(options: () => CubeCameraOptions, { injector }:
55
54
onCleanup ( ( ) => _fbo . dispose ( ) ) ;
56
55
} ) ;
57
56
58
- const camera = computed ( ( ) => new CubeCamera ( near ( ) ! , far ( ) ! , fbo ( ) ) ) ;
57
+ const cubeCamera = computed ( ( ) => new THREE . CubeCamera ( near ( ) ! , far ( ) ! , fbo ( ) ) ) ;
59
58
const update = ( ) => {
60
- const [ _scene , _gl , _camera , { envMap, fog } ] = [ scene ( ) , gl ( ) , camera ( ) , untracked ( mergedOptions ) ] ;
61
- let originalFog : Fog | FogExp2 ;
62
- let originalBackground : Texture ;
63
-
64
- originalFog = _scene . fog as Fog | FogExp2 ;
65
- originalBackground = _scene . background as Texture ;
66
- _scene . background = envMap || originalBackground ;
67
- _scene . fog = fog || originalFog ;
68
- _camera . update ( _gl , _scene ) ;
69
- _scene . fog = originalFog ;
70
- _scene . background = originalBackground ;
59
+ const [ scene , gl , camera , { envMap, fog } ] = [ store . scene ( ) , store . gl ( ) , cubeCamera ( ) , untracked ( mergedOptions ) ] ;
60
+ let originalFog : THREE . Fog | THREE . FogExp2 ;
61
+ let originalBackground : THREE . Texture ;
62
+
63
+ originalFog = scene . fog as THREE . Fog | THREE . FogExp2 ;
64
+ originalBackground = scene . background as THREE . Texture ;
65
+ scene . background = envMap || originalBackground ;
66
+ scene . fog = fog || originalFog ;
67
+ camera . update ( gl , scene ) ;
68
+ scene . fog = originalFog ;
69
+ scene . background = originalBackground ;
71
70
} ;
72
71
73
- return { fbo, camera, update } ;
72
+ return { fbo, camera : cubeCamera , update } ;
74
73
} ) ;
75
74
}
76
75
77
- export interface NgtsCubeCameraOptions extends Partial < NgtGroup > , CubeCameraOptions {
76
+ export interface NgtsCubeCameraOptions extends Partial < NgtThreeElements [ 'ngt-group' ] > , CubeCameraOptions {
78
77
frames : number ;
79
78
}
80
79
@@ -101,15 +100,15 @@ const defaultOptions: NgtsCubeCameraOptions = {
101
100
} )
102
101
export class NgtsCubeCamera {
103
102
options = input ( defaultOptions , { transform : mergeInputs ( defaultOptions ) } ) ;
104
- parameters = omit ( this . options , [ 'fog' , 'near' , 'far' , 'envMap' , 'resolution' , 'frames' ] ) ;
103
+ protected parameters = omit ( this . options , [ 'fog' , 'near' , 'far' , 'envMap' , 'resolution' , 'frames' ] ) ;
105
104
106
105
private cubeCamera = injectCubeCamera ( pick ( this . options , [ 'near' , 'far' , 'envMap' , 'fog' , 'resolution' ] ) ) ;
107
106
108
- camera = this . cubeCamera . camera ;
109
- texture = pick ( this . cubeCamera . fbo , 'texture' ) ;
107
+ protected camera = this . cubeCamera . camera ;
108
+ protected texture = pick ( this . cubeCamera . fbo , 'texture' ) ;
110
109
111
- groupRef = viewChild . required < ElementRef < Group > > ( 'group' ) ;
112
- cameraContent = contentChild ( NgtsCameraContent , { read : TemplateRef } ) ;
110
+ groupRef = viewChild . required < ElementRef < THREE . Group > > ( 'group' ) ;
111
+ protected cameraContent = contentChild ( NgtsCameraContent , { read : TemplateRef } ) ;
113
112
114
113
constructor ( ) {
115
114
extend ( { Group } ) ;
0 commit comments