Exemplo n.º 1
0
        public Rhino.Commands.Result GetPoints(Rhino.RhinoDoc doc)
        {
            // Input interval
            var input = new Rhino.Input.Custom.GetNumber();
            // Select surface
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select point");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Point;
            go.GetMultiple(1, 1);

            Rhino.Geometry.Point   pt     = go.Object(0).Point();
            Rhino.Geometry.Point3d pointA = pt.Location;

            go.SetCommandPrompt("Select surface");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            go.GetMultiple(1, 1);

            Rhino.Geometry.Surface surfaceB = go.Object(0).Surface();
            double u, v;

            if (surfaceB.ClosestPoint(pointA, out u, out v))
            {
                Rhino.Geometry.Point3d pointC = surfaceB.PointAt(u, v);

                Rhino.Geometry.Vector3d vector = pointA - pointC;
                // write list pointD
            }

            return(Rhino.Commands.Result.Success);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Copies a Rhino_DotNet surface to a RhinoCommon Surface class.
 /// </summary>
 /// <param name="source">
 /// Any of the following in the RMA.OpenNURBS namespace are acceptable.
 /// IOnSurface, OnSurface, IOnPlaneSurface, OnPlaneSurface, IOnClippingPlaneSurface,
 /// OnClippingPlaneSurface, IOnNurbsSurface, OnNurbsSurfac, IOnRevSurface, OnRevSurface,
 /// IOnSumSurface, OnSumSurface.
 /// </param>
 /// <returns>
 /// RhinoCommon object on success. This will be an independent copy.
 /// </returns>
 public static Rhino.Geometry.Surface FromOnSurface(object source)
 {
     Rhino.Geometry.GeometryBase g = CopyHelper(source, "RMA.OpenNURBS.OnSurface");
     if (null == g)
     {
         g = CopyHelper(source, "RMA.OpenNURBS.OnPlaneSurface");
     }
     if (null == g)
     {
         g = CopyHelper(source, "RMA.OpenNURBS.OnClippingPlaneSurface");
     }
     if (null == g)
     {
         g = CopyHelper(source, "RMA.OpenNURBS.OnNurbsSurface");
     }
     if (null == g)
     {
         g = CopyHelper(source, "RMA.OpenNURBS.OnRevSurface");
     }
     if (null == g)
     {
         g = CopyHelper(source, "RMA.OpenNURBS.OnSumSurface");
     }
     Rhino.Geometry.Surface rc = g as Rhino.Geometry.Surface;
     return(rc);
 }
Exemplo n.º 3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_String        style = new GH_String("");
            GH_String        layer = new GH_String("");
            GH_Point         stop  = new GH_Point();
            GH_Point         sbtm  = new GH_Point();
            List <Parameter> param = new List <Parameter>();

            if (!DA.GetDataList <Parameter>("Parameters", param))
            {
                param = new List <Parameter>();
            }

            DA.GetData <GH_String>("Style", ref style);
            DA.GetData <GH_String>("Layer", ref layer);

            DA.GetData <GH_Point>("PointTop", ref stop);
            DA.GetData <GH_Point>("PointBottom", ref sbtm);

            Column s = new Column(style.Value, layer.Value, param, sbtm.ToGrevitPoint(), stop.ToGrevitPoint(), "", true);

            SetGID(s);

            Rhino.Geometry.Circle  c   = new Rhino.Geometry.Circle(sbtm.Value, 0.5);
            Rhino.Geometry.Surface srf = Rhino.Geometry.NurbsSurface.CreateExtrusion(c.ToNurbsCurve(), new Rhino.Geometry.Vector3d(new Rhino.Geometry.Point3d(stop.Value.X - sbtm.Value.X, stop.Value.Y - sbtm.Value.Y, stop.Value.Z - sbtm.Value.Z)));
            SetPreview(s.GID, srf.ToBrep());
            DA.SetData("GrevitComponent", s);
        }
Exemplo n.º 4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Curve         baseline = new GH_Curve();
            GH_String        layer    = new GH_String("");
            GH_Number        height   = new GH_Number();
            GH_String        style    = new GH_String("");
            List <Parameter> param    = new List <Parameter>();

            if (!DA.GetDataList <Parameter>("Parameters", param))
            {
                param = new List <Parameter>();
            }

            //DA.GetData<GH_String>("Family", ref family);
            DA.GetData <GH_String>("Layer", ref layer);
            DA.GetData <GH_String>("Style", ref style);
            DA.GetData <GH_Number>("Height", ref height);
            DA.GetData <GH_Curve>("Baseline", ref baseline);


            Wall w = new Wall(style.Value, layer.Value, param, baseline.ToGrevitCurve(), "", height.Value, true, false);

            SetGID(w);
            Rhino.Geometry.Surface srf = Rhino.Geometry.Surface.CreateExtrusion(baseline.Value, new Rhino.Geometry.Vector3d(0, 0, height.Value));
            SetPreview(w.GID, srf.ToBrep());
            DA.SetData("GrevitComponent", w);
        }
