private void CalculateProjectedTangents(GenericDecalProjectorBase a_Projector)
        {
            while (base.m_Tangents.Count < a_Projector.DecalsMeshLowerVertexIndex)
            {
                base.m_Tangents.Add(Vector4.zero);
            }
            Matrix4x4 transpose = (a_Projector.WorldToProjectorMatrix * this.m_Decals.CachedTransform.localToWorldMatrix).inverse.transpose;
            Matrix4x4 matrixx4  = (this.m_Decals.CachedTransform.worldToLocalMatrix * a_Projector.ProjectorToWorldMatrix).inverse.transpose;

            for (int i = a_Projector.DecalsMeshLowerVertexIndex; i <= a_Projector.DecalsMeshUpperVertexIndex; i++)
            {
                Vector3 v = transpose.MultiplyVector(base.Normals[i]);
                v.z = 0f;
                if (Mathf.Approximately(v.x, 0f) && Mathf.Approximately(v.y, 0f))
                {
                    v = new Vector3(0f, 1f, 0f);
                }
                v = new Vector3(v.y, -v.x, v.z);
                v = matrixx4.MultiplyVector(v);
                v.Normalize();
                Vector4 item = new Vector4(v.x, v.y, v.z, -1f);
                if (i < base.m_Tangents.Count)
                {
                    base.m_Tangents[i] = item;
                }
                else
                {
                    base.m_Tangents.Add(item);
                }
            }
        }
        private void CalculateProjectedUV2(GenericDecalProjectorBase a_Projector)
        {
            Matrix4x4      matrixx   = a_Projector.WorldToProjectorMatrix * this.m_Decals.CachedTransform.localToWorldMatrix;
            UVRectangle    rectangle = this.m_Decals.CurrentUv2Rectangles[a_Projector.UV2RectangleIndex];
            List <Vector2> list      = base.m_UV2s;
            int            decalsMeshLowerVertexIndex = a_Projector.DecalsMeshLowerVertexIndex;
            int            decalsMeshUpperVertexIndex = a_Projector.DecalsMeshUpperVertexIndex;

            if (this.m_Decals.CurrentUVMode == UVMode.Project)
            {
                this.CalculateProjectedUV(matrixx, rectangle, list, decalsMeshLowerVertexIndex, decalsMeshUpperVertexIndex);
            }
            else
            {
                this.CalculateWrappedProjectionUV(matrixx, rectangle, list, decalsMeshLowerVertexIndex, decalsMeshUpperVertexIndex);
            }
            a_Projector.IsUV2ProjectionCalculated = true;
        }
