@xviewer.js/core 1.0.0-alpha.44 → 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 +126 -28
- package/dist/main.js.map +1 -1
- package/dist/module.js +126 -29
- package/dist/module.js.map +1 -1
- package/package.json +1 -1
- package/types/Viewer.d.ts +13 -4
- package/types/asset/aLoader.d.ts +1 -1
- package/types/cinestation/FreelookVirtualCamera.d.ts +1 -1
- 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
|
@@ -1050,7 +1050,7 @@ class TweenManager {
|
|
|
1050
1050
|
}
|
|
1051
1051
|
|
|
1052
1052
|
class aLoader {
|
|
1053
|
-
static
|
|
1053
|
+
static _setUserData(node) {
|
|
1054
1054
|
const keys = aLoader._texKeys;
|
|
1055
1055
|
const meshes = [];
|
|
1056
1056
|
const textures = {};
|
|
@@ -1121,7 +1121,7 @@ class aEXRLoader extends aLoader {
|
|
|
1121
1121
|
class aFBXLoader extends aLoader {
|
|
1122
1122
|
load({ url, onLoad, onProgress, onError }) {
|
|
1123
1123
|
const loadCallback = (node)=>{
|
|
1124
|
-
onLoad(aLoader.
|
|
1124
|
+
onLoad(aLoader._setUserData(node));
|
|
1125
1125
|
};
|
|
1126
1126
|
const loader = new FBXLoader(this.manager.loadingManager);
|
|
1127
1127
|
loader.setPath(this.manager.path);
|
|
@@ -1141,7 +1141,7 @@ class aGLTFLoader extends aLoader {
|
|
|
1141
1141
|
const loadCallback = (gltf)=>{
|
|
1142
1142
|
const node = gltf.scene;
|
|
1143
1143
|
if (gltf.animations) node.animations = gltf.animations;
|
|
1144
|
-
onLoad(aLoader.
|
|
1144
|
+
onLoad(aLoader._setUserData(node));
|
|
1145
1145
|
};
|
|
1146
1146
|
let gltfLoader = new GLTFLoader(this.manager.loadingManager);
|
|
1147
1147
|
gltfLoader.setPath(this.manager.path);
|
|
@@ -2690,7 +2690,7 @@ class FreelookVirtualCamera extends VirtualCamera {
|
|
|
2690
2690
|
this._button = e.button;
|
|
2691
2691
|
this._preLoc0.set(e.pageX, e.pageY);
|
|
2692
2692
|
}
|
|
2693
|
-
_onPointerUp(
|
|
2693
|
+
_onPointerUp(_) {
|
|
2694
2694
|
if (SystemInfo.isMobile) return;
|
|
2695
2695
|
this._button = -1;
|
|
2696
2696
|
}
|
|
@@ -2810,7 +2810,7 @@ class FreelookVirtualCamera extends VirtualCamera {
|
|
|
2810
2810
|
this._targetPhi = clamp(this._targetPhi, this.phiMin, this.phiMax);
|
|
2811
2811
|
this._targetSpringLength = clamp(this._targetSpringLength, this.distanceMin, this.distanceMax);
|
|
2812
2812
|
}
|
|
2813
|
-
gotoPOI({ duration = -1, easing = Easing.Cubic.InOut, springLength = this._targetSpringLength, theta = this._targetTheta, phi = this._targetPhi, lookAt = this._lookAt, fov = this.lens.fov, smoothing = this.smoothing, rotateSmoothing =
|
|
2813
|
+
gotoPOI({ duration = -1, easing = Easing.Cubic.InOut, springLength = this._targetSpringLength, theta = this._targetTheta, phi = this._targetPhi, lookAt = this._lookAt, fov = this.lens.fov, smoothing = this.smoothing, rotateSmoothing = smoothing }) {
|
|
2814
2814
|
this._targetFov = fov;
|
|
2815
2815
|
this._tempSmoothing = smoothing;
|
|
2816
2816
|
this._tempRotateSmoothing = rotateSmoothing;
|
|
@@ -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() {
|
|
@@ -4518,33 +4591,44 @@ class Viewer extends EventEmitter {
|
|
|
4518
4591
|
static getChildByName(node, name) {
|
|
4519
4592
|
return Viewer.getObject(node, (v)=>v.name === name && v);
|
|
4520
4593
|
}
|
|
4521
|
-
static getObject(node, filter) {
|
|
4594
|
+
static getObject(node, filter, group = false) {
|
|
4522
4595
|
const queue = [
|
|
4523
4596
|
node
|
|
4524
4597
|
];
|
|
4598
|
+
const objects = [];
|
|
4525
4599
|
while(queue.length !== 0){
|
|
4526
4600
|
let object = queue.shift();
|
|
4527
4601
|
let target = filter(object);
|
|
4528
4602
|
if (target) {
|
|
4529
|
-
|
|
4603
|
+
objects.push(object);
|
|
4604
|
+
if (!group) {
|
|
4605
|
+
break;
|
|
4606
|
+
}
|
|
4530
4607
|
}
|
|
4531
4608
|
object.children.forEach((v)=>queue.push(v));
|
|
4532
4609
|
}
|
|
4610
|
+
if (group) {
|
|
4611
|
+
return objects;
|
|
4612
|
+
}
|
|
4613
|
+
return objects[0];
|
|
4533
4614
|
}
|
|
4534
|
-
static
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
const objects = [];
|
|
4539
|
-
while(queue.length !== 0){
|
|
4540
|
-
let object = queue.shift();
|
|
4541
|
-
let target = filter(object);
|
|
4542
|
-
if (target) {
|
|
4543
|
-
objects.push(object);
|
|
4615
|
+
static _getObjectValue(object, name, group = false) {
|
|
4616
|
+
if (name) {
|
|
4617
|
+
if (group) {
|
|
4618
|
+
return Object.values(object || Viewer.__emtpyObject).filter((v)=>v.name === name);
|
|
4544
4619
|
}
|
|
4545
|
-
object.
|
|
4620
|
+
return Object.values(object || Viewer.__emtpyObject).find((v)=>v.name === name);
|
|
4546
4621
|
}
|
|
4547
|
-
return
|
|
4622
|
+
return Object.values(object);
|
|
4623
|
+
}
|
|
4624
|
+
static getMaterial(node, name, group = false) {
|
|
4625
|
+
return Viewer._getObjectValue(node.userData.materials, name, group);
|
|
4626
|
+
}
|
|
4627
|
+
static getTexture(node, name, group = false) {
|
|
4628
|
+
return Viewer._getObjectValue(node.userData.textures, name, group);
|
|
4629
|
+
}
|
|
4630
|
+
static getMesh(node, name, group = false) {
|
|
4631
|
+
return Viewer._getObjectValue(node.userData.meshes, name, group);
|
|
4548
4632
|
}
|
|
4549
4633
|
get root() {
|
|
4550
4634
|
return this._root;
|
|
@@ -4740,12 +4824,12 @@ class Viewer extends EventEmitter {
|
|
|
4740
4824
|
this._tweenManager.killTweensOf(target);
|
|
4741
4825
|
}
|
|
4742
4826
|
traverseMaterials(callback) {
|
|
4743
|
-
Viewer.
|
|
4744
|
-
if (item.
|
|
4827
|
+
Viewer.getObject(this._scene, (item)=>{
|
|
4828
|
+
if (item.material) {
|
|
4745
4829
|
if (Array.isArray(item.material)) item.material.forEach(callback);
|
|
4746
4830
|
else callback(item.material);
|
|
4747
4831
|
}
|
|
4748
|
-
});
|
|
4832
|
+
}, true);
|
|
4749
4833
|
}
|
|
4750
4834
|
traversePlugins(callback) {
|
|
4751
4835
|
return this._pluginManager.traversePlugins(callback);
|
|
@@ -4825,7 +4909,7 @@ class Viewer extends EventEmitter {
|
|
|
4825
4909
|
node.visible = active;
|
|
4826
4910
|
return node;
|
|
4827
4911
|
}
|
|
4828
|
-
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) {
|
|
4829
4913
|
return new WebGLRenderTarget(width, height, {
|
|
4830
4914
|
wrapS: ClampToEdgeWrapping,
|
|
4831
4915
|
wrapT: ClampToEdgeWrapping,
|
|
@@ -4834,13 +4918,13 @@ class Viewer extends EventEmitter {
|
|
|
4834
4918
|
type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : UnsignedByteType : floatType,
|
|
4835
4919
|
anisotropy: 0,
|
|
4836
4920
|
colorSpace: LinearSRGBColorSpace,
|
|
4837
|
-
depthBuffer:
|
|
4921
|
+
depthBuffer: depth,
|
|
4838
4922
|
stencilBuffer: false,
|
|
4839
4923
|
samples: SystemInfo.isSupportMSAA ? msaa : 0,
|
|
4840
4924
|
generateMipmaps: mipmap
|
|
4841
4925
|
});
|
|
4842
4926
|
}
|
|
4843
|
-
createCubeRenderTarget(size, nearest = false, floatType = false, msaa = 0, mipmap = false) {
|
|
4927
|
+
createCubeRenderTarget(size, nearest = false, floatType = false, msaa = 0, mipmap = false, depth = false) {
|
|
4844
4928
|
return new WebGLCubeRenderTarget(size, {
|
|
4845
4929
|
wrapS: ClampToEdgeWrapping,
|
|
4846
4930
|
wrapT: ClampToEdgeWrapping,
|
|
@@ -4849,7 +4933,7 @@ class Viewer extends EventEmitter {
|
|
|
4849
4933
|
type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : UnsignedByteType : floatType,
|
|
4850
4934
|
anisotropy: 0,
|
|
4851
4935
|
colorSpace: LinearSRGBColorSpace,
|
|
4852
|
-
depthBuffer:
|
|
4936
|
+
depthBuffer: depth,
|
|
4853
4937
|
stencilBuffer: false,
|
|
4854
4938
|
samples: SystemInfo.isSupportMSAA ? msaa : 0,
|
|
4855
4939
|
generateMipmaps: mipmap
|
|
@@ -4977,6 +5061,7 @@ Viewer._shadowCameraKeys = [
|
|
|
4977
5061
|
"near",
|
|
4978
5062
|
"far"
|
|
4979
5063
|
];
|
|
5064
|
+
Viewer.__emtpyObject = {};
|
|
4980
5065
|
Viewer.fullscreenMesh = new Mesh(Viewer.createFullscreenTriangle());
|
|
4981
5066
|
Viewer.fullscreenCamera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
|
4982
5067
|
|
|
@@ -5231,7 +5316,14 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5231
5316
|
}
|
|
5232
5317
|
}
|
|
5233
5318
|
}
|
|
5234
|
-
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() {
|
|
5235
5327
|
const { renderer } = this.viewer;
|
|
5236
5328
|
const autoClear = renderer.autoClear;
|
|
5237
5329
|
const oldTarget = renderer.getRenderTarget();
|
|
@@ -5268,14 +5360,16 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5268
5360
|
};
|
|
5269
5361
|
this._debug = false;
|
|
5270
5362
|
this._debugNode = null;
|
|
5363
|
+
this._elapsed = 0;
|
|
5271
5364
|
this.performance = _Performance.HIGH;
|
|
5272
5365
|
this.envMapIntensity = 1;
|
|
5273
5366
|
this.reflectExposure = 1;
|
|
5274
5367
|
this.reflectBlurIntensity = 5;
|
|
5368
|
+
this.interval = 0;
|
|
5275
5369
|
this.install = ()=>{
|
|
5276
5370
|
const viewer = this.viewer;
|
|
5277
5371
|
this._scene = scene || viewer.scene;
|
|
5278
|
-
const cubeRenderTarget = viewer.createCubeRenderTarget(resolution, false, floatType, 0, true);
|
|
5372
|
+
const cubeRenderTarget = viewer.createCubeRenderTarget(resolution, false, floatType, 0, true, true);
|
|
5279
5373
|
this._cubeCamera = new CubeCamera(near || viewer.camera.near, far || viewer.camera.far, cubeRenderTarget);
|
|
5280
5374
|
this._cubeCamera.position.copy(position);
|
|
5281
5375
|
this._cubeCamera.layers.mask = layer;
|
|
@@ -5324,6 +5418,9 @@ __decorate([
|
|
|
5324
5418
|
step: 0.1
|
|
5325
5419
|
})
|
|
5326
5420
|
], EnvironmentPlugin.prototype, "reflectBlurIntensity", void 0);
|
|
5421
|
+
__decorate([
|
|
5422
|
+
property
|
|
5423
|
+
], EnvironmentPlugin.prototype, "interval", void 0);
|
|
5327
5424
|
|
|
5328
5425
|
class BoxProjectionPlugin extends Plugin {
|
|
5329
5426
|
get debug() {
|
|
@@ -5452,5 +5549,5 @@ __decorate([
|
|
|
5452
5549
|
property
|
|
5453
5550
|
], BoxProjectionPlugin.prototype, "boxMax", null);
|
|
5454
5551
|
|
|
5455
|
-
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 };
|
|
5456
5553
|
//# sourceMappingURL=module.js.map
|