Beispiel #1
0
        public virtual Object3d Clone()
        {
            Object3d obj = new Object3d();

            try
            {
                obj.m_name     = UVDLPApp.Instance().Engine3D.GetUniqueName(this.m_name); // need to find unique name
                obj.m_fullname = this.m_fullname;
                obj.tag        = this.tag;

                foreach (Polygon ply in m_lstpolys)
                {
                    Polygon pl2 = new Polygon();
                    pl2.m_color  = ply.m_color;
                    pl2.m_points = new Point3d[3];
                    obj.m_lstpolys.Add(pl2);
                    pl2.m_points[0] = new Point3d(ply.m_points[0]);
                    pl2.m_points[1] = new Point3d(ply.m_points[1]);
                    pl2.m_points[2] = new Point3d(ply.m_points[2]);
                }
                foreach (Polygon ply in obj.m_lstpolys)
                {
                    foreach (Point3d pnt in ply.m_points)
                    {
                        obj.m_lstpoints.Add(pnt); // a fair bit of overlap, but whatever...
                    }
                }
                obj.Update();
            }
            catch (Exception ex)
            {
                DebugLogger.Instance().LogError(ex);
            }
            return(obj);
        }
Beispiel #2
0
 private void RaiseEvent(eCSGEvent ev, string msg, Object3d dat) 
 {
     if (CSGEvent != null) 
     {
         CSGEvent(ev, msg, dat);
     }
 }
Beispiel #3
0
        private int s5i; // top of the head

        #endregion Fields

        #region Constructors

        public Support()
        {
            tag = Object3d.OBJ_SUPPORT; // tag for support
            m_supporting = null;
            this.Name = "Support_" + supcnt.ToString();
            supcnt++;
        }
 void ParseMesh(XmlNode xMesh)
 {
     ReadVertices(xMesh["vertices"]);
     if (m_smoothObj && (m_smoothLevel == -1))
     {
         if (m_formSmooth.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             m_smoothLevel = m_formSmooth.SmoothLevel;
         }
     }
     m_curObject             = new Object3d();
     m_curObject.m_lstpoints = new List <Point3d>();
     m_flatTrigs             = new List <TriangleAmf>();
     foreach (XmlNode node in xMesh.ChildNodes)
     {
         if (node.Name == "volume")
         {
             ReadVolume(node);
         }
     }
     foreach (PointAmf pamf in m_pointList)
     {
         m_curObject.m_lstpoints.Add(pamf.pt);
     }
     foreach (TriangleAmf t in m_flatTrigs)
     {
         AddFlatTriangle(t.v1, t.v2, t.v3);
     }
 }
 public Support()
 {
     tag          = Object3d.OBJ_SUPPORT; // tag for support
     m_supporting = null;
     this.Name    = "Support_" + supcnt.ToString();
     supcnt++;
 }
 public void FillObjectInfo(Object3d obj)
 {
     if (obj == null)
     {
         foreach (Control ctl in layoutPanel.Controls)
         {
             if (ctl.GetType() == typeof(ctlInfoItem))
                 ((ctlInfoItem)ctl).DataText = "";
         }
         tName.Text = "";
         return;
     }
     obj.FindMinMax();
     tName.Text = obj.Name;
     tPoints.DataText = obj.NumPoints.ToString();
     tPolys.DataText = obj.NumPolys.ToString();
     tMin.DataText = String.Format("{0:0.00}, {1:0.00}, {2:0.00}", obj.m_min.x, obj.m_min.y, obj.m_min.z);
     tMax.DataText = String.Format("{0:0.00}, {1:0.00}, {2:0.00}", obj.m_max.x, obj.m_max.y, obj.m_max.z);
     double xs, ys, zs;
     xs = obj.m_max.x - obj.m_min.x;
     ys = obj.m_max.y - obj.m_min.y;
     zs = obj.m_max.z - obj.m_min.z;
     tSize.DataText = String.Format("{0:0.00}, {1:0.00}, {2:0.00}", xs, ys, zs);
     double vol = obj.Volume;
     vol /= 1000.0; // convert to cm^3
     tVolume.DataText = string.Format("{0:0.000} cm^3", vol);
     double cost = vol * (UVDLPApp.Instance().m_buildparms.m_resinprice / 1000.0);
     tCost.DataText = string.Format("{0:0.000}", cost);
 }
Beispiel #7
0
        public virtual Object3d Clone() 
        {
            Object3d obj = new Object3d();
            try
            {
                obj.m_name = UVDLPApp.Instance().Engine3D.GetUniqueName( this.m_name); // need to find unique name
                obj.m_fullname = this.m_fullname;
                obj.tag = this.tag;

                foreach (Polygon ply in m_lstpolys)
                {
                    Polygon pl2 = new Polygon();
                    pl2.m_color = ply.m_color;
                    pl2.m_points = new Point3d[3];
                    obj.m_lstpolys.Add(pl2);
                    pl2.m_points[0] = new Point3d(ply.m_points[0]);
                    pl2.m_points[1] = new Point3d(ply.m_points[1]);
                    pl2.m_points[2] = new Point3d(ply.m_points[2]);
                }
                foreach (Polygon ply in obj.m_lstpolys) 
                {
                    foreach (Point3d pnt in ply.m_points) 
                    {
                        obj.m_lstpoints.Add(pnt); // a fair bit of overlap, but whatever...
                    }
                }
                obj.Update();
            }
            catch (Exception ex) 
            {
                DebugLogger.Instance().LogError(ex);
            }
            return obj;
        }
