public static Rhino.Commands.Result AddClippingPlane(Rhino.RhinoDoc doc) { // Define the corners of the clipping plane Rhino.Geometry.Point3d[] corners; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetRectangle(out corners); if (rc != Rhino.Commands.Result.Success) { return(rc); } // Get the active view Rhino.Display.RhinoView view = doc.Views.ActiveView; if (view == null) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.Point3d p0 = corners[0]; Rhino.Geometry.Point3d p1 = corners[1]; Rhino.Geometry.Point3d p3 = corners[3]; // Create a plane from the corner points Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(p0, p1, p3); // Add a clipping plane object to the document Guid id = doc.Objects.AddClippingPlane(plane, p0.DistanceTo(p1), p0.DistanceTo(p3), view.ActiveViewportID); if (id != Guid.Empty) { doc.Views.Redraw(); return(Rhino.Commands.Result.Success); } return(Rhino.Commands.Result.Failure); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Mesh; Rhino.DocObjects.ObjRef objref = null; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select mesh to contour", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Geometry.Mesh mesh = objref.Geometry() as Rhino.Geometry.Mesh; if (null == mesh) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.BoundingBox bbox = mesh.GetBoundingBox(false); Rhino.Geometry.Point3d start_pt = bbox.Corner(true, true, true); Rhino.Geometry.Point3d end_pt = bbox.Corner(false, true, true); double interval = start_pt.DistanceTo(end_pt) / 10; Rhino.Geometry.Curve[] curves = Rhino.Geometry.Mesh.CreateContourCurves(mesh, start_pt, end_pt, interval); if (null != curves && curves.Length > 0) { for (int i = 0; i < curves.Length; i++) { doc.Objects.AddCurve(curves[i]); } doc.Views.Redraw(); } return(Result.Success); }
static public bool GetNormalVector(Rhino.Geometry.Surface surface, Rhino.Geometry.Point3d pt, ref Rhino.Geometry.Vector3d normal, double tolerance = 0.001) { double u, v; if (surface.ClosestPoint(pt, out u, out v) == false) { return(false); } Rhino.Geometry.Point3d pt2 = surface.PointAt(u, v); double distance = pt.DistanceTo(pt2); if (distance > tolerance) { return(false); } RhinoApp.WriteLine("Found the closest point on surface within {0}", distance); Rhino.Geometry.Vector3d n = surface.NormalAt(u, v); normal = n; return(true); }
private void AnimateRestoreView() { FastDrawing = true; var restoreViewCurrentTime = DateTime.Now; var currentTime = restoreViewCurrentTime; var startTime = RestoreViewStartTime; var timeElapsed = currentTime.Subtract(startTime); var timeElapsedInMs = timeElapsed.TotalMilliseconds; var totalTimeOfAnimationInMs = RestoreViewTotalTime.TotalMilliseconds; double percentCompleted = timeElapsedInMs / totalTimeOfAnimationInMs; if (percentCompleted > 1) { // Animation is completed. Perform one last draw. percentCompleted = 1; IsInAnimatedRestoreView = false; View.UserInteractionEnabled = true; CameraIsAtInitialPosition = !ShouldStartRestoreToInitialPosition; AnimationTimer.Invalidate(); } // Get some data from the starting view Rhino.Geometry.Point3d sourceTarget = RestoreViewStartViewport.TargetPoint; Rhino.Geometry.Point3d sourceCamera = RestoreViewStartViewport.CameraLocation; double sourceDistance = sourceCamera.DistanceTo(sourceTarget); Rhino.Geometry.Vector3d sourceUp = RestoreViewStartViewport.CameraUp; sourceUp.Unitize(); // Get some data from the ending view Rhino.Geometry.Point3d targetTarget = RestoreViewFinishViewport.TargetPoint; Rhino.Geometry.Point3d targetCamera = RestoreViewFinishViewport.CameraLocation; double targetDistance = targetCamera.DistanceTo(targetTarget); Rhino.Geometry.Vector3d targetCameraDir = targetCamera - targetTarget; Rhino.Geometry.Vector3d targetUp = RestoreViewFinishViewport.CameraUp; targetUp.Unitize(); // Adjust the target camera location so that the starting camera to target distance // and the ending camera to target distance are the same. Doing this will calculate // a constant rotational angular momentum when tweening the camera location. // Further down we independently tween the camera to target distance. targetCameraDir.Unitize(); targetCameraDir *= sourceDistance; targetCamera = targetCameraDir + targetTarget; // calculate interim viewport values double frameDistance = ViewportInfoExtensions.CosInterp(sourceDistance, targetDistance, percentCompleted); Rhino.Geometry.Point3d frameTarget = new Rhino.Geometry.Point3d(); frameTarget.X = ViewportInfoExtensions.CosInterp(sourceTarget.X, targetTarget.X, percentCompleted); frameTarget.Y = ViewportInfoExtensions.CosInterp(sourceTarget.Y, targetTarget.Y, percentCompleted); frameTarget.Z = ViewportInfoExtensions.CosInterp(sourceTarget.Z, targetTarget.Z, percentCompleted); var origin = Rhino.Geometry.Point3d.Origin; Rhino.Geometry.Point3d frameCamera = origin + (ViewportInfoExtensions.Slerp((sourceCamera - origin), (targetCamera - origin), percentCompleted)); Rhino.Geometry.Vector3d frameCameraDir = frameCamera - frameTarget; // adjust the camera location along the camera direction vector to preserve the target location and the camera distance frameCameraDir.Unitize(); frameCameraDir *= frameDistance; frameCamera = frameCameraDir + frameTarget; Rhino.Geometry.Vector3d frameUp = new Rhino.Geometry.Vector3d(ViewportInfoExtensions.Slerp(sourceUp, targetUp, percentCompleted)); if (percentCompleted >= 1) { // put the last redraw at the exact end point to eliminate any rounding errors Camera.SetTarget(RestoreViewFinishViewport.TargetPoint, RestoreViewFinishViewport.CameraLocation, RestoreViewFinishViewport.CameraUp); } else { Camera.SetTarget(frameTarget, frameCamera, frameUp); } SetFrustum(Camera, App.Manager.CurrentModel.BBox); View.SetNeedsDisplay(); if (!IsInAnimatedRestoreView) { // FastDrawing is still enabled and we just scheduled a draw of the model at the final location. // This entirely completes the animation. Now schedule one more redraw of the model with FastDrawing disabled // and this redraw will be done at exactly the same postion. This prevents the final animation frame // from jumping to the final location because the final draw will take longer with FastDrawing disabled. PerformSelector(new Selector("RedrawDetailed"), null, 0.05); } }