예제 #1
0
 public ISectData(Object3d o, Polygon p, Point3d isect, Point3d orgin, Vector3d dir)
 {
     intersect = new Point3d();
     intersect.Set(isect);
     origin    = new Point3d();
     direction = new Vector3d();
     origin.Set(orgin);
     direction.Set(dir);
     obj  = o;
     poly = p;
 }
예제 #2
0
        Object3d GetSupportParrent(float x, float y, float z)
        {
            //Object3d obj;
            List <Object3d> matchingObjects = new List <Object3d>();

            foreach (Object3d obj in UVDLPApp.Instance().Engine3D.m_objects)
            {
                if (obj.tag != Object3d.OBJ_NORMAL)
                {
                    continue;
                }
                if ((x > obj.m_min.x) && (x < obj.m_max.x) && (y > obj.m_min.y) && (y < obj.m_max.y))
                {
                    matchingObjects.Add(obj);
                }
            }
            if (matchingObjects.Count == 0)
            {
                return(null); // Should not happen!
            }
            if (matchingObjects.Count == 1)
            {
                return(matchingObjects[0]); // the easy case.
            }
            Point3d origin;

            origin = new Point3d(); // bottom point
            origin.Set(x, y, 0.0f);
            //intersected = false; // reset the intersected flag to be false

            Vector3d up = new Vector3d(); // the up vector

            up.x = 0.0f;
            up.y = 0.0f;
            up.z = 1.0f;

            List <ISectData> lstISects = RTUtils.IntersectObjects(up, origin, matchingObjects, false);
            Object3d         objFound  = null;
            float            minzdiff  = 99999999f;

            // find the intersection closest to z.
            foreach (ISectData htd in lstISects)
            {
                float zdiff = Math.Abs(htd.intersect.z - z);
                if (zdiff < minzdiff)
                {
                    minzdiff = zdiff;
                    objFound = htd.obj;
                }
            }
            return(objFound);
        }
        /*
         * public class Config
         * {
         *  int xres, yres;
         * // double
         * }
         * */

        public static bool FindIntersection(Vector3d direction, Point3d origin, ref Point3d intersect)
        {
            UVDLPApp.Instance().CalcScene();
            //bool intersected = false;

            //  Point3d bpoint, tpoint;
            //  Point3d lowest = new Point3d(); // the lowest point of intersection on the z axis
            direction.Normalize();
            direction.Scale(100.0);
            Point3d endp = new Point3d();

            endp.Set(origin);
            endp.x += direction.x;
            endp.y += direction.y;
            endp.z += direction.z;

            /*
             * intersect = new Point3d();
             * intersect.x = 0.0d;
             * intersect.y = 0.0d;
             * intersect.z = 0.0d;
             */
            //intersect the scene with a ray

            // intersected = false;
            foreach (Polygon p in UVDLPApp.Instance().Scene.m_lstpolys)
            {
                intersect = new Point3d();
                // try a less- costly sphere intersect here
                if (RTUtils.IntersectSphere(origin, endp, ref intersect, p.m_center, p.m_radius))
                {
                    // if it intersects,
                    if (RTUtils.IntersectPoly(p, origin, endp, ref intersect))
                    {
                        return(true);

                        /*
                         * // and it's the lowest one
                         * if (intersect.z <= lowest.z)
                         * {
                         *  //save this point
                         *  intersected = true;
                         *  lowest.Set(intersect);
                         * }
                         * */
                    }
                }
            }


            return(false);
        }
