@xviewer.js/core 1.0.4-alpha.9 → 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/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,7 +4371,6 @@ 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);
@@ -4357,14 +4384,14 @@ class TaskManager {
4357
4384
  console.error(e);
4358
4385
  this.onError && this.onError(task);
4359
4386
  }
4360
- ++this._taskIndex;
4361
- if (this._onstartCalled === false) {
4362
- this._onstartCalled = true;
4387
+ if (this._onStartCalled === false) {
4388
+ this._onStartCalled = true;
4363
4389
  this.onStart && this.onStart();
4364
4390
  }
4391
+ ++this._taskIndex;
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
 
@@ -4498,7 +4523,10 @@ class ResourceManager {
4498
4523
  texSettings,
4499
4524
  ...props,
4500
4525
  onProgress,
4501
- onLoad: resolve,
4526
+ onLoad: (asset)=>{
4527
+ this._resources.set(url, asset);
4528
+ resolve(asset);
4529
+ },
4502
4530
  onError: (err)=>{
4503
4531
  console.error(`${url} not exist`, err);
4504
4532
  reject(err);
@@ -4509,8 +4537,12 @@ class ResourceManager {
4509
4537
  }
4510
4538
  });
4511
4539
  }
4540
+ getAsset(url) {
4541
+ return this._resources.get(url);
4542
+ }
4512
4543
  constructor(viewer){
4513
4544
  this._loaders = new Map();
4545
+ this._resources = new Map();
4514
4546
  this._viewer = viewer;
4515
4547
  }
4516
4548
  }
@@ -4530,10 +4562,11 @@ ResourceManager._texSettingKeys = [
4530
4562
  ];
4531
4563
 
4532
4564
  class Task {
4533
- constructor(excute, name = "task" + this.instanceId){
4534
- this.excute = excute;
4535
- this.name = name;
4565
+ constructor(excute, name){
4536
4566
  this.instanceId = Task._instanceCount++;
4567
+ this.name = "task" + this.instanceId;
4568
+ this.excute = excute;
4569
+ this.name = name || this.name;
4537
4570
  }
4538
4571
  }
4539
4572
  Task._instanceCount = 0;
@@ -4724,16 +4757,24 @@ class Viewer extends EventEmitter {
4724
4757
  }
4725
4758
  }
4726
4759
  loop(dt) {
4727
- dt = Math.min(dt, 0.067);
4728
- this._renderer.info.reset();
4729
- this._componentManager.update(dt);
4730
- this._componentManager.render(dt);
4760
+ if (!this._loading) {
4761
+ this._taskManager.update();
4762
+ if (!this._tasking) {
4763
+ this._running = true;
4764
+ }
4765
+ }
4766
+ if (this._running) {
4767
+ dt = Math.min(dt, 0.067);
4768
+ this._renderer.info.reset();
4769
+ this._componentManager.update(dt);
4770
+ this._componentManager.render(dt);
4771
+ }
4731
4772
  }
4732
4773
  start() {
4733
- if (this._running == false) {
4734
- this._running = true;
4774
+ if (this._active == false) {
4775
+ this._active = true;
4735
4776
  const frameCallback = (time)=>{
4736
- if (this._running) {
4777
+ if (this._active) {
4737
4778
  this._frame(time * 0.001);
4738
4779
  }
4739
4780
  };
@@ -4742,7 +4783,7 @@ class Viewer extends EventEmitter {
4742
4783
  return this;
4743
4784
  }
4744
4785
  stop() {
4745
- this._running = false;
4786
+ this._active = this._running = false;
4746
4787
  this._time = this._lastTime = 0;
4747
4788
  return this;
4748
4789
  }
@@ -4824,8 +4865,13 @@ class Viewer extends EventEmitter {
4824
4865
  setURLModifier(callback) {
4825
4866
  return this._loadingManager.setURLModifier(callback);
4826
4867
  }
4827
- loadAsset(props) {
4828
- return this._resourceManager.loadAsset(Object.assign({}, this._resourceOptions, props));
4868
+ loadAsset({ url, ...props }) {
4869
+ return this._resourceManager.loadAsset(Object.assign({
4870
+ url: this._decodeURL(url)
4871
+ }, this._resourceOptions, props));
4872
+ }
4873
+ getAsset(url) {
4874
+ return this._resourceManager.getAsset(this._decodeURL(url));
4829
4875
  }
4830
4876
  getLoader(ext) {
4831
4877
  return this._resourceManager.getLoader(ext);
@@ -5087,12 +5133,12 @@ class Viewer extends EventEmitter {
5087
5133
  near: 0.1,
5088
5134
  far: 1000,
5089
5135
  position: new THREE.Vector3(0, 0, 4)
5090
- }, 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 } = {}){
5136
+ }, 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 } = {}){
5091
5137
  super(), this._instanceId = Viewer.instanceCount++, this._dpr = 1, this._width = 1, this._height = 1, this._viewport = {
5092
5138
  width: 1,
5093
5139
  height: 1,
5094
5140
  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 = ()=>[
5141
+ }, 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 = ()=>[
5096
5142
  window.innerWidth,
5097
5143
  window.innerHeight
5098
5144
  ], this._orientation = Orientation.AUTO;
@@ -5124,21 +5170,14 @@ class Viewer extends EventEmitter {
5124
5170
  this._renderer.sortObjects = sortObjects;
5125
5171
  this._targetFrameRate = targetFrameRate;
5126
5172
  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
5173
  const complete = (set, cb)=>{
5134
5174
  set();
5135
5175
  cb && cb();
5136
- !this._running && setTimeout(start);
5137
5176
  };
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;
5177
+ this._taskManager = new TaskManager(()=>complete(()=>this._tasking = false, tasker.onComplete), tasker.onProgress, tasker.onError);
5178
+ this._taskManager.onStart = ()=>this._tasking = true;
5179
+ this._loadingManager = new THREE.LoadingManager(()=>complete(()=>this._loading = false, loader.onComplete), loader.onProgress, loader.onError);
5180
+ this._loadingManager.onStart = ()=>this._loading = true;
5142
5181
  this._resourceManager = new ResourceManager(this);
5143
5182
  this._componentManager = new ComponentManager(this);
5144
5183
  this._resourceOptions = {
@@ -5154,6 +5193,7 @@ class Viewer extends EventEmitter {
5154
5193
  this._input = this.add(new DeviceInput(input || {
5155
5194
  source: this._canvas
5156
5195
  }));
5196
+ this._decodeURL = decodeURL;
5157
5197
  this.add(Renderer);
5158
5198
  this.addLoader(GLTFLoader);
5159
5199
  this.addLoader(HDRLoader);
@@ -5165,7 +5205,7 @@ class Viewer extends EventEmitter {
5165
5205
  setTimeout(()=>{
5166
5206
  this.rotate();
5167
5207
  this.resize();
5168
- start();
5208
+ this.start();
5169
5209
  });
5170
5210
  }
5171
5211
  }