コード例 #1
0
 public static Surface ToRhino(this DB.RuledSurface surface, DB.BoundingBoxUV bboxUV) => FromRuledSurface
 (
     new DB.Curve[] { surface.GetFirstProfileCurve(), surface.GetSecondProfileCurve() },
     surface.GetFirstProfilePoint(),
     surface.GetSecondProfilePoint(),
     bboxUV
 );
コード例 #2
0
        public static RevSurface ToRhino(this DB.CylindricalSurface surface, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;
            var atol = Revit.AngleTolerance;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);
            var vv   = new Interval(bboxUV.Min.V - ctol, bboxUV.Max.V + ctol);

            var origin = surface.Origin.ToRhino();
            var xdir   = (Vector3d)surface.XDir.ToRhino();
            var zdir   = (Vector3d)surface.Axis.ToRhino();

            var axis  = new Line(origin, origin + zdir);
            var curve = new LineCurve
                        (
                new Line
                (
                    origin + (xdir * surface.Radius) + (zdir * vv.Min),
                    origin + (xdir * surface.Radius) + (zdir * vv.Max)
                ),
                vv.Min,
                vv.Max
                        );

            return(RevSurface.Create(curve, axis, uu.Min, uu.Max));
        }
コード例 #3
0
        static Surface FromExtrudedSurface(IList <DB.Curve> curves, DB.BoundingBoxUV bboxUV, double relativeTolerance)
        {
            var ctol = relativeTolerance * Revit.ShortCurveTolerance;

            var axis = new LineCurve
                       (
                new Line(curves[0].GetEndPoint(0).ToPoint3d(), curves[1].GetEndPoint(0).ToPoint3d()),
                0.0,
                1.0
                       );

            Curve curveU = ToRhino(curves[0]);

            curveU.Translate(axis.PointAt(bboxUV.Min.V) - curveU.PointAtStart);

            Curve curveV = new LineCurve(new Line(axis.PointAt(bboxUV.Min.V), axis.PointAt(bboxUV.Max.V)));

            if (ctol != 0.0)
            {
                curveU = curveU.Extend(CurveEnd.Both, ctol, CurveExtensionStyle.Smooth);
                curveV = curveV.Extend(CurveEnd.Both, ctol, CurveExtensionStyle.Smooth);
            }

            return(SumSurface.Create(curveU, curveV));
        }
コード例 #4
0
        public static RevSurface ToRhino(this DB.ConicalSurface surface, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;
            var atol = Revit.AngleTolerance * 10.0;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);
            var vv   = new Interval(bboxUV.Min.V - ctol, bboxUV.Max.V + ctol);

            var origin = surface.Origin.ToRhino();
            var xdir   = (Vector3d)surface.XDir.ToRhino();
            var zdir   = (Vector3d)surface.Axis.ToRhino();

            var axis = new Line(origin, origin + zdir);

            var dir = zdir + xdir * Math.Tan(surface.HalfAngle);

            dir.Unitize();

            var curve = new LineCurve
                        (
                new Line
                (
                    surface.Origin.ToRhino() + (dir * vv.Min),
                    surface.Origin.ToRhino() + (dir * vv.Max)
                ),
                vv.Min,
                vv.Max
                        );

            return(RevSurface.Create(curve, axis, uu.Min, uu.Max));
        }
コード例 #5
0
        public BRepBuilderSurfaceGeometry BrepFaceToNative(BrepFace face)
        {
            var surface = face.Surface;
            var uvBox   = new DB.BoundingBoxUV(surface.knotsU[0], surface.knotsV[0], surface.knotsU[surface.knotsU.Count - 1], surface.knotsV[surface.knotsV.Count - 1]);
            var surfPts = surface.GetControlPoints();
            var uKnots  = SurfaceKnotsToNative(surface.knotsU);
            var vKnots  = SurfaceKnotsToNative(surface.knotsV);
            var cPts    = ControlPointsToNative(surfPts);

            BRepBuilderSurfaceGeometry result;

            if (!surface.rational)
            {
                result = DB.BRepBuilderSurfaceGeometry.CreateNURBSSurface(surface.degreeU, surface.degreeV, uKnots,
                                                                          vKnots, cPts, false, uvBox);
            }
            else
            {
                var weights = ControlPointWeightsToNative(surfPts);
                result = DB.BRepBuilderSurfaceGeometry.CreateNURBSSurface(surface.degreeU, surface.degreeV, uKnots,
                                                                          vKnots, cPts, weights, false, uvBox);
            }

            return(result);
        }
