Ejemplo n.º 1
0
        /// <summary> RunCommandPickPlane is a helper method for picking an existing surface to draw on </summary>
        /// <param name="mRhinoDoc"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        protected Result RunCommandPickPlane(RhinoDoc mRhinoDoc, RunMode mode)
        {
            //routine for picking an existing surface to draw on

            //please select a plane

            Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Surface;
            Rhino.DocObjects.ObjRef     objref = null;
            Rhino.Commands.Result       rc     = Rhino.Input.RhinoGet.GetOneObject("Select surface", false, filter, out objref);
            if (rc != Rhino.Commands.Result.Success || objref == null)
            {
                return(rc);
            }

            Rhino.Geometry.Surface refSrf = objref.Surface();
            refSrf.FrameAt(.5, .5, out plane1);

            Point3d  pOrigin = refSrf.PointAt(1, 1);
            Point3d  pY      = refSrf.PointAt(0.5, 1);
            Point3d  pX      = refSrf.PointAt(1, 0.75);
            Vector3d vX      = Rhino.Geometry.Point3d.Subtract(pX, pOrigin);
            Vector3d vY      = Rhino.Geometry.Point3d.Subtract(pY, pOrigin);

            plane1 = new Plane(pOrigin, vX, vY);

            Rhino.DocObjects.RhinoObject rhobj = objref.Object();
            rhobj.Select(false);

            mRhinoDoc.Objects.AddPoint(pOrigin);
            mRhinoDoc.Objects.AddPoint(pX);
            mRhinoDoc.Objects.AddPoint(pY);
            mRhinoDoc.Views.Redraw();

            return(Result.Success);
        }
Ejemplo n.º 2
0
        /// <example>
        /// <code source='examples\vbnet\ex_orientonsrf.vb' lang='vbnet'/>
        /// <code source='examples\cs\ex_orientonsrf.cs' lang='cs'/>
        /// <code source='examples\py\ex_orientonsrf.py' lang='py'/>
        /// </example>
        public DocObjects.ObjRef Object(int index)
        {
            DocObjects.ObjRef rc  = new Rhino.DocObjects.ObjRef();
            IntPtr            ptr = NonConstPointer();

            UnsafeNativeMethods.CRhinoGetObject_Object(ptr, index, rc.NonConstPointer());
            return(rc);
        }
Ejemplo n.º 3
0
        public override void init()
        {
            resetVariables();

            //support undo function
            if (mScene != null && (afterCurveCount - beforeCurveCount) > 0)
            {
                if (mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.CurveOnObj.ToString()) != "")
                {
                    Guid   curveOnObjId  = new Guid(mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.CurveOnObj.ToString()));
                    ObjRef curveOnObjRef = new ObjRef(curveOnObjId);
                    if (curveOnObjRef.Object().Attributes.Name.Contains("MoveP"))
                    {
                        UtilOld.removeRhinoObject(ref mScene, curveOnObjRef.ObjectId);
                    }
                }
                mScene.iCurveList.RemoveAt(mScene.iCurveList.Count - 1);

                pointOnObjRef = null;
            }

            if (drawnType != DrawnType.In3D && drawnType != DrawnType.None)
            {
                UtilOld.showLaser(ref mScene, true);
                if (drawnType == DrawnType.Plane)
                {
                    UtilOld.setPlaneAlpha(ref mScene, 0.4f);
                }

                //init rayCastingObjs
                Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings();
                settings.ObjectTypeFilter = Rhino.DocObjects.ObjectType.Brep;
                foreach (Rhino.DocObjects.RhinoObject rhObj in mScene.rhinoDoc.Objects.GetObjectList(settings))
                {
                    bool b1 = (drawnType == DrawnType.Plane) && rhObj.Attributes.Name.Contains("plane");
                    bool b2 = (drawnType == DrawnType.Surface) && (rhObj.Attributes.Name.Contains("brepMesh") || rhObj.Attributes.Name.Contains("aprint") || rhObj.Attributes.Name.Contains("patchSurface"));
                    bool b3 = (drawnType == DrawnType.Reference) && rhObj.Attributes.Name.Contains("railPlane");

                    if (b1 || b2 || b3)
                    {
                        rayCastingObjs.Add(new ObjRef(rhObj.Id));
                    }
                }

                Geometry.Geometry geo = new Geometry.DrawPointMarker(new OpenTK.Vector3(0, 0, 0));
                Material.Material m   = new Material.SingleColorMaterial(1, 1, 1, 0);
                drawPoint = new SceneNode("drawPoint", ref geo, ref m);
                UtilOld.addSceneNode(ref mScene, ref drawPoint);
            }
            else
            {
                UtilOld.showLaser(ref mScene, false);
            }
        }
Ejemplo n.º 4
0
        protected Vector3d getWidthHeigthDepthVect(Rhino.DocObjects.ObjRef boxObjRef)
        {
            Brep        boxBrep = boxObjRef.Brep();
            BoundingBox bbox    = boxBrep.GetBoundingBox(true);
            Point3d     bboxMin = bbox.Min;
            Point3d     bboxMax = bbox.Max;
            double      xDist   = bboxMax.X - bboxMin.X;
            double      yDist   = bboxMax.Y - bboxMin.Y;
            double      zDist   = bboxMax.Z - bboxMin.Z;

            return(new Vector3d(xDist, yDist, zDist));
        }
Ejemplo n.º 5
0
    public static Rhino.Commands.Result Flow(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();

        Rhino.DocObjects.ObjRef objref;
        Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetOneObject("Select object to flow", false, filter, out objref);
        if (rc != Rhino.Commands.Result.Success || objref == null)
        {
            return(rc);
        }

        Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject();
        go0.SetCommandPrompt("Source curve");
        go0.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
        go0.SubObjectSelect = false;
        go0.EnablePreSelect(false, true);
        go0.DeselectAllBeforePostSelect = false;
        go0.Get();
        if (go0.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go0.CommandResult());
        }

        Rhino.DocObjects.ObjRef crv0_ref = go0.Object(0);

        Rhino.Input.Custom.GetObject go1 = new Rhino.Input.Custom.GetObject();
        go1.SetCommandPrompt("Source curve");
        go1.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
        go1.SubObjectSelect = false;
        go1.EnablePreSelect(false, true);
        go1.DeselectAllBeforePostSelect = false;
        go1.Get();
        if (go1.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go1.CommandResult());
        }

        Rhino.DocObjects.ObjRef crv1_ref = go1.Object(0);

        Rhino.Geometry.Morphs.FlowSpaceMorph morph = new Rhino.Geometry.Morphs.FlowSpaceMorph(crv0_ref.Curve(), crv1_ref.Curve(), false);

        Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
            doc.Objects.Add(geom);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
Ejemplo n.º 6
0
        internal override IntPtr _InternalGetConstPointer()
        {
            if (null != m_shallow_parent)
            {
                return(m_shallow_parent.ConstPointer());
            }

#if RHINO_SDK
            Rhino.DocObjects.ObjRef obj_ref = m__parent as Rhino.DocObjects.ObjRef;
            if (null != obj_ref)
            {
                return(obj_ref.GetGeometryConstPointer(this));
            }

            Rhino.DocObjects.RhinoObject parent_object = ParentRhinoObject();
            if (parent_object == null)
            {
                Rhino.FileIO.File3dmObject fileobject = m__parent as Rhino.FileIO.File3dmObject;
                if (null != fileobject)
                {
                    return(fileobject.GetGeometryConstPointer());
                }
            }

            uint   serial_number      = 0;
            IntPtr pParentRhinoObject = IntPtr.Zero;
            if (null != parent_object)
            {
                serial_number      = parent_object.m_rhinoobject_serial_number;
                pParentRhinoObject = parent_object.m_pRhinoObject;
            }
            ComponentIndex ci = new ComponentIndex();
            // There are a few cases (like in ReplaceObject callback) where the parent
            // rhino object temporarily holds onto the CRhinoObject* because the object
            // is not officially in the document yet.
            if (pParentRhinoObject != IntPtr.Zero)
            {
                return(UnsafeNativeMethods.CRhinoObject_Geometry(pParentRhinoObject, ci));
            }
            return(UnsafeNativeMethods.CRhinoObject_Geometry2(serial_number, ci));
#else
            Rhino.FileIO.File3dmObject fileobject = m__parent as Rhino.FileIO.File3dmObject;
            if (null != fileobject)
            {
                return(fileobject.GetGeometryConstPointer());
            }
            return(IntPtr.Zero);
#endif
        }
