UnityEditor.TreeAO.GetWeight C# (CSharp) Method

GetWeight() private static method

private static GetWeight ( int coeff, Vector3 dir ) : float
coeff int
dir Vector3
return float
        private static float GetWeight(int coeff, Vector3 dir)
        {
            switch (coeff)
            {
                case 0:
                    return 0.5f;

                case 1:
                    return (0.5f * dir.x);

                case 2:
                    return (0.5f * dir.y);

                case 3:
                    return (0.5f * dir.z);
            }
            Debug.Log("Only defined up to 3");
            return 0f;
        }

Usage Example

示例#1
0
        public static void CalcSoftOcclusion(Mesh mesh)
        {
            GameObject gameObject = new GameObject("Test");

            gameObject.layer = 29;
            MeshFilter meshFilter = gameObject.AddComponent <MeshFilter>();

            meshFilter.mesh = mesh;
            gameObject.AddComponent <MeshCollider>();
            if (TreeAO.directions == null)
            {
                TreeAO.InitializeDirections();
            }
            Vector4[] array = new Vector4[TreeAO.directions.Length];
            for (int i = 0; i < TreeAO.directions.Length; i++)
            {
                array[i] = new Vector4(TreeAO.GetWeight(1, TreeAO.directions[i]), TreeAO.GetWeight(2, TreeAO.directions[i]), TreeAO.GetWeight(3, TreeAO.directions[i]), TreeAO.GetWeight(0, TreeAO.directions[i]));
            }
            Vector3[] vertices = mesh.vertices;
            Vector4[] array2   = new Vector4[vertices.Length];
            float     num      = 0f;

            for (int j = 0; j < vertices.Length; j++)
            {
                Vector4 vector = Vector4.zero;
                Vector3 v      = gameObject.transform.TransformPoint(vertices[j]);
                for (int k = 0; k < TreeAO.directions.Length; k++)
                {
                    float num2 = (float)TreeAO.CountIntersections(v, gameObject.transform.TransformDirection(TreeAO.directions[k]), 3f);
                    num2    = Mathf.Pow(0.5f, num2);
                    vector += array[k] * num2;
                }
                vector   /= (float)TreeAO.directions.Length;
                num      += vector.w;
                array2[j] = vector;
            }
            num /= (float)vertices.Length;
            for (int l = 0; l < vertices.Length; l++)
            {
                Vector4[] expr_1D4_cp_0 = array2;
                int       expr_1D4_cp_1 = l;
                expr_1D4_cp_0[expr_1D4_cp_1].w = expr_1D4_cp_0[expr_1D4_cp_1].w - num;
            }
            mesh.tangents = array2;
            UnityEngine.Object.DestroyImmediate(gameObject);
        }
All Usage Examples Of UnityEditor.TreeAO::GetWeight