Beispiel #8
0
 public void AddObject(Object3d obj)
 {
     m_objects.Add(obj);
     if (ModelAddedEvent != null)
     {
         ModelAddedEvent(obj);
     }
 }
 public void AddObject(Object3d obj)
 {
     m_objects.Add(obj);
     if (ModelAddedEvent != null)
     {
         ModelAddedEvent(obj);
     }
 }
Beispiel #10
0
 public void RemoveObject(Object3d obj)
 {
     m_objects.Remove(obj);
     if (ModelRemovedEvent != null)
     {
         ModelRemovedEvent(obj);
     }
 }
 public void SaveRotation(Object3d obj, double x, double y, double z)
 {
     if ((x == 0) && (y == 0) && (z == 0))
     {
         return;
     }
     AddItem(eOperationType.Rotate, obj, x, y, z);
 }
Beispiel #12
0
 public void FillObjectInfo(Object3d selobj)
 {
     List<Object3d> objects;
     if (buttScene.Checked)
     {
         objects = UVDLPApp.Instance().Engine3D.m_objects;
     }
     else
     {
         objects = new List<Object3d>();
         if (selobj != null)
             objects.Add(selobj);
     }
     if (objects.Count == 0)
     {
         foreach (Control ctl in layoutPanel.Controls)
         {
             if (ctl.GetType() == typeof(ctlInfoItem))
                 ((ctlInfoItem)ctl).DataText = "";
         }
         tName.Text = "";
         return;
     }
     tName.Text = buttScene.Checked ? "Scene" : selobj.Name;
     Point3d min = new Point3d(99999999,99999999,99999999);
     Point3d max = new Point3d(-99999999,-99999999,-99999999);
     int points = 0;
     int polys = 0;
     double vol = 0;
     foreach (Object3d obj in objects)
     {
         if (obj.tag != Object3d.OBJ_NORMAL && obj.tag != Object3d.OBJ_SUPPORT && obj.tag != Object3d.OBJ_SUPPORT_BASE)
             continue;
         obj.FindMinMax();
         points += obj.NumPoints;
         polys += obj.NumPolys;
         if (obj.m_min.x < min.x) min.x = obj.m_min.x;
         if (obj.m_min.y < min.y) min.y = obj.m_min.y;
         if (obj.m_min.z < min.z) min.z = obj.m_min.z;
         if (obj.m_max.x > max.x) max.x = obj.m_max.x;
         if (obj.m_max.y > max.y) max.y = obj.m_max.y;
         if (obj.m_max.z > max.z) max.z = obj.m_max.z;
         vol += obj.Volume;
     }
     tPoints.DataText = points.ToString();
     tPolys.DataText = polys.ToString();
     tMin.DataText = String.Format("{0:0.00}, {1:0.00}, {2:0.00}", min.x, min.y, min.z);
     tMax.DataText = String.Format("{0:0.00}, {1:0.00}, {2:0.00}", max.x, max.y, max.z);
     double xs, ys, zs;
     xs = max.x - min.x;
     ys = max.y - min.y;
     zs = max.z - min.z;
     tSize.DataText = String.Format("{0:0.00}, {1:0.00}, {2:0.00}", xs, ys, zs);
     vol /= 1000.0; // convert to cm^3
     tVolume.DataText = string.Format("{0:0.000} cm^3", vol);
     double cost = vol * (UVDLPApp.Instance().m_buildparms.m_resinprice / 1000.0);
     tCost.DataText = string.Format("{0:0.000}", cost);
 }
        void ProcessChunk(ThreeDSChunk chunk)
        {
            while (chunk.BytesRead < chunk.Length)
            {
                ThreeDSChunk child = new ThreeDSChunk(reader);

                switch ((Groups)child.ID)
                {
                case Groups.C_VERSION:

                    int version = reader.ReadInt32();
                    child.BytesRead += 4;

                    Console.WriteLine("3DS File Version: {0}", version);
                    break;

                case Groups.C_OBJECTINFO:

                    ThreeDSChunk obj_chunk = new ThreeDSChunk(reader);

                    // not sure whats up with this chunk
                    SkipChunk(obj_chunk);
                    child.BytesRead += obj_chunk.BytesRead;

                    ProcessChunk(child);

                    break;

                case Groups.C_MATERIAL:

                    ProcessMaterialChunk(child);
                    //SkipChunk ( child );
                    break;

                case Groups.C_OBJECT:

                    //SkipChunk ( child );
                    string name = ProcessString(child);
                    Console.WriteLine("OBJECT NAME: {0}", name);

                    Object3d e = ProcessObjectChunk(child);
                    //e.CalculateNormals();
                    e.Update();
                    models.Add(e);

                    break;

                default:

                    SkipChunk(child);
                    break;
                }

                chunk.BytesRead += child.BytesRead;
                //Console.WriteLine ( "ID: {0} Length: {1} Read: {2}", chunk.ID.ToString("x"), chunk.Length , chunk.BytesRead );
            }
        }
