public Model(string path) { Parts = new List <ModelPart>(); FilePath = path; using (var stream = new FileStream(path, FileMode.Open)) { CheckHeader(stream); Type = BitConverter.ToInt32(stream.ReadBytes(4)); Template = new ModelTemplate(stream); stream.ReadBytes(10); MountPoints = new MountPoints(stream); Lights = new Lights(stream); stream.ReadBytes(64); stream.ReadBytes(488); UnknownVal1 = BitConverter.ToInt16(stream.ReadBytes(2)); UnknownVal2 = BitConverter.ToInt16(stream.ReadBytes(2)); UnknownVal3 = BitConverter.ToInt16(stream.ReadBytes(2)); UnknownVal4 = BitConverter.ToInt16(stream.ReadBytes(2)); UnknownVal5 = BitConverter.ToInt16(stream.ReadBytes(4)); if (Type != 0) { throw new NotSupportedException("Not supported mesh format"); } Parts = GetParts(stream).ToList(); PartsTree = GetPartsTree(Parts); } }
public PartNode(int id, ModelPart part = null, PartNode parent = null) { Children = new List <PartNode>(); Id = id; Part = part; Parent = parent; if (parent != null) { parent.Children.Add(this); } }
private PartNode GetPartsTree(IEnumerable <ModelPart> parts) { var currentId = 0; var root = new PartNode(currentId, parts.First()); var lastNode = root; foreach (var part in parts.Skip(1)) { var skip = part.SkipParent; var parent = lastNode; for (var i = 0; i < skip; i++) { parent = parent.Parent; } lastNode = new PartNode(++currentId, part, parent); } return(root); }