Skip to content

Commit

Permalink
Merge master into explicit-ref
Browse files Browse the repository at this point in the history
  • Loading branch information
wynged authored Aug 16, 2022
2 parents 6872d96 + 83c36c5 commit 0ca1148
Show file tree
Hide file tree
Showing 34 changed files with 732 additions and 203 deletions.
19 changes: 12 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
## 1.2.0

### Added

- Message class along with helper creation methods.
- `Polygon(IList<Vector3> @vertices, bool disableValidation = false)`
- `Polygon(bool disableValidation, params Vector3[] vertices)`
- `Polyline(IList<Vector3> @vertices, bool disableValidation = false)`
- `Polyline(bool disableValidation, params Vector3[] vertices)`
- `Mesh.Intersects(Ray)` (same as `Ray.Intersects(Mesh)`)
- `Ray.NearbyPoints()`
- `PointOctree<T>`
- `Message` class along with helper creation methods.

### Changed

- MeshElement constructor signature modified to be compatible with code generation.
- Improved performance of mesh/ray intersection
- `BBox3.Extend` method is public now
- `AdaptiveGrid.Boundary` can be left null.
- `Obstacle` properties `Points`, `Offset`, `Perimeter` and `Transform` can be modified from outside.
Expand All @@ -18,6 +25,7 @@
- Fixed a bug where `Polyline.Frames` would return inconsistently-oriented transforms.
- `Obstacle.FromBox` works properly with `AdaptiveGrid` transformation.
- `AdaptiveGrid.SubtractObstacle` worked incorrectly in `AdaptiveGrid.Boundary` had elevation.
- #805

## 1.1.0

Expand Down Expand Up @@ -76,11 +84,6 @@
- `ContinuousDimension`
- `Vector3.AreCollinearByAngle(Vector3 a, Vector3 b, Vector3 c, double tolerance)`


### Fixed

- #805

### Fixed

- `Line.IsCollinear(Line line)` would return `false` if lines are close to each other but not collinear
Expand All @@ -89,11 +92,13 @@
- `Line.GetUParameter(Vector 3)` - calculate U parameter for point on line
- `Line.MergeCollinearLine(Line line)` creates new line containing all four collinear vertices
- `Line.Projected(Plane plane)` create new line projected onto plane
- `Profile.Split` would sometimes fail if the profile being split contained voids.

### Changed

- Simplified `IEnumerable<Vector3>.ToGraphicsBuffers()`
- `TryToGraphicsBuffers` is now public
- `Solid SweepFaceAlongCurve` now has an additional parameter, `profileRotation`, which enables the caller to pass a profile rotation into sweep creation.

## 1.0.0

Expand Down
74 changes: 74 additions & 0 deletions Elements.Benchmarks/Mesh.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using Elements.Geometry;

namespace Elements.Benchmarks
{
public class MeshRayIntersection
{
private Mesh _mesh;
private List<Ray> _rays;

public MeshRayIntersection()
{
var random = new Random(10);
_mesh = new Mesh();
_rays = new List<Ray>();
var xCount = 100;
var yCount = 300;
MeshConstruction.BuildRandomMesh(_mesh, random, xCount, yCount);

// create 1000 random rays
for (int i = 0; i < 1000; i++)
{
var ray = new Ray(new Vector3(random.NextDouble() * xCount, random.NextDouble() * yCount, 2.1), new Vector3(random.NextDouble() * 2 - 1, random.NextDouble() * 2 - 1, -1));
_rays.Add(ray);
}
}


[Benchmark(Description = "Intersect 1000 rays with mesh.")]
public void IntersectRays()
{
foreach (var ray in _rays)
{
ray.Intersects(_mesh, out var _);
}
}
}
public class MeshConstruction
{
public static void BuildRandomMesh(Mesh m, Random random, int xCount, int yCount)
{
for (int i = 0; i < xCount; i++)
{
for (int j = 0; j < yCount; j++)
{
var point = new Vector3(i, j, random.NextDouble() * 2);
var c = m.AddVertex(point);
if (i != 0 && j != 0)
{
// add faces
var d = m.Vertices[i * yCount + j - 1];
var a = m.Vertices[(i - 1) * yCount + j - 1];
var b = m.Vertices[(i - 1) * yCount + j];
m.AddTriangle(a, b, c);
m.AddTriangle(c, d, a);
}
}
}
}

[Params(1000, 5000, 10000, 30000)]
public int VertexCount { get; set; }

[Benchmark(Description = "Construct Mesh")]
public void ConstructMesh()
{
var mesh = new Mesh();
BuildRandomMesh(mesh, new Random(10), 100, VertexCount / 100);
}

}
}
1 change: 1 addition & 0 deletions Elements.Benchmarks/Trace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void TraceModelCreation()
}

[EventPipeProfiler(EventPipeProfile.CpuSampling)]
[MemoryDiagnoser]
[SimpleJob]
public class TraceGltfSerialization
{
Expand Down
34 changes: 34 additions & 0 deletions Elements/src/EdgeDisplaySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ public class EdgeDisplaySettings
/// How the Width should be interpreted. If set to Screen Units, Width is interpreted as a constant pixel width (and rounded to the nearest integer). If set to World Units, Width is interpreted as a constant meter width.
/// </summary>
public EdgeDisplayWidthMode WidthMode { get; set; } = EdgeDisplayWidthMode.ScreenUnits;

/// <summary>
/// Whether and how to display dashes along the line.
/// </summary>
public EdgeDisplayDashMode DashMode { get; set; } = EdgeDisplayDashMode.None;

/// <summary>
/// The size of the dash. If Mode is set to None, this value will be ignored. Note that the units for this value (screen vs world) are affected by the choice of Dash Mode.
/// </summary>
public double DashSize { get; set; } = 1;

/// <summary>
/// The size of the gaps between dashes. If Mode is set to None, this value will be ignored. If this value is set to null, DashSize will be used. Note that the units for this value (screen vs world) are affected by the choice of Dash Mode.
/// </summary>
public double? GapSize { get; set; } = 1;
}