Beispiel #14
0
        public void SaveScale(Object3d obj, double x, double y, double z)
        {
            if ((x == 1) && (y == 1) && (z == 1))
                return;
            if ((x == 0) || (y == 0) || (z == 0))
                return;

            AddItem(eOperationType.Scale, obj, x, y, z);
        }
        /*
        class SolidSphere
        {
        protected:
        std::vector<GLfloat> vertices;
        std::vector<GLfloat> normals;
        std::vector<GLfloat> texcoords;
        std::vector<GLushort> indices;

        public:
        SolidSphere(float radius, unsigned int rings, unsigned int sectors)
        {
        float const R = 1./(float)(rings-1);
        float const S = 1./(float)(sectors-1);
        int r, s;

        vertices.resize(rings * sectors * 3);
        normals.resize(rings * sectors * 3);
        texcoords.resize(rings * sectors * 2);
        std::vector<GLfloat>::iterator v = vertices.begin();
        std::vector<GLfloat>::iterator n = normals.begin();
        std::vector<GLfloat>::iterator t = texcoords.begin();
        for(r = 0; r < rings; r++) for(s = 0; s < sectors; s++) {
                float const y = sin( -M_PI_2 + M_PI * r * R );
                float const x = cos(2*M_PI * s * S) * sin( M_PI * r * R );
                float const z = sin(2*M_PI * s * S) * sin( M_PI * r * R );

                *t++ = s*S;
                *t++ = r*R;

                *v++ = x * radius;
                *v++ = y * radius;
                *v++ = z * radius;

                *n++ = x;
                *n++ = y;
                *n++ = z;
        }

        indices.resize(rings * sectors * 4);
        std::vector<GLushort>::iterator i = indices.begin();
        for(r = 0; r < rings-1; r++) for(s = 0; s < sectors-1; s++) {
                *i++ = r * sectors + s;
                *i++ = r * sectors + (s+1);
                *i++ = (r+1) * sectors + (s+1);
                *i++ = (r+1) * sectors + s;
        }
        }
         */
        public static Object3d Sphere(float radius, int rings, int sectors)
        {
            try
            {
                Object3d sp = new Object3d();
                sp.Name = "Sphere";
                float R = 1f/(float)(rings-1);
                float S = 1f/(float)(sectors-1);

                float M_PI = (float)Math.PI;// *0.0174532925f; // with deg2rad
                float M_PI_2 = M_PI / 2;
                for(int r = 0; r < rings; r++)
                {
                    for(int s = 0; s < sectors; s++)
                    {
                        float y =(float) Math.Sin( - M_PI_2 + M_PI * r * R );
                        float x = (float)Math.Cos(2 * M_PI * s * S) * (float)Math.Sin(M_PI * r * R);
                        float z = (float)Math.Sin(2 * M_PI * s * S) * (float)Math.Sin(M_PI * r * R);

                        Point3d pnt = new Point3d(x * radius, y * radius, z * radius);
                        sp.m_lstpoints.Add(pnt);
                    }
                }

                //indices.resize(rings * sectors * 4);
                //std::vector<GLushort>::iterator i = indices.begin();
                for(int r = 0; r < rings - 1; r++)
                {
                    for (int s = 0; s < sectors - 1; s++)
                    {
                        Polygon p1 = new Polygon();
                        Polygon p2 = new Polygon();
                        sp.m_lstpolys.Add(p1);
                        sp.m_lstpolys.Add(p2);
                        p1.m_points = new Point3d[3];
                        p2.m_points = new Point3d[3];
                        p1.m_points[2] = sp.m_lstpoints[r * sectors + s];
                        p1.m_points[1] = sp.m_lstpoints[r * sectors + (s + 1)];
                        p1.m_points[0] = sp.m_lstpoints[(r + 1) * sectors + (s + 1)];

                        p2.m_points[2] = sp.m_lstpoints[(r + 1) * sectors + (s + 1)];
                        p2.m_points[1] = sp.m_lstpoints[(r + 1) * sectors + s];
                        p2.m_points[0] = sp.m_lstpoints[r * sectors + s];
                    }
                }
                sp.Update();
                sp.Rotate(90 * 0.0174532925f, 0, 0);
                sp.Update();
                return sp;
            }
            catch(Exception ex)
            {
                DebugLogger.Instance().LogError(ex);
                return null;
            }
        }
	    private TreeNode FindObjectNode(TreeNodeCollection nodes, Object3d sel) 
        {
	        TreeNode found = null;
	        foreach (TreeNode node in nodes) {
	            if (node.Tag == sel) { return node; }
                found = FindObjectNode(node.Nodes, sel);
	            if (found!=null) { break; }
	        }
	        return found;
        }
Beispiel #17
0
 public void StartOp(eCSGOp op, Object3d obj1, Object3d obj2) 
 {
     m_op = op;
     m_obj1 = obj1;
     m_obj2 = obj2;
     //m_cancel = false;
     m_runthread = new Thread(new ThreadStart(RunThread), STACKSIZE);
     m_running = true;
     m_runthread.Start();
 }
Beispiel #18
0
 public Support()
 {
     tag          = Object3d.OBJ_SUPPORT; // tag for support
     m_supporting = null;
     this.Name    = "Support_" + supcnt.ToString();
     supcnt++;
     mSC       = UVDLPApp.Instance().m_supportconfig.Clone(); // start off by cloing the app's defaults
     SubType   = eSubType.eBase;
     m_seltype = eSelType.eWhole;
 }
 public void RemoveObject(Object3d obj, bool sendevents)
 {
     m_objects.Remove(obj);
     if (sendevents == true)
     {
         if (ModelRemovedEvent != null)
         {
             ModelRemovedEvent(obj);
         }
     }
 }
 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;
 }
