@xviewer.js/core 1.0.4 → 1.0.5-alhpa.1
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.cjs +41 -24
- package/dist/main.cjs.map +1 -1
- package/dist/module.js +41 -24
- package/dist/module.js.map +1 -1
- package/package.json +1 -1
- package/types/TaskManager.d.ts +1 -0
- package/types/Viewer.d.ts +5 -2
- package/types/asset/ResourceManager.d.ts +8 -3
package/dist/main.cjs
CHANGED
|
@@ -4368,16 +4368,15 @@ function _getMipBlurMaterial(lodMax, width, height) {
|
|
|
4368
4368
|
}
|
|
4369
4369
|
|
|
4370
4370
|
class TaskManager {
|
|
4371
|
+
get isComplete() {
|
|
4372
|
+
return this._taskIndex >= this._tasks.length;
|
|
4373
|
+
}
|
|
4371
4374
|
destroy() {
|
|
4372
4375
|
this._tasks = [];
|
|
4373
4376
|
this._taskIndex = 0;
|
|
4374
4377
|
}
|
|
4375
4378
|
add(task) {
|
|
4376
4379
|
this._tasks.push(task);
|
|
4377
|
-
if (this._onStartCalled === false) {
|
|
4378
|
-
this._onStartCalled = true;
|
|
4379
|
-
this.onStart && this.onStart();
|
|
4380
|
-
}
|
|
4381
4380
|
}
|
|
4382
4381
|
update() {
|
|
4383
4382
|
let task = this._tasks[this._taskIndex];
|
|
@@ -4388,6 +4387,10 @@ class TaskManager {
|
|
|
4388
4387
|
console.error(e);
|
|
4389
4388
|
this.onError && this.onError(task);
|
|
4390
4389
|
}
|
|
4390
|
+
if (this._onStartCalled === false) {
|
|
4391
|
+
this._onStartCalled = true;
|
|
4392
|
+
this.onStart && this.onStart();
|
|
4393
|
+
}
|
|
4391
4394
|
++this._taskIndex;
|
|
4392
4395
|
this.onProgress && this.onProgress(task, this._taskIndex, this._tasks.length);
|
|
4393
4396
|
if (this._taskIndex === this._tasks.length) {
|
|
@@ -4500,6 +4503,9 @@ class ResourceManager {
|
|
|
4500
4503
|
}
|
|
4501
4504
|
return settings;
|
|
4502
4505
|
}
|
|
4506
|
+
get isComplete() {
|
|
4507
|
+
return this._loaded >= this._totalCount;
|
|
4508
|
+
}
|
|
4503
4509
|
destroy() {
|
|
4504
4510
|
this._loaders.clear();
|
|
4505
4511
|
}
|
|
@@ -4523,19 +4529,30 @@ class ResourceManager {
|
|
|
4523
4529
|
texSettings,
|
|
4524
4530
|
...props,
|
|
4525
4531
|
onProgress,
|
|
4526
|
-
onLoad:
|
|
4532
|
+
onLoad: (asset)=>{
|
|
4533
|
+
this._loaded++;
|
|
4534
|
+
this._resources.set(url, asset);
|
|
4535
|
+
resolve(asset);
|
|
4536
|
+
},
|
|
4527
4537
|
onError: (err)=>{
|
|
4528
4538
|
console.error(`${url} not exist`, err);
|
|
4529
4539
|
reject(err);
|
|
4530
4540
|
}
|
|
4531
4541
|
});
|
|
4542
|
+
this._totalCount++;
|
|
4532
4543
|
} else {
|
|
4533
4544
|
reject("ResourceManager.loadAsset: missing loader for " + sel);
|
|
4534
4545
|
}
|
|
4535
4546
|
});
|
|
4536
4547
|
}
|
|
4548
|
+
getAsset(url) {
|
|
4549
|
+
return this._resources.get(url);
|
|
4550
|
+
}
|
|
4537
4551
|
constructor(viewer){
|
|
4538
4552
|
this._loaders = new Map();
|
|
4553
|
+
this._resources = new Map();
|
|
4554
|
+
this._loaded = 0;
|
|
4555
|
+
this._totalCount = 0;
|
|
4539
4556
|
this._viewer = viewer;
|
|
4540
4557
|
}
|
|
4541
4558
|
}
|
|
@@ -4750,11 +4767,13 @@ class Viewer extends EventEmitter {
|
|
|
4750
4767
|
}
|
|
4751
4768
|
}
|
|
4752
4769
|
loop(dt) {
|
|
4753
|
-
this.
|
|
4754
|
-
|
|
4755
|
-
this.
|
|
4770
|
+
if (this._resourceManager.isComplete) {
|
|
4771
|
+
this._taskManager.update();
|
|
4772
|
+
if (this._taskManager.isComplete) {
|
|
4773
|
+
this._running = true;
|
|
4774
|
+
}
|
|
4756
4775
|
}
|
|
4757
|
-
if (this._running
|
|
4776
|
+
if (this._running) {
|
|
4758
4777
|
dt = Math.min(dt, 0.067);
|
|
4759
4778
|
this._renderer.info.reset();
|
|
4760
4779
|
this._componentManager.update(dt);
|
|
@@ -4774,8 +4793,7 @@ class Viewer extends EventEmitter {
|
|
|
4774
4793
|
return this;
|
|
4775
4794
|
}
|
|
4776
4795
|
stop() {
|
|
4777
|
-
this._active = false;
|
|
4778
|
-
this._running = 4;
|
|
4796
|
+
this._active = this._running = false;
|
|
4779
4797
|
this._time = this._lastTime = 0;
|
|
4780
4798
|
return this;
|
|
4781
4799
|
}
|
|
@@ -4857,8 +4875,13 @@ class Viewer extends EventEmitter {
|
|
|
4857
4875
|
setURLModifier(callback) {
|
|
4858
4876
|
return this._loadingManager.setURLModifier(callback);
|
|
4859
4877
|
}
|
|
4860
|
-
loadAsset(props) {
|
|
4861
|
-
return this._resourceManager.loadAsset(Object.assign({
|
|
4878
|
+
loadAsset({ url, ...props }) {
|
|
4879
|
+
return this._resourceManager.loadAsset(Object.assign({
|
|
4880
|
+
url: this._decodeURL(url)
|
|
4881
|
+
}, this._resourceOptions, props));
|
|
4882
|
+
}
|
|
4883
|
+
getAsset(url) {
|
|
4884
|
+
return this._resourceManager.getAsset(this._decodeURL(url));
|
|
4862
4885
|
}
|
|
4863
4886
|
getLoader(ext) {
|
|
4864
4887
|
return this._resourceManager.getLoader(ext);
|
|
@@ -5120,13 +5143,12 @@ class Viewer extends EventEmitter {
|
|
|
5120
5143
|
near: 0.1,
|
|
5121
5144
|
far: 1000,
|
|
5122
5145
|
position: new THREE.Vector3(0, 0, 4)
|
|
5123
|
-
}, targetFrameRate = -1, fixedFrameTime = false, colorSpace = THREE.SRGBColorSpace, toneMapping = THREE.LinearToneMapping, toneMappingExposure = 1, maxDPR = 1.5, path = "", resourcePath = "", dracoPath = "https://www.gstatic.com/draco/v1/decoders/", transcoderPath = "three/examples/js/libs/basis/", orientation = Orientation.AUTO, loader = {}, tasker = {}, ...webglOpts } = {}){
|
|
5146
|
+
}, targetFrameRate = -1, fixedFrameTime = false, colorSpace = THREE.SRGBColorSpace, toneMapping = THREE.LinearToneMapping, toneMappingExposure = 1, maxDPR = 1.5, path = "", resourcePath = "", dracoPath = "https://www.gstatic.com/draco/v1/decoders/", transcoderPath = "three/examples/js/libs/basis/", orientation = Orientation.AUTO, decodeURL = (url)=>url, loader = {}, tasker = {}, ...webglOpts } = {}){
|
|
5124
5147
|
super(), this._instanceId = Viewer.instanceCount++, this._dpr = 1, this._width = 1, this._height = 1, this._viewport = {
|
|
5125
5148
|
width: 1,
|
|
5126
5149
|
height: 1,
|
|
5127
5150
|
factor: 1
|
|
5128
|
-
}, this._active = false, this._loading = false, this._tasking = false, this._running =
|
|
5129
|
-
, this._rootRotated = false, this._time = 0, this._lastTime = 0, this._lastFrameTime = 0, this._targetFrameRate = -1, this._fixedFrameTime = false, this._windowSize = ()=>[
|
|
5151
|
+
}, this._active = false, this._loading = false, this._tasking = false, this._running = false, this._rootRotated = false, this._time = 0, this._lastTime = 0, this._lastFrameTime = 0, this._targetFrameRate = -1, this._fixedFrameTime = false, this._windowSize = ()=>[
|
|
5130
5152
|
window.innerWidth,
|
|
5131
5153
|
window.innerHeight
|
|
5132
5154
|
], this._orientation = Orientation.AUTO;
|
|
@@ -5158,14 +5180,8 @@ class Viewer extends EventEmitter {
|
|
|
5158
5180
|
this._renderer.sortObjects = sortObjects;
|
|
5159
5181
|
this._targetFrameRate = targetFrameRate;
|
|
5160
5182
|
this._windowSize = typeof resize === "function" ? resize : resize === ResizeMode.AUTO ? this._windowSize : null;
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
cb && cb();
|
|
5164
|
-
};
|
|
5165
|
-
this._taskManager = new TaskManager(()=>complete(()=>this._tasking = false, tasker.onComplete), tasker.onProgress, tasker.onError);
|
|
5166
|
-
this._taskManager.onStart = ()=>this._tasking = true;
|
|
5167
|
-
this._loadingManager = new THREE.LoadingManager(()=>complete(()=>this._loading = false, loader.onComplete), loader.onProgress, loader.onError);
|
|
5168
|
-
this._loadingManager.onStart = ()=>this._loading = true;
|
|
5183
|
+
this._taskManager = new TaskManager(tasker.onComplete, tasker.onProgress, tasker.onError);
|
|
5184
|
+
this._loadingManager = new THREE.LoadingManager(loader.onComplete, loader.onProgress, loader.onError);
|
|
5169
5185
|
this._resourceManager = new ResourceManager(this);
|
|
5170
5186
|
this._componentManager = new ComponentManager(this);
|
|
5171
5187
|
this._resourceOptions = {
|
|
@@ -5181,6 +5197,7 @@ class Viewer extends EventEmitter {
|
|
|
5181
5197
|
this._input = this.add(new DeviceInput(input || {
|
|
5182
5198
|
source: this._canvas
|
|
5183
5199
|
}));
|
|
5200
|
+
this._decodeURL = decodeURL;
|
|
5184
5201
|
this.add(Renderer);
|
|
5185
5202
|
this.addLoader(GLTFLoader);
|
|
5186
5203
|
this.addLoader(HDRLoader);
|