예제 #4
0
        /*
         * To start, we're going to intersect the entire scene and generate support objects
         * we can change this to generate support for individual objects if needed.
         */
        public ArrayList GenerateSupportObjects()
        {
            // ArrayList objects = new ArrayList();
            // iterate over the platform size by indicated mm step; // projected resolution in x,y
            // generate a 3d x/y point on z=0,
            // generate another on the z=zmax
            // use this ray to intersect the scene
            // foreach intersection point, generate a support
            // we gott make sure supports don't collide
            // I also have to take into account the
            // interface between the support and the model
            ArrayList lstsupports = new ArrayList();

            // double HX =  UVDLPApp.Instance().m_printerinfo.m_PlatXSize / 2; // half X size
            //  double HY =  UVDLPApp.Instance().m_printerinfo.m_PlatYSize / 2; // half Y size
            double ZVal = UVDLPApp.Instance().m_printerinfo.m_PlatZSize;


            //UVDLPApp.Instance().CalcScene();
            m_model.Update();
            double MinX = m_model.m_min.x;
            double MaxX = m_model.m_max.x;
            double MinY = m_model.m_min.y;
            double MaxY = m_model.m_max.y;

            bool intersected = false;
            int  scnt        = 0; // support count
            // iterate from -HX to HX step xtep;
            double dts     = (MaxX - MinX) / m_sc.xspace;
            int    its     = (int)dts;
            int    curstep = 0;

            for (double x = (MinX + (m_sc.xspace / 2)); x < MaxX; x += m_sc.xspace)
            {
                RaiseSupportEvent(UV_DLP_3D_Printer.SupportEvent.eProgress, "" + curstep + "/" + its, null);
                curstep++;
                for (double y = (MinY + (m_sc.yspace / 2)); y < MaxY; y += m_sc.yspace)
                {
                    Point3d bpoint, tpoint;
                    Point3d lowest = new Point3d(); // the lowest point of intersection on the z axis

                    bpoint = new Point3d();         // bottom point
                    tpoint = new Point3d();         // top point
                    bpoint.Set(x, y, 0.0, 1);
                    tpoint.Set(x, y, ZVal, 1);      // set to the max height
                    //intersect the scene with a ray

                    lowest.Set(0, 0, ZVal, 0);
                    intersected = false; // reset the intersected flag to be false
                    foreach (Polygon p in m_model.m_lstpolys)
                    {
                        Point3d intersect = new Point3d();
                        // try a less- costly sphere intersect here
                        if (RTUtils.IntersectSphere(bpoint, tpoint, ref intersect, p.m_center, p.m_radius))
                        {
                            // if it intersects,
                            if (RTUtils.IntersectPoly(p, bpoint, tpoint, ref intersect))
                            {
                                // and it's the lowest one
                                if (intersect.z <= lowest.z)
                                {
                                    //save this point
                                    intersected = true;
                                    lowest.Set(intersect);
                                }
                            }
                        }
                    }
                    // for some reason, we're getting negatively generating cylinders
                    // that extend to the -Z world axis
                    // and we're also unnessary support generate on the y -axis that
                    // do not intersect objects vertically in the x/y plane

                    if ((lowest.z < ZVal) && intersected && (lowest.z >= 0))
                    {
                        // now, generate and add a cylinder here
                        Cylinder3d cyl = new Cylinder3d();
                        cyl.Create(m_sc.brad, m_sc.trad, lowest.z, 20, m_sc.vdivs);
                        cyl.Translate((float)x, (float)y, 0);
                        cyl.Name      = "Support " + scnt;
                        cyl.IsSupport = true;
                        cyl.SetColor(Color.Yellow);
                        scnt++;
                        lstsupports.Add(cyl);
                        RaiseSupportEvent(UV_DLP_3D_Printer.SupportEvent.eSupportGenerated, cyl.Name, cyl);
                    }
                }
            }
            // return objects;
            RaiseSupportEvent(UV_DLP_3D_Printer.SupportEvent.eCompleted, "Support Generation Completed", null);
            m_generating = false;
            return(lstsupports);
        }
        public List <Object3d> GenerateSupportObjects()
        {
            // iterate over the platform size by indicated mm step; // projected resolution in x,y
            // generate a 3d x/y point on z=0,
            // generate another on the z=zmax
            // use this ray to intersect the scene
            // foreach intersection point, generate a support
            // we gott make sure supports don't collide
            // I also have to take into account the
            // interface between the support and the model
            List <Object3d> lstsupports = new List <Object3d>();

            float ZVal = (float)UVDLPApp.Instance().m_printerinfo.m_PlatZSize;

            m_model.Update();
            float MinX = m_model.m_min.x;
            float MaxX = m_model.m_max.x;
            float MinY = m_model.m_min.y;
            float MaxY = m_model.m_max.y;

            // bool intersected = false;
            int scnt = 0; // support count
            // iterate from -HX to HX step xtep;
            double dts     = (MaxX - MinX) / m_sc.xspace;
            int    its     = (int)dts;
            int    curstep = 0;

            for (float x = (float)(MinX + (m_sc.xspace / 2.0f)); x < MaxX; x += (float)m_sc.xspace)
            {
                // say we're doing stuff
                RaiseSupportEvent(UV_DLP_3D_Printer.SupportEvent.eProgress, "" + curstep + "/" + its, null);
                curstep++;
                for (float y = (float)(MinY + (m_sc.yspace / 2)); y < MaxY; y += (float)m_sc.yspace)
                {
                    Point3d origin;
                    origin = new Point3d(); // bottom point
                    origin.Set(x, y, 0.0f);
                    //intersected = false; // reset the intersected flag to be false

                    Vector3d up = new Vector3d(); // the up vector
                    up.x = 0.0f;
                    up.y = 0.0f;
                    up.z = 1.0f;

                    List <ISectData> lstISects = RTUtils.IntersectObjects(up, origin, UVDLPApp.Instance().Engine3D.m_objects, false);
                    //check for cancelling
                    if (m_cancel)
                    {
                        RaiseSupportEvent(UV_DLP_3D_Printer.SupportEvent.eCancel, "Support Generation Cancelled", null);
                        return(lstsupports);
                    }


                    foreach (ISectData htd in lstISects)
                    {
                        if (htd.obj.tag != Object3d.OBJ_SUPPORT)    // if this is not another support or the ground
                        {
                            if (htd.obj.tag != Object3d.OBJ_GROUND) // if it's not the ground
                            {
                                if (m_sc.m_onlydownward && htd.poly.tag != Polygon.TAG_MARKDOWN)
                                {
                                    break; // not a downward facing and we're only doing downward
                                }
                                // this should be the closest intersected
                                Support s  = new Support();
                                float   lz = (float)htd.intersect.z;
                                s.Create((float)m_sc.fbrad, (float)m_sc.ftrad, (float)m_sc.hbrad, (float)m_sc.htrad, lz * .2f, lz * .6f, lz * .2f, 11);
                                s.Translate((float)x, (float)y, 0);
                                s.Name = "Support " + scnt;
                                s.SetColor(Color.Yellow);
                                scnt++;
                                lstsupports.Add(s);
                                RaiseSupportEvent(UV_DLP_3D_Printer.SupportEvent.eSupportGenerated, s.Name, s);
                                break; // only need to make one support
                            }
                        }
                    }
                }
            }
            // return objects;
            RaiseSupportEvent(UV_DLP_3D_Printer.SupportEvent.eCompleted, "Support Generation Completed", lstsupports);
            m_generating = false;
            return(lstsupports);
        }
        /*
         * To start, we're going to intersect the entire scene and generate support objects
         * we can change this to generate support for individual objects if needed.
         */
        public static void GenerateSupportObjects(double xstep, double ystep)
        {
            // ArrayList objects = new ArrayList();
            // iterate over the platform size by indicated mm step; // projected resolution in x,y
            // generate a 3d x/y point on z=0,
            // generate another on the z=zmax
            // use this ray to intersect the scene
            // foreach intersection point, generate a support
            // we gott make sure supports don't collide
            // I also have to take into account the
            // interface between the support and the model

            double HX   = UVDLPApp.Instance().m_printerinfo.m_PlatXSize / 2; // half X size
            double HY   = UVDLPApp.Instance().m_printerinfo.m_PlatYSize / 2; // half Y size
            double ZVal = UVDLPApp.Instance().m_printerinfo.m_PlatZSize;

            UVDLPApp.Instance().CalcScene();
            bool intersected = false;

            // iterate from -HX to HX step xtep;
            for (double x = -HX; x < HX; x += xstep)
            {
                for (double y = -HY; y < 0 /*HY*/; y += ystep)
                {
                    Point3d bpoint, tpoint;
                    Point3d lowest = new Point3d(); // the lowest point of intersection on the z axis

                    bpoint = new Point3d();         // bottom point
                    tpoint = new Point3d();         // top point
                    bpoint.Set(x, y, 0.0, 1);
                    tpoint.Set(x, y, ZVal, 1);      // set to the max height
                    //intersect the scene with a ray

                    lowest.Set(0, 0, ZVal, 0);
                    intersected = false;
                    foreach (Polygon p in UVDLPApp.Instance().Scene.m_lstpolys)
                    {
                        Point3d intersect = new Point3d();
                        // try a less- costly sphere intersect here
                        if (RTUtils.IntersectSphere(bpoint, tpoint, ref intersect, p.m_center, p.m_radius))
                        {
                            // if it intersects,
                            if (RTUtils.IntersectPoly(p, bpoint, tpoint, ref intersect))
                            {
                                // and it's the lowest one
                                if (intersect.z <= lowest.z)
                                {
                                    //save this point
                                    intersected = true;
                                    lowest.Set(intersect);
                                }
                            }
                        }
                    }
                    // for some reason, we're getting negatively generating cylinders
                    // that extend to the -Z world axis
                    // and we're also unnessary support generate on the y -axis that
                    // do not intersect objects vertically in the x/y plane

                    if ((lowest.z < ZVal) && intersected && (lowest.z >= 0))
                    {
                        // now, generate and add a cylinder here
                        Cylinder3d cyl = new Cylinder3d();
                        cyl.Create(1, .5, lowest.z, 20, 1);
                        cyl.Translate((float)x, (float)y, 0);
                        UVDLPApp.Instance().Engine3D.AddObject(cyl);
                    }
                }
            }
            // return objects;
        }