Skip to content

Commit

Permalink
Merge pull request #1065 from hypar-io/allow-setting-snap-points-on-r…
Browse files Browse the repository at this point in the history
…epresentation

Added methods to set and get snap points (#1065)
  • Loading branch information
anthonie-kramer authored Nov 29, 2023
2 parents b905514 + 6b6cd3f commit 8f7ee25
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Elements/src/BIM/Door/Door.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ private RepresentationInstance CreateDoorCurveRepresentation()
var points = CollectPointsForSchematicVisualization();
var curve = new IndexedPolycurve(points);
var curveRep = new CurveRepresentation(curve, false);
curveRep.SetSnappingPoints(new List<SnappingPoints>());
var repInstance = new RepresentationInstance(curveRep, BuiltInMaterials.Black);

return repInstance;
Expand Down Expand Up @@ -251,6 +252,7 @@ private RepresentationInstance CreateDoorFrameRepresentation()
var doorFrameExtrude = new Extrude(new Profile(doorFramePolygon), this.FrameDepth, Vector3.YAxis);

var solidRep = new SolidRepresentation(doorFrameExtrude);
solidRep.SetSnappingPoints(new List<SnappingPoints>());
var repInstance = new RepresentationInstance(solidRep, FrameMaterial, true);
return repInstance;
}
Expand Down Expand Up @@ -286,6 +288,7 @@ private RepresentationInstance CreateDoorSolidRepresentation()
}

var solidRep = new SolidRepresentation(doorExtrusions);
solidRep.SetSnappingPoints(new List<SnappingPoints>(new SnappingPoints[] { new SnappingPoints(new[] { left, Vector3.Origin, right }, SnappingEdgeMode.LineStrip) }));
var repInstance = new RepresentationInstance(solidRep, this.Material, true);
return repInstance;
}
Expand Down Expand Up @@ -416,6 +419,7 @@ private RepresentationInstance CreateDoorHandleRepresentation()
}

var solidRep = new SolidRepresentation(solidOperationsList);
solidRep.SetSnappingPoints(new List<SnappingPoints>());
var repInst = new RepresentationInstance(solidRep, FrameMaterial);
return repInst;
}
Expand Down
22 changes: 21 additions & 1 deletion Elements/src/CoreModels/ElementRepresentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/// </summary>
public abstract class ElementRepresentation : SharedObject
{
protected List<SnappingPoints> _snapPoints;

/// <summary>
/// Get graphics buffers and other metadata required to modify a GLB.
/// </summary>
Expand All @@ -28,12 +30,30 @@ internal virtual List<NodeExtension> GetNodeExtensions(GeometricElement element)
return new List<NodeExtension>();
}

/// <summary>
/// Set the snapping points for this representation.
/// </summary>
public void SetSnappingPoints(List<SnappingPoints> snapPoints)
{
_snapPoints = snapPoints;
}

/// <summary>
/// Get the snapping points for this representation. Uses CreateSnappingPoints if _snapPoints is null.
/// </summary>
public List<SnappingPoints> GetSnappingPoints(GeometricElement element)
{
if (_snapPoints == null) return CreateSnappingPoints(element);
return _snapPoints;
}


/// <summary>
///Creates the set of snapping points
/// </summary>
/// <param name="element">The element with this representation.</param>
/// <returns></returns>
public virtual List<SnappingPoints> CreateSnappingPoints(GeometricElement element)
protected virtual List<SnappingPoints> CreateSnappingPoints(GeometricElement element)
{
return new List<SnappingPoints>();
}
Expand Down
3 changes: 2 additions & 1 deletion Elements/src/Representations/CurveRepresentation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Elements.Geometry;
using glTFLoader.Schema;

Expand Down Expand Up @@ -47,7 +48,7 @@ public override bool TryToGraphicsBuffers(GeometricElement element, out List<Gra
}

/// <inheritdoc/>
public override List<SnappingPoints> CreateSnappingPoints(GeometricElement element)
protected override List<SnappingPoints> CreateSnappingPoints(GeometricElement element)
{
var snappingPoints = new List<SnappingPoints>();
var curvePoints = _curve.RenderVertices();
Expand Down
4 changes: 2 additions & 2 deletions Elements/src/Representations/SolidRepresentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Elements
{
/// <summary>
///
/// A solid representation of an element.
/// </summary>
public class SolidRepresentation : ElementRepresentation
{
Expand Down Expand Up @@ -193,7 +193,7 @@ public List<List<Vector3>> CalculateIntersectionPoints(GeometricElement element,
}

/// <inheritdoc/>
public override List<SnappingPoints> CreateSnappingPoints(GeometricElement element)
protected override List<SnappingPoints> CreateSnappingPoints(GeometricElement element)
{
var snappingPoints = new List<SnappingPoints>();

Expand Down
5 changes: 3 additions & 2 deletions Elements/src/Serialization/glTF/GltfExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,8 +1341,9 @@ private static void GetRenderDataForElement(Element e,
var meshIdList = new List<int> { meshId };
representationsMap.Add(combinedId, meshIdList);
addedNodes.AddRange(NodeUtilities.AddNodes(nodes, meshIdList, elementNodeId));
var snappingPoints = representation.Representation.CreateSnappingPoints(element);
if (snappingPoints.Any())
var snappingPoints = representation.Representation.GetSnappingPoints(element);

if (snappingPoints != null)
{
AddExtension(gltf, meshes[meshId], "HYPAR_snapping_points", new Dictionary<string, object>() { { "points", snappingPoints } });
}
Expand Down

0 comments on commit 8f7ee25

Please sign in to comment.