@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/module.js CHANGED
@@ -3723,7 +3723,9 @@ uniform float roughness;
3723
3723
  uniform float metalness;
3724
3724
  uniform sampler2D map;
3725
3725
  uniform sampler2D normalMap;
3726
+ uniform vec4 normalScaleBias;
3726
3727
  uniform sampler2D roughnessMap;
3728
+ uniform vec4 roughnessScaleBias;
3727
3729
  uniform sampler2D aoMap;
3728
3730
  uniform float aoMapIntensity;
3729
3731
  uniform sampler2D lightMap;
@@ -3761,7 +3763,7 @@ void main() {
3761
3763
  vec2 reflectUv = coord.xy;
3762
3764
 
3763
3765
  #ifdef USE_NORMALMAP
3764
- vec4 texelNormal = texture2D(normalMap, UV_NORMAL);
3766
+ vec4 texelNormal = texture2D(normalMap, UV_NORMAL * normalScaleBias.xy + normalScaleBias.zw);
3765
3767
  vec3 normal = normalize(vec3(texelNormal.r * 2.0 - 1.0, texelNormal.b, texelNormal.g * 2.0 - 1.0));
3766
3768
  reflectUv += coord.z * normal.xz * 0.05;
3767
3769
  #endif
@@ -3788,7 +3790,7 @@ void main() {
3788
3790
  float roughnessFactor = roughness;
3789
3791
 
3790
3792
  #ifdef USE_ROUGHNESSMAP
3791
- roughnessFactor *= texture2D(roughnessMap, UV_ROUGHNESS).g * roughness;
3793
+ roughnessFactor *= texture2D(roughnessMap, UV_ROUGHNESS * roughnessScaleBias.xy + roughnessScaleBias.zw).g * roughness;
3792
3794
  #endif
3793
3795
 
3794
3796
  computeMultiscattering( geometryNormal, geometryViewDir, specularColor, specularF90, roughnessFactor, singleScattering, multiScattering );
@@ -3800,6 +3802,8 @@ void main() {
3800
3802
 
3801
3803
  #ifdef USE_LIGHTMAP
3802
3804
  irradiance += texture2D(lightMap, UV_LIGHTMAP).rgb * lightMapIntensity;
3805
+ #else
3806
+ irradiance += vec3(1.);
3803
3807
  #endif
3804
3808
 
3805
3809
  float lod = roughnessFactor * (1.7 - 0.7 * roughnessFactor) * 6.;
@@ -3886,12 +3890,24 @@ class ReflectorMaterial extends ShaderMaterial {
3886
3890
  set roughnessMap(v) {
3887
3891
  this.uniforms.roughnessMap.value = v;
3888
3892
  }
3893
+ get roughnessScaleBias() {
3894
+ return this.uniforms.roughnessScaleBias.value;
3895
+ }
3896
+ set roughnessScaleBias(v) {
3897
+ this.uniforms.roughnessScaleBias.value.copy(v);
3898
+ }
3889
3899
  get normalMap() {
3890
3900
  return this.uniforms.normalMap.value;
3891
3901
  }
3892
3902
  set normalMap(v) {
3893
3903
  this.uniforms.normalMap.value = v;
3894
3904
  }
3905
+ get normalScaleBias() {
3906
+ return this.uniforms.normalScaleBias.value;
3907
+ }
3908
+ set normalScaleBias(v) {
3909
+ this.uniforms.normalScaleBias.value.copy(v);
3910
+ }
3895
3911
  get aoMap() {
3896
3912
  return this.uniforms.aoMap.value;
3897
3913
  }
@@ -3956,9 +3972,15 @@ class ReflectorMaterial extends ShaderMaterial {
3956
3972
  roughnessMap: {
3957
3973
  value: null
3958
3974
  },
3975
+ roughnessScaleBias: {
3976
+ value: new Vector4(1, 1, 0, 0)
3977
+ },
3959
3978
  normalMap: {
3960
3979
  value: null
3961
3980
  },
3981
+ normalScaleBias: {
3982
+ value: new Vector4(1, 1, 0, 0)
3983
+ },
3962
3984
  aoMap: {
3963
3985
  value: null
3964
3986
  },
@@ -4004,9 +4026,15 @@ __decorate([
4004
4026
  __decorate([
4005
4027
  property
4006
4028
  ], ReflectorMaterial.prototype, "roughnessMap", null);
4029
+ __decorate([
4030
+ property
4031
+ ], ReflectorMaterial.prototype, "roughnessScaleBias", null);
4007
4032
  __decorate([
4008
4033
  property
4009
4034
  ], ReflectorMaterial.prototype, "normalMap", null);
4035
+ __decorate([
4036
+ property
4037
+ ], ReflectorMaterial.prototype, "normalScaleBias", null);
4010
4038
  __decorate([
4011
4039
  property
4012
4040
  ], ReflectorMaterial.prototype, "aoMap", null);
@@ -4323,10 +4351,13 @@ class TaskManager {
4323
4351
  destroy() {
4324
4352
  this._tasks = [];
4325
4353
  this._taskIndex = 0;
4326
- clearInterval(this._interval);
4327
4354
  }
4328
4355
  add(task) {
4329
4356
  this._tasks.push(task);
4357
+ if (this._onStartCalled === false) {
4358
+ this._onStartCalled = true;
4359
+ this.onStart && this.onStart();
4360
+ }
4330
4361
  }
4331
4362
  update() {
4332
4363
  let task = this._tasks[this._taskIndex];
@@ -4338,13 +4369,9 @@ class TaskManager {
4338
4369
  this.onError && this.onError(task);
4339
4370
  }
4340
4371
  ++this._taskIndex;
4341
- if (this._onstartCalled === false) {
4342
- this._onstartCalled = true;
4343
- this.onStart && this.onStart();
4344
- }
4345
4372
  this.onProgress && this.onProgress(task, this._taskIndex, this._tasks.length);
4346
4373
  if (this._taskIndex === this._tasks.length) {
4347
- this._onstartCalled = false;
4374
+ this._onStartCalled = false;
4348
4375
  this.onComplete && this.onComplete();
4349
4376
  }
4350
4377
  }
@@ -4355,9 +4382,7 @@ class TaskManager {
4355
4382
  this.onError = onError;
4356
4383
  this._tasks = [];
4357
4384
  this._taskIndex = 0;
4358
- this._interval = null;
4359
- this._onstartCalled = false;
4360
- this._interval = setInterval(()=>this.update());
4385
+ this._onStartCalled = false;
4361
4386
  }
4362
4387
  }
4363
4388
 
@@ -4510,10 +4535,11 @@ ResourceManager._texSettingKeys = [
4510
4535
  ];
4511
4536
 
4512
4537
  class Task {
4513
- constructor(excute, name = "task" + this.instanceId){
4514
- this.excute = excute;
4515
- this.name = name;
4538
+ constructor(excute, name){
4516
4539
  this.instanceId = Task._instanceCount++;
4540
+ this.name = "task" + this.instanceId;
4541
+ this.excute = excute;
4542
+ this.name = name || this.name;
4517
4543
  }
4518
4544
  }
4519
4545
  Task._instanceCount = 0;
@@ -4704,16 +4730,22 @@ class Viewer extends EventEmitter {
4704
4730
  }
4705
4731
  }
4706
4732
  loop(dt) {
4707
- dt = Math.min(dt, 0.067);
4708
- this._renderer.info.reset();
4709
- this._componentManager.update(dt);
4710
- this._componentManager.render(dt);
4733
+ this._taskManager.update();
4734
+ if (!this._loading && !this._tasking && this._running > 0) {
4735
+ this._running--;
4736
+ }
4737
+ if (this._running <= 0) {
4738
+ dt = Math.min(dt, 0.067);
4739
+ this._renderer.info.reset();
4740
+ this._componentManager.update(dt);
4741
+ this._componentManager.render(dt);
4742
+ }
4711
4743
  }
4712
4744
  start() {
4713
- if (this._running == false) {
4714
- this._running = true;
4745
+ if (this._active == false) {
4746
+ this._active = true;
4715
4747
  const frameCallback = (time)=>{
4716
- if (this._running) {
4748
+ if (this._active) {
4717
4749
  this._frame(time * 0.001);
4718
4750
  }
4719
4751
  };
@@ -4722,7 +4754,8 @@ class Viewer extends EventEmitter {
4722
4754
  return this;
4723
4755
  }
4724
4756
  stop() {
4725
- this._running = false;
4757
+ this._active = false;
4758
+ this._running = 4;
4726
4759
  this._time = this._lastTime = 0;
4727
4760
  return this;
4728
4761
  }
@@ -5072,7 +5105,8 @@ class Viewer extends EventEmitter {
5072
5105
  width: 1,
5073
5106
  height: 1,
5074
5107
  factor: 1
5075
- }, this._running = false, this._rootRotated = false, this._time = 0, this._lastTime = 0, this._lastFrameTime = 0, this._targetFrameRate = -1, this._fixedFrameTime = false, this._windowSize = ()=>[
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 = ()=>[
5076
5110
  window.innerWidth,
5077
5111
  window.innerHeight
5078
5112
  ], this._orientation = Orientation.AUTO;
@@ -5104,21 +5138,14 @@ class Viewer extends EventEmitter {
5104
5138
  this._renderer.sortObjects = sortObjects;
5105
5139
  this._targetFrameRate = targetFrameRate;
5106
5140
  this._windowSize = typeof resize === "function" ? resize : resize === ResizeMode.AUTO ? this._windowSize : null;
5107
- const states = {
5108
- tasking: false,
5109
- loading: false};
5110
- const start = ()=>{
5111
- !states.tasking && !states.loading && this.start();
5112
- };
5113
5141
  const complete = (set, cb)=>{
5114
5142
  set();
5115
5143
  cb && cb();
5116
- !this._running && setTimeout(start);
5117
5144
  };
5118
- this._taskManager = new TaskManager(()=>complete(()=>states.tasking = false, tasker.onComplete), tasker.onProgress, tasker.onError);
5119
- this._taskManager.onStart = ()=>states.tasking = true;
5120
- this._loadingManager = new LoadingManager(()=>complete(()=>states.loading = false, loader.onComplete), loader.onProgress, loader.onError);
5121
- this._loadingManager.onStart = ()=>states.loading = true;
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;
5122
5149
  this._resourceManager = new ResourceManager(this);
5123
5150
  this._componentManager = new ComponentManager(this);
5124
5151
  this._resourceOptions = {
@@ -5145,7 +5172,7 @@ class Viewer extends EventEmitter {
5145
5172
  setTimeout(()=>{
5146
5173
  this.rotate();
5147
5174
  this.resize();
5148
- start();
5175
+ this.start();
5149
5176
  });
5150
5177
  }
5151
5178
  }