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

Expose Draco parameters for Max #918

Merged
merged 9 commits into from
Jan 13, 2021
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
100 changes: 71 additions & 29 deletions 3ds Max/Max2Babylon/Forms/ExporterForm.Designer.cs

Large diffs are not rendered by default.

60 changes: 56 additions & 4 deletions 3ds Max/Max2Babylon/Forms/ExporterForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private void LoadOptions()
chkDracoCompression.Enabled = false;
}


Tools.PrepareCheckBox(chkFullPBR, Loader.Core.RootNode, ExportParameters.PBRFullPropertyName);
Tools.PrepareCheckBox(chkNoAutoLight, Loader.Core.RootNode, ExportParameters.PBRNoLightPropertyName);
string storedEnvironmentPath = Loader.Core.RootNode.GetStringProperty(ExportParameters.PBREnvironmentPathPropertyName, string.Empty);
Expand All @@ -119,7 +120,23 @@ private void LoadOptions()
Tools.PrepareCheckBox(chkFlatten, Loader.Core.RootNode, "babylonjs_flattenScene", 0);
Tools.PrepareCheckBox(chkMrgContainersAndXref, Loader.Core.RootNode, "babylonjs_mergecontainersandxref", 0);
Tools.PrepareCheckBox(chkTryReuseTexture, Loader.Core.RootNode, "babylonjs_tryReuseTexture", 0);


#region prepare draco
LoadDracoOptions();
dracoUserControl.UpdateValueLabels(); // force value label to be updated
dracoGroupBox.Enabled = chkDracoCompression.Enabled && chkDracoCompression.Checked;
#endregion
}

private void LoadDracoOptions()
{
Tools.PrepareNumericUpDown(dracoUserControl.CompressionLevelNumericUpDown, Loader.Core.RootNode, $"babylonjs_{DracoParameters.compressionLevel_param_name}", DracoParameters.compressionLevel_default);
Tools.PrepareTrackBar(dracoUserControl.QPositionTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizePositionBits_param_name}", DracoParameters.quantizePositionBits_default);
Tools.PrepareTrackBar(dracoUserControl.QNormalTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeNormalBits_param_name}", DracoParameters.quantizeNormalBits_default);
Tools.PrepareTrackBar(dracoUserControl.QTexcoordTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeTexcoordBits_param_name}", DracoParameters.quantizeTexcoordBits_default);
Tools.PrepareTrackBar(dracoUserControl.QColorTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeColorBits_param_name}", DracoParameters.quantizeColorBits_default);
Tools.PrepareTrackBar(dracoUserControl.QGenericTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeGenericBits_param_name}", DracoParameters.quantizeGenericBits_default);
Tools.PrepareCheckBox(dracoUserControl.UnifiedCheckBox, Loader.Core.RootNode, $"babylonjs_{DracoParameters.unifiedQuantization_param_name}", DracoParameters.unifiedQuantization_default?1:0);
}

private void ExporterForm_Load(object sender, EventArgs e)
Expand Down Expand Up @@ -326,8 +343,22 @@ private void SaveOptions()
Tools.UpdateCheckBox(chkFlatten, Loader.Core.RootNode, "babylonjs_flattenScene");
Tools.UpdateCheckBox(chkMrgContainersAndXref, Loader.Core.RootNode, "babylonjs_mergecontainersandxref");
Tools.UpdateCheckBox(chkTryReuseTexture, Loader.Core.RootNode, "babylonjs_tryReuseTexture");

SaveDracoOptions();
}

private void SaveDracoOptions()
{
Tools.UpdateNumericUpDown(dracoUserControl.CompressionLevelNumericUpDown, Loader.Core.RootNode, $"babylonjs_{DracoParameters.compressionLevel_param_name}");
Tools.UpdateTrackBar(dracoUserControl.QPositionTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizePositionBits_param_name}");
Tools.UpdateTrackBar(dracoUserControl.QNormalTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeNormalBits_param_name}");
Tools.UpdateTrackBar(dracoUserControl.QTexcoordTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeTexcoordBits_param_name}");
Tools.UpdateTrackBar(dracoUserControl.QColorTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeColorBits_param_name}");
Tools.UpdateTrackBar(dracoUserControl.QGenericTrackBar, Loader.Core.RootNode, $"babylonjs_{DracoParameters.quantizeGenericBits_param_name}");
Tools.UpdateCheckBox(dracoUserControl.UnifiedCheckBox, Loader.Core.RootNode, $"babylonjs_{DracoParameters.unifiedQuantization_param_name}");
}


