@xviewer.js/core 1.0.4-alpha.9 → 1.0.4

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 CHANGED
@@ -3743,7 +3743,9 @@ uniform float roughness;
3743
3743
  uniform float metalness;
3744
3744
  uniform sampler2D map;
3745
3745
  uniform sampler2D normalMap;
3746
+ uniform vec4 normalScaleBias;
3746
3747
  uniform sampler2D roughnessMap;
3748
+ uniform vec4 roughnessScaleBias;
3747
3749
  uniform sampler2D aoMap;
3748
3750
  uniform float aoMapIntensity;
3749
3751
  uniform sampler2D lightMap;
@@ -3781,7 +3783,7 @@ void main() {
3781
3783
  vec2 reflectUv = coord.xy;
3782
3784
 
3783
3785
  #ifdef USE_NORMALMAP
3784
- vec4 texelNormal = texture2D(normalMap, UV_NORMAL);
3786
+ vec4 texelNormal = texture2D(normalMap, UV_NORMAL * normalScaleBias.xy + normalScaleBias.zw);
3785
3787
  vec3 normal = normalize(vec3(texelNormal.r * 2.0 - 1.0, texelNormal.b, texelNormal.g * 2.0 - 1.0));
3786
3788
  reflectUv += coord.z * normal.xz * 0.05;
3787
3789
  #endif
@@ -3808,7 +3810,7 @@ void main() {
3808
3810
  float roughnessFactor = roughness;
3809
3811
 
3810
3812
  #ifdef USE_ROUGHNESSMAP
3811
- roughnessFactor *= texture2D(roughnessMap, UV_ROUGHNESS).g * roughness;
3813
+ roughnessFactor *= texture2D(roughnessMap, UV_ROUGHNESS * roughnessScaleBias.xy + roughnessScaleBias.zw).g * roughness;
3812
3814
  #endif
3813
3815
 
3814
3816
  computeMultiscattering( geometryNormal, geometryViewDir, specularColor, specularF90, roughnessFactor, singleScattering, multiScattering );
@@ -3820,6 +3822,8 @@ void main() {
3820
3822
 
3821
3823
  #ifdef USE_LIGHTMAP
3822
3824
  irradiance += texture2D(lightMap, UV_LIGHTMAP).rgb * lightMapIntensity;
3825
+ #else
3826
+ irradiance += vec3(1.);
3823
3827
  #endif
3824
3828
 
3825
3829
  float lod = roughnessFactor * (1.7 - 0.7 * roughnessFactor) * 6.;
@@ -3906,12 +3910,24 @@ class ReflectorMaterial extends THREE.ShaderMaterial {
3906
3910
  set roughnessMap(v) {
3907
3911
  this.uniforms.roughnessMap.value = v;
3908
3912
  }
3913
+ get roughnessScaleBias() {
3914
+ return this.uniforms.roughnessScaleBias.value;
3915
+ }
3916
+ set roughnessScaleBias(v) {
3917
+ this.uniforms.roughnessScaleBias.value.copy(v);
3918
+ }
3909
3919
  get normalMap() {
3910
3920
  return this.uniforms.normalMap.value;
3911
3921
  }
3912
3922
  set normalMap(v) {
3913
3923
  this.uniforms.normalMap.value = v;
3914
3924
  }
3925
+ get normalScaleBias() {
3926
+ return this.uniforms.normalScaleBias.value;
3927
+ }
3928
+ set normalScaleBias(v) {
3929
+ this.uniforms.normalScaleBias.value.copy(v);
3930
+ }
3915
3931
  get aoMap() {
3916
3932
  return this.uniforms.aoMap.value;
3917
3933
  }
@@ -3976,9 +3992,15 @@ class ReflectorMaterial extends THREE.ShaderMaterial {
3976
3992
  roughnessMap: {
3977
3993
  value: null
3978
3994
  },
3995
+ roughnessScaleBias: {
3996
+ value: new THREE.Vector4(1, 1, 0, 0)
3997
+ },
3979
3998
  normalMap: {
3980
3999
  value: null
3981
4000
  },
4001
+ normalScaleBias: {
4002
+ value: new THREE.Vector4(1, 1, 0, 0)
4003
+ },
3982
4004
  aoMap: {
3983
4005
  value: null
3984
4006
  },
@@ -4024,9 +4046,15 @@ __decorate([
4024
4046
  __decorate([
4025
4047
  property
4026
4048
  ], ReflectorMaterial.prototype, "roughnessMap", null);
4049
+ __decorate([
4050
+ property
4051
+ ], ReflectorMaterial.prototype, "roughnessScaleBias", null);
4027
4052
  __decorate([
4028
4053
  property
4029
4054
  ], ReflectorMaterial.prototype, "normalMap", null);
4055
+ __decorate([
4056
+ property
4057
+ ], ReflectorMaterial.prototype, "normalScaleBias", null);
4030
4058
  __decorate([
4031
4059
  property
4032
4060
  ], ReflectorMaterial.prototype, "aoMap", null);
@@ -4343,10 +4371,13 @@ class TaskManager {
4343
4371
  destroy() {
4344
4372
  this._tasks = [];
4345
4373
  this._taskIndex = 0;
4346
- clearInterval(this._interval);
4347
4374
  }
4348
4375
  add(task) {
4349
4376
  this._tasks.push(task);
4377
+ if (this._onStartCalled === false) {
4378
+ this._onStartCalled = true;
4379
+ this.onStart && this.onStart();
4380
+ }
4350
4381
  }
4351
4382
  update() {
4352
4383
  let task = this._tasks[this._taskIndex];
@@ -4358,13 +4389,9 @@ class TaskManager {
4358
4389
  this.onError && this.onError(task);
4359
4390
  }
4360
4391
  ++this._taskIndex;
4361
- if (this._onstartCalled === false) {
4362
- this._onstartCalled = true;
4363
- this.onStart && this.onStart();
4364
- }
4365
4392
  this.onProgress && this.onProgress(task, this._taskIndex, this._tasks.length);
4366
4393
  if (this._taskIndex === this._tasks.length) {
4367
- this._onstartCalled = false;
4394
+ this._onStartCalled = false;
4368
4395
  this.onComplete && this.onComplete();
4369
4396
  }
4370
4397
  }
@@ -4375,9 +4402,7 @@ class TaskManager {
4375
4402
  this.onError = onError;
4376
4403
  this._tasks = [];
4377
4404
  this._taskIndex = 0;
4378
- this._interval = null;
4379
- this._onstartCalled = false;
4380
- this._interval = setInterval(()=>this.update());
4405
+ this._onStartCalled = false;
4381
4406
  }
4382
4407
  }
4383
4408
 
@@ -4530,10 +4555,11 @@ ResourceManager._texSettingKeys = [
4530
4555
  ];
4531
4556
 
4532
4557
  class Task {
4533
- constructor(excute, name = "task" + this.instanceId){
4534
- this.excute = excute;
4535
- this.name = name;
4558
+ constructor(excute, name){
4536
4559
  this.instanceId = Task._instanceCount++;
4560
+ this.name = "task" + this.instanceId;
4561
+ this.excute = excute;
4562
+ this.name = name || this.name;
4537
4563
  }
4538
4564
  }
4539
4565
  Task._instanceCount = 0;
@@ -4724,16 +4750,22 @@ class Viewer extends EventEmitter {
4724
4750
  }
4725
4751
  }
4726
4752
  loop(dt) {
4727
- dt = Math.min(dt, 0.067);
4728
- this._renderer.info.reset();
4729
- this._componentManager.update(dt);
4730
- this._componentManager.render(dt);
4753
+ this._taskManager.update();
4754
+ if (!this._loading && !this._tasking && this._running > 0) {
4755
+ this._running--;
4756
+ }
4757
+ if (this._running <= 0) {
4758
+ dt = Math.min(dt, 0.067);
4759
+ this._renderer.info.reset();
4760
+ this._componentManager.update(dt);
4761
+ this._componentManager.render(dt);
4762
+ }
4731
4763
  }
4732
4764
  start() {
4733
- if (this._running == false) {
4734
- this._running = true;
4765
+ if (this._active == false) {
4766
+ this._active = true;
4735
4767
  const frameCallback = (time)=>{
4736
- if (this._running) {
4768
+ if (this._active) {
4737
4769
  this._frame(time * 0.001);
4738
4770
  }
4739
4771
  };
@@ -4742,7 +4774,8 @@ class Viewer extends EventEmitter {
4742
4774
  return this;
4743
4775
  }
4744
4776
  stop() {
4745
- this._running = false;
4777
+ this._active = false;
4778
+ this._running = 4;
4746
4779
  this._time = this._lastTime = 0;
4747
4780
  return this;
4748
4781
  }
@@ -5092,7 +5125,8 @@ class Viewer extends EventEmitter {
5092
5125
  width: 1,
5093
5126
  height: 1,
5094
5127
  factor: 1
5095
- }, this._running = false, this._rootRotated = false, this._time = 0, this._lastTime = 0, this._lastFrameTime = 0, this._targetFrameRate = -1, this._fixedFrameTime = false, this._windowSize = ()=>[
5128
+ }, this._active = false, this._loading = false, this._tasking = false, this._running = 4 //延迟4帧执行
5129
+ , this._rootRotated = false, this._time = 0, this._lastTime = 0, this._lastFrameTime = 0, this._targetFrameRate = -1, this._fixedFrameTime = false, this._windowSize = ()=>[
5096
5130
  window.innerWidth,
5097
5131
  window.innerHeight
5098
5132
  ], this._orientation = Orientation.AUTO;
@@ -5124,21 +5158,14 @@ class Viewer extends EventEmitter {
5124
5158
  this._renderer.sortObjects = sortObjects;
5125
5159
  this._targetFrameRate = targetFrameRate;
5126
5160
  this._windowSize = typeof resize === "function" ? resize : resize === ResizeMode.AUTO ? this._windowSize : null;
5127
- const states = {
5128
- tasking: false,
5129
- loading: false};
5130
- const start = ()=>{
5131
- !states.tasking && !states.loading && this.start();
5132
- };
5133
5161
  const complete = (set, cb)=>{
5134
5162
  set();
5135
5163
  cb && cb();
5136
- !this._running && setTimeout(start);
5137
5164
  };
5138
- this._taskManager = new TaskManager(()=>complete(()=>states.tasking = false, tasker.onComplete), tasker.onProgress, tasker.onError);
5139
- this._taskManager.onStart = ()=>states.tasking = true;
5140
- this._loadingManager = new THREE.LoadingManager(()=>complete(()=>states.loading = false, loader.onComplete), loader.onProgress, loader.onError);
5141
- this._loadingManager.onStart = ()=>states.loading = true;
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;
5142
5169
  this._resourceManager = new ResourceManager(this);
5143
5170
  this._componentManager = new ComponentManager(this);
5144
5171
  this._resourceOptions = {
@@ -5165,7 +5192,7 @@ class Viewer extends EventEmitter {
5165
5192
  setTimeout(()=>{
5166
5193
  this.rotate();
5167
5194
  this.resize();
5168
- start();
5195
+ this.start();
5169
5196
  });
5170
5197
  }
5171
5198
  }