/// <summary>
Expand All @@ -30,4 +45,23 @@ public enum EdgeDisplayWidthMode
/// </summary>
WorldUnits = 1,
}

/// <summary>
/// Different ways to interpret the Width property of a EdgeDisplaySettings.
/// </summary>
public enum EdgeDisplayDashMode
{
/// <summary>
/// Dashed display is not enabled. Dash size is ignored.
/// </summary>
None = 0,
/// <summary>
/// Dash sizes are specified in pixels, and maintain a constant size when zooming.
/// </summary>
ScreenUnits = 1,
/// <summary>
/// Dash sizes are specified in meters, and maintain a constant size relative to the model.
/// </summary>
WorldUnits = 2,
}
}
3 changes: 2 additions & 1 deletion Elements/src/Geometry/BBox3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public BBox3(IEnumerable<Vector3> points)
/// Extend a bounding box with a new point
/// </summary>
/// <param name="point">The point which should be inside the extended bounding box</param>
public void Extend(Vector3 point)
public BBox3 Extend(Vector3 point)
{
var newMin = new Vector3(Min.X, Min.Y, Min.Z);
if (point.X < this.Min.X) newMin.X = point.X;
Expand All @@ -107,6 +107,7 @@ public void Extend(Vector3 point)
if (point.Y > this.Max.Y) newMax.Y = point.Y;
if (point.Z > this.Max.Z) newMax.Z = point.Z;
this.Max = newMax;
return this;
}

/// <summary>
Expand Down
10 changes: 8 additions & 2 deletions Elements/src/Geometry/Bezier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,19 @@ public override BBox3 Bounds()
/// </summary>
/// <param name="startSetback"></param>
/// <param name="endSetback"></param>
/// <returns></returns>
public override Transform[] Frames(double startSetback = 0, double endSetback = 0)
/// <param name="additionalRotation"></param>
public override Transform[] Frames(double startSetback = 0,
double endSetback = 0,
double additionalRotation = 0.0)
{
var transforms = new Transform[_samples + 1];
for (var i = 0; i <= _samples; i++)
{
transforms[i] = TransformAt(i * 1.0 / _samples);
if (additionalRotation != 0.0)
{
transforms[i].RotateAboutPoint(transforms[i].Origin, transforms[i].ZAxis, additionalRotation);
}
}
return transforms;
}
Expand Down
2 changes: 1 addition & 1 deletion Elements/src/Geometry/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Polygon ToPolygon(int divisions = 10)
{
pts[i] = this.PointAt((double)i / (double)divisions);
}
return new Polygon(pts);
return new Polygon(pts, true);
}
}
}
10 changes: 2 additions & 8 deletions Elements/src/Geometry/CsgExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,19 @@ internal static void Tessellate(this Csg.Solid csg, ref Mesh mesh)
/// appropriate for use with gltf.
/// </summary>
internal static GraphicsBuffers Tessellate(this Csg.Solid csg,
bool mergeVertices = false,
Func<(Vector3, Vector3, UV, Color), (Vector3, Vector3, UV, Color)> modifyVertexAttributes = null)
{
return Tessellate(new[] { csg }, mergeVertices, modifyVertexAttributes);
return Tessellate(new[] { csg }, modifyVertexAttributes);
}

/// <summary>
/// Triangulate a collection of CSGs and pack the triangulated data into
/// buffers appropriate for use with gltf.
/// </summary>
internal static GraphicsBuffers Tessellate(this Csg.Solid[] csgs,
bool mergeVertices = false,
Func<(Vector3, Vector3, UV, Color), (Vector3, Vector3, UV, Color)> modifyVertexAttributes = null)
{
var buffers = new GraphicsBuffers();

Tessellation.Tessellation.Tessellate(csgs.Select(csg => new CsgTessellationTargetProvider(csg)),
buffers,
mergeVertices,
var buffers = Tessellation.Tessellation.Tessellate<GraphicsBuffers>(csgs.Select(csg => new CsgTessellationTargetProvider(csg)),
modifyVertexAttributes);
return buffers;
}
Expand Down
9 changes: 8 additions & 1 deletion Elements/src/Geometry/Curve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@ public abstract partial class Curve : ICurve, ITransformable<Curve>
/// </summary>
/// <param name="startSetback">The offset parameter from the start of the curve.</param>
/// <param name="endSetback">The offset parameter from the end of the curve.</param>
/// <param name="additionalRotation">An additional rotation of the frame at each point.</param>
/// <returns>A collection of transforms.</returns>
public virtual Transform[] Frames(double startSetback = 0.0, double endSetback = 0.0)
public virtual Transform[] Frames(double startSetback = 0.0,
double endSetback = 0.0,
double additionalRotation = 0.0)
{
var parameters = GetSampleParameters(startSetback, endSetback);
var transforms = new Transform[parameters.Length];
for (var i = 0; i < parameters.Length; i++)
{
transforms[i] = TransformAt(parameters[i]);
if (additionalRotation != 0.0)
{
transforms[i].RotateAboutPoint(transforms[i].Origin, transforms[i].ZAxis, additionalRotation);
}
}
return transforms;
}
Expand Down
Loading

0 comments on commit 0ca1148

Please sign in to comment.