@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/module.js CHANGED
@@ -4348,16 +4348,15 @@ function _getMipBlurMaterial(lodMax, width, height) {
4348
4348
  }
4349
4349
 
4350
4350
  class TaskManager {
4351
+ get isComplete() {
4352
+ return this._taskIndex >= this._tasks.length;
4353
+ }
4351
4354
  destroy() {
4352
4355
  this._tasks = [];
4353
4356
  this._taskIndex = 0;
4354
4357
  }
4355
4358
  add(task) {
4356
4359
  this._tasks.push(task);
4357
- if (this._onStartCalled === false) {
4358
- this._onStartCalled = true;
4359
- this.onStart && this.onStart();
4360
- }
4361
4360
  }
4362
4361
  update() {
4363
4362
  let task = this._tasks[this._taskIndex];
@@ -4368,6 +4367,10 @@ class TaskManager {
4368
4367
  console.error(e);
4369
4368
  this.onError && this.onError(task);
4370
4369
  }
4370
+ if (this._onStartCalled === false) {
4371
+ this._onStartCalled = true;
4372
+ this.onStart && this.onStart();
4373
+ }
4371
4374
  ++this._taskIndex;
4372
4375
  this.onProgress && this.onProgress(task, this._taskIndex, this._tasks.length);
4373
4376
  if (this._taskIndex === this._tasks.length) {
@@ -4480,6 +4483,9 @@ class ResourceManager {
4480
4483
  }
4481
4484
  return settings;
4482
4485
  }
4486
+ get isComplete() {
4487
+ return this._loaded >= this._totalCount;
4488
+ }
4483
4489
  destroy() {
4484
4490
  this._loaders.clear();
4485
4491
  }
@@ -4503,19 +4509,30 @@ class ResourceManager {
4503
4509
  texSettings,
4504
4510
  ...props,
4505
4511
  onProgress,
4506
- onLoad: resolve,
4512
+ onLoad: (asset)=>{
4513
+ this._loaded++;
4514
+ this._resources.set(url, asset);
4515
+ resolve(asset);
4516
+ },
4507
4517
  onError: (err)=>{
4508
4518
  console.error(`${url} not exist`, err);
4509
4519
  reject(err);
4510
4520
  }
4511
4521
  });
4522
+ this._totalCount++;
4512
4523
  } else {
4513
4524
  reject("ResourceManager.loadAsset: missing loader for " + sel);
4514
4525
  }
4515
4526
  });
4516
4527
  }
4528
+ getAsset(url) {
4529
+ return this._resources.get(url);
4530
+ }
4517
4531
  constructor(viewer){
4518
4532
  this._loaders = new Map();
4533
+ this._resources = new Map();
4534
+ this._loaded = 0;
4535
+ this._totalCount = 0;
4519
4536
  this._viewer = viewer;
4520
4537
  }
4521
4538
  }
@@ -4730,11 +4747,13 @@ class Viewer extends EventEmitter {
4730
4747
  }
4731
4748
  }
