-
Notifications
You must be signed in to change notification settings - Fork 41
feat (rhino): receive revit solids as breps #1273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using Speckle.Connectors.DUI.Settings; | ||
|
|
||
| namespace Speckle.Connectors.Rhino.Operations.Receive.Settings; | ||
|
|
||
| public class ConvertMeshesToBrepsSetting(bool value = false) : ICardSetting | ||
| { | ||
| public const string SETTING_ID = "convertMeshesToBreps"; | ||
|
|
||
| public string? Id { get; set; } = SETTING_ID; | ||
| public string? Title { get; set; } = "Convert solid meshes to Breps"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| public string? Type { get; set; } = "boolean"; | ||
| public object? Value { get; set; } = value; | ||
| public List<string>? Enum { get; set; } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using Speckle.Connectors.DUI.Models.Card; | ||
| using Speckle.InterfaceGenerator; | ||
|
|
||
| namespace Speckle.Connectors.Rhino.Operations.Receive.Settings; | ||
|
|
||
| [GenerateAutoInterface] | ||
| public class ToHostSettingsManager : IToHostSettingsManager | ||
| { | ||
| public bool GetConvertMeshesToBrepsSetting(ModelCard modelCard) | ||
| { | ||
| var value = modelCard.Settings?.FirstOrDefault(s => s.Id == ConvertMeshesToBrepsSetting.SETTING_ID)?.Value as bool?; | ||
| return value is true; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -293,14 +293,23 @@ private List<DisplayValueResult> ProcessGeometryCollections( | |
| DB.Transform? curveTransform | ||
| ) | ||
| { | ||
| var meshesByMaterial = GetMeshesByMaterial(collections.Meshes, collections.Solids); | ||
| var displayMeshes = _meshByMaterialConverter.Convert( | ||
| (meshesByMaterial, element.Id, ShouldSetElementDisplayToTransparent(element)) | ||
| ); | ||
| bool makeTransparent = ShouldSetElementDisplayToTransparent(element); | ||
|
|
||
| // Native meshes | ||
| var meshesByMaterial = GetMeshesByMaterialFromMeshes(collections.Meshes); | ||
| var displayMeshes = _meshByMaterialConverter.Convert((meshesByMaterial, element.Id, makeTransparent)); | ||
|
|
||
| // Solid-origin meshes — processed separately and tagged | ||
| var solidMeshesByMaterial = GetMeshesByMaterialFromSolids(collections.Solids); | ||
| var solidDisplayMeshes = _meshByMaterialConverter.Convert((solidMeshesByMaterial, element.Id, makeTransparent)); | ||
| foreach (var solidMesh in solidDisplayMeshes) | ||
| { | ||
| solidMesh["fromSolid"] = true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we would need this flag at all? Why not to just |
||
| } | ||
|
|
||
| List<DisplayValueResult> displayValue = new(collections.TotalCount); | ||
|
|
||
| foreach (var mesh in displayMeshes) | ||
| foreach (var mesh in displayMeshes.Concat(solidDisplayMeshes)) | ||
| { | ||
| // if we have a transform, keep mesh in symbol space and attach transform | ||
| displayValue.Add( | ||
|
|
@@ -388,10 +397,7 @@ private Matrix4x4 TransformToMatrix(DB.Transform transform) => | |
| return null; | ||
| } | ||
|
|
||
| private static Dictionary<DB.ElementId, List<DB.Mesh>> GetMeshesByMaterial( | ||
| List<DB.Mesh> meshes, | ||
| List<DB.Solid> solids | ||
| ) | ||
| private static Dictionary<DB.ElementId, List<DB.Mesh>> GetMeshesByMaterialFromMeshes(List<DB.Mesh> meshes) | ||
| { | ||
| var meshesByMaterial = new Dictionary<DB.ElementId, List<DB.Mesh>>(); | ||
| foreach (var mesh in meshes) | ||
|
|
@@ -406,6 +412,12 @@ private Matrix4x4 TransformToMatrix(DB.Transform transform) => | |
| value.Add(mesh); | ||
| } | ||
|
|
||
| return meshesByMaterial; | ||
| } | ||
|
|
||
| private static Dictionary<DB.ElementId, List<DB.Mesh>> GetMeshesByMaterialFromSolids(List<DB.Solid> solids) | ||
| { | ||
| var meshesByMaterial = new Dictionary<DB.ElementId, List<DB.Mesh>>(); | ||
| foreach (var solid in solids) | ||
| { | ||
| foreach (DB.Face face in solid.Faces) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| using Speckle.Converters.Common; | ||
| using Speckle.Converters.Common.Objects; | ||
|
|
||
| namespace Speckle.Converters.Rhino.ToHost.Helpers; | ||
|
|
||
| public interface IMeshToHostConversionHelper | ||
| { | ||
| RG.GeometryBase ConvertMesh(SOG.Mesh mesh); | ||
| } | ||
|
|
||
| public class MeshToHostConversionHelper( | ||
| ITypedConverter<SOG.Mesh, RG.Mesh> meshConverter, | ||
| IConverterSettingsStore<RhinoConversionSettings> settingsStore | ||
| ) : IMeshToHostConversionHelper | ||
| { | ||
| #pragma warning disable CA1508 // Brep.CreateFromMesh can return null for degenerate meshes | ||
| public RG.GeometryBase ConvertMesh(SOG.Mesh mesh) | ||
| { | ||
| var rhinoMesh = meshConverter.Convert(mesh); | ||
|
|
||
| if (settingsStore.Current.ConvertMeshesToBreps && mesh["fromSolid"] is true) | ||
| { | ||
| var brep = RG.Brep.CreateFromMesh(rhinoMesh, true); | ||
| if (brep is not null) | ||
| { | ||
| brep.MergeCoplanarFaces( | ||
| settingsStore.Current.Document.ModelAbsoluteTolerance, | ||
| settingsStore.Current.Document.ModelAngleToleranceRadians | ||
| ); | ||
| return brep; | ||
| } | ||
| } | ||
|
|
||
| return rhinoMesh; | ||
| } | ||
| #pragma warning restore CA1508 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| using Speckle.Converters.Common; | ||
| using Speckle.Converters.Common.Objects; | ||
| using Speckle.Converters.Common.ToHost; | ||
| using Speckle.Converters.Rhino.ToHost.Helpers; | ||
| using Speckle.Objects.Data; | ||
| using Speckle.Sdk.Common; | ||
| using Speckle.Sdk.Common.Exceptions; | ||
|
|
@@ -21,7 +22,7 @@ public class DataObjectConverter | |
| private readonly ITypedConverter<SOG.Ellipse, RG.NurbsCurve> _ellipseConverter; | ||
| private readonly ITypedConverter<SOG.ExtrusionX, List<RG.GeometryBase>> _extrusionConverter; | ||
| private readonly ITypedConverter<SOG.Line, RG.LineCurve> _lineConverter; | ||
| private readonly ITypedConverter<SOG.Mesh, RG.Mesh> _meshConverter; | ||
| private readonly IMeshToHostConversionHelper _meshConversionHelper; | ||
| private readonly ITypedConverter<SOG.Pointcloud, RG.PointCloud> _pointcloudConverter; | ||
| private readonly ITypedConverter<SOG.Point, RG.Point> _pointConverter; | ||
| private readonly ITypedConverter<SOG.Polycurve, RG.PolyCurve> _polycurveConverter; | ||
|
|
@@ -39,7 +40,7 @@ public DataObjectConverter( | |
| ITypedConverter<SOG.Ellipse, RG.NurbsCurve> ellipseConverter, | ||
| ITypedConverter<SOG.ExtrusionX, List<RG.GeometryBase>> extrusionConverter, | ||
| ITypedConverter<SOG.Line, RG.LineCurve> lineConverter, | ||
| ITypedConverter<SOG.Mesh, RG.Mesh> meshConverter, | ||
| IMeshToHostConversionHelper meshConversionHelper, | ||
| ITypedConverter<SOG.Pointcloud, RG.PointCloud> pointcloudConverter, | ||
| ITypedConverter<SOG.Point, RG.Point> pointConverter, | ||
| ITypedConverter<SOG.Polyline, RG.PolylineCurve> polylineConverter, | ||
|
|
@@ -57,7 +58,7 @@ IDataObjectInstanceRegistry dataObjectInstanceRegistry | |
| _ellipseConverter = ellipseConverter; | ||
| _extrusionConverter = extrusionConverter; | ||
| _lineConverter = lineConverter; | ||
| _meshConverter = meshConverter; | ||
| _meshConversionHelper = meshConversionHelper; | ||
| _pointcloudConverter = pointcloudConverter; | ||
| _pointConverter = pointConverter; | ||
| _polycurveConverter = polycurveConverter; | ||
|
|
@@ -107,7 +108,7 @@ IDataObjectInstanceRegistry dataObjectInstanceRegistry | |
| SOG.Ellipse ellipse => new() { _ellipseConverter.Convert(ellipse) }, | ||
| SOG.ExtrusionX extrusion => _extrusionConverter.Convert(extrusion), | ||
| SOG.Line line => new() { _lineConverter.Convert(line) }, | ||
| SOG.Mesh mesh => new() { _meshConverter.Convert(mesh) }, | ||
| SOG.Mesh mesh => new() { _meshConversionHelper.ConvertMesh(mesh) }, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't believe we need another wrapper/helper class for this operation. Just use utility in the converter class. |
||
| SOG.Pointcloud pointcloud => new() { _pointcloudConverter.Convert(pointcloud) }, | ||
| SOG.Point point => new() { _pointConverter.Convert(point) }, | ||
| SOG.Polycurve polycurve => new() { _polycurveConverter.Convert(polycurve) }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
convertMeshesToPolysurfaces