コード例 #6
0
 public static Surface ToRhino(DB.RuledSurface surface, DB.BoundingBoxUV bboxUV) => FromRuledSurface
 (
     new DB.Curve[] { surface.GetFirstProfileCurve(), surface.GetSecondProfileCurve() },
     surface.HasFirstProfilePoint() ? surface.GetFirstProfilePoint() : null,
     surface.HasSecondProfilePoint() ? surface.GetSecondProfilePoint() : null,
     bboxUV,
     0.0
 );
コード例 #7
0
 public static PlaneSurface ToRhino(this DB.Plane surface, DB.BoundingBoxUV bboxUV) => FromPlane
 (
     surface.Origin,
     surface.XVec,
     surface.YVec,
     surface.Normal,
     bboxUV
 );
コード例 #8
0
 public static RevSurface ToRhino(this DB.ConicalSurface surface, DB.BoundingBoxUV bboxUV) => FromConicalSurface
 (
     surface.Origin,
     surface.XDir,
     surface.YDir,
     surface.Axis,
     surface.HalfAngle,
     bboxUV
 );
コード例 #9
0
 public static RevSurface ToRhino(this DB.CylindricalSurface surface, DB.BoundingBoxUV bboxUV) => FromCylindricalSurface
 (
     surface.Origin,
     surface.XDir,
     surface.YDir,
     surface.Axis,
     surface.Radius,
     bboxUV
 );
コード例 #10
0
 public static RevSurface ToRhino(this DB.RevolvedSurface surface, DB.BoundingBoxUV bboxUV) => FromRevolvedSurface
 (
     surface.Origin,
     surface.XDir,
     surface.YDir,
     surface.Axis,
     surface.GetProfileCurve(),
     bboxUV
 );
コード例 #11
0
        public static NurbsSurface ToRhino(DB.NurbsSurfaceData surface, DB.BoundingBoxUV bboxUV)
        {
            var degreeU = surface.DegreeU;
            var degreeV = surface.DegreeV;

            var knotsU = surface.GetKnotsU();
            var knotsV = surface.GetKnotsV();

            int controlPointCountU = knotsU.Count - degreeU - 1;
            int controlPointCountV = knotsV.Count - degreeV - 1;

            var nurbsSurface = NurbsSurface.Create(3, surface.IsRational, degreeU + 1, degreeV + 1, controlPointCountU, controlPointCountV);

            var controlPoints = surface.GetControlPoints();
            var weights       = surface.GetWeights();

            var points = nurbsSurface.Points;

            for (int u = 0; u < controlPointCountU; u++)
            {
                int u_offset = u * controlPointCountV;
                for (int v = 0; v < controlPointCountV; v++)
                {
                    var pt = controlPoints[u_offset + v];
                    if (surface.IsRational)
                    {
                        double w = weights[u_offset + v];
                        points.SetPoint(u, v, pt.X * w, pt.Y * w, pt.Z * w, w);
                    }
                    else
                    {
                        points.SetPoint(u, v, pt.X, pt.Y, pt.Z);
                    }
                }
            }

            {
                var knots = nurbsSurface.KnotsU;
                int index = 0;
                foreach (var w in knotsU.Skip(1).Take(knots.Count))
                {
                    knots[index++] = w;
                }
            }

            {
                var knots = nurbsSurface.KnotsV;
                int index = 0;
                foreach (var w in knotsV.Skip(1).Take(knots.Count))
                {
                    knots[index++] = w;
                }
            }

            return(nurbsSurface);
        }