Example #3
0
        private void ApplyToSkinnedDecalsMeshRenderer(SkinnedDecalsMeshRenderer a_SkinnedDecalsMeshRenderer, SkinnedDecalsMesh a_SkinnedDecalsMesh, GenericDecalProjectorBase a_FirstProjector, GenericDecalProjectorBase a_LastProjector)
        {
            int  decalsMeshLowerVertexIndex   = a_FirstProjector.DecalsMeshLowerVertexIndex;
            int  decalsMeshUpperVertexIndex   = a_LastProjector.DecalsMeshUpperVertexIndex;
            int  decalsMeshLowerTriangleIndex = a_FirstProjector.DecalsMeshLowerTriangleIndex;
            int  decalsMeshUpperTriangleIndex = a_LastProjector.DecalsMeshUpperTriangleIndex;
            Mesh mesh = this.MeshOfSkinnedDecalsMeshRenderer(a_SkinnedDecalsMeshRenderer);

            mesh.Clear();
            if (!Edition.IsDX11)
            {
                mesh.MarkDynamic();
            }
            Vector3[] vectorArray = new Vector3[(decalsMeshUpperVertexIndex - decalsMeshLowerVertexIndex) + 1];
            CopyListRangeToArray <Vector3>(ref vectorArray, a_SkinnedDecalsMesh.OriginalVertices, decalsMeshLowerVertexIndex, decalsMeshUpperVertexIndex);
            mesh.vertices = vectorArray;
            BoneWeight[] weightArray = new BoneWeight[(decalsMeshUpperVertexIndex - decalsMeshLowerVertexIndex) + 1];
            CopyListRangeToArray <BoneWeight>(ref weightArray, a_SkinnedDecalsMesh.BoneWeights, decalsMeshLowerVertexIndex, decalsMeshUpperVertexIndex);
            mesh.boneWeights = weightArray;
            int[] numArray = new int[(decalsMeshUpperTriangleIndex - decalsMeshLowerTriangleIndex) + 1];
            CopyListRangeToArray <int>(ref numArray, a_SkinnedDecalsMesh.Triangles, decalsMeshLowerTriangleIndex, decalsMeshUpperTriangleIndex);
            for (int i = 0; i < numArray.Length; i++)
            {
                numArray[i] -= decalsMeshLowerVertexIndex;
            }
            mesh.triangles = numArray;
            Vector2[] vectorArray2 = new Vector2[(decalsMeshUpperVertexIndex - decalsMeshLowerVertexIndex) + 1];
            CopyListRangeToArray <Vector2>(ref vectorArray2, a_SkinnedDecalsMesh.UVs, decalsMeshLowerVertexIndex, decalsMeshUpperVertexIndex);
            if (a_SkinnedDecalsMesh.PreserveProjectedUVArrays)
            {
                a_SkinnedDecalsMesh.PreservedProjectedUVArrays.Add(vectorArray2);
            }
            mesh.uv = vectorArray2;
            if ((base.CurrentUV2Mode == UV2Mode.None) || (base.CurrentUV2Mode == UV2Mode.Lightmapping))
            {
                mesh.uv2 = null;
            }
            else
            {
                Vector2[] vectorArray3 = new Vector2[(decalsMeshUpperVertexIndex - decalsMeshLowerVertexIndex) + 1];
                CopyListRangeToArray <Vector2>(ref vectorArray3, a_SkinnedDecalsMesh.UV2s, decalsMeshLowerVertexIndex, decalsMeshUpperVertexIndex);
                if (a_SkinnedDecalsMesh.PreserveProjectedUV2Arrays)
                {
                    a_SkinnedDecalsMesh.PreservedProjectedUV2Arrays.Add(vectorArray3);
                }
                mesh.uv2 = vectorArray3;
            }
            if (base.CurrentNormalsMode == NormalsMode.None)
            {
                mesh.normals = null;
            }
            else
            {
                Vector3[] vectorArray4 = new Vector3[(decalsMeshUpperVertexIndex - decalsMeshLowerVertexIndex) + 1];
                CopyListRangeToArray <Vector3>(ref vectorArray4, a_SkinnedDecalsMesh.Normals, decalsMeshLowerVertexIndex, decalsMeshUpperVertexIndex);
                mesh.normals = vectorArray4;
            }
            if (base.CurrentTangentsMode == TangentsMode.None)
            {
                mesh.tangents = null;
            }
            else
            {
                Vector4[] vectorArray5 = new Vector4[(decalsMeshUpperVertexIndex - decalsMeshLowerVertexIndex) + 1];
                CopyListRangeToArray <Vector4>(ref vectorArray5, a_SkinnedDecalsMesh.Tangents, decalsMeshLowerVertexIndex, decalsMeshUpperVertexIndex);
                mesh.tangents = vectorArray5;
            }
            if (!base.UseVertexColors)
            {
                mesh.colors = null;
            }
            else
            {
                Color[] colorArray = new Color[(decalsMeshUpperVertexIndex - decalsMeshLowerVertexIndex) + 1];
                CopyListRangeToArray <Color>(ref colorArray, a_SkinnedDecalsMesh.VertexColors, decalsMeshLowerVertexIndex, decalsMeshUpperVertexIndex);
                if (a_SkinnedDecalsMesh.PreserveVertexColorArrays)
                {
                    a_SkinnedDecalsMesh.PreservedVertexColorArrays.Add(colorArray);
                }
                mesh.colors = colorArray;
            }
            mesh.bindposes = a_SkinnedDecalsMesh.BindPoses.ToArray();
            Transform[] transformArray = a_SkinnedDecalsMesh.Bones.ToArray();
            a_SkinnedDecalsMeshRenderer.SkinnedMeshRenderer.bones               = transformArray;
            a_SkinnedDecalsMeshRenderer.SkinnedMeshRenderer.localBounds         = mesh.bounds;
            a_SkinnedDecalsMeshRenderer.SkinnedMeshRenderer.updateWhenOffscreen = true;
        }
