Skip to content

Commit

Permalink
support old vmd format
Browse files Browse the repository at this point in the history
  • Loading branch information
noname0310 committed Jan 29, 2024
1 parent df0196d commit 620b67b
Showing 1 changed file with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bool FVmdImporter::IsValidVmdFile()
FileReader->Seek(0);
uint8 Magic[30];
FileReader->Serialize(Magic, sizeof Magic);
if (FMmdImportHelper::ShiftJisToFString(Magic, sizeof Magic).Contains("Vocaloid Motion Data 0002") == false)
if (FMmdImportHelper::ShiftJisToFString(Magic, sizeof Magic).StartsWith("Vocaloid Motion Data 0002", ESearchCase::CaseSensitive) == false)
{
UE_LOG(LogMMDCameraImporter, Error, TEXT("File is not vmd format"));
return false;
Expand Down Expand Up @@ -77,8 +77,8 @@ bool FVmdImporter::IsValidVmdFile()

if (FileSize < Offset + static_cast<int64>(sizeof(uint32)))
{
UE_LOG(LogMMDCameraImporter, Error, TEXT("File seems to be corrupt(Failed to read number of camera keyframes)"));
return false;
UE_LOG(LogMMDCameraImporter, Warning, TEXT("File does not contain camera/self shadow/property keyframes"));
return true;
}
FileReader->Seek(Offset);
uint32 CameraKeyFrameCount = 0;
Expand All @@ -97,8 +97,8 @@ bool FVmdImporter::IsValidVmdFile()

if (FileSize < Offset + static_cast<int64>(sizeof(uint32)))
{
UE_LOG(LogMMDCameraImporter, Error, TEXT("File seems to be corrupt(Failed to read number of self shadow keyframes)"));
return false;
UE_LOG(LogMMDCameraImporter, Log, TEXT("File does not contain self shadow/property keyframes"));
return true;
}
FileReader->Seek(Offset);
uint32 SelfShadowKeyFrameCount = 0;
Expand All @@ -107,8 +107,8 @@ bool FVmdImporter::IsValidVmdFile()

if (FileSize < Offset + static_cast<int64>(sizeof(uint32)))
{
UE_LOG(LogMMDCameraImporter, Error, TEXT("File seems to be corrupt(Failed to read number of properties keyframes)"));
return false;
UE_LOG(LogMMDCameraImporter, Log, TEXT("File does not contain property keyframes"));
return true;
}
FileReader->Seek(Offset);
uint32 PropertyKeyFrameCount = 0;
Expand Down Expand Up @@ -164,6 +164,8 @@ FVmdParseResult FVmdImporter::ParseVmdFile()
FScopedSlowTask ImportVmdTask(7, LOCTEXT("ReadingVMDFile", "Reading VMD File"));
ImportVmdTask.MakeDialog(true, true);

const int64 FileSize = FileReader->TotalSize();

FVmdParseResult VmdParseResult;
VmdParseResult.bIsSuccess = false;

Expand Down Expand Up @@ -201,6 +203,11 @@ FVmdParseResult FVmdImporter::ParseVmdFile()
{
return VmdParseResult;
}
if (FileSize < FileReader->Tell() + static_cast<int64>(sizeof(uint32))) // some VMD files don't have camera, light key frames
{
VmdParseResult.bIsSuccess = true;
return VmdParseResult;
}
ImportVmdTask.EnterProgressFrame(1, LOCTEXT("ReadingVMDFileCameraKeyFrames", "Reading Camera Key Frames"));
uint32 CameraKeyFrameCount = 0;
FileReader->Serialize(&CameraKeyFrameCount, sizeof(uint32));
Expand All @@ -223,6 +230,11 @@ FVmdParseResult FVmdImporter::ParseVmdFile()
{
return VmdParseResult;
}
if (FileSize < FileReader->Tell() + static_cast<int64>(sizeof(uint32))) // some VMD files don't have self shadow key frames
{
VmdParseResult.bIsSuccess = true;
return VmdParseResult;
}
ImportVmdTask.EnterProgressFrame(1, LOCTEXT("ReadingVMDFileSelfShadowKeyFrames", "Reading Self Shadow Key Frames"));
uint32 SelfShadowKeyFrameCount = 0;
FileReader->Serialize(&SelfShadowKeyFrameCount, sizeof(uint32));
Expand All @@ -234,6 +246,11 @@ FVmdParseResult FVmdImporter::ParseVmdFile()
{
return VmdParseResult;
}
if (FileSize < FileReader->Tell() + static_cast<int64>(sizeof(uint32))) // some VMD files don't have property key frames
{
VmdParseResult.bIsSuccess = true;
return VmdParseResult;
}
ImportVmdTask.EnterProgressFrame(1, LOCTEXT("ReadingVMDFilePropertyKeyFrames", "Reading Property Key Frames"));
uint32 PropertyKeyFrameCount = 0;
FileReader->Serialize(&PropertyKeyFrameCount, sizeof(uint32));
Expand Down

0 comments on commit 620b67b

Please sign in to comment.