Skip to content

Commit

Permalink
Merge pull request #532 from elpie89/texture_folder_explicit
Browse files Browse the repository at this point in the history
Texture folder explicit
  • Loading branch information
Drigax authored Jun 7, 2019
2 parents bbabd59 + 593c0a5 commit 7bbeed6
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 84 deletions.
1 change: 1 addition & 0 deletions 3ds Max/Max2Babylon/ExportParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class ExportParameters
{
public string outputPath;
public string outputFormat;
public string textureFolder;
public string scaleFactor = "1";
public bool writeTextures = true;
public bool overwriteTextures = true;
Expand Down
1 change: 1 addition & 0 deletions 3ds Max/Max2Babylon/Exporter/BabylonExporter.ExportItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public bool Selected
private bool selected = true;
private string exportPathRelative = "";
private string exportPathAbsolute = "";
private string exportTextureFolderPathRelative = "";

public ExportItem(string outputFileExt) { this.outputFileExt = outputFileExt; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ partial class BabylonExporter
public const string KHR_texture_transform = "KHR_texture_transform"; // Name of the extension
private Dictionary<string, GLTFTextureInfo> glTFTextureInfoMap = new Dictionary<string, GLTFTextureInfo>();
private Dictionary<string, GLTFImage> glTFImageMap = new Dictionary<string, GLTFImage>();

public string relativeTextureFolder = "";
/// <summary>
/// Export the texture using the parameters of babylonTexture except its name.
/// Write the bitmap file
Expand Down Expand Up @@ -62,6 +62,21 @@ private GLTFTextureInfo ExportTexture(BabylonTexture babylonTexture, GLTF gltf)
() => { return TryWriteImage(gltf, babylonTexture.originalPath, babylonTexture.name); });
}

private bool ExtensionIsValidGLTFTexture(string _extension)
{
if (_extension.StartsWith("."))
{
_extension = _extension.Replace(".", "");
}

if (validGltfFormats.Contains(_extension))
{
return true;
}

return false;
}

private string TryWriteImage(GLTF gltf, string sourcePath, string textureName)
{
if (sourcePath == null || sourcePath == "")
Expand Down Expand Up @@ -157,9 +172,14 @@ private GLTFTextureInfo ExportTexture(BabylonTexture babylonTexture, GLTF gltf,
}
else
{
string textureUri = name;
if (!string.IsNullOrWhiteSpace(relativeTextureFolder))
{
textureUri = relativeTextureFolder + "/"+ name;
}
gltfImage = new GLTFImage
{
uri = name
uri = textureUri
};
gltfImage.index = gltf.ImagesList.Count;
gltf.ImagesList.Add(gltfImage);
Expand Down
9 changes: 8 additions & 1 deletion 3ds Max/Max2Babylon/Exporter/BabylonExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void Export(ExportParameters exportParameters)

string tempOutputDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
string outputDirectory = Path.GetDirectoryName(exportParameters.outputPath);
string folderOuputDirectory = exportParameters.textureFolder;
string outputFileName = Path.GetFileName(exportParameters.outputPath);

// Check directory exists
Expand Down Expand Up @@ -557,6 +558,7 @@ public void Export(ExportParameters exportParameters)
var tempFilePath = Path.Combine(tempOutputDirectory, file);
var outputFile = Path.Combine(outputDirectory, file);


IUTF8Str maxNotification = GlobalInterface.Instance.UTF8Str.Create(outputFile);
Loader.Global.BroadcastNotification(SystemNotificationCode.PreExport, maxNotification);
moveFileToOutputDirectory(tempFilePath, outputFile, exportParameters);
Expand All @@ -571,8 +573,13 @@ public void Export(ExportParameters exportParameters)
foreach (var filePath in filePaths)
{
var file = Path.GetFileName(filePath);
var outputPath = Path.Combine(outputDirectory, file);
string ext = Path.GetExtension(file);
var tempFilePath = Path.Combine(tempOutputDirectory, file);
var outputPath = Path.Combine(outputDirectory, file);
if (!string.IsNullOrWhiteSpace(exportParameters.textureFolder) && ExtensionIsValidGLTFTexture(ext))
{
outputPath = Path.Combine(exportParameters.textureFolder, file);
}

IUTF8Str maxNotification = GlobalInterface.Instance.UTF8Str.Create(outputPath);
Loader.Global.BroadcastNotification(SystemNotificationCode.PreExport, maxNotification);
Expand Down
Loading

0 comments on commit 7bbeed6

Please sign in to comment.