From 33d1c8c68c725498f39be52fa404887e684ee050 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 29 May 2024 14:54:28 +0200 Subject: [PATCH] Add async SDF generation for all meshes in the scene --- Source/Editor/Editor.cs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index d0076068e..2a768099d 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.InteropServices.Marshalling; +using System.Threading.Tasks; using FlaxEditor.Content; using FlaxEditor.Content.Settings; using FlaxEditor.Content.Thumbnails; @@ -1338,20 +1339,33 @@ namespace FlaxEditor /// public void BuildAllMeshesSDF() { - // TODO: async maybe with progress reporting? + var models = new List(); Scene.ExecuteOnGraph(node => { if (node is StaticModelNode staticModelNode && staticModelNode.Actor is StaticModel staticModel) { - if (staticModel.DrawModes.HasFlag(DrawPass.GlobalSDF) && staticModel.Model != null && !staticModel.Model.IsVirtual && staticModel.Model.SDF.Texture == null) + var model = staticModel.Model; + if (staticModel.DrawModes.HasFlag(DrawPass.GlobalSDF) && + model != null && + !models.Contains(model) && + !model.IsVirtual && + model.SDF.Texture == null) { - Log("Generating SDF for " + staticModel.Model); - if (!staticModel.Model.GenerateSDF()) - staticModel.Model.Save(); + models.Add(model); } } return true; }); + Task.Run(() => + { + for (int i = 0; i < models.Count; i++) + { + var model = models[i]; + Log($"[{i}/{models.Count}] Generating SDF for {model}"); + if (!model.GenerateSDF()) + model.Save(); + } + }); } #endregion