@@ -11,12 +11,13 @@ import {
11
11
untracked ,
12
12
viewChild ,
13
13
} from '@angular/core' ;
14
- import { NgtGroup , extend , getLocalState , injectBeforeRender , injectStore , omit , pick } from 'angular-three' ;
14
+ import { NgtThreeElements , extend , getInstanceState , injectBeforeRender , injectStore , omit , pick } from 'angular-three' ;
15
15
import { ProgressiveLightMap , SoftShadowMaterial } from 'angular-three-soba/vanilla-exports' ;
16
16
import { mergeInputs } from 'ngxtension/inject-inputs' ;
17
+ import * as THREE from 'three' ;
17
18
import { Group , Mesh , PlaneGeometry } from 'three' ;
18
19
19
- export interface NgtsAccumulativeShadowsOptions extends Partial < NgtGroup > {
20
+ export interface NgtsAccumulativeShadowsOptions extends Partial < NgtThreeElements [ 'ngt-group' ] > {
20
21
/** How many frames it can render, more yields cleaner results but takes more time, 40 */
21
22
frames : number ;
22
23
/** If frames === Infinity blend controls the refresh ratio, 100 */
@@ -98,14 +99,11 @@ export class NgtsAccumulativeShadows {
98
99
'toneMapped' ,
99
100
] ) ;
100
101
101
- lightsRef = viewChild . required < ElementRef < Group > > ( 'lights' ) ;
102
- planeRef = viewChild . required < ElementRef < Mesh < PlaneGeometry , InstanceType < typeof SoftShadowMaterial > > > > ( 'plane' ) ;
102
+ lightsRef = viewChild . required < ElementRef < THREE . Group > > ( 'lights' ) ;
103
+ planeRef =
104
+ viewChild . required < ElementRef < THREE . Mesh < THREE . PlaneGeometry , InstanceType < typeof SoftShadowMaterial > > > > ( 'plane' ) ;
103
105
104
106
private store = injectStore ( ) ;
105
- private gl = this . store . select ( 'gl' ) ;
106
- private camera = this . store . select ( 'camera' ) ;
107
- private scene = this . store . select ( 'scene' ) ;
108
- private invalidate = this . store . select ( 'invalidate' ) ;
109
107
110
108
private opacity = pick ( this . options , 'opacity' ) ;
111
109
private alphaTest = pick ( this . options , 'alphaTest' ) ;
@@ -117,22 +115,22 @@ export class NgtsAccumulativeShadows {
117
115
if ( this . previousPLM ) {
118
116
this . previousPLM . clear ( ) ;
119
117
}
120
- return ( this . previousPLM = new ProgressiveLightMap ( this . gl ( ) , this . scene ( ) , this . resolution ( ) ) ) ;
118
+ return ( this . previousPLM = new ProgressiveLightMap ( this . store . gl ( ) , this . store . scene ( ) , this . resolution ( ) ) ) ;
121
119
} ) ;
122
120
123
- scale = pick ( this . options , 'scale' ) ;
124
- toneMapped = pick ( this . options , 'toneMapped' ) ;
125
- color = pick ( this . options , 'color' ) ;
126
- colorBlend = pick ( this . options , 'colorBlend' ) ;
127
- map = computed ( ( ) => this . pLM ( ) . progressiveLightMap2 . texture ) ;
121
+ protected scale = pick ( this . options , 'scale' ) ;
122
+ protected toneMapped = pick ( this . options , 'toneMapped' ) ;
123
+ protected color = pick ( this . options , 'color' ) ;
124
+ protected colorBlend = pick ( this . options , 'colorBlend' ) ;
125
+ protected map = computed ( ( ) => this . pLM ( ) . progressiveLightMap2 . texture ) ;
128
126
129
127
lightsMap = new Map < string , ( ) => void > ( ) ;
130
- temporal = computed ( ( ) => ! ! this . options ( ) . temporal ) ;
131
- frames = computed ( ( ) => Math . max ( 2 , this . options ( ) . frames ) ) ;
132
- blend = computed ( ( ) =>
128
+ private temporal = computed ( ( ) => ! ! this . options ( ) . temporal ) ;
129
+ private frames = computed ( ( ) => Math . max ( 2 , this . options ( ) . frames ) ) ;
130
+ private blend = computed ( ( ) =>
133
131
Math . max ( 2 , this . options ( ) . frames === Infinity ? this . options ( ) . blend : this . options ( ) . frames ) ,
134
132
) ;
135
- count = 0 ;
133
+ private count = 0 ;
136
134
137
135
constructor ( ) {
138
136
extend ( { Group, SoftShadowMaterial, Mesh, PlaneGeometry } ) ;
@@ -142,13 +140,13 @@ export class NgtsAccumulativeShadows {
142
140
} ) ;
143
141
144
142
effect ( ( ) => {
145
- const sceneLS = getLocalState ( this . scene ( ) ) ;
146
- if ( ! sceneLS ) return ;
143
+ const sceneInstanceState = getInstanceState ( this . store . scene ( ) ) ;
144
+ if ( ! sceneInstanceState ) return ;
147
145
148
146
// track deps
149
147
this . planeRef ( ) ;
150
148
this . options ( ) ;
151
- sceneLS . objects ( ) ;
149
+ sceneInstanceState . objects ( ) ;
152
150
153
151
// Reset internals, buffers, ...
154
152
this . reset ( ) ;
@@ -157,7 +155,12 @@ export class NgtsAccumulativeShadows {
157
155
} ) ;
158
156
159
157
injectBeforeRender ( ( ) => {
160
- const [ frames , temporal , invalidate , limit ] = [ this . frames ( ) , ! ! this . temporal ( ) , this . invalidate ( ) , this . limit ( ) ] ;
158
+ const [ frames , temporal , invalidate , limit ] = [
159
+ this . frames ( ) ,
160
+ ! ! this . temporal ( ) ,
161
+ this . store . snapshot . invalidate ,
162
+ this . limit ( ) ,
163
+ ] ;
161
164
if ( ( temporal || frames === Infinity ) && this . count < frames && this . count < limit ) {
162
165
invalidate ( ) ;
163
166
this . update ( ) ;
@@ -202,7 +205,7 @@ export class NgtsAccumulativeShadows {
202
205
// Update the lightmap and the accumulative lights
203
206
for ( let i = 0 ; i < frames ; i ++ ) {
204
207
this . lightsMap . forEach ( ( lightUpdate ) => lightUpdate ( ) ) ;
205
- this . pLM ( ) . update ( this . camera ( ) , this . blend ( ) ) ;
208
+ this . pLM ( ) . update ( this . store . camera ( ) , this . blend ( ) ) ;
206
209
}
207
210
// Switch lights off
208
211
this . lightsRef ( ) . nativeElement . visible = false ;
0 commit comments