@xviewer.js/core 1.0.4 → 1.0.5-alhpa.0

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
@@ -4354,10 +4354,6 @@ class TaskManager {
4354
4354
  }
4355
4355
  add(task) {
4356
4356
  this._tasks.push(task);
4357
- if (this._onStartCalled === false) {
4358
- this._onStartCalled = true;
4359
- this.onStart && this.onStart();
4360
- }
4361
4357
  }
4362
4358
  update() {
4363
4359
  let task = this._tasks[this._taskIndex];
@@ -4368,6 +4364,10 @@ class TaskManager {
4368
4364
  console.error(e);
4369
4365
  this.onError && this.onError(task);
4370
4366
  }
4367
+ if (this._onStartCalled === false) {
4368
+ this._onStartCalled = true;
4369
+ this.onStart && this.onStart();
4370
+ }
4371
4371
  ++this._taskIndex;
4372
4372
  this.onProgress && this.onProgress(task, this._taskIndex, this._tasks.length);
4373
4373
  if (this._taskIndex === this._tasks.length) {
@@ -4503,7 +4503,10 @@ class ResourceManager {
4503
4503
  texSettings,
4504
4504
  ...props,
4505
4505
  onProgress,
4506
- onLoad: resolve,
4506
+ onLoad: (asset)=>{
4507
+ this._resources.set(url, asset);
4508
+ resolve(asset);
4509
+ },
4507
4510
  onError: (err)=>{
4508
4511
  console.error(`${url} not exist`, err);
4509
4512
  reject(err);
@@ -4514,8 +4517,12 @@ class ResourceManager {
4514
4517
  }
4515
4518
  });
4516
4519
  }
4520
+ getAsset(url) {
4521
+ return this._resources.get(url);
4522
+ }
4517
4523
  constructor(viewer){
4518
4524
  this._loaders = new Map();
4525
+ this._resources = new Map();
4519
4526
  this._viewer = viewer;
4520
4527
  }
4521
4528
  }
@@ -4730,11 +4737,13 @@ class Viewer extends EventEmitter {
4730
4737
  }
4731
4738
  }
4732
4739
  loop(dt) {
4733
- this._taskManager.update();
4734
- if (!this._loading && !this._tasking && this._running > 0) {
4735
- this._running--;
4740
+ if (!this._loading) {
4741
+ this._taskManager.update();
4742
+ if (!this._tasking) {
4743
+ this._running = true;
4744
+ }
4736
4745
  }
4737
- if (this._running <= 0) {
4746
+ if (this._running) {
4738
4747
  dt = Math.min(dt, 0.067);
4739
4748
  this._renderer.info.reset();
4740
4749
  this._componentManager.update(dt);
@@ -4754,8 +4763,7 @@ class Viewer extends EventEmitter {
4754
4763
  return this;
4755
4764
  }
4756
4765
  stop() {
4757
- this._active = false;
4758
- this._running = 4;
4766
+ this._active = this._running = false;
4759
4767
  this._time = this._lastTime = 0;
4760
4768
  return this;
4761
4769
  }
@@ -4837,8 +4845,13 @@ class Viewer extends EventEmitter {
4837
4845
  setURLModifier(callback) {
4838
4846
  return this._loadingManager.setURLModifier(callback);
4839
4847
  }
4840
- loadAsset(props) {
4841
- return this._resourceManager.loadAsset(Object.assign({}, this._resourceOptions, props));
4848
+ loadAsset({ url, ...props }) {
4849
+ return this._resourceManager.loadAsset(Object.assign({
4850
+ url: this._decodeURL(url)
4851
+ }, this._resourceOptions, props));
4852
+ }
4853
+ getAsset(url) {
4854
+ return this._resourceManager.getAsset(this._decodeURL(url));
4842
4855
  }
4843
4856
  getLoader(ext) {
4844
4857
  return this._resourceManager.getLoader(ext);
@@ -5100,13 +5113,12 @@ class Viewer extends EventEmitter {
5100
5113
  near: 0.1,
5101
5114
  far: 1000,
5102
5115
  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 } = {}){
5116
+ }, 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
5117
  super(), this._instanceId = Viewer.instanceCount++, this._dpr = 1, this._width = 1, this._height = 1, this._viewport = {
5105
5118
  width: 1,
5106
5119
  height: 1,
5107
5120
  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 = ()=>[
5121
+ }, 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
5122
  window.innerWidth,
5111
5123
  window.innerHeight
5112
5124
  ], this._orientation = Orientation.AUTO;
@@ -5161,6 +5173,7 @@ class Viewer extends EventEmitter {
5161
5173
  this._input = this.add(new DeviceInput(input || {
5162
5174
  source: this._canvas
5163
5175
  }));
5176
+ this._decodeURL = decodeURL;
5164
5177
  this.add(Renderer);
5165
5178
  this.addLoader(GLTFLoader);
5166
5179
  this.addLoader(HDRLoader);