Skip to content

Commit

Permalink
Discard local "relative" path to gltf image uri when located in same …
Browse files Browse the repository at this point in the history
…folder than model (#991)

* Update GLTFExporter.Texture.cs

* move test function to PathUtilities

* Update PathUtilities.cs

* Update PathUtilities.cs
  • Loading branch information
pandaGaume authored Aug 2, 2021
1 parent 48e066e commit 226ba04
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions SharedProjects/Babylon2GLTF/GLTFExporter.Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private GLTFTextureInfo ExportTexture(BabylonTexture babylonTexture, GLTF gltf,
if (!string.IsNullOrWhiteSpace(exportParameters.textureFolder))
{
textureUri = PathUtilities.GetRelativePath( exportParameters.outputPath,exportParameters.textureFolder);
textureUri = Path.Combine(textureUri, ImageName);
textureUri = PathUtilities.IsLocalRootPath(textureUri) ? ImageName : Path.Combine(textureUri, ImageName);
}
gltfImage = new GLTFImage
{
Expand Down Expand Up @@ -266,7 +266,6 @@ private GLTFTextureInfo ExportTexture(BabylonTexture babylonTexture, GLTF gltf,
if (CheckIfImageIsRegistered(textureID))
{
var textureComponent = GetRegisteredTexture(textureID);

return textureComponent;
}

Expand All @@ -278,6 +277,7 @@ private GLTFTextureInfo ExportTexture(BabylonTexture babylonTexture, GLTF gltf,
}
}


private string TextureTransformID(GLTFTextureInfo gltfTextureInfo)
{
if (gltfTextureInfo.extensions == null || !gltfTextureInfo.extensions.ContainsKey(KHR_texture_transform))
Expand Down
5 changes: 5 additions & 0 deletions SharedProjects/Utilities/PathUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace Utilities
{
static class PathUtilities
{
public static string LocalDir = ".";
public static string LocalDirPath = $"{LocalDir}{Path.DirectorySeparatorChar}";
public static string AltLocalDirPath = $"{LocalDir}{Path.AltDirectorySeparatorChar}";

/// <summary>
/// Creates a relative path from one file or folder to another. Input paths that are directories should have a trailing slash.
Expand Down Expand Up @@ -66,6 +69,8 @@ public static string VerifyLegalFileName(string fileName)
return r.Replace(fileName, "_");
//source: https://stackoverflow.com/a/146162/301388
}

public static bool IsLocalRootPath(string path) => string.IsNullOrEmpty(path) || path.CompareTo(AltLocalDirPath) == 0 || path.CompareTo(LocalDirPath) == 0 || path.CompareTo(LocalDir) == 0;
}


Expand Down

0 comments on commit 226ba04

Please sign in to comment.