Skip to content

Commit

Permalink
Now GeometryBase.ToShape skip geometry with bounding box below tole…
Browse files Browse the repository at this point in the history
…rance.
  • Loading branch information
kike-garbo committed Jul 6, 2023
1 parent c2a42f1 commit ea5e807
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 47 deletions.
9 changes: 2 additions & 7 deletions src/RhinoInside.Revit/Convert/Geometry/BrepEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,9 @@ internal static bool EncodeRaw(ref Brep brep, double scaleFactor)
if (scaleFactor != 1.0 && !brep.Scale(scaleFactor))
return default;

var tol = GeometryTolerance.Internal;
var bbox = brep.GetBoundingBox(false);
if (!bbox.IsValid || bbox.Diagonal.Length < tol.ShortCurveTolerance)
return default;

// Split and Shrink faces
{
brep.Faces.SplitKinkyFaces(tol.AngleTolerance, true);
brep.Faces.SplitKinkyFaces(GeometryTolerance.Internal.AngleTolerance, true);
brep.Faces.SplitClosedFaces(0);
brep.Faces.ShrinkFaces();
}
Expand Down Expand Up @@ -290,7 +285,7 @@ internal static bool TryGetSolid(/*const*/Brep brep, double factor, out ARDB.Sol
{
var tol = GeometryTolerance.Internal;
var height = extrusion.PathStart.DistanceTo(extrusion.PathEnd);
if (height < Autodesk.Revit.ApplicationServices.Application.MinimumThickness / factor)
if (height < tol.VertexTolerance / factor)
{
var curves = new Curve[extrusion.ProfileCount];
for (int p = 0; p < extrusion.ProfileCount; ++p)
Expand Down
100 changes: 60 additions & 40 deletions src/RhinoInside.Revit/Convert/Geometry/ShapeEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,73 @@ static class ShapeEncoder
public static ARDB.GeometryObject[] ToShape(this GeometryBase geometry) => ToShape(geometry, GeometryEncoder.ModelScaleFactor);
internal static ARDB.GeometryObject[] ToShape(this GeometryBase geometry, double factor)
{
switch (geometry)
if (AuditGeometry(geometry))
{
case Point point:
return new ARDB.Point[] { point.ToPoint(factor) };

case PointCloud pointCloud:
return pointCloud.Select(x => x.ToPoint(factor)).ToArray();

case Curve curve:
if (curve.SpanCount > 1 && curve.TryGetPolyline(out var polyline))
return new ARDB.PolyLine[] { polyline.ToPolyLine(factor) };

return curve.TryGetPolyCurve(out var polyCurve, GeometryTolerance.Internal.AngleTolerance) ?
polyCurve.ToCurveMany(factor).Select(ToShape).ToArray() :
new ARDB.Curve[] { curve.ToCurve(factor).ToShape() };

case Brep brep:
if (ToShape(brep, factor) is ARDB.GeometryObject brepShape)
return new ARDB.GeometryObject[] { brepShape };
break;
switch (geometry)
{
case Point point:
return new ARDB.Point[] { point.ToPoint(factor) };

case PointCloud pointCloud:
return pointCloud.Select(x => x.ToPoint(factor)).ToArray();

case Curve curve:
if (curve.SpanCount > 1 && curve.TryGetPolyline(out var polyline))
return new ARDB.PolyLine[] { polyline.ToPolyLine(factor) };

return curve.TryGetPolyCurve(out var polyCurve, GeometryTolerance.Internal.AngleTolerance) ?
polyCurve.ToCurveMany(factor).Select(ToShape).ToArray() :
new ARDB.Curve[] { curve.ToCurve(factor).ToShape() };

case Brep brep:
if (ToShape(brep, factor) is ARDB.GeometryObject brepShape)
return new ARDB.GeometryObject[] { brepShape };
break;

case Extrusion extrusion:
if (ToShape(extrusion, factor) is ARDB.GeometryObject extrusionShape)
return new ARDB.GeometryObject[] { extrusionShape };
break;

case SubD subD:
if (ToShape(subD, factor) is ARDB.GeometryObject subDShape)
return new ARDB.GeometryObject[] { subDShape };
break;

case Mesh mesh:
if (MeshEncoder.ToMesh(MeshEncoder.ToRawMesh(mesh, factor)) is ARDB.GeometryObject meshShape)
return new ARDB.GeometryObject[] { meshShape };
break;

default:
if (geometry.HasBrepForm)
{
var brepForm = Brep.TryConvertBrep(geometry);
if (brepForm is object && ToShape(brepForm, factor) is ARDB.GeometryObject geometryShape)
return new ARDB.GeometryObject[] { geometryShape };
}
break;
}
}

case Extrusion extrusion:
if (ToShape(extrusion, factor) is ARDB.GeometryObject extrusionShape)
return new ARDB.GeometryObject[] { extrusionShape };
break;
return Array.Empty<ARDB.GeometryObject>();
}

case SubD subD:
if (ToShape(subD, factor) is ARDB.GeometryObject subDShape)
return new ARDB.GeometryObject[] { subDShape };
break;
static bool AuditGeometry(GeometryBase geometry)
{
var bbox = geometry.GetBoundingBox(false);
if (!bbox.IsValid)
return false;

case Mesh mesh:
if (MeshEncoder.ToMesh(MeshEncoder.ToRawMesh(mesh, factor)) is ARDB.GeometryObject meshShape)
return new ARDB.GeometryObject[] { meshShape };
break;
var tol = GeometryTolerance.Model;
switch (geometry)
{
case Point _:
return true;

default:
if (geometry.HasBrepForm)
{
var brepForm = Brep.TryConvertBrep(geometry);
if (brepForm is object && ToShape(brepForm, factor) is ARDB.GeometryObject geometryShape)
return new ARDB.GeometryObject[] { geometryShape };
}
break;
return !bbox.Diagonal.EpsilonEquals(Vector3d.Zero, 2.0 * tol.VertexTolerance);
}

return Array.Empty<ARDB.GeometryObject>();
}

static ARDB.Curve ToShape(this ARDB.Curve curve)
Expand Down

0 comments on commit ea5e807

Please sign in to comment.