Ejemplo n.º 7
0
    public static Rhino.Commands.Result Splop(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();

        Rhino.DocObjects.ObjRef objref;
        Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetOneObject("Select object to splop", false, filter, out objref);
        if (rc != Rhino.Commands.Result.Success || objref == null)
        {
            return(rc);
        }

        Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();

        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Surface to splop on");
        go.GeometryFilter  = Rhino.DocObjects.ObjectType.Surface;
        go.SubObjectSelect = false;
        go.EnablePreSelect(false, true);
        go.DeselectAllBeforePostSelect = false;
        go.Get();
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        Rhino.DocObjects.ObjRef srfref = go.Object(0);

        double u, v;

        srfref.SurfaceParameter(out u, out v);

        Rhino.Geometry.Point2d uv = new Rhino.Geometry.Point2d(u, v);

        Rhino.Geometry.Morphs.SplopSpaceMorph morph = new Rhino.Geometry.Morphs.SplopSpaceMorph(plane, srfref.Surface(), uv);
        Rhino.Geometry.GeometryBase           geom  = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
            doc.Objects.Add(geom);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
Ejemplo n.º 8
0
        /// <summary>
        /// Rhino calls the virtual ReplayHistory functions to to remake an objects when inputs have changed.
        /// </summary>
        protected override bool ReplayHistory(Rhino.DocObjects.ReplayHistoryData replay)
        {
            Rhino.DocObjects.ObjRef objref2 = null;
            List <Curve>            curves2 = new List <Curve>();

            Brep[]        pipe2;
            PipeCapMode[] pCapM = { PipeCapMode.None, PipeCapMode.Flat, PipeCapMode.Round };

            double radius1 = 0.0;
            double radius2 = 0.0;

            double[] radiParam = { 0.0, 0.5, 1.0 };
            double[] radi      = { radius1, radius2, radius1 };

            if (!ReadHistory(replay, ref ids, ref radius1, ref radius2, ref capIndex))
            {
                return(false);
            }

            foreach (Guid i in ids)
            {
                objref2 = new ObjRef(i);
                Rhino.Geometry.Curve curve = objref2.Curve();
                curves2.Add(curve);
            }

            foreach (Curve x in curves2)
            {
                pipe2 = Brep.CreatePipe(x, radiParam, radi, true, pCapM[capIndex], true, 0.01, 0.01);
                replay.Results[0].UpdateToBrep(pipe2[0], null);
            }



            return(true);
        }
Ejemplo n.º 9
0
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            Mesh meshObj;
            Point3d pointObj = new Point3d(0.0,0.0,0.0);

            RhinoApp.WriteLine("dikka dikka dikka...");

            Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
            gp.SetCommandPrompt("Start of ray");
            gp.Get();
            if (gp.CommandResult() != Rhino.Commands.Result.Success)
                return gp.CommandResult();

            pointObj = gp.Point();
            doc.Objects.AddPoint(pointObj);

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select the mesh to print");
            go.Get();
            Result rc = go.CommandResult();

            if (rc != Rhino.Commands.Result.Success)
            {
                RhinoApp.WriteLine("sdfafadsfda");
                return rc;
            }

            RhinoApp.WriteLine("2 2 dikka dikka dikka...");

            meshObj = new Mesh();
            if (go.ObjectCount == 1)
            {
                ObjRef tmpRef = new ObjRef(go.Object(0).ObjectId);
                meshObj = tmpRef.Mesh();
                if (meshObj == null)
                {
                    return rc;
                }
            }

            Ray3d rayObj = new Ray3d(pointObj, new Vector3d(1.0, 1.0, 1.0));
            doc.Objects.AddPoint(rayObj.PointAt(1.0));
            doc.Objects.AddPoint(rayObj.PointAt(2.0));
            doc.Objects.AddPoint(rayObj.PointAt(3.0));

            double p  = Intersection.MeshRay(meshObj, rayObj);
            string a = string.Format("mesh ray gives {0:0.00}",p);
            doc.Objects.AddPoint(rayObj.PointAt(p));
            RhinoApp.WriteLine(a);
            return Rhino.Commands.Result.Success;
        }
Ejemplo n.º 10
0
        //Dynamic Object Draw
        void RefObjDraw(object sender, Rhino.Input.Custom.GetPointDrawEventArgs e)
        {
            double factorTemp = (scaleCenter.DistanceTo(e.CurrentPoint)) / (scaleCenter.DistanceTo(scaleRefPoint));

            //Translate 3d
            if (dimensionIndex == 0)
            {
                for (int i = 0; i < dynRef.Count; i++)
                {
                    Rhino.DocObjects.ObjRef objref = dynRef[i] as Rhino.DocObjects.ObjRef;
                    var xform = Transform.Scale(centers[i], factorTemp);

                    Brep brep  = objref.Brep();
                    var  index = objref.GeometryComponentIndex.Index;
                    if (index > 0)
                    {
                        brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, 0.01, 0, true);
                        //doc.Objects.Replace(objref.ObjectId, brep);

                        e.Display.DrawBrepWires(brep, System.Drawing.Color.Gray);
                    }
                    else
                    {
                        Rhino.DocObjects.RhinoObject rhobj = objref.Object();
                        e.Display.DrawObject(rhobj, xform);
                    }
                }
            }
            //Translate 2d
            else if (dimensionIndex == 1)
            {
                for (int i = 0; i < dynRef.Count; i++)
                {
                    Rhino.DocObjects.ObjRef objref = dynRef[i] as Rhino.DocObjects.ObjRef;
                    plane2D.Origin = centers[i];
                    var  xform = Rhino.Geometry.Transform.Scale(plane2D, factorTemp, factorTemp, 1);
                    Brep brep  = objref.Brep();
                    var  index = objref.GeometryComponentIndex.Index;
                    if (index > 0)
                    {
                        brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, 0.01, 0, true);
                        //doc.Objects.Replace(objref.ObjectId, brep);

                        e.Display.DrawBrepWires(brep, System.Drawing.Color.Gray);
                    }
                    else
                    {
                        Rhino.DocObjects.RhinoObject rhobj = objref.Object();
                        e.Display.DrawObject(rhobj, xform);
                    }
                }
            }
            //Translate 1d
            else if (dimensionIndex == 2)
            {
                for (int i = 0; i < dynRef.Count; i++)
                {
                    Vector3d vec                   = (scaleRefPoint - scaleCenter);
                    Plane    scalePlane            = new Plane(centers[i], vec);
                    var      xform                 = Transform.Scale(scalePlane, 1, 1, factorTemp);
                    Rhino.DocObjects.ObjRef objref = dynRef[i] as Rhino.DocObjects.ObjRef;
                    Brep brep  = objref.Brep();
                    var  index = objref.GeometryComponentIndex.Index;
                    if (index > 0)
                    {
                        brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, 0.01, 0, true);
                        //doc.Objects.Replace(objref.ObjectId, brep);

                        e.Display.DrawBrepWires(brep, System.Drawing.Color.Gray);
                    }
                    else
                    {
                        Rhino.DocObjects.RhinoObject rhobj = objref.Object();
                        e.Display.DrawObject(rhobj, xform);
                    }
                }
            }
        }
Ejemplo n.º 11
0
 /// <example>
 /// <code source='examples\vbnet\ex_orientonsrf.vb' lang='vbnet'/>
 /// <code source='examples\cs\ex_orientonsrf.cs' lang='cs'/>
 /// <code source='examples\py\ex_orientonsrf.py' lang='py'/>
 /// </example>
 public DocObjects.ObjRef Object(int index)
 {
   DocObjects.ObjRef rc = new Rhino.DocObjects.ObjRef();
   IntPtr ptr = NonConstPointer();
   UnsafeNativeMethods.CRhinoGetObject_Object(ptr, index, rc.NonConstPointer());
   return rc;
 }
Ejemplo n.º 12
0
 public bool SetObjRef(int id, ObjRef value)
 {
   IntPtr pThis = NonConstPointer();
   IntPtr pConstObjRef = value.ConstPointer();
   return UnsafeNativeMethods.CRhinoHistory_SetObjRef(pThis, id, pConstObjRef);
 }
Ejemplo n.º 13
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter;

            Rhino.DocObjects.ObjRef objref;
            Result rc = Rhino.Input.RhinoGet.GetOneObject("Select first/main polysurface or surface to bool",
                                                          false, geometryFilter, out objref);

            if (rc != Rhino.Commands.Result.Success)
            {
                return(rc);
            }
            if (objref == null)
            {
                return(Rhino.Commands.Result.Failure);
            }

            Rhino.Geometry.Brep brep = objref.Brep();
            bool resIssolid          = brep.IsSolid;

            if (!resIssolid)
            {
                Dialogs.ShowMessage("Your polysurface or surface is not solid! Result might not be valid!", "Warning!");
            }
            Guid firstBrep = objref.ObjectId;

            doc.Objects.UnselectAll(true);


            //Select rest of polysurfaces or surfaces to bool
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select rest of polysurfaces or surfaces to bool");
            go.GeometryFilter = geometryFilter | Rhino.DocObjects.ObjectType.InstanceReference;
            go.GroupSelect    = true;
            go.GetMultiple(1, 0);

            bool isSolid = true;

            //Add set to breps list
            List <Rhino.Geometry.Brep> breps = new List <Rhino.Geometry.Brep>();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                //Explode if instance object and add to breps list
                if (go.Object(i).Object() is InstanceObject)
                {
                    InstanceObject     instObj = go.Object(i).Object() as InstanceObject;
                    RhinoObject[]      explodedObjects;
                    ObjectAttributes[] attributesOfExplodedObjects;
                    Transform[]        transformOfExplodedObjects;

                    instObj.Explode(false, out explodedObjects, out attributesOfExplodedObjects, out transformOfExplodedObjects);
                    Guid addedObjectID = doc.Objects.Add(explodedObjects[0].Geometry, explodedObjects[0].Attributes);

                    ObjRef objrefs            = new Rhino.DocObjects.ObjRef(addedObjectID);
                    Rhino.Geometry.Brep brepd = objrefs.Brep();

                    brepd.Transform(transformOfExplodedObjects[0]);

                    resIssolid = brepd.IsSolid;
                    if (!resIssolid)
                    {
                        isSolid = false;
                    }
                    if (brepd != null && firstBrep != addedObjectID)
                    {
                        breps.Add(brepd);
                    }
                    doc.Objects.Delete(addedObjectID, true);
                }
                else
                {
                    Rhino.DocObjects.ObjRef objrefs = go.Object(i);
                    Rhino.Geometry.Brep     brepd   = objrefs.Brep();
                    resIssolid = brepd.IsSolid;
                    if (!resIssolid)
                    {
                        isSolid = false;
                    }
                    if (brepd != null && firstBrep != objrefs.ObjectId)
                    {
                        breps.Add(brepd);
                    }
                }
            }
            if (!isSolid)
            {
                Dialogs.ShowMessage("At least on polysurface or surface to subtract is not solid! Result might not be valid!", "Warning!");
            }

            doc.Objects.UnselectAll(true);

            //Create layers for failed and successfull booleans if not already existing
            var fail_layer_index = doc.Layers.FindName("FJ Boolean Fails");

            if (fail_layer_index == null)
            {
                string name_fail_layer          = "FJ Boolean Fails";
                Rhino.DocObjects.Layer boolFail = new Rhino.DocObjects.Layer();
                boolFail.Name  = name_fail_layer;
                boolFail.Color = System.Drawing.Color.Red;
                doc.Layers.Add(boolFail);
                fail_layer_index = doc.Layers.FindName(name_fail_layer);
            }

            var done_layer_index = doc.Layers.FindName("FJ Boolean Done");

            if (done_layer_index == null)
            {
                string name_done_layer          = "FJ Boolean Done";
                Rhino.DocObjects.Layer boolDone = new Rhino.DocObjects.Layer();
                boolDone.Name  = name_done_layer;
                boolDone.Color = System.Drawing.Color.BlueViolet;
                doc.Layers.Add(boolDone);
                done_layer_index = doc.Layers.FindName(name_done_layer);
            }

            //Compute boolean union
            double tolerance = doc.ModelAbsoluteTolerance;
            int    a         = 0;

            for (int i = 0; i < breps.Count; i++)
            {
                RhinoApp.WriteLine("computing number: " + i + " of: " + breps.Count + " operations...");

                List <Brep> brepBool = new List <Brep>();
                brepBool.Add(brep);
                brepBool.Add(breps[i]);
                Rhino.Geometry.Brep[] brepBoolNew = Rhino.Geometry.Brep.CreateBooleanUnion(brepBool, tolerance, true);

                if (brepBoolNew == null || brepBoolNew.Length > 1)
                {
                    a++;
                    doc.Objects.Delete(go.Object(i).Object());

                    var    boolresultfail = doc.Objects.AddBrep(breps[i]);
                    ObjRef objFailref     = new ObjRef(boolresultfail);
                    Rhino.DocObjects.RhinoObject objFail = objFailref.Object();
                    objFail.Attributes.LayerIndex = fail_layer_index.Index;
                    objFail.CommitChanges();
                }
                else
                {
                    brep = brepBoolNew[0];
                    doc.Objects.Delete(go.Object(i).Object());

                    var    boolresult = doc.Objects.AddBrep(breps[i]);
                    ObjRef obj20ref   = new ObjRef(boolresult);
                    Rhino.DocObjects.RhinoObject obj2Org = obj20ref.Object();
                    obj2Org.Attributes.LayerIndex = done_layer_index.Index;
                    obj2Org.CommitChanges();
                }

                doc.Views.Redraw();
            }

            RhinoApp.WriteLine(a + " of " + breps.Count + " operations failed!");

            Rhino.DocObjects.RhinoObject obj1Org = objref.Object();
            doc.Objects.Delete(obj1Org);

            doc.Objects.AddBrep(brep);

            doc.Views.Redraw();
            return(Rhino.Commands.Result.Success);
        }
