Skip to content

Commit

Permalink
Added a shape map to I3D class for quick lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Donkie committed Dec 18, 2021
1 parent 34764c2 commit b2c06fb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 38 additions & 1 deletion I3DShapesTool.Lib/Model/I3D/I3D.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace I3DShapesTool.Lib.Model.I3D
{
Expand All @@ -7,5 +8,41 @@ public class I3D
public string? Name { get; set; }
public string? Version { get; set; }
public TransformGroup SceneRoot { get; } = new TransformGroup("root", 0, I3DVector.Zero, I3DVector.Zero, I3DVector.One);

private IDictionary<int, Shape>? _shapesMap;

private void MapShapesRecurse(TransformGroup parent)
{
if (_shapesMap == null)
throw new InvalidOperationException();

if (parent is Shape shape && shape.ShapeId != null)
{
_shapesMap.Add((int)shape.ShapeId, shape);
}

foreach (var child in parent.Children)
{
MapShapesRecurse(child);
}
}

private void MapShapes()
{
_shapesMap = new Dictionary<int, Shape>();
MapShapesRecurse(SceneRoot);
}

public void Setup()
{
MapShapes();
}

public Shape? GetShape(int id)
{
if (_shapesMap == null || !_shapesMap.ContainsKey(id))
return null;
return _shapesMap[id];
}
}
}
2 changes: 2 additions & 0 deletions I3DShapesTool.Lib/Model/I3D/I3DXMLReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public static I3D ParseXML(string filePath)
}
}

result.Setup();

return result;
}
}
Expand Down

0 comments on commit b2c06fb

Please sign in to comment.