Skip to content

Commit 0a53724

Browse files
pandaGaumeDrigax
andauthored
Expose Draco parameters for Max (#918)
* Introduce draco parameters * Prepare Draco Parameters Add class support for parameters 1- DracoParameter 2 - Draco User Control Modify GltfUtility to take parameters in account * Expose Draco Setting to form * Save and restore Draco parameters Let user to save and restore draco parameters along other exporters params * Update Draco Export flow * add comments to clarify default value * Update SharedProjects/Utilities/Draco/DracoUserControl.cs * Update SharedProjects/BabylonExport.Entities/ExportParameters.cs Co-authored-by: Nicholas Barlow <whoisdrigax@gmail.com>
1 parent 9d511e9 commit 0a53724

File tree

10 files changed

+864
-42
lines changed

10 files changed

+864
-42
lines changed

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

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

3ds Max/Max2Babylon/Forms/ExporterForm.cs

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ private void LoadOptions()
109109
chkDracoCompression.Enabled = false;
110110
}
111111

112+
112113
Tools.PrepareCheckBox(chkFullPBR, Loader.Core.RootNode, ExportParameters.PBRFullPropertyName);
113114
Tools.PrepareCheckBox(chkNoAutoLight, Loader.Core.RootNode, ExportParameters.PBRNoLightPropertyName);
114115
string storedEnvironmentPath = Loader.Core.RootNode.GetStringProperty(ExportParameters.PBREnvironmentPathPropertyName, string.Empty);
@@ -119,7 +120,23 @@ private void LoadOptions()
119120
Tools.PrepareCheckBox(chkFlatten, Loader.Core.RootNode, "babylonjs_flattenScene", 0);
120121
Tools.PrepareCheckBox(chkMrgContainersAndXref, Loader.Core.RootNode, "babylonjs_mergecontainersandxref", 0);
121122
Tools.PrepareCheckBox(chkTryReuseTexture, Loader.Core.RootNode, "babylonjs_tryReuseTexture", 0);
122-
123+
124+
#region prepare draco
125+
LoadDracoOptions();
126+
dracoUserControl.UpdateValueLabels(); // force value label to be updated
127+
dracoGroupBox.Enabled = chkDracoCompression.Enabled && chkDracoCompression.Checked;
128+
#endregion
129+
}
130+
131+
private void LoadDracoOptions()
132+
{
133+
Tools.PrepareNumericUpDown(dracoUserControl.CompressionLevelNumericUpDown, Loader.Core.RootNode, $"babylonjs_{DracoParameters.compressionLevel_param_name}", DracoParameters.compressionLevel_default);
134+
Tools.PrepareTrackBar(dracoUserControl.QPositionTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizePositionBits_param_name}", DracoParameters.quantizePositionBits_default);
135+
Tools.PrepareTrackBar(dracoUserControl.QNormalTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeNormalBits_param_name}", DracoParameters.quantizeNormalBits_default);
136+
Tools.PrepareTrackBar(dracoUserControl.QTexcoordTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeTexcoordBits_param_name}", DracoParameters.quantizeTexcoordBits_default);
137+
Tools.PrepareTrackBar(dracoUserControl.QColorTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeColorBits_param_name}", DracoParameters.quantizeColorBits_default);
138+
Tools.PrepareTrackBar(dracoUserControl.QGenericTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeGenericBits_param_name}", DracoParameters.quantizeGenericBits_default);
139+
Tools.PrepareCheckBox(dracoUserControl.UnifiedCheckBox, Loader.Core.RootNode, $"babylonjs_{DracoParameters.unifiedQuantization_param_name}", DracoParameters.unifiedQuantization_default?1:0);
123140
}
124141

