@xviewer.js/core 1.0.0-alpha.46 → 1.0.0-alpha.48
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 +113 -93
- package/dist/main.js.map +1 -1
- package/dist/module.js +113 -93
- package/dist/module.js.map +1 -1
- package/package.json +1 -1
- package/types/Viewer.d.ts +2 -0
- package/types/components/index.d.ts +0 -1
- package/types/passes/cubeuv/MergeInfo.d.ts +1 -1
- package/types/passes/cubeuv/utils.d.ts +4 -3
- package/types/plugins/EnvironmentPlugin.d.ts +7 -4
- package/types/plugins/PerformanceMonitorPlugin.d.ts +48 -0
- package/types/plugins/index.d.ts +1 -0
package/dist/main.js
CHANGED
|
@@ -3146,79 +3146,6 @@ 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
|
-
|
|
3222
3149
|
const vert_fullscreen = /*glsl*/ `
|
|
3223
3150
|
varying vec2 vUv;
|
|
3224
3151
|
void main() {
|
|
@@ -3677,10 +3604,11 @@ const _axisDirections = [
|
|
|
3677
3604
|
/*@__PURE__*/ new three.Vector3(PHI, INV_PHI, 0),
|
|
3678
3605
|
/*@__PURE__*/ new three.Vector3(-PHI, INV_PHI, 0)
|
|
3679
3606
|
];
|
|
3680
|
-
const
|
|
3681
|
-
|
|
3607
|
+
const _Quality = {
|
|
3608
|
+
LOW: 0,
|
|
3682
3609
|
MEDIUM: 1,
|
|
3683
|
-
|
|
3610
|
+
HIGH: 2,
|
|
3611
|
+
ULTRA: 3
|
|
3684
3612
|
};
|
|
3685
3613
|
function _setViewport(target, x, y, width, height) {
|
|
3686
3614
|
target.viewport.set(x, y, width, height);
|
|
@@ -4677,6 +4605,12 @@ class Viewer extends EventEmitter {
|
|
|
4677
4605
|
get input() {
|
|
4678
4606
|
return this._input;
|
|
4679
4607
|
}
|
|
4608
|
+
get targetFrameRate() {
|
|
4609
|
+
return this._targetFrameRate;
|
|
4610
|
+
}
|
|
4611
|
+
set targetFrameRate(v) {
|
|
4612
|
+
this._targetFrameRate = Math.max(1, v);
|
|
4613
|
+
}
|
|
4680
4614
|
destroy() {
|
|
4681
4615
|
this._renderer.dispose();
|
|
4682
4616
|
this._taskManager.destroy();
|
|
@@ -5078,7 +5012,7 @@ class MergeRefectPass {
|
|
|
5078
5012
|
}
|
|
5079
5013
|
mergeReflect(info) {
|
|
5080
5014
|
this._pmremGenerator._copyTexture(this._envMapTarget, this._sourceTarget.texture, info.envMapIntensity);
|
|
5081
|
-
this._pmremGenerator._mergeReflect(this._envMapTarget, this._reflectMap, info.
|
|
5015
|
+
this._pmremGenerator._mergeReflect(this._envMapTarget, this._reflectMap, info.quality);
|
|
5082
5016
|
info.envMapTarget = this._envMapTarget;
|
|
5083
5017
|
info.lodMax = this._pmremGenerator._lodMeshes.length - 1;
|
|
5084
5018
|
}
|
|
@@ -5112,19 +5046,19 @@ class MergeRefectPass {
|
|
|
5112
5046
|
pmremGenerator._clearTexture = function(targetOut, intensity) {
|
|
5113
5047
|
this._copyTexture(targetOut, this._sourceTarget.texture, intensity);
|
|
5114
5048
|
};
|
|
5115
|
-
pmremGenerator._mergeReflect = function(sourceTarget, reflectMap,
|
|
5049
|
+
pmremGenerator._mergeReflect = function(sourceTarget, reflectMap, quality) {
|
|
5116
5050
|
const renderer = this._renderer;
|
|
5117
5051
|
const autoClear = renderer.autoClear;
|
|
5118
5052
|
const cubeMapMaterial = this._cubeMapMaterial;
|
|
5119
5053
|
const uniforms = this._cubeMapMaterial.uniforms;
|
|
5120
5054
|
uniforms.envMap.value = reflectMap;
|
|
5121
5055
|
renderer.autoClear = false;
|
|
5122
|
-
if (
|
|
5056
|
+
if (quality === _Quality.HIGH) {
|
|
5123
5057
|
for(let i = 0; i < this._lodMeshes.length - 1; i++){
|
|
5124
5058
|
uniforms.lod.value = i < 5 ? 0 : i;
|
|
5125
5059
|
this._blit(sourceTarget, i, cubeMapMaterial);
|
|
5126
5060
|
}
|
|
5127
|
-
} else if (
|
|
5061
|
+
} else if (quality === _Quality.MEDIUM) {
|
|
5128
5062
|
for(let i = 0; i < this._lodMeshes.length; i++){
|
|
5129
5063
|
if (i < 4) {
|
|
5130
5064
|
uniforms.lod.value = 0;
|
|
@@ -5133,7 +5067,7 @@ class MergeRefectPass {
|
|
|
5133
5067
|
this._pmremblur(sourceTarget, i - 1, i);
|
|
5134
5068
|
}
|
|
5135
5069
|
}
|
|
5136
|
-
} else {
|
|
5070
|
+
} else if (quality === _Quality.ULTRA) {
|
|
5137
5071
|
uniforms.lod.value = 0;
|
|
5138
5072
|
this._blit(sourceTarget, 0, cubeMapMaterial);
|
|
5139
5073
|
for(let i = 1; i < this._lodMeshes.length; i++){
|
|
@@ -5319,11 +5253,18 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5319
5253
|
}
|
|
5320
5254
|
}
|
|
5321
5255
|
onRender(dt) {
|
|
5322
|
-
if (this.
|
|
5323
|
-
this._elapsed
|
|
5256
|
+
if (!this.manual) {
|
|
5257
|
+
if (this._elapsed >= this.interval || this._elapsed === 0) {
|
|
5258
|
+
this._elapsed = 0;
|
|
5259
|
+
this._renderFrame();
|
|
5260
|
+
}
|
|
5261
|
+
this._elapsed += dt;
|
|
5262
|
+
}
|
|
5263
|
+
}
|
|
5264
|
+
manualFrame() {
|
|
5265
|
+
if (this.manual) {
|
|
5324
5266
|
this._renderFrame();
|
|
5325
5267
|
}
|
|
5326
|
-
this._elapsed += dt;
|
|
5327
5268
|
}
|
|
5328
5269
|
_renderFrame() {
|
|
5329
5270
|
const { renderer } = this.viewer;
|
|
@@ -5332,13 +5273,15 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5332
5273
|
const oldActiveCubeFace = renderer.getActiveCubeFace();
|
|
5333
5274
|
const oldActiveMipmapLevel = renderer.getActiveMipmapLevel();
|
|
5334
5275
|
renderer.autoClear = true;
|
|
5335
|
-
this.
|
|
5336
|
-
this._mergeInfo.performance = this.performance;
|
|
5276
|
+
this._mergeInfo.quality = this.quality;
|
|
5337
5277
|
this._mergeInfo.exposure = this.reflectExposure;
|
|
5338
5278
|
this._mergeInfo.envMapIntensity = this.envMapIntensity;
|
|
5339
5279
|
this._mergeInfo.blurIntensity = this.reflectBlurIntensity;
|
|
5280
|
+
if (this.quality !== _Quality.LOW) {
|
|
5281
|
+
this._cubeCamera.update(renderer, this._scene);
|
|
5282
|
+
}
|
|
5340
5283
|
this._reflectPass.mergeReflect(this._mergeInfo);
|
|
5341
|
-
if (this.
|
|
5284
|
+
if (this.quality === _Quality.HIGH) {
|
|
5342
5285
|
if (this._mipBlurPass === undefined) {
|
|
5343
5286
|
this._mipBlurPass = new MergeMipBlurPass({
|
|
5344
5287
|
viewer: this.viewer,
|
|
@@ -5353,7 +5296,7 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5353
5296
|
constructor({ envMap, scene, near, far, layer = 0, resolution = 256, floatType = three.HalfFloatType, position = new three.Vector3(0, 1, 0) } = {}){
|
|
5354
5297
|
super();
|
|
5355
5298
|
this._mergeInfo = {
|
|
5356
|
-
|
|
5299
|
+
quality: _Quality.HIGH,
|
|
5357
5300
|
envMapTarget: null,
|
|
5358
5301
|
envMapIntensity: 1,
|
|
5359
5302
|
blurIntensity: 1,
|
|
@@ -5363,11 +5306,12 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5363
5306
|
this._debug = false;
|
|
5364
5307
|
this._debugNode = null;
|
|
5365
5308
|
this._elapsed = 0;
|
|
5366
|
-
this.
|
|
5309
|
+
this.quality = _Quality.HIGH;
|
|
5367
5310
|
this.envMapIntensity = 1;
|
|
5368
5311
|
this.reflectExposure = 1;
|
|
5369
5312
|
this.reflectBlurIntensity = 5;
|
|
5370
5313
|
this.interval = 0;
|
|
5314
|
+
this.manual = false;
|
|
5371
5315
|
this.install = ()=>{
|
|
5372
5316
|
const viewer = this.viewer;
|
|
5373
5317
|
this._scene = scene || viewer.scene;
|
|
@@ -5390,15 +5334,15 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5390
5334
|
};
|
|
5391
5335
|
}
|
|
5392
5336
|
}
|
|
5393
|
-
EnvironmentPlugin.
|
|
5337
|
+
EnvironmentPlugin.Quality = _Quality;
|
|
5394
5338
|
__decorate([
|
|
5395
5339
|
property
|
|
5396
5340
|
], EnvironmentPlugin.prototype, "debug", null);
|
|
5397
5341
|
__decorate([
|
|
5398
5342
|
property({
|
|
5399
|
-
value:
|
|
5343
|
+
value: _Quality
|
|
5400
5344
|
})
|
|
5401
|
-
], EnvironmentPlugin.prototype, "
|
|
5345
|
+
], EnvironmentPlugin.prototype, "quality", void 0);
|
|
5402
5346
|
__decorate([
|
|
5403
5347
|
property({
|
|
5404
5348
|
min: 0,
|
|
@@ -5423,6 +5367,9 @@ __decorate([
|
|
|
5423
5367
|
__decorate([
|
|
5424
5368
|
property
|
|
5425
5369
|
], EnvironmentPlugin.prototype, "interval", void 0);
|
|
5370
|
+
__decorate([
|
|
5371
|
+
property
|
|
5372
|
+
], EnvironmentPlugin.prototype, "manual", void 0);
|
|
5426
5373
|
|
|
5427
5374
|
class BoxProjectionPlugin extends Plugin {
|
|
5428
5375
|
get debug() {
|
|
@@ -5551,6 +5498,79 @@ __decorate([
|
|
|
5551
5498
|
property
|
|
5552
5499
|
], BoxProjectionPlugin.prototype, "boxMax", null);
|
|
5553
5500
|
|
|
5501
|
+
class PerformanceMonitorPlugin extends Plugin {
|
|
5502
|
+
subscribe(subscriber) {
|
|
5503
|
+
this.subscriptions.set(Symbol(), subscriber);
|
|
5504
|
+
}
|
|
5505
|
+
constructor({ iterations = 10, ms = 250, threshold = 0.75, step = 0.1, factor: _factor = 0.5, flipflops = Infinity, bounds = (refreshrate)=>refreshrate > 100 ? [
|
|
5506
|
+
60,
|
|
5507
|
+
100
|
|
5508
|
+
] : [
|
|
5509
|
+
40,
|
|
5510
|
+
60
|
|
5511
|
+
], onIncline, onDecline, onChange, onFallback }){
|
|
5512
|
+
super();
|
|
5513
|
+
this.fps = 0;
|
|
5514
|
+
this.index = 0;
|
|
5515
|
+
this.factor = 0.5;
|
|
5516
|
+
this.flipped = 0;
|
|
5517
|
+
this.refreshrate = 0;
|
|
5518
|
+
this.fallback = false;
|
|
5519
|
+
this.frames = [];
|
|
5520
|
+
this.averages = [];
|
|
5521
|
+
this.subscriptions = new Map();
|
|
5522
|
+
let lastFactor = 0;
|
|
5523
|
+
const decimalPlacesRatio = Math.pow(10, 0);
|
|
5524
|
+
this.onUpdate = (dt)=>{
|
|
5525
|
+
// If the fallback has been reached do not continue running samples
|
|
5526
|
+
if (this.fallback) return;
|
|
5527
|
+
const { frames, averages } = this;
|
|
5528
|
+
if (averages.length < iterations) {
|
|
5529
|
+
frames.push(performance.now());
|
|
5530
|
+
const msPassed = frames[frames.length - 1] - frames[0];
|
|
5531
|
+
if (msPassed >= ms) {
|
|
5532
|
+
this.fps = Math.round(frames.length / msPassed * 1000 * decimalPlacesRatio) / decimalPlacesRatio;
|
|
5533
|
+
this.refreshrate = Math.max(this.refreshrate, this.fps);
|
|
5534
|
+
averages[this.index++ % iterations] = this.fps;
|
|
5535
|
+
if (averages.length === iterations) {
|
|
5536
|
+
const [lower, upper] = bounds(this.refreshrate);
|
|
5537
|
+
const upperBounds = averages.filter((value)=>value >= upper);
|
|
5538
|
+
const lowerBounds = averages.filter((value)=>value < lower);
|
|
5539
|
+
// Trigger incline when more than -threshold- avgs exceed the upper bound
|
|
5540
|
+
if (upperBounds.length > iterations * threshold) {
|
|
5541
|
+
this.factor = Math.min(1, this.factor + step);
|
|
5542
|
+
this.flipped++;
|
|
5543
|
+
if (onIncline) onIncline(this);
|
|
5544
|
+
this.subscriptions.forEach((value)=>value.onIncline && value.onIncline(this));
|
|
5545
|
+
}
|
|
5546
|
+
// Trigger decline when more than -threshold- avgs are below the lower bound
|
|
5547
|
+
if (lowerBounds.length > iterations * threshold) {
|
|
5548
|
+
this.factor = Math.max(0, this.factor - step);
|
|
5549
|
+
this.flipped++;
|
|
5550
|
+
if (onDecline) onDecline(this);
|
|
5551
|
+
this.subscriptions.forEach((value)=>value.onDecline && value.onDecline(this));
|
|
5552
|
+
}
|
|
5553
|
+
if (lastFactor !== this.factor) {
|
|
5554
|
+
lastFactor = this.factor;
|
|
5555
|
+
if (onChange) onChange(this);
|
|
5556
|
+
this.subscriptions.forEach((value)=>value.onChange && value.onChange(this));
|
|
5557
|
+
}
|
|
5558
|
+
if (this.flipped > flipflops && !this.fallback) {
|
|
5559
|
+
this.fallback = true;
|
|
5560
|
+
if (onFallback) onFallback(this);
|
|
5561
|
+
this.subscriptions.forEach((value)=>value.onFallback && value.onFallback(this));
|
|
5562
|
+
}
|
|
5563
|
+
this.averages = [];
|
|
5564
|
+
// Resetting the refreshrate creates more problems than it solves atm
|
|
5565
|
+
// this.refreshrate = 0
|
|
5566
|
+
}
|
|
5567
|
+
this.frames = [];
|
|
5568
|
+
}
|
|
5569
|
+
}
|
|
5570
|
+
};
|
|
5571
|
+
}
|
|
5572
|
+
}
|
|
5573
|
+
|
|
5554
5574
|
exports.AnimationCurve = AnimationCurve;
|
|
5555
5575
|
exports.Box = Box;
|
|
5556
5576
|
exports.BoxProjectionPlugin = BoxProjectionPlugin;
|
|
@@ -5567,7 +5587,7 @@ exports.FInterpTo = FInterpTo;
|
|
|
5567
5587
|
exports.FreelookVirtualCamera = FreelookVirtualCamera;
|
|
5568
5588
|
exports.Logger = Logger;
|
|
5569
5589
|
exports.ObjectInstance = ObjectInstance;
|
|
5570
|
-
exports.
|
|
5590
|
+
exports.PerformanceMonitorPlugin = PerformanceMonitorPlugin;
|
|
5571
5591
|
exports.Perlin = Perlin;
|
|
5572
5592
|
exports.Plane = Plane;
|
|
5573
5593
|
exports.Plugin = Plugin;
|