private void ExportCommonMeshData(FArchiveWriter Ar, CMeshSection[] sections, CMeshVertex[] verts, FRawStaticIndexBuffer indices, CVertexShare share, List <MaterialExporter>?materialExports, ETexturePlatform platform = ETexturePlatform.DesktopMobile) { var mainHdr = new VChunkHeader(); var ptsHdr = new VChunkHeader(); var wedgHdr = new VChunkHeader(); var facesHdr = new VChunkHeader(); var matrHdr = new VChunkHeader(); var normHdr = new VChunkHeader(); mainHdr.TypeFlag = Constants.PSK_VERSION; Ar.SerializeChunkHeader(mainHdr, "ACTRHEAD"); var numPoints = share.Points.Count; ptsHdr.DataCount = numPoints; ptsHdr.DataSize = 12; Ar.SerializeChunkHeader(ptsHdr, "PNTS0000"); for (var i = 0; i < numPoints; i++) { var point = share.Points[i]; point.Y = -point.Y; // MIRROR_MESH point.Serialize(Ar); } var numFaces = 0; var numVerts = verts.Length; var numSections = sections.Length; var wedgeMat = new int[numVerts]; for (var i = 0; i < numSections; i++) { var faces = sections[i].NumFaces; numFaces += faces; for (var j = 0; j < faces * 3; j++) { wedgeMat[indices[j + sections[i].FirstIndex]] = i; } } wedgHdr.DataCount = numVerts; wedgHdr.DataSize = 16; Ar.SerializeChunkHeader(wedgHdr, "VTXW0000"); for (var i = 0; i < numVerts; i++) { Ar.Write(share.WedgeToVert[i]); Ar.Write(verts[i].UV.U); Ar.Write(verts[i].UV.V); Ar.Write((byte)wedgeMat[i]); Ar.Write((byte)0); Ar.Write((short)0); } facesHdr.DataCount = numFaces; if (numVerts <= 65536) { facesHdr.DataSize = 12; Ar.SerializeChunkHeader(facesHdr, "FACE0000"); for (var i = 0; i < numSections; i++) { for (var j = 0; j < sections[i].NumFaces; j++) { var wedgeIndex = new ushort[3]; for (var k = 0; k < wedgeIndex.Length; k++) { wedgeIndex[k] = (ushort)indices[sections[i].FirstIndex + j * 3 + k]; } Ar.Write(wedgeIndex[1]); // MIRROR_MESH Ar.Write(wedgeIndex[0]); // MIRROR_MESH Ar.Write(wedgeIndex[2]); Ar.Write((byte)i); Ar.Write((byte)0); Ar.Write((uint)1); } } } else { facesHdr.DataSize = 18; Ar.SerializeChunkHeader(facesHdr, "FACE3200"); for (var i = 0; i < numSections; i++) { for (var j = 0; j < sections[i].NumFaces; j++) { var wedgeIndex = new int[3]; for (var k = 0; k < wedgeIndex.Length; k++) { wedgeIndex[k] = indices[sections[i].FirstIndex + j * 3 + k]; } Ar.Write(wedgeIndex[1]); // MIRROR_MESH Ar.Write(wedgeIndex[0]); // MIRROR_MESH Ar.Write(wedgeIndex[2]); Ar.Write((byte)i); Ar.Write((byte)0); Ar.Write((uint)1); } } } matrHdr.DataCount = numSections; matrHdr.DataSize = 88; Ar.SerializeChunkHeader(matrHdr, "MATT0000"); for (var i = 0; i < numSections; i++) { string materialName; if (sections[i].Material?.Load <UMaterialInterface>() is { } tex) { materialName = tex.Name; materialExports?.Add(new MaterialExporter(tex, true, platform)); }
private void ExportCommonMeshData(FCustomArchiveWriter writer, CMeshSection[] sections, CMeshVertex[] verts, FRawStaticIndexBuffer indices, CVertexShare share, List <MaterialExporter>?materialExports) { var mainHdr = new VChunkHeader(); var ptsHdr = new VChunkHeader(); var wedgHdr = new VChunkHeader(); var facesHdr = new VChunkHeader(); var matrHdr = new VChunkHeader(); mainHdr.TypeFlag = _PSK_VERSION; writer.SerializeChunkHeader(mainHdr, "ACTRHEAD"); var numPoints = share.Points.Count; ptsHdr.DataCount = numPoints; ptsHdr.DataSize = 12; writer.SerializeChunkHeader(ptsHdr, "PNTS0000"); for (var i = 0; i < numPoints; i++) { var point = share.Points[i]; point.Y = -point.Y; // MIRROR_MESH point.Serialize(writer); } var numFaces = 0; var numVerts = verts.Length; var numSections = sections.Length; var wedgeMat = new int[numVerts]; for (var i = 0; i < numSections; i++) { var faces = sections[i].NumFaces; numFaces += faces; for (var j = 0; j < faces * 3; j++) { wedgeMat[indices[j + sections[i].FirstIndex]] = i; } } wedgHdr.DataCount = numVerts; wedgHdr.DataSize = 16; writer.SerializeChunkHeader(wedgHdr, "VTXW0000"); for (var i = 0; i < numVerts; i++) { writer.Write(share.WedgeToVert[i]); writer.Write((int)verts[i].UV.U); // the 4 bit int value is the actual needed float value writer.Write((int)verts[i].UV.V); // the 4 bit int value is the actual needed float value writer.Write((byte)wedgeMat[i]); writer.Write((byte)0); writer.Write((short)0); } facesHdr.DataCount = numFaces; if (numVerts <= 65536) { facesHdr.DataSize = 12; writer.SerializeChunkHeader(facesHdr, "FACE0000"); for (var i = 0; i < numSections; i++) { for (var j = 0; j < sections[i].NumFaces; j++) { var wedgeIndex = new ushort[3]; for (var k = 0; k < wedgeIndex.Length; k++) { wedgeIndex[k] = (ushort)indices[sections[i].FirstIndex + j * 3 + k]; } writer.Write(wedgeIndex[1]); // MIRROR_MESH writer.Write(wedgeIndex[0]); // MIRROR_MESH writer.Write(wedgeIndex[2]); writer.Write((byte)i); writer.Write((byte)0); writer.Write((uint)1); } } } else { facesHdr.DataSize = 18; writer.SerializeChunkHeader(facesHdr, "FACE3200"); for (var i = 0; i < numSections; i++) { for (var j = 0; j < sections[i].NumFaces; j++) { var wedgeIndex = new int[3]; for (var k = 0; k < wedgeIndex.Length; k++) { wedgeIndex[k] = indices[sections[i].FirstIndex + j * 3 + k]; } writer.Write(wedgeIndex[1]); // MIRROR_MESH writer.Write(wedgeIndex[0]); // MIRROR_MESH writer.Write(wedgeIndex[2]); writer.Write((byte)i); writer.Write((byte)0); writer.Write((uint)1); } } } matrHdr.DataCount = numSections; matrHdr.DataSize = 88; writer.SerializeChunkHeader(matrHdr, "MATT0000"); for (var i = 0; i < numSections; i++) { string materialName; if (sections[i].Material?.Value is { } tex) { materialName = tex.Name; materialExports?.Add(new MaterialExporter(tex, true)); }