private void UpdateShadowMesh()
        {
            // Updating shadowMesh
            Vector3[] vertices = new Vector3[m_IndicesCount + 2];
            int[]     indices  = new int[m_IndicesCount * 3];

            /* IMPORTANT :
             *   all vertices are in local space.
             */

            Vector3 rayDirection = transform.right;
            float   currentAngle = transform.eulerAngles.z;
            float   angleStep    = m_Angle / m_IndicesCount;

            // create a line-mesh
            vertices[0] = Vector3.zero;
            for (int i = 1; i < m_IndicesCount + 2; i++)
            {
                rayDirection.x = Mathf.Cos(currentAngle * Mathf.Deg2Rad);
                rayDirection.y = Mathf.Sin(currentAngle * Mathf.Deg2Rad);
                rayDirection.z = 0.0f;
                rayDirection.Normalize();
                rayDirection *= m_Radius;

                vertices[i] = transform.InverseTransformPoint(transform.position + rayDirection);

                currentAngle += angleStep;

                //Debug.DrawLine(transform.position, transform.TransformPoint(vertices[i]), shadowColor);

                if (i < m_IndicesCount + 1)
                {
                    indices[(i - 1) * 3]     = 0;
                    indices[(i - 1) * 3 + 1] = i;
                    indices[(i - 1) * 3 + 2] = i + 1;
                }
            }
            //indices[indicesCount] = 0;

            ShadowMesh.Clear();

            ShadowMesh.vertices  = vertices;
            ShadowMesh.triangles = indices;
            //m_shadowMesh.SetIndices(indices, MeshTopology.Triangles, 0);
            ShadowMesh.RecalculateNormals();
        }
Example #2
0
        public MeshSlot Clone()
        {
            MeshSlot cloneMeshSlot = new MeshSlot();

            if (NormalMesh != null)
            {
                cloneMeshSlot.NormalMesh = NormalMesh.Clone();
            }
            if (ShadowMesh != null)
            {
                cloneMeshSlot.ShadowMesh = ShadowMesh.Clone();
            }
            cloneMeshSlot.PS0Texture  = PS0Texture;
            cloneMeshSlot.PS1Texture  = PS1Texture;
            cloneMeshSlot.PS2Texture  = PS2Texture;
            cloneMeshSlot.PSCB2Buffer = PSCB2Buffer;

            return(cloneMeshSlot);
        }