@xviewer.js/postprocessing 1.0.0-alpha.5 → 1.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -4,18 +4,283 @@ var core = require('@xviewer.js/core');
4
4
  var postprocessing = require('postprocessing');
5
5
  var three = require('three');
6
6
 
7
- function _extends() {
8
- _extends = Object.assign || function assign(target) {
9
- for (var i = 1; i < arguments.length; i++) {
10
- var source = arguments[i];
11
- for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
7
+ class EffectComposerPlugin extends core.Plugin {
8
+ static Instance(viewer) {
9
+ return viewer.getPlugin(EffectComposerPlugin, true);
10
+ }
11
+ get multisampling() {
12
+ return this._composer.multisampling;
13
+ }
14
+ set multisampling(v) {
15
+ this._composer.multisampling = v;
16
+ }
17
+ getPass(constructor) {
18
+ return this._composer.passes.find((v)=>v.constructor === constructor);
19
+ }
20
+ addPass(pass) {
21
+ this._composer.addPass(pass, this._composer.passes.length - 1);
22
+ this._checkOutputPass();
23
+ return pass;
24
+ }
25
+ removePass(pass) {
26
+ this._composer.removePass(pass);
27
+ this._checkOutputPass();
28
+ }
29
+ activePass(pass, v) {
30
+ pass.enabled = v;
31
+ this._checkOutputPass();
32
+ return pass;
33
+ }
34
+ _checkOutputPass() {
35
+ const count = this._composer.passes.filter((v)=>v.enabled && v.name !== "VelocityDepthNormalPass" && v !== this._outputPass).length;
36
+ this._outputPass.enabled = this._composer.multisampling > 0 && count === 1;
37
+ this._setRenderToScreen();
38
+ }
39
+ _setRenderToScreen() {
40
+ const passes = this._composer.passes;
41
+ for(let k = 0, i = passes.length; i--;){
42
+ let pass = passes[i];
43
+ if (pass.enabled && pass.name !== "VelocityDepthNormalPass" && k === 0) {
44
+ k = i;
45
+ }
46
+ pass.renderToScreen = k === i;
12
47
  }
48
+ }
49
+ constructor(props){
50
+ super();
51
+ this.install = ()=>{
52
+ const { renderer, scene, camera } = this.viewer;
53
+ this._renderPass = new postprocessing.RenderPass(scene, camera);
54
+ this._outputPass = new postprocessing.EffectPass(camera);
55
+ this._composer = new postprocessing.EffectComposer(renderer, Object.assign({
56
+ frameBufferType: three.HalfFloatType
57
+ }, props));
58
+ this._composer.addPass(this._renderPass);
59
+ this._composer.addPass(this._outputPass);
60
+ this.viewer._onResize = (width, height)=>this._composer.setSize(width, height);
61
+ this.viewer._onRender = (dt)=>this._composer.render(dt);
62
+ };
63
+ this.uninstall = ()=>{
64
+ this._composer.dispose();
65
+ };
66
+ }
67
+ }
13
68
 
14
- return target;
15
- };
69
+ function _ts_decorate$4(decorators, target, key, desc) {
70
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
71
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
72
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
73
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
74
+ }
75
+ class PassPlugin extends core.Plugin {
76
+ get enable() {
77
+ return this.pass.enabled;
78
+ }
79
+ set enable(v) {
80
+ this.setEnable(v);
81
+ }
82
+ get composer() {
83
+ return EffectComposerPlugin.Instance(this.viewer);
84
+ }
85
+ setEnable(v) {
86
+ this.composer.activePass(this.pass, v);
87
+ }
88
+ }
89
+ _ts_decorate$4([
90
+ core.property
91
+ ], PassPlugin.prototype, "enable", null);
16
92
 
17
- return _extends.apply(this, arguments);
93
+ function _ts_decorate$3(decorators, target, key, desc) {
94
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
95
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
96
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
97
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
98
+ }
99
+ class ToneMappingPlugin extends PassPlugin {
100
+ get mode() {
101
+ return this.effect.mode;
102
+ }
103
+ set mode(v) {
104
+ this.effect.mode = v;
105
+ }
106
+ constructor(props){
107
+ super();
108
+ this.install = ()=>{
109
+ this.effect = new postprocessing.ToneMappingEffect(props);
110
+ this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, this.effect));
111
+ };
112
+ this.uninstall = ()=>{
113
+ this.composer.removePass(this.pass);
114
+ };
115
+ }
18
116
  }