Ejemplo n.º 14
0
 public static bool ToLinearDimension_Secondary(object data, ref LinearDimension rc)
 {
     if (data != null)
     {
         Guid gUID = data.GetType().GUID;
         Guid guid3 = gUID;
         if ((guid3 == GH_TypeLib.id_guid) || (guid3 == GH_TypeLib.id_gh_guid))
         {
             Guid guid2;
             if (gUID == GH_TypeLib.id_guid)
             {
                 guid2 = (Guid)data;
             }
             else
             {
                 guid2 = ((GH_Guid)data).Value;
             }
             Rhino.DocObjects.ObjRef refer = new ObjRef((Guid)guid2);
             LinearDimension dimension = (LinearDimension)refer.Geometry();
             if (dimension != null)
             {
                 rc = (LinearDimension)dimension.Duplicate();
                 return true;
             }
         }
         return false;
     }
     return false;
 }
Ejemplo n.º 15
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.

            MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;

            if (p.if_painted_object_set_ == false)
            {
                RhinoApp.WriteLine("No mesh");
                return(Result.Failure);
            }
            Mesh my_mesh = p.painted_object_;

            DijkstraGraph my_graph = p.graph;

            GetObject gbrep1 = new GetObject();

            gbrep1.SetCommandPrompt("get the brep");
            gbrep1.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep1.SubObjectSelect = false;
            gbrep1.Get();
            if (gbrep1.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep1.CommandResult());
            }
            Rhino.DocObjects.ObjRef      my_objref1 = gbrep1.Object(0);
            Rhino.DocObjects.RhinoObject my_obj1    = my_objref1.Object();
            if (my_obj1 == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep1 = my_objref1.Brep();

            if (brep1 == null)
            {
                return(Result.Failure);
            }
            my_obj1.Select(false);

            GetObject gbrep2 = new GetObject();

            gbrep2.SetCommandPrompt("get the brep");
            gbrep2.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep2.SubObjectSelect = false;
            gbrep2.Get();
            if (gbrep2.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep2.CommandResult());
            }
            Rhino.DocObjects.ObjRef      my_objref2 = gbrep2.Object(0);
            Rhino.DocObjects.RhinoObject my_obj2    = my_objref2.Object();
            if (my_obj2 == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep2 = my_objref2.Brep();

            if (brep2 == null)
            {
                return(Result.Failure);
            }
            my_obj2.Select(false);

            Point3d pin_1_position = brep1.UserDictionary.GetPoint3d("CurrentPosition");
            Point3d pin_2_position = brep2.UserDictionary.GetPoint3d("CurrentPosition");
            Guid    pin_1_id       = brep1.UserDictionary.GetGuid("PinID");
            Guid    pin_2_id       = brep2.UserDictionary.GetGuid("PinID");

            MeshPoint pin_1_meshpoint = my_mesh.ClosestMeshPoint(pin_1_position, 0);
            MeshPoint pin_2_meshpoint = my_mesh.ClosestMeshPoint(pin_2_position, 0);
            Stopwatch watch           = new Stopwatch();

            watch.Start();
            NurbsCurve d_path = my_graph.DijkstraPath_Add(pin_1_meshpoint, pin_1_id, pin_2_meshpoint, pin_2_id);

            watch.Stop();
            if (d_path == null)
            {
                return(Result.Success);
            }
            RhinoApp.WriteLine("link time: {0}", watch.Elapsed);
            ObjectAttributes my_attributes = new ObjectAttributes();

            my_attributes.ObjectColor      = Color.Yellow;
            my_attributes.ColorSource      = ObjectColorSource.ColorFromObject;
            my_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject;
            my_attributes.PlotWeight       = 2.0;

            doc.Objects.AddCurve(d_path, my_attributes);
            doc.Views.Redraw();

            return(Result.Success);
        }
Ejemplo n.º 16
0
        protected override void onClickOculusTrigger(ref VREvent_t vrEvent)
        {
            primaryDeviceIndex = vrEvent.trackedDeviceIndex;
            if (currentState != State.READY || targetPRhObjID == Guid.Empty)
            {
                return;
            }

            pointOnObjRef = new ObjRef(targetPRhObjID);
            //chage to only raycasting to the obj where we draw, if not snap to the origin
            if (!(projectP.X == 0 && projectP.Y == 0 && projectP.Z == 0))
            {
                rayCastingObjs.Clear();
                rayCastingObjs.Add(pointOnObjRef);
            }

            //testing
            Vector3 projectPVR = UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(projectP));

            mScene.iPointList.Add(UtilOld.platformToVRPoint(ref mScene, projectPVR)); //not use at the current version, point is VR coordinate
            pointsList.Add(projectP);

            //render edit points in VR
            Geometry.Geometry geo = new Geometry.DrawPointMarker(new Vector3(0, 0, 0));
            Material.Material m   = new Material.SingleColorMaterial(0, 1, 0, 1);
            SceneNode         editPointSN;

            UtilOld.MarkPointVR(ref mScene, projectPVR, ref geo, ref m, out editPointSN);
            pointMarkers.Add(editPointSN);

            //TODO-hide two other design plane
            if (pointMarkers.Count == 1)
            {
                if (pointOnObjRef != null && drawnType == DrawnType.Plane)
                {
                    if (!(projectP.X == 0 && projectP.Y == 0 && projectP.Z == 0))
                    {
                        UtilOld.hideOtherPlanes(ref mScene, pointOnObjRef.Object().Attributes.Name);
                    }
                    computeContourCurve();
                }
                //TODO- how to find the curvePlane on the surface like teapot body, using the normal of first point?
                //do we need to use different ways for patch surface and other generated surface
                else if (pointOnObjRef != null && drawnType == DrawnType.Surface)
                {
                    computeContourCurve();
                }
            }

            if (maxNumPoint == pointMarkers.Count)
            {
                //Assume we always can find a curvePlane sicnce we use a huge tolerance
                NurbsCurve modelcurve = null;
                Brep       modelBrep;
                string     modelName = "";
                if (shapeType == ShapeType.Circle)
                {
                    float  radius = (float)Math.Sqrt(Math.Pow(pointsList[1].X - pointsList[0].X, 2) + Math.Pow(pointsList[1].Y - pointsList[0].Y, 2) + Math.Pow(pointsList[1].Z - pointsList[0].Z, 2));
                    Circle circle = new Rhino.Geometry.Circle(curvePlane, pointsList[0], radius);
                    modelcurve = circle.ToNurbsCurve();
                    modelName  = "Circle";
                }
                else if (shapeType == ShapeType.Rect)
                {
                    Vector3 rectDiagonalV = new Vector3((float)(pointsList[0].X - pointsList[1].X), (float)(pointsList[0].Y - pointsList[1].Y), (float)(pointsList[0].Z - pointsList[1].Z));
                    float   lenDiagonal   = rectDiagonalV.Length;
                    Vector3 rectLeftTop   = new Vector3((float)pointsList[0].X, (float)pointsList[0].Y, (float)pointsList[0].Z) + lenDiagonal * rectDiagonalV.Normalized();
                    Point3d topLeftP      = new Point3d(rectLeftTop.X, rectLeftTop.Y, rectLeftTop.Z);

                    Rectangle3d rect = new Rectangle3d(curvePlane, topLeftP, pointsList[1]);

                    //using top-left cornel and bottom right

                    //Rectangle3d rect = new Rectangle3d(curvePlane, pointsList[0], pointsList[1]);

                    modelcurve = rect.ToNurbsCurve();
                    modelName  = "Rect";
                }

                /*
                 * Brep[] shapes = Brep.CreatePlanarBreps(modelcurve);
                 * modelBrep = shapes[0];
                 * Guid guid = Util.addRhinoObjectSceneNode(ref mScene, ref modelBrep, ref profile_m, modelName, out renderObjSN);
                 */

                //generate new curveOnObj for mvoingPlane cases sicne and move the XYZPlanes to origial positons
                if (drawnType == DrawnType.Plane)
                {
                    Rhino.Geometry.Vector3d newNormal = new Rhino.Geometry.Vector3d();;
                    Point3d newOrigin   = new Point3d();
                    String  planeName   = pointOnObjRef.Object().Attributes.Name;
                    Point3d planeOrigin = pointOnObjRef.Object().Geometry.GetBoundingBox(true).Center;
                    if (planeName.Contains("planeXY"))
                    {
                        newNormal = new Rhino.Geometry.Vector3d(0, 0, 1);
                        newOrigin = new Point3d(0, 0, planeOrigin.Z);
                    }
                    else if (planeName.Contains("planeYZ"))
                    {
                        newNormal = new Rhino.Geometry.Vector3d(1, 0, 0);
                        newOrigin = new Point3d(planeOrigin.X, 0, 0);
                    }
                    else if (planeName.Contains("planeXZ"))
                    {
                        newNormal = new Rhino.Geometry.Vector3d(0, 1, 0);
                        newOrigin = new Point3d(0, planeOrigin.Y, 0);
                    }

                    Plane        newPlane      = new Plane(newOrigin, newNormal);
                    int          size          = 240;
                    PlaneSurface plane_surface = new PlaneSurface(newPlane, new Interval(-size, size), new Interval(-size, size));
                    Brep         newPlaneBrep  = Brep.CreateFromSurface(plane_surface);

                    Guid newPlaneID = UtilOld.addRhinoObject(ref mScene, ref newPlaneBrep, "MoveP");
                    //might be better to use Replace(), just need to be careful about the referece count
                    pointOnObjRef = null;
                    pointOnObjRef = new ObjRef(newPlaneID);

                    modelcurve.SetUserString(CurveData.CurveOnObj.ToString(), newPlaneID.ToString());
                    modelcurve.SetUserString(CurveData.PlaneOrigin.ToString(), newPlane.Origin.ToString());
                    modelcurve.SetUserString(CurveData.PlaneNormal.ToString(), newPlane.Normal.ToString());
                }
                else if (drawnType == DrawnType.Surface)
                {
                    modelcurve.SetUserString(CurveData.CurveOnObj.ToString(), pointOnObjRef.ObjectId.ToString());
                    modelcurve.SetUserString(CurveData.PlaneOrigin.ToString(), curvePlane.Origin.ToString());
                    modelcurve.SetUserString(CurveData.PlaneNormal.ToString(), curvePlane.Normal.ToString());
                }

                mScene.iCurveList.Add(modelcurve);

                //call next interaction in the chain
                afterCurveCount = mScene.iCurveList.Count;
                mScene.pushInteractionFromChain();
                currentState = State.READY;
            }
        }
