@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 +78 -38
- package/dist/main.cjs.map +1 -1
- package/dist/module.js +78 -38
- package/dist/module.js.map +1 -1
- package/package.json +1 -1
- package/types/Task.d.ts +3 -3
- package/types/TaskManager.d.ts +1 -2
- package/types/Viewer.d.ts +8 -2
- package/types/asset/ResourceManager.d.ts +5 -3
- package/types/materials/ReflectorMaterial.d.ts +11 -2
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,7 +4351,6 @@ 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);
|
|
@@ -4337,14 +4364,14 @@ class TaskManager {
|
|
|
4337
4364
|
console.error(e);
|
|
4338
4365
|
this.onError && this.onError(task);
|
|
4339
4366
|
}
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
this._onstartCalled = true;
|
|
4367
|
+
if (this._onStartCalled === false) {
|
|
4368
|
+
this._onStartCalled = true;
|
|
4343
4369
|
this.onStart && this.onStart();
|
|
4344
4370
|
}
|
|
4371
|
+
++this._taskIndex;
|
|
4345
4372
|
this.onProgress && this.onProgress(task, this._taskIndex, this._tasks.length);
|
|
4346
4373
|
if (this._taskIndex === this._tasks.length) {
|
|
4347
|
-
this.
|
|
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.
|
|
4359
|
-
this._onstartCalled = false;
|
|
4360
|
-
this._interval = setInterval(()=>this.update());
|
|
4385
|
+
this._onStartCalled = false;
|
|
4361
4386
|
}
|
|
4362
4387
|
}
|
|
4363
4388
|
|
|
@@ -4478,7 +4503,10 @@ class ResourceManager {
|
|
|
4478
4503
|
texSettings,
|
|
4479
4504
|
...props,
|
|
4480
4505
|
onProgress,
|
|
4481
|
-
onLoad:
|
|
4506
|
+
onLoad: (asset)=>{
|
|
4507
|
+
this._resources.set(url, asset);
|
|
4508
|
+
resolve(asset);
|
|
4509
|
+
},
|
|
4482
4510
|
onError: (err)=>{
|
|
4483
4511
|
console.error(`${url} not exist`, err);
|
|
4484
4512
|
reject(err);
|
|
@@ -4489,8 +4517,12 @@ class ResourceManager {
|
|
|
4489
4517
|
}
|
|
4490
4518
|
});
|
|
4491
4519
|
}
|
|
4520
|
+
getAsset(url) {
|
|
4521
|
+
return this._resources.get(url);
|
|
4522
|
+
}
|
|
4492
4523
|
constructor(viewer){
|
|
4493
4524
|
this._loaders = new Map();
|
|
4525
|
+
this._resources = new Map();
|
|
4494
4526
|
this._viewer = viewer;
|
|
4495
4527
|
}
|
|
4496
4528
|
}
|
|
@@ -4510,10 +4542,11 @@ ResourceManager._texSettingKeys = [
|
|
|
4510
4542
|
];
|
|
4511
4543
|
|
|
4512
4544
|
class Task {
|
|
4513
|
-
constructor(excute, name
|
|
4514
|
-
this.excute = excute;
|
|
4515
|
-
this.name = name;
|
|
4545
|
+
constructor(excute, name){
|
|
4516
4546
|
this.instanceId = Task._instanceCount++;
|
|
4547
|
+
this.name = "task" + this.instanceId;
|
|
4548
|
+
this.excute = excute;
|
|
4549
|
+
this.name = name || this.name;
|
|
4517
4550
|
}
|
|
4518
4551
|
}
|
|
4519
4552
|
Task._instanceCount = 0;
|
|
@@ -4704,16 +4737,24 @@ class Viewer extends EventEmitter {
|
|
|
4704
4737
|
}
|
|
4705
4738
|
}
|
|
4706
4739
|
loop(dt) {
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4740
|
+
if (!this._loading) {
|
|
4741
|
+
this._taskManager.update();
|
|
4742
|
+
if (!this._tasking) {
|
|
4743
|
+
this._running = true;
|
|
4744
|
+
}
|
|
4745
|
+
}
|
|
4746
|
+
if (this._running) {
|
|
4747
|
+
dt = Math.min(dt, 0.067);
|
|
4748
|
+
this._renderer.info.reset();
|
|
4749
|
+
this._componentManager.update(dt);
|
|
4750
|
+
this._componentManager.render(dt);
|
|
4751
|
+
}
|
|
4711
4752
|
}
|
|
4712
4753
|
start() {
|
|
4713
|
-
if (this.
|
|
4714
|
-
this.
|
|
4754
|
+
if (this._active == false) {
|
|
4755
|
+
this._active = true;
|
|
4715
4756
|
const frameCallback = (time)=>{
|
|
4716
|
-
if (this.
|
|
4757
|
+
if (this._active) {
|
|
4717
4758
|
this._frame(time * 0.001);
|
|
4718
4759
|
}
|
|
4719
4760
|
};
|
|
@@ -4722,7 +4763,7 @@ class Viewer extends EventEmitter {
|
|
|
4722
4763
|
return this;
|
|
4723
4764
|
}
|
|
4724
4765
|
stop() {
|
|
4725
|
-
this._running = false;
|
|
4766
|
+
this._active = this._running = false;
|
|
4726
4767
|
this._time = this._lastTime = 0;
|
|
4727
4768
|
return this;
|
|
4728
4769
|
}
|
|
@@ -4804,8 +4845,13 @@ class Viewer extends EventEmitter {
|
|
|
4804
4845
|
setURLModifier(callback) {
|
|
4805
4846
|
return this._loadingManager.setURLModifier(callback);
|
|
4806
4847
|
}
|
|
4807
|
-
loadAsset(props) {
|
|
4808
|
-
return this._resourceManager.loadAsset(Object.assign({
|
|
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));
|
|
4809
4855
|
}
|
|
4810
4856
|
getLoader(ext) {
|
|
4811
4857
|
return this._resourceManager.getLoader(ext);
|
|
@@ -5067,12 +5113,12 @@ class Viewer extends EventEmitter {
|
|
|
5067
5113
|
near: 0.1,
|
|
5068
5114
|
far: 1000,
|
|
5069
5115
|
position: new Vector3(0, 0, 4)
|
|
5070
|
-
}, 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 } = {}){
|
|
5071
5117
|
super(), this._instanceId = Viewer.instanceCount++, this._dpr = 1, this._width = 1, this._height = 1, this._viewport = {
|
|
5072
5118
|
width: 1,
|
|
5073
5119
|
height: 1,
|
|
5074
5120
|
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 = ()=>[
|
|
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 = ()=>[
|
|
5076
5122
|
window.innerWidth,
|
|
5077
5123
|
window.innerHeight
|
|
5078
5124
|
], this._orientation = Orientation.AUTO;
|
|
@@ -5104,21 +5150,14 @@ class Viewer extends EventEmitter {
|
|
|
5104
5150
|
this._renderer.sortObjects = sortObjects;
|
|
5105
5151
|
this._targetFrameRate = targetFrameRate;
|
|
5106
5152
|
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
5153
|
const complete = (set, cb)=>{
|
|
5114
5154
|
set();
|
|
5115
5155
|
cb && cb();
|
|
5116
|
-
!this._running && setTimeout(start);
|
|
5117
5156
|
};
|
|
5118
|
-
this._taskManager = new TaskManager(()=>complete(()=>
|
|
5119
|
-
this._taskManager.onStart = ()=>
|
|
5120
|
-
this._loadingManager = new LoadingManager(()=>complete(()=>
|
|
5121
|
-
this._loadingManager.onStart = ()=>
|
|
5157
|
+
this._taskManager = new TaskManager(()=>complete(()=>this._tasking = false, tasker.onComplete), tasker.onProgress, tasker.onError);
|
|
5158
|
+
this._taskManager.onStart = ()=>this._tasking = true;
|
|
5159
|
+
this._loadingManager = new LoadingManager(()=>complete(()=>this._loading = false, loader.onComplete), loader.onProgress, loader.onError);
|
|
5160
|
+
this._loadingManager.onStart = ()=>this._loading = true;
|
|
5122
5161
|
this._resourceManager = new ResourceManager(this);
|
|
5123
5162
|
this._componentManager = new ComponentManager(this);
|
|
5124
5163
|
this._resourceOptions = {
|
|
@@ -5134,6 +5173,7 @@ class Viewer extends EventEmitter {
|
|
|
5134
5173
|
this._input = this.add(new DeviceInput(input || {
|
|
5135
5174
|
source: this._canvas
|
|
5136
5175
|
}));
|
|
5176
|
+
this._decodeURL = decodeURL;
|
|
5137
5177
|
this.add(Renderer);
|
|
5138
5178
|
this.addLoader(GLTFLoader);
|
|
5139
5179
|
this.addLoader(HDRLoader);
|
|
@@ -5145,7 +5185,7 @@ class Viewer extends EventEmitter {
|
|
|
5145
5185
|
setTimeout(()=>{
|
|
5146
5186
|
this.rotate();
|
|
5147
5187
|
this.resize();
|
|
5148
|
-
start();
|
|
5188
|
+
this.start();
|
|
5149
5189
|
});
|
|
5150
5190
|
}
|
|
5151
5191
|
}
|