Example #1
0
        internal void PlaneDecalsMeshCutter(DM a_DecalsMesh, Plane a_Plane)
        {
            this.m_RelativeVertexLocations.Clear();
            this.m_ObsoleteTriangleIndices.Clear();
            this.m_CutEdges.Clear();
            this.m_RemovedIndices.Clear();
            int     decalsMeshLowerVertexIndex = this.m_ActiveProjector.DecalsMeshLowerVertexIndex;
            int     decalsMeshUpperVertexIndex = this.m_ActiveProjector.DecalsMeshUpperVertexIndex;
            int     num3   = decalsMeshLowerVertexIndex;
            Vector3 vector = this.PlaneOrigin(a_Plane);
            Vector3 normal = a_Plane.normal;

            for (int i = decalsMeshLowerVertexIndex; i <= decalsMeshUpperVertexIndex; i++)
            {
                Vector3 vector3             = a_DecalsMesh.Vertices[i];
                RelativeVertexLocation item = this.VertexLocationRelativeToPlane(vector, normal, vector3);
                this.m_RelativeVertexLocations.Add(item);
            }
            int count = a_DecalsMesh.Triangles.Count;
            int decalsMeshLowerTriangleIndex = this.m_ActiveProjector.DecalsMeshLowerTriangleIndex;

            for (int j = decalsMeshLowerTriangleIndex; j < count; j += 3)
            {
                int num8  = a_DecalsMesh.Triangles[j];
                int num9  = a_DecalsMesh.Triangles[j + 1];
                int num10 = a_DecalsMesh.Triangles[j + 2];
                RelativeVertexLocation location2 = this.m_RelativeVertexLocations[num8 - num3];
                RelativeVertexLocation location3 = this.m_RelativeVertexLocations[num9 - num3];
                RelativeVertexLocation location4 = this.m_RelativeVertexLocations[num10 - num3];
                if ((location2 != RelativeVertexLocation.Inside) && ((location3 != RelativeVertexLocation.Inside) && (location4 != RelativeVertexLocation.Inside)))
                {
                    this.m_ObsoleteTriangleIndices.Add(j);
                }
                else
                {
                    Vector3 vector4 = a_DecalsMesh.Vertices[num8];
                    Vector3 vector5 = a_DecalsMesh.Vertices[num9];
                    Vector3 vector6 = a_DecalsMesh.Vertices[num10];
                    bool    flag    = this.Intersect(location2, location3);
                    bool    flag2   = this.Intersect(location2, location4);
                    bool    flag3   = this.Intersect(location3, location4);
                    int     item    = 0;
                    int     num12   = 0;
                    int     num13   = 0;
                    if (flag)
                    {
                        DecalRay ray   = new DecalRay(vector4, vector5 - vector4);
                        float    num14 = this.IntersectionFactor(ray, a_Plane);
                        item = this.m_GetCutEdgeDelegate(num3, num8, num9, vector4, vector5, location2 == RelativeVertexLocation.Inside, num14);
                    }
                    if (flag2)
                    {
                        DecalRay ray2  = new DecalRay(vector4, vector6 - vector4);
                        float    num15 = this.IntersectionFactor(ray2, a_Plane);
                        num12 = this.m_GetCutEdgeDelegate(num3, num8, num10, vector4, vector6, location2 == RelativeVertexLocation.Inside, num15);
                    }
                    if (flag3)
                    {
                        DecalRay ray3  = new DecalRay(vector5, vector6 - vector5);
                        float    num16 = this.IntersectionFactor(ray3, a_Plane);
                        num13 = this.m_GetCutEdgeDelegate(num3, num9, num10, vector5, vector6, location3 == RelativeVertexLocation.Inside, num16);
                    }
                    if (flag && flag2)
                    {
                        if (location2 == RelativeVertexLocation.Inside)
                        {
                            a_DecalsMesh.Triangles[j + 1] = item;
                            a_DecalsMesh.Triangles[j + 2] = num12;
                        }
                        else
                        {
                            a_DecalsMesh.Triangles[j] = item;
                            a_DecalsMesh.Triangles.Add(num10);
                            a_DecalsMesh.Triangles.Add(num12);
                            a_DecalsMesh.Triangles.Add(item);
                        }
                    }
                    else if (flag && flag3)
                    {
                        if (location3 == RelativeVertexLocation.Inside)
                        {
                            a_DecalsMesh.Triangles[j]     = item;
                            a_DecalsMesh.Triangles[j + 2] = num13;
                        }
                        else
                        {
                            a_DecalsMesh.Triangles[j + 1] = item;
                            a_DecalsMesh.Triangles.Add(num10);
                            a_DecalsMesh.Triangles.Add(item);
                            a_DecalsMesh.Triangles.Add(num13);
                        }
                    }
                    else if (flag2 && flag3)
                    {
                        if (location4 == RelativeVertexLocation.Inside)
                        {
                            a_DecalsMesh.Triangles[j]     = num12;
                            a_DecalsMesh.Triangles[j + 1] = num13;
                        }
                        else
                        {
                            a_DecalsMesh.Triangles[j + 2] = num12;
                            a_DecalsMesh.Triangles.Add(num9);
                            a_DecalsMesh.Triangles.Add(num13);
                            a_DecalsMesh.Triangles.Add(num12);
                        }
                    }
                    else if (flag && (location4 == RelativeVertexLocation.OnPlane))
                    {
                        if (location2 == RelativeVertexLocation.Inside)
                        {
                            a_DecalsMesh.Triangles[j + 1] = item;
                        }
                        else
                        {
                            a_DecalsMesh.Triangles[j] = item;
                        }
                    }
                    else if (flag2 && (location3 == RelativeVertexLocation.OnPlane))
                    {
                        if (location2 == RelativeVertexLocation.Inside)
                        {
                            a_DecalsMesh.Triangles[j + 2] = num12;
                        }
                        else
                        {
                            a_DecalsMesh.Triangles[j] = num12;
                        }
                    }
                    else if (flag3 && (location2 == RelativeVertexLocation.OnPlane))
                    {
                        if (location3 == RelativeVertexLocation.Inside)
                        {
                            a_DecalsMesh.Triangles[j + 2] = num13;
                        }
                        else
                        {
                            a_DecalsMesh.Triangles[j + 1] = num13;
                        }
                    }
                }
            }
            int num17 = this.m_ObsoleteTriangleIndices.Count - 1;

            while (num17 >= 0)
            {
                int num18 = this.m_ObsoleteTriangleIndices[num17];
                int num19 = 1;
                while (true)
                {
                    if ((num17 <= 0) || ((num18 - 3) != this.m_ObsoleteTriangleIndices[num17 - 1]))
                    {
                        a_DecalsMesh.RemoveTrianglesAt(num18, num19);
                        num17--;
                        break;
                    }
                    num18 -= 3;
                    num19++;
                    num17--;
                }
            }
            for (int k = 0; k < this.m_RelativeVertexLocations.Count; k++)
            {
                if (((RelativeVertexLocation)this.m_RelativeVertexLocations[k]) == RelativeVertexLocation.Outside)
                {
                    this.m_RemovedIndices.AddRemovedIndex(k + num3);
                }
            }
            a_DecalsMesh.RemoveAndAdjustIndices(decalsMeshLowerTriangleIndex, this.m_RemovedIndices);
            this.m_ActiveProjector.IsUV1ProjectionCalculated     = false;
            this.m_ActiveProjector.IsUV2ProjectionCalculated     = false;
            this.m_ActiveProjector.IsTangentProjectionCalculated = false;
        }
Example #2
0
 private float IntersectionFactor(DecalRay a_Ray, Plane a_Plane) =>
 (a_Plane.distance - Vector3.Dot(a_Plane.normal, a_Ray.origin)) / Vector3.Dot(a_Plane.normal, a_Ray.direction);