117
+ _ts_decorate$3([
118
+ core.property({
119
+ value: postprocessing.ToneMappingMode
120
+ })
121
+ ], ToneMappingPlugin.prototype, "mode", null);
122
+
123
+ function _ts_decorate$2(decorators, target, key, desc) {
124
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
125
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
126
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
127
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
128
+ }
129
+ class BloomPlugin extends PassPlugin {
130
+ get intensity() {
131
+ return this.effect.intensity;
132
+ }
133
+ set intensity(v) {
134
+ this.effect.intensity = v;
135
+ }
136
+ get luminanceThreshold() {
137
+ return this.effect.luminanceMaterial.threshold;
138
+ }
139
+ set luminanceThreshold(v) {
140
+ this.effect.luminanceMaterial.threshold = v;
141
+ }
142
+ get luminanceSmoothing() {
143
+ return this.effect.luminanceMaterial.smoothing;
144
+ }
145
+ set luminanceSmoothing(v) {
146
+ this.effect.luminanceMaterial.smoothing = v;
147
+ }
148
+ constructor(props){
149
+ super();
150
+ this.install = ()=>{
151
+ this.effect = new postprocessing.BloomEffect({
152
+ blendFunction: postprocessing.BlendFunction.ADD,
153
+ ...props
154
+ });
155
+ this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, this.effect));
156
+ };
157
+ this.uninstall = ()=>{
158
+ this.composer.removePass(this.pass);
159
+ };
160
+ }
161
+ }
162
+ _ts_decorate$2([
163
+ core.property({
164
+ min: 0,
165
+ max: 2,
166
+ step: 0.01
167
+ })
168
+ ], BloomPlugin.prototype, "intensity", null);
169
+ _ts_decorate$2([
170
+ core.property({
171
+ min: 0,
172
+ max: 10,
173
+ step: 0.01
174
+ })
175
+ ], BloomPlugin.prototype, "luminanceThreshold", null);
176
+ _ts_decorate$2([
177
+ core.property({
178
+ min: 0,
179
+ max: 10,
180
+ step: 0.01
181
+ })
182
+ ], BloomPlugin.prototype, "luminanceSmoothing", null);
183
+
184
+ class FXAAPlugin extends PassPlugin {
185
+ constructor(){
186
+ super();
187
+ this.install = ()=>{
188
+ this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, new postprocessing.FXAAEffect()));
189
+ };
190
+ this.uninstall = ()=>{
191
+ this.composer.removePass(this.pass);
192
+ };
193
+ }
194
+ }
195
+
196
+ function _ts_decorate$1(decorators, target, key, desc) {
197
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
198
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
199
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
200
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
201
+ }
202
+ class SMAAPlugin extends PassPlugin {
203
+ get preset() {
204
+ return this._preset;
205
+ }
206
+ set preset(v) {
207
+ if (this._preset !== v) {
208
+ this._preset = v;
209
+ this.effect.applyPreset(v);
210
+ }
211
+ }
212
+ get edgeDetectionMode() {
213
+ return this.effect.edgeDetectionMaterial.edgeDetectionMode;
214
+ }
215
+ set edgeDetectionMode(v) {
216
+ this.effect.edgeDetectionMaterial.edgeDetectionMode = v;
217
+ }
218
+ get predicationMode() {
219
+ return this.effect.edgeDetectionMaterial.predicationMode;
220
+ }
221
+ set predicationMode(v) {
222
+ this.effect.edgeDetectionMaterial.predicationMode = v;
223
+ }
224
+ constructor(props = {}){
225
+ super();
226
+ this._preset = postprocessing.SMAAPreset.MEDIUM;
227
+ this.install = ()=>{
228
+ this.effect = new postprocessing.SMAAEffect(props);
229
+ this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, this.effect));
230
+ };
231
+ this.uninstall = ()=>{
232
+ this.composer.removePass(this.pass);
233
+ };
234
+ }
235
+ }
236
+ _ts_decorate$1([
237
+ core.property({
238
+ value: postprocessing.SMAAPreset
239
+ })
240
+ ], SMAAPlugin.prototype, "preset", null);
241
+ _ts_decorate$1([
242
+ core.property({
243
+ value: postprocessing.EdgeDetectionMode
244
+ })
245
+ ], SMAAPlugin.prototype, "edgeDetectionMode", null);
246
+ _ts_decorate$1([
247
+ core.property({
248
+ value: postprocessing.PredicationMode
249
+ })
250
+ ], SMAAPlugin.prototype, "predicationMode", null);
251
+
252
+ function _ts_decorate(decorators, target, key, desc) {
253
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
254
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
255
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
256
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
257
+ }
258
+ class MSAAPlugin extends core.Plugin {
259
+ get enable() {
260
+ return this.composer.multisampling > 0;
261
+ }
262
+ set enable(v) {
263
+ this.composer.multisampling = v ? this._maxSamples : 0;
264
+ }
265
+ get composer() {
266
+ return EffectComposerPlugin.Instance(this.viewer);
267
+ }
268
+ constructor(){
269
+ super();
270
+ this._maxSamples = 4;
271
+ this.install = ()=>{
272
+ const { renderer } = this.viewer;
273
+ this._maxSamples = Math.min(4, renderer.capabilities.maxSamples);
274
+ this.composer.multisampling = this._maxSamples;
275
+ };
276
+ this.uninstall = ()=>{
277
+ this.composer.multisampling = 0;
278
+ };
279
+ }
280
+ }
281
+ _ts_decorate([
282
+ core.property
283
+ ], MSAAPlugin.prototype, "enable", null);
19
284
 
