From d91fa7328f273e2afa94e88e1ae840be89684c02 Mon Sep 17 00:00:00 2001 From: elpie89 Date: Thu, 21 Nov 2019 20:07:24 +0100 Subject: [PATCH 1/2] image uri fix --- .../Forms/ExporterForm.Designer.cs | 80 +++++++++---------- 3ds Max/Max2Babylon/Forms/ExporterForm.cs | 55 +++++++------ .../Babylon2GLTF/GLTFExporter.Texture.cs | 11 ++- SharedProjects/Babylon2GLTF/GLTFExporter.cs | 2 +- .../GltfExport.Entities/GLTFImage.cs | 10 +-- SharedProjects/Utilities/PathUtilities.cs | 17 +++- 6 files changed, 97 insertions(+), 78 deletions(-) diff --git a/3ds Max/Max2Babylon/Forms/ExporterForm.Designer.cs b/3ds Max/Max2Babylon/Forms/ExporterForm.Designer.cs index 96b10e3b..f86678b5 100644 --- a/3ds Max/Max2Babylon/Forms/ExporterForm.Designer.cs +++ b/3ds Max/Max2Babylon/Forms/ExporterForm.Designer.cs @@ -31,7 +31,7 @@ private void InitializeComponent() this.components = new System.ComponentModel.Container(); this.butExport = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); - this.txtModelName = new System.Windows.Forms.RichTextBox(); + this.txtModelPath = new System.Windows.Forms.RichTextBox(); this.butModelBrowse = new System.Windows.Forms.Button(); this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); this.progressBar = new System.Windows.Forms.ProgressBar(); @@ -56,7 +56,7 @@ private void InitializeComponent() this.btnEnvBrowse = new System.Windows.Forms.Button(); this.chkNoAutoLight = new System.Windows.Forms.CheckBox(); this.textureLabel = new System.Windows.Forms.Label(); - this.txtTextureName = new System.Windows.Forms.RichTextBox(); + this.txtTexturesPath = new System.Windows.Forms.RichTextBox(); this.btnTxtBrowse = new System.Windows.Forms.Button(); this.chkExportMaterials = new System.Windows.Forms.CheckBox(); this.chkKHRMaterialsUnlit = new System.Windows.Forms.CheckBox(); @@ -108,32 +108,32 @@ private void InitializeComponent() // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(6, 17); + this.label1.Location = new System.Drawing.Point(11, 51); this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(68, 13); + this.label1.Size = new System.Drawing.Size(63, 13); this.label1.TabIndex = 1; - this.label1.Text = "Model name:"; + this.label1.Text = "Model path:"; // - // txtModelName + // txtModelPath // - this.txtModelName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.txtModelPath.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.txtModelName.Location = new System.Drawing.Point(86, 14); - this.txtModelName.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); - this.txtModelName.Multiline = false; - this.txtModelName.Name = "txtModelName"; - this.txtModelName.Size = new System.Drawing.Size(708, 20); - this.txtModelName.TabIndex = 2; - this.txtModelName.Text = ""; - this.txtModelName.TextChanged += new System.EventHandler(this.txtFilename_TextChanged); - this.txtModelName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ExporterForm_KeyDown); + this.txtModelPath.Location = new System.Drawing.Point(91, 48); + this.txtModelPath.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.txtModelPath.Multiline = false; + this.txtModelPath.Name = "txtModelPath"; + this.txtModelPath.Size = new System.Drawing.Size(708, 20); + this.txtModelPath.TabIndex = 2; + this.txtModelPath.Text = ""; + this.txtModelPath.TextChanged += new System.EventHandler(this.txtFilename_TextChanged); + this.txtModelPath.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ExporterForm_KeyDown); // // butModelBrowse // this.butModelBrowse.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.butModelBrowse.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.butModelBrowse.Location = new System.Drawing.Point(800, 12); + this.butModelBrowse.Location = new System.Drawing.Point(805, 46); this.butModelBrowse.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.butModelBrowse.Name = "butModelBrowse"; this.butModelBrowse.Size = new System.Drawing.Size(28, 23); @@ -243,7 +243,7 @@ private void InitializeComponent() this.groupBox1.Controls.Add(this.btnEnvBrowse); this.groupBox1.Controls.Add(this.chkNoAutoLight); this.groupBox1.Controls.Add(this.textureLabel); - this.groupBox1.Controls.Add(this.txtTextureName); + this.groupBox1.Controls.Add(this.txtTexturesPath); this.groupBox1.Controls.Add(this.btnTxtBrowse); this.groupBox1.Controls.Add(this.chkExportMaterials); this.groupBox1.Controls.Add(this.chkKHRMaterialsUnlit); @@ -268,7 +268,7 @@ private void InitializeComponent() this.groupBox1.Controls.Add(this.chkHidden); this.groupBox1.Controls.Add(this.label1); this.groupBox1.Controls.Add(this.chkWriteTextures); - this.groupBox1.Controls.Add(this.txtModelName); + this.groupBox1.Controls.Add(this.txtModelPath); this.groupBox1.Controls.Add(this.chkManifest); this.groupBox1.Controls.Add(this.butModelBrowse); this.groupBox1.Controls.Add(this.label2); @@ -445,30 +445,30 @@ private void InitializeComponent() // textureLabel // this.textureLabel.AutoSize = true; - this.textureLabel.Location = new System.Drawing.Point(6, 43); + this.textureLabel.Location = new System.Drawing.Point(11, 83); this.textureLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.textureLabel.Name = "textureLabel"; - this.textureLabel.Size = new System.Drawing.Size(75, 13); + this.textureLabel.Size = new System.Drawing.Size(76, 13); this.textureLabel.TabIndex = 24; - this.textureLabel.Text = "Texture folder:"; + this.textureLabel.Text = "Textures Path:"; // - // txtTextureName + // txtTexturesPath // - this.txtTextureName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.txtTexturesPath.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.txtTextureName.Location = new System.Drawing.Point(86, 40); - this.txtTextureName.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); - this.txtTextureName.Multiline = false; - this.txtTextureName.Name = "txtTextureName"; - this.txtTextureName.Size = new System.Drawing.Size(708, 20); - this.txtTextureName.TabIndex = 25; - this.txtTextureName.Text = ""; + this.txtTexturesPath.Location = new System.Drawing.Point(91, 80); + this.txtTexturesPath.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.txtTexturesPath.Multiline = false; + this.txtTexturesPath.Name = "txtTexturesPath"; + this.txtTexturesPath.Size = new System.Drawing.Size(708, 20); + this.txtTexturesPath.TabIndex = 25; + this.txtTexturesPath.Text = ""; // // btnTxtBrowse // this.btnTxtBrowse.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnTxtBrowse.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnTxtBrowse.Location = new System.Drawing.Point(800, 38); + this.btnTxtBrowse.Location = new System.Drawing.Point(805, 78); this.btnTxtBrowse.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.btnTxtBrowse.Name = "btnTxtBrowse"; this.btnTxtBrowse.Size = new System.Drawing.Size(28, 23); @@ -595,7 +595,7 @@ private void InitializeComponent() // // txtQuality // - this.txtQuality.Location = new System.Drawing.Point(403, 92); + this.txtQuality.Location = new System.Drawing.Point(786, 151); this.txtQuality.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.txtQuality.Name = "txtQuality"; this.txtQuality.Size = new System.Drawing.Size(43, 20); @@ -607,7 +607,7 @@ private void InitializeComponent() // labelQuality // this.labelQuality.AutoSize = true; - this.labelQuality.Location = new System.Drawing.Point(319, 94); + this.labelQuality.Location = new System.Drawing.Point(702, 153); this.labelQuality.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.labelQuality.Name = "labelQuality"; this.labelQuality.Size = new System.Drawing.Size(79, 13); @@ -658,7 +658,7 @@ private void InitializeComponent() // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(331, 70); + this.label4.Location = new System.Drawing.Point(714, 129); this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(67, 13); @@ -667,7 +667,7 @@ private void InitializeComponent() // // txtScaleFactor // - this.txtScaleFactor.Location = new System.Drawing.Point(403, 68); + this.txtScaleFactor.Location = new System.Drawing.Point(786, 127); this.txtScaleFactor.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.txtScaleFactor.Name = "txtScaleFactor"; this.txtScaleFactor.Size = new System.Drawing.Size(42, 20); @@ -679,7 +679,7 @@ private void InitializeComponent() // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(6, 66); + this.label3.Location = new System.Drawing.Point(11, 18); this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(74, 13); @@ -694,7 +694,7 @@ private void InitializeComponent() "binary babylon", "gltf", "glb"}); - this.comboOutputFormat.Location = new System.Drawing.Point(86, 64); + this.comboOutputFormat.Location = new System.Drawing.Point(91, 16); this.comboOutputFormat.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.comboOutputFormat.Name = "comboOutputFormat"; this.comboOutputFormat.Size = new System.Drawing.Size(121, 21); @@ -854,7 +854,7 @@ private void InitializeComponent() private System.Windows.Forms.Button butExport; private System.Windows.Forms.Label label1; - private System.Windows.Forms.RichTextBox txtModelName; + private System.Windows.Forms.RichTextBox txtModelPath; private System.Windows.Forms.Button butModelBrowse; private System.Windows.Forms.SaveFileDialog saveFileDialog; private System.Windows.Forms.ProgressBar progressBar; @@ -887,7 +887,7 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox chkExportMaterials; private System.Windows.Forms.Button saveOptionBtn; private System.Windows.Forms.Label textureLabel; - private System.Windows.Forms.RichTextBox txtTextureName; + private System.Windows.Forms.RichTextBox txtTexturesPath; private System.Windows.Forms.Button btnTxtBrowse; private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label7; diff --git a/3ds Max/Max2Babylon/Forms/ExporterForm.cs b/3ds Max/Max2Babylon/Forms/ExporterForm.cs index ab37e16c..968708f4 100644 --- a/3ds Max/Max2Babylon/Forms/ExporterForm.cs +++ b/3ds Max/Max2Babylon/Forms/ExporterForm.cs @@ -59,11 +59,11 @@ private void ExporterForm_Load(object sender, EventArgs e) { string storedModelPath = Loader.Core.RootNode.GetStringProperty(ExportParameters.ModelFilePathProperty, string.Empty); string absoluteModelPath = Tools.ResolveRelativePath(storedModelPath); - txtModelName.MaxPath(absoluteModelPath); + txtModelPath.MaxPath(absoluteModelPath); string storedFolderPath = Loader.Core.RootNode.GetStringProperty(ExportParameters.TextureFolderPathProperty, string.Empty); string absoluteTexturesFolderPath = Tools.ResolveRelativePath(storedFolderPath); - txtTextureName.MaxPath(absoluteTexturesFolderPath); + txtTexturesPath.MaxPath(absoluteTexturesFolderPath); singleExportItem = new ExportItem(absoluteModelPath); @@ -119,9 +119,9 @@ private void ExporterForm_Load(object sender, EventArgs e) private void butModelBrowse_Click(object sender, EventArgs e) { - if (!string.IsNullOrEmpty(txtModelName.Text)) + if (!string.IsNullOrEmpty(txtModelPath.Text)) { - string intialDirectory = Path.GetDirectoryName(txtModelName.Text); + string intialDirectory = Path.GetDirectoryName(txtModelPath.Text); if (!Directory.Exists(intialDirectory)) { @@ -138,13 +138,18 @@ private void butModelBrowse_Click(object sender, EventArgs e) if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { - txtModelName.MaxPath(saveFileDialog.FileName); + txtModelPath.MaxPath(saveFileDialog.FileName); + if (string.IsNullOrWhiteSpace(txtTexturesPath.Text)) + { + string defaultTexturesDir = Path.GetDirectoryName(txtModelPath.Text); + txtTexturesPath.MaxPath(defaultTexturesDir); + } } } private void btnTextureBrowse_Click(object sender, EventArgs e) { - if (string.IsNullOrWhiteSpace(txtModelName.Text)) + if (string.IsNullOrWhiteSpace(txtModelPath.Text)) { MessageBox.Show("Select model file path first"); return; @@ -152,11 +157,11 @@ private void btnTextureBrowse_Click(object sender, EventArgs e) CommonOpenFileDialog dialog = new CommonOpenFileDialog(); - string intialDirectory = txtTextureName.Text; + string intialDirectory = txtTexturesPath.Text; if (!Directory.Exists(intialDirectory)) { - intialDirectory = Path.GetDirectoryName(txtModelName.Text); + intialDirectory = Path.GetDirectoryName(txtModelPath.Text); } if (!Directory.Exists(intialDirectory)) @@ -175,14 +180,14 @@ private void btnTextureBrowse_Click(object sender, EventArgs e) if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { string selectedFolderPath = dialog.FileName; - string absoluteModelPath = txtModelName.Text; + string absoluteModelPath = txtModelPath.Text; if (!PathUtilities.IsBelowPath(selectedFolderPath, absoluteModelPath)) { - MessageBox.Show("WARNING: folderPath should be below model file path"); + CreateWarningMessage("WARNING: textures path should be below model file path, not all client renderer support this feature",0); } - txtTextureName.MaxPath(selectedFolderPath); + txtTexturesPath.MaxPath(selectedFolderPath); } } @@ -282,8 +287,8 @@ private void SaveOptions() Tools.UpdateComboBoxByIndex(cmbBakeAnimationOptions, Loader.Core.RootNode, "babylonjs_bakeAnimationsType"); Tools.UpdateCheckBox(chkApplyPreprocessToScene,Loader.Core.RootNode, "babylonjs_applyPreprocess"); - Loader.Core.RootNode.SetStringProperty(ExportParameters.ModelFilePathProperty, Tools.RelativePathStore(txtModelName.Text)); - Loader.Core.RootNode.SetStringProperty(ExportParameters.TextureFolderPathProperty, Tools.RelativePathStore(txtTextureName.Text)); + Loader.Core.RootNode.SetStringProperty(ExportParameters.ModelFilePathProperty, Tools.RelativePathStore(txtModelPath.Text)); + Loader.Core.RootNode.SetStringProperty(ExportParameters.TextureFolderPathProperty, Tools.RelativePathStore(txtTexturesPath.Text)); Tools.UpdateCheckBox(chkFullPBR, Loader.Core.RootNode, ExportParameters.PBRFullPropertyName); Tools.UpdateCheckBox(chkNoAutoLight, Loader.Core.RootNode, ExportParameters.PBRNoLightPropertyName); @@ -347,8 +352,8 @@ private async Task DoExport(ExportItem exportItem, bool multiExport = fals bool success = true; try { - string modelAbsolutePath = multiExport ? exportItem.ExportFilePathAbsolute : txtModelName.Text; - string textureExportPath = multiExport ? exportItem.ExportTexturesesFolderPath : txtTextureName.Text; + string modelAbsolutePath = multiExport ? exportItem.ExportFilePathAbsolute : txtModelPath.Text; + string textureExportPath = multiExport ? exportItem.ExportTexturesesFolderPath : txtTexturesPath.Text; MaxExportParameters exportParameters = new MaxExportParameters { outputPath = modelAbsolutePath, @@ -530,7 +535,7 @@ private void ExporterForm_FormClosed(object sender, FormClosedEventArgs e) private void txtFilename_TextChanged(object sender, EventArgs e) { - butExport.Enabled = !string.IsNullOrEmpty(txtModelName.Text.Trim()); + butExport.Enabled = !string.IsNullOrEmpty(txtModelPath.Text.Trim()); butExportAndRun.Enabled = butExport.Enabled && WebServer.IsSupported; } @@ -560,8 +565,8 @@ private async void butExportAndRun_Click(object sender, EventArgs e) if (await DoExport(singleExportItem)) { - WebServer.SceneFilename = Path.GetFileName(txtModelName.Text); - WebServer.SceneFolder = Path.GetDirectoryName(txtModelName.Text); + WebServer.SceneFilename = Path.GetFileName(txtModelPath.Text); + WebServer.SceneFolder = Path.GetDirectoryName(txtModelPath.Text); Process.Start(WebServer.url + WebServer.SceneFilename); @@ -598,8 +603,8 @@ private void comboOutputFormat_SelectedIndexChanged(object sender, EventArgs e) chkDracoCompression.Enabled = false; chkWriteTextures.Enabled = true; chkOverwriteTextures.Enabled = true; - txtTextureName.Text = string.Empty; - txtTextureName.Enabled = false; + txtTexturesPath.Text = string.Empty; + txtTexturesPath.Enabled = false; textureLabel.Enabled = false; btnTxtBrowse.Enabled = false; chkNoAutoLight.Enabled = true; @@ -616,7 +621,7 @@ private void comboOutputFormat_SelectedIndexChanged(object sender, EventArgs e) chkDracoCompression.Enabled = gltfPipelineInstalled; chkWriteTextures.Enabled = true; chkOverwriteTextures.Enabled = true; - txtTextureName.Enabled = true; + txtTexturesPath.Enabled = true; textureLabel.Enabled = true; btnTxtBrowse.Enabled = true; chkNoAutoLight.Enabled = false; @@ -638,8 +643,8 @@ private void comboOutputFormat_SelectedIndexChanged(object sender, EventArgs e) chkWriteTextures.Enabled = false; chkOverwriteTextures.Checked = true; chkOverwriteTextures.Enabled = false; - txtTextureName.Text = string.Empty; - txtTextureName.Enabled = false; + txtTexturesPath.Text = string.Empty; + txtTexturesPath.Enabled = false; textureLabel.Enabled = false; btnTxtBrowse.Enabled = false; chkNoAutoLight.Enabled = false; @@ -655,8 +660,8 @@ private void comboOutputFormat_SelectedIndexChanged(object sender, EventArgs e) break; } - string newModelPath = Path.ChangeExtension(txtModelName.Text, this.saveFileDialog.DefaultExt); - this.txtModelName.MaxPath(newModelPath); + string newModelPath = Path.ChangeExtension(txtModelPath.Text, this.saveFileDialog.DefaultExt); + this.txtModelPath.MaxPath(newModelPath); } /// diff --git a/SharedProjects/Babylon2GLTF/GLTFExporter.Texture.cs b/SharedProjects/Babylon2GLTF/GLTFExporter.Texture.cs index 9d63a790..c7d34ce7 100644 --- a/SharedProjects/Babylon2GLTF/GLTFExporter.Texture.cs +++ b/SharedProjects/Babylon2GLTF/GLTFExporter.Texture.cs @@ -160,7 +160,16 @@ private GLTFTextureInfo ExportTexture(BabylonTexture babylonTexture, GLTF gltf, string textureUri = name; if (!string.IsNullOrWhiteSpace(exportParameters.textureFolder)) { - textureUri = PathUtilities.GetRelativePath( exportParameters.outputPath,exportParameters.textureFolder) + "/"+ name; + textureUri = PathUtilities.GetRelativePath( exportParameters.outputPath,exportParameters.textureFolder); + if (textureUri == ".\\") + { + //texture is in same location of model + textureUri = name; + } + else + { + textureUri = Path.Combine(textureUri, name); + } } gltfImage = new GLTFImage { diff --git a/SharedProjects/Babylon2GLTF/GLTFExporter.cs b/SharedProjects/Babylon2GLTF/GLTFExporter.cs index 4c587d4b..bdc83480 100644 --- a/SharedProjects/Babylon2GLTF/GLTFExporter.cs +++ b/SharedProjects/Babylon2GLTF/GLTFExporter.cs @@ -482,7 +482,7 @@ private List SwitchImagesFromUriToBinary(GLTF gltf) foreach (GLTFImage gltfImage in gltf.ImagesList) { - var path = Path.Combine(gltf.OutputFolder, Uri.UnescapeDataString(gltfImage.uri)); + var path = Path.Combine(gltf.OutputFolder, gltfImage.uri); byte[] imageBytes = File.ReadAllBytes(path); // Chunk must be padded with trailing zeros (0x00) to satisfy alignment requirements diff --git a/SharedProjects/GltfExport.Entities/GLTFImage.cs b/SharedProjects/GltfExport.Entities/GLTFImage.cs index 1daede76..a2b16dcf 100644 --- a/SharedProjects/GltfExport.Entities/GLTFImage.cs +++ b/SharedProjects/GltfExport.Entities/GLTFImage.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Runtime.Serialization; namespace GLTFExport.Entities @@ -12,14 +13,7 @@ public string uri get { return _uri; } set { - if (value == null) - { - _uri = null; - } - else - { - _uri = Uri.EscapeDataString(value); - } + _uri = value; } } diff --git a/SharedProjects/Utilities/PathUtilities.cs b/SharedProjects/Utilities/PathUtilities.cs index a248b667..f7a312db 100644 --- a/SharedProjects/Utilities/PathUtilities.cs +++ b/SharedProjects/Utilities/PathUtilities.cs @@ -23,15 +23,14 @@ public static string GetRelativePath(string fromPath, string toPath) if (string.IsNullOrEmpty(toPath)) throw new ArgumentNullException("toPath"); - Uri fromUri = new Uri(fromPath); - Uri toUri = new Uri(toPath); + Uri fromUri = new Uri(AppendDirectorySeparatorChar(fromPath)); + Uri toUri = new Uri(AppendDirectorySeparatorChar(toPath)); if (fromUri.Scheme != toUri.Scheme) return toPath; Uri relativeUri = fromUri.MakeRelativeUri(toUri); string relativePath = Uri.UnescapeDataString(relativeUri.ToString()); - if (string.Equals(toUri.Scheme, Uri.UriSchemeFile, StringComparison.OrdinalIgnoreCase)) relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); @@ -47,6 +46,18 @@ public static bool IsBelowPath(string childPath, string parentPath) } return false; + } + + private static string AppendDirectorySeparatorChar(string path) + { + // Append a slash only if the path is a directory and does not have a slash. + if (!Path.HasExtension(path) && + !path.EndsWith(Path.DirectorySeparatorChar.ToString())) + { + return path + Path.DirectorySeparatorChar; + } + + return path; } } } From 7ca17fed14a5ea1b484a007c28be22c876679534 Mon Sep 17 00:00:00 2001 From: Pierabella Luca Date: Sun, 24 Nov 2019 00:37:11 +0100 Subject: [PATCH 2/2] uri fix --- 3ds Max/Max2Babylon/Forms/ExporterForm.cs | 7 ++++++- SharedProjects/Babylon2GLTF/GLTFExporter.Texture.cs | 10 +--------- SharedProjects/Babylon2GLTF/GLTFExporter.cs | 4 ++++ SharedProjects/Utilities/PathUtilities.cs | 4 +--- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/3ds Max/Max2Babylon/Forms/ExporterForm.cs b/3ds Max/Max2Babylon/Forms/ExporterForm.cs index 968708f4..658c5307 100644 --- a/3ds Max/Max2Babylon/Forms/ExporterForm.cs +++ b/3ds Max/Max2Babylon/Forms/ExporterForm.cs @@ -144,6 +144,11 @@ private void butModelBrowse_Click(object sender, EventArgs e) string defaultTexturesDir = Path.GetDirectoryName(txtModelPath.Text); txtTexturesPath.MaxPath(defaultTexturesDir); } + + if (!PathUtilities.IsBelowPath(txtTexturesPath.Text, txtModelPath.Text)) + { + CreateWarningMessage("WARNING: textures path should be below model file path, not all client renderers support this feature", 0); + } } } @@ -184,7 +189,7 @@ private void btnTextureBrowse_Click(object sender, EventArgs e) if (!PathUtilities.IsBelowPath(selectedFolderPath, absoluteModelPath)) { - CreateWarningMessage("WARNING: textures path should be below model file path, not all client renderer support this feature",0); + CreateWarningMessage("WARNING: textures path should be below model file path, not all client renderers support this feature",0); } txtTexturesPath.MaxPath(selectedFolderPath); diff --git a/SharedProjects/Babylon2GLTF/GLTFExporter.Texture.cs b/SharedProjects/Babylon2GLTF/GLTFExporter.Texture.cs index c7d34ce7..6509f1ed 100644 --- a/SharedProjects/Babylon2GLTF/GLTFExporter.Texture.cs +++ b/SharedProjects/Babylon2GLTF/GLTFExporter.Texture.cs @@ -161,15 +161,7 @@ private GLTFTextureInfo ExportTexture(BabylonTexture babylonTexture, GLTF gltf, if (!string.IsNullOrWhiteSpace(exportParameters.textureFolder)) { textureUri = PathUtilities.GetRelativePath( exportParameters.outputPath,exportParameters.textureFolder); - if (textureUri == ".\\") - { - //texture is in same location of model - textureUri = name; - } - else - { - textureUri = Path.Combine(textureUri, name); - } + textureUri = Path.Combine(textureUri, name); } gltfImage = new GLTFImage { diff --git a/SharedProjects/Babylon2GLTF/GLTFExporter.cs b/SharedProjects/Babylon2GLTF/GLTFExporter.cs index bdc83480..f5ebac39 100644 --- a/SharedProjects/Babylon2GLTF/GLTFExporter.cs +++ b/SharedProjects/Babylon2GLTF/GLTFExporter.cs @@ -470,7 +470,11 @@ private string gltfToJson(GLTF gltf) // Use the bounded writer in case some values are infinity () using (var jsonWriter = new JsonTextWriterBounded(sw)) { +#if DEBUG + jsonWriter.Formatting = Formatting.Indented; +#else jsonWriter.Formatting = Formatting.None; +#endif jsonSerializer.Serialize(jsonWriter, gltf); } return sb.ToString(); diff --git a/SharedProjects/Utilities/PathUtilities.cs b/SharedProjects/Utilities/PathUtilities.cs index f7a312db..48f74c2f 100644 --- a/SharedProjects/Utilities/PathUtilities.cs +++ b/SharedProjects/Utilities/PathUtilities.cs @@ -31,9 +31,7 @@ public static string GetRelativePath(string fromPath, string toPath) Uri relativeUri = fromUri.MakeRelativeUri(toUri); string relativePath = Uri.UnescapeDataString(relativeUri.ToString()); - if (string.Equals(toUri.Scheme, Uri.UriSchemeFile, StringComparison.OrdinalIgnoreCase)) - relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); - + return relativePath; }