125142
private void ExporterForm_Load(object sender, EventArgs e)
@@ -326,8 +343,22 @@ private void SaveOptions()
326343
Tools.UpdateCheckBox(chkFlatten, Loader.Core.RootNode, "babylonjs_flattenScene");
327344
Tools.UpdateCheckBox(chkMrgContainersAndXref, Loader.Core.RootNode, "babylonjs_mergecontainersandxref");
328345
Tools.UpdateCheckBox(chkTryReuseTexture, Loader.Core.RootNode, "babylonjs_tryReuseTexture");
346+
347+
SaveDracoOptions();
348+
}
349+
350+
private void SaveDracoOptions()
351+
{
352+
Tools.UpdateNumericUpDown(dracoUserControl.CompressionLevelNumericUpDown, Loader.Core.RootNode, $"babylonjs_{DracoParameters.compressionLevel_param_name}");
353+
Tools.UpdateTrackBar(dracoUserControl.QPositionTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizePositionBits_param_name}");
354+
Tools.UpdateTrackBar(dracoUserControl.QNormalTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeNormalBits_param_name}");
355+
Tools.UpdateTrackBar(dracoUserControl.QTexcoordTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeTexcoordBits_param_name}");
356+
Tools.UpdateTrackBar(dracoUserControl.QColorTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeColorBits_param_name}");
357+
Tools.UpdateTrackBar(dracoUserControl.QGenericTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeGenericBits_param_name}");
358+
Tools.UpdateCheckBox(dracoUserControl.UnifiedCheckBox, Loader.Core.RootNode, $"babylonjs_{DracoParameters.unifiedQuantization_param_name}");
329359
}
330360

361+
331362
private async Task<bool> DoExport(ExportItem exportItem, bool multiExport = false, bool clearLogs = true)
332363
{
333364
new BabylonAnimationActionItem().Close();
@@ -398,7 +429,7 @@ private async Task<bool> DoExport(ExportItem exportItem, bool multiExport = fals
398429
butCancel.Enabled = true;
399430

400431
// switch to the log tab.
401-
exporterTabControl.SelectTab(1);
432+
exporterTabControl.SelectTab(logTabPage.Name);
402433

403434
bool success = true;
404435
try
@@ -444,7 +475,7 @@ private async Task<bool> DoExport(ExportItem exportItem, bool multiExport = fals
444475
txtQuality = textureQualityParsed,
445476
mergeAOwithMR = chkMergeAOwithMR.Checked,
446477
bakeAnimationType = (BakeAnimationType)cmbBakeAnimationOptions.SelectedIndex,
447-
dracoCompression = chkDracoCompression.Checked,
478+
dracoCompression = chkDracoCompression.Enabled && chkDracoCompression.Checked,
448479
enableKHRLightsPunctual = chkKHRLightsPunctual.Checked,
449480
enableKHRTextureTransform = chkKHRTextureTransform.Checked,
450481
enableKHRMaterialsUnlit = chkKHRMaterialsUnlit.Checked,
@@ -462,9 +493,23 @@ private async Task<bool> DoExport(ExportItem exportItem, bool multiExport = fals
462493
flattenScene = chkFlatten.Checked,
463494
mergeContainersAndXRef = chkMrgContainersAndXref.Checked,
464495
useMultiExporter = multiExport,
465-
tryToReuseOpaqueAndBlendTexture = chkTryReuseTexture.Checked
496+
tryToReuseOpaqueAndBlendTexture = chkTryReuseTexture.Checked,
466497
};
467498

499+
if (exportParameters.dracoCompression)
500+
{
501+
exportParameters.dracoParams = new DracoParameters()
502+
{
503+
compressionLevel = (int)dracoUserControl.CompressionLevelNumericUpDown.Value,
504+
quantizePositionBits = dracoUserControl.QPositionTrackBar.Value,
505+
quantizeNormalBits = dracoUserControl.QNormalTrackBar.Value,
506+
quantizeTexcoordBits = dracoUserControl.QTexcoordTrackBar.Value,
507+
quantizeColorBits = dracoUserControl.QColorTrackBar.Value,
508+
quantizeGenericBits = dracoUserControl.QGenericTrackBar.Value,
509+
unifiedQuantization = dracoUserControl.UnifiedCheckBox.Checked
510+
};
511+
}
512+
468513
exporter.callerForm = this;
469514

470515
exporter.Export(exportParameters);
@@ -741,6 +786,8 @@ private void comboOutputFormat_SelectedIndexChanged(object sender, EventArgs e)
741786
break;
742787
}
743788

789+
dracoGroupBox.Enabled = chkDracoCompression.Enabled && chkDracoCompression.Checked;
790+
744791
string newModelPath = Path.ChangeExtension(txtModelPath.Text, this.saveFileDialog.DefaultExt);
745792
this.txtModelPath.MaxPath(newModelPath);
746793
}
@@ -845,5 +892,10 @@ private void chkUsePreExportProces_CheckedChanged(object sender, EventArgs e)
845892
chkApplyPreprocessToScene.Enabled = true;
846893
}
847894
}
895+
896+
private void chkDracoCompression_CheckedChanged(object sender, EventArgs e)
897+
{
898+
dracoGroupBox.Enabled = chkDracoCompression.Checked;
899+
}
848900
}
849901
}