20
285
  // from: https://news.ycombinator.com/item?id=17876741
21
286
  // reference: http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/
@@ -298,7 +563,10 @@ class TemporalReprojectPass extends postprocessing.Pass {
298
563
  this._scene = scene;
299
564
  this._camera = camera;
300
565
  this.textureCount = textureCount;
301
- options = _extends({}, defaultTemporalReprojectPassOptions, options);
566
+ options = {
567
+ ...defaultTemporalReprojectPassOptions,
568
+ ...options
569
+ };
302
570
  this.renderTarget = new three.WebGLRenderTarget(1, 1, {
303
571
  count: textureCount,
304
572
  minFilter: three.NearestFilter,
@@ -391,15 +659,21 @@ class TRAAEffect extends postprocessing.Effect {
391
659
  this._scene = scene;
392
660
  this._camera = camera;
393
661
  this.velocityDepthNormalPass = velocityDepthNormalPass;
394
- options = _extends({}, options, {
395
- maxBlend: 0.9,
396
- neighborhoodClamp: true,
397
- neighborhoodClampIntensity: 1,
398
- neighborhoodClampRadius: 1,
399
- logTransform: true,
400
- confidencePower: 4
401
- });
402
- this.options = _extends({}, defaultTemporalReprojectPassOptions, options);
662
+ options = {
663
+ ...options,
664
+ ...{
665
+ maxBlend: 0.9,
666
+ neighborhoodClamp: true,
667
+ neighborhoodClampIntensity: 1,
668
+ neighborhoodClampRadius: 1,
669
+ logTransform: true,
670
+ confidencePower: 4
671
+ }
672
+ };
673
+ this.options = {
674
+ ...defaultTemporalReprojectPassOptions,
675
+ ...options
676
+ };
403
677
  this.setSize(options.width, options.height);
404
678
  }
405
679
  }
@@ -412,8 +686,8 @@ class CubeToEquirectEnvPass extends postprocessing.Pass {
412
686
  generateEquirectEnvMap(renderer, cubeMap, width = null, height = null, maxWidth = 4096) {
413
687
  if (width === null && height === null) {
414
688
  const w = cubeMap.source.data[0].width;
415
- const widthEquirect = Math.pow(2, Math.ceil(Math.log2(2 * w * Math.pow(3, 0.5))));
416
- const heightEquirect = Math.pow(2, Math.ceil(Math.log2(w * Math.pow(3, 0.5))));
689
+ const widthEquirect = 2 ** Math.ceil(Math.log2(2 * w * 3 ** 0.5));
690
+ const heightEquirect = 2 ** Math.ceil(Math.log2(w * 3 ** 0.5));
417
691
  width = widthEquirect;
418
692
  height = heightEquirect;
419
693
  }
@@ -525,7 +799,10 @@ const setupBlueNoise = (fragmentShader)=>{
525
799
  const useBlueNoise = (material)=>{
526
800
  const { fragmentShader, uniforms } = setupBlueNoise(material.fragmentShader);
527
801
  material.fragmentShader = fragmentShader;
528
- material.uniforms = _extends({}, material.uniforms, uniforms);
802
+ material.uniforms = {
803
+ ...material.uniforms,
804
+ ...uniforms
805
+ };
529
806
  material.needsUpdate = true;
530
807
  };
531
808
 
@@ -602,7 +879,10 @@ class GBufferMaterial extends three.MeshPhysicalMaterial {
602
879
 
603
880
  gl_FragColor = gBuffer;`);
604
881
  const { uniforms, fragmentShader } = setupBlueNoise(shader.fragmentShader);
605
- shader.uniforms = _extends({}, shader.uniforms, uniforms);
882
+ shader.uniforms = {
883
+ ...shader.uniforms,
884
+ ...uniforms
885
+ };
606
886
  shader.fragmentShader = fragmentShader;
607
887
  }
608
888
  }
@@ -1268,11 +1548,14 @@ const velocity_uniforms = {
1268
1548
  class VelocityDepthNormalMaterial extends three.ShaderMaterial {
1269
1549
  constructor(camera){
1270
1550
  super({
1271
- uniforms: _extends({}, three.UniformsUtils.clone(velocity_uniforms), {
1272
- cameraMatrixWorld: {
1273
- value: camera.matrixWorld
1551
+ uniforms: {
1552
+ ...three.UniformsUtils.clone(velocity_uniforms),
1553
+ ...{
1554
+ cameraMatrixWorld: {
1555
+ value: camera.matrixWorld
1556
+ }
1274
1557
  }
1275
- }),
1558
+ },
1276
1559
  vertexShader: /* glsl */ `
1277
1560
  #include <common>
1278
1561
  #include <uv_pars_vertex>
@@ -1736,7 +2019,10 @@ class PoissonDenoisePass extends postprocessing.Pass {
1736
2019
  super("PoissonBlurPass");
1737
2020
  this.iterations = defaultPoissonBlurOptions.iterations;
1738
2021
  this.index = 0;
1739
- options = _extends({}, defaultPoissonBlurOptions, options);
2022
+ options = {
2023
+ ...defaultPoissonBlurOptions,
2024
+ ...options
2025
+ };
1740
2026
  this.textures = textures;
1741
2027
  let isTextureSpecular = [
1742
2028
  false,
@@ -1880,13 +2166,16 @@ class Denoiser {
1880
2166
  }
1881
2167
  constructor(scene, camera, texture, options = defaultDenosierOptions){
1882
2168
  var _this_denoisePass;
1883
- options = _extends({}, defaultDenosierOptions, options);
2169
+ options = {
2170
+ ...defaultDenosierOptions,
2171
+ ...options
2172
+ };
1884
2173
  this.options = options;
1885
2174
  var _options_velocityDepthNormalPass;
1886
2175
  this.velocityDepthNormalPass = (_options_velocityDepthNormalPass = options.velocityDepthNormalPass) != null ? _options_velocityDepthNormalPass : new VelocityDepthNormalPass(scene, camera);
1887
2176
  this.isOwnVelocityDepthNormalPass = !options.velocityDepthNormalPass;
1888
2177
  const textureCount = options.inputType === "diffuseSpecular" ? 2 : 1;
1889
- this.temporalReprojectPass = new TemporalReprojectPass(scene, camera, this.velocityDepthNormalPass, texture, textureCount, _extends({
2178
+ this.temporalReprojectPass = new TemporalReprojectPass(scene, camera, this.velocityDepthNormalPass, texture, textureCount, {
1890
2179
  fullAccumulate: true,
1891
2180
  logTransform: true,
1892
2181
  copyTextures: !options.denoise,
@@ -1899,8 +2188,9 @@ class Denoiser {
1899
2188
  true
1900
2189
  ],
1901
2190
  neighborhoodClampRadius: 2,
1902
- neighborhoodClampIntensity: 0.5
1903
- }, options));
2191
+ neighborhoodClampIntensity: 0.5,
2192
+ ...options
2193
+ });
1904
2194
  const textures = this.temporalReprojectPass.renderTarget.texture.slice(0, textureCount);
1905
2195
  if (this.options.denoiseMode === "full" || this.options.denoiseMode === "denoised") {
1906
2196
  this.denoisePass = new PoissonDenoisePass(camera, textures, options);
@@ -2278,7 +2568,10 @@ class SSGIEffect extends postprocessing.Effect {
2278
2568
  }
2279
2569
  constructor(composer, scene, camera, options){
2280
2570
  var _scene_fog;
2281
- options = _extends({}, defaultSSGIOptions, options);
2571
+ options = {
2572
+ ...defaultSSGIOptions,
2573
+ ...options
2574
+ };
2282
2575
  let fragmentShader = ssgi_compose.replace("#include <fog_pars_fragment>", three.ShaderChunk.fog_pars_fragment.replace("varying", ""));
2283
2576
  // delete the line starting with gl_FragColor using a regex
2284
2577
  fragmentShader = fragmentShader.replace("#include <fog_fragment>", three.ShaderChunk.fog_fragment.replace(/.*gl_FragColor.*/g, ""));
@@ -2376,10 +2669,11 @@ class SSGIEffect extends postprocessing.Effect {
2376
2669
  }
2377
2670
  }
2378
2671
  this.ssgiPass = new SSGIPass(this, options);
2379
- this.denoiser = new Denoiser(scene, camera, this.ssgiPass.texture, _extends({
2672
+ this.denoiser = new Denoiser(scene, camera, this.ssgiPass.texture, {
2380
2673
  gBufferPass: this.ssgiPass.gBufferPass,
2381
- velocityDepthNormalPass: options.velocityDepthNormalPass
2382
- }, options));
2674
+ velocityDepthNormalPass: options.velocityDepthNormalPass,
2675
+ ...options
2676
+ });
2383
2677
  this.lastSize = {
2384
2678
  width: options.width,
2385
2679
  height: options.height,
@@ -2463,7 +2757,10 @@ class MotionBlurEffect extends postprocessing.Effect {
2463
2757
  }
2464
2758
  }
2465
2759
  constructor(velocityPass, options = defaultOptions){
2466
- options = _extends({}, defaultOptions, options);
2760
+ options = {
2761
+ ...defaultOptions,
2762
+ ...options
2763
+ };
2467
2764
  const { fragmentShader, uniforms } = setupBlueNoise(motion_blur);
2468
2765
  // convert the uniforms from type { uniform: value,... } to type ["uniform", value,...]
2469
2766
  const formattedUniforms = [];
@@ -2524,7 +2821,7 @@ class MotionBlurEffect extends postprocessing.Effect {
2524
2821
 
2525
2822
  var ao_compose = "#define GLSLIFY 1\nuniform sampler2D inputTexture;uniform highp sampler2D depthTexture;uniform float power;uniform vec3 color;void mainImage(const in vec4 inputColor,const in vec2 uv,out vec4 outputColor){float unpackedDepth=textureLod(depthTexture,uv,0.).r;float ao=unpackedDepth>0.9999 ? 1.0 : textureLod(inputTexture,uv,0.0).a;ao=pow(ao,power);vec3 aoColor=mix(color,vec3(1.),ao);aoColor*=inputColor.rgb;outputColor=vec4(aoColor,inputColor.a);}"; // eslint-disable-line
2526
2823
 
2527
- const defaultAOOptions = _extends({
2824
+ const defaultAOOptions = {
2528
2825
  resolutionScale: 1,
2529
2826
  spp: 8,
2530
2827
  distance: 2,
@@ -2535,8 +2832,9 @@ const defaultAOOptions = _extends({
2535
2832
  color: new three.Color("black"),
2536
2833
  useNormalPass: false,
2537
2834
  velocityDepthNormalPass: null,
2538
- normalTexture: null
2539
- }, PoissonDenoisePass.DefaultOptions);
2835
+ normalTexture: null,
2836
+ ...PoissonDenoisePass.DefaultOptions
2837
+ };
2540
2838
  class AOEffect extends postprocessing.Effect {
2541
2839
  makeOptionsReactive(options) {
2542
2840
  for (const key of Object.keys(options)){
@@ -2658,7 +2956,10 @@ class AOEffect extends postprocessing.Effect {
2658
2956
  };
2659
2957
  this.composer = composer;
2660
2958
  this.aoPass = aoPass;
2661
- options = _extends({}, defaultAOOptions, options);
2959
+ options = {
2960
+ ...defaultAOOptions,
2961
+ ...options
2962
+ };
2662
2963
  // set up depth texture
2663
2964
  if (!composer.depthTexture) composer.createDepthTexture();
2664
2965
  this.aoPass.fullscreenMaterial.uniforms.depthTexture.value = composer.depthTexture;
@@ -2679,153 +2980,34 @@ class AOEffect extends postprocessing.Effect {
2679
2980
  }
2680
2981
  AOEffect.DefaultOptions = defaultAOOptions;
2681
2982
 
2682
- class EffectComposerPlugin extends core.Plugin {
2683
- static Instance(viewer) {
2684
- return viewer.getPlugin(EffectComposerPlugin, true);
2685
- }
2686
- get multisampling() {
2687
- return this._composer.multisampling;
2688
- }
2689
- set multisampling(v) {
2690
- this._composer.multisampling = v;
2691
- }
2692
- getPass(constructor) {
2693
- return this._composer.passes.find((v)=>v.constructor === constructor);
2694
- }
2695
- addPass(pass) {
2696
- this._composer.addPass(pass, this._composer.passes.length - 1);
2697
- this._checkOutputPass();
2698
- return pass;
2699
- }
2700
- removePass(pass) {
2701
- this._composer.removePass(pass);
2702
- this._checkOutputPass();
2703
- }
2704
- activePass(pass, v) {
2705
- pass.enabled = v;
2706
- this._checkOutputPass();
2707
- return pass;
2708
- }
2709
- getVelocityDepthNormalPass(autoAdd = false) {
2710
- let vdnPass = this.getPass(VelocityDepthNormalPass);
2711
- if (vdnPass === undefined && autoAdd) {
2712
- vdnPass = this.addPass(new VelocityDepthNormalPass(this.viewer.scene, this.viewer.camera));
2713
- }
2714
- return vdnPass;
2715
- }
2716
- _checkOutputPass() {
2717
- const vdnPass = this.getVelocityDepthNormalPass();
2718
- const count = this._composer.passes.filter((v)=>v.enabled && v !== vdnPass && v !== this._outputPass).length;
2719
- this._outputPass.enabled = this._composer.multisampling > 0 && count === 1;
2720
- this._setRenderToScreen();
2721
- }
2722
- _setRenderToScreen() {
2723
- const vdnPass = this.getVelocityDepthNormalPass();
2724
- const passes = this._composer.passes;
2725
- for(let k = 0, i = passes.length; i--;){
2726
- let pass = passes[i];
2727
- if (pass.enabled && pass !== vdnPass && k === 0) {
2728
- k = i;
2729
- }
2730
- pass.renderToScreen = k === i;
2731
- }
2732
- }
2733
- constructor(props){
2734
- super();
2735
- this.install = ()=>{
2736
- const { renderer, scene, camera } = this.viewer;
2737
- this._renderPass = new postprocessing.RenderPass(scene, camera);
2738
- this._outputPass = new postprocessing.EffectPass(camera);
2739
- this._composer = new postprocessing.EffectComposer(renderer, Object.assign({
2740
- frameBufferType: three.HalfFloatType
2741
- }, props));
2742
- this._composer.addPass(this._renderPass);
2743
- this._composer.addPass(this._outputPass);
2744
- this.viewer._onResize = (width, height)=>this._composer.setSize(width, height);
2745
- this.viewer._onRender = (dt)=>this._composer.render(dt);
2746
- };
2747
- this.uninstall = ()=>{
2748
- this._composer.dispose();
2749
- };
2750
- }
2751
- }
2752
-
2753
- /******************************************************************************
2754
- Copyright (c) Microsoft Corporation.
2755
-
2756
- Permission to use, copy, modify, and/or distribute this software for any
2757
- purpose with or without fee is hereby granted.
2758
-
2759
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
2760
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2761
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
2762
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2763
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2764
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2765
- PERFORMANCE OF THIS SOFTWARE.
2766
- ***************************************************************************** */
2767
- /* global Reflect, Promise, SuppressedError, Symbol */
2768
-
2769
-
2770
- function __decorate(decorators, target, key, desc) {
2771
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2772
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2773
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2774
- return c > 3 && r && Object.defineProperty(target, key, r), r;
2775
- }
2776
-
2777
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
2778
- var e = new Error(message);
2779
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
2780
- };
2781
-
2782
- class PassPlugin extends core.Plugin {
2783
- get enable() {
2784
- return this.pass.enabled;
2785
- }
2786
- set enable(v) {
2787
- this.setEnable(v);
2788
- }
2789
- get composer() {
2790
- return EffectComposerPlugin.Instance(this.viewer);
2791
- }
2792
- setEnable(v) {
2793
- this.composer.activePass(this.pass, v);
2983
+ function getVelocityDepthNormalPass(viewer, autoAdd = true) {
2984
+ const composer = EffectComposerPlugin.Instance(viewer);
2985
+ let vdnPass = composer.getPass(VelocityDepthNormalPass);
2986
+ if (vdnPass === undefined && autoAdd) {
2987
+ vdnPass = composer.addPass(new VelocityDepthNormalPass(viewer.scene, viewer.camera));
2794
2988
  }
2989
+ return vdnPass;
2795
2990
  }
2796
- __decorate([
2797
- core.property
2798
- ], PassPlugin.prototype, "enable", null);
2799
2991
 
2800
- class ToneMappingPlugin extends PassPlugin {
2801
- get mode() {
2802
- return this.effect.mode;
2803
- }
2804
- set mode(v) {
2805
- this.effect.mode = v;
2806
- }
2807
- constructor(props){
2992
+ class TRAAPlugin extends PassPlugin {
2993
+ constructor(props = {}){
2808
2994
  super();
2809
2995
  this.install = ()=>{
2810
- this.effect = new postprocessing.ToneMappingEffect(props);
2811
- this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, this.effect));
2996
+ const { scene, camera } = this.viewer;
2997
+ this._effect = new TRAAEffect(scene, camera, getVelocityDepthNormalPass(this.viewer), props);
2998
+ this.pass = this.composer.addPass(new postprocessing.EffectPass(camera, this._effect));
2812
2999
  };
2813
3000
  this.uninstall = ()=>{
2814
3001
  this.composer.removePass(this.pass);
2815
3002
  };
2816
3003
  }
2817
3004
  }
2818
- __decorate([
2819
- core.property({
2820
- value: postprocessing.ToneMappingMode
2821
- })
2822
- ], ToneMappingPlugin.prototype, "mode", null);
2823
3005
 
2824
3006
  class MotionBlurPlugin extends PassPlugin {
2825
3007
  constructor(){
2826
3008
  super();
2827
3009
  this.install = ()=>{
2828
- const effect = new MotionBlurEffect(this.composer.getVelocityDepthNormalPass(true));
3010
+ const effect = new MotionBlurEffect(getVelocityDepthNormalPass(this.viewer));
2829
3011
  this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, effect));
2830
3012
  };
2831
3013
  this.uninstall = ()=>{
@@ -2834,163 +3016,6 @@ class MotionBlurPlugin extends PassPlugin {
2834
3016
  }
2835
3017
  }
2836
3018
 
2837
- class BloomPlugin extends PassPlugin {
2838
- get intensity() {
2839
- return this.effect.intensity;
2840
- }
2841
- set intensity(v) {
2842
- this.effect.intensity = v;
2843
- }
2844
- get luminanceThreshold() {
2845
- return this.effect.luminanceMaterial.threshold;
2846
- }
2847
- set luminanceThreshold(v) {
2848
- this.effect.luminanceMaterial.threshold = v;
2849
- }
2850
- get luminanceSmoothing() {
2851
- return this.effect.luminanceMaterial.smoothing;
2852
- }
2853
- set luminanceSmoothing(v) {
2854
- this.effect.luminanceMaterial.smoothing = v;
2855
- }
2856
- constructor(props){
2857
- super();
2858
- this.install = ()=>{
2859
- this.effect = new postprocessing.BloomEffect(_extends({
2860
- blendFunction: postprocessing.BlendFunction.ADD
2861
- }, props));
2862
- this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, this.effect));
2863
- };
2864
- this.uninstall = ()=>{
2865
- this.composer.removePass(this.pass);
2866
- };
2867
- }
2868
- }
2869
- __decorate([
2870
- core.property({
2871
- min: 0,
2872
- max: 2,
2873
- step: 0.01
2874
- })
2875
- ], BloomPlugin.prototype, "intensity", null);
2876
- __decorate([
2877
- core.property({
2878
- min: 0,
2879
- max: 10,
2880
- step: 0.01
2881
- })
2882
- ], BloomPlugin.prototype, "luminanceThreshold", null);
2883
- __decorate([
2884
- core.property({
2885
- min: 0,
2886
- max: 10,
2887
- step: 0.01
2888
- })
2889
- ], BloomPlugin.prototype, "luminanceSmoothing", null);
2890
-
2891
- class FXAAPlugin extends PassPlugin {
2892
- constructor(){
2893
- super();
2894
- this.install = ()=>{
2895
- this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, new postprocessing.FXAAEffect()));
2896
- };
2897
- this.uninstall = ()=>{
2898
- this.composer.removePass(this.pass);
2899
- };
2900
- }
2901
- }
2902
-
2903
- class SMAAPlugin extends PassPlugin {
2904
- get preset() {
2905
- return this._preset;
2906
- }
2907
- set preset(v) {
2908
- if (this._preset !== v) {
2909
- this._preset = v;
2910
- this.effect.applyPreset(v);
2911
- }
2912
- }
2913
- get edgeDetectionMode() {
2914
- return this.effect.edgeDetectionMaterial.edgeDetectionMode;
2915
- }
2916
- set edgeDetectionMode(v) {
2917
- this.effect.edgeDetectionMaterial.edgeDetectionMode = v;
2918
- }
2919
- get predicationMode() {
2920
- return this.effect.edgeDetectionMaterial.predicationMode;
2921
- }
2922
- set predicationMode(v) {
2923
- this.effect.edgeDetectionMaterial.predicationMode = v;
2924
- }
2925
- constructor(props = {}){
2926
- super();
2927
- this._preset = postprocessing.SMAAPreset.MEDIUM;
2928
- this.install = ()=>{
2929
- this.effect = new postprocessing.SMAAEffect(props);
2930
- this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, this.effect));
2931
- };
2932
- this.uninstall = ()=>{
2933
- this.composer.removePass(this.pass);
2934
- };
2935
- }
2936
- }
2937
- __decorate([
2938
- core.property({
2939
- value: postprocessing.SMAAPreset
2940
- })
2941
- ], SMAAPlugin.prototype, "preset", null);
2942
- __decorate([
2943
- core.property({
2944
- value: postprocessing.EdgeDetectionMode
2945
- })
2946
- ], SMAAPlugin.prototype, "edgeDetectionMode", null);
2947
- __decorate([
2948
- core.property({
2949
- value: postprocessing.PredicationMode
2950
- })
2951
- ], SMAAPlugin.prototype, "predicationMode", null);
2952
-
2953
- class MSAAPlugin extends core.Plugin {
2954
- get enable() {
2955
- return this.composer.multisampling > 0;
2956
- }
2957
- set enable(v) {
2958
- this.composer.multisampling = v ? this._maxSamples : 0;
2959
- }
2960
- get composer() {
2961
- return EffectComposerPlugin.Instance(this.viewer);
2962
- }
2963
- constructor(){
2964
- super();
2965
- this._maxSamples = 4;
2966
- this.install = ()=>{
2967
- const { renderer } = this.viewer;
2968
- this._maxSamples = Math.min(4, renderer.capabilities.maxSamples);
2969
- this.composer.multisampling = this._maxSamples;
2970
- };
2971
- this.uninstall = ()=>{
2972
- this.composer.multisampling = 0;
2973
- };
2974
- }
2975
- }
2976
- __decorate([
2977
- core.property
2978
- ], MSAAPlugin.prototype, "enable", null);
2979
-
2980
- class TRAAPlugin extends PassPlugin {
2981
- constructor(props = {}){
2982
- super();
2983
- this.install = ()=>{
2984
- const { scene, camera } = this.viewer;
2985
- this._effect = new TRAAEffect(scene, camera, this.composer.getVelocityDepthNormalPass(true), props);
2986
- this.pass = this.composer.addPass(new postprocessing.EffectPass(camera, this._effect));
2987
- };
2988
- this.uninstall = ()=>{
2989
- this.composer.removePass(this.pass);
2990
- };
2991
- }
2992
- }
2993
-
2994
3019
  exports.BloomPlugin = BloomPlugin;
2995
3020
  exports.EffectComposerPlugin = EffectComposerPlugin;
2996
3021
  exports.FXAAPlugin = FXAAPlugin;