Ejemplo n.º 17
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.

            MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;

            if (p.if_painted_object_set_ == false)
            {
                RhinoApp.WriteLine("No mesh");
                return(Result.Failure);
            }
            Mesh my_mesh = p.painted_object_;

            DijkstraGraph my_graph = p.graph;

            GetObject gbrep = new GetObject();

            gbrep.SetCommandPrompt("get the brep");
            gbrep.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep.SubObjectSelect = false;
            gbrep.Get();
            if (gbrep.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep.CommandResult());
            }
            Rhino.DocObjects.ObjRef      my_objref = gbrep.Object(0);
            Rhino.DocObjects.RhinoObject my_obj    = my_objref.Object();
            if (my_obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep = my_objref.Brep();

            if (brep == null)
            {
                return(Result.Failure);
            }
            my_obj.Select(false);

            int         pin_number_1         = My_object_functions.GetPinQuantity(brep);
            List <Guid> pin_ball_guid_list_1 = new List <Guid>();

            for (int i = 0; i < pin_number_1; i++)
            {
                ObjectAttributes green_ball_attributes = new ObjectAttributes();
                green_ball_attributes.ObjectColor = Color.Green;
                green_ball_attributes.ColorSource = ObjectColorSource.ColorFromObject;

                Point3d pin_position = My_object_functions.GetPinPosition(brep, i);
                Guid    pin_id       = My_object_functions.GetPinGuid(brep, i);
                green_ball_attributes.ObjectId = pin_id;
                green_ball_attributes.UserDictionary.Set("isPin", true);
                Sphere pin_ball = new Sphere(pin_position, 2);
                //Brep pin_ball_brep = pin_ball.ToBrep();
                doc.Objects.AddSphere(pin_ball, green_ball_attributes);
                pin_ball_guid_list_1.Add(pin_id);
            }
            doc.Views.Redraw();

            GetObject g_pinball = new GetObject();

            g_pinball.SetCommandPrompt("choose the pin");
            g_pinball.GeometryFilter = ObjectType.Surface;
            //g_pinball.SetCustomGeometryFilter(PinBallGeometryFilter);
            //g_pinball.DisablePreSelect();
            g_pinball.SubObjectSelect = false;
            g_pinball.Get();
            if (g_pinball.CommandResult() != Result.Success)
            {
                return(g_pinball.CommandResult());
            }
            if (g_pinball.Object(0).Brep() == null)
            {
                return(Result.Failure);
            }

            RhinoObject selected_pin_ball    = g_pinball.Object(0).Object();
            Guid        selected_pin_ball_id = selected_pin_ball.Id;

            for (int i = 0; i < pin_ball_guid_list_1.Count; i++)
            {
                doc.Objects.Delete(pin_ball_guid_list_1[i], true);
            }

            ObjectAttributes greenyellow_ball_attributes = new ObjectAttributes();

            greenyellow_ball_attributes.ObjectColor = Color.GreenYellow;
            greenyellow_ball_attributes.ColorSource = ObjectColorSource.ColorFromObject;
            greenyellow_ball_attributes.ObjectId    = selected_pin_ball_id;
            greenyellow_ball_attributes.UserDictionary.Set("isPin", true);
            int     pin_number            = My_object_functions.FindPinNumber(brep, selected_pin_ball_id);
            Point3d selected_pin_position = My_object_functions.GetPinPosition(brep, pin_number);
            Sphere  pin_ball_new          = new Sphere(selected_pin_position, 2);

            doc.Objects.AddSphere(pin_ball_new, greenyellow_ball_attributes);


            doc.Views.Redraw();

            //MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;
            if (p.my_objects_list.Count <= 1)
            {
                RhinoApp.WriteLine("not enough objects");
                return(Result.Failure);
            }

            List <Guid> pin_ball_guid_list_2 = new List <Guid>();

            for (int i = 0; i < p.my_objects_list.Count; i++)
            {
                Brep an_object = p.my_objects_list[i];
                if (My_object_functions.GetComponentID(brep) != My_object_functions.GetComponentID(an_object))
                {
                    int pin_quantity = My_object_functions.GetPinQuantity(an_object);
                    for (int j = 0; j < pin_quantity; j++)
                    {
                        ObjectAttributes green_ball_attributes = new ObjectAttributes();
                        green_ball_attributes.ObjectColor = Color.Green;
                        green_ball_attributes.ColorSource = ObjectColorSource.ColorFromObject;
                        Point3d pin_position = My_object_functions.GetPinPosition(an_object, j);
                        Guid    pin_id       = My_object_functions.GetPinGuid(an_object, j);
                        green_ball_attributes.ObjectId = pin_id;
                        green_ball_attributes.UserDictionary.Set("isPin", true);
                        Sphere pin_ball = new Sphere(pin_position, 2);
                        doc.Objects.AddSphere(pin_ball, green_ball_attributes);
                        pin_ball_guid_list_2.Add(pin_id);
                    }
                }
            }
            doc.Views.Redraw();

            GetObject g_pinball_2 = new GetObject();

            g_pinball_2.SetCommandPrompt("choose the pin");
            g_pinball_2.GeometryFilter = ObjectType.Surface;
            //g_pinball.SetCustomGeometryFilter(PinBallGeometryFilter);
            //g_pinball.DisablePreSelect();
            g_pinball_2.SubObjectSelect = false;
            g_pinball_2.Get();
            if (g_pinball_2.CommandResult() != Result.Success)
            {
                return(g_pinball_2.CommandResult());
            }
            if (g_pinball_2.Object(0).Brep() == null)
            {
                return(Result.Failure);
            }

            RhinoObject selected_pin_ball_2    = g_pinball_2.Object(0).Object();
            Guid        selected_pin_ball_id_2 = selected_pin_ball_2.Id;
            Brep        brep_2 = null;

            for (int i = 0; i < p.my_objects_list.Count; i++)
            {
                Brep an_object    = p.my_objects_list[i];
                int  pin_quantity = My_object_functions.GetPinQuantity(an_object);
                bool mark         = false;
                for (int j = 0; j < pin_quantity; j++)
                {
                    if (My_object_functions.GetPinGuid(an_object, j) == selected_pin_ball_id_2)
                    {
                        mark = true;
                        break;
                    }
                }
                if (mark)
                {
                    brep_2 = an_object;
                    break;
                }
            }
            if (brep_2 == null)
            {
                return(Result.Failure);
            }

            int selected_pin_number_2 = My_object_functions.FindPinNumber(brep_2, selected_pin_ball_id_2);

            for (int i = 0; i < pin_ball_guid_list_2.Count; i++)
            {
                doc.Objects.Delete(pin_ball_guid_list_2[i], true);
            }

            Point3d selected_pin_position_2 = My_object_functions.GetPinPosition(brep_2, selected_pin_number_2);

            Sphere pin_ball_new_2 = new Sphere(selected_pin_position_2, 2);

            greenyellow_ball_attributes.ObjectId = selected_pin_ball_id_2;

            doc.Objects.AddSphere(pin_ball_new_2, greenyellow_ball_attributes);

            doc.Views.Redraw();

            MeshPoint  pin_1_meshpoint = my_mesh.ClosestMeshPoint(selected_pin_position, 0);
            MeshPoint  pin_2_meshpoint = my_mesh.ClosestMeshPoint(selected_pin_position_2, 0);
            NurbsCurve d_path          = my_graph.DijkstraPath_Add(pin_1_meshpoint, selected_pin_ball_id, pin_2_meshpoint, selected_pin_ball_id_2);


            if (d_path != null)
            {
                ObjectAttributes path_attributes = new ObjectAttributes();
                path_attributes.ObjectColor      = Color.Yellow;
                path_attributes.ColorSource      = ObjectColorSource.ColorFromObject;
                path_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject;
                path_attributes.PlotWeight       = 2.0;
                path_attributes.ObjectId         = d_path.UserDictionary.GetGuid("PathID");
                doc.Objects.AddCurve(d_path, path_attributes);
            }



            doc.Objects.Delete(selected_pin_ball_id, true);
            doc.Objects.Delete(selected_pin_ball_id_2, true);

            doc.Views.Redraw();



            return(Result.Success);
        }
