Skip to content

Commit

Permalink
use the representationinstances cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbradleym committed Dec 31, 2024
1 parent 0620af2 commit 2897b96
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
21 changes: 18 additions & 3 deletions Elements.MEP/src/Fittings/FittingRepresentationStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,32 @@ static class FittingRepresentationStorage
private static readonly Dictionary<string, List<RepresentationInstance>> _fittings = new Dictionary<string, List<RepresentationInstance>>();
public static Dictionary<string, List<RepresentationInstance>> Fittings => _fittings;

public static void SetFittingRepresentation(Fitting fitting, Func<IList<SolidOperation>> makeSolids)
public static void SetFittingRepresentation(Fitting fitting, Func<IList<SolidOperation>> makeSolids, Boolean unioned = true, Boolean updateTransform = true)
{
var hash = fitting.GetRepresentationHash();
if (!_fittings.ContainsKey(hash))
{
var solids = makeSolids();
_fittings.Add(hash, new List<RepresentationInstance> { new RepresentationInstance(new SolidRepresentation(solids), fitting.Material) });
var representationInstances = new List<RepresentationInstance>();
if (unioned)
{
representationInstances = new List<RepresentationInstance> { new RepresentationInstance(new SolidRepresentation(solids), fitting.Material) };
}
else
{
foreach (var solid in solids)
{
representationInstances.Add(new RepresentationInstance(new SolidRepresentation(solid), fitting.Material));
}
}
_fittings.Add(hash, representationInstances);
}
fitting.RepresentationInstances = _fittings[hash];

fitting.Transform = fitting.GetRotatedTransform().Concatenated(new Transform(fitting.Transform.Origin));
if (updateTransform)
{
fitting.Transform = fitting.GetRotatedTransform().Concatenated(new Transform(fitting.Transform.Origin));
}
}
}
}
11 changes: 5 additions & 6 deletions Elements.MEP/src/Fittings/Reducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@ public override void UpdateRepresentations()
var arrows = this.Start.GetArrow(branchSideTransformInverted.OfPoint(startNodeTransform.Origin))
.Concat(this.End.GetArrow(endNodeTransform.Origin)).Concat(GetExtensions());

this.RepresentationInstances.Add(new RepresentationInstance(new SolidRepresentation(sweep1), this.Material));
this.RepresentationInstances.Add(new RepresentationInstance(new SolidRepresentation(sweep2), this.Material));
foreach (var arrow in arrows)
{
this.RepresentationInstances.Add(new RepresentationInstance(new SolidRepresentation(arrow), this.Material));
}
// TODO: Update the Factory pattern for setting representationInstances to work with Reducer transforms.
// It would also be ideal to fully understand the geometry artifacts seen with certain Reducers that result in
// bad boolean graphics which result in invisible or fractured geometry.
var solidOperations = new List<SolidOperation> { sweep1, sweep2 }.Concat(arrows).ToList();
FittingRepresentationStorage.SetFittingRepresentation(this, () => solidOperations, false, false);
}

public override void ApplyAdditionalTransform()
Expand Down

0 comments on commit 2897b96

Please sign in to comment.