Skip to content

Commit 354f933

Browse files
pandaGaumeDrigax
andauthored
3dsMax : Add keep position option to multi export process. (#960)
* add keep pos check * fix index for exception Co-authored-by: Nicholas Barlow <whoisdrigax@gmail.com>
1 parent da84a0b commit 354f933

File tree

7 files changed

+59
-23
lines changed

7 files changed

+59
-23
lines changed

3ds Max/Max2Babylon/Exporter/BabylonExporter.ExportItem.cs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,28 @@ public bool Selected
102102
IsDirty = true;
103103
}
104104
}
105+
public bool KeepPosition
106+
{
107+
get { return keepPosition; }
108+
set
109+
{
110+
if (keepPosition == value) return;
111+
keepPosition = value;
112+
IsDirty = true;
113+
}
114+
}
105115

106-
const string s_DisplayNameFormat = "{0} | {1} | \"{2}\" | \"{3}\"| {4}";
107-
const char s_PropertySeparator = ';';
116+
const char s_PropertySeparator = ';';
108117
private const char s_ProperyLayerSeparator = '~';
109-
const string s_PropertyFormat = "{0};{1};{2};{3}";
118+
const string s_PropertyFormat = "{0};{1};{2};{3};{4}";
110119
const string s_PropertyNamePrefix = "babylonjs_ExportItem";
111120

112121
private string outputFileExt;
113122
private IINode exportNode;
114123
private List<IILayer> exportLayers;
115124
private uint exportNodeHandle = uint.MaxValue; // 0 is the scene root node
116125
private bool selected = true;
126+
private bool keepPosition = false;
117127
private string exportPathRelative = "";
118128
private string exportPathAbsolute = "";
119129
private string exportTexturesFolderRelative = "";
@@ -154,7 +164,7 @@ public ExportItem(string outputFileExt, string propertyName)
154164
LoadFromData(propertyName);
155165
}
156166

157-
public override string ToString() { return string.Format(s_DisplayNameFormat, selected, NodeName, exportPathRelative, exportTexturesFolderRelative, LayersToString(exportLayers)); }
167+
public override string ToString() { return $"{selected} | {keepPosition} | { NodeName} | \"{exportPathRelative}\" | \"{ exportTexturesFolderRelative}\" | { LayersToString(exportLayers)}"; }
158168

159169
public void SetExportLayers(List<IILayer> layers)
160170
{
@@ -303,21 +313,21 @@ public void LoadFromData(string propertyName)
303313
if (properties.Length < 2)
304314
throw new Exception("Invalid number of properties, can't deserialize.");
305315

316+
var i = 0;
317+
if (!bool.TryParse(properties[i], out selected))
318+
throw new Exception(string.Format("Failed to parse selected property from string {0}", properties[i]));
319+
320+
if (!bool.TryParse(properties[++i], out keepPosition))
321+
throw new Exception(string.Format("Failed to parse selected property from string {0}", properties[i]));
306322

307-
if (!bool.TryParse(properties[0], out selected))
308-
throw new Exception(string.Format("Failed to parse selected property from string {0}", properties[0]));
323+
SetExportFilePath(properties[++i]);
324+
SetExportTexturesFolderPath(properties[++i]);
325+
List<IILayer> layers = StringToLayers(properties[++i]);
309326

310-
311-
SetExportFilePath(properties[1]);
312-
SetExportTexturesFolderPath(properties[2]);
313-
List<IILayer> layers = StringToLayers(properties[3]);
314327
if (layers.Count > 0)
315328
{
316329
SetExportLayers(layers);
317330
}
318-
319-
320-
321331
IsDirty = false;
322332
}
323333

@@ -333,7 +343,7 @@ public bool SaveToData()
333343
IINode node = Node;
334344
if (node == null) return false;
335345

336-
node.SetStringProperty(GetPropertyName(), string.Format(s_PropertyFormat, selected.ToString(), exportPathRelative,exportTexturesFolderRelative,LayersToString(exportLayers)));
346+
node.SetStringProperty(GetPropertyName(), string.Format(s_PropertyFormat, selected.ToString(), keepPosition.ToString(), exportPathRelative,exportTexturesFolderRelative,LayersToString(exportLayers)));
337347

338348
IsDirty = false;
339349
return true;

3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,6 @@ private BabylonNode ExportInstanceMesh(IIGameScene maxScene, IIGameNode maxNode,
839839
babylonInstanceMesh.physicsRestitution = maxNode.MaxNode.GetFloatProperty("babylonjs_restitution", 0.2f);
840840
}
841841

842-
843842
// Add instance to master mesh
844843
List<BabylonAbstractMesh> list = babylonMasterMesh.instances != null ? babylonMasterMesh.instances.ToList() : new List<BabylonAbstractMesh>();
845844
list.Add(babylonInstanceMesh);

