CalcSoftOcclusion() public static method

public static CalcSoftOcclusion ( Mesh mesh ) : void
mesh UnityEngine.Mesh
return void
コード例 #1
0
        void OnPostprocessModel(GameObject root)
        {
            // Check if path contains "AO Tree"
            string lowerPath = assetPath.ToLower();

            if (lowerPath.IndexOf("ambient-occlusion") != -1)
            {
                var physicsScene = root.scene.GetPhysicsScene();

                Component[] filters = root.GetComponentsInChildren(typeof(MeshFilter));
                foreach (MeshFilter filter in filters)
                {
                    if (filter.sharedMesh != null)
                    {
                        Mesh mesh = filter.sharedMesh;

                        // Calculate AO
                        TreeAO.CalcSoftOcclusion(mesh, physicsScene);

                        // Calculate vertex colors for tree waving
                        Bounds    bounds   = mesh.bounds;
                        Color[]   colors   = mesh.colors;
                        Vector3[] vertices = mesh.vertices;
                        Vector4[] tangents = mesh.tangents;
                        if (colors.Length == 0)
                        {
                            colors = new Color[mesh.vertexCount];
                            for (int i = 0; i < colors.Length; i++)
                            {
                                colors[i] = Color.white;
                            }
                        }

                        float maxAO = 0.0F;
                        for (int i = 0; i < tangents.Length; i++)
                        {
                            maxAO = Mathf.Max(tangents[i].w, maxAO);
                        }

                        float largest = 0.0F;
                        for (int i = 0; i < colors.Length; i++)
                        {
                            Vector2 offset = new Vector2(vertices[i].x, vertices[i].z);
                            float   branch = offset.magnitude;
                            largest = Mathf.Max(branch, largest);
                        }
                        for (int i = 0; i < colors.Length; i++)
                        {
                            Vector2 offset = new Vector2(vertices[i].x, vertices[i].z);
                            float   branch = offset.magnitude / largest;

                            float height = (vertices[i].y - bounds.min.y) / bounds.size.y;
                            //                  colors[i].a = tangents[i].w * maxAO + height;
                            colors[i].a = (height * branch) * 0.6F + height * 0.5F;
                        }
                        mesh.colors = colors;
                    }
                }
            }
        }
コード例 #2
0
        private void OnPostprocessModel(GameObject root)
        {
            string text = base.assetPath.ToLower();

            if (text.IndexOf("ambient-occlusion") != -1)
            {
                Component[] componentsInChildren = root.GetComponentsInChildren(typeof(MeshFilter));
                Component[] array = componentsInChildren;
                for (int i = 0; i < array.Length; i++)
                {
                    MeshFilter meshFilter = (MeshFilter)array[i];
                    if (meshFilter.sharedMesh != null)
                    {
                        Mesh sharedMesh = meshFilter.sharedMesh;
                        TreeAO.CalcSoftOcclusion(sharedMesh);
                        Bounds    bounds   = sharedMesh.bounds;
                        Color[]   array2   = sharedMesh.colors;
                        Vector3[] vertices = sharedMesh.vertices;
                        Vector4[] tangents = sharedMesh.tangents;
                        if (array2.Length == 0)
                        {
                            array2 = new Color[sharedMesh.vertexCount];
                            for (int j = 0; j < array2.Length; j++)
                            {
                                array2[j] = Color.white;
                            }
                        }
                        float b = 0f;
                        for (int k = 0; k < tangents.Length; k++)
                        {
                            b = Mathf.Max(tangents[k].w, b);
                        }
                        float num = 0f;
                        for (int l = 0; l < array2.Length; l++)
                        {
                            Vector2 vector    = new Vector2(vertices[l].x, vertices[l].z);
                            float   magnitude = vector.magnitude;
                            num = Mathf.Max(magnitude, num);
                        }
                        for (int m = 0; m < array2.Length; m++)
                        {
                            Vector2 vector2 = new Vector2(vertices[m].x, vertices[m].z);
                            float   num2    = vector2.magnitude / num;
                            float   num3    = (vertices[m].y - bounds.min.y) / bounds.size.y;
                            array2[m].a = num3 * num2 * 0.6f + num3 * 0.5f;
                        }
                        sharedMesh.colors = array2;
                    }
                }
            }
        }