private async Task<bool> DoExport(ExportItem exportItem, bool multiExport = false, bool clearLogs = true)
{
new BabylonAnimationActionItem().Close();
Expand Down Expand Up @@ -398,7 +429,7 @@ private async Task<bool> DoExport(ExportItem exportItem, bool multiExport = fals
butCancel.Enabled = true;

// switch to the log tab.
exporterTabControl.SelectTab(1);
exporterTabControl.SelectTab(logTabPage.Name);

bool success = true;
try
Expand Down Expand Up @@ -444,7 +475,7 @@ private async Task<bool> DoExport(ExportItem exportItem, bool multiExport = fals
txtQuality = textureQualityParsed,
mergeAOwithMR = chkMergeAOwithMR.Checked,
bakeAnimationType = (BakeAnimationType)cmbBakeAnimationOptions.SelectedIndex,
dracoCompression = chkDracoCompression.Checked,
dracoCompression = chkDracoCompression.Enabled && chkDracoCompression.Checked,
enableKHRLightsPunctual = chkKHRLightsPunctual.Checked,
enableKHRTextureTransform = chkKHRTextureTransform.Checked,
enableKHRMaterialsUnlit = chkKHRMaterialsUnlit.Checked,
Expand All @@ -462,9 +493,23 @@ private async Task<bool> DoExport(ExportItem exportItem, bool multiExport = fals
flattenScene = chkFlatten.Checked,
mergeContainersAndXRef = chkMrgContainersAndXref.Checked,
useMultiExporter = multiExport,
tryToReuseOpaqueAndBlendTexture = chkTryReuseTexture.Checked
tryToReuseOpaqueAndBlendTexture = chkTryReuseTexture.Checked,
};

if (exportParameters.dracoCompression)
{
exportParameters.dracoParams = new DracoParameters()
{
compressionLevel = (int)dracoUserControl.CompressionLevelNumericUpDown.Value,
quantizePositionBits = dracoUserControl.QPositionTrackBar.Value,
quantizeNormalBits = dracoUserControl.QNormalTrackBar.Value,
quantizeTexcoordBits = dracoUserControl.QTexcoordTrackBar.Value,
quantizeColorBits = dracoUserControl.QColorTrackBar.Value,
quantizeGenericBits = dracoUserControl.QGenericTrackBar.Value,
unifiedQuantization = dracoUserControl.UnifiedCheckBox.Checked
};
}

exporter.callerForm = this;

exporter.Export(exportParameters);
Expand Down Expand Up @@ -741,6 +786,8 @@ private void comboOutputFormat_SelectedIndexChanged(object sender, EventArgs e)
break;
}

dracoGroupBox.Enabled = chkDracoCompression.Enabled && chkDracoCompression.Checked;

string newModelPath = Path.ChangeExtension(txtModelPath.Text, this.saveFileDialog.DefaultExt);
this.txtModelPath.MaxPath(newModelPath);
}
Expand Down Expand Up @@ -845,5 +892,10 @@ private void chkUsePreExportProces_CheckedChanged(object sender, EventArgs e)
chkApplyPreprocessToScene.Enabled = true;
}
}

private void chkDracoCompression_CheckedChanged(object sender, EventArgs e)
{
dracoGroupBox.Enabled = chkDracoCompression.Checked;
}
}
}
23 changes: 23 additions & 0 deletions 3ds Max/Max2Babylon/Tools/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,12 @@ public static float GetFloatProperty(this IINode node, string propertyName, floa
node.GetUserPropFloat(propertyName, ref state);
return state;
}
public static int GetIntProperty(this IINode node, string propertyName, int defaultState = 0)
{
int state = defaultState;
node.GetUserPropInt(propertyName, ref state);
return state;
}

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

public static void PrepareTrackBar(TrackBar tb, IINode node, string propertyName, int defaultState = 0)
{
tb.Value = node.GetIntProperty(propertyName, defaultState);
}
public static void UpdateTrackBar(TrackBar tb, IINode node, string propertyName)
{
node.SetUserPropInt(propertyName, tb.Value);
}
public static void PrepareNumericUpDown(NumericUpDown nup, List<IINode> nodes, string propertyName, float defaultState = 0)
{
nup.Value = (decimal)nodes[0].GetFloatProperty(propertyName, defaultState);
}

