Beispiel #1
0
        public Slice(TriangleMesh mesh, Plane plane)
        {
            //GL.Disable(EnableCap.Lighting);
            //GL.LineWidth(2);
            //GL.Begin(PrimitiveType.Lines);
            //float height = 0;

            // Slice at 3 levels and combine all segments - this obviates dealing with triangles that are exactly on the plane.
            for (int i = -1; i <= 1; i++)
            {
                Vector3 offset = plane.Normal * 0.0001f * (float)i;
                LineHandler lineHandler = new LineHandler(0.0f);
                Plane testPlane = new Plane(plane.Normal, plane.Point + offset);
                foreach (Triangle t in mesh.Triangles)
                {
                    var intersect = new TrianglePlaneIntersect(t, testPlane);
                    if (intersect.Intersects)
                    {
                        lineHandler.AddSegment(intersect.PointA, intersect.PointB);
                        //GL.Color3(Color.Blue);
                        //GL.Vertex3(intersect.PointA + new Vector3(0, 0, height + .01f));
                        //GL.Color3(Color.Red);
                        //GL.Vertex3(intersect.PointB + new Vector3(0, 0, height + .01f));
                    }
                    else if (intersect.all_intersect && Vector3.Dot(t.Plane.Normal, testPlane.Normal) > 0.5f)
                    {
                        // Entire triangle intersects
                        // Add all the triangle edges (TODO: clean this up...)
                        List<Vector3> vertices = new List<Vector3>(t.Vertices);
                        for (int a = 0; a < 3; a++)
                        {
                            Vector3 v1 = vertices[a];
                            Vector3 v2 = vertices[(a + 1) % 3];
                            lineHandler.AddSegment(v1, v2);
                        }
                    }
                }
                if (this.polyTree == null)
                {
                    Init(lineHandler.GetOuterLoops(), plane);
                }
                else
                {
                    Slice s = new Slice(lineHandler.GetOuterLoops(), plane);
                    this.Union(s);
                }
            }
            //GL.End();
            //GL.Enable(EnableCap.Lighting);
            //GL.LineWidth(1);
        }
Beispiel #2
0
        public Slice(TriangleMesh mesh, Plane plane)
        {
            //GL.Disable(EnableCap.Lighting);
            //GL.LineWidth(2);
            //GL.Begin(PrimitiveType.Lines);
            //float height = 0;

            // Slice at 3 levels and combine all segments - this obviates dealing with triangles that are exactly on the plane.
            for (int i = -1; i <= 1; i++)
            {
                Vector3     offset      = plane.Normal * 0.0001f * (float)i;
                LineHandler lineHandler = new LineHandler(0.0f);
                Plane       testPlane   = new Plane(plane.Normal, plane.Point + offset);
                foreach (Triangle t in mesh.Triangles)
                {
                    var intersect = new TrianglePlaneIntersect(t, testPlane);
                    if (intersect.Intersects)
                    {
                        lineHandler.AddSegment(intersect.PointA, intersect.PointB);
                        //GL.Color3(Color.Blue);
                        //GL.Vertex3(intersect.PointA + new Vector3(0, 0, height + .01f));
                        //GL.Color3(Color.Red);
                        //GL.Vertex3(intersect.PointB + new Vector3(0, 0, height + .01f));
                    }
                    else if (intersect.all_intersect && Vector3.Dot(t.Plane.Normal, testPlane.Normal) > 0.5f)
                    {
                        // Entire triangle intersects
                        // Add all the triangle edges (TODO: clean this up...)
                        List <Vector3> vertices = new List <Vector3>(t.Vertices);
                        for (int a = 0; a < 3; a++)
                        {
                            Vector3 v1 = vertices[a];
                            Vector3 v2 = vertices[(a + 1) % 3];
                            lineHandler.AddSegment(v1, v2);
                        }
                    }
                }
                if (this.polyTree == null)
                {
                    Init(lineHandler.GetOuterLoops(), plane);
                }
                else
                {
                    Slice s = new Slice(lineHandler.GetOuterLoops(), plane);
                    this.Union(s);
                }
            }
            //GL.End();
            //GL.Enable(EnableCap.Lighting);
            //GL.LineWidth(1);
        }