public IEnumerable <Pos3Norm3VertexSDX> GetVertices(D2DGeometry geometry, float height = 1f) { List <Pos3Norm3VertexSDX> vertices = new List <Pos3Norm3VertexSDX>(); //Empty mesh if (geometry == null) { Pos3Norm3VertexSDX zero = new Pos3Norm3VertexSDX(); vertices.Add(zero); vertices.Add(zero); vertices.Add(zero); return(vertices); } if (height > 0) { D2DGeometry flattenedGeometry = this.FlattenGeometry(geometry, sc_flatteningTolerance); D2DGeometry outlinedGeometry = this.OutlineGeometry(flattenedGeometry); //Add snap here var sink = new ExtrudingSink(vertices, height); outlinedGeometry.Simplify(GeometrySimplificationOption.Lines, sink); var bounds = flattenedGeometry.GetBounds(); var scaling = Math.Min(1 / Math.Abs(bounds.Bottom - bounds.Top), 1); outlinedGeometry.Tessellate(sink); outlinedGeometry.Dispose(); flattenedGeometry.Dispose(); sink.Dispose(); return(vertices.Select(v => v.Scale(scaling).AssignTexCd()).Reverse()); } else { D2DGeometry flattenedGeometry = this.FlattenGeometry(geometry, sc_flatteningTolerance); //Add snap here var sink = new FlatSink(vertices); var bounds = flattenedGeometry.GetBounds(); var scaling = Math.Min(1 / Math.Abs(bounds.Bottom - bounds.Top), 1); flattenedGeometry.Tessellate(sink); flattenedGeometry.Dispose(); sink.Dispose(); return(vertices.Select(v => v.Scale(scaling).AssignTexCd()).Reverse()); } }
private D2DGeometry FlattenGeometry(D2DGeometry geometry, float tolerance) { PathGeometry path = new PathGeometry(this.factory); using (GeometrySink sink = path.Open()) { geometry.Simplify(GeometrySimplificationOption.Lines, tolerance, sink); sink.Close(); } return(path); }
private D2DGeometry FlattenGeometry(D2DGeometry geometry, float tolerance) { PathGeometry path = new PathGeometry(this.factory); GeometrySink sink = path.Open(); geometry.Simplify(GeometrySimplificationOption.Lines, tolerance, sink); sink.Close(); return path; }
public Shape CreateSimplification(DxGeometry resolvedSource, float tolerance) { Contract.Requires(resolvedSource != null); Contract.Requires(Check.IsPositive(tolerance)); Contract.Ensures(Contract.Result<Shape>() != null); _Builder = Shape.Create(); resolvedSource.Simplify(GeometrySimplificationOption.Lines, tolerance, this); Shape result = _Builder.Build(); _Builder = null; return result; }
public void GetVertices(D2DGeometry geometry, List <Pos3Norm3VertexSDX> vertices, float height = 24.0f) { vertices.Clear(); //Empty mesh if (geometry == null) { Pos3Norm3VertexSDX zero = new Pos3Norm3VertexSDX(); vertices.Add(zero); vertices.Add(zero); vertices.Add(zero); } using (D2DGeometry flattenedGeometry = this.FlattenGeometry(geometry, sc_flatteningTolerance)) { using (D2DGeometry outlinedGeometry = this.OutlineGeometry(flattenedGeometry)) { using (ExtrudingSink sink = new ExtrudingSink(vertices, height)) { outlinedGeometry.Simplify(GeometrySimplificationOption.Lines, sink); outlinedGeometry.Tessellate(sink); } } } }