コード例 #12
0
        public Geometry.Surface FaceToSpeckle(DB.Face face, DB.BoundingBoxUV uvBox, string units = null)
        {
#if (REVIT2021 || REVIT2022)
            var surf = DB.ExportUtils.GetNurbsSurfaceDataForSurface(face.GetSurface());
#else
            var surf = DB.ExportUtils.GetNurbsSurfaceDataForFace(face);
#endif
            var spcklSurface = NurbsSurfaceToSpeckle(surf, face.GetBoundingBox(), units ?? ModelUnits);
            return(spcklSurface);
        }
コード例 #13
0
        public Surface NurbsSurfaceToSpeckle(DB.NurbsSurfaceData surface, DB.BoundingBoxUV uvBox, string units = null)
        {
            var result = new Surface();
            var unit   = units ?? ModelUnits;

            result.units = unit;

            result.degreeU = surface.DegreeU;
            result.degreeV = surface.DegreeV;

            result.domainU = new Interval(0, 1);
            result.domainV = new Interval(0, 1);

            var knotsU = surface.GetKnotsU().ToList();
            var knotsV = surface.GetKnotsV().ToList();

            result.knotsU = knotsU.GetRange(1, knotsU.Count - 2);
            result.knotsV = knotsV.GetRange(1, knotsV.Count - 2);

            var controlPointCountU = knotsU.Count - result.degreeU - 1;
            var controlPointCountV = knotsV.Count - result.degreeV - 1;

            var controlPoints = surface.GetControlPoints();
            var weights       = surface.GetWeights();

            var points = new List <List <ControlPoint> >();

            for (var u = 0; u < controlPointCountU; u++)
            {
                var uOffset = u * controlPointCountV;
                var row     = new List <ControlPoint>();

                for (var v = 0; v < controlPointCountV; v++)
                {
                    var pt    = controlPoints[uOffset + v];
                    var extPt = ToExternalCoordinates(pt);
                    if (surface.IsRational)
                    {
                        var w     = weights[uOffset + v];
                        var point = PointToSpeckle(extPt, unit);
                        row.Add(new ControlPoint(point.x, point.y, point.z, w, unit));
                    }
                    else
                    {
                        var point = PointToSpeckle(extPt, unit);
                        row.Add(new ControlPoint(point.x, point.y, point.z, unit));
                    }
                }
                points.Add(row);
            }

            result.SetControlPoints(points);

            return(result);
        }
コード例 #14
0
        public Geometry.Surface FaceToSpeckle(DB.Face face, DB.BoundingBoxUV uvBox)
        {
#if REVIT2021
            var surf = DB.ExportUtils.GetNurbsSurfaceDataForSurface(face.GetSurface());
#else
            var surf = DB.ExportUtils.GetNurbsSurfaceDataForFace(face);
#endif

            var spcklSurface = NurbsSurfaceToSpeckle(surf, face.GetBoundingBox());
            return(spcklSurface);
        }
コード例 #15
0
        public static PlaneSurface ToRhino(this DB.Plane surface, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;
            var uu   = new Interval(bboxUV.Min.U - ctol, bboxUV.Max.U + ctol);
            var vv   = new Interval(bboxUV.Min.V - ctol, bboxUV.Max.V + ctol);

            return(new PlaneSurface
                   (
                       new Plane(surface.Origin.ToRhino(), (Vector3d)surface.XVec.ToRhino(), (Vector3d)surface.YVec.ToRhino()),
                       uu,
                       vv
                   ));
        }