3ds Max/Max2Babylon/Tools/Tools.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,12 @@ public static float GetFloatProperty(this IINode node, string propertyName, floa
13011301
node.GetUserPropFloat(propertyName, ref state);
13021302
return state;
13031303
}
1304+
public static int GetIntProperty(this IINode node, string propertyName, int defaultState = 0)
1305+
{
1306+
int state = defaultState;
1307+
node.GetUserPropInt(propertyName, ref state);
1308+
return state;
1309+
}
13041310

13051311
public static float[] GetVector3Property(this IINode node, string propertyName)
13061312
{
@@ -1591,18 +1597,35 @@ public static void UpdateTextBox(TextBox textBox, List<IINode> nodes, string pro
15911597
}
15921598
}
15931599

1600+
public static void PrepareTrackBar(TrackBar tb, IINode node, string propertyName, int defaultState = 0)
1601+
{
1602+
tb.Value = node.GetIntProperty(propertyName, defaultState);
1603+
}
1604+
public static void UpdateTrackBar(TrackBar tb, IINode node, string propertyName)
1605+
{
1606+
node.SetUserPropInt(propertyName, tb.Value);
1607+
}
15941608
public static void PrepareNumericUpDown(NumericUpDown nup, List<IINode> nodes, string propertyName, float defaultState = 0)
15951609
{
15961610
nup.Value = (decimal)nodes[0].GetFloatProperty(propertyName, defaultState);
15971611
}
15981612

1613+
public static void PrepareNumericUpDown(NumericUpDown nup, IINode node, string propertyName, float defaultState)
1614+
{
1615+
nup.Value = (decimal)node.GetFloatProperty(propertyName, defaultState);
1616+
}
1617+
15991618
public static void UpdateNumericUpDown(NumericUpDown nup, List<IINode> nodes, string propertyName)
16001619
{
16011620
foreach (var node in nodes)
16021621
{
16031622
node.SetUserPropFloat(propertyName, (float)nup.Value);
16041623
}
16051624
}
1625+
public static void UpdateNumericUpDown(NumericUpDown nup, IINode node, string propertyName)
1626+
{
1627+
node.SetUserPropFloat(propertyName, (float)nup.Value);
1628+
}
16061629