Ejemplo n.º 18
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.ApplicationSettings.HistorySettings.RecordingEnabled = true;
            double tolerance = doc.ModelAbsoluteTolerance;

            GetObject gc = new GetObject();

            gc.SetCommandPrompt("Select curve(s) for multipipe");
            gc.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            gc.GroupSelect    = true;
            gc.GetMultiple(1, 0);

            if (gc.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gc.CommandResult());
            }

            List <Curve> curves = new List <Curve>();

            for (int i = 0; i < gc.ObjectCount; i++)
            {
                Rhino.DocObjects.ObjRef objref = gc.Object(i);
                Rhino.Geometry.Curve    curve  = objref.Curve();
                curves.Add(curve);
                ids.Add(objref.ObjectId);
            }


            Rhino.Input.Custom.GetNumber gn = new Rhino.Input.Custom.GetNumber();
            gn.SetCommandPrompt("Start and end radius");
            int opList = gn.AddOptionList("Cap", caps, capIndex);

            gn.SetDefaultNumber(radius1);

            while (true)
            {
                Rhino.Input.GetResult get_rc = gn.Get();
                if (gn.CommandResult() != Rhino.Commands.Result.Success)
                {
                    return(gn.CommandResult());
                }

                if (get_rc == Rhino.Input.GetResult.Number)
                {
                    radius1 = gn.Number();
                    if (radius1 < 0 || radius1 < 0.0)
                    {
                        Dialogs.ShowMessage("Value must be >= 0.0", "Warning!");
                        continue;
                    }
                }


                else if (get_rc == Rhino.Input.GetResult.Option)
                {
                    if (gn.OptionIndex() == opList)
                    {
                        capIndex = gn.Option().CurrentListOptionIndex;
                    }
                    continue;
                }

                break;
            }



            while (true)
            {
                RhinoGet.GetNumber("Middle radius", false, ref radius2);
                if (radius2 <= 0 || radius2 <= 0.0)
                {
                    Dialogs.ShowMessage("Value must be > 0.0", "Warning!");
                    continue;
                }

                break;
            }



            Brep[] pipe;

            double[]      radiParam = { 0.0, 0.5, 1.0 };
            double[]      radi      = { radius1, radius2, radius1 };
            PipeCapMode[] pCapM     = { PipeCapMode.None, PipeCapMode.Flat, PipeCapMode.Round };

            // Create a history record
            Rhino.DocObjects.HistoryRecord history = new Rhino.DocObjects.HistoryRecord(this, HISTORY_VERSION);
            WriteHistory(history, ids, radius1, radius2, capIndex);

            foreach (Curve x in curves)
            {
                pipe = Brep.CreatePipe(x, radiParam, radi, true, pCapM[capIndex], true, doc.ModelAbsoluteTolerance, doc.ModelAngleToleranceRadians);
                doc.Objects.AddBrep(pipe[0], null, history, false);
                doc.Views.Redraw();
            }


            doc.Views.Redraw();
            return(Result.Success);
        }
Ejemplo n.º 19
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            double tolerance = doc.ModelAbsoluteTolerance;

            List <Curve> icur = new List <Curve>();

            GetObject gcr = new Rhino.Input.Custom.GetObject();

            gcr.SetCommandPrompt("Select reference circles for stones. (No curves)");
            gcr.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
            gcr.GroupSelect                 = true;
            gcr.SubObjectSelect             = true;
            gcr.DeselectAllBeforePostSelect = true;
            gcr.OneByOnePostSelect          = false;
            gcr.GetMultiple(1, 0);

            for (int ie = 0; ie < gcr.ObjectCount; ie++)
            {
                Rhino.DocObjects.ObjRef      objref = gcr.Object(ie);
                Rhino.DocObjects.RhinoObject obj    = objref.Object();
                if (obj == null)
                {
                    return(Result.Failure);
                }
                Curve refcr = objref.Curve();
                if (refcr == null)
                {
                    return(Result.Failure);
                }
                obj.Select(false);

                icur.Add(refcr);
            }
            var rm = FindMaterial(doc, "Diamond");

            if (null == rm)
            {
                //Didn't find the material - create one and carry on.

                //Create a basic material
                var custom = new Rhino.DocObjects.Material();
                custom.Reflectivity = 1;
                custom.Transparency = 0.2;
                custom.SetEnvironmentTexture(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/Free Jewels Rhino Plug-Ins/Dia3.jpg");
                custom.Name = "Diamond";
                custom.CommitChanges();

                rm = RenderMaterial.CreateBasicMaterial(custom);

                var docMats = doc.RenderMaterials;

                //docMats.BeginChange(RenderContent.ChangeContexts.Program);
                docMats.Add(rm);
                //docMats.EndChange();
            }



            // Create Stone Mesh
            Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh();


            mesh.Vertices.Add(0.0, 0.0, -0.44);      //0

            mesh.Vertices.Add(0.0, 0.097, -0.363);   //1
            mesh.Vertices.Add(0.069, 0.069, -0.363); //2
            mesh.Vertices.Add(0.097, 0.0, -0.363);   //3

            mesh.Vertices.Add(0.0, 0.5, -0.013);     //4
            mesh.Vertices.Add(0.098, 0.49, -0.005);  //5
            mesh.Vertices.Add(0.191, 0.462, -0.013); //6
            mesh.Vertices.Add(0.278, 0.416, -0.005); //7
            mesh.Vertices.Add(0.354, 0.354, -0.013); //8
            mesh.Vertices.Add(0.416, 0.278, -0.005); //9
            mesh.Vertices.Add(0.462, 0.191, -0.013); //10
            mesh.Vertices.Add(0.49, 0.098, -0.005);  //11
            mesh.Vertices.Add(0.5, 0.0, -0.013);     //12

            mesh.Vertices.Add(0.0, 0.5, 0.013);      //13
            mesh.Vertices.Add(0.098, 0.49, 0.005);   //14
            mesh.Vertices.Add(0.191, 0.462, 0.013);  //15
            mesh.Vertices.Add(0.278, 0.416, 0.005);  //16
            mesh.Vertices.Add(0.354, 0.354, 0.013);  //17
            mesh.Vertices.Add(0.416, 0.278, 0.005);  //18
            mesh.Vertices.Add(0.462, 0.191, 0.013);  //19
            mesh.Vertices.Add(0.49, 0.098, 0.005);   //20
            mesh.Vertices.Add(0.5, 0.0, 0.013);      //21

            mesh.Vertices.Add(0.0, 0.372, 0.12);     //22
            mesh.Vertices.Add(0.263, 0.263, 0.12);   //23
            mesh.Vertices.Add(0.372, 0.0, 0.12);     //24
            mesh.Vertices.Add(0.263, -0.263, 0.12);  //25
            mesh.Vertices.Add(0.0, -0.372, 0.12);    //26
            mesh.Vertices.Add(-0.263, -0.263, 0.12); //27
            mesh.Vertices.Add(-0.372, 0.0, 0.12);    //28
            mesh.Vertices.Add(-0.263, 0.263, 0.12);  //29

            mesh.Vertices.Add(0.109, 0.263, 0.16);   //30
            mesh.Vertices.Add(0.263, 0.109, 0.16);   //31
            mesh.Vertices.Add(0.263, -0.109, 0.16);  //32
            mesh.Vertices.Add(0.109, -0.263, 0.16);  //33
            mesh.Vertices.Add(-0.109, -0.263, 0.16); //34
            mesh.Vertices.Add(-0.263, -0.109, 0.16); //35
            mesh.Vertices.Add(-0.263, 0.109, 0.16);  //36
            mesh.Vertices.Add(-0.109, 0.263, 0.16);  //37

            mesh.Vertices.Add(0.0, 0.0, 0.16);       //38

            mesh.Faces.AddFace(0, 1, 6, 2);
            mesh.Faces.AddFace(0, 2, 10, 3);

            mesh.Faces.AddFace(1, 4, 5, 6);
            mesh.Faces.AddFace(2, 6, 7, 8);
            mesh.Faces.AddFace(2, 8, 9, 10);
            mesh.Faces.AddFace(3, 10, 11, 12);

            mesh.Faces.AddFace(4, 13, 14, 5);
            mesh.Faces.AddFace(5, 14, 15, 6);
            mesh.Faces.AddFace(6, 15, 16, 7);
            mesh.Faces.AddFace(7, 16, 17, 8);
            mesh.Faces.AddFace(8, 17, 18, 9);
            mesh.Faces.AddFace(9, 18, 19, 10);
            mesh.Faces.AddFace(10, 19, 20, 11);
            mesh.Faces.AddFace(11, 20, 21, 12);

            mesh.Faces.AddFace(13, 22, 15, 14);
            mesh.Faces.AddFace(15, 23, 17, 16);
            mesh.Faces.AddFace(17, 23, 19, 18);
            mesh.Faces.AddFace(19, 24, 21, 20);

            mesh.Faces.AddFace(15, 22, 30, 23);
            mesh.Faces.AddFace(19, 23, 31, 24);

            mesh.Faces.AddFace(23, 30, 31);
            mesh.Faces.AddFace(24, 31, 32);

            mesh.Faces.AddFace(32, 31, 30, 38);

            mesh.Unweld(0.001, false);

            Mesh meshAll = new Mesh();

            for (int i = 0; i < 4; i++)
            {
                meshAll.Append(mesh);
                Point3d  center = new Point3d(0.0, 0.0, 0.0);
                Vector3d rotVec = new Vector3d(0.0, 0.0, 1.0);
                mesh.Rotate(Math.PI / 2, rotVec, center);
            }
            meshAll.Compact();
            meshAll.Weld(0.001);

            //Get object Guid to apply render material
            var         meshGuid = doc.Objects.AddMesh(meshAll);
            ObjRef      objre    = new ObjRef(meshGuid);
            RhinoObject obje     = objre.Object();

            obje.RenderMaterial = rm;
            obje.CommitChanges();

            //Make InstanceDefinition
            string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss");

            var geometry = new System.Collections.Generic.List <Rhino.Geometry.GeometryBase>()
            {
                obje.Geometry
            };
            var attributes = new System.Collections.Generic.List <Rhino.DocObjects.ObjectAttributes>()
            {
                obje.Attributes
            };


            var stoneIndex = doc.InstanceDefinitions.Add("Stone" + instDefCount, "StoneMesh 1mm", Point3d.Origin, geometry, attributes);

            List <InstanceReferenceGeometry> meshPave = new List <InstanceReferenceGeometry>();


            foreach (Curve c in icur)
            {
                Circle circle1 = new Circle();
                c.TryGetCircle(out circle1, tolerance);
                double   radius     = circle1.Diameter;
                Point3d  center     = circle1.Center;
                Vector3d moveV      = new Vector3d(center);
                Vector3d zaxis      = new Vector3d(0.0, 0.0, 1.0);
                Plane    planeOr    = new Plane(center, zaxis);
                Plane    planeNew   = circle1.Plane;
                var      transform1 = Transform.Translation(moveV);
                var      transform2 = Transform.Scale(center, radius);
                var      transform3 = Transform.PlaneToPlane(planeOr, planeNew);

                var stoneA = doc.Objects.AddInstanceObject(stoneIndex, transform1);
                var stoneB = doc.Objects.Transform(stoneA, transform2, true);
                var stoneC = doc.Objects.Transform(stoneB, transform3, true);

                ids.Add(stoneC);
            }
            doc.Groups.Add(ids);
            doc.Objects.Delete(obje);
            doc.Views.Redraw();

            return(Result.Success);
        }
