Exemplo 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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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;
            }
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
                    }
                }
            }
        }
Exemplo n.º 9
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);
        }