Example #4
0
 public override void UpdateDecalsMeshes(SkinnedDecalsMesh a_DecalsMesh)
 {
     base.UpdateDecalsMeshes(a_DecalsMesh);
     if (a_DecalsMesh.Vertices.Count <= 0xffff)
     {
         if (this.m_SkinnedDecalsMeshRenderers.Count == 0)
         {
             this.PushSkinnedDecalsMeshRenderer();
         }
         else if (this.m_SkinnedDecalsMeshRenderers.Count > 1)
         {
             while (this.m_SkinnedDecalsMeshRenderers.Count > 1)
             {
                 this.PopSkinnedDecalsMeshRenderer();
             }
         }
         SkinnedDecalsMeshRenderer renderer = this.m_SkinnedDecalsMeshRenderers[0];
         this.ApplyToSkinnedDecalsMeshRenderer(renderer, a_DecalsMesh);
     }
     else
     {
         int num  = 0;
         int num2 = 0;
         while (true)
         {
             if (num2 >= a_DecalsMesh.Projectors.Count)
             {
                 while ((num + 1) < this.m_SkinnedDecalsMeshRenderers.Count)
                 {
                     this.PopSkinnedDecalsMeshRenderer();
                 }
                 break;
             }
             GenericDecalProjectorBase base2 = a_DecalsMesh.Projectors[num2];
             GenericDecalProjectorBase base3 = a_DecalsMesh.Projectors[num2];
             if (num >= this.m_SkinnedDecalsMeshRenderers.Count)
             {
                 this.PushSkinnedDecalsMeshRenderer();
             }
             SkinnedDecalsMeshRenderer renderer2 = this.m_SkinnedDecalsMeshRenderers[num];
             int num3 = 0;
             int num4 = num2;
             GenericDecalProjectorBase base4 = a_DecalsMesh.Projectors[num2];
             while (true)
             {
                 if ((num2 >= a_DecalsMesh.Projectors.Count) || ((num3 + base4.DecalsMeshVertexCount) > 0xffff))
                 {
                     if (num4 != num2)
                     {
                         this.ApplyToSkinnedDecalsMeshRenderer(renderer2, a_DecalsMesh, base2, base3);
                         num++;
                     }
                     num2++;
                     break;
                 }
                 base3 = base4;
                 num3 += base4.DecalsMeshVertexCount;
                 num2++;
                 if (num2 < a_DecalsMesh.Projectors.Count)
                 {
                     base4 = a_DecalsMesh.Projectors[num2];
                 }
             }
         }
     }
     base.SetDecalsMeshesAreNotOptimized();
 }
