diff --git a/Objects/Converters/ConverterAutocadCivil/ConverterAutocadCivilShared/ConverterAutocadCivil.Civil.cs b/Objects/Converters/ConverterAutocadCivil/ConverterAutocadCivilShared/ConverterAutocadCivil.Civil.cs index b81e00b677..116e3c0a77 100644 --- a/Objects/Converters/ConverterAutocadCivil/ConverterAutocadCivilShared/ConverterAutocadCivil.Civil.cs +++ b/Objects/Converters/ConverterAutocadCivil/ConverterAutocadCivilShared/ConverterAutocadCivil.Civil.cs @@ -736,44 +736,40 @@ private Featureline FeaturelineToSpeckle(CivilDB.CorridorFeatureLine featureline public Mesh SurfaceToSpeckle(TinSurface surface) { // output vars - List vertices = new(); - var faces = new List(); + List vertices = new(); + List faces = new (); + Dictionary indices = new(); + + int indexCounter = 0; foreach (var triangle in surface.GetTriangles(false)) { - var triangleVertices = new List { triangle.Vertex1.Location, triangle.Vertex2.Location, triangle.Vertex3.Location }; - -#if CIVIL2023 || CIVIL2024 // skip any triangles that are hidden in the surface! - if (!triangle.IsVisible) - { - triangle.Dispose(); - continue; - } -#endif - - // store vertices - var faceIndices = new List(); - foreach (var vertex in triangleVertices) + try { - if (!vertices.Contains(vertex)) + Point3d[] triangleVertices = { triangle.Vertex1.Location, triangle.Vertex2.Location, triangle.Vertex3.Location }; + foreach (Point3d p in triangleVertices) { - faceIndices.Add(vertices.Count); - vertices.Add(vertex); - } - else - { - faceIndices.Add(vertices.IndexOf(vertex)); + if (!indices.ContainsKey(p)) + { + var scaledP = ToExternalCoordinates(p); + vertices.Add(scaledP.X); + vertices.Add(scaledP.Y); + vertices.Add(scaledP.Z); + indices.Add(p, indexCounter); + indexCounter++; + } } + faces.Add(3); + faces.Add(indices[triangleVertices[0]]); + faces.Add(indices[triangleVertices[1]]); + faces.Add(indices[triangleVertices[2]]); + } + finally + { + triangle.Dispose(); } - - // get face - faces.AddRange(new List { 3, faceIndices[0], faceIndices[1], faceIndices[2] }); - - triangle.Dispose(); } - - var speckleVertices = vertices.SelectMany(o => PointToSpeckle(o).ToList()).ToList(); - - var mesh = new Mesh(speckleVertices, faces) + + var mesh = new Mesh(vertices, faces) { units = ModelUnits, bbox = BoxToSpeckle(surface.GeometricExtents) @@ -962,7 +958,7 @@ public ApplicationObject TinSurfaceToNative(Mesh mesh, Base props) { continue; } - + var a1 = surface.FindVertexAtXY(edgeStart.X, edgeStart.Y); var a2 = surface.FindVertexAtXY(vertexToAdd.X, vertexToAdd.Y); surface.AddLine(a1, a2); diff --git a/Objects/Converters/ConverterAutocadCivil/ConverterAutocadCivilShared/ConverterAutocadCivil.Geometry.cs b/Objects/Converters/ConverterAutocadCivil/ConverterAutocadCivilShared/ConverterAutocadCivil.Geometry.cs index 134621830f..385a38ec5e 100644 --- a/Objects/Converters/ConverterAutocadCivil/ConverterAutocadCivilShared/ConverterAutocadCivil.Geometry.cs +++ b/Objects/Converters/ConverterAutocadCivil/ConverterAutocadCivilShared/ConverterAutocadCivil.Geometry.cs @@ -57,12 +57,9 @@ public Point PointToSpeckle(Point2d point, string units = null) public Point3d PointToNative(Point point) { - var _point = new Point3d( - ScaleToNative(point.x, point.units), - ScaleToNative(point.y, point.units), - ScaleToNative(point.z, point.units) - ); - var intPt = ToInternalCoordinates(_point); + var scaleFactor = Units.GetConversionFactor(point.units, ModelUnits); + var scaledPoint = new Point3d(point.x * scaleFactor, point.y * scaleFactor, point.z * scaleFactor); + var intPt = ToInternalCoordinates(scaledPoint); return intPt; }