@xviewer.js/core 1.0.0-alpha.45 → 1.0.0-alpha.46
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 +92 -6
- package/dist/main.js.map +1 -1
- package/dist/module.js +92 -7
- package/dist/module.js.map +1 -1
- package/package.json +1 -1
- package/types/Viewer.d.ts +2 -2
- package/types/components/PerformanceMonitor.d.ts +48 -0
- package/types/components/index.d.ts +1 -0
- package/types/plugins/EnvironmentPlugin.d.ts +4 -1
package/dist/main.js
CHANGED
|
@@ -3146,6 +3146,79 @@ class Reflector extends Component {
|
|
|
3146
3146
|
}
|
|
3147
3147
|
}
|
|
3148
3148
|
|
|
3149
|
+
class PerformanceMonitor extends Component {
|
|
3150
|
+
subscribe(subscriber) {
|
|
3151
|
+
this.subscriptions.set(Symbol(), subscriber);
|
|
3152
|
+
}
|
|
3153
|
+
constructor({ iterations = 10, ms = 250, threshold = 0.75, step = 0.1, factor: _factor = 0.5, flipflops = Infinity, bounds = (refreshrate)=>refreshrate > 100 ? [
|
|
3154
|
+
60,
|
|
3155
|
+
100
|
|
3156
|
+
] : [
|
|
3157
|
+
40,
|
|
3158
|
+
60
|
|
3159
|
+
], onIncline, onDecline, onChange, onFallback }){
|
|
3160
|
+
super();
|
|
3161
|
+
this.fps = 0;
|
|
3162
|
+
this.index = 0;
|
|
3163
|
+
this.factor = 0.5;
|
|
3164
|
+
this.flipped = 0;
|
|
3165
|
+
this.refreshrate = 0;
|
|
3166
|
+
this.fallback = false;
|
|
3167
|
+
this.frames = [];
|
|
3168
|
+
this.averages = [];
|
|
3169
|
+
this.subscriptions = new Map();
|
|
3170
|
+
let lastFactor = 0;
|
|
3171
|
+
const decimalPlacesRatio = Math.pow(10, 0);
|
|
3172
|
+
this.update = (dt)=>{
|
|
3173
|
+
// If the fallback has been reached do not continue running samples
|
|
3174
|
+
if (this.fallback) return;
|
|
3175
|
+
const { frames, averages } = this;
|
|
3176
|
+
if (averages.length < iterations) {
|
|
3177
|
+
frames.push(performance.now());
|
|
3178
|
+
const msPassed = frames[frames.length - 1] - frames[0];
|
|
3179
|
+
if (msPassed >= ms) {
|
|
3180
|
+
this.fps = Math.round(frames.length / msPassed * 1000 * decimalPlacesRatio) / decimalPlacesRatio;
|
|
3181
|
+
this.refreshrate = Math.max(this.refreshrate, this.fps);
|
|
3182
|
+
averages[this.index++ % iterations] = this.fps;
|
|
3183
|
+
if (averages.length === iterations) {
|
|
3184
|
+
const [lower, upper] = bounds(this.refreshrate);
|
|
3185
|
+
const upperBounds = averages.filter((value)=>value >= upper);
|
|
3186
|
+
const lowerBounds = averages.filter((value)=>value < lower);
|
|
3187
|
+
// Trigger incline when more than -threshold- avgs exceed the upper bound
|
|
3188
|
+
if (upperBounds.length > iterations * threshold) {
|
|
3189
|
+
this.factor = Math.min(1, this.factor + step);
|
|
3190
|
+
this.flipped++;
|
|
3191
|
+
if (onIncline) onIncline(this);
|
|
3192
|
+
this.subscriptions.forEach((value)=>value.onIncline && value.onIncline(this));
|
|
3193
|
+
}
|
|
3194
|
+
// Trigger decline when more than -threshold- avgs are below the lower bound
|
|
3195
|
+
if (lowerBounds.length > iterations * threshold) {
|
|
3196
|
+
this.factor = Math.max(0, this.factor - step);
|
|
3197
|
+
this.flipped++;
|
|
3198
|
+
if (onDecline) onDecline(this);
|
|
3199
|
+
this.subscriptions.forEach((value)=>value.onDecline && value.onDecline(this));
|
|
3200
|
+
}
|
|
3201
|
+
if (lastFactor !== this.factor) {
|
|
3202
|
+
lastFactor = this.factor;
|
|
3203
|
+
if (onChange) onChange(this);
|
|
3204
|
+
this.subscriptions.forEach((value)=>value.onChange && value.onChange(this));
|
|
3205
|
+
}
|
|
3206
|
+
if (this.flipped > flipflops && !this.fallback) {
|
|
3207
|
+
this.fallback = true;
|
|
3208
|
+
if (onFallback) onFallback(this);
|
|
3209
|
+
this.subscriptions.forEach((value)=>value.onFallback && value.onFallback(this));
|
|
3210
|
+
}
|
|
3211
|
+
this.averages = [];
|
|
3212
|
+
// Resetting the refreshrate creates more problems than it solves atm
|
|
3213
|
+
// this.refreshrate = 0
|
|
3214
|
+
}
|
|
3215
|
+
this.frames = [];
|
|
3216
|
+
}
|
|
3217
|
+
}
|
|
3218
|
+
};
|
|
3219
|
+
}
|
|
3220
|
+
}
|
|
3221
|
+
|
|
3149
3222
|
const vert_fullscreen = /*glsl*/ `
|
|
3150
3223
|
varying vec2 vUv;
|
|
3151
3224
|
void main() {
|
|
@@ -4838,7 +4911,7 @@ class Viewer extends EventEmitter {
|
|
|
4838
4911
|
node.visible = active;
|
|
4839
4912
|
return node;
|
|
4840
4913
|
}
|
|
4841
|
-
createRenderTarget(width, height, nearest = false, floatType = false, msaa = 0, mipmap = false) {
|
|
4914
|
+
createRenderTarget(width, height, nearest = false, floatType = false, msaa = 0, mipmap = false, depth = false) {
|
|
4842
4915
|
return new three.WebGLRenderTarget(width, height, {
|
|
4843
4916
|
wrapS: three.ClampToEdgeWrapping,
|
|
4844
4917
|
wrapT: three.ClampToEdgeWrapping,
|
|
@@ -4847,13 +4920,13 @@ class Viewer extends EventEmitter {
|
|
|
4847
4920
|
type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : three.UnsignedByteType : floatType,
|
|
4848
4921
|
anisotropy: 0,
|
|
4849
4922
|
colorSpace: three.LinearSRGBColorSpace,
|
|
4850
|
-
depthBuffer:
|
|
4923
|
+
depthBuffer: depth,
|
|
4851
4924
|
stencilBuffer: false,
|
|
4852
4925
|
samples: SystemInfo.isSupportMSAA ? msaa : 0,
|
|
4853
4926
|
generateMipmaps: mipmap
|
|
4854
4927
|
});
|
|
4855
4928
|
}
|
|
4856
|
-
createCubeRenderTarget(size, nearest = false, floatType = false, msaa = 0, mipmap = false) {
|
|
4929
|
+
createCubeRenderTarget(size, nearest = false, floatType = false, msaa = 0, mipmap = false, depth = false) {
|
|
4857
4930
|
return new three.WebGLCubeRenderTarget(size, {
|
|
4858
4931
|
wrapS: three.ClampToEdgeWrapping,
|
|
4859
4932
|
wrapT: three.ClampToEdgeWrapping,
|
|
@@ -4862,7 +4935,7 @@ class Viewer extends EventEmitter {
|
|
|
4862
4935
|
type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : three.UnsignedByteType : floatType,
|
|
4863
4936
|
anisotropy: 0,
|
|
4864
4937
|
colorSpace: three.LinearSRGBColorSpace,
|
|
4865
|
-
depthBuffer:
|
|
4938
|
+
depthBuffer: depth,
|
|
4866
4939
|
stencilBuffer: false,
|
|
4867
4940
|
samples: SystemInfo.isSupportMSAA ? msaa : 0,
|
|
4868
4941
|
generateMipmaps: mipmap
|
|
@@ -5245,7 +5318,14 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5245
5318
|
}
|
|
5246
5319
|
}
|
|
5247
5320
|
}
|
|
5248
|
-
onRender() {
|
|
5321
|
+
onRender(dt) {
|
|
5322
|
+
if (this._elapsed >= this.interval || this._elapsed === 0) {
|
|
5323
|
+
this._elapsed = 0;
|
|
5324
|
+
this._renderFrame();
|
|
5325
|
+
}
|
|
5326
|
+
this._elapsed += dt;
|
|
5327
|
+
}
|
|
5328
|
+
_renderFrame() {
|
|
5249
5329
|
const { renderer } = this.viewer;
|
|
5250
5330
|
const autoClear = renderer.autoClear;
|
|
5251
5331
|
const oldTarget = renderer.getRenderTarget();
|
|
@@ -5282,14 +5362,16 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5282
5362
|
};
|
|
5283
5363
|
this._debug = false;
|
|
5284
5364
|
this._debugNode = null;
|
|
5365
|
+
this._elapsed = 0;
|
|
5285
5366
|
this.performance = _Performance.HIGH;
|
|
5286
5367
|
this.envMapIntensity = 1;
|
|
5287
5368
|
this.reflectExposure = 1;
|
|
5288
5369
|
this.reflectBlurIntensity = 5;
|
|
5370
|
+
this.interval = 0;
|
|
5289
5371
|
this.install = ()=>{
|
|
5290
5372
|
const viewer = this.viewer;
|
|
5291
5373
|
this._scene = scene || viewer.scene;
|
|
5292
|
-
const cubeRenderTarget = viewer.createCubeRenderTarget(resolution, false, floatType, 0, true);
|
|
5374
|
+
const cubeRenderTarget = viewer.createCubeRenderTarget(resolution, false, floatType, 0, true, true);
|
|
5293
5375
|
this._cubeCamera = new three.CubeCamera(near || viewer.camera.near, far || viewer.camera.far, cubeRenderTarget);
|
|
5294
5376
|
this._cubeCamera.position.copy(position);
|
|
5295
5377
|
this._cubeCamera.layers.mask = layer;
|
|
@@ -5338,6 +5420,9 @@ __decorate([
|
|
|
5338
5420
|
step: 0.1
|
|
5339
5421
|
})
|
|
5340
5422
|
], EnvironmentPlugin.prototype, "reflectBlurIntensity", void 0);
|
|
5423
|
+
__decorate([
|
|
5424
|
+
property
|
|
5425
|
+
], EnvironmentPlugin.prototype, "interval", void 0);
|
|
5341
5426
|
|
|
5342
5427
|
class BoxProjectionPlugin extends Plugin {
|
|
5343
5428
|
get debug() {
|
|
@@ -5482,6 +5567,7 @@ exports.FInterpTo = FInterpTo;
|
|
|
5482
5567
|
exports.FreelookVirtualCamera = FreelookVirtualCamera;
|
|
5483
5568
|
exports.Logger = Logger;
|
|
5484
5569
|
exports.ObjectInstance = ObjectInstance;
|
|
5570
|
+
exports.PerformanceMonitor = PerformanceMonitor;
|
|
5485
5571
|
exports.Perlin = Perlin;
|
|
5486
5572
|
exports.Plane = Plane;
|
|
5487
5573
|
exports.Plugin = Plugin;
|