コード例 #1
0
        /// <summary>
        /// Convert a Nucleus Linear Element to a Rhino Extrusion, if possible
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static RC.Extrusion ConvertToExtrusion(LinearElement element)
        {
            Curve           perimeter = element?.Family?.Profile?.Perimeter;
            CurveCollection voids     = element?.Family?.Profile?.Voids;

            if (perimeter != null && element.Geometry != null)
            {
                RC.Curve profile = Convert(perimeter);
                var      cSystem = element.Geometry.LocalCoordinateSystem(0, element.Orientation);
                if (element.Geometry is Line)
                {
                    //If a line, create an extrusion:
                    RC.Extrusion ext = new RC.Extrusion();
                    ext.SetPathAndUp(
                        Convert(element.Geometry.EndPoint), Convert(element.Geometry.StartPoint),
                        ConvertVector(cSystem.Z));
                    ext.SetOuterProfile(profile, true);
                    if (voids != null)
                    {
                        var voidCrvs = Convert(voids);
                        foreach (var rCrv in voidCrvs)
                        {
                            ext.AddInnerProfile(rCrv);
                        }
                    }
                    //RC.Surface surface = RC.Extrusion.CreateExtrusion(profile, new RC.Vector3d(Convert(element.End.Position - element.Start.Position)));
                    return(ext);
                }
            }
            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Convert a Nucleus extrusion volume to a Rhino one
        /// </summary>
        /// <param name="extrusion"></param>
        /// <returns></returns>
        public static RC.Extrusion Convert(Extrusion extrusion)
        {
            if (extrusion.IsValid)
            {
                Curve           perimeter = extrusion.Profile?.Perimeter;
                CurveCollection voids     = extrusion.Profile?.Voids;
                if (perimeter != null)
                {
                    RC.Curve profile = Convert(perimeter);
                    // var cSystem = new CartesianCoordinateSystem(new Vector(), extrusion.Path);
                    //If a line, create an extrusion:
                    RC.Extrusion ext = new RC.Extrusion();

                    ext.SetPathAndUp(new RC.Point3d(0, 0, 0), Convert(extrusion.Path), RC.Vector3d.YAxis); //TODO: Test!
                    //ConvertVector(cSystem.Z));
                    ext.SetOuterProfile(profile, true);
                    if (voids != null)
                    {
                        var voidCrvs = Convert(voids);
                        foreach (var rCrv in voidCrvs)
                        {
                            ext.AddInnerProfile(rCrv);
                        }
                    }
                    //RC.Surface surface = RC.Extrusion.CreateExtrusion(profile, new RC.Vector3d(Convert(element.End.Position - element.Start.Position)));
                    return(ext);
                }
            }
            return(null);
        }
コード例 #3
0
        public static bool TryGetExtrusion(this Surface surface, out Extrusion extrusion)
        {
            extrusion = null;
            var nurbsSurface = surface as NurbsSurface ?? surface.ToNurbsSurface();

            for (int direction = 1; direction >= 0; --direction)
            {
                var oposite = direction == 0 ? 1 : 0;

                if (surface.IsClosed(direction))
                {
                    continue;
                }

                var domain = nurbsSurface.Domain(direction);
                var iso0   = nurbsSurface.IsoCurve(oposite, domain.Min);
                var iso1   = nurbsSurface.IsoCurve(oposite, domain.Max);

                if (iso0.TryGetPlane(out var plane0) && iso1.TryGetPlane(out var plane1))
                {
                    if (plane0.Normal.IsParallelTo(plane1.Normal, RhinoMath.DefaultAngleTolerance / 100.0) == 1)
                    {
                        var rowCount    = direction == 0 ? nurbsSurface.Points.CountU : nurbsSurface.Points.CountV;
                        var columnCount = direction == 0 ? nurbsSurface.Points.CountV : nurbsSurface.Points.CountU;
                        for (int c = 0; c < columnCount; ++c)
                        {
                            var point = direction == 0 ? nurbsSurface.Points.GetControlPoint(0, c) : nurbsSurface.Points.GetControlPoint(c, 0);
                            for (int r = 1; r < rowCount; ++r)
                            {
                                var pointR          = direction == 0 ? nurbsSurface.Points.GetControlPoint(r, c) : nurbsSurface.Points.GetControlPoint(c, r);
                                var projectedPointR = plane0.ClosestPoint(pointR.Location);
                                if (projectedPointR.DistanceToSquared(point.Location) > RhinoMath.SqrtEpsilon)
                                {
                                    return(false);
                                }

                                if (Math.Abs(pointR.Weight - point.Weight) > RhinoMath.ZeroTolerance)
                                {
                                    return(false);
                                }
                            }
                        }

                        // Extrusion.Create does not work well when 'iso0' is a line-like curve,
                        // plane used to extrude is "arbitrary" in this case
                        //extrusion = Extrusion.Create(iso0, zAxis.Length, false);

                        var axis  = new Line(iso0.PointAtStart, iso1.PointAtStart);
                        var zAxis = iso1.PointAtStart - iso0.PointAtStart;
                        var xAxis = (iso0.IsClosed ? iso0.PointAt(iso0.Domain.Mid) : iso0.PointAtEnd) - iso0.PointAtStart;
                        var yAxis = Vector3d.CrossProduct(zAxis, xAxis);

                        extrusion = new Extrusion();
                        if (!iso0.Transform(Transform.PlaneToPlane(new Plane(iso0.PointAtStart, xAxis, yAxis), Plane.WorldXY)))
                        {
                            return(false);
                        }

                        return(extrusion.SetPathAndUp(axis.From, axis.To, yAxis) && extrusion.SetOuterProfile(iso0, false));
                    }
                }
            }

            return(false);
        }