Skip to content

Commit 226ba04

Browse files
authored
Discard local "relative" path to gltf image uri when located in same folder than model (#991)
* Update GLTFExporter.Texture.cs * move test function to PathUtilities * Update PathUtilities.cs * Update PathUtilities.cs
1 parent 48e066e commit 226ba04

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

SharedProjects/Babylon2GLTF/GLTFExporter.Texture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private GLTFTextureInfo ExportTexture(BabylonTexture babylonTexture, GLTF gltf,
177177
if (!string.IsNullOrWhiteSpace(exportParameters.textureFolder))
178178
{
179179
textureUri = PathUtilities.GetRelativePath( exportParameters.outputPath,exportParameters.textureFolder);
180-
textureUri = Path.Combine(textureUri, ImageName);
180+
textureUri = PathUtilities.IsLocalRootPath(textureUri) ? ImageName : Path.Combine(textureUri, ImageName);
181181
}
182182
gltfImage = new GLTFImage
183183
{
@@ -266,7 +266,6 @@ private GLTFTextureInfo ExportTexture(BabylonTexture babylonTexture, GLTF gltf,
266266
if (CheckIfImageIsRegistered(textureID))
267267
{
268268
var textureComponent = GetRegisteredTexture(textureID);
269-
270269
return textureComponent;
271270
}
272271

@@ -278,6 +277,7 @@ private GLTFTextureInfo ExportTexture(BabylonTexture babylonTexture, GLTF gltf,
278277
}
279278
}
280279

280+
281281
private string TextureTransformID(GLTFTextureInfo gltfTextureInfo)
282282
{
283283
if (gltfTextureInfo.extensions == null || !gltfTextureInfo.extensions.ContainsKey(KHR_texture_transform))

SharedProjects/Utilities/PathUtilities.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ namespace Utilities
66
{
77
static class PathUtilities
88
{
9+
public static string LocalDir = ".";
10+
public static string LocalDirPath = $"{LocalDir}{Path.DirectorySeparatorChar}";
11+
public static string AltLocalDirPath = $"{LocalDir}{Path.AltDirectorySeparatorChar}";
912

1013
/// <summary>
1114
/// Creates a relative path from one file or folder to another. Input paths that are directories should have a trailing slash.
@@ -66,6 +69,8 @@ public static string VerifyLegalFileName(string fileName)
6669
return r.Replace(fileName, "_");
6770
//source: https://stackoverflow.com/a/146162/301388
6871
}
72+
73+
public static bool IsLocalRootPath(string path) => string.IsNullOrEmpty(path) || path.CompareTo(AltLocalDirPath) == 0 || path.CompareTo(LocalDirPath) == 0 || path.CompareTo(LocalDir) == 0;
6974
}
7075

7176

0 commit comments

Comments
 (0)