Beispiel #21
0
        /// <summary>
        /// This function creates a new support structure
        /// you can specify the:
        /// Foot Bottom Radius  - fbrad
        /// Foot Top Radius     - ftrad
        /// Head Bottom Radius  - hbrad
        /// Head Top Radius     - htrad
        ///
        /// as well as the segment lengths from bottom to top D1,D2,D3
        /// you can also specify the number of divisions in the circle - divs
        /// </summary>
        /// <param name="d1"></param>
        /// <param name="d2"></param>
        /// <param name="d3"></param>
        public void Create(SupportConfig SC, Object3d supporting, float d1, float d2, float d3)
        {
            try
            {
                mSC          = SC.Clone();
                m_tipheight  = 2;// d3;
                m_baseheight = d1;

                m_supporting = supporting;
                float zlev = 0.0f;                                      // start at the bottom of the cylinder
                s1i = 0;                                                // set 0 to be the starting index for the bottom of the foot
                GenerateCirclePoints(mSC.fbrad, mSC.cdivs, zlev, true); // foot bottom
                zlev += d1;
                //now the top of the foot
                s2i = m_lstpoints.Count;
                GenerateCirclePoints(mSC.ftrad, mSC.cdivs, zlev, false); // foot top

                //zlev += d1;
                s3i = m_lstpoints.Count;
                GenerateCirclePoints(mSC.ftrad, mSC.cdivs, zlev, false); // foot top

                zlev += d2;

                //now the bottom of the shaft
                s4i = m_lstpoints.Count;
                GenerateCirclePoints(mSC.hbrad, mSC.cdivs, zlev, false); // bottom of head
                zlev += d3;
                //now the top of the shaft, bottom of the head
                s5i = m_lstpoints.Count;
                GenerateCirclePoints(mSC.htrad, mSC.cdivs, zlev, true); // top of head
                psi_base = m_lstpolys.Count;                            // should be 0 index
                MakeTopBottomFace(s1i, mSC.cdivs, false);               // bottom
                //MakeTopBottomFace(s5i, mSC.cdivs, true);// top
                makeWalls(s1i, s2i, mSC.cdivs);
                pei_base = m_lstpolys.Count; // should be top index of

                makeWalls(s2i, s3i - mSC.cdivs - 1, mSC.cdivs);
                makeWalls(s3i, s4i - (2 * mSC.cdivs) - 1, mSC.cdivs);

                psi_tip = m_lstpolys.Count;
                makeWalls(s4i, s5i - (3 * mSC.cdivs) - 1, mSC.cdivs);
                MakeTopBottomFace(s5i, mSC.cdivs, true);// top
                pei_tip = m_lstpolys.Count;

                Update(); // update should only be called for new objects, otherwise, use the move/scale/rotate functions
                SetColor(Color.Yellow);
                ScaleToHeight(d1 + d2 + d3);
            }
            catch (Exception ex)
            {
                DebugLogger.Instance().LogError(ex.Message);
            }
        }
Beispiel #22
0
 public void RemoveSupport(Object3d s)
 {
     if (s == null)
     {
         return;
     }
     while (m_supports.IndexOf(s) >= 0)
     {
         m_supports.Remove(s);
     }
     s.m_parrent = null;
 }
Beispiel #23
0
 /*This cuntion adds the objects points and polygons to this one*/
 public void Add(Object3d obj)
 {
     foreach (Point3d p in obj.m_lstpoints)
     {
         m_lstpoints.Add(p);
     }
     foreach (Polygon ply in obj.m_lstpolys)
     {
         m_lstpolys.Add(ply);
     }
     Update();
 }
Beispiel #24
0
 /*This cuntion adds the objects points and polygons to this one*/
 public void Add(Object3d obj)
 {
     foreach (Point3d p in obj.m_lstpoints)
     {
         m_lstpoints.Add(p);
     }
     foreach (Polygon ply in obj.m_lstpolys)
     {
         m_lstpolys.Add(ply);
     }
     Update();
 }
 void ParseObject(XmlNode xObject)
 {
     m_curObject   = new Object3d();
     m_smoothObj   = false;
     m_smoothLevel = -1;
     ParseMesh(xObject["mesh"]);
     m_curObject.m_fullname = m_filepath;
     m_curObject.Name       = Path.GetFileName(m_filepath);
     m_curObject.Update();
     //m_curObject.m_wireframe = 4;
     m_objList.Add(m_curObject);
     m_nobjects++;
 }
 public int GetNumberOfSlices(SliceBuildConfig sp, Object3d obj)
 {
     try
     {
         obj.FindMinMax();
         int numslices = (int)((obj.m_max.z - obj.m_min.z) / sp.ZThick);
         return numslices;
     }
     catch (Exception)
     {
         return 0;
     }
 }
        public void SaveScale(Object3d obj, double x, double y, double z)
        {
            if ((x == 1) && (y == 1) && (z == 1))
            {
                return;
            }
            if ((x == 0) || (y == 0) || (z == 0))
            {
                return;
            }

            AddItem(eOperationType.Scale, obj, x, y, z);
        }
 private void HighLightSelected(Object3d sel) 
 {
     int idx = 0;
     foreach (ListViewItem lvi in lbSupports.Items) 
     {
         Object3d obj = (Object3d)lvi.Tag;
         if (obj == sel) 
         {
             //lbSupports.sel
             lbSupports.Items[idx].Selected = true;
             break;
         }
         idx++;
     }
 }
Beispiel #29
0
 public void AddSupport(Object3d s)
 {
     if (s == null)
     {
         return;
     }
     if (s.m_parrent != null)
     {
         s.m_parrent.RemoveSupport(s);
     }
     s.m_parrent = this;
     if (m_supports.IndexOf(s) < 0)
     {
         m_supports.Add(s);
     }
 }
