Skip to content

Commit

Permalink
Merge pull request #848 from hypar-io/make-mesh-code-gen-compatible
Browse files Browse the repository at this point in the history
Make mesh code gen compatible
  • Loading branch information
wynged authored Aug 4, 2022
2 parents 5e3050c + 658cfe6 commit ec68bc0
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 17 deletions.
15 changes: 7 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.2.0

### Changed
- MeshElement constructor signature modified to be compatible with code generation.

## 1.1.0

### Added
Expand All @@ -18,7 +23,7 @@
- `Polyline.Intersects(Line line, out List<Vector3> intersections, bool infinite = false, bool includeEnds = false)` method
- `Polyline.GetParameterAt(Vector3 point)` method
- `Polyline.GetSubsegment(Vector3 start, Vector3 end)` method
- `Polygon.GetSharedSegments(Polyline polyline)` method
- `Polygon.GetSharedSegments(Polyline polyline)` method
- `BBox3.Offset(double amount)`
- `Obstacle` in `Elements.Spatial.AdaptiveGrid`
- `IAddVertexStrategy` with `Connect` and `ConnectWithAngle` implementations in `Elements.Spatial.AdaptiveGrid`
Expand All @@ -37,17 +42,11 @@
- `Elements.Geometry.Solids.Edge` public constructor
- `Elements.Geometry.Solids.Vertex` public constructor
- `Line.PointOnLine` now uses distance to line instead of dot product.
- `Line.Intersects` for `BBox3` now has `double tolerance` parameter.
- `AdaptiveGraphRouting.BuildSpanningTree` functions now have `TreeOrder` parameter: `ClosestToFurthest` or `FurthestToClosest`.
- `AdaptiveGrid.SubtractBox(BBox3 box)` is changed into `AdaptiveGrid.SubtractObstacle(Obstacle obstacle)`
- `AdaptiveGrid.AddVertex(Vector3 point, IList<Vertex> connections)` is removed and replaced with IAddVertexStrategy approach.
- `AdaptiveGrid.AddVertexStrip(IList<Vector3> points)` is changed into `AdaptiveGrid.AddVertices(IList<Vector3> points, VerticesInsertionMethod method)`
- `AdaptiveGrid.AddEdge(ulong vertexId1, ulong vertexId2, bool cut = true)` - added cut parameter.

### Fixed

- `Profile.Split` would sometimes fail if the profile being split contained voids.
- `Line.Intersects(BBox3 box, out List<Vector> results, bool infinite = false)` fix incomplete results when line misaligned with bounding box
- `Line.Intersects(BBox3 box, out List<Vector> results, bool infinite = false)` fix incomplete results when line misaligned with bounding box
- Fixed a mathematical error in `MercatorProjection.MetersToLatLon`, which was returning longitude values that were skewed.
- `Grid2d.IsTrimmed` would occasionally return `true` for cells that were not actually trimmed.
- `Vector3[].AreCoplanar()` computed its tolerance for deviation incorrectly, this is fixed.
Expand Down
3 changes: 2 additions & 1 deletion Elements/src/ImportMeshElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public ImportMeshElement(string path,
Material material = null,
Guid id = default(Guid),
string name = null) : base(null,
material == null ? BuiltInMaterials.Default : material,
new Transform(),
material == null ? BuiltInMaterials.Default : material,
null,
true,
id == default(Guid) ? Guid.NewGuid() : id,
name)
Expand Down
15 changes: 13 additions & 2 deletions Elements/src/MeshElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ public Mesh Mesh
/// Construct an import mesh element.
/// </summary>
/// <param name="mesh">The element's mesh.</param>
/// <param name="material">The element's material.</param>
/// <param name="transform">The element's transform.</param>
/// <param name="material">The element's material.</param>
/// <param name="representation">The element's representation.</param>
/// <param name="isElementDefinition">Is this element a definition?</param>
/// <param name="id">The element's id.</param>
/// <param name="name">The element's name.</param>
[JsonConstructor]
public MeshElement(Mesh mesh,
Material material = null,
Transform transform = null,
Material material = null,
Representation representation = null,
bool isElementDefinition = false,
Guid id = default(Guid),
string name = null) : base(transform == null ? new Transform() : transform,
Expand All @@ -52,6 +54,15 @@ public MeshElement(Mesh mesh,
this._mesh = mesh;
}

/// <summary>
/// Empty constructor for compatibility purposes. It is best to use the
/// structured constructor with arguments, to ensure the mesh is correctly created.
/// </summary>
public MeshElement() : base()
{
_mesh = new Mesh();
}

internal MeshElement(Material material = null,
Transform transform = null,
bool isElementDefinition = false,
Expand Down
2 changes: 1 addition & 1 deletion Elements/test/BBox3Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private MeshElement ConstructExampleMesh()
}
}
mesh.ComputeNormals();
var meshElement = new MeshElement(mesh, new Material("Lime", Colors.Lime), new Transform(new Vector3(-7, -8, 0), new Vector3(-5, 3, 2)));
var meshElement = new MeshElement(mesh, new Transform(new Vector3(-7, -8, 0), new Vector3(-5, 3, 2)), new Material("Lime", Colors.Lime));
return meshElement;
}

Expand Down
2 changes: 1 addition & 1 deletion Elements/test/MaterialTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void EmissiveTextureTest()

var m = new Material("test", Colors.Orange, emissiveTexture: "./Textures/Checkerboard.png", emissiveFactor: 0.5);
var sphere = Mesh.Sphere(2, 30);
Model.AddElement(new MeshElement(sphere, m));
Model.AddElement(new MeshElement(sphere, material: m));
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Elements/test/MeshElementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void MeshElement()
}
}
mesh.ComputeNormals();
var meshElement = new MeshElement(mesh, new Material("Lime", Colors.Lime));
var meshElement = new MeshElement(mesh, material: new Material("Lime", Colors.Lime));
//</example>
this.Model.AddElement(meshElement);
}
Expand Down
2 changes: 1 addition & 1 deletion Elements/test/MeshPrimitivesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void Sphere()
var s = Mesh.Sphere(3, 20);
Assert.Equal(401, s.Vertices.Count);
Assert.Equal(760, s.Triangles.Count);
Model.AddElement(new MeshElement(s, m));
Model.AddElement(new MeshElement(s, material: m));
}
}
}
4 changes: 2 additions & 2 deletions Elements/test/TopographyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public void Csg()
csg.Tessellate(ref result);

var material = new Material($"Topo", Colors.White, 0.0f, 0.0f, "./Topography/Texture_12454f24-690a-43e2-826d-e4deae5eb82e_2.jpg");
this.Model.AddElement(new MeshElement(result, material));
this.Model.AddElement(new MeshElement(result, material: material));
}

[Fact]
Expand Down Expand Up @@ -344,7 +344,7 @@ public void Fill()

foreach (var mesh in fillVolumes)
{
this.Model.AddElement(new MeshElement(mesh, BuiltInMaterials.XAxis));
this.Model.AddElement(new MeshElement(mesh, material: BuiltInMaterials.XAxis));
}
}

Expand Down

0 comments on commit ec68bc0

Please sign in to comment.