Example #5
0
        private void ApplyToDecalsMeshRenderer(DecalsMeshRenderer a_DecalsMeshRenderer, DecalsMesh a_DecalsMesh, GenericDecalProjectorBase a_FirstProjector, GenericDecalProjectorBase a_LastProjector)
        {
            int  decalsMeshLowerVertexIndex   = a_FirstProjector.DecalsMeshLowerVertexIndex;
            int  decalsMeshUpperVertexIndex   = a_LastProjector.DecalsMeshUpperVertexIndex;
            int  decalsMeshLowerTriangleIndex = a_FirstProjector.DecalsMeshLowerTriangleIndex;
            int  decalsMeshUpperTriangleIndex = a_LastProjector.DecalsMeshUpperTriangleIndex;
            Mesh mesh = this.MeshOfDecalsMeshRenderer(a_DecalsMeshRenderer);

            mesh.Clear();
            if (!Edition.IsDX11)
            {
                mesh.MarkDynamic();
            }
            Vector3[] vectorArray = new Vector3[(decalsMeshUpperVertexIndex - decalsMeshLowerVertexIndex) + 1];
            CopyListRangeToArray <Vector3>(ref vectorArray, a_DecalsMesh.Vertices, decalsMeshLowerVertexIndex, decalsMeshUpperVertexIndex);
            mesh.vertices = vectorArray;
            int[] numArray = new int[(decalsMeshUpperTriangleIndex - decalsMeshLowerTriangleIndex) + 1];
            CopyListRangeToArray <int>(ref numArray, a_DecalsMesh.Triangles, decalsMeshLowerTriangleIndex, decalsMeshUpperTriangleIndex);
            for (int i = 0; i < numArray.Length; i++)
            {
                numArray[i] -= decalsMeshLowerVertexIndex;
            }
            mesh.triangles = numArray;
            Vector2[] vectorArray2 = new Vector2[(decalsMeshUpperVertexIndex - decalsMeshLowerVertexIndex) + 1];
            CopyListRangeToArray <Vector2>(ref vectorArray2, a_DecalsMesh.UVs, decalsMeshLowerVertexIndex, decalsMeshUpperVertexIndex);
            if (a_DecalsMesh.PreserveProjectedUVArrays)
            {
                a_DecalsMesh.PreservedProjectedUVArrays.Add(vectorArray2);
            }
            mesh.uv = vectorArray2;
            if ((base.CurrentUV2Mode == UV2Mode.None) || (base.CurrentUV2Mode == UV2Mode.Lightmapping))
            {
                mesh.uv2 = null;
            }
            else
            {
                Vector2[] vectorArray3 = new Vector2[(decalsMeshUpperVertexIndex - decalsMeshLowerVertexIndex) + 1];
                CopyListRangeToArray <Vector2>(ref vectorArray3, a_DecalsMesh.UV2s, decalsMeshLowerVertexIndex, decalsMeshUpperVertexIndex);
                if (a_DecalsMesh.PreserveProjectedUV2Arrays)
                {
                    a_DecalsMesh.PreservedProjectedUV2Arrays.Add(vectorArray3);
                }
                mesh.uv2 = vectorArray3;
            }
            if (base.CurrentNormalsMode == NormalsMode.None)
            {
                mesh.normals = null;
            }
            else
            {
                Vector3[] vectorArray4 = new Vector3[(decalsMeshUpperVertexIndex - decalsMeshLowerVertexIndex) + 1];
                CopyListRangeToArray <Vector3>(ref vectorArray4, a_DecalsMesh.Normals, decalsMeshLowerVertexIndex, decalsMeshUpperVertexIndex);
                mesh.normals = vectorArray4;
            }
            if (base.CurrentTangentsMode == TangentsMode.None)
            {
                mesh.tangents = null;
            }
            else
            {
                Vector4[] vectorArray5 = new Vector4[(decalsMeshUpperVertexIndex - decalsMeshLowerVertexIndex) + 1];
                CopyListRangeToArray <Vector4>(ref vectorArray5, a_DecalsMesh.Tangents, decalsMeshLowerVertexIndex, decalsMeshUpperVertexIndex);
                mesh.tangents = vectorArray5;
            }
            if (!base.UseVertexColors)
            {
                mesh.colors = null;
            }
            else
            {
                Color[] colorArray = new Color[(decalsMeshUpperVertexIndex - decalsMeshLowerVertexIndex) + 1];
                CopyListRangeToArray <Color>(ref colorArray, a_DecalsMesh.VertexColors, decalsMeshLowerVertexIndex, decalsMeshUpperVertexIndex);
                if (a_DecalsMesh.PreserveVertexColorArrays)
                {
                    a_DecalsMesh.PreservedVertexColorArrays.Add(colorArray);
                }
                mesh.colors = colorArray;
            }
        }