Beispiel #30
0
        public Object3d Copy()
        {
            //copy this object
            Object3d cpy = Clone();

            //copy the support structures
            foreach (Object3d obj in this.m_supports)
            {
                if (obj is Support)
                {
                    Support newsup = ((Support)obj).MakeCopy();
                    cpy.AddSupport(newsup);
                }
            }
            return(cpy);
        }
        /// <summary>
        /// This function creates a new support structure
        /// you can specify the:
        /// Foot Bottom Radius  - fbrad
        /// Foot Top Radius     - ftrad
        /// Head Bottom Radius  - hbrad
        /// Head Top Radius     - htrad
        ///
        /// as well as the segment lengths from bottom to top D1,D2,D3
        /// you can also specify the number of divisions in the circle - divs
        /// </summary>
        /// <param name="fbrad"></param>
        /// <param name="ftrad"></param>
        /// <param name="hbrad"></param>
        /// <param name="htrad"></param>
        /// <param name="d1"></param>
        /// <param name="d2"></param>
        /// <param name="d3"></param>
        public void Create(Object3d supporting, float fbrad, float ftrad, float hbrad, float htrad, float d1, float d2, float d3, int divs)
        {
            try
            {
                m_supporting = supporting;
                cdivs        = divs;
                float zlev = 0.0f;                             // start at the bottom of the cylinder
                s1i = 0;                                       // set 0 to be the starting index for the bottom of the foot
                GenerateCirclePoints(fbrad, divs, zlev, true); // foot bottom
                zlev += d1;
                //now the top of the foot
                s2i = m_lstpoints.Count;
                GenerateCirclePoints(ftrad, divs, zlev, false); // foot top

                //zlev += d1;
                s3i = m_lstpoints.Count;
                GenerateCirclePoints(ftrad, divs, zlev, false); // foot top

                zlev += d2;

                //now the bottom of the shaft
                s4i = m_lstpoints.Count;
                GenerateCirclePoints(hbrad, divs, zlev, false); // bottom of head
                zlev += d3;
                //now the top of the shaft, bottom of the head
                s5i = m_lstpoints.Count;
                GenerateCirclePoints(htrad, divs, zlev, true); // top of head

                MakeTopBottomFace(s1i, divs, false);           // bottom
                MakeTopBottomFace(s5i, divs, true);            // top
                //MakeTopBottomFace(s4i, divs, true);// top

                makeWalls(s1i, s2i, divs);
                makeWalls(s2i, s3i - divs - 1, divs);
                makeWalls(s3i, s4i - (2 * divs) - 1, divs);

                makeWalls(s4i, s5i - (3 * divs) - 1, divs);

                Update();
                SetColor(Color.Yellow);
                ScaleToHeight(d1 + d2 + d3);
            }
            catch (Exception ex)
            {
                DebugLogger.Instance().LogError(ex.Message);
            }
        }
Beispiel #32
0
 protected void AddItem(eOperationType type, Object3d obj, double x, double y, double z)
 {
     if (obj == null)
         return;
     while (m_undopointer < m_undoItemList.Count)
     {
         m_undoItemList.RemoveAt(m_undopointer);
     }
     UndoItem item = new UndoItem();
     item.opType = type;
     item.obj = obj;
     item.x = x;
     item.y = y;
     item.z = z;
     item.linkedToPrev = false;
     m_undoItemList.Add(item);
     m_undopointer++;
     UpdateButtons();
 }