16071630
public static void PrepareVector3Control(Vector3Control vector3Control, IINode node, string propertyName, float defaultX = 0, float defaultY = 0, float defaultZ = 0)
16081631
{

SharedProjects/Babylon2GLTF/GLTFExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public void ExportGltf(ExportParameters exportParameters, BabylonScene babylonSc
274274
if(exportParameters.dracoCompression)
275275
{
276276
logger.RaiseMessage("GLTFExporter | Draco compression");
277-
GLTFPipelineUtilities.DoDracoCompression(logger, generateBinary, outputFile);
277+
GLTFPipelineUtilities.DoDracoCompression(logger, generateBinary, outputFile, exportParameters.dracoParams);
278278
}
279279

280280
logger.ReportProgressChanged(100);

SharedProjects/BabylonExport.Entities/ExportParameters.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,40 @@ public enum TextureFormatExportPolicy
1010
CONSERVATIV, // we try to keep the source format if possible
1111
SIZE // we try to minimize the size of texture as much as possibe.
1212
}
13+
public class DracoParameters
14+
{
15+
public const string dracoPrefix = "draco.";
16+
public static readonly string compressionLevel_param_name = $"{dracoPrefix}compressionLevel";
17+
public static readonly string quantizePositionBits_param_name = $"{dracoPrefix}quantizePositionBits";
18+
public static readonly string quantizeNormalBits_param_name = $"{dracoPrefix}quantizeNormalBits";
19+
public static readonly string quantizeTexcoordBits_param_name = $"{dracoPrefix}quantizeTexcoordBits";
20+
public static readonly string quantizeColorBits_param_name = $"{dracoPrefix}quantizeColorBits";
21+
public static readonly string quantizeGenericBits_param_name = $"{dracoPrefix}quantizeGenericBits";
22+
public static readonly string unifiedQuantization_param_name = $"{dracoPrefix}unifiedQuantization";
23+
24+
25+
// default values are defined from https://github.com/CesiumGS/gltf-pipeline#command-line-flags
26+
public const int compressionLevel_default = 7;
27+
public const int quantizePositionBits_default = 14;
28+
public const int quantizeNormalBits_default = 10;
29+
public const int quantizeTexcoordBits_default = 12;
30+
public const int quantizeColorBits_default = 8;
31+
public const int quantizeGenericBits_default = 12;
32+
public const bool unifiedQuantization_default = false;
33+
34+
public int compressionLevel = compressionLevel_default;
35+
public int quantizePositionBits = quantizePositionBits_default;
36+
public int quantizeNormalBits = quantizeNormalBits_default;
37+
public int quantizeTexcoordBits = quantizeTexcoordBits_default;
38+
public int quantizeColorBits = quantizeColorBits_default;
39+
public int quantizeGenericBits = quantizeGenericBits_default;
40+
public bool unifiedQuantization = unifiedQuantization_default;
41+
42+
public string toCLIArgs()
43+
{
44+
return $"--{compressionLevel_param_name} {compressionLevel} --{quantizePositionBits_param_name} {quantizePositionBits} --{quantizeNormalBits_param_name} {quantizeNormalBits} --{quantizeTexcoordBits_param_name} {quantizeTexcoordBits} --{quantizeColorBits_param_name} {quantizeColorBits} --{quantizeGenericBits_param_name} {quantizeGenericBits} --{unifiedQuantization_param_name} {unifiedQuantization}";
45+
}
46+
}
1347

1448
public class ExportParameters
1549
{
@@ -37,7 +71,6 @@ public class ExportParameters
3771
public bool exportMorphNormals = true;
3872
public long txtQuality = 100;
3973
public bool mergeAOwithMR = true;
40-
public bool dracoCompression = false;
4174
public bool enableKHRLightsPunctual = false;
4275
public bool enableKHRTextureTransform = false;
4376
public bool enableKHRMaterialsUnlit = false;
@@ -62,5 +95,10 @@ public class ExportParameters
6295
public const string PBRFullPropertyName = "babylonjs_pbr_full";
6396
public const string PBRNoLightPropertyName = "babylonjs_pbr_nolight";
6497
public const string PBREnvironmentPathPropertyName = "babylonjs_pbr_environmentPathProperty";
98+
99+
#region DRACO
100+
public bool dracoCompression = false;
101+
public DracoParameters dracoParams = null;
102+
#endregion
65103
}
66104
}

0 commit comments

Comments
 (0)