Ejemplo n.º 20
0
 internal ObjRef(ObjRef other)
 {
   m_ptr = UnsafeNativeMethods.CRhinoObjRef_Copy(other.m_ptr);
 }
Ejemplo n.º 21
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;

            if (p.if_painted_object_set_ == false)
            {
                RhinoApp.WriteLine("No mesh");
                return(Result.Failure);
            }
            Mesh my_mesh = p.painted_object_;

            DijkstraGraph my_graph = p.graph;

            GetObject gbrep1 = new GetObject();

            gbrep1.SetCommandPrompt("get the brep");
            gbrep1.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep1.SubObjectSelect = false;
            gbrep1.Get();
            if (gbrep1.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep1.CommandResult());
            }
            Rhino.DocObjects.ObjRef      my_objref1 = gbrep1.Object(0);
            Rhino.DocObjects.RhinoObject my_obj1    = my_objref1.Object();
            if (my_obj1 == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep1 = my_objref1.Brep();

            if (brep1 == null)
            {
                return(Result.Failure);
            }
            my_obj1.Select(false);

            for (int i = 0; i < p.my_objects_list.Count; i++)
            {
                Guid brep1_id     = My_object_functions.GetComponentID(brep1);
                Guid my_object_id = My_object_functions.GetComponentID(p.my_objects_list[i]);
                if (brep1_id == my_object_id)
                {
                    p.my_objects_list.RemoveAt(i);
                }
            }

            IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve);

            foreach (RhinoObject path in path_objref)
            {
                doc.Objects.Delete(path, true);
            }

            List <NurbsCurve> new_path_list = new List <NurbsCurve>();
            int pin_number = My_object_functions.GetPinQuantity(brep1);

            for (int i = 0; i < pin_number; i++)
            {
                Guid pin_id = My_object_functions.GetPinGuid(brep1, i);
                new_path_list = p.graph.DijkstraPath_DeletePin(pin_id);
            }

            ObjectAttributes my_attributes = new ObjectAttributes();

            my_attributes.ObjectColor      = Color.Yellow;
            my_attributes.ColorSource      = ObjectColorSource.ColorFromObject;
            my_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject;
            my_attributes.PlotWeight       = 2.0;

            doc.Objects.Delete(my_objref1, true);

            for (int i = 0; i < new_path_list.Count; i++)
            {
                Guid path_id = new_path_list[i].UserDictionary.GetGuid("PathID");
                my_attributes.ObjectId = path_id;
                doc.Objects.Add(new_path_list[i], my_attributes);
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
Ejemplo n.º 22
0
 private Rhino.Geometry.GeometryBase ObjRefToGeometryHelper(IntPtr pGeometry)
 {
   if (pGeometry == IntPtr.Zero)
     return null;
   object parent;
   if (UnsafeNativeMethods.CRhinoObjRef_IsTopLevelGeometryPointer(m_ptr, pGeometry))
     parent = Object();
   else
     parent = new ObjRef(this); // copy in case user decides to call Dispose on this ObjRef
   return null == parent ? null : Rhino.Geometry.GeometryBase.CreateGeometryHelper(pGeometry, parent);
 }
Ejemplo n.º 23
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;

            if (p.if_painted_object_set_ == false)
            {
                RhinoApp.WriteLine("No mesh");
                return(Result.Failure);
            }
            Mesh my_mesh = p.painted_object_;

            Stopwatch watch = new Stopwatch();

            GetObject gbrep = new GetObject();

            gbrep.SetCommandPrompt("get the brep");
            gbrep.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep.SubObjectSelect = false;
            gbrep.Get();
            if (gbrep.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep.CommandResult());
            }
            Rhino.DocObjects.ObjRef      my_objref = gbrep.Object(0);
            Rhino.DocObjects.RhinoObject my_obj    = my_objref.Object();
            if (my_obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep = my_objref.Brep();

            if (brep == null)
            {
                return(Result.Failure);
            }
            my_obj.Select(false);

            GetObjectPosition gp = new GetObjectPosition(brep, my_mesh);

            gp.SetCommandPrompt("Get the object position on mesh: ");
            gp.Constrain(my_mesh, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            Brep     moved_brep     = brep.DuplicateBrep();
            Point3d  Origin         = brep.UserDictionary.GetPoint3d("CurrentPosition");
            Vector3d OriginVector   = brep.UserDictionary.GetVector3d("CurrentDirection");
            Point3d  new_position   = gp.Point();
            Vector3d normal_on_mesh = my_mesh.NormalAt(my_mesh.ClosestMeshPoint(new_position, 0));

            if (OriginVector.IsParallelTo(normal_on_mesh) == 0)
            {
                double   RotationAngle = Vector3d.VectorAngle(OriginVector, normal_on_mesh);
                Vector3d RoationAxis   = Vector3d.CrossProduct(OriginVector, normal_on_mesh);
                moved_brep.Rotate(RotationAngle, RoationAxis, Origin);
            }

            moved_brep.Translate(new_position - Origin);
            moved_brep.UserDictionary.Set("CurrentPosition", new_position);
            moved_brep.UserDictionary.Set("CurrentDirection", normal_on_mesh);

            ObjectAttributes my_attributes = new ObjectAttributes();

            my_attributes.ObjectColor = Color.FromName(moved_brep.UserDictionary.GetString("Color"));
            my_attributes.ColorSource = ObjectColorSource.ColorFromObject;

            watch.Start();
            //delete all old paths
            IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve);

            foreach (RhinoObject path in path_objref)
            {
                doc.Objects.Delete(path, true);
            }
            watch.Stop();
            RhinoApp.WriteLine("time 1: {0}", watch.Elapsed);

            ObjectAttributes path_attributes = new ObjectAttributes();

            path_attributes.ObjectColor      = Color.Yellow;
            path_attributes.ColorSource      = ObjectColorSource.ColorFromObject;
            path_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject;
            path_attributes.PlotWeight       = 2.0;


            Guid      pin_1_id          = moved_brep.UserDictionary.GetGuid("PinID");
            MeshPoint current_meshpoint = my_mesh.ClosestMeshPoint(new_position, 0.0);

            watch.Restart();
            List <NurbsCurve> new_path_list = p.graph.DijkstraPath_Change(pin_1_id, current_meshpoint);

            watch.Stop();
            RhinoApp.WriteLine("time 2: {0}", watch.Elapsed);
            watch.Restart();
            for (int i = 0; i < new_path_list.Count; i++)
            {
                doc.Objects.Add(new_path_list[i], path_attributes);
            }

            doc.Objects.Delete(my_objref, true);
            brep.Dispose();
            doc.Objects.AddBrep(moved_brep, my_attributes);
            doc.Views.Redraw();
            watch.Stop();
            RhinoApp.WriteLine("time 3: {0}", watch.Elapsed);

            return(Result.Success);
        }
Ejemplo n.º 24
0
    /// <summary>
    /// Gets the render meshes of some objects.
    /// </summary>
    /// <param name="rhinoObjects">An array, a list, or any enumerable set of Rhino objects.</param>
    /// <param name="okToCreate">true if the method is allowed to instantiate new meshes if they do not exist.</param>
    /// <param name="returnAllObjects">true if all objects should be returned.</param>
    /// <returns>An array of object references.</returns>
    public static ObjRef[] GetRenderMeshes(System.Collections.Generic.IEnumerable<RhinoObject> rhinoObjects, bool okToCreate, bool returnAllObjects)
    {
      ObjRef[] rc = null;
      Runtime.INTERNAL_RhinoObjectArray rhinoobject_array = new Rhino.Runtime.INTERNAL_RhinoObjectArray(rhinoObjects);
      IntPtr pRhObjectArray = rhinoobject_array.NonConstPointer();
      IntPtr pObjRefArray = UnsafeNativeMethods.RHC_RhinoGetRenderMeshes(pRhObjectArray, okToCreate, returnAllObjects);
      rhinoobject_array.Dispose();

      if (IntPtr.Zero != pObjRefArray)
      {
        int count = UnsafeNativeMethods.RhinoObjRefArray_Count(pObjRefArray);
        if (count > 0)
        {
          rc = new ObjRef[count];
          for (int i = 0; i < count; i++)
          {
            IntPtr pConstObjRef = UnsafeNativeMethods.RhinoObjRefArray_GetItem(pObjRefArray, i);
            rc[i] = new ObjRef(pConstObjRef);
          }
        }
      }
      UnsafeNativeMethods.RhinoObjRefArray_Delete(pObjRefArray);
      return rc;
    }
Ejemplo n.º 25
0
 /// <summary>
 /// In ReplayHistory, use GetRhinoObjRef to convert the information
 /// in a history record into the ObjRef that has up to date
 /// RhinoObject pointers
 /// </summary>
 /// <param name="id">HistoryRecord value id</param>
 /// <returns>ObjRef on success, null if not successful</returns>
 public Rhino.DocObjects.ObjRef GetRhinoObjRef(int id)
 {
   ObjRef objref = new ObjRef();
   IntPtr pObjRef = objref.NonConstPointer();
   if (UnsafeNativeMethods.CRhinoHistoryRecord_GetRhinoObjRef(m_pConstRhinoHistoryRecord, id, pObjRef))
     return objref;
   return null;
 }
