@xviewer.js/core 1.0.0-alpha.23 → 1.0.0-alpha.26
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.js +117 -28
- package/dist/main.js.map +1 -1
- package/dist/module.js +117 -28
- package/dist/module.js.map +1 -1
- package/package.json +1 -1
- package/types/Viewer.d.ts +8 -7
- package/types/materials/ReflectorMaterial.d.ts +5 -1
package/dist/main.js
CHANGED
|
@@ -3182,7 +3182,19 @@ const vert_Reflector = `
|
|
|
3182
3182
|
uniform mat4 textureMatrix;
|
|
3183
3183
|
varying vec4 vUv4;
|
|
3184
3184
|
varying vec2 vUv;
|
|
3185
|
-
|
|
3185
|
+
|
|
3186
|
+
#ifdef USE_UV1
|
|
3187
|
+
varying vec2 vUv1;
|
|
3188
|
+
#endif
|
|
3189
|
+
|
|
3190
|
+
#ifdef USE_UV2
|
|
3191
|
+
varying vec2 vUv2;
|
|
3192
|
+
#endif
|
|
3193
|
+
|
|
3194
|
+
#ifdef USE_UV3
|
|
3195
|
+
varying vec2 vUv3;
|
|
3196
|
+
#endif
|
|
3197
|
+
|
|
3186
3198
|
varying vec3 vViewPosition;
|
|
3187
3199
|
|
|
3188
3200
|
#include <common>
|
|
@@ -3197,7 +3209,19 @@ void main() {
|
|
|
3197
3209
|
vec4 mvPosition = viewMatrix * positionWS;
|
|
3198
3210
|
|
|
3199
3211
|
vUv = uv;
|
|
3212
|
+
|
|
3213
|
+
#ifdef USE_UV1
|
|
3200
3214
|
vUv1 = uv1;
|
|
3215
|
+
#endif
|
|
3216
|
+
|
|
3217
|
+
#ifdef USE_UV2
|
|
3218
|
+
vUv2 = uv2;
|
|
3219
|
+
#endif
|
|
3220
|
+
|
|
3221
|
+
#ifdef USE_UV3
|
|
3222
|
+
vUv3 = uv2;
|
|
3223
|
+
#endif
|
|
3224
|
+
|
|
3201
3225
|
vUv4 = textureMatrix * vec4(position, 1.0);
|
|
3202
3226
|
|
|
3203
3227
|
vViewPosition = -mvPosition.xyz;
|
|
@@ -3215,13 +3239,25 @@ uniform sampler2D tDiffuse;
|
|
|
3215
3239
|
uniform sampler2D normalMap;
|
|
3216
3240
|
uniform sampler2D roughnessMap;
|
|
3217
3241
|
uniform sampler2D aoMap;
|
|
3218
|
-
uniform float
|
|
3242
|
+
uniform float aoMapIntensity;
|
|
3219
3243
|
uniform sampler2D lightMap;
|
|
3220
|
-
uniform float
|
|
3244
|
+
uniform float lightMapIntensity;
|
|
3221
3245
|
|
|
3222
|
-
varying vec4 vUv4;
|
|
3223
3246
|
varying vec2 vUv;
|
|
3224
|
-
|
|
3247
|
+
|
|
3248
|
+
#ifdef USE_UV1
|
|
3249
|
+
varying vec2 vUv1;
|
|
3250
|
+
#endif
|
|
3251
|
+
|
|
3252
|
+
#ifdef USE_UV2
|
|
3253
|
+
varying vec2 vUv2;
|
|
3254
|
+
#endif
|
|
3255
|
+
|
|
3256
|
+
#ifdef USE_UV3
|
|
3257
|
+
varying vec2 vUv3;
|
|
3258
|
+
#endif
|
|
3259
|
+
|
|
3260
|
+
varying vec4 vUv4;
|
|
3225
3261
|
varying vec3 vViewPosition;
|
|
3226
3262
|
varying vec3 vNormal;
|
|
3227
3263
|
|
|
@@ -3232,10 +3268,9 @@ varying vec3 vNormal;
|
|
|
3232
3268
|
void main() {
|
|
3233
3269
|
#include <logdepthbuf_fragment>
|
|
3234
3270
|
|
|
3235
|
-
vec4
|
|
3236
|
-
vec4 texelNormal = texture2D(normalMap, vUv);
|
|
3271
|
+
vec4 texelNormal = texture2D(normalMap, UV_NORMAL);
|
|
3237
3272
|
vec3 normal = normalize(vec3(texelNormal.r * 2.0 - 1.0, texelNormal.b, texelNormal.g * 2.0 - 1.0));
|
|
3238
|
-
vec3 coord =
|
|
3273
|
+
vec3 coord = vUv4.xyz / vUv4.w;
|
|
3239
3274
|
vec2 reflectUv = coord.xy + coord.z * normal.xz * 0.05;
|
|
3240
3275
|
|
|
3241
3276
|
vec3 geometryNormal = normalize(vNormal);
|
|
@@ -3249,7 +3284,7 @@ void main() {
|
|
|
3249
3284
|
vec3 specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
|
|
3250
3285
|
float specularF90 = 1.0;
|
|
3251
3286
|
|
|
3252
|
-
float roughnessFactor = texture2D(roughnessMap,
|
|
3287
|
+
float roughnessFactor = texture2D(roughnessMap, UV_ROUGHNESS).g * roughness;
|
|
3253
3288
|
|
|
3254
3289
|
computeMultiscattering( geometryNormal, geometryViewDir, specularColor, specularF90, roughnessFactor, singleScattering, multiScattering );
|
|
3255
3290
|
|
|
@@ -3257,7 +3292,7 @@ void main() {
|
|
|
3257
3292
|
vec3 diffuse = diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );
|
|
3258
3293
|
|
|
3259
3294
|
vec3 irradiance = vec3(0.);
|
|
3260
|
-
irradiance += texture2D(lightMap,
|
|
3295
|
+
irradiance += texture2D(lightMap, UV_LIGHTMAP).rgb * lightMapIntensity;
|
|
3261
3296
|
|
|
3262
3297
|
float lod = roughnessFactor * (1.7 - 0.7 * roughnessFactor) * 6.;
|
|
3263
3298
|
vec4 reflectColor = textureLod(tDiffuse, reflectUv, lod);
|
|
@@ -3268,7 +3303,7 @@ void main() {
|
|
|
3268
3303
|
f_specular += reflectColor.rgb * (1.0 - roughnessFactor * roughnessFactor) + multiScattering * irradiance;
|
|
3269
3304
|
f_diffuse += diffuse * irradiance;
|
|
3270
3305
|
|
|
3271
|
-
float ambientOcclusion = mix(1., texture2D(aoMap,
|
|
3306
|
+
float ambientOcclusion = mix(1., texture2D(aoMap, UV_AO).r, aoMapIntensity);
|
|
3272
3307
|
float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
|
|
3273
3308
|
f_specular *= computeSpecularOcclusion(dotNV, ambientOcclusion, roughnessFactor);
|
|
3274
3309
|
|
|
@@ -3279,6 +3314,36 @@ void main() {
|
|
|
3279
3314
|
}
|
|
3280
3315
|
`;
|
|
3281
3316
|
class ReflectorMaterial extends three.ShaderMaterial {
|
|
3317
|
+
onBeforeCompile(shader, renderer) {
|
|
3318
|
+
const channels = [];
|
|
3319
|
+
if (this.aoMap && this.aoMap.channel) {
|
|
3320
|
+
channels.push([
|
|
3321
|
+
"UV_AO",
|
|
3322
|
+
this.aoMap.channel
|
|
3323
|
+
]);
|
|
3324
|
+
}
|
|
3325
|
+
if (this.lightMap && this.lightMap.channel) {
|
|
3326
|
+
channels.push([
|
|
3327
|
+
"UV_LIGHTMAP",
|
|
3328
|
+
this.lightMap.channel
|
|
3329
|
+
]);
|
|
3330
|
+
}
|
|
3331
|
+
if (this.roughnessMap && this.roughnessMap.channel) {
|
|
3332
|
+
channels.push([
|
|
3333
|
+
"UV_ROUGHNESS",
|
|
3334
|
+
this.roughnessMap.channel
|
|
3335
|
+
]);
|
|
3336
|
+
}
|
|
3337
|
+
if (this.normalMap && this.normalMap.channel) {
|
|
3338
|
+
channels.push([
|
|
3339
|
+
"UV_NORMAL",
|
|
3340
|
+
this.normalMap.channel
|
|
3341
|
+
]);
|
|
3342
|
+
}
|
|
3343
|
+
channels.forEach(([key, channel])=>{
|
|
3344
|
+
this.defines[key] = "vUv" + channel;
|
|
3345
|
+
});
|
|
3346
|
+
}
|
|
3282
3347
|
get metalness() {
|
|
3283
3348
|
return this.uniforms.metalness.value;
|
|
3284
3349
|
}
|
|
@@ -3296,29 +3361,39 @@ class ReflectorMaterial extends three.ShaderMaterial {
|
|
|
3296
3361
|
}
|
|
3297
3362
|
set roughnessMap(v) {
|
|
3298
3363
|
this.uniforms.roughnessMap.value = v;
|
|
3364
|
+
this.needsUpdate = true;
|
|
3299
3365
|
}
|
|
3300
3366
|
get normalMap() {
|
|
3301
3367
|
return this.uniforms.normalMap.value;
|
|
3302
3368
|
}
|
|
3303
3369
|
set normalMap(v) {
|
|
3304
3370
|
this.uniforms.normalMap.value = v;
|
|
3371
|
+
this.needsUpdate = true;
|
|
3305
3372
|
}
|
|
3306
3373
|
get aoMap() {
|
|
3307
3374
|
return this.uniforms.aoMap.value;
|
|
3308
3375
|
}
|
|
3309
3376
|
set aoMap(v) {
|
|
3310
3377
|
this.uniforms.aoMap.value = v;
|
|
3378
|
+
this.needsUpdate = true;
|
|
3311
3379
|
}
|
|
3312
3380
|
get lightMap() {
|
|
3313
3381
|
return this.uniforms.lightMap.value;
|
|
3314
3382
|
}
|
|
3315
3383
|
set lightMap(v) {
|
|
3316
3384
|
this.uniforms.lightMap.value = v;
|
|
3385
|
+
this.needsUpdate = true;
|
|
3317
3386
|
}
|
|
3318
3387
|
constructor(...args){
|
|
3319
3388
|
super(...args);
|
|
3320
3389
|
this.vertexShader = vert_Reflector;
|
|
3321
3390
|
this.fragmentShader = frag_Reflector;
|
|
3391
|
+
this.defines = {
|
|
3392
|
+
UV_AO: "vUv",
|
|
3393
|
+
UV_LIGHTMAP: "vUv",
|
|
3394
|
+
UV_ROUGHNESS: "vUv",
|
|
3395
|
+
UV_NORMAL: "vUv"
|
|
3396
|
+
};
|
|
3322
3397
|
this.uniforms = {
|
|
3323
3398
|
color: {
|
|
3324
3399
|
value: new three.Color(0xffffff)
|
|
@@ -4246,14 +4321,14 @@ class Viewer extends EventEmitter {
|
|
|
4246
4321
|
}
|
|
4247
4322
|
return shadow;
|
|
4248
4323
|
}
|
|
4249
|
-
static
|
|
4324
|
+
static compileMaterial(renderer, scene, camera, target) {
|
|
4250
4325
|
Viewer.fullscreenMesh.material = target;
|
|
4251
4326
|
renderer.compile(Viewer.fullscreenMesh, camera, scene);
|
|
4252
4327
|
}
|
|
4253
|
-
static
|
|
4328
|
+
static compileObject3D(renderer, scene, camera, target) {
|
|
4254
4329
|
renderer.compile(target, camera, scene);
|
|
4255
4330
|
}
|
|
4256
|
-
static
|
|
4331
|
+
static compileTexture(renderer, target) {
|
|
4257
4332
|
if (Array.isArray(target)) {
|
|
4258
4333
|
for (let v of target){
|
|
4259
4334
|
renderer.initTexture(v);
|
|
@@ -4269,7 +4344,7 @@ class Viewer extends EventEmitter {
|
|
|
4269
4344
|
renderer.render(Viewer.fullscreenMesh, Viewer.fullscreenCamera);
|
|
4270
4345
|
renderer.setRenderTarget(RT);
|
|
4271
4346
|
}
|
|
4272
|
-
static
|
|
4347
|
+
static createFullscreenTriangle() {
|
|
4273
4348
|
let geometry = new three.BufferGeometry();
|
|
4274
4349
|
geometry.setAttribute('position', new three.Float32BufferAttribute([
|
|
4275
4350
|
-1,
|
|
@@ -4292,10 +4367,24 @@ class Viewer extends EventEmitter {
|
|
|
4292
4367
|
], 2));
|
|
4293
4368
|
return geometry;
|
|
4294
4369
|
}
|
|
4295
|
-
static
|
|
4296
|
-
|
|
4370
|
+
static findChild(node, path) {
|
|
4371
|
+
let child = null;
|
|
4372
|
+
let parts = path.split("/");
|
|
4373
|
+
let children = node.children;
|
|
4374
|
+
for (let part of parts){
|
|
4375
|
+
child = children.find((v)=>v.name === part);
|
|
4376
|
+
if (child) {
|
|
4377
|
+
children = child.children;
|
|
4378
|
+
} else {
|
|
4379
|
+
return null;
|
|
4380
|
+
}
|
|
4381
|
+
}
|
|
4382
|
+
return child;
|
|
4383
|
+
}
|
|
4384
|
+
static getChildByName(node, name) {
|
|
4385
|
+
return Viewer.getObject(node, (v)=>v.name === name && v);
|
|
4297
4386
|
}
|
|
4298
|
-
static
|
|
4387
|
+
static getObject(node, filter) {
|
|
4299
4388
|
const queue = [
|
|
4300
4389
|
node
|
|
4301
4390
|
];
|
|
@@ -4308,7 +4397,7 @@ class Viewer extends EventEmitter {
|
|
|
4308
4397
|
object.children.forEach((v)=>queue.push(v));
|
|
4309
4398
|
}
|
|
4310
4399
|
}
|
|
4311
|
-
static
|
|
4400
|
+
static getObjects(node, filter) {
|
|
4312
4401
|
const queue = [
|
|
4313
4402
|
node
|
|
4314
4403
|
];
|
|
@@ -4517,7 +4606,7 @@ class Viewer extends EventEmitter {
|
|
|
4517
4606
|
this._tweenManager.killTweensOf(target);
|
|
4518
4607
|
}
|
|
4519
4608
|
traverseMaterials(callback) {
|
|
4520
|
-
Viewer.
|
|
4609
|
+
Viewer.getObjects(this._scene, (item)=>{
|
|
4521
4610
|
if (item.isMesh) {
|
|
4522
4611
|
if (Array.isArray(item.material)) item.material.forEach(callback);
|
|
4523
4612
|
else callback(item.material);
|
|
@@ -4651,28 +4740,28 @@ class Viewer extends EventEmitter {
|
|
|
4651
4740
|
compile(target) {
|
|
4652
4741
|
if (Array.isArray(target)) {
|
|
4653
4742
|
if (target.every((v)=>v.isMaterial)) {
|
|
4654
|
-
Viewer.
|
|
4743
|
+
Viewer.compileMaterial(this._renderer, this._scene, this._camera, target);
|
|
4655
4744
|
} else {
|
|
4656
4745
|
throw Error("Viewer.compile: unsuport material");
|
|
4657
4746
|
}
|
|
4658
4747
|
} else if (typeof target === "object") {
|
|
4659
4748
|
if (target.isMaterial) {
|
|
4660
|
-
Viewer.
|
|
4749
|
+
Viewer.compileMaterial(this._renderer, this._scene, this._camera, target);
|
|
4661
4750
|
} else if (target.isObject3D) {
|
|
4662
4751
|
if (target.meshData.materials) {
|
|
4663
|
-
Viewer.
|
|
4752
|
+
Viewer.compileMaterial(this._renderer, this._scene, this._camera, Object.values(target.meshData.materials));
|
|
4664
4753
|
}
|
|
4665
4754
|
if (target.meshData.textures) {
|
|
4666
|
-
Viewer.
|
|
4755
|
+
Viewer.compileTexture(this._renderer, Object.values(target.meshData.textures));
|
|
4667
4756
|
}
|
|
4668
4757
|
if (!target.meshData.meshes) {
|
|
4669
|
-
Viewer.
|
|
4758
|
+
Viewer.compileObject3D(this._renderer, this._scene, this._camera, target);
|
|
4670
4759
|
}
|
|
4671
4760
|
} else if (target.isTexture) {
|
|
4672
|
-
Viewer.
|
|
4761
|
+
Viewer.compileTexture(this._renderer, target);
|
|
4673
4762
|
}
|
|
4674
4763
|
} else {
|
|
4675
|
-
Viewer.
|
|
4764
|
+
Viewer.compileObject3D(this._renderer, this._scene, this._camera, this._scene);
|
|
4676
4765
|
}
|
|
4677
4766
|
}
|
|
4678
4767
|
constructor({ root, canvas, autoStart = true, autoResize = true, shadows = false, camera = {
|
|
@@ -4750,7 +4839,7 @@ Viewer._shadowCameraKeys = [
|
|
|
4750
4839
|
"near",
|
|
4751
4840
|
"far"
|
|
4752
4841
|
];
|
|
4753
|
-
Viewer.fullscreenMesh = new three.Mesh(Viewer.
|
|
4842
|
+
Viewer.fullscreenMesh = new three.Mesh(Viewer.createFullscreenTriangle());
|
|
4754
4843
|
Viewer.fullscreenCamera = new three.OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
|
4755
4844
|
|
|
4756
4845
|
class MergeRefectPass {
|