@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/module.js
CHANGED
|
@@ -3144,6 +3144,79 @@ class Reflector extends Component {
|
|
|
3144
3144
|
}
|
|
3145
3145
|
}
|
|
3146
3146
|
|
|
3147
|
+
class PerformanceMonitor extends Component {
|
|
3148
|
+
subscribe(subscriber) {
|
|
3149
|
+
this.subscriptions.set(Symbol(), subscriber);
|
|
3150
|
+
}
|
|
3151
|
+
constructor({ iterations = 10, ms = 250, threshold = 0.75, step = 0.1, factor: _factor = 0.5, flipflops = Infinity, bounds = (refreshrate)=>refreshrate > 100 ? [
|
|
3152
|
+
60,
|
|
3153
|
+
100
|
|
3154
|
+
] : [
|
|
3155
|
+
40,
|
|
3156
|
+
60
|
|
3157
|
+
], onIncline, onDecline, onChange, onFallback }){
|
|
3158
|
+
super();
|
|
3159
|
+
this.fps = 0;
|
|
3160
|
+
this.index = 0;
|
|
3161
|
+
this.factor = 0.5;
|
|
3162
|
+
this.flipped = 0;
|
|
3163
|
+
this.refreshrate = 0;
|
|
3164
|
+
this.fallback = false;
|
|
3165
|
+
this.frames = [];
|
|
3166
|
+
this.averages = [];
|
|
3167
|
+
this.subscriptions = new Map();
|
|
3168
|
+
let lastFactor = 0;
|
|
3169
|
+
const decimalPlacesRatio = Math.pow(10, 0);
|
|
3170
|
+
this.update = (dt)=>{
|
|
3171
|
+
// If the fallback has been reached do not continue running samples
|
|
3172
|
+
if (this.fallback) return;
|
|
3173
|
+
const { frames, averages } = this;
|
|
3174
|
+
if (averages.length < iterations) {
|
|
3175
|
+
frames.push(performance.now());
|
|
3176
|
+
const msPassed = frames[frames.length - 1] - frames[0];
|
|
3177
|
+
if (msPassed >= ms) {
|
|
3178
|
+
this.fps = Math.round(frames.length / msPassed * 1000 * decimalPlacesRatio) / decimalPlacesRatio;
|
|
3179
|
+
this.refreshrate = Math.max(this.refreshrate, this.fps);
|
|
3180
|
+
averages[this.index++ % iterations] = this.fps;
|
|
3181
|
+
if (averages.length === iterations) {
|
|
3182
|
+
const [lower, upper] = bounds(this.refreshrate);
|
|
3183
|
+
const upperBounds = averages.filter((value)=>value >= upper);
|
|
3184
|
+
const lowerBounds = averages.filter((value)=>value < lower);
|
|
3185
|
+
// Trigger incline when more than -threshold- avgs exceed the upper bound
|
|
3186
|
+
if (upperBounds.length > iterations * threshold) {
|
|
3187
|
+
this.factor = Math.min(1, this.factor + step);
|
|
3188
|
+
this.flipped++;
|
|
3189
|
+
if (onIncline) onIncline(this);
|
|
3190
|
+
this.subscriptions.forEach((value)=>value.onIncline && value.onIncline(this));
|
|
3191
|
+
}
|
|
3192
|
+
// Trigger decline when more than -threshold- avgs are below the lower bound
|
|
3193
|
+
if (lowerBounds.length > iterations * threshold) {
|
|
3194
|
+
this.factor = Math.max(0, this.factor - step);
|
|
3195
|
+
this.flipped++;
|
|
3196
|
+
if (onDecline) onDecline(this);
|
|
3197
|
+
this.subscriptions.forEach((value)=>value.onDecline && value.onDecline(this));
|
|
3198
|
+
}
|
|
3199
|
+
if (lastFactor !== this.factor) {
|
|
3200
|
+
lastFactor = this.factor;
|
|
3201
|
+
if (onChange) onChange(this);
|
|
3202
|
+
this.subscriptions.forEach((value)=>value.onChange && value.onChange(this));
|
|
3203
|
+
}
|
|
3204
|
+
if (this.flipped > flipflops && !this.fallback) {
|
|
3205
|
+
this.fallback = true;
|
|
3206
|
+
if (onFallback) onFallback(this);
|
|
3207
|
+
this.subscriptions.forEach((value)=>value.onFallback && value.onFallback(this));
|
|
3208
|
+
}
|
|
3209
|
+
this.averages = [];
|
|
3210
|
+
// Resetting the refreshrate creates more problems than it solves atm
|
|
3211
|
+
// this.refreshrate = 0
|
|
3212
|
+
}
|
|
3213
|
+
this.frames = [];
|
|
3214
|
+
}
|
|
3215
|
+
}
|
|
3216
|
+
};
|
|
3217
|
+
}
|
|
3218
|
+
}
|
|
3219
|
+
|
|
3147
3220
|
const vert_fullscreen = /*glsl*/ `
|
|
3148
3221
|
varying vec2 vUv;
|
|
3149
3222
|
void main() {
|
|
@@ -4836,7 +4909,7 @@ class Viewer extends EventEmitter {
|
|
|
4836
4909
|
node.visible = active;
|
|
4837
4910
|
return node;
|
|
4838
4911
|
}
|
|
4839
|
-
createRenderTarget(width, height, nearest = false, floatType = false, msaa = 0, mipmap = false) {
|
|
4912
|
+
createRenderTarget(width, height, nearest = false, floatType = false, msaa = 0, mipmap = false, depth = false) {
|
|
4840
4913
|
return new WebGLRenderTarget(width, height, {
|
|
4841
4914
|
wrapS: ClampToEdgeWrapping,
|
|
4842
4915
|
wrapT: ClampToEdgeWrapping,
|
|
@@ -4845,13 +4918,13 @@ class Viewer extends EventEmitter {
|
|
|
4845
4918
|
type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : UnsignedByteType : floatType,
|
|
4846
4919
|
anisotropy: 0,
|
|
4847
4920
|
colorSpace: LinearSRGBColorSpace,
|
|
4848
|
-
depthBuffer:
|
|
4921
|
+
depthBuffer: depth,
|
|
4849
4922
|
stencilBuffer: false,
|
|
4850
4923
|
samples: SystemInfo.isSupportMSAA ? msaa : 0,
|
|
4851
4924
|
generateMipmaps: mipmap
|
|
4852
4925
|
});
|
|
4853
4926
|
}
|
|
4854
|
-
createCubeRenderTarget(size, nearest = false, floatType = false, msaa = 0, mipmap = false) {
|
|
4927
|
+
createCubeRenderTarget(size, nearest = false, floatType = false, msaa = 0, mipmap = false, depth = false) {
|
|
4855
4928
|
return new WebGLCubeRenderTarget(size, {
|
|
4856
4929
|
wrapS: ClampToEdgeWrapping,
|
|
4857
4930
|
wrapT: ClampToEdgeWrapping,
|
|
@@ -4860,7 +4933,7 @@ class Viewer extends EventEmitter {
|
|
|
4860
4933
|
type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : UnsignedByteType : floatType,
|
|
4861
4934
|
anisotropy: 0,
|
|
4862
4935
|
colorSpace: LinearSRGBColorSpace,
|
|
4863
|
-
depthBuffer:
|
|
4936
|
+
depthBuffer: depth,
|
|
4864
4937
|
stencilBuffer: false,
|
|
4865
4938
|
samples: SystemInfo.isSupportMSAA ? msaa : 0,
|
|
4866
4939
|
generateMipmaps: mipmap
|
|
@@ -5243,7 +5316,14 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5243
5316
|
}
|
|
5244
5317
|
}
|
|
5245
5318
|
}
|
|
5246
|
-
onRender() {
|
|
5319
|
+
onRender(dt) {
|
|
5320
|
+
if (this._elapsed >= this.interval || this._elapsed === 0) {
|
|
5321
|
+
this._elapsed = 0;
|
|
5322
|
+
this._renderFrame();
|
|
5323
|
+
}
|
|
5324
|
+
this._elapsed += dt;
|
|
5325
|
+
}
|
|
5326
|
+
_renderFrame() {
|
|
5247
5327
|
const { renderer } = this.viewer;
|
|
5248
5328
|
const autoClear = renderer.autoClear;
|
|
5249
5329
|
const oldTarget = renderer.getRenderTarget();
|
|
@@ -5280,14 +5360,16 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5280
5360
|
};
|
|
5281
5361
|
this._debug = false;
|
|
5282
5362
|
this._debugNode = null;
|
|
5363
|
+
this._elapsed = 0;
|
|
5283
5364
|
this.performance = _Performance.HIGH;
|
|
5284
5365
|
this.envMapIntensity = 1;
|
|
5285
5366
|
this.reflectExposure = 1;
|
|
5286
5367
|
this.reflectBlurIntensity = 5;
|
|
5368
|
+
this.interval = 0;
|
|
5287
5369
|
this.install = ()=>{
|
|
5288
5370
|
const viewer = this.viewer;
|
|
5289
5371
|
this._scene = scene || viewer.scene;
|
|
5290
|
-
const cubeRenderTarget = viewer.createCubeRenderTarget(resolution, false, floatType, 0, true);
|
|
5372
|
+
const cubeRenderTarget = viewer.createCubeRenderTarget(resolution, false, floatType, 0, true, true);
|
|
5291
5373
|
this._cubeCamera = new CubeCamera(near || viewer.camera.near, far || viewer.camera.far, cubeRenderTarget);
|
|
5292
5374
|
this._cubeCamera.position.copy(position);
|
|
5293
5375
|
this._cubeCamera.layers.mask = layer;
|
|
@@ -5336,6 +5418,9 @@ __decorate([
|
|
|
5336
5418
|
step: 0.1
|
|
5337
5419
|
})
|
|
5338
5420
|
], EnvironmentPlugin.prototype, "reflectBlurIntensity", void 0);
|
|
5421
|
+
__decorate([
|
|
5422
|
+
property
|
|
5423
|
+
], EnvironmentPlugin.prototype, "interval", void 0);
|
|
5339
5424
|
|
|
5340
5425
|
class BoxProjectionPlugin extends Plugin {
|
|
5341
5426
|
get debug() {
|
|
@@ -5464,5 +5549,5 @@ __decorate([
|
|
|
5464
5549
|
property
|
|
5465
5550
|
], BoxProjectionPlugin.prototype, "boxMax", null);
|
|
5466
5551
|
|
|
5467
|
-
export { AnimationCurve, Box, BoxProjectionPlugin, CinestationBlendDefinition, CinestationBrain, Component, DebugPlugin, DeviceInput, Easing, EnvironmentPlugin, EventEmitter, FInterpConstantTo, FInterpTo, FreelookVirtualCamera, Logger, ObjectInstance, Orientation, Perlin, Plane, Plugin, PropertyManager, QInterpConstantTo, QInterpTo, Quat_AngularDistance, Quat_Equals, Quat_exponentialDamp, Quat_quarticDamp, Quat_smoothDamp, Reflector, ReflectorMaterial, Sphere, SystemInfo, Tween, TweenChain, TweenManager, VInterpConstantTo, VInterpTo, Vec3_smoothDamp, Vector3_NEG_ONE, Vector3_ONE, Vector3_RIGHT, Vector3_UNIT_X, Vector3_UNIT_Y, Vector3_UNIT_Z, Vector3_UP, Vector3_ZERO, Viewer, VirtualCamera, aEXRLoader, aFBXLoader, aGLTFLoader, aHDRLoader, aJSONLoader, aLoader, aTextureLoader, exponentialDamp, frag_BoxfilterBlur, frag_cubeMapToPanorama, frag_panoramaToCubeMap, getClassInstance, getShaderMaterial, mixin, property, quarticDamp, smoothDamp, vert_fullscreen };
|
|
5552
|
+
export { AnimationCurve, Box, BoxProjectionPlugin, CinestationBlendDefinition, CinestationBrain, Component, DebugPlugin, DeviceInput, Easing, EnvironmentPlugin, EventEmitter, FInterpConstantTo, FInterpTo, FreelookVirtualCamera, Logger, ObjectInstance, Orientation, PerformanceMonitor, Perlin, Plane, Plugin, PropertyManager, QInterpConstantTo, QInterpTo, Quat_AngularDistance, Quat_Equals, Quat_exponentialDamp, Quat_quarticDamp, Quat_smoothDamp, Reflector, ReflectorMaterial, Sphere, SystemInfo, Tween, TweenChain, TweenManager, VInterpConstantTo, VInterpTo, Vec3_smoothDamp, Vector3_NEG_ONE, Vector3_ONE, Vector3_RIGHT, Vector3_UNIT_X, Vector3_UNIT_Y, Vector3_UNIT_Z, Vector3_UP, Vector3_ZERO, Viewer, VirtualCamera, aEXRLoader, aFBXLoader, aGLTFLoader, aHDRLoader, aJSONLoader, aLoader, aTextureLoader, exponentialDamp, frag_BoxfilterBlur, frag_cubeMapToPanorama, frag_panoramaToCubeMap, getClassInstance, getShaderMaterial, mixin, property, quarticDamp, smoothDamp, vert_fullscreen };
|
|
5468
5553
|
//# sourceMappingURL=module.js.map
|