Example #1
0
 // Token: 0x0600418E RID: 16782 RVA: 0x0014B334 File Offset: 0x00149734
 public int Hash(CSGVertex p)
 {
     for (int i = 0; i < this.count; i++)
     {
         CSGVertex csgvertex = this.buckets[i];
         float     num       = p.P.x - csgvertex.P.x;
         float     num2      = p.P.y - csgvertex.P.y;
         float     num3      = p.P.z - csgvertex.P.z;
         float     num4      = num * num + num2 * num2 + num3 * num3;
         if (num4 < this.bucketSize2)
         {
             num  = p.N.x - csgvertex.N.x;
             num2 = p.N.y - csgvertex.N.y;
             num3 = p.N.z - csgvertex.N.z;
             num4 = num * num + num2 * num2 + num3 * num3;
             if (num4 < this.bucketSize2)
             {
                 num  = p.UV.x - csgvertex.UV.x;
                 num2 = p.UV.y - csgvertex.UV.y;
                 num4 = num * num + num2 * num2;
                 if (num4 < this.bucketSize2)
                 {
                     return(i);
                 }
             }
         }
     }
     this.buckets[this.count++] = p;
     return(this.count - 1);
 }
Example #2
0
        // Token: 0x06004171 RID: 16753 RVA: 0x0014A704 File Offset: 0x00148B04
        private int AddVertex(CSGVertex v0, List <Vector3> vertices, List <Vector3> normals, List <Vector2> uvs, Dictionary <int, int> cache, VertexHash hash)
        {
            int key = hash.Hash(v0);
            int result;

            if (cache.TryGetValue(key, out result))
            {
                return(result);
            }
            vertices.Add(v0.P);
            normals.Add(v0.N);
            uvs.Add(v0.UV);
            int num = vertices.Count - 1;

            cache.Add(key, num);
            return(num);
        }
Example #3
0
        /// <summary>
        /// helper for caching duplicated vertices
        /// </summary>
        private int AddVertex(CSGVertex v0, List <Vector3> vertices, List <Vector3> normals, List <Vector2> uvs, Dictionary <int, int> cache, VertexHash hash)
        {
            var h = hash.Hash(v0);

            int value;

            if (cache.TryGetValue(h, out value))
            {
                return(value);
            }

            vertices.Add(v0.P);
            normals.Add(v0.N);
            uvs.Add(v0.UV);

            var id = vertices.Count - 1;

            cache.Add(h, id);

            return(id);
        }
Example #4
0
        /// <summary>
        /// split polygon by plane and push the results to polygon lists
        /// </summary>
        /// <param name="polygon">polygon to split</param>
        /// <param name="coplanarFront">list of coplanar polygons in front plane</param>
        /// <param name="coplanarBack">list of coplanar polygons in back plane</param>
        /// <param name="front">list of polygons in front plane</param>
        /// <param name="back">list of polygons in back plane</param>
        public void Split(CSGPolygon polygon, List<CSGPolygon> coplanarFront, List<CSGPolygon> coplanarBack, List<CSGPolygon> front, List<CSGPolygon> back)
        {
            var verticesCount = polygon.Vertices.Count;

            var classes = new Plane.PointClass[verticesCount];
            var polygonClass = Plane.PointClass.Coplanar;

            for (int i = 0; i < verticesCount; i++)
            {
                var t = Vector3.Dot(Normal, polygon.Vertices[i].P) - Distance;
                var type = (t < -epsylon
                                ? Plane.PointClass.Back
                                : (t > epsylon ? Plane.PointClass.Front : Plane.PointClass.Coplanar));
                //classes[i] = ClassifyPoint(polygon.Vertices[i].P);

                polygonClass |= type; //classes[i];
                classes[i] = type;
            }

            switch (polygonClass)
            {
                case Plane.PointClass.Coplanar:
                    {
                        if (Vector3.Dot(Normal, polygon.Plane.Normal) > 0)
                        {
                            coplanarFront.Add(polygon);
                        }
                        else
                        {
                            coplanarBack.Add(polygon);
                        }
                    }
                    break;

                case Plane.PointClass.Front:
                    {
                        front.Add(polygon);
                    }
                    break;

                case Plane.PointClass.Back:
                    {
                        back.Add(polygon);
                    }
                    break;

                case Plane.PointClass.Intersection:
                    {
                        var frontList = new List<CSGVertex>(4);
                        var backList = new List<CSGVertex>(4);

                        for (int i = 0; i < verticesCount; i++)
                        {
                            var j = (i + 1) % verticesCount;

                            var class0 = classes[i];
                            var class1 = classes[j];

                            var v0 = polygon.Vertices[i];
                            var v1 = polygon.Vertices[j];

                            if (class0 != Plane.PointClass.Back)
                            {
                                frontList.Add(v0);
                            }

                            if (class0 != Plane.PointClass.Front)
                            {
                                backList.Add(class0 != Plane.PointClass.Back ? new CSGVertex(v0) : v0);
                            }

                            if ((class0 | class1) == Plane.PointClass.Intersection)
                            {
                                var q = new CSGVertex(polygon.Vertices[0]);

                                // find intersection point
                                //IntersectSegment(v0.P, v1.P, out t, out q.P);
                                var t = (this.Distance - Vector3.Dot(this.Normal, v0.P)) / Vector3.Dot(this.Normal, v1.P - v0.P);

                                // interpolate
                                q.P = Vector3.Lerp(v0.P, v1.P, t);
                                q.N = Vector3.Lerp(v0.N, v1.N, t);
                                q.UV = Vector2.Lerp(v0.UV, v1.UV, t);

                                frontList.Add(q);
                                backList.Add(new CSGVertex(q));
                            }
                        }

                        if (frontList.Count >= 3)
                        {
                            front.Add(new CSGPolygon(polygon.Id, frontList));
                        }

                        if (backList.Count >= 3)
                        {
                            back.Add(new CSGPolygon(polygon.Id, backList));
                        }
                    }
                    break;
            }
        }
