Skip to content

Commit

Permalink
Merge pull request #850 from hypar-io/dashed-lines
Browse files Browse the repository at this point in the history
Add support for dash settings
  • Loading branch information
andrewheumann authored Aug 16, 2022
2 parents ea464c6 + bd46217 commit 83c36c5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
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,
}
}
2 changes: 2 additions & 0 deletions Elements/src/Serialization/glTF/GltfExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ internal static Dictionary<string, int> AddMaterials(this Gltf gltf,
AddExtension(gltf, gltfMaterial, "HYPAR_materials_edge_settings", new Dictionary<string, object>{
{"lineWidth", material.EdgeDisplaySettings.LineWidth},
{"widthMode", (int)material.EdgeDisplaySettings.WidthMode},
{"dashMode", (int)material.EdgeDisplaySettings.DashMode},
{"dashSize", material.EdgeDisplaySettings.DashSize}
});
}

Expand Down
4 changes: 2 additions & 2 deletions Elements/test/ModelCurveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public void ModelCurveWithLineWeights()
var ctrlPts = new List<Vector3> { a, b, c, d, e, f };
var bezier = new Bezier(ctrlPts);

var lineModelCurve = new ModelCurve(line, new Material("Red", Colors.Red) { EdgeDisplaySettings = new EdgeDisplaySettings { LineWidth = 5 } });
var lineModelCurve = new ModelCurve(line, new Material("Red", Colors.Red) { EdgeDisplaySettings = new EdgeDisplaySettings { LineWidth = 5, DashMode = EdgeDisplayDashMode.WorldUnits, DashSize = 0.1 } });
var arcModelCurve = new ModelCurve(arc, new Material("Orange", Colors.Orange) { EdgeDisplaySettings = new EdgeDisplaySettings { LineWidth = 0.1, WidthMode = EdgeDisplayWidthMode.WorldUnits } }, new Transform(5, 0, 0));
var plineModelCurve = new ModelCurve(pline, new Material("Purple", Colors.Purple) { EdgeDisplaySettings = new EdgeDisplaySettings { LineWidth = 10, WidthMode = EdgeDisplayWidthMode.ScreenUnits } }, new Transform(10, 0, 0));
var plineModelCurve = new ModelCurve(pline, new Material("Purple", Colors.Purple) { EdgeDisplaySettings = new EdgeDisplaySettings { LineWidth = 10, WidthMode = EdgeDisplayWidthMode.ScreenUnits, DashMode = EdgeDisplayDashMode.ScreenUnits, DashSize = 10, GapSize = 4 } }, new Transform(10, 0, 0));
var bezierModelCurve = new ModelCurve(bezier, new Material("Green", Colors.Green) { EdgeDisplaySettings = new EdgeDisplaySettings { LineWidth = 1, WidthMode = EdgeDisplayWidthMode.WorldUnits } }, new Transform(15, 0, 0));
// </example>

Expand Down

0 comments on commit 83c36c5

Please sign in to comment.