Beispiel #33
0
        public List <Object3d> Load(string filename)
        {
            string ext = Path.GetExtension(filename).ToLower();

            // special loaders
            foreach (ModelLoaderType loader in m_loaders)
            {
                if (ext == loader.FileExtension)
                {
                    return(loader.LoadModel(filename));
                }
            }

            // built in loaders
            Object3d obj = new Object3d();
            bool     ret = false;

            if (ext.Equals(".dxf"))
            {
                ret = obj.LoadDXF(filename);
            }
            if (ext.Equals(".stl"))
            {
                ret = obj.LoadSTL(filename);
            }
            if (ext.Equals(".obj"))
            {
                ret = obj.LoadObjFile(filename);
            }
            if (ext.Equals(".3ds"))
            {
                ret = obj.Load3ds(filename);
            }
            if (ret == true)
            {
                List <Object3d> objlist = new List <Object3d>();
                objlist.Add(obj);
                return(objlist);
            }

            return(null);
        }
        public bool StartSlice(Object3d obj)
        {
            try
            {
                // make sure we've got new slicedata
                m_data = new SliceData();
                SliceModule.m_data = m_data;
                //set the target object
                SliceModule.m_data.m_obj = obj;

                //start the thread
                m_running = true;
                m_runthread = new Thread(run);
                m_runthread.Start();
            }
            catch (Exception ex)
            {
                DebugLogger.Instance().LogError(ex.Message);
            }
            return false;
        }
        // generate a support base plate under a reference object
        public void Generate(Object3d refObj, float spacing)
        {
            if ((refObj == null) || (spacing < 1))
            {
                return;
            }

            m_spacing = spacing;
            m_refObj  = refObj;
            GenerateTileMap();
            FillTiles();
            FillOutline();
            foreach (Polygon ply in m_lstpolys)
            {
                ply.CalcCenter();
                ply.CalcNormal();
            }
            Update();
            SetColor(Color.Yellow);
            m_name = refObj.m_name + "_Base";
        }
        protected void AddItem(eOperationType type, Object3d obj, double x, double y, double z)
        {
            if (obj == null)
            {
                return;
            }
            while (m_undopointer < m_undoItemList.Count)
            {
                m_undoItemList.RemoveAt(m_undopointer);
            }
            UndoItem item = new UndoItem();

            item.opType       = type;
            item.obj          = obj;
            item.x            = x;
            item.y            = y;
            item.z            = z;
            item.linkedToPrev = false;
            m_undoItemList.Add(item);
            m_undopointer++;
            UpdateButtons();
        }
        public List<Object3d> Load(string filename)
        {
            string ext = Path.GetExtension(filename).ToLower();
            // special loaders
            foreach (ModelLoaderType loader in m_loaders)
            {
                if (ext == loader.FileExtension)
                    return loader.LoadModel(filename);
            }

            // built in loaders
            Object3d obj = new Object3d();
            bool ret = false;
            if (ext.Equals(".dxf"))
            {
                ret = obj.LoadDXF(filename);
            }
            if (ext.Equals(".stl"))
            {
                ret = obj.LoadSTL(filename);
            }
            if (ext.Equals(".obj"))
            {
                ret = obj.LoadObjFile(filename);
            }
            if (ext.Equals(".3ds"))
            {
                ret = obj.Load3ds(filename);
            }
            if (ret == true)
            {
                List<Object3d> objlist = new List<Object3d>();
                objlist.Add(obj);
                return objlist;
            }

            return null;
        }
        Object3d ProcessObjectChunk(ThreeDSChunk chunk, Object3d e)
        {
            while (chunk.BytesRead < chunk.Length)
            {
                ThreeDSChunk child = new ThreeDSChunk(reader);

                switch ((Groups)child.ID)
                {
                case Groups.C_OBJECT_MESH:

                    ProcessObjectChunk(child, e);
                    break;

                case Groups.C_OBJECT_VERTICES:

                    //e.vertices = ReadVertices(child);
                    e.m_lstpoints = ReadVertices(child);
                    break;

                case Groups.C_OBJECT_FACES:

                    //e.indices =
                    Triangle [] tris = ReadIndices(child);
                    foreach (Triangle t in tris)
                    {
                        Polygon p = new Polygon();
                        p.m_points    = new Point3d[3];
                        p.m_points[0] = (Point3d)e.m_lstpoints[t.vertex1];
                        p.m_points[1] = (Point3d)e.m_lstpoints[t.vertex2];
                        p.m_points[2] = (Point3d)e.m_lstpoints[t.vertex3];
                        e.m_lstpolys.Add(p);
                    }
                    e.Update();
                    if (child.BytesRead < child.Length)
                    {
                        ProcessObjectChunk(child, e);
                    }
                    break;

                case Groups.C_OBJECT_MATERIAL:

                    string name2 = ProcessString(child);
                    Console.WriteLine("	Uses Material: {0}", name2);

                    Material mat;
                    if (materials.TryGetValue(name2, out mat))
                    {
                        e.material = mat;
                    }
                    else
                    {
                        Console.WriteLine(" Warning: Material '{0}' not found. ", name2);
                    }

                    SkipChunk(child);
                    break;

                case Groups.C_OBJECT_UV:

                    int cnt = reader.ReadUInt16();
                    child.BytesRead += 2;

                    Console.WriteLine("	TexCoords: {0}", cnt);
                    //e.texcoords = new TexCoord[cnt];
                    //TexCoord tc = new TexCoord();
                    for (int ii = 0; ii < cnt; ii++)
                    {
                        //should add this to a list somewhere
                        TexCoord tc = new TexCoord(reader.ReadSingle(), reader.ReadSingle());
                    }

                    child.BytesRead += (cnt * (4 * 2));

                    break;

                default:

                    SkipChunk(child);
                    break;
                }
                chunk.BytesRead += child.BytesRead;
                //Console.WriteLine ( "	ID: {0} Length: {1} Read: {2}", chunk.ID.ToString("x"), chunk.Length , chunk.BytesRead );
            }
            return(e);
        }
 public void AddToSelectionList(Object3d obj)
 {
     if (obj == null)
         return;
     if (m_selectedobjects == null)
         SelectedObject = obj;
     else
     {
         m_selectedobjects.Add(obj);
         obj.m_inSelectedList = true;
     }
 }
        private int s5i; // top of the head

        #endregion Fields

        #region Constructors

        public Support()
        {
            tag = Object3d.OBJ_SUPPORT; // tag for support
            m_supporting = null;
        }
        /*
         * This function try to rearranges all objects on the build platform so they
         * do not touch each other
         */
        public void RearrangeObjects()
        {
            BinPacker bp = new BinPacker();
            List <BinPacker.BinRect> rects = new List <BinPacker.BinRect>();

            foreach (Object3d obj in m_objects)
            {
                if (obj.tag != Object3d.OBJ_NORMAL)
                {
                    continue;
                }
                float             w  = obj.m_max.x - obj.m_min.x;
                float             h  = obj.m_max.y - obj.m_min.y;
                BinPacker.BinRect rc = new BinPacker.BinRect(w, h, obj);
                rects.Add(rc);
            }

            float pw = (float)UVDLPApp.Instance().m_printerinfo.m_PlatXSize;
            float ph = (float)UVDLPApp.Instance().m_printerinfo.m_PlatYSize;

            bp.Pack(rects, (int)pw, (int)ph, true);

            // find pack size
            int maxw = 0;
            int maxh = 0;

            foreach (BinPacker.BinRect rc in rects)
            {
                if (rc.packed && ((rc.x + rc.w) > maxw))
                {
                    maxw = rc.x + rc.w;
                }
                if (rc.packed && ((rc.y + rc.h) > maxh))
                {
                    maxh = rc.y + rc.h;
                }
            }

            // find offsets to center all objects
            float offsx = -(float)maxw / 2f + 0.5f;
            float offsy = -(float)maxh / 2f + 0.5f;

            // move all objects to new positions
            foreach (BinPacker.BinRect rc in rects)
            {
                Object3d obj = (Object3d)rc.obj;
                if (rc.packed)
                {
                    if (rc.rotated)
                    {
                        obj.Rotate(0, 0, 1.570796326f);
                    }
                    float dx = rc.x - obj.m_min.x + offsx;
                    float dy = rc.y - obj.m_min.y + offsy;
                    obj.Translate(dx, dy, 0, true);
                }
                else
                {
                    // object could not fit, place outside platform
                    obj.Translate(pw / 2f - obj.m_min.x, 0, 0, true);
                }
            }
            UVDLPApp.Instance().RaiseAppEvent(eAppEvent.eReDraw, "Redraw new arrangement");
        }
