Skip to content

Commit

Permalink
Fix bug loading cached remote files with spaces in the name via Unity…
Browse files Browse the repository at this point in the history
…GLTF
  • Loading branch information
andybak committed Jan 23, 2025
1 parent 1af184f commit 8cdaf9a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Assets/Scripts/ImportGltfast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ private static async Task _ImportUsingUnityGltf(
try
{
ImportOptions options = new ImportOptions();
GLTFSceneImporter gltf = new GLTFSceneImporter(localPath, options);

// See https://github.com/KhronosGroup/UnityGLTF/issues/805
var uriPath = $"file:///{ Uri.UnescapeDataString(localPath).Replace("\\","/")}";
GLTFSceneImporter gltf = new GLTFSceneImporter(uriPath, options);

gltf.IsMultithreaded = false;
AsyncHelpers.RunSync(() => gltf.LoadSceneAsync());
Expand Down
6 changes: 4 additions & 2 deletions Assets/Scripts/Poly/IcosaRawAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ public bool WriteToDisk()
UnityEngine.Debug.LogErrorFormat("Caller did not create directory for me: {0}", assetDir);
}
string rootFilePath = Path.Combine(assetDir, GetPolySanitizedFilePath(m_RootElement.filePath));
var unescapedRootFilePath = Uri.UnescapeDataString(rootFilePath);
if (!FileUtils.InitializeDirectory(Path.GetDirectoryName(rootFilePath)) ||
!FileUtils.WriteBytesIgnoreExceptions(m_RootElement.assetBytes, rootFilePath))
!FileUtils.WriteBytesIgnoreExceptions(m_RootElement.assetBytes, unescapedRootFilePath))
{
return false;
}
Expand All @@ -155,8 +156,9 @@ public bool WriteToDisk()
for (int j = 0; j < m_ResourceElements.Count; ++j)
{
string filePath = Path.Combine(assetDir, GetPolySanitizedFilePath(m_ResourceElements[j].filePath));
string unescapedFilePath = Uri.UnescapeDataString(filePath);
if (!FileUtils.InitializeDirectory(Path.GetDirectoryName(filePath)) ||
!FileUtils.WriteBytesIgnoreExceptions(m_ResourceElements[j].assetBytes, filePath))
!FileUtils.WriteBytesIgnoreExceptions(m_ResourceElements[j].assetBytes, unescapedFilePath))
{
RemoveFiles(written);
return false;
Expand Down

0 comments on commit 8cdaf9a

Please sign in to comment.