Exemplo n.º 5
0
 public void drawColumn(Rhino.Geometry.Point3d point1, Rhino.Geometry.Point3d point2, Rhino.Geometry.Brep brep)
 {
     foreach (Rhino.Geometry.Curve curve in brep.Curves3D)
     {
         Rhino.Geometry.Surface srf = Rhino.Geometry.Surface.CreateExtrusion(curve, new Rhino.Geometry.Vector3d((point2 - point1)));
         SetPreview(srf.ToBrep());
     }
 }
    public static Rhino.Commands.Result MoveGripObjects(Rhino.RhinoDoc doc)
    {
        // The following example demonstrates how to move a surface's grip objects.
        // In this sample, all grips will be moved a fixed distance of 0.5 units
        // in the normal direction of the surface at that grip location.

        Rhino.DocObjects.ObjRef objRef;
        Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetOneObject("Select surface for control point editing", false, Rhino.DocObjects.ObjectType.Surface, out objRef);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        Rhino.DocObjects.RhinoObject obj = objRef.Object();
        if (null == obj)
        {
            return(Rhino.Commands.Result.Failure);
        }

        Rhino.Geometry.Surface srf = objRef.Surface();
        if (null == srf)
        {
            return(Rhino.Commands.Result.Failure);
        }

        // Make sure the object's grips are enabled
        obj.GripsOn = true;
        doc.Views.Redraw();

        Rhino.DocObjects.GripObject[] grips = obj.GetGrips();
        for (int i = 0; i < grips.Length; i++)
        {
            Rhino.DocObjects.GripObject grip = grips[i];

            // Calculate the point on the surface closest to our test point,
            // which is the grip's 3-D location (for this example).
            double u, v;
            if (srf.ClosestPoint(grip.CurrentLocation, out u, out v))
            {
                // Compute the surface normal at a point
                Rhino.Geometry.Vector3d dir = srf.NormalAt(u, v);
                dir.Unitize();

                // Scale by our fixed distance
                dir *= 0.5;

                // Move the grip to a new location
                grip.Move(dir);
            }
        }

        // Altered grip positions on a RhinoObject are used to calculate an updated
        // object that is added to the document.
        doc.Objects.GripUpdate(obj, false);
        doc.Views.Redraw();

        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 7
0
 public void drawExtrusion(Rhino.Geometry.Point3d point1, double height, double width, double thickness)
 {
     Rhino.Geometry.Plane       plane   = new Rhino.Geometry.Plane(point1, Rhino.Geometry.Vector3d.ZAxis);
     Rhino.Geometry.Point3d     cornerA = new Rhino.Geometry.Point3d(point1.X - width / 2, point1.Y - height / 2, point1.Z);
     Rhino.Geometry.Point3d     cornerB = new Rhino.Geometry.Point3d(point1.X + width / 2, point1.Y + height / 2, point1.Z);
     Rhino.Geometry.Rectangle3d rect    = new Rhino.Geometry.Rectangle3d(plane, cornerA, cornerB);
     Rhino.Geometry.Surface     srf     = Rhino.Geometry.Surface.CreateExtrusion(rect.ToNurbsCurve(), new Rhino.Geometry.Vector3d(0, 0, thickness));
     SetPreview(srf.ToBrep());
 }
Exemplo n.º 8
0
        public void drawColumn(Rhino.Geometry.Point3d point1, double length, double radius)
        {
            Rhino.Geometry.Circle c = new Rhino.Geometry.Circle(point1, radius);

            Rhino.Geometry.Surface srf = Rhino.Geometry.NurbsSurface.CreateExtrusion(c.ToNurbsCurve(),
                                                                                     new Rhino.Geometry.Vector3d(0, 0, (length * -1)));

            SetPreview(srf.ToBrep());
        }
Exemplo n.º 9
0
        public void drawColumn(Rhino.Geometry.Point3d point1, Rhino.Geometry.Point3d point2, double radius)
        {
            Rhino.Geometry.Plane  plane = new Rhino.Geometry.Plane(point1, new Rhino.Geometry.Vector3d((point2 - point1)));
            Rhino.Geometry.Circle c     = new Rhino.Geometry.Circle(plane, point1, radius);

            Rhino.Geometry.Surface srf = Rhino.Geometry.Surface.CreateExtrusion(c.ToNurbsCurve(), new Rhino.Geometry.Vector3d((point2 - point1)));

            SetPreview(srf.ToBrep());
        }
Exemplo n.º 10
0
        static public bool CreateSections(Rhino.RhinoDoc doc, Rhino.Geometry.GeometryBase geo, Rhino.Geometry.Surface surfaceB, Rhino.Geometry.Curve curve, double interval, ref List <PlanePoint> points)
        {
            Rhino.Geometry.Interval domain = curve.Domain;  // fixed issue
            for (double t = domain.T0; t < domain.T1; t += interval)
            {
                Rhino.Geometry.Point3d  pt        = curve.PointAt(t);
                Rhino.Geometry.Vector3d tangent   = curve.TangentAt(t);
                Rhino.Geometry.Vector3d curvature = curve.CurvatureAt(t);
                Rhino.Geometry.Plane    plane     = new Rhino.Geometry.Plane();
                curve.FrameAt(t, out plane);

                doc.Objects.AddPoint(pt);
                curvature = curvature * 10.0;
                Rhino.Geometry.Line line = new Rhino.Geometry.Line(pt, curvature);
                doc.Objects.AddLine(line);
                RhinoApp.WriteLine("Curve at {0}", t);

                Rhino.Geometry.Vector3d normal = new Rhino.Geometry.Vector3d();

                bool ret = false;
                if (geo is Rhino.Geometry.Brep)
                {
                    Rhino.Geometry.Brep brepA = (Rhino.Geometry.Brep)geo;
                    ret = GetNormalVector(brepA, pt, ref normal);
                    RhinoApp.WriteLine("   Added Brep point at ({0}, {0}, {0})", pt.X, pt.Y, pt.Z);
                }
                else if (geo is Rhino.Geometry.Surface)
                {
                    Rhino.Geometry.Surface surfaceA = (Rhino.Geometry.Surface)geo;
                    ret = GetNormalVector(surfaceA, pt, ref normal);
                    RhinoApp.WriteLine("   Added surface point at ({0}, {0}, {0})", pt.X, pt.Y, pt.Z);
                }

                if (ret)
                {
                    Rhino.Geometry.Vector3d ucoord = CrossProduct(tangent, normal);
                    Rhino.Geometry.Plane    plane2 = new Rhino.Geometry.Plane(pt, ucoord, tangent); // normal);
                    double[] parameters            = plane2.GetPlaneEquation();

                    PlanePoint PlanePoint = new PlanePoint();
                    PlanePoint.pt        = pt;
                    PlanePoint.A         = parameters[0];
                    PlanePoint.B         = parameters[1];
                    PlanePoint.C         = parameters[2];
                    PlanePoint.D         = parameters[3];
                    PlanePoint.curvature = curvature;
                    points.Add(PlanePoint);

                    Rhino.Geometry.Interval     Interval1    = new Rhino.Geometry.Interval(-0.1, -0.1);
                    Rhino.Geometry.Interval     Interval2    = new Rhino.Geometry.Interval(0.1, 0.1);
                    Rhino.Geometry.PlaneSurface PlaneSurface = new Rhino.Geometry.PlaneSurface(plane2, Interval1, Interval2);
                    doc.Objects.AddSurface(PlaneSurface);
                }
            }
            return(true);
        }
Exemplo n.º 11
0
    public static Rhino.Commands.Result UnrollSurface2(Rhino.RhinoDoc doc)
    {
        const ObjectType filter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Surface;

        Rhino.DocObjects.ObjRef objref;
        Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface or brep to unroll", false, filter, out objref);

        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }
        Rhino.Geometry.Unroller unroll = null;
        Rhino.Geometry.Brep     brep   = objref.Brep();
        Rhino.Geometry.Mesh     mesh   = null;
        if (brep != null)
        {
            unroll = new Rhino.Geometry.Unroller(brep);
            mesh   = brep.Faces[0].GetMesh(Rhino.Geometry.MeshType.Render);
        }
        else
        {
            Rhino.Geometry.Surface srf = objref.Surface();
            if (srf != null)
            {
                unroll = new Rhino.Geometry.Unroller(srf);
            }
        }
        if (unroll == null || mesh == null)
        {
            return(Rhino.Commands.Result.Cancel);
        }

        unroll.AddFollowingGeometry(mesh.Vertices.ToPoint3dArray());

        unroll.ExplodeOutput = false;
        Rhino.Geometry.Curve[]   curves;
        Rhino.Geometry.Point3d[] points;
        Rhino.Geometry.TextDot[] dots;
        unroll.PerformUnroll(out curves, out points, out dots);

        // change the mesh vertices to the flattened form and add it to the document
        if (points.Length == mesh.Vertices.Count)
        {
            for (int i = 0; i < points.Length; i++)
            {
                mesh.Vertices.SetVertex(i, points[i]);
            }
            mesh.Normals.ComputeNormals();
        }
        doc.Objects.AddMesh(mesh, objref.Object().Attributes);
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 12
0
        /// <summary>
        /// Constructs a Rhino_DotNet OnSurface that is a copy of a given curve.
        /// </summary>
        /// <param name="source">A source brep.</param>
        /// <returns>
        /// Rhino_DotNet object on success. This will be an independent copy.
        /// </returns>
        public static object ToOnSurface(Rhino.Geometry.Surface source)
        {
            object rc      = null;
            IntPtr pSource = source.ConstPointer();
            Type   onType  = GetRhinoDotNetType("RMA.OpenNURBS.OnSurface");

            if (IntPtr.Zero != pSource && null != onType)
            {
                System.Reflection.MethodInfo mi = onType.GetMethod("WrapNativePointer", new Type[] { typeof(IntPtr), typeof(bool), typeof(bool) });
                IntPtr pNewSurface = UnsafeNativeMethods.ON_Surface_DuplicateSurface(pSource);
                rc = mi.Invoke(null, new object[] { pNewSurface, false, true });
            }
            return(rc);
        }
Exemplo n.º 13
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Point point = new GH_Point();

            Grevit.Types.Wall wall = null;


            GH_String layer = new GH_String("");
            GH_String style = new GH_String("");

            List <Parameter> param = new List <Parameter>();

            if (!DA.GetDataList <Parameter>("Parameters", param))
            {
                param = new List <Parameter>();
            }

            DA.GetData <GH_Point>("Point", ref point);
            DA.GetData <GH_String>("Layer", ref layer);
            DA.GetData <GH_String>("Style", ref style);
            DA.GetData <Wall>("wall", ref wall);


            Door d = new Door();

            SetGID(d);
            d.stalledForReference = true;
            d.TypeOrLayer         = layer.Value;
            d.FamilyOrStyle       = style.Value;
            d.locationPoint       = point.ToGrevitPoint();
            d.parameters          = param;
            SetGID(d);



            Rhino.Geometry.Circle  c   = new Rhino.Geometry.Circle(point.Value, 0.5);
            Rhino.Geometry.Surface srf = Rhino.Geometry.NurbsSurface.CreateExtrusion(c.ToNurbsCurve(), new Rhino.Geometry.Vector3d(0, 0, 2));



            SetPreview(d.GID, srf.ToBrep());


            GH_Surface ghb = new GH_Surface(srf);

            DA.SetData("GrevitComponent", d);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Create FdCoordinateSystem from Rhino plane on surface mid u/v-point.
        /// </summary>
        internal static FdCoordinateSystem FromRhinoSurface(this Rhino.Geometry.Surface obj)
        {
            // reparameterize if necessary
            if (obj.Domain(0).T0 == 0 && obj.Domain(1).T0 == 0 && obj.Domain(0).T1 == 1 && obj.Domain(1).T1 == 1)
            {
                // pass
            }
            else
            {
                obj.SetDomain(0, new Rhino.Geometry.Interval(0, 1));
                obj.SetDomain(1, new Rhino.Geometry.Interval(0, 1));
            }

            Rhino.Geometry.Plane plane;
            obj.FrameAt(0.5, 0.5, out plane);
            return(plane.FromRhinoPlane());
        }
Exemplo n.º 15
0
        public static List <Rhino.Geometry.Brep> InnerLoops(this SketchUpNET.Surface v, Transform t = null)
        {
            List <Rhino.Geometry.Brep> breps = new List <Rhino.Geometry.Brep>();

            foreach (Loop loop in v.InnerEdges)
            {
                List <Rhino.Geometry.Curve> curves = new List <Rhino.Geometry.Curve>();
                foreach (SketchUpNET.Edge c in loop.Edges)
                {
                    curves.Add(c.ToRhinoGeo(t).ToNurbsCurve());
                }

                Rhino.Geometry.Curve[] crv = Rhino.Geometry.Curve.JoinCurves(curves);
                Rhino.Geometry.Surface b   = Rhino.Geometry.Surface.CreateExtrusion(crv[0], v.Normal.ToRhinoGeo());
                breps.Add(b.ToBrep());
            }
            return(breps);
        }
Exemplo n.º 16
0
        /*
         * public Rhino.Geometry.Point3d randomPoint(Rhino.Geometry.Point3d pt, Rhino.Geometry.Vector3d n, double interval, double randomValue)
         * {
         *  const int MAX_RANDOM_VALUE = 1000;
         *  int maxValue = (int)(MAX_RANDOM_VALUE * interval);
         *  int maxRandom = (int)((double)maxValue * (double)randomValue / 100.0);
         *
         *  int n1 = _random.Next(0, maxRandom);
         *  int n2 = _random.Next(0, maxRandom);
         *  int n3 = _random.Next(0, maxRandom);
         *
         *  // uv 간격에 따른 랜덤값 획득
         *  double v1 = (double)n1 / maxValue;
         *  double v2 = (double)n2 / maxValue;
         *  double v3 = (double)n3 / maxValue;
         *
         *  Rhino.Geometry.Point3d pt2 = new Rhino.Geometry.Point3d();
         *  pt2.X = pt.X * (1.0 + v1);   // 2.0을 나누어 uv 지점에서 노이즈 편차가 되도록 함.
         *  pt2.Y = pt.Y * (1.0 + v2);
         *  pt2.Z = pt.Z * (1.0 + v3);
         *  return pt2;
         * }
         * function randomSpherePoint(x0,y0,z0,radius){
         * var u = Math.random();
         * var v = Math.random();
         * var theta = 2 * Math.PI * u;
         * var phi = Math.acos(2 * v - 1);
         * var x = x0 + (radius * Math.sin(phi) * Math.cos(theta));
         * var y = y0 + (radius * Math.sin(phi) * Math.sin(theta));
         * var z = z0 + (radius * Math.cos(phi));
         * return [x,y,z];
         * }
         */
        /*
         * public Rhino.Geometry.Point3d randomPoint(Rhino.Geometry.Surface surface, Rhino.Geometry.Point3d pt, Rhino.Geometry.Vector3d n, double interval, double randomValue)
         * {
         *  double radius = interval;
         *  double u = _random.NextDouble();
         *  double v = _random.NextDouble();
         *  double theta = 2.0 * Math.PI * u;
         *  double phi = Math.Acos(2.0 * v - 1.0);
         *  double x = pt.X + (radius * Math.Sin(phi) * Math.Cos(theta));
         *  double y = pt.Y + (radius * Math.Sin(phi) * Math.Sin(theta));
         *  double z = pt.Z + (radius * Math.Cos(phi));
         *
         *  Rhino.Geometry.Point3d pt2 = new Rhino.Geometry.Point3d(x, y, z);
         *  return pt2;
         * }
         */
        public Rhino.Geometry.Point3d randomPoint(Rhino.Geometry.Surface surface, double u, double v, double interval, double noise)
        {
            noise = noise / 2.0 / 100;
            double randomU = _random.NextDouble();  // random number from 0 to 1.0
            double randomV = _random.NextDouble();

            randomU = randomU * interval * noise;
            randomV = randomV * interval * noise;
            Rhino.Geometry.Point3d  pt = surface.PointAt(u + randomU, v + randomV);
            Rhino.Geometry.Vector3d n  = surface.NormalAt(u + randomU, v + randomV);

            double randomZ = _random.NextDouble();

            // randomZ = (randomZ - 0.5) * interval * noise;
            randomZ = randomZ * interval * noise;
            n       = n * randomZ;

            Rhino.Geometry.Point3d pt2 = pt + n;
            return(pt2);
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        public static Rhino.Geometry.Brep ToRhinoGeo(this SketchUpNET.Surface v, Transform t = null)
        {
            List <Rhino.Geometry.Curve> curves = new List <Rhino.Geometry.Curve>();

            foreach (SketchUpNET.Edge c in v.OuterEdges.Edges)
            {
                curves.Add(c.ToRhinoGeo(t).ToNurbsCurve());
            }

            foreach (Loop loop in v.InnerEdges)
            {
                foreach (SketchUpNET.Edge c in loop.Edges)
                {
                    curves.Add(c.ToRhinoGeo(t).ToNurbsCurve());
                }
            }

            Rhino.Geometry.Curve[] crv = Rhino.Geometry.Curve.JoinCurves(curves);

            Rhino.Geometry.Surface b = Rhino.Geometry.Surface.CreateExtrusion(crv[0], v.Normal.ToRhinoGeo());

            List <Rhino.Geometry.Brep> breps = v.InnerLoops(t);

            Rhino.Geometry.Brep result = b.ToBrep();

            if (breps.Count > 0)
            {
                Rhino.Geometry.Brep[] tmp = Rhino.Geometry.Brep.CreateBooleanDifference(new List <Rhino.Geometry.Brep>()
                {
                    b.ToBrep()
                }, breps, 0);
                if (tmp.Length > 0)
                {
                    result = tmp[0];
                }
            }
            return(result);
        }
Exemplo n.º 19
0
        bool CreateSolid(double tolerance, out Rhino.Geometry.Brep outBrep)
        {
            outBrep = null;

            Rhino.Geometry.Point3d  origin = new Rhino.Geometry.Point3d(0.0, 0.0, 0.0);
            Rhino.Geometry.Circle   circle = new Rhino.Geometry.Circle(origin, 10.0);
            Rhino.Geometry.ArcCurve curve  = new Rhino.Geometry.ArcCurve(circle);

            Rhino.Geometry.Vector3d direction = new Rhino.Geometry.Vector3d(0, 0, 10);
            Rhino.Geometry.Surface  surface   = Rhino.Geometry.Surface.CreateExtrusion(curve, direction);

            Rhino.Geometry.Brep brep  = Rhino.Geometry.Brep.CreateFromSurface(surface);
            Rhino.Geometry.Brep solid = brep.CapPlanarHoles(tolerance);

            bool rc = solid.IsValid;

            if (rc)
            {
                outBrep = solid;
            }

            return(rc);
        }
Exemplo n.º 20
0
        public Rhino.Commands.Result IntersectBrep(Rhino.RhinoDoc doc)
        {
            // Input interval
            var input = new Rhino.Input.Custom.GetNumber();

            input.SetCommandPrompt("Input slicing interval");
            input.Get();
            if (input.CommandResult() != Rhino.Commands.Result.Success)
            {
                RhinoApp.WriteLine("Can't obtain interval number");
                return(input.CommandResult());
            }
            double SlicingInterval = input.Number();

            // Select two curves to intersect
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select Brep");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep;
            go.GetMultiple(1, 1);

            Rhino.Geometry.Brep    brepA    = null;
            Rhino.Geometry.Surface surfaceB = null;
            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                RhinoApp.WriteLine("Can't obtain objects");
                return(input.CommandResult());
            }
            brepA = go.Object(0).Brep();

            var go2 = new Rhino.Input.Custom.GetObject();

            go2.SetCommandPrompt("Select surface");
            go2.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            go2.GetMultiple(1, 1);
            if (go2.CommandResult() != Rhino.Commands.Result.Success)
            {
                RhinoApp.WriteLine("Can't obtain objects");
                return(input.CommandResult());
            }
            surfaceB = go2.Object(0).Surface();

            // Calculate the intersection
            RhinoApp.WriteLine("Executing the intersection between surfaces");
            const double intersection_tolerance = 0.001;

            Rhino.Geometry.Curve[]   intersectionCurves = null;
            Rhino.Geometry.Point3d[] intersectionPoints = null;
            bool ret = Rhino.Geometry.Intersect.Intersection.BrepSurface(brepA, surfaceB, intersection_tolerance, out intersectionCurves, out intersectionPoints);

            if (ret)
            {
                List <PlanePoint> PlanePoints = new List <PlanePoint>();
                RhinoApp.WriteLine("Success - {0} curves", intersectionCurves.Length);
                for (int i = 0; i < intersectionCurves.Length; i++)
                {
                    Rhino.Geometry.Curve curve = intersectionCurves[i];
                    doc.Objects.AddCurve(curve);
                    RhinoApp.WriteLine("Curve is added");

                    Utility.CreateSections(doc, brepA, surfaceB, curve, SlicingInterval, ref PlanePoints);
                }

                RhinoApp.WriteLine("Success - {0} points", intersectionPoints.Length);
                for (int i = 0; i < intersectionPoints.Length; i++)
                {
                    Rhino.Geometry.Point3d point = intersectionPoints[i];
                    doc.Objects.AddPoint(point);
                    RhinoApp.WriteLine("Point is added");
                }

                if (Utility.SavePlanePoints(@"c:\SlicerPlanePoints.csv", PlanePoints))
                {
                    RhinoApp.WriteLine("Saved SlicerPlanePoints.csv");
                }
            }

            return(Rhino.Commands.Result.Success);
        }
Exemplo n.º 21
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!FriedChiken.isInitialized)
            {
                Rhino.Geometry.Surface s = null;
                if (!DA.GetData(0, ref s))
                {
                    return;
                }
                Rhino.Geometry.Interval uDomain = s.Domain(0);
                Rhino.Geometry.Interval vDomain = s.Domain(1);
                int[] nEdgeNodes = new int[_dim];
                DA.GetData(1, ref nEdgeNodes[0]);
                DA.GetData(2, ref nEdgeNodes[1]);
                for (int i = 0; i < _dim; i++)
                {
                    if (nEdgeNodes[i] < 2)
                    {
                        AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "Integers must be greater than or equal to 2");
                        return;
                    }
                }
                Rhino.Geometry.Mesh m = new Rhino.Geometry.Mesh();
                //メッシュノード構築
                newNodes.Clear();
                for (int i = 0; i < nEdgeNodes[1]; i++)
                {
                    for (int j = 0; j < nEdgeNodes[0]; j++)
                    {
                        newNodes.Add(s.PointAt(uDomain.T0 + (uDomain.T1 - uDomain.T0) / (nEdgeNodes[0] - 1) * j, vDomain.T0 + (vDomain.T1 - vDomain.T0) / (nEdgeNodes[1] - 1) * i));
                    }
                }
                m.Vertices.AddVertices(newNodes);
                int nNewNodes = newNodes.Count;

                GH_material mat = null;
                GH_gravity  gvt = null;
                if (!DA.GetData(3, ref mat))
                {
                    return;
                }
                if (!DA.GetData(4, ref gvt))
                {
                    return;
                }

                el = MathUtil.isoparametricElements(nEdgeNodes);
                int nElements = el.Length;
                //メッシュ構築
                for (int i = 0; i < nElements; i++)
                {
                    m.Faces.AddFace(el[i][0], el[i][1], el[i][3], el[i][2]);
                }
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    particles[i] = new mikity.NumericalMethodHelper.particle(newNodes[i][0], newNodes[i][1], newNodes[i][2]);
                }

                eM = new generalSpring();
                pS = new GH_particleSystem(particles);
                for (int i = 0; i < nElements; i++)
                {
                    if (_subdv == subdivide.quad)
                    {
                        eM.addElement(new mikity.NumericalMethodHelper.elements.isoparametricElement(el[i]));
                    }
                    if (_subdv == subdivide.triA)
                    {
                        eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                            el[i][0], el[i][1], el[i][3]
                        }));
                        eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                            el[i][0], el[i][3], el[i][2]
                        }));
                    }
                    if (_subdv == subdivide.triB)
                    {
                        int S = i % (nEdgeNodes[0] - 1);
                        int T = (i - S) / (nEdgeNodes[0] - 1);
                        if (T % 2 == 1)
                        {
                            S++;
                        }
                        if (S % 2 == 0)
                        {
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][0], el[i][1], el[i][3]
                            }));
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][0], el[i][3], el[i][2]
                            }));
                        }
                        else
                        {
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][0], el[i][1], el[i][2]
                            }));
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][2], el[i][1], el[i][3]
                            }));
                        }
                    }
                    if (_subdv == subdivide.triC)
                    {
                        int S = i % (nEdgeNodes[0] - 1);
                        if (S % 2 == 0)
                        {
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][0], el[i][1], el[i][3]
                            }));
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][0], el[i][3], el[i][2]
                            }));
                        }
                        else
                        {
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][0], el[i][1], el[i][2]
                            }));
                            eM.addElement(new mikity.NumericalMethodHelper.elements.simplexElement(new int[3] {
                                el[i][2], el[i][1], el[i][3]
                            }));
                        }
                    }
                }
                if (_subdv == subdivide.quad)
                {
                    nElements *= 1;
                }
                else
                {
                    nElements *= 2;
                }
                lGeometry  = new Rhino.Geometry.Mesh();
                lGeometry2 = new Rhino.Geometry.Mesh();
                lGeometry.Vertices.Clear();
                lGeometry.Faces.Clear();
                lGeometry2.Faces.Clear();
                for (int i = 0; i < pS.Value.__N; i++)
                {
                    lGeometry.Vertices.Add(particles[i][0], particles[i][1], particles[i][2]);
                }
                for (int i = 0; i < nElements; i++)
                {
                    if (_subdv == subdivide.quad)
                    {
                        lGeometry.Faces.AddFace(eM.elemList[i].el[0], eM.elemList[i].el[1], eM.elemList[i].el[3], eM.elemList[i].el[2]);
                    }
                    else
                    {
                        lGeometry.Faces.AddFace(eM.elemList[i].el[0], eM.elemList[i].el[1], eM.elemList[i].el[2]);
                    }
                }
                for (int i = 0; i < nElements; i++)
                {
                    if (_subdv == subdivide.quad)
                    {
                        lGeometry2.Faces.AddFace(eM.elemList[i].el[0], eM.elemList[i].el[1], eM.elemList[i].el[3], eM.elemList[i].el[2]);
                    }
                    else
                    {
                        lGeometry2.Faces.AddFace(eM.elemList[i].el[0], eM.elemList[i].el[1], eM.elemList[i].el[2]);
                    }
                }

                eM.setMaterial(mat.Value, gvt.Value);
                pS.Value.addObject(eM);
                this.DVPW = GetDVPW(lGeometry);
                this.BKGT = GetBKGT(lGeometry);
                pS.DVPW   = GetDVPW(lGeometry2);
                pS.UPGR   = GetUPGR(lGeometry2);
                pS.BKGT   = GetBKGT(lGeometry2);

                DA.SetData(0, pS);
                DA.SetDataList(1, newNodes);
            }
        }