3ds Max/Max2Babylon/Exporter/BabylonExporter.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,12 @@ public void Export(MaxExportParameters exportParameters)
476476
BabylonNode node = exportNodeRec(maxRootNode, babylonScene, gameScene);
477477
// if we're exporting from a specific node, reset the pivot to {0,0,0}
478478
if (node != null && exportNode != null && !exportNode.IsRootNode)
479-
SetNodePosition(ref node, ref babylonScene, new float[] { 0, 0, 0 });
479+
{
480+
if (!exportParameters.exportKeepNodePosition)
481+
{
482+
SetNodePosition(ref node, ref babylonScene, new float[] { 0, 0, 0 });
483+
}
484+
}
480485

481486
progression += progressionStep;
482487
ReportProgressChanged((int)progression);

3ds Max/Max2Babylon/Exporter/MaxExportParameters.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class MaxExportParameters : ExportParameters
1515
{
1616
public Autodesk.Max.IINode exportNode;
1717
public List<Autodesk.Max.IILayer> exportLayers;
18+
public bool exportKeepNodePosition = false;
1819
public bool usePreExportProcess = false;
1920
public bool applyPreprocessToScene = false;
2021
public bool mergeContainersAndXRef = false;

3ds Max/Max2Babylon/Forms/ExporterForm.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ private async Task<bool> DoExport(ExportItem exportItem, bool multiExport = fals
488488
optimizeAnimations = !chkDoNotOptimizeAnimations.Checked,
489489
animgroupExportNonAnimated = chkAnimgroupExportNonAnimated.Checked,
490490
exportNode = exportItem?.Node,
491+
exportKeepNodePosition = exportItem?.KeepPosition??false,
491492
exportLayers = exportItem?.Layers,
492493
pbrNoLight = chkNoAutoLight.Checked,
493494
pbrFull = chkFullPBR.Checked,

3ds Max/Max2Babylon/Forms/MultiExportForm.Designer.cs

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3ds Max/Max2Babylon/Forms/MultiExportForm.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Max2Babylon
1515
public partial class MultiExportForm : Form
1616
{
1717
const bool Default_ExportItemSelected = true;
18+
const bool Default_KeepPosition = false;
1819
private CommonOpenFileDialog setTexturesFolderDialog;
1920
private ExportItemList exportItemList;
2021

@@ -34,6 +35,7 @@ private void ExportItemGridView_Populate(ExportItemList exportItemList)
3435
{
3536
DataGridViewRow row = new DataGridViewRow();
3637
row.Cells.Add(new DataGridViewCheckBoxCell());
38+
row.Cells.Add(new DataGridViewCheckBoxCell());
3739
row.Cells.Add(new DataGridViewTextBoxCell());
3840
row.Cells.Add(new DataGridViewTextBoxCell());
3941
row.Cells.Add(new DataGridViewTextBoxCell());
@@ -49,11 +51,13 @@ private void ExportItemGridView_Populate(ExportItemList exportItemList)
4951
private void SetRowData(DataGridViewRow row, ExportItem item)
5052
{
5153
row.Tag = item;
52-
row.Cells[0].Value = item.Selected;
53-
row.Cells[1].Value = item.LayersToString(item.Layers);
54-
row.Cells[2].Value = item.NodeName;
55-
row.Cells[3].Value = item.ExportFilePathAbsolute;
56-
row.Cells[4].Value = item.ExportTexturesesFolderAbsolute;
54+
var i = 0;
55+
row.Cells[i++].Value = item.Selected;
56+
row.Cells[i++].Value = item.KeepPosition;
57+
row.Cells[i++].Value = item.LayersToString(item.Layers);
58+
row.Cells[i++].Value = item.NodeName;
59+
row.Cells[i++].Value = item.ExportFilePathAbsolute;
60+
row.Cells[i ].Value = item.ExportTexturesesFolderAbsolute;
5761
Refresh();
5862
}
5963

@@ -168,9 +172,14 @@ private void ExportItemGridView_CellValueChanged(object sender, DataGridViewCell
168172

169173
if (e.ColumnIndex == ColumnExportCheckbox.Index)
170174
{
171-
if(item != null)
175+
if (item != null)
172176
item.Selected = row.Cells[0].Value == null ? Default_ExportItemSelected : (bool)row.Cells[0].Value;
173177
}
178+
if (e.ColumnIndex == ColumnKeepPositionCheckbox.Index)
179+
{
180+
if (item != null)
181+
item.KeepPosition = row.Cells[e.ColumnIndex].Value == null ? Default_KeepPosition : (bool)row.Cells[e.ColumnIndex].Value;
182+
}
174183
if (e.ColumnIndex == ColumnFilePath.Index)
175184
{
176185
string str = row.Cells[e.ColumnIndex].Value as string;
@@ -321,7 +330,7 @@ private void ExportItemGridView_CellContentClick(object sender, DataGridViewCell
321330
if (e.RowIndex < 0) return;
322331

323332
// necessary for checkboxes, problem with datagridview
324-
if (e.ColumnIndex == ColumnExportCheckbox.Index)
333+
if (e.ColumnIndex == ColumnExportCheckbox.Index || e.ColumnIndex == ColumnKeepPositionCheckbox.Index)
325334
{
326335
ExportItemGridView.EndEdit();
327336
}

0 commit comments

Comments
 (0)