Beispiel #42
0
        private static void CreateGroundPlane()
        {
            m_gp = new Object3d();
            m_gp.Name = "GroundPlane";
            Point3d p0=new Point3d(-500,-500,0);
            Point3d p1=new Point3d(500,-500,0);
            Point3d p2=new Point3d(500,500,0);
            Point3d p3=new Point3d(-500,500,0);
            m_gp.m_lstpoints.Add(p0);
            m_gp.m_lstpoints.Add(p1);
            m_gp.m_lstpoints.Add(p2);
            m_gp.m_lstpoints.Add(p3);

            Polygon ply0 = new Polygon();
            ply0.m_points = new Point3d[3];
            ply0.m_points[0] = p0;
            ply0.m_points[1] = p1;
            ply0.m_points[2] = p2;

            Polygon ply1 = new Polygon();
            ply1.m_points = new Point3d[3];
            ply1.m_points[0] = p0;
            ply1.m_points[1] = p2;
            ply1.m_points[2] = p3;
            m_gp.m_lstpolys.Add(ply0);
            m_gp.m_lstpolys.Add(ply1);
            m_gp.tag = Object3d.OBJ_GROUND; // groundplane tag
            m_gp.Update();
           // p1.m

        }
        /// <summary>
        /// This function creates a new support structure
        /// you can specify the:
        /// Foot Bottom Radius  - fbrad
        /// Foot Top Radius     - ftrad
        /// Head Bottom Radius  - hbrad
        /// Head Top Radius     - htrad
        /// 
        /// as well as the segment lengths from bottom to top D1,D2,D3
        /// you can also specify the number of divisions in the circle - divs
        /// </summary>
        /// <param name="fbrad"></param>
        /// <param name="ftrad"></param>
        /// <param name="hbrad"></param>
        /// <param name="htrad"></param>
        /// <param name="d1"></param>
        /// <param name="d2"></param>
        /// <param name="d3"></param>
        public void Create(Object3d supporting, float fbrad, float ftrad, float hbrad, float htrad, float d1, float d2, float d3, int divs)
        {
            try
            {
                m_supporting = supporting;
                cdivs = divs;
                float zlev = 0.0f; // start at the bottom of the cylinder
                s1i = 0; // set 0 to be the starting index for the bottom of the foot
                GenerateCirclePoints(fbrad, divs, zlev, true); // foot bottom
                zlev += d1;
                //now the top of the foot
                s2i = m_lstpoints.Count;
                GenerateCirclePoints(fbrad, divs, zlev, false); // foot top

                //zlev += d1;
                s3i = m_lstpoints.Count;
                GenerateCirclePoints(ftrad, divs, zlev, false); // foot top

                zlev += d2;

                //now the bottom of the shaft
                s4i = m_lstpoints.Count;
                GenerateCirclePoints(hbrad, divs, zlev, false); // bottom of head
                zlev += d3;
                //now the top of the shaft, bottom of the head
                s5i = m_lstpoints.Count;
                GenerateCirclePoints(htrad, divs, zlev, true); // top of head

                MakeTopBottomFace(s1i, divs, false);// bottom
                MakeTopBottomFace(s5i, divs, true);// top
                //MakeTopBottomFace(s4i, divs, true);// top

                makeWalls(s1i, s2i, divs);
                makeWalls(s2i, s3i - divs - 1, divs);
                makeWalls(s3i, s4i - (2*divs) - 1, divs);

                makeWalls(s4i, s5i - (3 * divs) - 1, divs);

                Update();
                SetColor(Color.Yellow);
                ScaleToHeight(d1 + d2 + d3);
            }
            catch (Exception ex)
            {
                DebugLogger.Instance().LogError(ex.Message);

            }
        }
 // this function takes the object, the slicing parameters,
 // and the output directory. it generates the object slices
 // and saves them in the directory
 public SliceFile Slice(SliceBuildConfig sp, Object3d obj, String outdir)
 {
     m_obj = obj;
         m_cancel = false;
         // create new slice file
         m_sf = new SliceFile(sp);
         m_slicethread = new Thread(new ThreadStart(slicefunc));
         m_slicethread.Start();
         isslicing = true;
         return m_sf;
 }