コード例 #16
0
        public Surface NurbsSurfaceToSpeckle(DB.NurbsSurfaceData surface, DB.BoundingBoxUV uvBox)
        {
            var result = new Surface();

            result.units = ModelUnits;

            result.degreeU = surface.DegreeU;
            result.degreeV = surface.DegreeV;

            var knotsU = surface.GetKnotsU().ToList();
            var knotsV = surface.GetKnotsV().ToList();

            result.knotsU = knotsU.GetRange(1, knotsU.Count - 2);
            result.knotsV = knotsV.GetRange(1, knotsV.Count - 2);

            var controlPointCountU = knotsU.Count - result.degreeU - 1;
            var controlPointCountV = knotsV.Count - result.degreeV - 1;

            var controlPoints = surface.GetControlPoints();
            var weights       = surface.GetWeights();

            var points = new List <List <ControlPoint> >();

            for (var u = 0; u < controlPointCountU; u++)
            {
                var uOffset = u * controlPointCountV;
                var row     = new List <ControlPoint>();

                for (var v = 0; v < controlPointCountV; v++)
                {
                    var pt    = controlPoints[uOffset + v];
                    var extPt = ToExternalCoordinates(pt);
                    if (surface.IsRational)
                    {
                        var w = weights[uOffset + v];
                        row.Add(new ControlPoint(ScaleToSpeckle(extPt.X), ScaleToSpeckle(extPt.Y), ScaleToSpeckle(extPt.Z), w, ModelUnits));
                    }
                    else
                    {
                        row.Add(new ControlPoint(ScaleToSpeckle(extPt.X), ScaleToSpeckle(extPt.Y), ScaleToSpeckle(extPt.Z), ModelUnits));
                    }
                }
                points.Add(row);
            }
            result.SetControlPoints(points);
            return(result);
        }
コード例 #17
0
        public static RevSurface ToRhino(this DB.RevolvedSurface surface, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;
            var atol = Revit.AngleTolerance;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);

            var axis = new Line
                       (
                surface.Origin.ToRhino(),
                surface.Origin.ToRhino() + (Vector3d)surface.Axis.ToRhino()
                       );

            var curve = surface.GetProfileCurveInWorldCoordinates().ToRhino();

            curve = curve.Extend(CurveEnd.Both, ctol, CurveExtensionStyle.Line);

            return(RevSurface.Create(curve, axis, uu.Min, uu.Max));
        }
コード例 #18
0
        public static Surface ToRhino(this DB.RuledSurface surface, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;

            var     curves = new List <Curve>();
            Point3d start = Point3d.Unset, end = Point3d.Unset;

            if (surface.HasFirstProfilePoint())
            {
                start = surface.GetFirstProfilePoint().ToRhino();
            }
            else
            {
                curves.Add(surface.GetFirstProfileCurve().ToRhino());
            }

            if (surface.HasSecondProfilePoint())
            {
                end = surface.GetSecondProfilePoint().ToRhino();
            }
            else
            {
                curves.Add(surface.GetSecondProfileCurve().ToRhino());
            }

            // Revit Ruled surface Parametric Orientation is opposite to Rhino
            for (var c = 0; c < curves.Count; ++c)
            {
                curves[c].Reverse();
                curves[c] = curves[c].Extend(CurveEnd.Both, ctol, CurveExtensionStyle.Line);
            }

            var lofts = Brep.CreateFromLoft(curves, start, end, LoftType.Straight, false);

            if (lofts.Length == 1 && lofts[0].Surfaces.Count == 1)
            {
                return(lofts[0].Surfaces[0]);
            }

            return(null);
        }
