-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
166 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...s/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/RegionToSpeckleConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Speckle.Converters.Common; | ||
using Speckle.Converters.Common.Objects; | ||
using Speckle.Sdk.Common.Exceptions; | ||
using Speckle.Sdk.Models; | ||
|
||
namespace Speckle.Converters.Autocad.Geometry; | ||
|
||
[NameAndRankValue(nameof(ADB.Region), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] | ||
public class RegionToSpeckleConverter : IToSpeckleTopLevelConverter, ITypedConverter<ADB.Region, SOG.Mesh> | ||
{ | ||
private readonly ITypedConverter<ABR.Brep, SOG.Mesh> _brepConverter; | ||
|
||
public RegionToSpeckleConverter(ITypedConverter<ABR.Brep, SOG.Mesh> brepConverter) | ||
{ | ||
_brepConverter = brepConverter; | ||
} | ||
|
||
public Base Convert(object target) => Convert((ADB.Region)target); | ||
|
||
public SOG.Mesh Convert(ADB.Region target) | ||
{ | ||
using ABR.Brep brep = new(target); | ||
if (brep.IsNull) | ||
{ | ||
throw new ConversionException("Could not retrieve brep from the region."); | ||
} | ||
|
||
SOG.Mesh mesh = _brepConverter.Convert(brep); | ||
mesh.area = target.Area; | ||
|
||
return mesh; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
.../Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/SurfaceToSpeckleConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Speckle.Converters.Common; | ||
using Speckle.Converters.Common.Objects; | ||
using Speckle.Sdk.Common.Exceptions; | ||
using Speckle.Sdk.Models; | ||
|
||
namespace Speckle.Converters.Autocad.Geometry; | ||
|
||
[NameAndRankValue(nameof(ADB.Surface), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] | ||
public class SurfaceToSpeckleConverter : IToSpeckleTopLevelConverter, ITypedConverter<ADB.Surface, SOG.Mesh> | ||
{ | ||
private readonly ITypedConverter<ABR.Brep, SOG.Mesh> _brepConverter; | ||
|
||
public SurfaceToSpeckleConverter(ITypedConverter<ABR.Brep, SOG.Mesh> brepConverter) | ||
{ | ||
_brepConverter = brepConverter; | ||
} | ||
|
||
public Base Convert(object target) => Convert((ADB.Surface)target); | ||
|
||
public SOG.Mesh Convert(ADB.Surface target) | ||
{ | ||
using ABR.Brep brep = new(target); | ||
if (brep.IsNull) | ||
{ | ||
throw new ConversionException("Could not retrieve brep from the plane surface."); | ||
} | ||
|
||
return _brepConverter.Convert(brep); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...rters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/BrepToSpeckleRawConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using Speckle.Converters.Common; | ||
using Speckle.Converters.Common.Objects; | ||
using Speckle.Sdk; | ||
using Speckle.Sdk.Common.Exceptions; | ||
|
||
namespace Speckle.Converters.Autocad.ToSpeckle.Raw; | ||
|
||
public class BrepToSpeckleRawConverter : ITypedConverter<ABR.Brep, SOG.Mesh> | ||
{ | ||
private readonly IConverterSettingsStore<AutocadConversionSettings> _settingsStore; | ||
|
||
public BrepToSpeckleRawConverter(IConverterSettingsStore<AutocadConversionSettings> settingsStore) | ||
{ | ||
_settingsStore = settingsStore; | ||
} | ||
|
||
public SOG.Mesh Convert(ABR.Brep target) | ||
{ | ||
if (target.IsNull) | ||
{ | ||
throw new ConversionException("Brep was null."); | ||
} | ||
|
||
List<int> faces = new(); | ||
List<double> vertices = new(); | ||
int vertexCount = 0; | ||
|
||
using (var control = new ABR.Mesh2dControl()) | ||
{ | ||
// These settings may need adjusting | ||
control.MaxSubdivisions = 10000; | ||
|
||
// create mesh filters | ||
using (var filter = new ABR.Mesh2dFilter()) | ||
{ | ||
filter.Insert(target, control); | ||
using (ABR.Mesh2d m = new(filter)) | ||
{ | ||
foreach (ABR.Element2d? e in m.Element2ds) | ||
{ | ||
// add number of vertices for this face | ||
int nodeCount = e.Nodes.Count(); | ||
faces.Add(nodeCount); | ||
|
||
foreach (var n in e.Nodes) | ||
{ | ||
// add index of current vertex to face | ||
faces.Add(vertexCount); | ||
vertexCount++; | ||
|
||
// add vertex coords | ||
vertices.Add(n.Point.X); | ||
vertices.Add(n.Point.Y); | ||
vertices.Add(n.Point.Z); | ||
n.Dispose(); | ||
} | ||
|
||
e.Dispose(); | ||
} | ||
} | ||
} | ||
|
||
// create speckle mesh | ||
SOG.Mesh mesh = | ||
new() | ||
{ | ||
faces = faces, | ||
vertices = vertices, | ||
units = _settingsStore.Current.SpeckleUnits, | ||
area = target.GetSurfaceArea() | ||
}; | ||
|
||
try | ||
{ | ||
mesh.volume = target.GetVolume(); | ||
} | ||
catch (ABR.Exception e) when (!e.IsFatal()) { } // exceptions can be thrown for non-volumetric breps | ||
|
||
return mesh; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters