UnityEditor.TreeAO.CountIntersections C# (CSharp) Method

CountIntersections() private static method

private static CountIntersections ( Vector3 v, Vector3 dist, float length ) : int
v Vector3
dist Vector3
length float
return int
        private static int CountIntersections(Vector3 v, Vector3 dist, float length)
        {
            v += (Vector3) (dist * 0.01f);
            if (!kDebug)
            {
                return (Physics.RaycastAll(v, dist, length, 0x20000000).Length + Physics.RaycastAll(v + ((Vector3) (dist * length)), -dist, length, 0x20000000).Length);
            }
            RaycastHit[] hitArray = Physics.RaycastAll(v, dist, length, 0x20000000);
            int num2 = hitArray.Length;
            float distance = 0f;
            if (num2 > 0)
            {
                distance = hitArray[hitArray.Length - 1].distance;
            }
            hitArray = Physics.RaycastAll(v + ((Vector3) (dist * length)), -dist, length, 0x20000000);
            if (hitArray.Length > 0)
            {
                float num4 = length - hitArray[0].distance;
                if (num4 > distance)
                {
                    distance = num4;
                }
            }
            return (num2 + hitArray.Length);
        }

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::CountIntersections