Raanan Weber 7 年之前
父节点
当前提交
1edda05e82
共有 2 个文件被更改,包括 20 次插入74 次删除
  1. 0 65
      Viewer/src/loader/plugins/extendedMaterialLoaderPlugin.ts
  2. 20 9
      Viewer/src/viewer/sceneManager.ts

+ 0 - 65
Viewer/src/loader/plugins/extendedMaterialLoaderPlugin.ts

@@ -10,70 +10,5 @@ export class ExtendedMaterialLoaderPlugin implements ILoaderPlugin {
     public onMaterialLoaded(baseMaterial: Material) {
         var material = baseMaterial as PBRMaterial;
         material.alphaMode = Engine.ALPHA_PREMULTIPLIED_PORTERDUFF;
-
-        var isAlphaOnlyOne = (texture: BaseTexture) => {
-            var pixels = texture.readPixels() as Uint8Array;
-            var alphaOne = true;
-            for (var i = 3; i < pixels.length; i += 4) {
-                if (pixels[i] !== 255) {
-                    alphaOne = false;
-                    break;
-                }
-            }
-
-            return alphaOne;
-        };
-
-        if (material.albedoTexture) {
-            material.albedoColor = Color3.White();
-        }
-        else {
-            material.albedoColor = material.albedoColor.toLinearSpace();
-        }
-
-        if (material.reflectivityTexture) {
-            material.reflectivityColor = Color3.White();
-            material.microSurface = 1;
-
-            if (material.reflectivityTexture) {
-                if (material.reflectivityTexture.isReady()) {
-                    if (isAlphaOnlyOne(material.reflectivityTexture)) {
-                        material.useMicroSurfaceFromReflectivityMapAlpha = false;
-                        material.useAutoMicroSurfaceFromReflectivityMap = true;
-                    }
-                }
-                else {
-                    (<Texture>material.reflectivityTexture).onLoadObservable.add(loadedTexture => {
-                        if (isAlphaOnlyOne(loadedTexture)) {
-                            material.useMicroSurfaceFromReflectivityMapAlpha = false;
-                            material.useAutoMicroSurfaceFromReflectivityMap = true;
-                        }
-                    });
-                }
-            }
-        }
-        else {
-            material.reflectivityColor = material.reflectivityColor.toLinearSpace();
-        }
-
-        if (material.bumpTexture) {
-            material.bumpTexture.level = 1;
-            // Normal maps are currently DirectX convention instead of OpenGL.
-            material.invertNormalMapY = true;
-        }
-
-        if (material.emissiveTexture) {
-            material.emissiveColor = Color3.White();
-        }
-
-        material.useRadianceOcclusion = false;
-        material.useHorizonOcclusion = false;
-        material.useAlphaFresnel = material.needAlphaBlending();
-        material.backFaceCulling = material.forceDepthWrite;
-        material.twoSidedLighting = true;
-        material.useSpecularOverAlpha = false;
-        material.useRadianceOverAlpha = false;
-        material.usePhysicalLightFalloff = true;
-        material.forceNormalForward = true;
     }
 }

+ 20 - 9
Viewer/src/viewer/sceneManager.ts

@@ -745,7 +745,7 @@ export class SceneManager {
      * @param model optionally use the model to configure the camera.
      */
     protected _configureLights(lightsConfiguration: { [name: string]: ILightConfiguration | boolean } = {}, model?: ViewerModel) {
-        let focusMeshes = model ? model.meshes : this.scene.meshes;
+
         // sanity check!
         if (!Object.keys(lightsConfiguration).length) {
             if (!this.scene.lights.length)
@@ -853,14 +853,8 @@ export class SceneManager {
                     }
 
                     // add the focues meshes to the shadow list
-                    let shadownMap = shadowGenerator.getShadowMap();
-                    if (!shadownMap) return;
-                    let renderList = shadownMap.renderList;
-                    for (var index = 0; index < focusMeshes.length; index++) {
-                        if (Tags.MatchesQuery(focusMeshes[index], 'castShadow')) {
-                            renderList && renderList.push(focusMeshes[index]);
-                        }
-                    }
+                    this._updateShadowRenderList(shadowGenerator, model);
+
                     var blurKernel = this.getBlurKernel(light, bufferSize);
 
                     //shadowGenerator.useBlurCloseExponentialShadowMap = true;
@@ -895,6 +889,23 @@ export class SceneManager {
         });
     }
 
+    private _updateShadowRenderList(shadowGenerator: ShadowGenerator, model?: ViewerModel, resetList?: boolean) {
+        let focusMeshes = model ? model.meshes : this.scene.meshes;
+        // add the focues meshes to the shadow list
+        let shadownMap = shadowGenerator.getShadowMap();
+        if (!shadownMap) return;
+        if (resetList && shadownMap.renderList) {
+            shadownMap.renderList.length = 0;
+        } else {
+            shadownMap.renderList = []
+        }
+        for (var index = 0; index < focusMeshes.length; index++) {
+            if (Tags.MatchesQuery(focusMeshes[index], 'castShadow')) {
+                shadownMap.renderList.push(focusMeshes[index]);
+            }
+        }
+    }
+
     /**
      * Gets the shadow map blur kernel according to the light configuration.
      * @param light The light used to generate the shadows