Ejemplo n.º 26
0
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            nishanchiPlugin pluginObj = ((nishanchiPlugin)this.PlugIn);

            Boolean selectedObjectIsBrep = false;
            Boolean selectedObjectIsCurve = false;

            if (!pluginObj.trackerConnected)
            {
                RhinoApp.WriteLine("Tracker disconnected");
                return Rhino.Commands.Result.Failure;
            }
            connectKbEvt();

            //Ask the user to select Breps to print.
            //Result rc = Rhino.Input.RhinoGet.GetMultipleObjects("Select the surfaces to print",
            //false, Rhino.DocObjects.ObjectType.Surface, out objrefs);

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select the entity to print");
            go.GroupSelect = true;

            //Set this to go.GetMultiple(0,0) if you want to allow multiple entities to be selected
            go.GetMultiple(0, 1);

            Result rc = go.CommandResult();

            if (rc != Rhino.Commands.Result.Success)
            {
                disconnectKbEvt();
                return rc;
            }

            List<Rhino.Geometry.Brep> breps = new List<Rhino.Geometry.Brep>();
            List<Rhino.Geometry.Curve> curves = new List<Rhino.Geometry.Curve>();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                ObjRef tmpRef = new ObjRef(go.Object(i).ObjectId);
                Rhino.Geometry.Brep brep = tmpRef.Brep();
                if (brep != null)
                {
                    breps.Add(brep);
                    selectedObjectIsBrep = true;
                }

                Rhino.Geometry.Curve curve = tmpRef.Curve();
                if (curve != null)
                {
                    curves.Add(curve);
                    selectedObjectIsCurve = true;
                }

            }
            if (selectedObjectIsBrep)
                RhinoApp.WriteLine("Selected " + breps.Count + " surfaces! Good! No, not, really, I'm just a program, I couldn't care less.");

            if (selectedObjectIsCurve)
                RhinoApp.WriteLine("Selected " + curves.Count + " curves! Good! No, not, really, I'm just a program, I couldn't care less.");

            createEntities(doc);

            fastrak trackerObj = pluginObj.trackerObj;
            int numPoints = 0;
            int numIntersections = 0;
            Boolean retval;

            RhinoApp.WriteLine(string.Format("Starting continuous mode on the tracker."));
            pluginObj.trackerObj.setContinuous();
            RhinoApp.WriteLine(string.Format("Printing mode enabled now."));

            Curve[] intersectionCurves;
            Point3d[] intersectionPoints;

            running = true;
            while (running)
            {
                retval = trackerObj.readFrame();
                if (retval)
                {
                    //q0,q1,q2,q3 Quaternion begin
                    //Compute the rotation matrix
                    rxTxTx = new Point3d(trackerObj.x, trackerObj.y, trackerObj.z);
                    orientationQuat = new Quaternion(trackerObj.q0, trackerObj.q1, trackerObj.q2, trackerObj.q3);
                    orientationQuat.GetRotation(out angle, out axis);
                    rotMat = Transform.Rotation(angle, axis, origin);

                    // Compute the new positions for the nozzlePoints and also compute the new lines
                    for (int i = 0; i < numNozzles; i++)
                    {
                        nozzleStartPointRxTx[i] = rotMat * nozzleStartPointRxRx[i];
                        nozzleStartPointTxTx[i] = nozzleStartPointRxTx[i] + rxTxTx;

                        nozzleEndPointRxTx[i] = rotMat * nozzleEndPointRxRx[i];
                        nozzleEndPointTxTx[i] = nozzleEndPointRxTx[i] + rxTxTx;

                        nozzleLinesTx[i] = new Line(nozzleStartPointTxTx[i], nozzleEndPointTxTx[i]);
                        nozzleCurves[i] = new LineCurve(nozzleLinesTx[i]);
                    }

                    numIntersections = 0;
                    if (selectedObjectIsBrep)
                    {
                        for (int i = 0; i < numNozzles; i++)
                        {
                            foreach (Brep b in breps)
                            {
                                try
                                {
                                    Intersection.CurveBrep(nozzleCurves[i], b, nozzleTolerance, out intersectionCurves, out intersectionPoints);
                                    if (intersectionPoints.Length > 0)
                                    {
                                        intersectionsBits[i] = 1;
                                        numIntersections++;
                                    }
                                    else
                                    {
                                        intersectionsBits[i] = 0;
                                    }
                                }
                                catch (Exception e)
                                {
                                    RhinoApp.WriteLine(e.Message);
                                }
                            }
                        }
                    }

                    if (selectedObjectIsCurve)
                    {
                        for (int i = 0; i < numNozzles; i++)
                        {
                            foreach (Curve c in curves)
                            {
                                try
                                {
                                    var events = Intersection.CurveCurve(nozzleCurves[i], c, nozzleTolerance, nozzleTolerance);
                                    if (events != null)
                                    {
                                        if (events.Count >= 1)
                                        {
                                            intersectionsBits[i] = 1;
                                            numIntersections++;
                                        }
                                        else
                                        {
                                            intersectionsBits[i] = 0;
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    RhinoApp.WriteLine(e.Message);
                                }
                            }
                        }
                    }

                    if (pluginObj.printHeadConnected)
                    {
                        // I print
                        if (((numPoints % 5) == 0)&&(numIntersections > 0))
                        {
                            string p = printCommand();
                            //RhinoApp.WriteLine(p);
                            pluginObj.printHeadObj.printFrame(p);
                            //pluginObj.printHeadObj.printFullLine();
                        }
                    }

                    numPoints++;
                }

                //And, I move the printer like thing on the screen
                if ((numPoints % 10) == 0)
                {
                    for (int i = 0; i < numNozzles; i++)
                    {
                        doc.Objects.Delete(lineGuids[i],false);
                        lineGuids[i] = doc.Objects.AddLine(nozzleLinesTx[i]);
                    }
                    doc.Objects.Delete(ballGuid, false);
                    ball = new Sphere(rxTxTx, ballRadius);
                    ballGuid = doc.Objects.AddSphere(ball);

                    doc.Views.ActiveView.Redraw();
                    RhinoApp.Wait();
                }
            }

            running = false;
            removeEntities(doc);

            RhinoApp.WriteLine(string.Format("Stopping continuous mode on the tracker."));
            pluginObj.trackerObj.stopContinuous();
            disconnectKbEvt();
            RhinoApp.WriteLine(string.Format("I guess you don't wanna print anymore, well who cares! Not me!"));
            return Rhino.Commands.Result.Success;
        }
Ejemplo n.º 27
0
 public bool SetPoint3dOnObject(int id, ObjRef objref, Rhino.Geometry.Point3d value)
 {
   IntPtr pThis = NonConstPointer();
   IntPtr pConstObjRef = objref.ConstPointer();
   return UnsafeNativeMethods.CRhinoHistory_SetPoint3dOnObject(pThis, id, pConstObjRef, value);
 }
Ejemplo n.º 28
0
        protected override void onClickOculusAX(ref VREvent_t vrEvent)
        {
            //TODO-support projection curve
            Point3d planeCenter = new Point3d();

            if (!isProjection)
            {
                Brep[] shapes = Brep.CreatePlanarBreps(modelcurve);
                modelBrep = shapes[0];
                //Util.addRhinoObjectSceneNode(ref mScene, ref modelBrep, ref mesh_m, shapeType.ToString(), out renderObjSN);
                UtilOld.addSceneNode(ref mScene, ref modelBrep, ref mesh_m, shapeType.ToString(), out renderObjSN);

                if (shapeType == ShapeType.Circle)
                {
                    Circle circle;
                    if (modelcurve.TryGetCircle(out circle))
                    {
                        planeCenter = circle.Center;
                    }

                    mScene.iPointList.Add(UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(circle.Center)));
                    mScene.iPointList.Add(UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(circle.PointAt(0))));
                }
                else if (shapeType == ShapeType.Rect)
                {
                    Rhino.Geometry.Polyline polyline;
                    if (modelcurve.TryGetPolyline(out polyline))
                    {
                        Rectangle3d rect = Rectangle3d.CreateFromPolyline(polyline);
                        planeCenter = rect.Center;
                        mScene.iPointList.Add(UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(rect.Center)));
                        mScene.iPointList.Add(UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(rect.Corner(3))));
                    }
                }
            }

            //update modelPlane and use tolerance to support unplanar surface
            Plane  curvePlane = new Plane();
            Double tolerance  = 0;

            while (tolerance < 400)
            {
                if (modelcurve.TryGetPlane(out curvePlane, tolerance))
                {
                    modelPlane = curvePlane;
                    break;
                }
                tolerance++;
            }

            int          size          = 240;
            PlaneSurface plane_surface = new PlaneSurface(curvePlane, new Interval(-size, size), new Interval(-size, size));
            Brep         newPlaneBrep  = Brep.CreateFromSurface(plane_surface);

            Guid newPlaneID = UtilOld.addRhinoObject(ref mScene, ref newPlaneBrep, "3DP");

            //might be better to use Replace(), just need to be careful about the referece count
            pointOnObjRef = null;
            pointOnObjRef = new ObjRef(newPlaneID);

            //add icurveList since we don't use EditPoint2 for circle and rect
            modelcurve.SetUserString(CurveData.CurveOnObj.ToString(), newPlaneID.ToString());
            modelcurve.SetUserString(CurveData.PlaneOrigin.ToString(), curvePlane.Origin.ToString());
            modelcurve.SetUserString(CurveData.PlaneNormal.ToString(), curvePlane.Normal.ToString());
            mScene.iCurveList.Add(modelcurve);

            //call next interaction in the chain
            afterCurveCount = mScene.iCurveList.Count;
            mScene.pushInteractionFromChain();
        }
