4
4
* @author Jihoon Lee - [email protected]
5
5
*/
6
6
7
+ var ROS3D = require ( 'ros3d' ) ;
8
+ var THREE = require ( 'three' ) ;
9
+
10
+ var ShaderPass = require ( './passes/ShaderPass.js' ) ;
11
+ var RenderPass = require ( './passes/RenderPass.js' ) ;
12
+ var CelShadingPass = require ( './passes/CelShadingPass.js' ) ;
13
+ var HighlightingPass = require ( './passes/HighlightingPass.js' ) ;
14
+ var OutlinePass = require ( './passes/OutlinePass.js' ) ;
15
+ var SAOPass = require ( './passes/SAOPass.js' ) ;
16
+ var SSAOPass = require ( './passes/SSAOPass.js' ) ;
17
+
18
+ var CopyShader = require ( './shader/CopyShader.js' ) ;
19
+ var FXAAShader = require ( './shader/FXAAShader.js' ) ;
20
+
21
+ var EffectComposer = require ( './EffectComposer.js' ) ;
22
+
7
23
/**
8
24
* A Viewer can be used to render an interactive 3D scene to a HTML5 canvas.
9
25
*
17
33
* * antialias (optional) - if antialiasing should be used
18
34
* * intensity (optional) - the lighting intensity setting to use
19
35
*/
20
- EASE . Viewer = function ( options ) {
36
+ var Viewer = function ( options ) {
21
37
options = options || { } ;
22
38
var that = this ;
23
39
this . client = options . client ;
@@ -32,7 +48,7 @@ EASE.Viewer = function(options) {
32
48
this . interval = 1 / 30 ;
33
49
34
50
this . renderer = this . createRenderer ( options ) ;
35
- this . composer = new THREE . EffectComposer ( this . renderer ) ;
51
+ this . composer = new EffectComposer ( this . renderer ) ;
36
52
// create scene node + camera + lights
37
53
this . createScene ( options ) ;
38
54
if ( options . sun ) {
@@ -59,8 +75,8 @@ EASE.Viewer = function(options) {
59
75
this . createBGScene ( options ) ;
60
76
61
77
// add the renderer to the page
62
- options . div . appendChild ( this . renderer . domElement ) ;
63
- options . div . addEventListener ( 'dblclick' , function ( ev ) {
78
+ options . div . append ( this . renderer . domElement ) ;
79
+ options . div . on ( 'dblclick' , function ( ev ) {
64
80
if ( that . lastEvent === ev ) return ;
65
81
that . client . unselectMarker ( ) ;
66
82
that . lastEvent = ev ;
@@ -74,7 +90,7 @@ EASE.Viewer = function(options) {
74
90
this . start ( ) ;
75
91
} ;
76
92
77
- EASE . Viewer . prototype . createRenderer = function ( options ) {
93
+ Viewer . prototype . createRenderer = function ( options ) {
78
94
var background = options . background || '#111111' ;
79
95
var renderer = new THREE . WebGLRenderer ( { antialias : options . antialias } ) ;
80
96
renderer . setPixelRatio ( window . devicePixelRatio ) ;
@@ -86,7 +102,7 @@ EASE.Viewer.prototype.createRenderer = function(options){
86
102
return renderer ;
87
103
} ;
88
104
89
- EASE . Viewer . prototype . createScene = function ( options ) {
105
+ Viewer . prototype . createScene = function ( options ) {
90
106
var ambient = options . ambient || '#555555' ;
91
107
var cameraPosition = options . camera . position || { x : 3 , y : 3 , z : 3 } ;
92
108
var cameraZoomSpeed = options . camera . zoomSpeed || 0.5 ;
@@ -119,7 +135,7 @@ EASE.Viewer.prototype.createScene = function(options){
119
135
this . highlighter = new ROS3D . Highlighter ( { mouseHandler : this . mouseHandler } ) ;
120
136
} ;
121
137
122
- EASE . Viewer . prototype . createHUDScene = function ( options ) {
138
+ Viewer . prototype . createHUDScene = function ( options ) {
123
139
// create the HUD scene for GUI elements
124
140
this . sceneOrtho = new THREE . Scene ( ) ;
125
141
// create the global camera with orthogonal projection
@@ -131,13 +147,13 @@ EASE.Viewer.prototype.createHUDScene = function(options){
131
147
this . cameraOrtho . position . z = 10 ;
132
148
} ;
133
149
134
- EASE . Viewer . prototype . createBGScene = function ( ) {
150
+ Viewer . prototype . createBGScene = function ( ) {
135
151
this . backgroundScene = new THREE . Scene ( ) ;
136
152
this . backgroundCamera = new THREE . Camera ( ) ;
137
153
this . backgroundScene . add ( this . backgroundCamera ) ; // TODO is this required?
138
154
} ;
139
155
140
- EASE . Viewer . prototype . createSunLight = function ( options ) {
156
+ Viewer . prototype . createSunLight = function ( options ) {
141
157
var intensity = options . sun . intensity || 0.66 ;
142
158
var color = options . sun . color || '#eeeeee' ;
143
159
var pos = options . sun . pos || [ - 1 , 0.5 , 3.0 ] ;
@@ -161,7 +177,7 @@ EASE.Viewer.prototype.createSunLight = function(options){
161
177
return sun ;
162
178
} ;
163
179
164
- EASE . Viewer . prototype . createSpotLight = function ( options ) {
180
+ Viewer . prototype . createSpotLight = function ( options ) {
165
181
var color = options . spot . color || '#ffffbb' ;
166
182
var intensity = options . spot . intensity || 0.9 ;
167
183
var pos = options . spot . pos || [ 0 , 0 , 6 ] ;
@@ -183,58 +199,58 @@ EASE.Viewer.prototype.createSpotLight = function(options){
183
199
return spot ;
184
200
} ;
185
201
186
- EASE . Viewer . prototype . setSimplePipeline = function ( width , height ) {
202
+ Viewer . prototype . setSimplePipeline = function ( width , height ) {
187
203
this . composer . passes = [ ] ;
188
- // this.composer.addPass(new THREE. RenderPass(this.backgroundScene, this.backgroundCamera));
189
- this . composer . addPass ( new THREE . RenderPass ( this . scene , this . camera ) ) ;
190
- this . composer . addPass ( new EASE . HighlightingPass ( this . scene , this . camera , this . highlighter ) ) ;
204
+ // this.composer.addPass(new RenderPass(this.backgroundScene, this.backgroundCamera));
205
+ this . composer . addPass ( new RenderPass ( this . scene , this . camera ) ) ;
206
+ this . composer . addPass ( new HighlightingPass ( this . scene , this . camera , this . highlighter ) ) ;
191
207
this . addFXAAPass ( width , height , true ) ;
192
- // this.composer.addPass(new THREE. RenderPass(this.sceneOrtho, this.cameraOrtho));
208
+ // this.composer.addPass(new RenderPass(this.sceneOrtho, this.cameraOrtho));
193
209
} ;
194
210
195
- EASE . Viewer . prototype . setComicPipeline = function ( width , height ) {
196
- var outlinePass = new EASE . OutlinePass ( this . scene , this . camera , width , height ) ;
211
+ Viewer . prototype . setComicPipeline = function ( width , height ) {
212
+ var outlinePass = new OutlinePass ( this . scene , this . camera , width , height ) ;
197
213
this . composer . passes = [ ] ;
198
- this . composer . addPass ( new THREE . RenderPass ( this . scene , this . camera , outlinePass . mNormal ) ) ;
199
- this . composer . addPass ( new THREE . RenderPass ( this . scene , this . camera , outlinePass . mDepth ) ) ;
200
- this . composer . addPass ( new EASE . CelShadingPass ( this . scene , this . camera ) ) ;
201
- // this.composer.addPass(new EASE. HighlightingPass(this.scene, this.camera, this.highlighter));
214
+ this . composer . addPass ( new RenderPass ( this . scene , this . camera , outlinePass . mNormal ) ) ;
215
+ this . composer . addPass ( new RenderPass ( this . scene , this . camera , outlinePass . mDepth ) ) ;
216
+ this . composer . addPass ( new CelShadingPass ( this . scene , this . camera ) ) ;
217
+ // this.composer.addPass(new HighlightingPass(this.scene, this.camera, this.highlighter));
202
218
this . composer . addPass ( outlinePass ) ;
203
219
this . addFXAAPass ( width , height , true ) ;
204
220
} ;
205
221
206
- EASE . Viewer . prototype . addBlitPass = function ( ) {
207
- var blit = new THREE . ShaderPass ( THREE . CopyShader )
222
+ Viewer . prototype . addBlitPass = function ( ) {
223
+ var blit = new ShaderPass ( CopyShader )
208
224
blit . renderToScreen = true ;
209
225
this . composer . addPass ( blit ) ;
210
226
} ;
211
227
212
- EASE . Viewer . prototype . addFXAAPass = function ( width , height , renderToScreen ) {
213
- this . fxaaPass = new THREE . ShaderPass ( THREE . FXAAShader ) ;
228
+ Viewer . prototype . addFXAAPass = function ( width , height , renderToScreen ) {
229
+ this . fxaaPass = new ShaderPass ( FXAAShader ) ;
214
230
this . fxaaPass . uniforms [ 'resolution' ] . value . set ( 1.0 / width , 1.0 / height ) ;
215
231
this . fxaaPass . renderToScreen = renderToScreen ;
216
232
this . composer . addPass ( this . fxaaPass ) ;
217
233
} ;
218
234
219
- EASE . Viewer . prototype . addSSAOPass = function ( width , height , renderToScreen ) {
220
- this . ssaoPass = new THREE . SSAOPass ( this . scene , this . camera , width , height ) ;
235
+ Viewer . prototype . addSSAOPass = function ( width , height , renderToScreen ) {
236
+ this . ssaoPass = new SSAOPass ( this . scene , this . camera , width , height ) ;
221
237
this . ssaoPass . renderToScreen = renderToScreen ;
222
238
this . composer . addPass ( this . ssaoPass ) ;
223
239
} ;
224
240
225
- EASE . Viewer . prototype . addSAOPass = function ( renderToScreen ) {
226
- var saoPass = new THREE . SAOPass ( this . scene , this . camera , true , false , { x : 256 , y : 256 } ) ;
241
+ Viewer . prototype . addSAOPass = function ( renderToScreen ) {
242
+ var saoPass = new SAOPass ( this . scene , this . camera , true , false , { x : 256 , y : 256 } ) ;
227
243
this . saoPass = saoPass ;
228
244
saoPass . renderToScreen = renderToScreen ;
229
245
this . composer . addPass ( saoPass ) ;
230
246
if ( this . showDatgui ) {
231
247
var saoFolder = gui . addFolder ( 'SAO' ) ;
232
248
saoFolder . add ( saoPass . params , 'output' , {
233
- 'Beauty' : THREE . SAOPass . OUTPUT . Beauty ,
234
- 'Beauty+SAO' : THREE . SAOPass . OUTPUT . Default ,
235
- 'SAO' : THREE . SAOPass . OUTPUT . SAO ,
236
- 'Depth' : THREE . SAOPass . OUTPUT . Depth ,
237
- 'Normal' : THREE . SAOPass . OUTPUT . Normal
249
+ 'Beauty' : SAOPass . OUTPUT . Beauty ,
250
+ 'Beauty+SAO' : SAOPass . OUTPUT . Default ,
251
+ 'SAO' : SAOPass . OUTPUT . SAO ,
252
+ 'Depth' : SAOPass . OUTPUT . Depth ,
253
+ 'Normal' : SAOPass . OUTPUT . Normal
238
254
} ) . onChange ( function ( value ) { saoPass . params . output = parseInt ( value ) ; } ) ;
239
255
saoFolder . add ( saoPass . params , 'saoBias' , - 1 , 1 ) ;
240
256
saoFolder . add ( saoPass . params , 'saoIntensity' , 0 , 1 ) ;
@@ -251,15 +267,15 @@ EASE.Viewer.prototype.addSAOPass = function(renderToScreen){
251
267
/**
252
268
* Start the render loop
253
269
*/
254
- EASE . Viewer . prototype . start = function ( ) {
270
+ Viewer . prototype . start = function ( ) {
255
271
this . stopped = false ;
256
272
this . draw ( ) ;
257
273
} ;
258
274
259
275
/**
260
276
* Renders the associated scene to the viewer.
261
277
*/
262
- EASE . Viewer . prototype . draw = function ( ) {
278
+ Viewer . prototype . draw = function ( ) {
263
279
if ( this . stopped ) {
264
280
return ; // Do nothing if stopped
265
281
}
@@ -268,6 +284,18 @@ EASE.Viewer.prototype.draw = function(){
268
284
if ( this . delta > this . interval ) {
269
285
// update the controls
270
286
this . cameraControls . update ( ) ;
287
+ this . render ( ) ;
288
+ this . delta = this . delta % this . interval ;
289
+ }
290
+
291
+ // draw the frame
292
+ this . animationRequestId = requestAnimationFrame ( this . draw . bind ( this ) ) ;
293
+ } ;
294
+
295
+ /**
296
+ * Renders the associated scene to the viewer.
297
+ */
298
+ Viewer . prototype . render = function ( ) {
271
299
this . renderer . clear ( ) ;
272
300
if ( this . useShader ) {
273
301
this . composer . render ( ) ;
@@ -278,18 +306,12 @@ EASE.Viewer.prototype.draw = function(){
278
306
this . highlighter . renderHighlights ( this . scene , this . renderer , this . camera ) ;
279
307
this . renderer . render ( this . sceneOrtho , this . cameraOrtho ) ;
280
308
}
281
-
282
- this . delta = this . delta % this . interval ;
283
- }
284
-
285
- // draw the frame
286
- this . animationRequestId = requestAnimationFrame ( this . draw . bind ( this ) ) ;
287
309
} ;
288
310
289
311
/**
290
312
* Stop the render loop
291
313
*/
292
- EASE . Viewer . prototype . stop = function ( ) {
314
+ Viewer . prototype . stop = function ( ) {
293
315
if ( ! this . stopped ) {
294
316
// Stop animation render loop
295
317
cancelAnimationFrame ( this . animationRequestId ) ;
@@ -303,7 +325,7 @@ EASE.Viewer.prototype.stop = function(){
303
325
* @param object - the THREE Object3D to add
304
326
* @param selectable (optional) - if the object should be added to the selectable list
305
327
*/
306
- EASE . Viewer . prototype . addObject = function ( object , selectable ) {
328
+ Viewer . prototype . addObject = function ( object , selectable ) {
307
329
if ( selectable ) {
308
330
this . selectableObjects . add ( object ) ;
309
331
} else {
@@ -317,7 +339,7 @@ EASE.Viewer.prototype.addObject = function(object, selectable) {
317
339
* @param width - new width value
318
340
* @param height - new height value
319
341
*/
320
- EASE . Viewer . prototype . resize = function ( width , height ) {
342
+ Viewer . prototype . resize = function ( width , height ) {
321
343
this . camera . width = width ;
322
344
this . camera . height = height ;
323
345
this . camera . aspect = width / height ;
@@ -338,7 +360,7 @@ EASE.Viewer.prototype.resize = function(width, height) {
338
360
if ( this . fxaaPass ) this . fxaaPass . uniforms [ 'resolution' ] . value . set ( 1.0 / width , 1.0 / height ) ;
339
361
} ;
340
362
341
- EASE . Viewer . prototype . addMarker = function ( marker , node ) {
363
+ Viewer . prototype . addMarker = function ( marker , node ) {
342
364
if ( marker . isBackgroundMarker ) {
343
365
this . backgroundScene . add ( node ) ;
344
366
}
@@ -367,7 +389,7 @@ EASE.Viewer.prototype.addMarker = function(marker,node) {
367
389
} ;
368
390
} ;
369
391
370
- EASE . Viewer . prototype . removeMarker = function ( marker , node ) {
392
+ Viewer . prototype . removeMarker = function ( marker , node ) {
371
393
if ( marker . isBackgroundMarker ) {
372
394
this . backgroundScene . remove ( node ) ;
373
395
}
@@ -384,7 +406,7 @@ EASE.Viewer.prototype.removeMarker = function(marker, node) {
384
406
this . client . removeMarker ( marker ) ;
385
407
} ;
386
408
387
- EASE . Viewer . prototype . addEventListener = function ( marker ) {
409
+ Viewer . prototype . addEventListener = function ( marker ) {
388
410
var that = this ;
389
411
var addEventListenerRecursive = function ( child ) {
390
412
child . addEventListener ( 'dblclick' , function ( ev ) {
@@ -414,9 +436,11 @@ EASE.Viewer.prototype.addEventListener = function(marker) {
414
436
marker . traverse ( addEventListenerRecursive ) ;
415
437
} ;
416
438
417
- EASE . Viewer . prototype . highlight = function ( node ) {
439
+ Viewer . prototype . highlight = function ( node ) {
418
440
this . highlighter . hoverObjs [ node . uuid ] = node ;
419
441
} ;
420
- EASE . Viewer . prototype . unhighlight = function ( node ) {
442
+ Viewer . prototype . unhighlight = function ( node ) {
421
443
delete this . highlighter . hoverObjs [ node . uuid ] ;
422
444
} ;
445
+
446
+ module . exports = Viewer ;
0 commit comments