public static G3D ReadG3d(this Stream stream, Func <string, string> renameFunc = null) { var header = G3dHeader.Default; GeometryAttribute ReadAttribute(Stream s2, string name, long size) { var rename = renameFunc?.Invoke(name) ?? name; // Check for the G3dHeader if (rename == "meta") { if (size == 8) { var buffer = s2.ReadArray <byte>((int)size); if (buffer[0] == G3dHeader.MagicA && buffer[1] == G3dHeader.MagicB) { header = G3dHeader.FromBytes(buffer); } } else { s2.ReadArray <byte>((int)size); } return(null); } else { // Figure out the correct type and then read it in var desc = AttributeDescriptor.Parse(rename); var dflt = desc.ToDefaultAttribute(0); return(dflt.Read(stream, size)); } } var results = stream.ReadBFast(ReadAttribute).Select(r => r.Item2); return(new G3D(results.Where(x => x != null), header)); }
public static G3D Create(G3dHeader header, params GeometryAttribute[] attributes) => new G3D(attributes, header);