Exemplo n.º 22
0
        public Rhino.Commands.Result AddPoints(Rhino.RhinoDoc doc)
        {
            // Input interval
            double _interval = 0.1;
            double _noise    = 1; // 1% noise

            var input = new Rhino.Input.Custom.GetNumber();

            input.SetCommandPrompt("Input interval(0.0 ~ 1.0)<0.1>");
            Rhino.Input.GetResult res = input.Get();
            if (res == Rhino.Input.GetResult.Number)
            {
                _interval = input.Number();
            }
            if (_interval == 0.0)
            {
                _interval = 0.1;
            }

            input.SetCommandPrompt("Noise factor(0.0 ~ 100.0)");
            res = input.Get();
            if (res == Rhino.Input.GetResult.Number)
            {
                _noise = input.Number();
            }

            // Select surface
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select surface");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            res = go.GetMultiple(1, 1024);
            if (res == Rhino.Input.GetResult.Nothing)
            {
                return(Rhino.Commands.Result.Failure);
            }

            Utility.SetOutputCount(10);
            for (int i = 0; i < go.ObjectCount; i++)
            {
                Rhino.Geometry.Surface surfaceA = go.Object(i).Surface();
                if (surfaceA == null)
                {
                    return(Rhino.Commands.Result.Failure);
                }

                Rhino.Geometry.Interval domU = surfaceA.Domain(0);
                Rhino.Geometry.Interval domV = surfaceA.Domain(1);

                double u, v;
                u = v = 0.0;
                for (u = domU.Min; u <= domU.Max; u += _interval)
                {
                    for (v = domV.Min; v <= domV.Max; v += _interval)
                    {
                        Rhino.Geometry.Point3d  pt  = surfaceA.PointAt(u, v);
                        Rhino.Geometry.Vector3d n   = surfaceA.NormalAt(u, v);
                        Rhino.Geometry.Point3d  pt2 = randomPoint(surfaceA, u, v, _interval, _noise);
                        doc.Objects.AddPoint(pt2);
                    }
                }
            }
            return(Rhino.Commands.Result.Success);
        }