コード例 #3
0
 private void OnPostprocessModel(GameObject root)
 {
     if (base.assetPath.ToLower().IndexOf("ambient-occlusion") != -1)
     {
         Component[] componentsInChildren = root.GetComponentsInChildren(typeof(MeshFilter));
         foreach (MeshFilter filter in componentsInChildren)
         {
             if (filter.sharedMesh != null)
             {
                 Mesh sharedMesh = filter.sharedMesh;
                 TreeAO.CalcSoftOcclusion(sharedMesh);
                 Bounds    bounds   = sharedMesh.bounds;
                 Color[]   colors   = sharedMesh.colors;
                 Vector3[] vertices = sharedMesh.vertices;
                 Vector4[] tangents = sharedMesh.tangents;
                 if (colors.Length == 0)
                 {
                     colors = new Color[sharedMesh.vertexCount];
                     for (int m = 0; m < colors.Length; m++)
                     {
                         colors[m] = Color.white;
                     }
                 }
                 float b = 0f;
                 for (int i = 0; i < tangents.Length; i++)
                 {
                     b = Mathf.Max(tangents[i].w, b);
                 }
                 float num5 = 0f;
                 for (int j = 0; j < colors.Length; j++)
                 {
                     Vector2 vector = new Vector2(vertices[j].x, vertices[j].z);
                     num5 = Mathf.Max(vector.magnitude, num5);
                 }
                 for (int k = 0; k < colors.Length; k++)
                 {
                     Vector2 vector2 = new Vector2(vertices[k].x, vertices[k].z);
                     float   num9    = vector2.magnitude / num5;
                     float   num10   = (vertices[k].y - bounds.min.y) / bounds.size.y;
                     colors[k].a = ((num10 * num9) * 0.6f) + (num10 * 0.5f);
                 }
                 sharedMesh.colors = colors;
             }
         }
     }
 }
コード例 #4
0
 private void OnPostprocessModel(GameObject root)
 {
     if (this.assetPath.ToLower().IndexOf("ambient-occlusion") == -1)
     {
         return;
     }
     foreach (MeshFilter componentsInChild in root.GetComponentsInChildren(typeof(MeshFilter)))
     {
         if ((Object)componentsInChild.sharedMesh != (Object)null)
         {
             Mesh sharedMesh = componentsInChild.sharedMesh;
             TreeAO.CalcSoftOcclusion(sharedMesh);
             Bounds    bounds     = sharedMesh.bounds;
             Color[]   colorArray = sharedMesh.colors;
             Vector3[] vertices   = sharedMesh.vertices;
             Vector4[] tangents   = sharedMesh.tangents;
             if (colorArray.Length == 0)
             {
                 colorArray = new Color[sharedMesh.vertexCount];
                 for (int index = 0; index < colorArray.Length; ++index)
                 {
                     colorArray[index] = Color.white;
                 }
             }
             float b1 = 0.0f;
             for (int index = 0; index < tangents.Length; ++index)
             {
                 b1 = Mathf.Max(tangents[index].w, b1);
             }
             float b2 = 0.0f;
             for (int index = 0; index < colorArray.Length; ++index)
             {
                 b2 = Mathf.Max(new Vector2(vertices[index].x, vertices[index].z).magnitude, b2);
             }
             for (int index = 0; index < colorArray.Length; ++index)
             {
                 float num1 = new Vector2(vertices[index].x, vertices[index].z).magnitude / b2;
                 float num2 = (vertices[index].y - bounds.min.y) / bounds.size.y;
                 colorArray[index].a = (float)((double)num2 * (double)num1 * 0.600000023841858 + (double)num2 * 0.5);
             }
             sharedMesh.colors = colorArray;
         }
     }
 }