@@ -3,232 +3,234 @@ import { FunctionNode } from '../core/FunctionNode.js';
3
3
import { FloatNode } from '../inputs/FloatNode.js' ;
4
4
import { PositionNode } from '../accessors/PositionNode.js' ;
5
5
6
- function CameraNode ( scope , camera ) {
6
+ class CameraNode extends TempNode {
7
7
8
- TempNode . call ( this , 'v3' ) ;
8
+ constructor ( scope , camera ) {
9
9
10
- this . setScope ( scope || CameraNode . POSITION ) ;
11
- this . setCamera ( camera ) ;
10
+ super ( 'v3' ) ;
12
11
13
- }
14
-
15
- CameraNode . Nodes = ( function ( ) {
16
-
17
- var depthColor = new FunctionNode ( [
18
- 'float depthColor( float mNear, float mFar ) {' ,
19
-
20
- ' #ifdef USE_LOGDEPTHBUF_EXT' ,
12
+ this . setScope ( scope || CameraNode . POSITION ) ;
13
+ this . setCamera ( camera ) ;
21
14
22
- ' float depth = gl_FragDepthEXT / gl_FragCoord.w;' ,
15
+ }
23
16
24
- ' #else' ,
17
+ setCamera ( camera ) {
25
18
26
- ' float depth = gl_FragCoord.z / gl_FragCoord.w;' ,
19
+ this . camera = camera ;
20
+ this . updateFrame = camera !== undefined ? this . onUpdateFrame : undefined ;
27
21
28
- ' #endif' ,
22
+ }
29
23
30
- ' return 1.0 - smoothstep( mNear, mFar, depth );' ,
24
+ setScope ( scope ) {
31
25
32
- '}'
33
- ] . join ( '\n' ) ) ;
26
+ switch ( this . scope ) {
34
27
35
- return {
36
- depthColor : depthColor
37
- } ;
28
+ case CameraNode . DEPTH :
38
29
39
- } ) ( ) ;
30
+ delete this . near ;
31
+ delete this . far ;
40
32
41
- CameraNode . POSITION = 'position' ;
42
- CameraNode . DEPTH = 'depth' ;
43
- CameraNode . TO_VERTEX = 'toVertex' ;
44
-
45
- CameraNode . prototype = Object . create ( TempNode . prototype ) ;
46
- CameraNode . prototype . constructor = CameraNode ;
47
- CameraNode . prototype . nodeType = 'Camera' ;
33
+ break ;
48
34
49
- CameraNode . prototype . setCamera = function ( camera ) {
35
+ }
50
36
51
- this . camera = camera ;
52
- this . updateFrame = camera !== undefined ? this . onUpdateFrame : undefined ;
37
+ this . scope = scope ;
53
38
54
- } ;
39
+ switch ( scope ) {
55
40
56
- CameraNode . prototype . setScope = function ( scope ) {
41
+ case CameraNode . DEPTH :
57
42
58
- switch ( this . scope ) {
43
+ const camera = this . camera ;
59
44
60
- case CameraNode . DEPTH :
45
+ this . near = new FloatNode ( camera ? camera . near : 1 ) ;
46
+ this . far = new FloatNode ( camera ? camera . far : 1200 ) ;
61
47
62
- delete this . near ;
63
- delete this . far ;
48
+ break ;
64
49
65
- break ;
50
+ }
66
51
67
52
}
68
53
69
- this . scope = scope ;
54
+ getType ( /* builder */ ) {
70
55
71
- switch ( scope ) {
56
+ switch ( this . scope ) {
72
57
73
- case CameraNode . DEPTH :
58
+ case CameraNode . DEPTH :
74
59
75
- var camera = this . camera ;
60
+ return 'f' ;
76
61
77
- this . near = new FloatNode ( camera ? camera . near : 1 ) ;
78
- this . far = new FloatNode ( camera ? camera . far : 1200 ) ;
62
+ }
79
63
80
- break ;
64
+ return this . type ;
81
65
82
66
}
83
67
84
- } ;
68
+ getUnique ( /* builder */ ) {
69
+
70
+ switch ( this . scope ) {
85
71
86
- CameraNode . prototype . getType = function ( /* builder */ ) {
72
+ case CameraNode . DEPTH :
73
+ case CameraNode . TO_VERTEX :
87
74
88
- switch ( this . scope ) {
75
+ return true ;
89
76
90
- case CameraNode . DEPTH :
77
+ }
91
78
92
- return 'f' ;
79
+ return false ;
93
80
94
81
}
95
82
96
- return this . type ;
83
+ getShared ( /* builder */ ) {
97
84
98
- } ;
85
+ switch ( this . scope ) {
99
86
100
- CameraNode . prototype . getUnique = function ( /* builder */ ) {
87
+ case CameraNode . POSITION :
101
88
102
- switch ( this . scope ) {
89
+ return false ;
103
90
104
- case CameraNode . DEPTH :
105
- case CameraNode . TO_VERTEX :
91
+ }
106
92
107
- return true ;
93
+ return true ;
108
94
109
95
}
110
96
111
- return false ;
97
+ generate ( builder , output ) {
112
98
113
- } ;
99
+ let result ;
114
100
115
- CameraNode . prototype . getShared = function ( /* builder */ ) {
101
+ switch ( this . scope ) {
116
102
117
- switch ( this . scope ) {
103
+ case CameraNode . POSITION :
118
104
119
- case CameraNode . POSITION :
105
+ result = 'cameraPosition' ;
120
106
121
- return false ;
107
+ break ;
122
108
123
- }
109
+ case CameraNode . DEPTH :
124
110
125
- return true ;
111
+ const depthColor = builder . include ( CameraNode . Nodes . depthColor ) ;
126
112
127
- } ;
113
+ result = depthColor + '( ' + this . near . build ( builder , 'f' ) + ', ' + this . far . build ( builder , 'f' ) + ' )' ;
128
114
129
- CameraNode . prototype . generate = function ( builder , output ) {
115
+ break ;
116
+
117
+ case CameraNode . TO_VERTEX :
130
118
131
- var result ;
119
+ result = 'normalize( ' + new PositionNode ( PositionNode . WORLD ) . build ( builder , 'v3' ) + ' - cameraPosition )' ;
132
120
133
- switch ( this . scope ) {
121
+ break ;
134
122
135
- case CameraNode . POSITION :
123
+ }
136
124
137
- result = 'cameraPosition' ;
125
+ return builder . format ( result , this . getType ( builder ) , output ) ;
138
126
139
- break ;
127
+ }
140
128
141
- case CameraNode . DEPTH :
129
+ onUpdateFrame ( /* frame */ ) {
142
130
143
- var depthColor = builder . include ( CameraNode . Nodes . depthColor ) ;
131
+ switch ( this . scope ) {
144
132
145
- result = depthColor + '( ' + this . near . build ( builder , 'f' ) + ', ' + this . far . build ( builder , 'f' ) + ' )' ;
133
+ case CameraNode . DEPTH :
146
134
147
- break ;
135
+ const camera = this . camera ;
148
136
149
- case CameraNode . TO_VERTEX :
137
+ this . near . value = camera . near ;
138
+ this . far . value = camera . far ;
150
139
151
- result = 'normalize( ' + new PositionNode ( PositionNode . WORLD ) . build ( builder , 'v3' ) + ' - cameraPosition )' ;
140
+ break ;
152
141
153
- break ;
142
+ }
154
143
155
144
}
156
145
157
- return builder . format ( result , this . getType ( builder ) , output ) ;
146
+ copy ( source ) {
158
147
159
- } ;
148
+ super . copy ( source ) ;
160
149
161
- CameraNode . prototype . onUpdateFrame = function ( /* frame */ ) {
150
+ this . setScope ( source . scope ) ;
162
151
163
- switch ( this . scope ) {
152
+ if ( source . camera ) {
164
153
165
- case CameraNode . DEPTH :
154
+ this . setCamera ( source . camera ) ;
166
155
167
- var camera = this . camera ;
156
+ }
157
+
158
+ switch ( source . scope ) {
168
159
169
- this . near . value = camera . near ;
170
- this . far . value = camera . far ;
160
+ case CameraNode . DEPTH :
171
161
172
- break ;
162
+ this . near . number = source . near ;
163
+ this . far . number = source . far ;
164
+
165
+ break ;
166
+
167
+ }
168
+
169
+ return this ;
173
170
174
171
}
175
172
176
- } ;
173
+ toJSON ( meta ) {
177
174
178
- CameraNode . prototype . copy = function ( source ) {
175
+ let data = this . getJSONNode ( meta ) ;
179
176
180
- TempNode . prototype . copy . call ( this , source ) ;
177
+ if ( ! data ) {
181
178
182
- this . setScope ( source . scope ) ;
179
+ data = this . createJSONNode ( meta ) ;
183
180
184
- if ( source . camera ) {
181
+ data . scope = this . scope ;
185
182
186
- this . setCamera ( source . camera ) ;
183
+ if ( this . camera ) data . camera = this . camera . uuid ;
187
184
188
- }
185
+ switch ( this . scope ) {
189
186
190
- switch ( source . scope ) {
187
+ case CameraNode . DEPTH :
191
188
192
- case CameraNode . DEPTH :
189
+ data . near = this . near . value ;
190
+ data . far = this . far . value ;
193
191
194
- this . near . number = source . near ;
195
- this . far . number = source . far ;
192
+ break ;
196
193
197
- break ;
194
+ }
198
195
199
- }
196
+ }
200
197
201
- return this ;
198
+ return data ;
202
199
203
- } ;
200
+ }
204
201
205
- CameraNode . prototype . toJSON = function ( meta ) {
202
+ }
206
203
207
- var data = this . getJSONNode ( meta ) ;
204
+ CameraNode . Nodes = ( function ( ) {
208
205
209
- if ( ! data ) {
206
+ const depthColor = new FunctionNode ( [
207
+ 'float depthColor( float mNear, float mFar ) {' ,
210
208
211
- data = this . createJSONNode ( meta ) ;
209
+ ' #ifdef USE_LOGDEPTHBUF_EXT' ,
212
210
213
- data . scope = this . scope ;
211
+ ' float depth = gl_FragDepthEXT / gl_FragCoord.w;' ,
214
212
215
- if ( this . camera ) data . camera = this . camera . uuid ;
213
+ ' #else' ,
216
214
217
- switch ( this . scope ) {
215
+ ' float depth = gl_FragCoord.z / gl_FragCoord.w;' ,
218
216
219
- case CameraNode . DEPTH :
217
+ ' #endif' ,
220
218
221
- data . near = this . near . value ;
222
- data . far = this . far . value ;
219
+ ' return 1.0 - smoothstep( mNear, mFar, depth );' ,
223
220
224
- break ;
221
+ '}'
222
+ ] . join ( '\n' ) ) ;
225
223
226
- }
224
+ return {
225
+ depthColor : depthColor
226
+ } ;
227
227
228
- }
228
+ } ) ( ) ;
229
229
230
- return data ;
230
+ CameraNode . POSITION = 'position' ;
231
+ CameraNode . DEPTH = 'depth' ;
232
+ CameraNode . TO_VERTEX = 'toVertex' ;
231
233
232
- } ;
234
+ CameraNode . prototype . nodeType = 'Camera' ;
233
235
234
236
export { CameraNode } ;
0 commit comments