Exemplo n.º 23
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select sphere");
            go.GeometryFilter          = Rhino.DocObjects.ObjectType.Surface;
            go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedSurface;
            go.SubObjectSelect         = false;
            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            Rhino.Geometry.Brep brep = go.Object(0).Brep();
            if (null == brep || 1 != brep.Faces.Count)
            {
                return(Result.Failure);
            }

            Rhino.Geometry.Surface srf = brep.Faces[0].UnderlyingSurface();
            if (null == srf)
            {
                return(Result.Failure);
            }

            Rhino.Geometry.Sphere sphere;
            if (!srf.TryGetSphere(out sphere))
            {
                RhinoApp.WriteLine("Surface is not a sphere");
                return(Result.Nothing);
            }

            Rhino.Input.Custom.GetNumber gn = new Rhino.Input.Custom.GetNumber();
            gn.SetCommandPrompt("New radius");
            gn.SetDefaultNumber(sphere.Radius);
            gn.SetLowerLimit(1.0, false); // or whatever you deem appripriate...
            gn.Get();
            if (gn.CommandResult() != Result.Success)
            {
                return(gn.CommandResult());
            }

            sphere.Radius = gn.Number();

            // Sometimes, Surface.TryGetSphere() will return a sphere with a left-handed
            // plane. So, ensure the plane is right-handed.
            Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(
                sphere.EquitorialPlane.Origin,
                sphere.EquitorialPlane.XAxis,
                sphere.EquitorialPlane.YAxis
                );

            sphere.EquitorialPlane = plane;

            Rhino.Geometry.RevSurface rev_srf = sphere.ToRevSurface();
            if (null != rev_srf)
            {
                doc.Objects.Replace(go.Object(0).ObjectId, rev_srf);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
Exemplo n.º 24
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!DA.GetData(3, ref v))
            {
                return;
            }
            if (!FriedChiken.isInitialized)
            {
                Rhino.Geometry.Surface s = null;
                if (!DA.GetData(0, ref s))
                {
                    return;
                }
                Rhino.Geometry.Interval uDomain = s.Domain(0);
                Rhino.Geometry.Interval vDomain = s.Domain(1);
                int[] nEdgeNodes = new int[_dim];
                DA.GetData(1, ref nEdgeNodes[0]);
                DA.GetData(2, ref nEdgeNodes[1]);
                for (int i = 0; i < _dim; i++)
                {
                    if (nEdgeNodes[i] < 2)
                    {
                        AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "Integers must be greater than or equal to 2");
                        return;
                    }
                }
                newNodes.Clear();
                for (int i = 0; i < nEdgeNodes[1]; i++)
                {
                    for (int j = 0; j < nEdgeNodes[0]; j++)
                    {
                        newNodes.Add(s.PointAt(uDomain.T0 + (uDomain.T1 - uDomain.T0) / (nEdgeNodes[0] - 1) * j, vDomain.T0 + (vDomain.T1 - vDomain.T0) / (nEdgeNodes[1] - 1) * i));
                    }
                }
                int nNewNodes = newNodes.Count;

                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    particles[i] = new mikity.NumericalMethodHelper.particle(newNodes[i][0], newNodes[i][1], newNodes[i][2]);
                }
                pS = new GH_particleSystem(particles);

                node[] lNodes = new node[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    lNodes[i] = new node(i);
                    lNodes[i].copyFrom(pS.Value.particles);
                }
                nF = new nodalForce(v.X, v.Y, v.Z);
                for (int i = 0; i < nNewNodes; i++)
                {
                    nF.addNode(lNodes[i]);
                }
                pS.Value.addObject(nF);
                lGeometry = new Rhino.Geometry.Point3d[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    lGeometry[i] = new Rhino.Geometry.Point3d(particles[i][0], particles[i][1], particles[i][2]);
                }
            }
            else
            {
                nF.forceX = v.X;
                nF.forceY = v.Y;
                nF.forceZ = v.Z;
            }

            DA.SetData(0, pS);
        }