コード例 #19
0
        public static DB.BRepBuilderSurfaceGeometry ToHost(BrepFace face)
        {
            // TODO: Implement conversion from other Rhino surface types like PlaneSurface, RevSurface and SumSurface.

            var isNurbs = face.UnderlyingSurface() is NurbsSurface;

            using (var nurbsSurface = face.ToNurbsSurface())
            {
                var degreeU       = nurbsSurface.Degree(0);
                var degreeV       = nurbsSurface.Degree(1);
                var knotsU        = ToHost(nurbsSurface.KnotsU);
                var knotsV        = ToHost(nurbsSurface.KnotsV);
                var controlPoints = ToHost(nurbsSurface.Points);
                var bboxUV        = new DB.BoundingBoxUV(knotsU[0], knotsV[0], knotsU[knotsU.Length - 1], knotsV[knotsV.Length - 1]);

                Debug.Assert(!nurbsSurface.IsClosed(0));
                Debug.Assert(!nurbsSurface.IsClosed(1));
                Debug.Assert(degreeU >= 1);
                Debug.Assert(degreeV >= 1);
                Debug.Assert(knotsU.Length >= 2 * (degreeU + 1));
                Debug.Assert(knotsV.Length >= 2 * (degreeV + 1));
                Debug.Assert(controlPoints.Length == (knotsU.Length - degreeU - 1) * (knotsV.Length - degreeV - 1));

                if (nurbsSurface.IsRational)
                {
                    var weights = nurbsSurface.Points.Select(p => p.Weight).ToList();

                    return(DB.BRepBuilderSurfaceGeometry.CreateNURBSSurface
                           (
                               degreeU, degreeV, knotsU, knotsV, controlPoints, weights, false, isNurbs ? bboxUV : default
                           ));
                }
                else
                {
                    return(DB.BRepBuilderSurfaceGeometry.CreateNURBSSurface
                           (
                               degreeU, degreeV, knotsU, knotsV, controlPoints, false, isNurbs ? bboxUV : default
                           ));
                }
            }
        }
コード例 #20
0
        static Surface FromRuledSurface(IList <DB.Curve> curves, DB.XYZ start, DB.XYZ end, DB.BoundingBoxUV bboxUV, double relativeTolerance)
        {
            var ctol = relativeTolerance * Revit.ShortCurveTolerance;

            var cs = curves.Where(x => x is object).Select
                     (
                x =>
            {
                var c = ToRhino(x);
                return(ctol == 0.0 ? c : c.Extend(CurveEnd.Both, ctol, CurveExtensionStyle.Smooth));
            }
                     );

            Point3d p0 = start is null ? Point3d.Unset : AsPoint3d(start),
                    pN = end   is null ? Point3d.Unset : AsPoint3d(end);

            var lofts = Brep.CreateFromLoft(cs, p0, pN, LoftType.Straight, false);

            if (lofts.Length == 1 && lofts[0].Faces.Count == 1)
            {
                // Surface.Transpose is necessary since Brep.CreateFromLoft places the input curves along V,
                // instead of that Revit Ruled Surface has those Curves along U axis.
                // This subtle thing also result in the correct normal of the resulting surface.
                // Transpose also duplicates the underlaying surface, what is a desired side effect of calling Transpose here.
                return(lofts[0].Faces[0].Transpose());
            }

            return(null);
        }
コード例 #21
0
        static RevSurface FromRevolvedSurface(DB.XYZ origin, DB.XYZ xDir, DB.XYZ yDir, DB.XYZ zDir, DB.Curve curve, DB.BoundingBoxUV bboxUV, double relativeTolerance)
        {
            var atol = relativeTolerance * Revit.AngleTolerance;
            var ctol = relativeTolerance * Revit.ShortCurveTolerance;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);

            var plane = new Plane
                        (
                AsPoint3d(origin),
                AsVector3d(xDir),
                AsVector3d(yDir)
                        );
            var axisDir = AsVector3d(zDir);

            using (var ECStoWCS = new DB.Transform(DB.Transform.Identity)
            {
                Origin = origin, BasisX = xDir.Normalize(), BasisY = yDir.Normalize(), BasisZ = zDir.Normalize()
            })
            {
                var c = ToRhino(curve.CreateTransformed(ECStoWCS));
                c = ctol == 0.0 ? c : c.Extend(CurveEnd.Both, ctol, CurveExtensionStyle.Smooth);

                var axis = new Line(plane.Origin, plane.Normal);
                return(RevSurface.Create(c, axis, uu.Min, uu.Max));
            }
        }