Beispiel #45
0
 private List<csgjs_polygon> ConvertTo(Object3d obj) 
 {
     List<csgjs_polygon> polys = new List<csgjs_polygon>();
     foreach (Polygon p in obj.m_lstpolys) 
     {
         List<csgjs_vertex> list = new List<csgjs_vertex>();
         list.Add(new csgjs_vertex(p.m_points[0]));
         list.Add(new csgjs_vertex(p.m_points[1]));
         list.Add(new csgjs_vertex(p.m_points[2]));
         csgjs_polygon newpoly = new csgjs_polygon(list); // create  from a list of vertexes to initialize plane
         polys.Add(newpoly);
     }
     return polys;
 }
 public void SaveDelition(Object3d obj)
 {
     AddItem(eOperationType.Del, obj, 0, 0, 0);
 }
 /*
  Return a list of polygons that intersect at this zlevel
  */
 public ArrayList GetZPolys(Object3d obj, double zlev)
 {
     ArrayList lst = new ArrayList();
     foreach(Polygon p in obj.m_lstpolys)
     {
         //check and see if current z level is between any of the polygons z coords
         MinMax mm = p.CalcMinMax();
         if (mm.InRange(zlev))
         {
             lst.Add(p);
         }
     }
     return lst;
 }
 /// <summary>
 /// Start the support generation
 /// </summary>
 public void Start(SupportConfig sc, Object3d model)
 {
     Thread m_thread = new Thread(new ThreadStart(StartGenerating));
     m_sc = sc;
     m_model = model;
     m_cancel = false;
     m_generating = true;
     m_thread.Start();
 }
 /*
  Return a list of polygons that intersect at this zlevel
  */
 public ArrayList GetZPolys(Object3d obj, double zlev)
 {
     ArrayList lst = new ArrayList();
     try
     {
         if (zlev >= obj.m_min.z && zlev <= obj.m_max.z)
         {
             foreach (Polygon p in obj.m_lstpolys)
             {
                 //check and see if current z level is between any of the polygons z coords
                 //MinMax mm = p.CalcMinMax();
                 if (p.m_minmax.InRange(zlev))
                 {
                     lst.Add(p);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         DebugLogger.Instance().LogError(ex.Message);
     }
     return lst;
 }
Beispiel #50
0
 private Object3d Intersect(Object3d obj1, Object3d obj2)
 {
     List<csgjs_polygon> a = ConvertTo(obj1);
     List<csgjs_polygon> b = ConvertTo(obj2);
     csgjs_csgnode A = new csgjs_csgnode(a);
     csgjs_csgnode B = new csgjs_csgnode(b);
     csgjs_csgnode AB = csgjs_csgnode.csg_intersect(A, B);
     return ConvertFrom(AB.allPolygons());
 }
 /// <summary>
 /// I want to get rid of this function, need to replace the 
 /// Slic3r model and the supportgenerator model
 /// </summary>
 public void CalcScene()
 {
     m_sceneobject = new Object3d();
     int idx = 0;
     foreach(Object3d obj in m_engine3d.m_objects)
     {
         m_sceneobject.Add(obj);
         if (idx == 0) // if this is the first object
         {
             if (m_engine3d.m_objects.Count > 1)// if there is more than one object in the scene, generate a unique name
             {
                 string scenename = obj.m_fullname;
                 scenename = Path.GetDirectoryName(obj.m_fullname) + m_pathsep + Path.GetFileNameWithoutExtension(obj.m_fullname) + "_scene.stl";
                 m_sceneobject.m_fullname = scenename;
             }
             else
             {
                 m_sceneobject.m_fullname = obj.m_fullname;
             }
         }
         idx++;
     }
 }
 public void SaveAddition(Object3d obj)
 {
     AddItem(eOperationType.Add, obj, 0, 0, 0);
 }
 public void CSGEvent(CSG.eCSGEvent ev, string msg, Object3d dat)
 {
     try
     {
         switch (ev)
         {
             case CSG.eCSGEvent.eCompleted:
                 m_engine3d.AddObject(dat);
                 RaiseAppEvent(eAppEvent.eReDraw, "");
                 break;
             case CSG.eCSGEvent.eError:
                 break;
             case CSG.eCSGEvent.eProgress:
                 break;
             case CSG.eCSGEvent.eStarted:
                 break;
         }
     }
     catch (Exception ex)
     {
         DebugLogger.Instance().LogError(ex);
     }
 }
Beispiel #54
0
        private Object3d ConvertFrom(List<csgjs_polygon> lstply) 
        {
            Object3d obj = new Object3d();
            for (int i = 0; i < lstply.Count; i++)
            {
                csgjs_polygon poly = lstply[i];

                for (int j = 2; j < poly.vertices.Count; j++)
                {
                    Polygon ply = new Polygon(); // create a new polygon
                    ply.m_points = new Point3d[3];
                    obj.m_lstpolys.Add(ply); //add it to the list

                    Point3d p0 = new Point3d();
                    Point3d p1 = new Point3d();
                    Point3d p2 = new Point3d();

                    p0.Set(poly.vertices[0].pos.x, poly.vertices[0].pos.y, poly.vertices[0].pos.z);
                    p1.Set(poly.vertices[j - 1].pos.x, poly.vertices[j - 1].pos.y, poly.vertices[j - 1].pos.z);
                    p2.Set(poly.vertices[j].pos.x, poly.vertices[j].pos.y, poly.vertices[j].pos.z);

                    ply.m_points[0] = p0;
                    ply.m_points[1] = p1;
                    ply.m_points[2] = p2;

                    obj.m_lstpoints.Add(p0);
                    obj.m_lstpoints.Add(p1);
                    obj.m_lstpoints.Add(p2);
                }
            }
            obj.Update();
            return obj;
        }