Exemplo n.º 25
0
    public static Rhino.Commands.Result OrientOnSrf(Rhino.RhinoDoc doc)
    {
        // Select objects to orient
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects to orient");
        go.SubObjectSelect = false;
        go.GroupSelect     = true;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        // Point to orient from
        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("Point to orient from");
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Define source plane
        Rhino.Display.RhinoView view = gp.View();
        if (view == null)
        {
            view = doc.Views.ActiveView;
            if (view == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
        }
        Rhino.Geometry.Plane source_plane = view.ActiveViewport.ConstructionPlane();
        source_plane.Origin = gp.Point();

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

        Rhino.DocObjects.ObjRef objref = gs.Object(0);
        // get selected surface object
        Rhino.DocObjects.RhinoObject obj = objref.Object();
        if (obj == null)
        {
            return(Rhino.Commands.Result.Failure);
        }
        // get selected surface (face)
        Rhino.Geometry.Surface surface = objref.Surface();
        if (surface == null)
        {
            return(Rhino.Commands.Result.Failure);
        }
        // Unselect surface
        obj.Select(false);

        // Point on surface to orient to
        gp.SetCommandPrompt("Point on surface to orient to");
        gp.Constrain(surface, false);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Do transformation
        Rhino.Commands.Result rc = Rhino.Commands.Result.Failure;
        double u, v;

        if (surface.ClosestPoint(gp.Point(), out u, out v))
        {
            Rhino.Geometry.Plane target_plane;
            if (surface.FrameAt(u, v, out target_plane))
            {
                // Build transformation
                Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(source_plane, target_plane);

                // Do the transformation. In this example, we will copy the original objects
                const bool delete_original = false;
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    doc.Objects.Transform(go.Object(i), xform, delete_original);
                }

                doc.Views.Redraw();
                rc = Rhino.Commands.Result.Success;
            }
        }
        return(rc);
    }