コード例 #22
0
        static RevSurface FromCylindricalSurface(DB.XYZ origin, DB.XYZ xDir, DB.XYZ yDir, DB.XYZ zDir, double radius, DB.BoundingBoxUV bboxUV, double relativeTolerance)
        {
            var atol = relativeTolerance * Revit.AngleTolerance;
            var ctol = relativeTolerance * Revit.ShortCurveTolerance;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);
            var vv   = new Interval(bboxUV.Min.V - ctol, bboxUV.Max.V + ctol);

            var plane = new Plane
                        (
                AsPoint3d(origin),
                AsVector3d(xDir),
                AsVector3d(yDir)
                        );
            var axisDir = AsVector3d(zDir);

            var curve = new LineCurve
                        (
                new Line
                (
                    plane.Origin + (radius * plane.XAxis) + (vv.Min * axisDir),
                    plane.Origin + (radius * plane.XAxis) + (vv.Max * axisDir)
                ),
                vv.Min,
                vv.Max
                        );

            var axis = new Line(plane.Origin, plane.Normal);

            return(RevSurface.Create(curve, axis, uu.Min, uu.Max));
        }
コード例 #23
0
        static RevSurface FromConicalSurface(DB.XYZ origin, DB.XYZ xDir, DB.XYZ yDir, DB.XYZ zDir, double halfAngle, DB.BoundingBoxUV bboxUV, double relativeTolerance)
        {
            var atol = relativeTolerance * Revit.AngleTolerance * 10.0;
            var ctol = relativeTolerance * Revit.ShortCurveTolerance;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);
            var vv   = new Interval(bboxUV.Min.V - ctol, bboxUV.Max.V + ctol);

            var plane = new Plane
                        (
                AsPoint3d(origin),
                AsVector3d(xDir),
                AsVector3d(yDir)
                        );
            var axisDir = AsVector3d(zDir);

            var dir = axisDir + Math.Tan(halfAngle) * plane.XAxis;

            dir.Unitize();

            var curve = new LineCurve
                        (
                new Line
                (
                    plane.Origin + (vv.Min * dir),
                    plane.Origin + (vv.Max * dir)
                ),
                vv.Min,
                vv.Max
                        );

            var axis = new Line(plane.Origin, plane.Normal);

            return(RevSurface.Create(curve, axis, uu.Min, uu.Max));
        }
コード例 #24
0
        static PlaneSurface FromPlane(DB.XYZ origin, DB.XYZ xDir, DB.XYZ yDir, DB.XYZ zDir, DB.BoundingBoxUV bboxUV, double relativeTolerance)
        {
            var ctol = relativeTolerance * Revit.ShortCurveTolerance;
            var uu   = new Interval(bboxUV.Min.U - ctol, bboxUV.Max.U + ctol);
            var vv   = new Interval(bboxUV.Min.V - ctol, bboxUV.Max.V + ctol);

            var plane = new Plane
                        (
                AsPoint3d(origin),
                AsVector3d(xDir),
                AsVector3d(yDir)
                        );

            return(new PlaneSurface(plane, uu, vv));
        }
コード例 #25
0
        static RevSurface FromConicalSurface(DB.XYZ origin, DB.XYZ xDir, DB.XYZ yDir, DB.XYZ zDir, double halfAngle, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;
            var atol = Revit.AngleTolerance * 10.0;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);
            var vv   = new Interval(bboxUV.Min.V - ctol, bboxUV.Max.V + ctol);

            var o = origin.ToRhino();
            var x = (Vector3d)xDir.Normalize().ToRhino();
            var z = (Vector3d)zDir.Normalize().ToRhino();

            var axis = new Line(o, o + z);

            var dir = z + x * Math.Tan(halfAngle);

            dir.Unitize();

            var curve = new LineCurve
                        (
                new Line
                (
                    o + (dir * vv.Min),
                    o + (dir * vv.Max)
                ),
                vv.Min,
                vv.Max
                        );

            return(RevSurface.Create(curve, axis, uu.Min, uu.Max));
        }
