Add Model SDF generation utilities
This commit is contained in:
@@ -38,7 +38,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
PreviewLight.ShadowsDistance = 2000.0f;
|
||||
Task.ViewFlags |= ViewFlags.Shadows;
|
||||
}
|
||||
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
base.Draw();
|
||||
@@ -75,10 +75,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
base.OnClean();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the highlight/isolate effects on UI.
|
||||
/// </summary>
|
||||
public void UpdateEffectsOnUI()
|
||||
private void UpdateEffectsOnUI()
|
||||
{
|
||||
Window._skipEffectsGuiEvents = true;
|
||||
|
||||
@@ -97,10 +94,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
Window._skipEffectsGuiEvents = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the material slots UI parts. Should be called after material slot rename.
|
||||
/// </summary>
|
||||
public void UpdateMaterialSlotsUI()
|
||||
private void UpdateMaterialSlotsUI()
|
||||
{
|
||||
Window._skipEffectsGuiEvents = true;
|
||||
|
||||
@@ -123,12 +117,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
Window._skipEffectsGuiEvents = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the material slot index to the mesh.
|
||||
/// </summary>
|
||||
/// <param name="mesh">The mesh.</param>
|
||||
/// <param name="newSlotIndex">New index of the material slot to use.</param>
|
||||
public void SetMaterialSlot(Mesh mesh, int newSlotIndex)
|
||||
private void SetMaterialSlot(Mesh mesh, int newSlotIndex)
|
||||
{
|
||||
if (Window._skipEffectsGuiEvents)
|
||||
return;
|
||||
@@ -139,11 +128,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
Window.MarkAsEdited();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the material slot to isolate.
|
||||
/// </summary>
|
||||
/// <param name="mesh">The mesh.</param>
|
||||
public void SetIsolate(Mesh mesh)
|
||||
private void SetIsolate(Mesh mesh)
|
||||
{
|
||||
if (Window._skipEffectsGuiEvents)
|
||||
return;
|
||||
@@ -153,11 +138,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
UpdateEffectsOnUI();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the material slot index to highlight.
|
||||
/// </summary>
|
||||
/// <param name="mesh">The mesh.</param>
|
||||
public void SetHighlight(Mesh mesh)
|
||||
private void SetHighlight(Mesh mesh)
|
||||
{
|
||||
if (Window._skipEffectsGuiEvents)
|
||||
return;
|
||||
@@ -169,6 +150,8 @@ namespace FlaxEditor.Windows.Assets
|
||||
|
||||
private class ProxyEditor : ProxyEditorBase
|
||||
{
|
||||
private CustomEditors.Elements.IntegerValueElement _sdfModelLodIndex;
|
||||
|
||||
public override void Initialize(LayoutElementsContainer layout)
|
||||
{
|
||||
var proxy = (MeshesPropertiesProxy)Values[0];
|
||||
@@ -198,6 +181,46 @@ namespace FlaxEditor.Windows.Assets
|
||||
};
|
||||
}
|
||||
|
||||
// SDF
|
||||
{
|
||||
var group = layout.Group("SDF");
|
||||
|
||||
var sdf = proxy.Asset.SDF;
|
||||
if (sdf.Texture != null)
|
||||
{
|
||||
var size = sdf.Texture.Size3;
|
||||
group.Label($"SDF Texture {size.X}x{size.Y}x{size.Z} ({Utilities.Utils.FormatBytesCount(sdf.Texture.MemoryUsage)})").AddCopyContextMenu();
|
||||
}
|
||||
else
|
||||
{
|
||||
group.Label("No SDF");
|
||||
}
|
||||
|
||||
var resolution = group.FloatValue("Resolution Scale", proxy.Window.Editor.CodeDocs.GetTooltip(typeof(ModelImportSettings), nameof(ModelImportSettings.SDFResolution)));
|
||||
resolution.FloatValue.MinValue = 0.0001f;
|
||||
resolution.FloatValue.MaxValue = 100.0f;
|
||||
resolution.FloatValue.Value = sdf.Texture != null ? sdf.ResolutionScale : 1.0f;
|
||||
resolution.FloatValue.BoxValueChanged += b => { proxy.Window._importSettings.SDFResolution = b.Value; };
|
||||
|
||||
var lodIndex = group.IntegerValue("LOD Index", "Index of the model Level of Detail to use for SDF data building. By default uses the lowest quality LOD for fast building.");
|
||||
lodIndex.IntValue.MinValue = 0;
|
||||
lodIndex.IntValue.MaxValue = lods.Length - 1;
|
||||
lodIndex.IntValue.Value = sdf.Texture != null ? sdf.LOD : 6;
|
||||
_sdfModelLodIndex = lodIndex;
|
||||
|
||||
var buttons = group.CustomContainer<UniformGridPanel>();
|
||||
var gridControl = buttons.CustomControl;
|
||||
gridControl.ClipChildren = false;
|
||||
gridControl.Height = Button.DefaultHeight;
|
||||
gridControl.SlotsHorizontally = 2;
|
||||
gridControl.SlotsVertically = 1;
|
||||
var rebuildButton = buttons.Button("Rebuild", "Rebuilds the model SDF.").Button;
|
||||
rebuildButton.Clicked += OnRebuildSDF;
|
||||
var removeButton = buttons.Button("Remove", "Removes the model SDF data from the asset.").Button;
|
||||
removeButton.Enabled = sdf.Texture != null;
|
||||
removeButton.Clicked += OnRemoveSDF;
|
||||
}
|
||||
|
||||
// Group per LOD
|
||||
for (int lodIndex = 0; lodIndex < lods.Length; lodIndex++)
|
||||
{
|
||||
@@ -260,6 +283,22 @@ namespace FlaxEditor.Windows.Assets
|
||||
proxy.UpdateMaterialSlotsUI();
|
||||
}
|
||||
|
||||
private void OnRebuildSDF()
|
||||
{
|
||||
var proxy = (MeshesPropertiesProxy)Values[0];
|
||||
proxy.Asset.GenerateSDF(proxy.Window._importSettings.SDFResolution, _sdfModelLodIndex.Value);
|
||||
proxy.Window.MarkAsEdited();
|
||||
Presenter.BuildLayoutOnUpdate();
|
||||
}
|
||||
|
||||
private void OnRemoveSDF()
|
||||
{
|
||||
var proxy = (MeshesPropertiesProxy)Values[0];
|
||||
proxy.Asset.SetSDF(new ModelBase.SDFData());
|
||||
proxy.Window.MarkAsEdited();
|
||||
Presenter.BuildLayoutOnUpdate();
|
||||
}
|
||||
|
||||
internal override void RefreshInternal()
|
||||
{
|
||||
// Skip updates when model is not loaded
|
||||
@@ -645,14 +684,14 @@ namespace FlaxEditor.Windows.Assets
|
||||
[CustomEditor(typeof(ProxyEditor))]
|
||||
private sealed class ImportPropertiesProxy : PropertiesProxyBase
|
||||
{
|
||||
private ModelImportSettings ImportSettings = new ModelImportSettings();
|
||||
private ModelImportSettings ImportSettings;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnLoad(ModelWindow window)
|
||||
{
|
||||
base.OnLoad(window);
|
||||
|
||||
ModelImportSettings.TryRestore(ref ImportSettings, window.Item.Path);
|
||||
ImportSettings = window._importSettings;
|
||||
}
|
||||
|
||||
public void Reimport()
|
||||
@@ -675,7 +714,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
{
|
||||
var group = layout.Group("Import Settings");
|
||||
|
||||
var importSettingsField = typeof(ImportPropertiesProxy).GetField("ImportSettings", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var importSettingsField = typeof(ImportPropertiesProxy).GetField(nameof(ImportSettings), BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var importSettingsValues = new ValueContainer(new ScriptMemberInfo(importSettingsField)) { proxy.ImportSettings };
|
||||
group.Object(importSettingsValues);
|
||||
|
||||
@@ -730,6 +769,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
private readonly ModelPreview _preview;
|
||||
private StaticModel _highlightActor;
|
||||
private MeshDataCache _meshData;
|
||||
private ModelImportSettings _importSettings = new ModelImportSettings();
|
||||
|
||||
/// <inheritdoc />
|
||||
public ModelWindow(Editor editor, AssetItem item)
|
||||
@@ -868,6 +908,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
{
|
||||
_refreshOnLODsLoaded = true;
|
||||
_preview.ViewportCamera.SetArcBallView(Asset.GetBox());
|
||||
ModelImportSettings.TryRestore(ref _importSettings, Item.Path);
|
||||
UpdateEffectsOnAsset();
|
||||
|
||||
// TODO: disable streaming for this model
|
||||
|
||||
Reference in New Issue
Block a user