/// <summary> /// Write the contents /// </summary> /// <param name="writer">The output stream</param> /// <param name="indexAttribs">How the indices of the loops are structured</param> public void Write(EndianWriter writer, IndexAttributes indexAttribs) { writer.PushBigEndian(true); writer.Write((byte)Type); writer.Write((ushort)Corners.Length); // checking the attributes bool hasFlag(IndexAttributes attrib) => indexAttribs.HasFlag(attrib); // position always exists bool hasCol = hasFlag(IndexAttributes.HasColor); bool hasNrm = hasFlag(IndexAttributes.HasNormal); bool hasUV = hasFlag(IndexAttributes.HasUV); bool shortPos = hasFlag(IndexAttributes.Position16BitIndex); bool shortCol = hasFlag(IndexAttributes.Color16BitIndex); bool shortNrm = hasFlag(IndexAttributes.Normal16BitIndex); bool shortUV = hasFlag(IndexAttributes.UV16BitIndex); foreach (Corner v in Corners) { // Position should always exist if (shortPos) { writer.Write(v.PositionIndex); } else { writer.Write((byte)v.PositionIndex); } if (hasNrm) { if (shortNrm) { writer.Write(v.NormalIndex); } else { writer.Write((byte)v.NormalIndex); } } if (hasCol) { if (shortCol) { writer.Write(v.Color0Index); } else { writer.Write((byte)v.Color0Index); } } if (hasUV) { if (shortUV) { writer.Write(v.UV0Index); } else { writer.Write((byte)v.UV0Index); } } } writer.PopEndian(); }