Example #5
0
 // Token: 0x0600418B RID: 16779 RVA: 0x0014B2D1 File Offset: 0x001496D1
 public CSGVertex(CSGVertex v)
 {
     this.P  = v.P;
     this.N  = v.N;
     this.UV = v.UV;
 }
        /// <summary>
        /// split polygon by plane and push the results to polygon lists
        /// </summary>
        /// <param name="polygon">polygon to split</param>
        /// <param name="coplanarFront">list of coplanar polygons in front plane</param>
        /// <param name="coplanarBack">list of coplanar polygons in back plane</param>
        /// <param name="front">list of polygons in front plane</param>
        /// <param name="back">list of polygons in back plane</param>
        public void Split(CSGPolygon polygon, List <CSGPolygon> coplanarFront, List <CSGPolygon> coplanarBack, List <CSGPolygon> front, List <CSGPolygon> back)
        {
            var verticesCount = polygon.Vertices.Count;

            var classes      = new Plane.PointClass[verticesCount];
            var polygonClass = Plane.PointClass.Coplanar;

            for (int i = 0; i < verticesCount; i++)
            {
                var t    = Vector3.Dot(Normal, polygon.Vertices[i].P) - Distance;
                var type = (t < -epsylon
                                ? Plane.PointClass.Back
                                : (t > epsylon ? Plane.PointClass.Front : Plane.PointClass.Coplanar));
                //classes[i] = ClassifyPoint(polygon.Vertices[i].P);

                polygonClass |= type; //classes[i];
                classes[i]    = type;
            }

            switch (polygonClass)
            {
            case Plane.PointClass.Coplanar:
            {
                if (Vector3.Dot(Normal, polygon.Plane.Normal) > 0)
                {
                    coplanarFront.Add(polygon);
                }
                else
                {
                    coplanarBack.Add(polygon);
                }
            }
            break;

            case Plane.PointClass.Front:
            {
                front.Add(polygon);
            }
            break;

            case Plane.PointClass.Back:
            {
                back.Add(polygon);
            }
            break;

            case Plane.PointClass.Intersection:
            {
                var frontList = new List <CSGVertex>(4);
                var backList  = new List <CSGVertex>(4);

                for (int i = 0; i < verticesCount; i++)
                {
                    var j = (i + 1) % verticesCount;

                    var class0 = classes[i];
                    var class1 = classes[j];

                    var v0 = polygon.Vertices[i];
                    var v1 = polygon.Vertices[j];

                    if (class0 != Plane.PointClass.Back)
                    {
                        frontList.Add(v0);
                    }

                    if (class0 != Plane.PointClass.Front)
                    {
                        backList.Add(class0 != Plane.PointClass.Back ? new CSGVertex(v0) : v0);
                    }

                    if ((class0 | class1) == Plane.PointClass.Intersection)
                    {
                        var q = new CSGVertex(polygon.Vertices[0]);

                        // find intersection point
                        //IntersectSegment(v0.P, v1.P, out t, out q.P);
                        var t = (this.Distance - Vector3.Dot(this.Normal, v0.P)) / Vector3.Dot(this.Normal, v1.P - v0.P);

                        // interpolate
                        q.P  = Vector3.Lerp(v0.P, v1.P, t);
                        q.N  = Vector3.Lerp(v0.N, v1.N, t);
                        q.UV = Vector2.Lerp(v0.UV, v1.UV, t);

                        frontList.Add(q);
                        backList.Add(new CSGVertex(q));
                    }
                }

                if (frontList.Count >= 3)
                {
                    front.Add(new CSGPolygon(polygon.Id, frontList));
                }

                if (backList.Count >= 3)
                {
                    back.Add(new CSGPolygon(polygon.Id, backList));
                }
            }
            break;
            }
        }