public static void PrepareNumericUpDown(NumericUpDown nup, IINode node, string propertyName, float defaultState)
{
nup.Value = (decimal)node.GetFloatProperty(propertyName, defaultState);
}

public static void UpdateNumericUpDown(NumericUpDown nup, List<IINode> nodes, string propertyName)
{
foreach (var node in nodes)
{
node.SetUserPropFloat(propertyName, (float)nup.Value);
}
}
public static void UpdateNumericUpDown(NumericUpDown nup, IINode node, string propertyName)
{
node.SetUserPropFloat(propertyName, (float)nup.Value);
}

public static void PrepareVector3Control(Vector3Control vector3Control, IINode node, string propertyName, float defaultX = 0, float defaultY = 0, float defaultZ = 0)
{
Expand Down
2 changes: 1 addition & 1 deletion SharedProjects/Babylon2GLTF/GLTFExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void ExportGltf(ExportParameters exportParameters, BabylonScene babylonSc
if(exportParameters.dracoCompression)
{
logger.RaiseMessage("GLTFExporter | Draco compression");
GLTFPipelineUtilities.DoDracoCompression(logger, generateBinary, outputFile);
GLTFPipelineUtilities.DoDracoCompression(logger, generateBinary, outputFile, exportParameters.dracoParams);
}

logger.ReportProgressChanged(100);
Expand Down
40 changes: 39 additions & 1 deletion SharedProjects/BabylonExport.Entities/ExportParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,40 @@ public enum TextureFormatExportPolicy
CONSERVATIV, // we try to keep the source format if possible
SIZE // we try to minimize the size of texture as much as possibe.
}
public class DracoParameters
{
public const string dracoPrefix = "draco.";
public static readonly string compressionLevel_param_name = $"{dracoPrefix}compressionLevel";
public static readonly string quantizePositionBits_param_name = $"{dracoPrefix}quantizePositionBits";
public static readonly string quantizeNormalBits_param_name = $"{dracoPrefix}quantizeNormalBits";
public static readonly string quantizeTexcoordBits_param_name = $"{dracoPrefix}quantizeTexcoordBits";
public static readonly string quantizeColorBits_param_name = $"{dracoPrefix}quantizeColorBits";
public static readonly string quantizeGenericBits_param_name = $"{dracoPrefix}quantizeGenericBits";
public static readonly string unifiedQuantization_param_name = $"{dracoPrefix}unifiedQuantization";


// default values are defined from https://github.com/CesiumGS/gltf-pipeline#command-line-flags
public const int compressionLevel_default = 7;
public const int quantizePositionBits_default = 14;
public const int quantizeNormalBits_default = 10;
public const int quantizeTexcoordBits_default = 12;
public const int quantizeColorBits_default = 8;
public const int quantizeGenericBits_default = 12;
public const bool unifiedQuantization_default = false;

public int compressionLevel = compressionLevel_default;
public int quantizePositionBits = quantizePositionBits_default;
public int quantizeNormalBits = quantizeNormalBits_default;
public int quantizeTexcoordBits = quantizeTexcoordBits_default;
public int quantizeColorBits = quantizeColorBits_default;
public int quantizeGenericBits = quantizeGenericBits_default;
public bool unifiedQuantization = unifiedQuantization_default;

public string toCLIArgs()
{
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}";
}
}

public class ExportParameters
{
Expand Down Expand Up @@ -37,7 +71,6 @@ public class ExportParameters
public bool exportMorphNormals = true;
public long txtQuality = 100;
public bool mergeAOwithMR = true;
public bool dracoCompression = false;
public bool enableKHRLightsPunctual = false;
public bool enableKHRTextureTransform = false;
public bool enableKHRMaterialsUnlit = false;
Expand All @@ -62,5 +95,10 @@ public class ExportParameters
public const string PBRFullPropertyName = "babylonjs_pbr_full";
public const string PBRNoLightPropertyName = "babylonjs_pbr_nolight";
public const string PBREnvironmentPathPropertyName = "babylonjs_pbr_environmentPathProperty";

#region DRACO
public bool dracoCompression = false;
public DracoParameters dracoParams = null;
#endregion
}
}
Loading