コード例 #26
0
        static Surface FromRuledSurface(IList <DB.Curve> curves, DB.XYZ start, DB.XYZ end, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;

            var cs = curves.Select
                     (
                x =>
            {
                var c = x.ToRhino(); c.Reverse();
                return(c.Extend(CurveEnd.Both, ctol, CurveExtensionStyle.Smooth));
            }
                     );

            Point3d p0 = start?.ToRhino() ?? Point3d.Unset, pN = end?.ToRhino() ?? Point3d.Unset;

            var lofts = Brep.CreateFromLoft(cs, p0, pN, LoftType.Straight, false);

            if (lofts.Length == 1 && lofts[0].Faces.Count == 1)
            {
                return(lofts[0].Faces[0].DuplicateSurface());
            }

            return(null);
        }
コード例 #27
0
        static RevSurface FromRevolvedSurface(DB.XYZ origin, DB.XYZ xDir, DB.XYZ yDir, DB.XYZ zDir, DB.Curve curve, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;
            var atol = Revit.AngleTolerance;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);

            var o = origin.ToRhino();
            var z = (Vector3d)zDir.Normalize().ToRhino();

            var axis = new Line(o, o + z);

            using (var ECStoWCS = new DB.Transform(DB.Transform.Identity)
            {
                Origin = origin, BasisX = xDir.Normalize(), BasisY = yDir.Normalize(), BasisZ = zDir.Normalize()
            })
            {
                var c = curve.CreateTransformed(ECStoWCS).ToRhino().Extend(CurveEnd.Both, ctol, CurveExtensionStyle.Smooth);
                return(RevSurface.Create(c, axis, uu.Min, uu.Max));
            }
        }
コード例 #28
0
        static Surface FromRuledSurface(IList <DB.Curve> curves, DB.XYZ start, DB.XYZ end, DB.BoundingBoxUV bboxUV, double relativeTolerance)
        {
            var ctol = relativeTolerance * Revit.ShortCurveTolerance;

            var cs = curves.Where(x => x is object).Select
                     (
                x =>
            {
                var c = ToRhino(x); c.Reverse();
                return(ctol == 0.0 ? c : c.Extend(CurveEnd.Both, ctol, CurveExtensionStyle.Smooth));
            }
                     );

            Point3d p0 = start is null ? Point3d.Unset : ToRhino(start),
                    pN = end is null ? Point3d.Unset : ToRhino(end);

            var lofts = Brep.CreateFromLoft(cs, p0, pN, LoftType.Straight, false);

            if (lofts.Length == 1 && lofts[0].Faces.Count == 1)
            {
                return(lofts[0].Faces[0].DuplicateSurface());
            }

            return(null);
        }
コード例 #29
0
        static RevSurface FromCylindricalSurface(DB.XYZ origin, DB.XYZ xDir, DB.XYZ yDir, DB.XYZ zDir, double radius, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;
            var atol = Revit.AngleTolerance;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);
            var vv   = new Interval(bboxUV.Min.V - ctol, bboxUV.Max.V + ctol);

            var o = origin.ToRhino();
            var x = (Vector3d)xDir.Normalize().ToRhino();
            var z = (Vector3d)zDir.Normalize().ToRhino();

            var axis  = new Line(o, o + z);
            var curve = new LineCurve
                        (
                new Line
                (
                    o + (x * radius) + (z * vv.Min),
                    o + (x * radius) + (z * vv.Max)
                ),
                vv.Min,
                vv.Max
                        );

            return(RevSurface.Create(curve, axis, uu.Min, uu.Max));
        }
コード例 #30
0
        static PlaneSurface FromPlane(DB.XYZ origin, DB.XYZ xDir, DB.XYZ yDir, DB.XYZ zDir, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;
            var uu   = new Interval(bboxUV.Min.U - ctol, bboxUV.Max.U + ctol);
            var vv   = new Interval(bboxUV.Min.V - ctol, bboxUV.Max.V + ctol);

            return(new PlaneSurface
                   (
                       new Plane(origin.ToRhino(), (Vector3d)xDir.ToRhino(), (Vector3d)yDir.ToRhino()),
                       uu,
                       vv
                   ));
        }