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); }
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; }
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); }
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); }