Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Texture folder explicit #532

Merged
merged 6 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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