public static XmlJunction FromElement(XElement element, Track[] tracks, Dictionary<string, int> counts) { string id = XmlValueMapper.FromAttribute(element, AttrJunctionId).AsIdValue("junction", counts); string branchDefault = XmlValueMapper.FromAttribute(element, AttrJunctionBranchDefault).AsText().MandatoryValue(); string branchAlternate = XmlValueMapper.FromAttribute(element, AttrJunctionBranchAlternate).AsText().MandatoryValue(); Junction.JunctionDirection direction = XmlValueMapper.FromAttribute(element, AttrJunctionDirection).AsEnum<Junction.JunctionDirection>().OptionalValue(Junction.JunctionDirection.OneToMany); return new XmlJunction(id, branchDefault, branchAlternate, direction); }
public SplitTrack MapXmlToDomain(Track track, IList<Split> splits, IList<SplittedRegion> splitRegions) { List<SubTrackNode> trackNodes = _subTrackNodesBuilder.Build(track); List<SubTrackGroupsBuilder.SubTrackBuilder> builders = _subTrackGroupsBuilder.Build(new TrackSplineGenerator(TrackBuilderConfiguration.DefaultConfig), trackNodes, splits, splitRegions); SubTrack[] subTracks = subTracksFromBuilders(builders); return new SplitTrack(track.Id, track.Down, subTracks); }
public XmlGroup(string id, XmlMeshBlock[] blocks, XmlSplit[] splits, Track[] tracks, XmlJunction[] junctions, XmlSplitSide splitAttachment) { Id = id; Blocks = blocks; Splits = splits; Tracks = tracks; Junctions = junctions; SplitAttachment = splitAttachment; }
public List<SubTrackNode> Build(Track track) { List<SubTrackNode> stNodes = new List<SubTrackNode>(); XmlTrackNode[] nodes = track.Nodes; if (nodes.Length < 2) return new List<SubTrackNode>(); SubTrackNode previousStNode = null; Vector3 down = track.Down; Vector3 lastForward = GetStartForward(track); for (int i = 0; i < nodes.Length; i++) { Vector3 forward = i > 0 ? GetDirection(nodes[i - 1].Position, nodes[i].Position) : lastForward; Vector3 nextForward = i < nodes.Length - 1 ? GetDirection(nodes[i].Position, nodes[i + 1].Position) : forward; down = GetNextDownDirection(forward, lastForward, down); lastForward = forward; SubTrackNode stNode = new SubTrackNode(nodes[i].Position, forward, down); stNodes.Add(stNode); UpdateLinks(previousStNode, stNode); previousStNode = stNode; // create a duplicate corner node if required if (Vector3.Angle(forward, nextForward) > 0.1f) { down = GetNextDownDirection(nextForward, lastForward, down); lastForward = nextForward; SubTrackNode cornerNode = new SubTrackNode(nodes[i].Position, nextForward, down); stNodes.Add(cornerNode); UpdateLinks(stNode, cornerNode); previousStNode = cornerNode; } } return stNodes; }
private Vector3 GetStartForward(Track track) { return track.StartDir ?? GetDirection(track.Nodes[0].Position, track.Nodes[1].Position); }