@xviewer.js/core 1.0.0-alpha.45 → 1.0.0-alpha.47

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
@@ -4838,7 +4838,7 @@ class Viewer extends EventEmitter {
4838
4838
  node.visible = active;
4839
4839
  return node;
4840
4840
  }
4841
- createRenderTarget(width, height, nearest = false, floatType = false, msaa = 0, mipmap = false) {
4841
+ createRenderTarget(width, height, nearest = false, floatType = false, msaa = 0, mipmap = false, depth = false) {
4842
4842
  return new three.WebGLRenderTarget(width, height, {
4843
4843
  wrapS: three.ClampToEdgeWrapping,
4844
4844
  wrapT: three.ClampToEdgeWrapping,
@@ -4847,13 +4847,13 @@ class Viewer extends EventEmitter {
4847
4847
  type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : three.UnsignedByteType : floatType,
4848
4848
  anisotropy: 0,
4849
4849
  colorSpace: three.LinearSRGBColorSpace,
4850
- depthBuffer: false,
4850
+ depthBuffer: depth,
4851
4851
  stencilBuffer: false,
4852
4852
  samples: SystemInfo.isSupportMSAA ? msaa : 0,
4853
4853
  generateMipmaps: mipmap
4854
4854
  });
4855
4855
  }
4856
- createCubeRenderTarget(size, nearest = false, floatType = false, msaa = 0, mipmap = false) {
4856
+ createCubeRenderTarget(size, nearest = false, floatType = false, msaa = 0, mipmap = false, depth = false) {
4857
4857
  return new three.WebGLCubeRenderTarget(size, {
4858
4858
  wrapS: three.ClampToEdgeWrapping,
4859
4859
  wrapT: three.ClampToEdgeWrapping,
@@ -4862,7 +4862,7 @@ class Viewer extends EventEmitter {
4862
4862
  type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : three.UnsignedByteType : floatType,
4863
4863
  anisotropy: 0,
4864
4864
  colorSpace: three.LinearSRGBColorSpace,
4865
- depthBuffer: false,
4865
+ depthBuffer: depth,
4866
4866
  stencilBuffer: false,
4867
4867
  samples: SystemInfo.isSupportMSAA ? msaa : 0,
4868
4868
  generateMipmaps: mipmap
@@ -5245,7 +5245,14 @@ class EnvironmentPlugin extends Plugin {
5245
5245
  }
5246
5246
  }
5247
5247
  }
5248
- onRender() {
5248
+ onRender(dt) {
5249
+ if (this._elapsed >= this.interval || this._elapsed === 0) {
5250
+ this._elapsed = 0;
5251
+ this._renderFrame();
5252
+ }
5253
+ this._elapsed += dt;
5254
+ }
5255
+ _renderFrame() {
5249
5256
  const { renderer } = this.viewer;
5250
5257
  const autoClear = renderer.autoClear;
5251
5258
  const oldTarget = renderer.getRenderTarget();
@@ -5282,14 +5289,16 @@ class EnvironmentPlugin extends Plugin {
5282
5289
  };
5283
5290
  this._debug = false;
5284
5291
  this._debugNode = null;
5292
+ this._elapsed = 0;
5285
5293
  this.performance = _Performance.HIGH;
5286
5294
  this.envMapIntensity = 1;
5287
5295
  this.reflectExposure = 1;
5288
5296
  this.reflectBlurIntensity = 5;
5297
+ this.interval = 0;
5289
5298
  this.install = ()=>{
5290
5299
  const viewer = this.viewer;
5291
5300
  this._scene = scene || viewer.scene;
5292
- const cubeRenderTarget = viewer.createCubeRenderTarget(resolution, false, floatType, 0, true);
5301
+ const cubeRenderTarget = viewer.createCubeRenderTarget(resolution, false, floatType, 0, true, true);
5293
5302
  this._cubeCamera = new three.CubeCamera(near || viewer.camera.near, far || viewer.camera.far, cubeRenderTarget);
5294
5303
  this._cubeCamera.position.copy(position);
5295
5304
  this._cubeCamera.layers.mask = layer;
@@ -5338,6 +5347,9 @@ __decorate([
5338
5347
  step: 0.1
5339
5348
  })
5340
5349
  ], EnvironmentPlugin.prototype, "reflectBlurIntensity", void 0);
5350
+ __decorate([
5351
+ property
5352
+ ], EnvironmentPlugin.prototype, "interval", void 0);
5341
5353
 
5342
5354
  class BoxProjectionPlugin extends Plugin {
5343
5355
  get debug() {
@@ -5466,6 +5478,79 @@ __decorate([
5466
5478
  property
5467
5479
  ], BoxProjectionPlugin.prototype, "boxMax", null);
5468
5480
 
5481
+ class PerformanceMonitorPlugin extends Plugin {
5482
+ subscribe(subscriber) {
5483
+ this.subscriptions.set(Symbol(), subscriber);
5484
+ }
5485
+ constructor({ iterations = 10, ms = 250, threshold = 0.75, step = 0.1, factor: _factor = 0.5, flipflops = Infinity, bounds = (refreshrate)=>refreshrate > 100 ? [
5486
+ 60,
5487
+ 100
5488
+ ] : [
5489
+ 40,
5490
+ 60
5491
+ ], onIncline, onDecline, onChange, onFallback }){
5492
+ super();
5493
+ this.fps = 0;
5494
+ this.index = 0;
5495
+ this.factor = 0.5;
5496
+ this.flipped = 0;
5497
+ this.refreshrate = 0;
5498
+ this.fallback = false;
5499
+ this.frames = [];
5500
+ this.averages = [];
5501
+ this.subscriptions = new Map();
5502
+ let lastFactor = 0;
5503
+ const decimalPlacesRatio = Math.pow(10, 0);
5504
+ this.onUpdate = (dt)=>{
5505
+ // If the fallback has been reached do not continue running samples
5506
+ if (this.fallback) return;
5507
+ const { frames, averages } = this;
5508
+ if (averages.length < iterations) {
5509
+ frames.push(performance.now());
5510
+ const msPassed = frames[frames.length - 1] - frames[0];
5511
+ if (msPassed >= ms) {
5512
+ this.fps = Math.round(frames.length / msPassed * 1000 * decimalPlacesRatio) / decimalPlacesRatio;
5513
+ this.refreshrate = Math.max(this.refreshrate, this.fps);
5514
+ averages[this.index++ % iterations] = this.fps;
5515
+ if (averages.length === iterations) {
5516
+ const [lower, upper] = bounds(this.refreshrate);
5517
+ const upperBounds = averages.filter((value)=>value >= upper);
5518
+ const lowerBounds = averages.filter((value)=>value < lower);
5519
+ // Trigger incline when more than -threshold- avgs exceed the upper bound
5520
+ if (upperBounds.length > iterations * threshold) {
5521
+ this.factor = Math.min(1, this.factor + step);
5522
+ this.flipped++;
5523
+ if (onIncline) onIncline(this);
5524
+ this.subscriptions.forEach((value)=>value.onIncline && value.onIncline(this));
5525
+ }
5526
+ // Trigger decline when more than -threshold- avgs are below the lower bound
5527
+ if (lowerBounds.length > iterations * threshold) {
5528
+ this.factor = Math.max(0, this.factor - step);
5529
+ this.flipped++;
5530
+ if (onDecline) onDecline(this);
5531
+ this.subscriptions.forEach((value)=>value.onDecline && value.onDecline(this));
5532
+ }
5533
+ if (lastFactor !== this.factor) {
5534
+ lastFactor = this.factor;
5535
+ if (onChange) onChange(this);
5536
+ this.subscriptions.forEach((value)=>value.onChange && value.onChange(this));
5537
+ }
5538
+ if (this.flipped > flipflops && !this.fallback) {
5539
+ this.fallback = true;
5540
+ if (onFallback) onFallback(this);
5541
+ this.subscriptions.forEach((value)=>value.onFallback && value.onFallback(this));
5542
+ }
5543
+ this.averages = [];
5544
+ // Resetting the refreshrate creates more problems than it solves atm
5545
+ // this.refreshrate = 0
5546
+ }
5547
+ this.frames = [];
5548
+ }
5549
+ }
5550
+ };
5551
+ }
5552
+ }
5553
+
5469
5554
  exports.AnimationCurve = AnimationCurve;
5470
5555
  exports.Box = Box;
5471
5556
  exports.BoxProjectionPlugin = BoxProjectionPlugin;
@@ -5482,6 +5567,7 @@ exports.FInterpTo = FInterpTo;
5482
5567
  exports.FreelookVirtualCamera = FreelookVirtualCamera;
5483
5568
  exports.Logger = Logger;
5484
5569
  exports.ObjectInstance = ObjectInstance;
5570
+ exports.PerformanceMonitorPlugin = PerformanceMonitorPlugin;
5485
5571
  exports.Perlin = Perlin;
5486
5572
  exports.Plane = Plane;
5487
5573
  exports.Plugin = Plugin;