Example #7
0
 /// <summary>
 /// copy constructor
 /// </summary>
 public CSGVertex(CSGVertex v)
 {
     P  = v.P;
     N  = v.N;
     UV = v.UV;
 }
Example #8
0
        /// <summary>
        /// helper for caching duplicated vertices
        /// </summary>
        int AddVertex(CSGVertex v0, List<Vector3> vertices, List<Vector3> normals, List<Vector2> uvs, Dictionary<int, int> cache, VertexHash hash)
        {
            var h = hash.Hash(v0);

            int value;
            if (cache.TryGetValue(h, out value))
            {
                return value;
            }

            vertices.Add(v0.P);
            normals.Add(v0.N);
            uvs.Add(v0.UV);

            var id = vertices.Count - 1;

            cache.Add(h, id);

            return id;
        }
Example #9
0
 /// <summary>
 /// copy constructor
 /// </summary>
 public CSGVertex(CSGVertex v)
 {
     P = v.P;
     N = v.N;
     UV = v.UV;
 }
Example #10
0
        // Token: 0x06004185 RID: 16773 RVA: 0x0014AE8C File Offset: 0x0014928C
        public void Split(CSGPolygon polygon, List <CSGPolygon> coplanarFront, List <CSGPolygon> coplanarBack, List <CSGPolygon> front, List <CSGPolygon> back)
        {
            int count = polygon.Vertices.Count;

            PrimitivesPro.Utils.Plane.PointClass[] array      = new PrimitivesPro.Utils.Plane.PointClass[count];
            PrimitivesPro.Utils.Plane.PointClass   pointClass = PrimitivesPro.Utils.Plane.PointClass.Coplanar;
            for (int i = 0; i < count; i++)
            {
                float num = Vector3.Dot(this.Normal, polygon.Vertices[i].P) - this.Distance;
                PrimitivesPro.Utils.Plane.PointClass pointClass2 = (num >= -1E-06f) ? ((num <= 1E-06f) ? PrimitivesPro.Utils.Plane.PointClass.Coplanar : PrimitivesPro.Utils.Plane.PointClass.Front) : PrimitivesPro.Utils.Plane.PointClass.Back;
                pointClass |= pointClass2;
                array[i]    = pointClass2;
            }
            switch (pointClass)
            {
            case PrimitivesPro.Utils.Plane.PointClass.Coplanar:
                if (Vector3.Dot(this.Normal, polygon.Plane.Normal) > 0f)
                {
                    coplanarFront.Add(polygon);
                }
                else
                {
                    coplanarBack.Add(polygon);
                }
                break;

            case PrimitivesPro.Utils.Plane.PointClass.Front:
                front.Add(polygon);
                break;

            case PrimitivesPro.Utils.Plane.PointClass.Back:
                back.Add(polygon);
                break;

            case PrimitivesPro.Utils.Plane.PointClass.Intersection:
            {
                List <CSGVertex> list  = new List <CSGVertex>(4);
                List <CSGVertex> list2 = new List <CSGVertex>(4);
                for (int j = 0; j < count; j++)
                {
                    int num2 = (j + 1) % count;
                    PrimitivesPro.Utils.Plane.PointClass pointClass3 = array[j];
                    PrimitivesPro.Utils.Plane.PointClass pointClass4 = array[num2];
                    CSGVertex csgvertex  = polygon.Vertices[j];
                    CSGVertex csgvertex2 = polygon.Vertices[num2];
                    if (pointClass3 != PrimitivesPro.Utils.Plane.PointClass.Back)
                    {
                        list.Add(csgvertex);
                    }
                    if (pointClass3 != PrimitivesPro.Utils.Plane.PointClass.Front)
                    {
                        list2.Add((pointClass3 == PrimitivesPro.Utils.Plane.PointClass.Back) ? csgvertex : new CSGVertex(csgvertex));
                    }
                    if ((pointClass3 | pointClass4) == PrimitivesPro.Utils.Plane.PointClass.Intersection)
                    {
                        CSGVertex csgvertex3 = new CSGVertex(polygon.Vertices[0]);
                        float     t          = (this.Distance - Vector3.Dot(this.Normal, csgvertex.P)) / Vector3.Dot(this.Normal, csgvertex2.P - csgvertex.P);
                        csgvertex3.P  = Vector3.Lerp(csgvertex.P, csgvertex2.P, t);
                        csgvertex3.N  = Vector3.Lerp(csgvertex.N, csgvertex2.N, t);
                        csgvertex3.UV = Vector2.Lerp(csgvertex.UV, csgvertex2.UV, t);
                        list.Add(csgvertex3);
                        list2.Add(new CSGVertex(csgvertex3));
                    }
                }
                if (list.Count >= 3)
                {
                    front.Add(new CSGPolygon(polygon.Id, list));
                }
                if (list2.Count >= 3)
                {
                    back.Add(new CSGPolygon(polygon.Id, list2));
                }
                break;
            }
            }
        }