Exemplo n.º 26
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            var filter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Surface;

            Rhino.DocObjects.ObjRef objref;
            Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface or brep to unroll", false, filter, out objref);

            if (rc != Rhino.Commands.Result.Success)
            {
                return(rc);
            }
            Rhino.Geometry.Unroller unroll = null;
            Rhino.Geometry.Brep     brep   = objref.Brep();
            if (brep != null)
            {
                unroll = new Rhino.Geometry.Unroller(brep);
            }
            else
            {
                Rhino.Geometry.Surface srf = objref.Surface();
                if (srf != null)
                {
                    unroll = new Rhino.Geometry.Unroller(srf);
                }
            }
            if (unroll == null)
            {
                return(Rhino.Commands.Result.Cancel);
            }

            unroll.AbsoluteTolerance = 0.01;
            unroll.RelativeTolerance = 0.01;

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select points, curves, and dots to unroll with surface");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Point | Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.TextDot;
            go.AcceptNothing(true);
            go.GetMultiple(0, 0);
            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }
            for (int i = 0; i < go.ObjectCount; i++)
            {
                objref = go.Object(i);
                Rhino.Geometry.GeometryBase g   = objref.Geometry();
                Rhino.Geometry.Point        pt  = g as Rhino.Geometry.Point;
                Rhino.Geometry.Curve        crv = g as Rhino.Geometry.Curve;
                Rhino.Geometry.TextDot      dot = g as Rhino.Geometry.TextDot;
                if (pt != null)
                {
                    unroll.AddFollowingGeometry(pt.Location);
                }
                else if (crv != null)
                {
                    unroll.AddFollowingGeometry(crv);
                }
                else if (dot != null)
                {
                    unroll.AddFollowingGeometry(dot);
                }
            }

            unroll.ExplodeOutput = false;
            Rhino.Geometry.Curve[]   curves;
            Rhino.Geometry.Point3d[] points;
            Rhino.Geometry.TextDot[] dots;
            Rhino.Geometry.Brep[]    breps = unroll.PerformUnroll(out curves, out points, out dots);
            if (breps == null || breps.Length < 1)
            {
                return(Rhino.Commands.Result.Failure);
            }

            for (int i = 0; i < breps.Length; i++)
            {
                doc.Objects.AddBrep(breps[i]);
            }
            for (int i = 0; i < curves.Length; i++)
            {
                doc.Objects.AddCurve(curves[i]);
            }
            doc.Objects.AddPoints(points);
            for (int i = 0; i < dots.Length; i++)
            {
                doc.Objects.AddTextDot(dots[i]);
            }
            doc.Views.Redraw();
            return(Rhino.Commands.Result.Success);
        }