Datasmith Asset
FBufferArchive
Archive for storing arbitrary data to the specified memory location.
UdsMesh
Datasmith Mesh
资源文件的写入。
/**
* @param MeshName The path and name of the udsmesh file to save
* @param RawMesh The FRawMesh object to save
*/
void FUdsAsset::SaveToUdsMeshFile(FString & MeshName, FRawMesh & RawMesh)
{
uint32 Zero4Bytes =0;//Placeholder
uint32 One4Bytes = 1;//Placeholder
uint32 FileSize = 0;
FBufferArchive RawMeshArchive;
RawMeshArchive << One4Bytes;
int64 FileSizePos = RawMeshArchive.Tell();
RawMeshArchive << One4Bytes;
int64 FileStartPos = RawMeshArchive.Tell();
RawMeshArchive << MeshName;
uint8 Zero1Bytes = 0; //Placeholder
RawMeshArchive << Zero1Bytes;
RawMeshArchive << One4Bytes;
RawMeshArchive << Source_Models;
RawMeshArchive << Struct_Property;
RawMeshArchive << Zero4Bytes<<Zero4Bytes;
RawMeshArchive << Datasmith_Mesh_Source_Model;
RawMeshArchive << Zero4Bytes << Zero4Bytes << Zero4Bytes << Zero4Bytes << Zero4Bytes << Zero4Bytes << Zero1Bytes;
int64 MeshSizePos = RawMeshArchive.Tell();
RawMeshArchive << One4Bytes << One4Bytes;
uint32 Placeholder125 = 125;//Placeholder
RawMeshArchive << Placeholder125 << Zero4Bytes;
int64 MeshStartPos = RawMeshArchive.Tell();
RawMeshArchive << RawMesh;
int64 MeshEndPos = RawMeshArchive.Tell();
RawMeshArchive << Zero4Bytes << Zero4Bytes << Zero4Bytes << Zero4Bytes << Zero4Bytes;
int64 FileEndPos = RawMeshArchive.Tell();
uint32 MeshSize = MeshEndPos - MeshStartPos;
RawMeshArchive.Seek(MeshSizePos);
RawMeshArchive << MeshSize;
RawMeshArchive << MeshSize;
FileSize = FileEndPos - FileSizePos;
RawMeshArchive.Seek(0);
RawMeshArchive << One4Bytes<<FileSize;
RawMeshArchive.Seek(FileEndPos);
int64 TotalSize = FileSize + 8;
TArray<uint8>RawBinaryData;
RawBinaryData.SetNum(TotalSize);
FMemory::Memcpy(RawBinaryData.GetData(), RawMeshArchive.GetData(),TotalSize);
FString UdsMeshFileName = FString::Printf(TEXT("%s.udsmesh"), *MeshName);
FFileHelper::SaveArrayToFile(RawBinaryData, *(UdsAssetPath+ UdsMeshFileName));
}
Texture
/**
* @param TexName The path and name of the png file to save
* @param RawData The TArray Data to save
*/
void FUdsAsset::SaveToPngFile(const FString & TexName, const TArray<uint8>& RawData)
{
FString FileName = FString::Printf(TEXT("%s.png"), *TexName);
FFileHelper::SaveArrayToFile(RawData, *(UdsAssetPath + FileName));
}