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