4732
4749
  loop(dt) {
4733
- this._taskManager.update();
4734
- if (!this._loading && !this._tasking && this._running > 0) {
4735
- this._running--;
4750
+ if (this._resourceManager.isComplete) {
4751
+ this._taskManager.update();
4752
+ if (this._taskManager.isComplete) {
4753
+ this._running = true;
4754
+ }
4736
4755
  }
4737
- if (this._running <= 0) {
4756
+ if (this._running) {
4738
4757
  dt = Math.min(dt, 0.067);
4739
4758
  this._renderer.info.reset();
4740
4759
  this._componentManager.update(dt);
@@ -4754,8 +4773,7 @@ class Viewer extends EventEmitter {
4754
4773
  return this;
4755
4774
  }
4756
4775
  stop() {
4757
- this._active = false;
4758
- this._running = 4;
4776
+ this._active = this._running = false;
4759
4777
  this._time = this._lastTime = 0;
4760
4778
  return this;
4761
4779
  }
@@ -4837,8 +4855,13 @@ class Viewer extends EventEmitter {
4837
4855
  setURLModifier(callback) {
4838
4856
  return this._loadingManager.setURLModifier(callback);
4839
4857
  }
4840
- loadAsset(props) {
4841
- return this._resourceManager.loadAsset(Object.assign({}, this._resourceOptions, props));
4858
+ loadAsset({ url, ...props }) {
4859
+ return this._resourceManager.loadAsset(Object.assign({
4860
+ url: this._decodeURL(url)
4861
+ }, this._resourceOptions, props));
4862
+ }
4863
+ getAsset(url) {
4864
+ return this._resourceManager.getAsset(this._decodeURL(url));
4842
4865
  }
4843
4866
  getLoader(ext) {
4844
4867
  return this._resourceManager.getLoader(ext);
@@ -5100,13 +5123,12 @@ class Viewer extends EventEmitter {
5100
5123
  near: 0.1,
5101
5124
  far: 1000,
5102
5125
  position: new Vector3(0, 0, 4)
5103
- }, targetFrameRate = -1, fixedFrameTime = false, colorSpace = SRGBColorSpace, toneMapping = 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 } = {}){
5126
+ }, targetFrameRate = -1, fixedFrameTime = false, colorSpace = SRGBColorSpace, toneMapping = 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 } = {}){
5104
5127
  super(), this._instanceId = Viewer.instanceCount++, this._dpr = 1, this._width = 1, this._height = 1, this._viewport = {
5105
5128
  width: 1,
5106
5129
  height: 1,
5107
5130
  factor: 1
5108
- }, this._active = false, this._loading = false, this._tasking = false, this._running = 4 //延迟4帧执行
5109
- , this._rootRotated = false, this._time = 0, this._lastTime = 0, this._lastFrameTime = 0, this._targetFrameRate = -1, this._fixedFrameTime = false, this._windowSize = ()=>[
5131
+ }, 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 = ()=>[
5110
5132
  window.innerWidth,
5111
5133
  window.innerHeight
5112
5134
  ], this._orientation = Orientation.AUTO;
@@ -5138,14 +5160,8 @@ class Viewer extends EventEmitter {
5138
5160
  this._renderer.sortObjects = sortObjects;
5139
5161
  this._targetFrameRate = targetFrameRate;
5140
5162
  this._windowSize = typeof resize === "function" ? resize : resize === ResizeMode.AUTO ? this._windowSize : null;
5141
- const complete = (set, cb)=>{
5142
- set();
5143
- cb && cb();
5144
- };
5145
- this._taskManager = new TaskManager(()=>complete(()=>this._tasking = false, tasker.onComplete), tasker.onProgress, tasker.onError);
5146
- this._taskManager.onStart = ()=>this._tasking = true;
5147
- this._loadingManager = new LoadingManager(()=>complete(()=>this._loading = false, loader.onComplete), loader.onProgress, loader.onError);
5148
- this._loadingManager.onStart = ()=>this._loading = true;
5163
+ this._taskManager = new TaskManager(tasker.onComplete, tasker.onProgress, tasker.onError);
5164
+ this._loadingManager = new LoadingManager(loader.onComplete, loader.onProgress, loader.onError);
5149
5165
  this._resourceManager = new ResourceManager(this);
5150
5166
  this._componentManager = new ComponentManager(this);
5151
5167
  this._resourceOptions = {
@@ -5161,6 +5177,7 @@ class Viewer extends EventEmitter {
5161
5177
  this._input = this.add(new DeviceInput(input || {
5162
5178
  source: this._canvas
5163
5179
  }));
5180
+ this._decodeURL = decodeURL;
5164
5181
  this.add(Renderer);
5165
5182
  this.addLoader(GLTFLoader);
5166
5183
  this.addLoader(HDRLoader);