Skip to content

Commit 3acea99

Browse files
committed
Clearer error message for non-binary LE PLY files (#165)
1 parent 3bff1de commit 3acea99

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

package/Editor/GaussianSplatAssetCreator.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,17 @@ void OnGUI()
8787

8888
if (m_InputFile != m_PrevFilePath && !string.IsNullOrWhiteSpace(m_InputFile))
8989
{
90-
m_PrevVertexCount = GaussianFileReader.ReadFileHeader(m_InputFile);
90+
m_PrevVertexCount = 0;
91+
m_ErrorMessage = null;
92+
try
93+
{
94+
m_PrevVertexCount = GaussianFileReader.ReadFileHeader(m_InputFile);
95+
}
96+
catch (Exception ex)
97+
{
98+
m_ErrorMessage = ex.Message;
99+
}
100+
91101
m_PrevFileSize = File.Exists(m_InputFile) ? new FileInfo(m_InputFile).Length : 0;
92102
m_PrevFilePath = m_InputFile;
93103
}

package/Editor/Utils/PLYFileReader.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ static void ReadHeaderImpl(string filePath, out int vertexCount, out int vertexS
3333
vertexStride = 0;
3434
attrs = new List<(string, ElementType)>();
3535
const int kMaxHeaderLines = 9000;
36+
bool got_binary_le = false;
3637
for (int lineIdx = 0; lineIdx < kMaxHeaderLines; ++lineIdx)
3738
{
3839
var line = ReadLine(fs);
3940
if (line == "end_header" || line.Length == 0)
4041
break;
4142
var tokens = line.Split(' ');
43+
if (tokens.Length == 3 && tokens[0] == "format" && tokens[1] == "binary_little_endian" && tokens[2] == "1.0")
44+
got_binary_le = true;
4245
if (tokens.Length == 3 && tokens[0] == "element" && tokens[1] == "vertex")
4346
vertexCount = int.Parse(tokens[2]);
4447
if (tokens.Length == 3 && tokens[0] == "property")
@@ -54,6 +57,11 @@ static void ReadHeaderImpl(string filePath, out int vertexCount, out int vertexS
5457
attrs.Add((tokens[2], type));
5558
}
5659
}
60+
61+
if (!got_binary_le)
62+
{
63+
throw new IOException($"PLY {filePath} not supported: needs to be binary, little endian PLY format");
64+
}
5765
}
5866

5967
public static void ReadFile(string filePath, out int vertexCount, out int vertexStride, out List<(string, ElementType)> attrs, out NativeArray<byte> vertices)

0 commit comments

Comments
 (0)