Ejemplo n.º 29
0
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            pluginObj = ((nishanchiPlugin)this.PlugIn);
            RhinoView viewObj = doc.Views.ActiveView;
            RhinoViewport viewPortObj = viewObj.ActiveViewport;
            Vector3d originalCameraVector = viewPortObj.CameraDirection;
            Point3d originalCameraLocation = viewPortObj.CameraLocation;
            Mesh meshObj;

            Boolean logging = false;
            StreamWriter logWriter = null;

            String reportString;
            String logString;
            String printCommandStr;

            if (((nishanchiPlugin)this.PlugIn).logEnabled())
            {
                logWriter = new StreamWriter(((nishanchiPlugin)this.PlugIn).getNewLogFile());
                logWriter.WriteLine("Printing...");
                logging = true;
            }

            if (!pluginObj.trackerConnected)
            {
                RhinoApp.WriteLine("Tracker disconnected");
                return Rhino.Commands.Result.Failure;
            }

            connectKbEvt();

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select the mesh to print");
            go.Get();
            Result rc = go.CommandResult();

            if (rc != Rhino.Commands.Result.Success)
            {
                disconnectKbEvt();
                return rc;
            }

            meshObj = new Mesh();
            if (go.ObjectCount == 1){
                ObjRef tmpRef = new ObjRef(go.Object(0).ObjectId);
                meshObj = tmpRef.Mesh();
                if (meshObj == null){
                    disconnectKbEvt();
                    return rc;
                }
            }

            createNozzles(doc);
            cameraPoint = new tPoint(Nozzle.XOffset + 100.0, Nozzle.YOffset, Nozzle.ZOffset + (Nozzle.ZMultiplier * ((numNozzles-1)/2)));

            fastrak trackerObj = pluginObj.trackerObj;
            int numPoints = 0;

            Boolean retval;

            RhinoApp.WriteLine(string.Format("Starting continuous mode on the tracker."));
            pluginObj.trackerObj.setContinuous();
            RhinoApp.WriteLine(string.Format("Printing mode enabled now."));

            running = true;
            while (running)
            {
                retval = trackerObj.readFrame();
                if (retval)
                {
                    //q0,q1,q2,q3 Quaternion begin
                    //Compute the rotation matrix
                    reportString = String.Format("{0},{1},{2}", trackerObj.x, trackerObj.y, trackerObj.z);
                    logString = String.Format("p,{0},{1},{2},{3},{4},{5},{6},{7}", numPoints, trackerObj.x, trackerObj.y, trackerObj.z, trackerObj.q0, trackerObj.q1, trackerObj.q2, trackerObj.q3);

                    RhinoApp.WriteLine(reportString);
                    if (logging)
                    {
                        logWriter.WriteLine(logString);
                    }

                    rxTxTx = new Point3d(trackerObj.x, trackerObj.y, trackerObj.z);
                    orientationQuat = new Quaternion(trackerObj.q0, trackerObj.q1, trackerObj.q2, trackerObj.q3);
                    orientationQuat.GetRotation(out angle, out axis);
                    rotMat = Transform.Rotation(angle, axis, origin);

                    // Compute the new positions for the nozzlePoints and also compute the new lines
                    for (int i = 0; i < numNozzles; i++)
                    {
                        nozzles[i].computeTxTx(rotMat, rxTxTx);
                    }

                    //And, I move the view around
                    if ((numPoints % 100) == 0)
                    {
                        cameraPoint.computeTxTx(rotMat, rxTxTx);
                        viewPortObj.SetCameraLocation(cameraPoint.txTx(), true);
                        viewPortObj.SetCameraDirection(nozzles[4].vector(), true);
                        viewPortObj.Rotate(Math.PI / 2, nozzles[4].vector(), cameraPoint.txTx());
                        cameraUpTx = rotMat * cameraUpRx;
                        viewPortObj.CameraUp = cameraUpTx;

                        removeNozzleLinesFromDocument(doc);
                        addNozzleLinesToDocument(doc);
                        doc.Views.ActiveView.Redraw();
                        RhinoApp.Wait();
                    }

                    //Compute ray intersections
                    if ((numPoints % 4) == 0)
                    {
                        //RhinoApp.WriteLine("Calculating intersections..");
                        for (int i = 0; i < numNozzles; i++)
                        {
                            nozzles[i].rayIntersectionDistance = Intersection.MeshRay(meshObj,nozzles[i].ray());
                        }

                        printCommandStr = printCommand();
                        //RhinoApp.WriteLine(printCommandStr);

                        if (logging)
                        {
                            logString = String.Format("c,{0},{1}", numPoints, printCommandStr);
                            logWriter.WriteLine(logString);
                        }
                    }
                    numPoints++;
                }
            }

            running = false;

            //clean up
            removeNozzleLinesFromDocument(doc);
            doc.Views.ActiveView.Redraw();
            RhinoApp.WriteLine("Removing printHead objects!!");

            if (logging)
            {
                logWriter.Close();
                ((nishanchiPlugin)this.PlugIn).closeLogFile();
            }

            //stop the tracker
            RhinoApp.WriteLine(string.Format("Stopping continuous mode on the tracker."));
            pluginObj.trackerObj.stopContinuous();
            disconnectKbEvt();
            RhinoApp.WriteLine(string.Format("I guess you don't wanna print anymore, well who cares! Not me!"));

            //setup the viewport as it was
            viewPortObj.SetCameraLocation(originalCameraLocation, true);
            viewPortObj.SetCameraDirection(originalCameraVector, true);

            return Rhino.Commands.Result.Success;
        }
Ejemplo n.º 30
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var myTypes = ObjectType.AnyObject ^ ObjectType.BrepLoop;


            //pick objects to expand
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to scale");
            go.GeometryFilter = myTypes;
            //go.GroupSelect = true;
            go.SubObjectSelect = true;
            //go.EnableClearObjectsOnEntry(false);
            //go.EnableUnselectObjectsOnExit(false);
            //go.DeselectAllBeforePostSelect = false;
            go.GetMultiple(1, 0);

            //Compute center
            Point3d centersAdd = new Point3d();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                Point3d     bbObjCenter = bbObj.Center;
                centers.Add(bbObjCenter);
                centersAdd += bbObjCenter;

                Rhino.DocObjects.ObjRef objref = go.Object(i);
                // get selected surface object
                Rhino.DocObjects.RhinoObject obj = objref.Object();
                dynRef.Add(objref);
            }
            Point3d allCenter = centersAdd / centers.Count;

            //pick center
            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("Basepoint. Press Enter for automatic.");
            gp.AcceptNothing(true);
            var resgp = gp.Get();

            if (resgp == GetResult.Nothing)
            {
                scaleCenter = allCenter;
            }
            else
            {
                scaleCenter = gp.Point();
            }

            Rhino.Display.RhinoView view = gp.View();
            plane2D = view.ActiveViewport.ConstructionPlane();

            //Expansion factor
            GetPoint gp2 = new GetPoint();

            gp2.SetCommandPrompt("Scale factor or first reference point <" + factor + ">");
            gp2.DrawLineFromPoint(scaleCenter, true);
            gp2.AcceptNumber(true, true);
            GetResult gr = gp2.Get();



            if (gr == GetResult.Number)
            {
                factor = gp2.Number();
            }
            if (gr == GetResult.Point)
            {
                scaleRefPoint = gp2.Point();
                Line line1     = new Line(scaleCenter, scaleRefPoint);
                Guid tempLine  = doc.Objects.AddLine(line1);
                Guid tempPoint = doc.Objects.AddPoint(scaleRefPoint);
                if (scaleCenter == gp2.Point())
                {
                    return(Rhino.Commands.Result.Cancel);
                }
                GetPoint gp3 = new GetPoint();
                gp3.SetCommandPrompt("Secondt reference point");
                gp3.AddOptionList("ScaleDimension", dimensions, 0);
                gp3.DrawLineFromPoint(scaleCenter, true);
                gp3.DynamicDraw += RefObjDraw;

                while (true)
                {
                    GetResult res = gp3.Get();
                    if (res == GetResult.Option)
                    {
                        dimensionIndex = gp3.Option().CurrentListOptionIndex;
                        continue;
                    }
                    else if (res == GetResult.Point)
                    {
                        Point3d scaleRefPoint2 = gp3.Point();

                        factor = (scaleCenter.DistanceTo(scaleRefPoint2)) / (scaleCenter.DistanceTo(scaleRefPoint));
                        doc.Objects.Delete(tempLine, true);
                        doc.Objects.Delete(tempPoint, true);
                    }
                    break;
                }
            }
            RhinoApp.WriteLine("Scale factor: " + factor);

            //Compute translation

            //Translate 3d
            if (dimensionIndex == 0)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    var xform  = Transform.Scale(centers[i], factor);
                    var objref = go.Object(i);
                    var brep   = objref.Brep();
                    var index  = objref.GeometryComponentIndex.Index;
                    if (index > 0)
                    {
                        brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true);
                        doc.Objects.Replace(objref.ObjectId, brep);
                    }
                    else
                    {
                        doc.Objects.Transform(go.Object(i), xform, true);
                    }
                }
            }
            //Translate 2d
            else if (dimensionIndex == 1)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    plane2D.Origin = centers[i];
                    var xform  = Rhino.Geometry.Transform.Scale(plane2D, factor, factor, 1);
                    var objref = go.Object(i);
                    var brep   = objref.Brep();
                    var index  = objref.GeometryComponentIndex.Index;
                    if (index > 0)
                    {
                        brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true);
                        doc.Objects.Replace(objref.ObjectId, brep);
                    }
                    else
                    {
                        doc.Objects.Transform(go.Object(i), xform, true);
                    }
                }
            }
            //Translate 1d
            else if (dimensionIndex == 2)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Vector3d vec        = (scaleRefPoint - scaleCenter);
                    Plane    scalePlane = new Plane(centers[i], vec);
                    var      xform      = Transform.Scale(scalePlane, 1, 1, factor);
                    var      objref     = go.Object(i);
                    var      brep       = objref.Brep();
                    var      index      = objref.GeometryComponentIndex.Index;
                    if (index > 0)
                    {
                        brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true);
                        doc.Objects.Replace(objref.ObjectId, brep);
                    }
                    else
                    {
                        doc.Objects.Transform(go.Object(i), xform, true);
                    }
                }
            }

            centers        = new List <Point3d>();
            dimensionIndex = 0;
            plane2D        = new Plane();
            dynRef         = new List <Rhino.DocObjects.ObjRef>();

            doc.Views.Redraw();
            return(Result.Success);
        }