From 979168e82c5e6c6a5848117290c0325467a1aa98 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 12 Jun 2023 14:34:07 +0200 Subject: [PATCH] Refactor various Editor APIs to use auto-generated bindings instead of manual code --- .../Editor/Content/Import/ModelImportEntry.cs | 730 ++---------------- .../Content/Import/TextureImportEntry.cs | 599 +++----------- Source/Editor/Editor.cpp | 4 +- Source/Editor/Editor.cs | 53 -- .../Editor/Managed/ManagedEditor.Internal.cpp | 383 +-------- Source/Editor/Managed/ManagedEditor.cpp | 7 + Source/Editor/Managed/ManagedEditor.h | 66 +- .../Editor/Windows/Assets/AnimationWindow.cs | 2 +- .../Windows/Assets/CubeTextureWindow.cs | 4 +- Source/Editor/Windows/Assets/ModelWindow.cs | 11 +- .../Windows/Assets/SkinnedModelWindow.cs | 2 +- .../Windows/Assets/SpriteAtlasWindow.cs | 8 +- Source/Editor/Windows/Assets/TextureWindow.cs | 4 +- .../Engine/ContentImporters/ImportAudio.cpp | 5 +- Source/Engine/ContentImporters/ImportAudio.h | 2 +- Source/Engine/ContentImporters/ImportModel.h | 2 +- .../ContentImporters/ImportModelFile.cpp | 7 +- .../Engine/ContentImporters/ImportTexture.cpp | 11 +- Source/Engine/Graphics/Models/Types.h | 10 +- Source/Engine/Graphics/Textures/Types.h | 20 +- .../Tools/ModelTool/ModelTool.Options.cpp | 119 --- Source/Engine/Tools/ModelTool/ModelTool.cpp | 111 +++ Source/Engine/Tools/ModelTool/ModelTool.h | 175 ++++- .../Engine/Tools/TextureTool/TextureTool.cpp | 23 +- Source/Engine/Tools/TextureTool/TextureTool.h | 149 ++-- .../Bindings/BindingsGenerator.CSharp.cs | 3 +- 26 files changed, 611 insertions(+), 1899 deletions(-) delete mode 100644 Source/Engine/Tools/ModelTool/ModelTool.Options.cpp diff --git a/Source/Editor/Content/Import/ModelImportEntry.cs b/Source/Editor/Content/Import/ModelImportEntry.cs index f2bde04a8..bbb384562 100644 --- a/Source/Editor/Content/Import/ModelImportEntry.cs +++ b/Source/Editor/Content/Import/ModelImportEntry.cs @@ -1,90 +1,47 @@ // Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. -using System; -using System.ComponentModel; -using System.Runtime.InteropServices; -using System.Runtime.InteropServices.Marshalling; +using System.Collections.Generic; +using FlaxEditor.CustomEditors.Editors; +using FlaxEditor.Scripting; using FlaxEngine; -using FlaxEngine.Interop; +using FlaxEngine.Tools; + +namespace FlaxEngine.Tools +{ + partial class ModelTool + { + partial struct Options + { + private bool ShowGeometry => Type == ModelTool.ModelType.Model || Type == ModelTool.ModelType.SkinnedModel; + private bool ShowModel => Type == ModelTool.ModelType.Model; + private bool ShowSkinnedModel => Type == ModelTool.ModelType.SkinnedModel; + private bool ShowAnimation => Type == ModelTool.ModelType.Animation; + private bool ShowSmoothingNormalsAngle => ShowGeometry && CalculateNormals; + private bool ShowSmoothingTangentsAngle => ShowGeometry && CalculateTangents; + private bool ShowFramesRange => ShowAnimation && Duration == ModelTool.AnimationDuration.Custom; + } + } +} + +namespace FlaxEditor.CustomEditors.Dedicated +{ + /// + /// Custom editor for . + /// + [CustomEditor(typeof(FlaxEngine.Tools.ModelTool.Options)), DefaultEditor] + public class ModelToolOptionsEditor : GenericEditor + { + /// + protected override List GetItemsForType(ScriptType type) + { + // Show both fields and properties + return GetItemsForType(type, true, true); + } + } +} namespace FlaxEditor.Content.Import { - /// - /// Importing model lightmap UVs source - /// - [HideInEditor] - public enum ModelLightmapUVsSource : int - { - /// - /// No lightmap UVs. - /// - Disable = 0, - - /// - /// Generate lightmap UVs from model geometry. - /// - Generate = 1, - - /// - /// The texcoords channel 0. - /// - Channel0 = 2, - - /// - /// The texcoords channel 1. - /// - Channel1 = 3, - - /// - /// The texcoords channel 2. - /// - Channel2 = 4, - - /// - /// The texcoords channel 3. - /// - Channel3 = 5 - } - - /// - /// Declares the imported data type. - /// - [HideInEditor] - public enum ModelType : int - { - /// - /// The model asset. - /// - Model = 0, - - /// - /// The skinned model asset. - /// - SkinnedModel = 1, - - /// - /// The animation asset. - /// - Animation = 2, - } - - /// - /// Declares the imported animation clip duration. - /// - [HideInEditor] - public enum AnimationDuration : int - { - /// - /// The imported duration. - /// - Imported = 0, - - /// - /// The custom duration specified via keyframes range. - /// - Custom = 1, - } - /// /// Proxy object to present model import settings in . /// @@ -92,600 +49,19 @@ namespace FlaxEditor.Content.Import public class ModelImportSettings { /// - /// Type of the imported asset. + /// The settings data. /// - [EditorOrder(0)] - public ModelType Type { get; set; } = ModelType.Model; - - /// - /// Enable model normal vectors recalculating. - /// - [EditorDisplay("Geometry"), VisibleIf(nameof(ShowGeometry))] - [EditorOrder(20), DefaultValue(false)] - public bool CalculateNormals { get; set; } = false; - - /// - /// Specifies the maximum angle (in degrees) that may be between two face normals at the same vertex position that their are smoothed together. The default value is 175. - /// - [EditorDisplay("Geometry"), VisibleIf(nameof(ShowSmoothingNormalsAngle))] - [EditorOrder(30), DefaultValue(175.0f), Limit(0, 175, 0.1f)] - public float SmoothingNormalsAngle { get; set; } = 175.0f; - - private bool ShowSmoothingNormalsAngle => ShowGeometry && CalculateNormals; - - /// - /// If checked, the imported normal vectors of the mesh will be flipped (scaled by -1). - /// - [EditorDisplay("Geometry"), VisibleIf(nameof(ShowGeometry))] - [EditorOrder(35), DefaultValue(false)] - public bool FlipNormals { get; set; } = false; - - /// - /// Enable model tangent vectors recalculating. - /// - [EditorDisplay("Geometry"), VisibleIf(nameof(ShowGeometry))] - [EditorOrder(40), DefaultValue(false)] - public bool CalculateTangents { get; set; } = false; - - /// - /// Specifies the maximum angle (in degrees) that may be between two vertex tangents that their tangents and bi-tangents are smoothed. The default value is 45. - /// - [EditorDisplay("Geometry"), VisibleIf(nameof(ShowSmoothingTangentsAngle))] - [EditorOrder(45), DefaultValue(45.0f), Limit(0, 45, 0.1f)] - public float SmoothingTangentsAngle { get; set; } = 45.0f; - - private bool ShowSmoothingTangentsAngle => ShowGeometry && CalculateTangents; - - /// - /// Enable/disable meshes geometry optimization. - /// - [EditorDisplay("Geometry"), VisibleIf(nameof(ShowGeometry))] - [EditorOrder(50), DefaultValue(true)] - public bool OptimizeMeshes { get; set; } = true; - - /// - /// Enable/disable geometry merge for meshes with the same materials. - /// - [EditorDisplay("Geometry"), VisibleIf(nameof(ShowGeometry))] - [EditorOrder(60), DefaultValue(true)] - public bool MergeMeshes { get; set; } = true; - - /// - /// Enable/disable importing meshes Level of Details. - /// - [EditorDisplay("Geometry", "Import LODs"), VisibleIf(nameof(ShowGeometry))] - [EditorOrder(70), DefaultValue(true)] - public bool ImportLODs { get; set; } = true; - - /// - /// Enable/disable importing vertex colors (channel 0 only). - /// - [EditorDisplay("Geometry"), VisibleIf(nameof(ShowModel))] - [EditorOrder(80), DefaultValue(true)] - public bool ImportVertexColors { get; set; } = true; - - /// - /// Enable/disable importing blend shapes (morph targets). - /// - [EditorDisplay("Geometry"), VisibleIf(nameof(ShowSkinnedModel))] - [EditorOrder(85), DefaultValue(false)] - public bool ImportBlendShapes { get; set; } = false; - - /// - /// The lightmap UVs source. - /// - [EditorDisplay("Geometry", "Lightmap UVs Source"), VisibleIf(nameof(ShowModel))] - [EditorOrder(90), DefaultValue(ModelLightmapUVsSource.Disable)] - public ModelLightmapUVsSource LightmapUVsSource { get; set; } = ModelLightmapUVsSource.Disable; - - /// - /// If specified, all meshes which name starts with this prefix will be imported as a separate collision data (excluded used for rendering). - /// - [EditorDisplay("Geometry"), VisibleIf(nameof(ShowGeometry))] - [EditorOrder(100), DefaultValue("")] - public string CollisionMeshesPrefix { get; set; } - - /// - /// Custom uniform import scale. - /// - [EditorOrder(500), DefaultValue(1.0f), EditorDisplay("Transform")] - public float Scale { get; set; } = 1.0f; - - /// - /// Custom import geometry rotation. - /// - [DefaultValue(typeof(Quaternion), "0,0,0,1")] - [EditorOrder(510), EditorDisplay("Transform")] - public Quaternion Rotation { get; set; } = Quaternion.Identity; - - /// - /// Custom import geometry offset. - /// - [DefaultValue(typeof(Float3), "0,0,0")] - [EditorOrder(520), EditorDisplay("Transform")] - public Float3 Translation { get; set; } = Float3.Zero; - - /// - /// If checked, the imported geometry will be shifted to the center of mass. - /// - [EditorOrder(530), DefaultValue(false), EditorDisplay("Transform")] - public bool CenterGeometry { get; set; } = false; - - /// - /// Imported animation duration mode. Can use the original value or overriden by settings. - /// - [EditorDisplay("Animation"), VisibleIf(nameof(ShowAnimation))] - [EditorOrder(1000), DefaultValue(AnimationDuration.Imported)] - public AnimationDuration Duration { get; set; } = AnimationDuration.Imported; - - /// - /// Imported animation first frame index. Used only if Duration mode is set to Custom. - /// - [EditorDisplay("Animation"), VisibleIf(nameof(ShowFramesRange))] - [EditorOrder(1010), DefaultValue(0.0f), Limit(0)] - public float FramesRangeStart { get; set; } = 0; - - /// - /// Imported animation last frame index. Used only if Duration mode is set to Custom. - /// - [EditorDisplay("Animation"), VisibleIf(nameof(ShowFramesRange))] - [EditorOrder(1020), DefaultValue(0.0f), Limit(0)] - public float FramesRangeEnd { get; set; } = 0; - - private bool ShowFramesRange => ShowAnimation && Duration == AnimationDuration.Custom; - - /// - /// The imported animation default frame rate. Can specify the default frames per second amount for imported animation. If value is 0 then the original animation frame rate will be used. - /// - [EditorDisplay("Animation"), VisibleIf(nameof(ShowAnimation))] - [EditorOrder(1025), DefaultValue(0.0f), Limit(0, 1000, 0.01f)] - public float DefaultFrameRate { get; set; } = 0.0f; - - /// - /// The imported animation sampling rate. If value is 0 then the original animation speed will be used. - /// - [EditorDisplay("Animation"), VisibleIf(nameof(ShowAnimation))] - [EditorOrder(1030), DefaultValue(0.0f), Limit(0, 1000, 0.01f)] - public float SamplingRate { get; set; } = 0.0f; - - /// - /// The imported animation will have removed tracks with no keyframes or unspecified data. - /// - [EditorDisplay("Animation"), VisibleIf(nameof(ShowAnimation))] - [EditorOrder(1040), DefaultValue(true)] - public bool SkipEmptyCurves { get; set; } = true; - - /// - /// The imported animation channels will be optimized to remove redundant keyframes. - /// - [EditorDisplay("Animation"), VisibleIf(nameof(ShowAnimation))] - [EditorOrder(1050), DefaultValue(true)] - public bool OptimizeKeyframes { get; set; } = true; - - /// - /// If checked, the importer will import scale animation tracks (otherwise scale animation will be ignored). - /// - [EditorDisplay("Animation"), VisibleIf(nameof(ShowAnimation))] - [EditorOrder(1055), DefaultValue(false)] - public bool ImportScaleTracks { get; set; } = false; - - /// - /// Enables root motion extraction support from this animation. - /// - [EditorDisplay("Animation"), VisibleIf(nameof(ShowAnimation))] - [EditorOrder(1060), DefaultValue(false)] - public bool EnableRootMotion { get; set; } = false; - - /// - /// The custom node name to be used as a root motion source. If not specified the actual root node will be used. - /// - [EditorDisplay("Animation"), VisibleIf(nameof(ShowAnimation))] - [EditorOrder(1070), DefaultValue(typeof(string), "")] - public string RootNodeName { get; set; } - - /// - /// If checked, the importer will generate a sequence of LODs based on the base LOD index. - /// - [EditorDisplay("Level Of Detail", "Generate LODs"), VisibleIf(nameof(ShowGeometry))] - [EditorOrder(1100), DefaultValue(false)] - public bool GenerateLODs { get; set; } = false; - - /// - /// The index of the LOD from the source model data to use as a reference for following LODs generation. - /// - [EditorDisplay("Level Of Detail", "Base LOD"), VisibleIf(nameof(ShowGeometry))] - [EditorOrder(1110), DefaultValue(0), Limit(0, Model.MaxLODs - 1)] - public int BaseLOD { get; set; } = 0; - - /// - /// The amount of LODs to include in the model (all remaining ones starting from Base LOD will be generated). - /// - [EditorDisplay("Level Of Detail", "LOD Count"), VisibleIf(nameof(ShowGeometry))] - [EditorOrder(1120), DefaultValue(4), Limit(1, Model.MaxLODs)] - public int LODCount { get; set; } = 4; - - /// - /// The target amount of triangles for the generated LOD (based on the higher LOD). Normalized to range 0-1. For instance 0.4 cuts the triangle count to 40%. - /// - [EditorDisplay("Level Of Detail"), VisibleIf(nameof(ShowGeometry))] - [EditorOrder(1130), DefaultValue(0.5f), Limit(0, 1, 0.001f)] - public float TriangleReduction { get; set; } = 0.5f; - - /// - /// If checked, the importer will create materials for model meshes as specified in the file. - /// - [EditorDisplay("Materials"), VisibleIf(nameof(ShowGeometry))] - [EditorOrder(400), DefaultValue(true)] - public bool ImportMaterials { get; set; } = true; - - /// - /// If checked, the importer will import texture files used by the model and any embedded texture resources. - /// - [EditorDisplay("Materials"), VisibleIf(nameof(ShowGeometry))] - [EditorOrder(410), DefaultValue(true)] - public bool ImportTextures { get; set; } = true; - - /// - /// If checked, the importer will try to restore the model material slots. - /// - [EditorDisplay("Materials", "Restore Materials On Reimport"), VisibleIf(nameof(ShowGeometry))] - [EditorOrder(420), DefaultValue(true)] - public bool RestoreMaterialsOnReimport { get; set; } = true; - - /// - /// If checked, enables generation of Signed Distance Field (SDF). - /// - [EditorDisplay("SDF"), VisibleIf(nameof(ShowModel))] - [EditorOrder(1500), DefaultValue(false)] - public bool GenerateSDF { get; set; } = false; - - /// - /// Resolution scale for generated Signed Distance Field (SDF) texture. Higher values improve accuracy but increase memory usage and reduce performance. - /// - [EditorDisplay("SDF"), VisibleIf(nameof(ShowModel))] - [EditorOrder(1510), DefaultValue(1.0f), Limit(0.0001f, 100.0f)] - public float SDFResolution { get; set; } = 1.0f; - - /// - /// If checked, the imported mesh/animations are splitted into separate assets. Used if ObjectIndex is set to -1. - /// - [EditorOrder(2000), DefaultValue(false), EditorDisplay("Splitting")] - public bool SplitObjects { get; set; } = false; - - /// - /// The zero-based index for the mesh/animation clip to import. If the source file has more than one mesh/animation it can be used to pick a desire object. Default -1 imports all objects. - /// - [EditorOrder(2010), DefaultValue(-1), EditorDisplay("Splitting")] - public int ObjectIndex { get; set; } = -1; - - private bool ShowGeometry => Type == ModelType.Model || Type == ModelType.SkinnedModel; - private bool ShowModel => Type == ModelType.Model; - private bool ShowSkinnedModel => Type == ModelType.SkinnedModel; - private bool ShowAnimation => Type == ModelType.Animation; - - [StructLayout(LayoutKind.Sequential)] - [NativeMarshalling(typeof(InternalOptionsMarshaller))] - internal struct InternalOptions - { - public ModelType Type; - - // Geometry - public byte CalculateNormals; - public float SmoothingNormalsAngle; - public byte FlipNormals; - public float SmoothingTangentsAngle; - public byte CalculateTangents; - public byte OptimizeMeshes; - public byte MergeMeshes; - public byte ImportLODs; - public byte ImportVertexColors; - public byte ImportBlendShapes; - public ModelLightmapUVsSource LightmapUVsSource; - public string CollisionMeshesPrefix; - - // Transform - public float Scale; - public Quaternion Rotation; - public Float3 Translation; - public byte CenterGeometry; - - // Animation - public AnimationDuration Duration; - public float FramesRangeStart; - public float FramesRangeEnd; - public float DefaultFrameRate; - public float SamplingRate; - public byte SkipEmptyCurves; - public byte OptimizeKeyframes; - public byte ImportScaleTracks; - public byte EnableRootMotion; - public string RootNodeName; - - // Level Of Detail - public byte GenerateLODs; - public int BaseLOD; - public int LODCount; - public float TriangleReduction; - - // Misc - public byte ImportMaterials; - public byte ImportTextures; - public byte RestoreMaterialsOnReimport; - - // SDF - public byte GenerateSDF; - public float SDFResolution; - - // Splitting - public byte SplitObjects; - public int ObjectIndex; - } - - [CustomMarshaller(typeof(InternalOptions), MarshalMode.Default, typeof(InternalOptionsMarshaller))] - internal static class InternalOptionsMarshaller - { - [Unmanaged] - [StructLayout(LayoutKind.Sequential)] - internal struct InternalOptionsNative - { - public int Type; - - // Geometry - public byte CalculateNormals; - public float SmoothingNormalsAngle; - public byte FlipNormals; - public float SmoothingTangentsAngle; - public byte CalculateTangents; - public byte OptimizeMeshes; - public byte MergeMeshes; - public byte ImportLODs; - public byte ImportVertexColors; - public byte ImportBlendShapes; - public int LightmapUVsSource; - public IntPtr CollisionMeshesPrefix; - - // Transform - public float Scale; - public Quaternion Rotation; - public Float3 Translation; - public byte CenterGeometry; - - // Animation - public int Duration; - public float FramesRangeStart; - public float FramesRangeEnd; - public float DefaultFrameRate; - public float SamplingRate; - public byte SkipEmptyCurves; - public byte OptimizeKeyframes; - public byte ImportScaleTracks; - public byte EnableRootMotion; - public IntPtr RootNodeName; - - // Level Of Detail - public byte GenerateLODs; - public int BaseLOD; - public int LODCount; - public float TriangleReduction; - - // Misc - public byte ImportMaterials; - public byte ImportTextures; - public byte RestoreMaterialsOnReimport; - - // SDF - public byte GenerateSDF; - public float SDFResolution; - - // Splitting - public byte SplitObjects; - public int ObjectIndex; - } - - internal static InternalOptions ConvertToManaged(InternalOptionsNative unmanaged) => ToManaged(unmanaged); - internal static InternalOptionsNative ConvertToUnmanaged(InternalOptions managed) => ToNative(managed); - - internal static InternalOptions ToManaged(InternalOptionsNative managed) - { - return new InternalOptions() - { - Type = (ModelType)managed.Type, - CalculateNormals = managed.CalculateNormals, - SmoothingNormalsAngle = managed.SmoothingNormalsAngle, - FlipNormals = managed.FlipNormals, - SmoothingTangentsAngle = managed.SmoothingTangentsAngle, - CalculateTangents = managed.CalculateTangents, - OptimizeMeshes = managed.OptimizeMeshes, - MergeMeshes = managed.MergeMeshes, - ImportLODs = managed.ImportLODs, - ImportVertexColors = managed.ImportVertexColors, - ImportBlendShapes = managed.ImportBlendShapes, - LightmapUVsSource = (ModelLightmapUVsSource)managed.LightmapUVsSource, - CollisionMeshesPrefix = ManagedString.ToManaged(managed.CollisionMeshesPrefix), - Scale = managed.Scale, - Rotation = managed.Rotation, - Translation = managed.Translation, - CenterGeometry = managed.CenterGeometry, - Duration = (AnimationDuration)managed.Duration, - FramesRangeStart = managed.FramesRangeStart, - FramesRangeEnd = managed.FramesRangeEnd, - DefaultFrameRate = managed.DefaultFrameRate, - SamplingRate = managed.SamplingRate, - SkipEmptyCurves = managed.SkipEmptyCurves, - OptimizeKeyframes = managed.OptimizeKeyframes, - ImportScaleTracks = managed.ImportScaleTracks, - EnableRootMotion = managed.EnableRootMotion, - RootNodeName = ManagedString.ToManaged(managed.RootNodeName), - GenerateLODs = managed.GenerateLODs, - BaseLOD = managed.BaseLOD, - LODCount = managed.LODCount, - TriangleReduction = managed.TriangleReduction, - ImportMaterials = managed.ImportMaterials, - ImportTextures = managed.ImportTextures, - RestoreMaterialsOnReimport = managed.RestoreMaterialsOnReimport, - GenerateSDF = managed.GenerateSDF, - SDFResolution = managed.SDFResolution, - SplitObjects = managed.SplitObjects, - ObjectIndex = managed.ObjectIndex, - }; - } - internal static InternalOptionsNative ToNative(InternalOptions managed) - { - return new InternalOptionsNative() - { - Type = (int)managed.Type, - CalculateNormals = managed.CalculateNormals, - SmoothingNormalsAngle = managed.SmoothingNormalsAngle, - FlipNormals = managed.FlipNormals, - SmoothingTangentsAngle = managed.SmoothingTangentsAngle, - CalculateTangents = managed.CalculateTangents, - OptimizeMeshes = managed.OptimizeMeshes, - MergeMeshes = managed.MergeMeshes, - ImportLODs = managed.ImportLODs, - ImportVertexColors = managed.ImportVertexColors, - ImportBlendShapes = managed.ImportBlendShapes, - LightmapUVsSource = (int)managed.LightmapUVsSource, - CollisionMeshesPrefix = ManagedString.ToNative(managed.CollisionMeshesPrefix), - Scale = managed.Scale, - Rotation = managed.Rotation, - Translation = managed.Translation, - CenterGeometry = managed.CenterGeometry, - Duration = (int)managed.Duration, - FramesRangeStart = managed.FramesRangeStart, - FramesRangeEnd = managed.FramesRangeEnd, - DefaultFrameRate = managed.DefaultFrameRate, - SamplingRate = managed.SamplingRate, - SkipEmptyCurves = managed.SkipEmptyCurves, - OptimizeKeyframes = managed.OptimizeKeyframes, - ImportScaleTracks = managed.ImportScaleTracks, - EnableRootMotion = managed.EnableRootMotion, - RootNodeName = ManagedString.ToNative(managed.RootNodeName), - GenerateLODs = managed.GenerateLODs, - BaseLOD = managed.BaseLOD, - LODCount = managed.LODCount, - TriangleReduction = managed.TriangleReduction, - ImportMaterials = managed.ImportMaterials, - ImportTextures = managed.ImportTextures, - RestoreMaterialsOnReimport = managed.RestoreMaterialsOnReimport, - GenerateSDF = managed.GenerateSDF, - SDFResolution = managed.SDFResolution, - SplitObjects = managed.SplitObjects, - ObjectIndex = managed.ObjectIndex, - }; - } - internal static void Free(InternalOptionsNative unmanaged) - { - ManagedString.Free(unmanaged.CollisionMeshesPrefix); - ManagedString.Free(unmanaged.RootNodeName); - } - } - - internal void ToInternal(out InternalOptions options) - { - options = new InternalOptions - { - Type = Type, - CalculateNormals = (byte)(CalculateNormals ? 1 : 0), - SmoothingNormalsAngle = SmoothingNormalsAngle, - FlipNormals = (byte)(FlipNormals ? 1 : 0), - SmoothingTangentsAngle = SmoothingTangentsAngle, - CalculateTangents = (byte)(CalculateTangents ? 1 : 0), - OptimizeMeshes = (byte)(OptimizeMeshes ? 1 : 0), - MergeMeshes = (byte)(MergeMeshes ? 1 : 0), - ImportLODs = (byte)(ImportLODs ? 1 : 0), - ImportVertexColors = (byte)(ImportVertexColors ? 1 : 0), - ImportBlendShapes = (byte)(ImportBlendShapes ? 1 : 0), - LightmapUVsSource = LightmapUVsSource, - CollisionMeshesPrefix = CollisionMeshesPrefix, - Scale = Scale, - Rotation = Rotation, - Translation = Translation, - CenterGeometry = (byte)(CenterGeometry ? 1 : 0), - Duration = Duration, - FramesRangeStart = FramesRangeStart, - FramesRangeEnd = FramesRangeEnd, - DefaultFrameRate = DefaultFrameRate, - SamplingRate = SamplingRate, - SkipEmptyCurves = (byte)(SkipEmptyCurves ? 1 : 0), - OptimizeKeyframes = (byte)(OptimizeKeyframes ? 1 : 0), - ImportScaleTracks = (byte)(ImportScaleTracks ? 1 : 0), - EnableRootMotion = (byte)(EnableRootMotion ? 1 : 0), - RootNodeName = RootNodeName, - GenerateLODs = (byte)(GenerateLODs ? 1 : 0), - BaseLOD = BaseLOD, - LODCount = LODCount, - TriangleReduction = TriangleReduction, - ImportMaterials = (byte)(ImportMaterials ? 1 : 0), - ImportTextures = (byte)(ImportTextures ? 1 : 0), - RestoreMaterialsOnReimport = (byte)(RestoreMaterialsOnReimport ? 1 : 0), - GenerateSDF = (byte)(GenerateSDF ? 1 : 0), - SDFResolution = SDFResolution, - SplitObjects = (byte)(SplitObjects ? 1 : 0), - ObjectIndex = ObjectIndex, - }; - } - - internal void FromInternal(ref InternalOptions options) - { - Type = options.Type; - CalculateNormals = options.CalculateNormals != 0; - SmoothingNormalsAngle = options.SmoothingNormalsAngle; - FlipNormals = options.FlipNormals != 0; - SmoothingTangentsAngle = options.SmoothingTangentsAngle; - CalculateTangents = options.CalculateTangents != 0; - OptimizeMeshes = options.OptimizeMeshes != 0; - MergeMeshes = options.MergeMeshes != 0; - ImportLODs = options.ImportLODs != 0; - ImportVertexColors = options.ImportVertexColors != 0; - ImportBlendShapes = options.ImportBlendShapes != 0; - LightmapUVsSource = options.LightmapUVsSource; - CollisionMeshesPrefix = options.CollisionMeshesPrefix; - Scale = options.Scale; - Rotation = options.Rotation; - Translation = options.Translation; - CenterGeometry = options.CenterGeometry != 0; - FramesRangeStart = options.FramesRangeStart; - FramesRangeEnd = options.FramesRangeEnd; - DefaultFrameRate = options.DefaultFrameRate; - SamplingRate = options.SamplingRate; - SkipEmptyCurves = options.SkipEmptyCurves != 0; - OptimizeKeyframes = options.OptimizeKeyframes != 0; - ImportScaleTracks = options.ImportScaleTracks != 0; - EnableRootMotion = options.EnableRootMotion != 0; - RootNodeName = options.RootNodeName; - GenerateLODs = options.GenerateLODs != 0; - BaseLOD = options.BaseLOD; - LODCount = options.LODCount; - TriangleReduction = options.TriangleReduction; - ImportMaterials = options.ImportMaterials != 0; - ImportTextures = options.ImportTextures != 0; - RestoreMaterialsOnReimport = options.RestoreMaterialsOnReimport != 0; - GenerateSDF = options.GenerateSDF != 0; - SDFResolution = options.SDFResolution; - SplitObjects = options.SplitObjects != 0; - ObjectIndex = options.ObjectIndex; - } - - /// - /// Tries the restore the asset import options from the target resource file. Applies the project default options too. - /// - /// The options. - /// The asset path. - /// True settings has been restored, otherwise false. - public static void TryRestore(ref ModelImportSettings options, string assetPath) - { - ModelImportEntry.Internal_GetModelImportOptions(assetPath, out var internalOptions); - options.FromInternal(ref internalOptions); - } + [EditorDisplay(null, EditorDisplayAttribute.InlineStyle)] + public ModelTool.Options Settings = ModelTool.Options.Default; } /// /// Model asset import entry. /// /// - public partial class ModelImportEntry : AssetImportEntry + public class ModelImportEntry : AssetImportEntry { - private ModelImportSettings _settings = new ModelImportSettings(); + private ModelImportSettings _settings = new(); /// /// Initializes a new instance of the class. @@ -695,7 +71,7 @@ namespace FlaxEditor.Content.Import : base(ref request) { // Try to restore target asset model import options (useful for fast reimport) - ModelImportSettings.TryRestore(ref _settings, ResultUrl); + Editor.TryRestoreImportOptions(ref _settings.Settings, ResultUrl); } /// @@ -704,9 +80,14 @@ namespace FlaxEditor.Content.Import /// public override bool TryOverrideSettings(object settings) { - if (settings is ModelImportSettings o) + if (settings is ModelImportSettings s) { - _settings = o; + _settings.Settings = s.Settings; + return true; + } + if (settings is ModelTool.Options o) + { + _settings.Settings = o; return true; } return false; @@ -715,14 +96,7 @@ namespace FlaxEditor.Content.Import /// public override bool Import() { - return Editor.Import(SourceUrl, ResultUrl, _settings); + return Editor.Import(SourceUrl, ResultUrl, _settings.Settings); } - - #region Internal Calls - - [LibraryImport("FlaxEngine", EntryPoint = "ModelImportEntryInternal_GetModelImportOptions", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(StringMarshaller))] - internal static partial void Internal_GetModelImportOptions(string path, out ModelImportSettings.InternalOptions result); - - #endregion } } diff --git a/Source/Editor/Content/Import/TextureImportEntry.cs b/Source/Editor/Content/Import/TextureImportEntry.cs index ce9a94510..00cd56d24 100644 --- a/Source/Editor/Content/Import/TextureImportEntry.cs +++ b/Source/Editor/Content/Import/TextureImportEntry.cs @@ -1,60 +1,96 @@ // Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. -using System; using System.Collections.Generic; using System.ComponentModel; using System.Reflection; -using System.Runtime.InteropServices; -using System.Runtime.InteropServices.Marshalling; +using FlaxEditor.CustomEditors.Editors; +using FlaxEditor.Scripting; using FlaxEngine; -using FlaxEngine.Interop; +using FlaxEngine.Tools; -// ReSharper disable InconsistentNaming +namespace FlaxEngine.Tools +{ + partial class TextureTool + { + partial struct Options + { +#pragma warning disable CS1591 + public enum CustomMaxSizes + { + _32 = 32, + _64 = 64, + _128 = 128, + _256 = 256, + _512 = 512, + _1024 = 1024, + _2048 = 2048, + _4096 = 4096, + _8192 = 8192, + _16384 = 16384, + } +#pragma warning restore CS1591 + + /// + /// The size of the imported texture. If Resize property is set to true then texture will be resized during the import to this value. Otherwise it will be ignored. + /// + [EditorOrder(110), VisibleIf(nameof(Resize)), DefaultValue(typeof(Int2), "1024,1024")] + public Int2 Size + { + get => new Int2(SizeX, SizeY); + set + { + SizeX = value.X; + SizeY = value.Y; + } + } + + /// + /// Maximum size of the texture (for both width and height). Higher resolution textures will be resized during importing process. + /// + [EditorOrder(90), DefaultValue(CustomMaxSizes._8192), EditorDisplay(null, "Max Size")] + public CustomMaxSizes CustomMaxSize + { + get + { + var value = MaxSize; + if (!Mathf.IsPowerOfTwo(value)) + value = Mathf.NextPowerOfTwo(value); + FieldInfo[] fields = typeof(CustomMaxSizes).GetFields(); + for (int i = 0; i < fields.Length; i++) + { + var field = fields[i]; + if (field.Name.Equals("value__")) + continue; + if (value == (int)field.GetRawConstantValue()) + return (CustomMaxSizes)value; + } + return CustomMaxSizes._8192; + } + set => MaxSize = (int)value; + } + } + } +} + +namespace FlaxEditor.CustomEditors.Dedicated +{ + /// + /// Custom editor for . + /// + [CustomEditor(typeof(FlaxEngine.Tools.TextureTool.Options)), DefaultEditor] + public class TextureToolOptionsEditor : GenericEditor + { + /// + protected override List GetItemsForType(ScriptType type) + { + // Show both fields and properties + return GetItemsForType(type, true, true); + } + } +} namespace FlaxEditor.Content.Import { - /// - /// Texture format types. - /// - [HideInEditor] - public enum TextureFormatType : byte - { - /// - /// The unknown. - /// - Unknown = 0, - - /// - /// The color with RGB channels. - /// - ColorRGB = 1, - - /// - /// The color with RGBA channels. - /// - ColorRGBA = 2, - - /// - /// The normal map (packed and compressed). - /// - NormalMap = 3, - - /// - /// The gray scale (R channel). - /// - GrayScale = 4, - - /// - /// The HDR color (RGBA channels). - /// - HdrRGBA = 5, - - /// - /// The HDR color (RGB channels). - /// - HdrRGB = 6 - } - /// /// Proxy object to present texture import settings in . /// @@ -62,435 +98,19 @@ namespace FlaxEditor.Content.Import public class TextureImportSettings { /// - /// A custom version of for GUI. + /// The settings data. /// - public enum CustomTextureFormatType - { - /// - /// The color with RGB channels. - /// - ColorRGB = 1, - - /// - /// The color with RGBA channels. - /// - ColorRGBA = 2, - - /// - /// The normal map (packed and compressed). - /// - NormalMap = 3, - - /// - /// The gray scale (R channel). - /// - GrayScale = 4, - - /// - /// The HDR color (RGBA channels). - /// - HdrRGBA = 5, - - /// - /// The HDR color (RGB channels). - /// - HdrRGB = 6 - } - - /// - /// A custom set of max texture import sizes. - /// - public enum CustomMaxSizeType - { - /// - /// The 32. - /// - _32 = 32, - - /// - /// The 64. - /// - _64 = 64, - - /// - /// The 128. - /// - _128 = 128, - - /// - /// The 256. - /// - _256 = 256, - - /// - /// The 512. - /// - _512 = 512, - - /// - /// The 1024. - /// - _1024 = 1024, - - /// - /// The 2048. - /// - _2048 = 2048, - - /// - /// The 4096. - /// - _4096 = 4096, - - /// - /// The 8192. - /// - _8192 = 8192, - } - - /// - /// Converts the maximum size to enum. - /// - /// The max size. - /// The converted enum. - public static CustomMaxSizeType ConvertMaxSize(int f) - { - if (!Mathf.IsPowerOfTwo(f)) - f = Mathf.NextPowerOfTwo(f); - - FieldInfo[] fields = typeof(CustomMaxSizeType).GetFields(); - for (int i = 0; i < fields.Length; i++) - { - var field = fields[i]; - if (field.Name.Equals("value__")) - continue; - - if (f == (int)field.GetRawConstantValue()) - return (CustomMaxSizeType)f; - } - - return CustomMaxSizeType._8192; - } - - /// - /// The sprite info. - /// - [StructLayout(LayoutKind.Sequential)] - public struct SpriteInfo - { - /// - /// The sprite area. - /// - public Rectangle Area; - - /// - /// The sprite name. - /// - public string Name; - - /// - /// Initializes a new instance of the struct. - /// - /// The area. - /// The name. - public SpriteInfo(Rectangle area, string name) - { - Area = area; - Name = name; - } - } - - /// - /// Texture format type - /// - [EditorOrder(0), DefaultValue(CustomTextureFormatType.ColorRGB), Tooltip("Texture import format type")] - public CustomTextureFormatType Type { get; set; } = CustomTextureFormatType.ColorRGB; - - /// - /// True if texture should be imported as a texture atlas resource - /// - [EditorOrder(10), DefaultValue(false), Tooltip("True if texture should be imported as a texture atlas (with sprites)")] - public bool IsAtlas { get; set; } - - /// - /// True if disable dynamic texture streaming - /// - [EditorOrder(20), DefaultValue(false), Tooltip("True if disable dynamic texture streaming")] - public bool NeverStream { get; set; } - - /// - /// Enables/disables texture data compression. - /// - [EditorOrder(30), DefaultValue(true), Tooltip("True if compress texture data")] - public bool Compress { get; set; } = true; - - /// - /// True if texture channels have independent data - /// - [EditorOrder(40), DefaultValue(false), Tooltip("True if texture channels have independent data (for compression methods)")] - public bool IndependentChannels { get; set; } - - /// - /// True if use sRGB format for texture data. Recommended for color maps and diffuse color textures. - /// - [EditorOrder(50), DefaultValue(false), EditorDisplay(null, "sRGB"), Tooltip("True if use sRGB format for texture data. Recommended for color maps and diffuse color textures.")] - public bool sRGB { get; set; } - - /// - /// True if generate mip maps chain for the texture. - /// - [EditorOrder(60), DefaultValue(true), Tooltip("True if generate mip maps chain for the texture")] - public bool GenerateMipMaps { get; set; } = true; - - /// - /// True if flip Y coordinate of the texture. - /// - [EditorOrder(65), DefaultValue(false), EditorDisplay(null, "Flip Y"), Tooltip("True if flip Y coordinate of the texture.")] - public bool FlipY { get; set; } = false; - - /// - /// The import texture scale. - /// - [EditorOrder(70), DefaultValue(1.0f), Tooltip("Texture scale. Default is 1.")] - public float Scale { get; set; } = 1.0f; - - /// - /// Maximum size of the texture (for both width and height). - /// Higher resolution textures will be resized during importing process. - /// - [EditorOrder(80), DefaultValue(CustomMaxSizeType._8192), Tooltip("Maximum texture size (will be resized if need to)")] - public CustomMaxSizeType MaxSize { get; set; } = CustomMaxSizeType._8192; - - /// - /// True if resize texture on import. Use Size property to define texture width and height. Texture scale property will be ignored. - /// - [EditorOrder(90), DefaultValue(false), Tooltip("True if resize texture on import. Use Size property to define texture width and height. Texture scale property will be ignored.")] - public bool Resize { get; set; } = false; - - /// - /// Gets or sets the size of the imported texture. If Resize property is set to true then texture will be resized during the import to this value. Otherwise it will be ignored. - /// - [EditorOrder(100), VisibleIf("Resize"), DefaultValue(typeof(Int2), "1024,1024"), Tooltip("The size of the imported texture. If Resize property is set to true then texture will be resized during the import to this value. Otherwise it will be ignored.")] - public Int2 Size { get; set; } = new Int2(1024, 1024); - - /// - /// True if preserve alpha coverage in generated mips for alpha test reference. Scales mipmap alpha values to preserve alpha coverage based on an alpha test reference value. - /// - [EditorOrder(240), DefaultValue(false), Tooltip("Check to preserve alpha coverage in generated mips for alpha test reference. Scales mipmap alpha values to preserve alpha coverage based on an alpha test reference value.")] - public bool PreserveAlphaCoverage { get; set; } = false; - - /// - /// The reference value for the alpha coverage preserving. - /// - [EditorOrder(250), VisibleIf("PreserveAlphaCoverage"), DefaultValue(0.5f), Tooltip("The reference value for the alpha coverage preserving.")] - public float PreserveAlphaCoverageReference { get; set; } = 0.5f; - - /// - /// Texture group for streaming (negative if unused). See Streaming Settings. - /// - [CustomEditor(typeof(CustomEditors.Dedicated.TextureGroupEditor))] - [EditorOrder(300), Tooltip("Texture group for streaming (negative if unused). See Streaming Settings.")] - public int TextureGroup = -1; - - /// - /// The sprites. Used to keep created sprites on sprite atlas reimport. - /// - [HideInEditor] - public List Sprites = new List(); - - [StructLayout(LayoutKind.Sequential)] - [NativeMarshalling(typeof(InternalOptionsMarshaller))] - internal struct InternalOptions - { - public TextureFormatType Type; - public byte IsAtlas; - public byte NeverStream; - public byte Compress; - public byte IndependentChannels; - public byte sRGB; - public byte GenerateMipMaps; - public byte FlipY; - public byte Resize; - public byte PreserveAlphaCoverage; - public float PreserveAlphaCoverageReference; - public float Scale; - public int MaxSize; - public int TextureGroup; - public Int2 Size; - public Rectangle[] SpriteAreas; - public string[] SpriteNames; - } - - [CustomMarshaller(typeof(InternalOptions), MarshalMode.Default, typeof(InternalOptionsMarshaller))] - internal static class InternalOptionsMarshaller - { - [StructLayout(LayoutKind.Sequential)] - internal struct InternalOptionsNative - { - public byte Type; - public byte IsAtlas; - public byte NeverStream; - public byte Compress; - public byte IndependentChannels; - public byte sRGB; - public byte GenerateMipMaps; - public byte FlipY; - public byte Resize; - public byte PreserveAlphaCoverage; - public float PreserveAlphaCoverageReference; - public float Scale; - public int MaxSize; - public int TextureGroup; - public Int2 Size; - public IntPtr SpriteAreas; - public IntPtr SpriteNames; - } - - internal static InternalOptions ConvertToManaged(InternalOptionsNative unmanaged) => ToManaged(unmanaged); - internal static InternalOptionsNative ConvertToUnmanaged(InternalOptions managed) => ToNative(managed); - - internal static InternalOptions ToManaged(InternalOptionsNative managed) - { - return new InternalOptions() - { - Type = (TextureFormatType)managed.Type, - IsAtlas = managed.IsAtlas, - NeverStream = managed.NeverStream, - Compress = managed.Compress, - IndependentChannels = managed.IndependentChannels, - sRGB = managed.sRGB, - GenerateMipMaps = managed.GenerateMipMaps, - FlipY = managed.FlipY, - Resize = managed.Resize, - PreserveAlphaCoverage = managed.PreserveAlphaCoverage, - PreserveAlphaCoverageReference = managed.PreserveAlphaCoverageReference, - Scale = managed.Scale, - MaxSize = managed.MaxSize, - TextureGroup = managed.TextureGroup, - Size = managed.Size, - SpriteAreas = managed.SpriteAreas != IntPtr.Zero ? ((ManagedArray)ManagedHandle.FromIntPtr(managed.SpriteAreas).Target).ToArray() : null, - SpriteNames = managed.SpriteNames != IntPtr.Zero ? NativeInterop.GCHandleArrayToManagedArray((ManagedArray)ManagedHandle.FromIntPtr(managed.SpriteNames).Target) : null, - }; - } - internal static InternalOptionsNative ToNative(InternalOptions managed) - { - return new InternalOptionsNative() - { - Type = (byte)managed.Type, - IsAtlas = managed.IsAtlas, - NeverStream = managed.NeverStream, - Compress = managed.Compress, - IndependentChannels = managed.IndependentChannels, - sRGB = managed.sRGB, - GenerateMipMaps = managed.GenerateMipMaps, - FlipY = managed.FlipY, - Resize = managed.Resize, - PreserveAlphaCoverage = managed.PreserveAlphaCoverage, - PreserveAlphaCoverageReference = managed.PreserveAlphaCoverageReference, - Scale = managed.Scale, - MaxSize = managed.MaxSize, - TextureGroup = managed.TextureGroup, - Size = managed.Size, - SpriteAreas = managed.SpriteAreas?.Length > 0 ? ManagedHandle.ToIntPtr(NativeInterop.ManagedArrayToGCHandleWrappedArray(managed.SpriteAreas)) : IntPtr.Zero, - SpriteNames = managed.SpriteNames?.Length > 0 ? ManagedHandle.ToIntPtr(NativeInterop.ManagedArrayToGCHandleWrappedArray(managed.SpriteNames)) : IntPtr.Zero, - }; - } - internal static void Free(InternalOptionsNative unmanaged) - { - } - } - - internal void ToInternal(out InternalOptions options) - { - options = new InternalOptions - { - Type = (TextureFormatType)(int)Type, - IsAtlas = (byte)(IsAtlas ? 1 : 0), - NeverStream = (byte)(NeverStream ? 1 : 0), - Compress = (byte)(Compress ? 1 : 0), - IndependentChannels = (byte)(IndependentChannels ? 1 : 0), - sRGB = (byte)(sRGB ? 1 : 0), - GenerateMipMaps = (byte)(GenerateMipMaps ? 1 : 0), - FlipY = (byte)(FlipY ? 1 : 0), - Resize = (byte)(Resize ? 1 : 0), - PreserveAlphaCoverage = (byte)(PreserveAlphaCoverage ? 1 : 0), - PreserveAlphaCoverageReference = PreserveAlphaCoverageReference, - Scale = Scale, - Size = Size, - MaxSize = (int)MaxSize, - TextureGroup = TextureGroup, - }; - if (Sprites != null && Sprites.Count > 0) - { - int count = Sprites.Count; - options.SpriteAreas = new Rectangle[count]; - options.SpriteNames = new string[count]; - for (int i = 0; i < count; i++) - { - options.SpriteAreas[i] = Sprites[i].Area; - options.SpriteNames[i] = Sprites[i].Name; - } - } - else - { - options.SpriteAreas = null; - options.SpriteNames = null; - } - } - - internal void FromInternal(ref InternalOptions options) - { - Type = (CustomTextureFormatType)(int)options.Type; - IsAtlas = options.IsAtlas != 0; - NeverStream = options.NeverStream != 0; - Compress = options.Compress != 0; - IndependentChannels = options.IndependentChannels != 0; - sRGB = options.sRGB != 0; - GenerateMipMaps = options.GenerateMipMaps != 0; - FlipY = options.FlipY != 0; - Resize = options.Resize != 0; - PreserveAlphaCoverage = options.PreserveAlphaCoverage != 0; - PreserveAlphaCoverageReference = options.PreserveAlphaCoverageReference; - Scale = options.Scale; - MaxSize = ConvertMaxSize(options.MaxSize); - TextureGroup = options.TextureGroup; - Size = options.Size; - if (options.SpriteAreas != null) - { - int spritesCount = options.SpriteAreas.Length; - Sprites.Capacity = spritesCount; - for (int i = 0; i < spritesCount; i++) - { - Sprites.Add(new SpriteInfo(options.SpriteAreas[i], options.SpriteNames[i])); - } - } - } - - /// - /// Tries the restore the asset import options from the target resource file. - /// - /// The options. - /// The asset path. - /// True settings has been restored, otherwise false. - public static bool TryRestore(ref TextureImportSettings options, string assetPath) - { - if (TextureImportEntry.Internal_GetTextureImportOptions(assetPath, out var internalOptions)) - { - // Restore settings - options.FromInternal(ref internalOptions); - return true; - } - return false; - } + [EditorDisplay(null, EditorDisplayAttribute.InlineStyle)] + public TextureTool.Options Settings = TextureTool.Options.Default; } /// /// Texture asset import entry. /// /// - public partial class TextureImportEntry : AssetImportEntry + public class TextureImportEntry : AssetImportEntry { - private TextureImportSettings _settings = new TextureImportSettings(); + private TextureImportSettings _settings = new(); /// /// Initializes a new instance of the class. @@ -505,15 +125,15 @@ namespace FlaxEditor.Content.Import if (extension == ".raw") { // Raw image data in 16bit gray-scale, preserve the quality - _settings.Type = TextureImportSettings.CustomTextureFormatType.HdrRGBA; - _settings.Compress = false; + _settings.Settings.Type = TextureFormatType.HdrRGBA; + _settings.Settings.Compress = false; } else if (extension == ".hdr") { // HDR sky texture - _settings.Type = TextureImportSettings.CustomTextureFormatType.HdrRGB; + _settings.Settings.Type = TextureFormatType.HdrRGB; } - else if (_settings.Type != TextureImportSettings.CustomTextureFormatType.ColorRGB) + else if (_settings.Settings.Type != TextureFormatType.ColorRGB) { // Skip checking } @@ -525,7 +145,7 @@ namespace FlaxEditor.Content.Import || snl.EndsWith("normals")) { // Normal map - _settings.Type = TextureImportSettings.CustomTextureFormatType.NormalMap; + _settings.Settings.Type = TextureFormatType.NormalMap; } else if (snl.EndsWith("_d") || snl.Contains("diffuse") @@ -536,8 +156,8 @@ namespace FlaxEditor.Content.Import || snl.Contains("albedo")) { // Albedo or diffuse map - _settings.Type = TextureImportSettings.CustomTextureFormatType.ColorRGB; - _settings.sRGB = true; + _settings.Settings.Type = TextureFormatType.ColorRGB; + _settings.Settings.sRGB = true; } else if (snl.EndsWith("ao") || snl.EndsWith("ambientocclusion") @@ -560,11 +180,11 @@ namespace FlaxEditor.Content.Import || snl.EndsWith("metallic")) { // Glossiness, metalness, ambient occlusion, displacement, height, cavity or specular - _settings.Type = TextureImportSettings.CustomTextureFormatType.GrayScale; + _settings.Settings.Type = TextureFormatType.GrayScale; } // Try to restore target asset texture import options (useful for fast reimport) - TextureImportSettings.TryRestore(ref _settings, ResultUrl); + Editor.TryRestoreImportOptions(ref _settings.Settings, ResultUrl); } /// @@ -573,11 +193,18 @@ namespace FlaxEditor.Content.Import /// public override bool TryOverrideSettings(object settings) { - if (settings is TextureImportSettings o) + if (settings is TextureImportSettings s) { - var sprites = o.Sprites ?? _settings.Sprites; // Preserve sprites if not specified to override - _settings = o; - _settings.Sprites = sprites; + var sprites = s.Settings.Sprites ?? _settings.Settings.Sprites; // Preserve sprites if not specified to override + _settings.Settings = s.Settings; + _settings.Settings.Sprites = sprites; + return true; + } + if (settings is TextureTool.Options o) + { + var sprites = o.Sprites ?? _settings.Settings.Sprites; // Preserve sprites if not specified to override + _settings.Settings = o; + _settings.Settings.Sprites = sprites; return true; } return false; @@ -586,15 +213,7 @@ namespace FlaxEditor.Content.Import /// public override bool Import() { - return Editor.Import(SourceUrl, ResultUrl, _settings); + return Editor.Import(SourceUrl, ResultUrl, _settings.Settings); } - - #region Internal Calls - - [LibraryImport("FlaxEngine", EntryPoint = "TextureImportEntryInternal_GetTextureImportOptions", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(StringMarshaller))] - [return: MarshalAs(UnmanagedType.U1)] - internal static partial bool Internal_GetTextureImportOptions(string path, out TextureImportSettings.InternalOptions result); - - #endregion } } diff --git a/Source/Editor/Editor.cpp b/Source/Editor/Editor.cpp index 62ef85f2c..8a92d11f4 100644 --- a/Source/Editor/Editor.cpp +++ b/Source/Editor/Editor.cpp @@ -671,9 +671,7 @@ bool Editor::Init() void Editor::BeforeRun() { - // If during last lightmaps baking engine crashed we could try to restore the progress - if (ShadowsOfMordor::Builder::Instance()->RestoreState()) - Managed->GetClass()->GetMethod("Internal_StartLightingBake")->Invoke(Managed->GetOrCreateManagedInstance(), nullptr, nullptr); + Managed->BeforeRun(); } void Editor::BeforeExit() diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index 6ad621a7a..1a1fd3b2d 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -933,47 +933,6 @@ namespace FlaxEditor Animation = 11, } - /// - /// Imports the asset file to the target location. - /// - /// The source file path. - /// The result asset file path. - /// True if importing failed, otherwise false. - public static bool Import(string inputPath, string outputPath) - { - return Internal_Import(inputPath, outputPath, IntPtr.Zero); - } - - /// - /// Imports the texture asset file to the target location. - /// - /// The source file path. - /// The result asset file path. - /// The settings. - /// True if importing failed, otherwise false. - public static bool Import(string inputPath, string outputPath, TextureImportSettings settings) - { - if (settings == null) - throw new ArgumentNullException(); - settings.ToInternal(out var internalOptions); - return Internal_ImportTexture(inputPath, outputPath, ref internalOptions); - } - - /// - /// Imports the model asset file to the target location. - /// - /// The source file path. - /// The result asset file path. - /// The settings. - /// True if importing failed, otherwise false. - public static bool Import(string inputPath, string outputPath, ModelImportSettings settings) - { - if (settings == null) - throw new ArgumentNullException(); - settings.ToInternal(out var internalOptions); - return Internal_ImportModel(inputPath, outputPath, ref internalOptions); - } - /// /// Imports the audio asset file to the target location. /// @@ -1643,18 +1602,6 @@ namespace FlaxEditor [return: MarshalAs(UnmanagedType.U1)] internal static partial bool Internal_CloneAssetFile(string dstPath, string srcPath, ref Guid dstId); - [LibraryImport("FlaxEngine", EntryPoint = "EditorInternal_Import", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(StringMarshaller))] - [return: MarshalAs(UnmanagedType.U1)] - internal static partial bool Internal_Import(string inputPath, string outputPath, IntPtr arg); - - [LibraryImport("FlaxEngine", EntryPoint = "EditorInternal_ImportTexture", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(StringMarshaller))] - [return: MarshalAs(UnmanagedType.U1)] - internal static partial bool Internal_ImportTexture(string inputPath, string outputPath, ref TextureImportSettings.InternalOptions options); - - [LibraryImport("FlaxEngine", EntryPoint = "EditorInternal_ImportModel", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(StringMarshaller))] - [return: MarshalAs(UnmanagedType.U1)] - internal static partial bool Internal_ImportModel(string inputPath, string outputPath, ref ModelImportSettings.InternalOptions options); - [LibraryImport("FlaxEngine", EntryPoint = "EditorInternal_ImportAudio", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(StringMarshaller))] [return: MarshalAs(UnmanagedType.U1)] internal static partial bool Internal_ImportAudio(string inputPath, string outputPath, ref AudioImportSettings.InternalOptions options); diff --git a/Source/Editor/Managed/ManagedEditor.Internal.cpp b/Source/Editor/Managed/ManagedEditor.Internal.cpp index c42123e41..bed9cfb5c 100644 --- a/Source/Editor/Managed/ManagedEditor.Internal.cpp +++ b/Source/Editor/Managed/ManagedEditor.Internal.cpp @@ -56,240 +56,6 @@ Guid ManagedEditor::ObjectID(0x91970b4e, 0x99634f61, 0x84723632, 0x54c776af); #pragma warning( disable : 4800) #endif -struct InternalTextureOptions -{ - TextureFormatType Type; - byte IsAtlas; - byte NeverStream; - byte Compress; - byte IndependentChannels; - byte sRGB; - byte GenerateMipMaps; - byte FlipY; - byte Resize; - byte PreserveAlphaCoverage; - float PreserveAlphaCoverageReference; - float Scale; - int32 MaxSize; - int32 TextureGroup; - int32 SizeX; - int32 SizeY; - MArray* SpriteAreas; - MArray* SpriteNames; - - static void Convert(InternalTextureOptions* from, ImportTexture::Options* to) - { - to->Type = from->Type; - to->IsAtlas = from->IsAtlas; - to->NeverStream = from->NeverStream; - to->Compress = from->Compress; - to->IndependentChannels = from->IndependentChannels; - to->sRGB = from->sRGB; - to->GenerateMipMaps = from->GenerateMipMaps; - to->FlipY = from->FlipY; - to->Scale = from->Scale; - to->Resize = from->Resize; - to->PreserveAlphaCoverage = from->PreserveAlphaCoverage; - to->PreserveAlphaCoverageReference = from->PreserveAlphaCoverageReference; - to->MaxSize = from->MaxSize; - to->TextureGroup = from->TextureGroup; - to->SizeX = from->SizeX; - to->SizeY = from->SizeY; - to->Sprites.Clear(); - if (from->SpriteNames != nullptr) - { - int32 count = MCore::Array::GetLength(from->SpriteNames); - ASSERT(count == MCore::Array::GetLength(from->SpriteAreas)); - to->Sprites.Resize(count); - MString** spriteNamesPtr = MCore::Array::GetAddress(from->SpriteNames); - Rectangle* spriteAreasPtr = MCore::Array::GetAddress(from->SpriteAreas); - for (int32 i = 0; i < count; i++) - { - Sprite& sprite = to->Sprites[i]; - sprite.Area = spriteAreasPtr[i]; - sprite.Name = MUtils::ToString(spriteNamesPtr[i]); - } - } - } - - static void Convert(ImportTexture::Options* from, InternalTextureOptions* to) - { - to->Type = from->Type; - to->IsAtlas = from->IsAtlas; - to->NeverStream = from->NeverStream; - to->Compress = from->Compress; - to->IndependentChannels = from->IndependentChannels; - to->sRGB = from->sRGB; - to->GenerateMipMaps = from->GenerateMipMaps; - to->FlipY = from->FlipY; - to->Resize = from->Resize; - to->PreserveAlphaCoverage = from->PreserveAlphaCoverage; - to->PreserveAlphaCoverageReference = from->PreserveAlphaCoverageReference; - to->Scale = from->Scale; - to->MaxSize = from->MaxSize; - to->TextureGroup = from->TextureGroup; - to->SizeX = from->SizeX; - to->SizeY = from->SizeY; - if (from->Sprites.HasItems()) - { - const int32 count = from->Sprites.Count(); - to->SpriteAreas = MCore::Array::New(Rectangle::TypeInitializer.GetClass(), count); - to->SpriteNames = MCore::Array::New( MCore::TypeCache::String, count); - Rectangle* spriteAreasPtr = MCore::Array::GetAddress(to->SpriteAreas); - for (int32 i = 0; i < count; i++) - { - spriteAreasPtr[i] = from->Sprites[i].Area; - MCore::GC::WriteArrayRef(to->SpriteNames, (MObject*)MUtils::ToString(from->Sprites[i].Name), i); - } - } - else - { - to->SpriteAreas = nullptr; - to->SpriteNames = nullptr; - } - } -}; - -struct InternalModelOptions -{ - ModelTool::ModelType Type; - - // Geometry - byte CalculateNormals; - float SmoothingNormalsAngle; - byte FlipNormals; - float SmoothingTangentsAngle; - byte CalculateTangents; - byte OptimizeMeshes; - byte MergeMeshes; - byte ImportLODs; - byte ImportVertexColors; - byte ImportBlendShapes; - ModelLightmapUVsSource LightmapUVsSource; - MString* CollisionMeshesPrefix; - - // Transform - float Scale; - Quaternion Rotation; - Float3 Translation; - byte CenterGeometry; - - // Animation - ModelTool::AnimationDuration Duration; - float FramesRangeStart; - float FramesRangeEnd; - float DefaultFrameRate; - float SamplingRate; - byte SkipEmptyCurves; - byte OptimizeKeyframes; - byte ImportScaleTracks; - byte EnableRootMotion; - MString* RootNodeName; - - // Level Of Detail - byte GenerateLODs; - int32 BaseLOD; - int32 LODCount; - float TriangleReduction; - - // Misc - byte ImportMaterials; - byte ImportTextures; - byte RestoreMaterialsOnReimport; - - // SDF - byte GenerateSDF; - float SDFResolution; - - // Splitting - byte SplitObjects; - int32 ObjectIndex; - - static void Convert(InternalModelOptions* from, ImportModelFile::Options* to) - { - to->Type = from->Type; - to->CalculateNormals = from->CalculateNormals; - to->SmoothingNormalsAngle = from->SmoothingNormalsAngle; - to->FlipNormals = from->FlipNormals; - to->SmoothingTangentsAngle = from->SmoothingTangentsAngle; - to->CalculateTangents = from->CalculateTangents; - to->OptimizeMeshes = from->OptimizeMeshes; - to->MergeMeshes = from->MergeMeshes; - to->ImportLODs = from->ImportLODs; - to->ImportVertexColors = from->ImportVertexColors; - to->ImportBlendShapes = from->ImportBlendShapes; - to->LightmapUVsSource = from->LightmapUVsSource; - to->CollisionMeshesPrefix = MUtils::ToString(from->CollisionMeshesPrefix); - to->Scale = from->Scale; - to->Rotation = from->Rotation; - to->Translation = from->Translation; - to->CenterGeometry = from->CenterGeometry; - to->Duration = from->Duration; - to->FramesRange.X = from->FramesRangeStart; - to->FramesRange.Y = from->FramesRangeEnd; - to->DefaultFrameRate = from->DefaultFrameRate; - to->SamplingRate = from->SamplingRate; - to->SkipEmptyCurves = from->SkipEmptyCurves; - to->OptimizeKeyframes = from->OptimizeKeyframes; - to->ImportScaleTracks = from->ImportScaleTracks; - to->EnableRootMotion = from->EnableRootMotion; - to->RootNodeName = MUtils::ToString(from->RootNodeName); - to->GenerateLODs = from->GenerateLODs; - to->BaseLOD = from->BaseLOD; - to->LODCount = from->LODCount; - to->TriangleReduction = from->TriangleReduction; - to->ImportMaterials = from->ImportMaterials; - to->ImportTextures = from->ImportTextures; - to->RestoreMaterialsOnReimport = from->RestoreMaterialsOnReimport; - to->GenerateSDF = from->GenerateSDF; - to->SDFResolution = from->SDFResolution; - to->SplitObjects = from->SplitObjects; - to->ObjectIndex = from->ObjectIndex; - } - - static void Convert(ImportModelFile::Options* from, InternalModelOptions* to) - { - to->Type = from->Type; - to->CalculateNormals = from->CalculateNormals; - to->SmoothingNormalsAngle = from->SmoothingNormalsAngle; - to->FlipNormals = from->FlipNormals; - to->SmoothingTangentsAngle = from->SmoothingTangentsAngle; - to->CalculateTangents = from->CalculateTangents; - to->OptimizeMeshes = from->OptimizeMeshes; - to->MergeMeshes = from->MergeMeshes; - to->ImportLODs = from->ImportLODs; - to->ImportVertexColors = from->ImportVertexColors; - to->ImportBlendShapes = from->ImportBlendShapes; - to->LightmapUVsSource = from->LightmapUVsSource; - to->CollisionMeshesPrefix = MUtils::ToString(from->CollisionMeshesPrefix); - to->Scale = from->Scale; - to->Rotation = from->Rotation; - to->Translation = from->Translation; - to->CenterGeometry = from->CenterGeometry; - to->Duration = from->Duration; - to->FramesRangeStart = from->FramesRange.X; - to->FramesRangeEnd = from->FramesRange.Y; - to->DefaultFrameRate = from->DefaultFrameRate; - to->SamplingRate = from->SamplingRate; - to->SkipEmptyCurves = from->SkipEmptyCurves; - to->OptimizeKeyframes = from->OptimizeKeyframes; - to->ImportScaleTracks = from->ImportScaleTracks; - to->EnableRootMotion = from->EnableRootMotion; - to->RootNodeName = MUtils::ToString(from->RootNodeName); - to->GenerateLODs = from->GenerateLODs; - to->BaseLOD = from->BaseLOD; - to->LODCount = from->LODCount; - to->TriangleReduction = from->TriangleReduction; - to->ImportMaterials = from->ImportMaterials; - to->ImportTextures = from->ImportTextures; - to->RestoreMaterialsOnReimport = from->RestoreMaterialsOnReimport; - to->GenerateSDF = from->GenerateSDF; - to->SDFResolution = from->SDFResolution; - to->SplitObjects = from->SplitObjects; - to->ObjectIndex = from->ObjectIndex; - } -}; - struct InternalAudioOptions { AudioFormat Format; @@ -529,35 +295,14 @@ DEFINE_INTERNAL_CALL(MString*) EditorInternal_CanImport(MString* extensionObj) return importer ? MUtils::ToString(importer->ResultExtension) : nullptr; } -DEFINE_INTERNAL_CALL(bool) EditorInternal_Import(MString* inputPathObj, MString* outputPathObj, void* arg) -{ - String inputPath, outputPath; - MUtils::ToString(inputPathObj, inputPath); - MUtils::ToString(outputPathObj, outputPath); - FileSystem::NormalizePath(inputPath); - FileSystem::NormalizePath(outputPath); - return AssetsImportingManager::Import(inputPath, outputPath, arg); -} - -DEFINE_INTERNAL_CALL(bool) EditorInternal_ImportTexture(MString* inputPathObj, MString* outputPathObj, InternalTextureOptions* optionsObj) -{ - ImportTexture::Options options; - InternalTextureOptions::Convert(optionsObj, &options); - return EditorInternal_Import(inputPathObj, outputPathObj, &options); -} - -DEFINE_INTERNAL_CALL(bool) EditorInternal_ImportModel(MString* inputPathObj, MString* outputPathObj, InternalModelOptions* optionsObj) -{ - ImportModelFile::Options options; - InternalModelOptions::Convert(optionsObj, &options); - return EditorInternal_Import(inputPathObj, outputPathObj, &options); -} - DEFINE_INTERNAL_CALL(bool) EditorInternal_ImportAudio(MString* inputPathObj, MString* outputPathObj, InternalAudioOptions* optionsObj) { ImportAudio::Options options; InternalAudioOptions::Convert(optionsObj, &options); - return EditorInternal_Import(inputPathObj, outputPathObj, &options); + String inputPath, outputPath; + MUtils::ToString(inputPathObj, inputPath); + MUtils::ToString(outputPathObj, outputPath); + return ManagedEditor::Import(inputPath, outputPath, &options); } DEFINE_INTERNAL_CALL(void) EditorInternal_GetAudioClipMetadata(AudioClip* clip, int32* originalSize, int32* importedSize) @@ -1020,40 +765,6 @@ DEFINE_INTERNAL_CALL(MTypeObject*) CustomEditorsUtilInternal_GetCustomEditor(MTy return CustomEditorsUtil::GetCustomEditor(targetType); } -DEFINE_INTERNAL_CALL(bool) TextureImportEntryInternal_GetTextureImportOptions(MString* pathObj, InternalTextureOptions* result) -{ - String path; - MUtils::ToString(pathObj, path); - FileSystem::NormalizePath(path); - ImportTexture::Options options; - if (ImportTexture::TryGetImportOptions(path, options)) - { - // Convert into managed storage - InternalTextureOptions::Convert(&options, result); - return true; - } - return false; -} - -DEFINE_INTERNAL_CALL(void) ModelImportEntryInternal_GetModelImportOptions(MString* pathObj, InternalModelOptions* result) -{ - // Initialize defaults - ImportModelFile::Options options; - if (const auto* graphicsSettings = GraphicsSettings::Get()) - { - options.GenerateSDF = graphicsSettings->GenerateSDFOnModelImport; - } - - // Get options from model - String path; - MUtils::ToString(pathObj, path); - FileSystem::NormalizePath(path); - ImportModelFile::TryGetImportOptions(path, options); - - // Convert into managed storage - InternalModelOptions::Convert(&options, result); -} - DEFINE_INTERNAL_CALL(bool) AudioImportEntryInternal_GetAudioImportOptions(MString* pathObj, InternalAudioOptions* result) { String path; @@ -1084,58 +795,38 @@ DEFINE_INTERNAL_CALL(void) GameSettingsInternal_Apply() GameSettings::Load(); } -class ManagedEditorInternal +bool ManagedEditor::Import(String inputPath, String outputPath, void* arg) { -public: - static void InitRuntime() - { - ADD_INTERNAL_CALL("FlaxEditor.Editor::IsDevInstance", &EditorInternal_IsDevInstance); - ADD_INTERNAL_CALL("FlaxEditor.Editor::IsOfficialBuild", &EditorInternal_IsOfficialBuild); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_IsPlayMode", &EditorInternal_IsPlayMode); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_ReadOutputLogs", &EditorInternal_ReadOutputLogs); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_SetPlayMode", &EditorInternal_SetPlayMode); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_GetProjectPath", &EditorInternal_GetProjectPath); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_Import", &EditorInternal_Import); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_ImportTexture", &EditorInternal_ImportTexture); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_ImportModel", &EditorInternal_ImportModel); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_ImportAudio", &EditorInternal_ImportAudio); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_GetAudioClipMetadata", &EditorInternal_GetAudioClipMetadata); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_SaveJsonAsset", &EditorInternal_SaveJsonAsset); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_CopyCache", &EditorInternal_CopyCache); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_CloneAssetFile", &EditorInternal_CloneAssetFile); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_BakeLightmaps", &EditorInternal_BakeLightmaps); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_GetShaderAssetSourceCode", &EditorInternal_GetShaderAssetSourceCode); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_CookMeshCollision", &EditorInternal_CookMeshCollision); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_GetCollisionWires", &EditorInternal_GetCollisionWires); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_GetEditorBoxWithChildren", &EditorInternal_GetEditorBoxWithChildren); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_SetOptions", &EditorInternal_SetOptions); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_DrawNavMesh", &EditorInternal_DrawNavMesh); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_CloseSplashScreen", &EditorInternal_CloseSplashScreen); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_CreateAsset", &EditorInternal_CreateAsset); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_CreateVisualScript", &EditorInternal_CreateVisualScript); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_CanImport", &EditorInternal_CanImport); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_CanExport", &EditorInternal_CanExport); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_Export", &EditorInternal_Export); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_GetIsEveryAssemblyLoaded", &EditorInternal_GetIsEveryAssemblyLoaded); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_GetLastProjectOpenedEngineBuild", &EditorInternal_GetLastProjectOpenedEngineBuild); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_GetIsCSGActive", &EditorInternal_GetIsCSGActive); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_RunVisualScriptBreakpointLoopTick", &EditorInternal_RunVisualScriptBreakpointLoopTick); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_GetVisualScriptLocals", &EditorInternal_GetVisualScriptLocals); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_GetVisualScriptStackFrames", &EditorInternal_GetVisualScriptStackFrames); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_GetVisualScriptPreviousScopeFrame", &EditorInternal_GetVisualScriptPreviousScopeFrame); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_EvaluateVisualScriptLocal", &EditorInternal_EvaluateVisualScriptLocal); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_DeserializeSceneObject", &EditorInternal_DeserializeSceneObject); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_LoadAsset", &EditorInternal_LoadAsset); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_CanSetToRoot", &EditorInternal_CanSetToRoot); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_GetAnimationTime", &EditorInternal_GetAnimationTime); - ADD_INTERNAL_CALL("FlaxEditor.Editor::Internal_SetAnimationTime", &EditorInternal_SetAnimationTime); - ADD_INTERNAL_CALL("FlaxEditor.CustomEditors.CustomEditorsUtil::Internal_GetCustomEditor", &CustomEditorsUtilInternal_GetCustomEditor); - ADD_INTERNAL_CALL("FlaxEditor.Content.Import.TextureImportEntry::Internal_GetTextureImportOptions", &TextureImportEntryInternal_GetTextureImportOptions); - ADD_INTERNAL_CALL("FlaxEditor.Content.Import.ModelImportEntry::Internal_GetModelImportOptions", &ModelImportEntryInternal_GetModelImportOptions); - ADD_INTERNAL_CALL("FlaxEditor.Content.Import.AudioImportEntry::Internal_GetAudioImportOptions", &AudioImportEntryInternal_GetAudioImportOptions); - ADD_INTERNAL_CALL("FlaxEditor.Content.Settings.LayersAndTagsSettings::GetCurrentLayers", &LayersAndTagsSettingsInternal_GetCurrentLayers); - ADD_INTERNAL_CALL("FlaxEditor.Content.Settings.GameSettings::Apply", &GameSettingsInternal_Apply); - } -}; + FileSystem::NormalizePath(inputPath); + FileSystem::NormalizePath(outputPath); + return AssetsImportingManager::Import(inputPath, outputPath, arg); +} -IMPLEMENT_SCRIPTING_TYPE_NO_SPAWN_WITH_BASE(ManagedEditor, ScriptingObject, FlaxEngine, "FlaxEditor.Editor", nullptr, nullptr); +bool ManagedEditor::Import(const String& inputPath, const String& outputPath, const TextureTool::Options& options) +{ + return Import(inputPath, outputPath, (void*)&options); +} + +bool ManagedEditor::TryRestoreImportOptions(TextureTool::Options& options, String assetPath) +{ + FileSystem::NormalizePath(assetPath); + return ImportTexture::TryGetImportOptions(assetPath, options); +} + +bool ManagedEditor::Import(const String& inputPath, const String& outputPath, const ModelTool::Options& options) +{ + return Import(inputPath, outputPath, (void*)&options); +} + +bool ManagedEditor::TryRestoreImportOptions(ModelTool::Options& options, String assetPath) +{ + // Initialize defaults + if (const auto* graphicsSettings = GraphicsSettings::Get()) + { + options.GenerateSDF = graphicsSettings->GenerateSDFOnModelImport; + } + + // Get options from model + FileSystem::NormalizePath(assetPath); + return ImportModelFile::TryGetImportOptions(assetPath, options); +} diff --git a/Source/Editor/Managed/ManagedEditor.cpp b/Source/Editor/Managed/ManagedEditor.cpp index dd35a0760..fd9219d35 100644 --- a/Source/Editor/Managed/ManagedEditor.cpp +++ b/Source/Editor/Managed/ManagedEditor.cpp @@ -241,6 +241,13 @@ void ManagedEditor::Init() } } +void ManagedEditor::BeforeRun() +{ + // If during last lightmaps baking engine crashed we could try to restore the progress + if (ShadowsOfMordor::Builder::Instance()->RestoreState()) + GetClass()->GetMethod("Internal_StartLightingBake")->Invoke(GetOrCreateManagedInstance(), nullptr, nullptr); +} + void ManagedEditor::Update() { // Skip if managed object is missing diff --git a/Source/Editor/Managed/ManagedEditor.h b/Source/Editor/Managed/ManagedEditor.h index 36fc0c234..ddd94b47e 100644 --- a/Source/Editor/Managed/ManagedEditor.h +++ b/Source/Editor/Managed/ManagedEditor.h @@ -5,6 +5,8 @@ #include "Engine/Scripting/ScriptingObject.h" #include "Engine/Platform/Window.h" #include "Engine/ShadowsOfMordor/Types.h" +#include "Engine/Tools/TextureTool/TextureTool.h" +#include "Engine/Tools/ModelTool/ModelTool.h" namespace CSG { @@ -12,14 +14,11 @@ namespace CSG } /// -/// Managed Editor root object +/// The main managed editor class. Editor root object. /// -class ManagedEditor : public ScriptingObject +API_CLASS(Namespace="FlaxEditor", Name="Editor", NoSpawn, NoConstructor) class ManagedEditor : private ScriptingObject { -DECLARE_SCRIPTING_TYPE_NO_SPAWN(ManagedEditor); - -public: - + DECLARE_SCRIPTING_TYPE_NO_SPAWN(ManagedEditor); static Guid ObjectID; struct InternalOptions @@ -36,7 +35,6 @@ public: static InternalOptions ManagedEditorOptions; public: - /// /// Initializes a new instance of the class. /// @@ -48,12 +46,13 @@ public: ~ManagedEditor(); public: - /// /// Initializes managed editor. /// void Init(); + void BeforeRun(); + /// /// Updates managed editor. /// @@ -94,7 +93,6 @@ public: bool CanAutoBuildNavMesh(); public: - /// /// Checks whenever the game viewport is focused by the user (eg. can receive input). /// @@ -144,12 +142,58 @@ public: /// void RequestStartPlayOnEditMode(); -private: +public: + /// + /// Imports the asset file to the target location. + /// + /// The source file path. + /// The result asset file path. + /// The custom argument 9native data). + /// True if importing failed, otherwise false. + API_FUNCTION() static bool Import(String inputPath, String outputPath, void* arg = nullptr); +#if COMPILE_WITH_TEXTURE_TOOL + /// + /// Imports the texture asset file to the target location. + /// + /// The source file path. + /// The result asset file path. + /// The import settings. + /// True if importing failed, otherwise false. + API_FUNCTION() static bool Import(const String& inputPath, const String& outputPath, const TextureTool::Options& options); + + /// + /// Tries the restore the asset import options from the target resource file. + /// + /// The options. + /// The asset path. + /// True settings has been restored, otherwise false. + API_FUNCTION() static bool TryRestoreImportOptions(API_PARAM(Ref) TextureTool::Options& options, String assetPath); +#endif + +#if COMPILE_WITH_MODEL_TOOL + /// + /// Imports the model asset file to the target location. + /// + /// The source file path. + /// The result asset file path. + /// The import settings. + /// True if importing failed, otherwise false. + API_FUNCTION() static bool Import(const String& inputPath, const String& outputPath, const ModelTool::Options& options); + + /// + /// Tries the restore the asset import options from the target resource file. + /// + /// The options. + /// The asset path. + /// True settings has been restored, otherwise false. + API_FUNCTION() static bool TryRestoreImportOptions(API_PARAM(Ref) ModelTool::Options& options, String assetPath); +#endif + +private: void OnEditorAssemblyLoaded(MAssembly* assembly); public: - // [ScriptingObject] void DestroyManaged() override; }; diff --git a/Source/Editor/Windows/Assets/AnimationWindow.cs b/Source/Editor/Windows/Assets/AnimationWindow.cs index 43b6765f1..a765c2faa 100644 --- a/Source/Editor/Windows/Assets/AnimationWindow.cs +++ b/Source/Editor/Windows/Assets/AnimationWindow.cs @@ -144,7 +144,7 @@ namespace FlaxEditor.Windows.Assets Asset = window.Asset; // Try to restore target asset import options (useful for fast reimport) - ModelImportSettings.TryRestore(ref ImportSettings, window.Item.Path); + Editor.TryRestoreImportOptions(ref ImportSettings.Settings, window.Item.Path); } public void OnClean() diff --git a/Source/Editor/Windows/Assets/CubeTextureWindow.cs b/Source/Editor/Windows/Assets/CubeTextureWindow.cs index 44db2016f..272cf351b 100644 --- a/Source/Editor/Windows/Assets/CubeTextureWindow.cs +++ b/Source/Editor/Windows/Assets/CubeTextureWindow.cs @@ -27,7 +27,7 @@ namespace FlaxEditor.Windows.Assets private CubeTextureWindow _window; [EditorOrder(1000), EditorDisplay("Import Settings", EditorDisplayAttribute.InlineStyle)] - public TextureImportSettings ImportSettings = new TextureImportSettings(); + public FlaxEngine.Tools.TextureTool.Options ImportSettings = new(); public sealed class ProxyEditor : GenericEditor { @@ -69,7 +69,7 @@ namespace FlaxEditor.Windows.Assets _window = window; // Try to restore target asset texture import options (useful for fast reimport) - TextureImportSettings.TryRestore(ref ImportSettings, window.Item.Path); + Editor.TryRestoreImportOptions(ref ImportSettings, window.Item.Path); // Prepare restore data PeekState(); diff --git a/Source/Editor/Windows/Assets/ModelWindow.cs b/Source/Editor/Windows/Assets/ModelWindow.cs index cfb8e7f73..e44882b73 100644 --- a/Source/Editor/Windows/Assets/ModelWindow.cs +++ b/Source/Editor/Windows/Assets/ModelWindow.cs @@ -11,6 +11,7 @@ using FlaxEditor.Viewport.Cameras; using FlaxEditor.Viewport.Previews; using FlaxEngine; using FlaxEngine.GUI; +using FlaxEngine.Tools; using FlaxEngine.Utilities; using Object = FlaxEngine.Object; @@ -196,12 +197,12 @@ namespace FlaxEditor.Windows.Assets group.Label("No SDF"); } - var resolution = group.FloatValue("Resolution Scale", proxy.Window.Editor.CodeDocs.GetTooltip(typeof(ModelImportSettings), nameof(ModelImportSettings.SDFResolution))); + var resolution = group.FloatValue("Resolution Scale", proxy.Window.Editor.CodeDocs.GetTooltip(typeof(ModelTool.Options), nameof(ModelImportSettings.Settings.SDFResolution))); resolution.ValueBox.MinValue = 0.0001f; resolution.ValueBox.MaxValue = 100.0f; resolution.ValueBox.Value = sdf.Texture != null ? sdf.ResolutionScale : 1.0f; - resolution.ValueBox.BoxValueChanged += b => { proxy.Window._importSettings.SDFResolution = b.Value; }; - proxy.Window._importSettings.SDFResolution = sdf.ResolutionScale; + resolution.ValueBox.BoxValueChanged += b => { proxy.Window._importSettings.Settings.SDFResolution = b.Value; }; + proxy.Window._importSettings.Settings.SDFResolution = sdf.ResolutionScale; var backfacesThreshold = group.FloatValue("Backfaces Threshold", "Custom threshold (in range 0-1) for adjusting mesh internals detection based on the percentage of test rays hit triangle backfaces. Use lower value for more dense mesh."); backfacesThreshold.ValueBox.MinValue = 0.001f; @@ -293,7 +294,7 @@ namespace FlaxEditor.Windows.Assets private void OnRebuildSDF() { var proxy = (MeshesPropertiesProxy)Values[0]; - proxy.Asset.GenerateSDF(proxy.Window._importSettings.SDFResolution, _sdfModelLodIndex.Value, true, proxy.Window._backfacesThreshold); + proxy.Asset.GenerateSDF(proxy.Window._importSettings.Settings.SDFResolution, _sdfModelLodIndex.Value, true, proxy.Window._backfacesThreshold); proxy.Window.MarkAsEdited(); Presenter.BuildLayoutOnUpdate(); } @@ -919,7 +920,7 @@ namespace FlaxEditor.Windows.Assets { _refreshOnLODsLoaded = true; _preview.ViewportCamera.SetArcBallView(Asset.GetBox()); - ModelImportSettings.TryRestore(ref _importSettings, Item.Path); + Editor.TryRestoreImportOptions(ref _importSettings.Settings, Item.Path); UpdateEffectsOnAsset(); // TODO: disable streaming for this model diff --git a/Source/Editor/Windows/Assets/SkinnedModelWindow.cs b/Source/Editor/Windows/Assets/SkinnedModelWindow.cs index 7660c6c8e..d18593549 100644 --- a/Source/Editor/Windows/Assets/SkinnedModelWindow.cs +++ b/Source/Editor/Windows/Assets/SkinnedModelWindow.cs @@ -986,7 +986,7 @@ namespace FlaxEditor.Windows.Assets { base.OnLoad(window); - ModelImportSettings.TryRestore(ref ImportSettings, window.Item.Path); + Editor.TryRestoreImportOptions(ref ImportSettings.Settings, window.Item.Path); } public void Reimport() diff --git a/Source/Editor/Windows/Assets/SpriteAtlasWindow.cs b/Source/Editor/Windows/Assets/SpriteAtlasWindow.cs index ed739bfc9..7d09620d5 100644 --- a/Source/Editor/Windows/Assets/SpriteAtlasWindow.cs +++ b/Source/Editor/Windows/Assets/SpriteAtlasWindow.cs @@ -103,7 +103,7 @@ namespace FlaxEditor.Windows.Assets public SpriteEntry[] Sprites; [EditorOrder(1000), EditorDisplay("Import Settings", EditorDisplayAttribute.InlineStyle)] - public TextureImportSettings ImportSettings = new TextureImportSettings(); + public FlaxEngine.Tools.TextureTool.Options ImportSettings = new(); public sealed class ProxyEditor : GenericEditor { @@ -183,11 +183,7 @@ namespace FlaxEditor.Windows.Assets UpdateSprites(); // Try to restore target asset texture import options (useful for fast reimport) - if (TextureImportEntry.Internal_GetTextureImportOptions(win.Item.Path, out TextureImportSettings.InternalOptions options)) - { - // Restore settings - ImportSettings.FromInternal(ref options); - } + Editor.TryRestoreImportOptions(ref ImportSettings, win.Item.Path); // Prepare restore data PeekState(); diff --git a/Source/Editor/Windows/Assets/TextureWindow.cs b/Source/Editor/Windows/Assets/TextureWindow.cs index 16ee84c48..80786f1ed 100644 --- a/Source/Editor/Windows/Assets/TextureWindow.cs +++ b/Source/Editor/Windows/Assets/TextureWindow.cs @@ -70,7 +70,7 @@ namespace FlaxEditor.Windows.Assets internal TextureWindow _window; [EditorOrder(1000), EditorDisplay("Import Settings", EditorDisplayAttribute.InlineStyle)] - public TextureImportSettings ImportSettings = new TextureImportSettings(); + public FlaxEngine.Tools.TextureTool.Options ImportSettings = new(); /// /// Gathers parameters from the specified texture. @@ -82,7 +82,7 @@ namespace FlaxEditor.Windows.Assets _window = window; // Try to restore target asset texture import options (useful for fast reimport) - TextureImportSettings.TryRestore(ref ImportSettings, window.Item.Path); + Editor.TryRestoreImportOptions(ref ImportSettings, window.Item.Path); // Prepare restore data PeekState(); diff --git a/Source/Engine/ContentImporters/ImportAudio.cpp b/Source/Engine/ContentImporters/ImportAudio.cpp index a9955a4d4..10915b2d1 100644 --- a/Source/Engine/ContentImporters/ImportAudio.cpp +++ b/Source/Engine/ContentImporters/ImportAudio.cpp @@ -45,12 +45,11 @@ void ImportAudio::Options::Deserialize(DeserializeStream& stream, ISerializeModi DESERIALIZE(BitDepth); } -bool ImportAudio::TryGetImportOptions(const String& path, Options& options) +bool ImportAudio::TryGetImportOptions(const StringView& path, Options& options) { #if IMPORT_AUDIO_CACHE_OPTIONS if (FileSystem::FileExists(path)) { - // Try to load asset file and asset info auto tmpFile = ContentStorageManager::GetStorage(path); AssetInitData data; if (tmpFile @@ -64,13 +63,11 @@ bool ImportAudio::TryGetImportOptions(const String& path, Options& options) metadata.Parse(data.Metadata.Get(), data.Metadata.Length()); if (!metadata.HasParseError()) { - // Success options.Deserialize(metadata, nullptr); return true; } } } - #endif return false; } diff --git a/Source/Engine/ContentImporters/ImportAudio.h b/Source/Engine/ContentImporters/ImportAudio.h index 28c8a2e67..fb4ee64e3 100644 --- a/Source/Engine/ContentImporters/ImportAudio.h +++ b/Source/Engine/ContentImporters/ImportAudio.h @@ -45,7 +45,7 @@ public: /// The asset path. /// The options. /// True if success, otherwise false. - static bool TryGetImportOptions(const String& path, Options& options); + static bool TryGetImportOptions(const StringView& path, Options& options); /// /// Imports the audio data (with given audio decoder). diff --git a/Source/Engine/ContentImporters/ImportModel.h b/Source/Engine/ContentImporters/ImportModel.h index 6a39d0bb3..02e6bfc8d 100644 --- a/Source/Engine/ContentImporters/ImportModel.h +++ b/Source/Engine/ContentImporters/ImportModel.h @@ -28,7 +28,7 @@ public: /// The asset path. /// The options. /// True if success, otherwise false. - static bool TryGetImportOptions(String path, Options& options); + static bool TryGetImportOptions(const StringView& path, Options& options); /// /// Imports the model file. diff --git a/Source/Engine/ContentImporters/ImportModelFile.cpp b/Source/Engine/ContentImporters/ImportModelFile.cpp index 7e50770f1..b9a4f5675 100644 --- a/Source/Engine/ContentImporters/ImportModelFile.cpp +++ b/Source/Engine/ContentImporters/ImportModelFile.cpp @@ -16,11 +16,9 @@ #include "Engine/Platform/FileSystem.h" #include "AssetsImportingManager.h" -bool ImportModelFile::TryGetImportOptions(String path, Options& options) +bool ImportModelFile::TryGetImportOptions(const StringView& path, Options& options) { #if IMPORT_MODEL_CACHE_OPTIONS - - // Check if target asset file exists if (FileSystem::FileExists(path)) { // Try to load asset file and asset info @@ -41,15 +39,12 @@ bool ImportModelFile::TryGetImportOptions(String path, Options& options) metadata.Parse((const char*)data.Metadata.Get(), data.Metadata.Length()); if (metadata.HasParseError() == false) { - // Success options.Deserialize(metadata, nullptr); return true; } } } - #endif - return false; } diff --git a/Source/Engine/ContentImporters/ImportTexture.cpp b/Source/Engine/ContentImporters/ImportTexture.cpp index 278837729..51b93420c 100644 --- a/Source/Engine/ContentImporters/ImportTexture.cpp +++ b/Source/Engine/ContentImporters/ImportTexture.cpp @@ -1,9 +1,7 @@ // Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #include "ImportTexture.h" - #if COMPILE_WITH_ASSETS_IMPORTER - #include "Engine/Core/Log.h" #include "Engine/Serialization/Serialization.h" #include "Engine/Serialization/JsonWriters.h" @@ -28,11 +26,8 @@ bool IsSpriteAtlasOrTexture(const String& typeName) bool ImportTexture::TryGetImportOptions(const StringView& path, Options& options) { #if IMPORT_TEXTURE_CACHE_OPTIONS - - // Check if target asset texture exists if (FileSystem::FileExists(path)) { - // Try to load asset file and asset info (also check for Sprite Atlas or Texture assets) auto tmpFile = ContentStorageManager::GetStorage(path); AssetInitData data; if (tmpFile @@ -48,12 +43,11 @@ bool ImportTexture::TryGetImportOptions(const StringView& path, Options& options if (chunk15 != nullptr && !tmpFile->LoadAssetChunk(chunk15) && chunk15->Data.IsValid()) { MemoryReadStream stream(chunk15->Data.Get(), chunk15->Data.Length()); - - // Load tiles data int32 tilesVersion, tilesCount; stream.ReadInt32(&tilesVersion); if (tilesVersion == 1) { + options.Sprites.Clear(); stream.ReadInt32(&tilesCount); for (int32 i = 0; i < tilesCount; i++) { @@ -72,15 +66,12 @@ bool ImportTexture::TryGetImportOptions(const StringView& path, Options& options metadata.Parse((const char*)data.Metadata.Get(), data.Metadata.Length()); if (metadata.HasParseError() == false) { - // Success options.Deserialize(metadata, nullptr); return true; } } } - #endif - return false; } diff --git a/Source/Engine/Graphics/Models/Types.h b/Source/Engine/Graphics/Models/Types.h index 3568cbe76..b03d4948e 100644 --- a/Source/Engine/Graphics/Models/Types.h +++ b/Source/Engine/Graphics/Models/Types.h @@ -22,14 +22,20 @@ struct RenderView; /// /// Importing model lightmap UVs source /// -enum class ModelLightmapUVsSource +API_ENUM(Attributes="HideInEditor") enum class ModelLightmapUVsSource { + // No lightmap UVs. Disable = 0, + // Generate lightmap UVs from model geometry. Generate, + /// The texcoords channel 0. Channel0, + // The texcoords channel 1. Channel1, + // The texcoords channel 2. Channel2, - Channel3 + // The texcoords channel 3. + Channel3, }; /// diff --git a/Source/Engine/Graphics/Textures/Types.h b/Source/Engine/Graphics/Textures/Types.h index f261e83cb..9593cbbc2 100644 --- a/Source/Engine/Graphics/Textures/Types.h +++ b/Source/Engine/Graphics/Textures/Types.h @@ -2,14 +2,30 @@ #pragma once -#include "Engine/Core/Enums.h" #include "Engine/Core/Types/BaseTypes.h" #include "Engine/Graphics/PixelFormat.h" /// /// Describes texture compression format type /// -DECLARE_ENUM_EX_7(TextureFormatType, byte, 0, Unknown, ColorRGB, ColorRGBA, NormalMap, GrayScale, HdrRGBA, HdrRGB); +API_ENUM() enum class TextureFormatType : byte +{ + // Invalid value. + API_ENUM(Attributes="HideInEditor") + Unknown = 0, + // The color with RGB channels. + ColorRGB, + // The color with RGBA channels. + ColorRGBA, + // Normal map data (packed and compressed). + NormalMap, + // The gray scale (R channel). + GrayScale, + // The HDR color (RGBA channels). + HdrRGBA, + // The HDR color (RGB channels). + HdrRGB, +}; /// /// Old texture header structure (was not fully initialized to zero). diff --git a/Source/Engine/Tools/ModelTool/ModelTool.Options.cpp b/Source/Engine/Tools/ModelTool/ModelTool.Options.cpp deleted file mode 100644 index b7fb04855..000000000 --- a/Source/Engine/Tools/ModelTool/ModelTool.Options.cpp +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. - -#if COMPILE_WITH_MODEL_TOOL && USE_EDITOR - -#include "ModelTool.h" -#include "Engine/Core/Log.h" -#include "Engine/Serialization/Serialization.h" - -BoundingBox ImportedModelData::LOD::GetBox() const -{ - if (Meshes.IsEmpty()) - return BoundingBox::Empty; - - BoundingBox box; - Meshes[0]->CalculateBox(box); - for (int32 i = 1; i < Meshes.Count(); i++) - { - if (Meshes[i]->Positions.HasItems()) - { - BoundingBox t; - Meshes[i]->CalculateBox(t); - BoundingBox::Merge(box, t, box); - } - } - - return box; -} - -void ModelTool::Options::Serialize(SerializeStream& stream, const void* otherObj) -{ - SERIALIZE_GET_OTHER_OBJ(ModelTool::Options); - - SERIALIZE(Type); - SERIALIZE(CalculateNormals); - SERIALIZE(SmoothingNormalsAngle); - SERIALIZE(FlipNormals); - SERIALIZE(CalculateTangents); - SERIALIZE(SmoothingTangentsAngle); - SERIALIZE(OptimizeMeshes); - SERIALIZE(MergeMeshes); - SERIALIZE(ImportLODs); - SERIALIZE(ImportVertexColors); - SERIALIZE(ImportBlendShapes); - SERIALIZE(LightmapUVsSource); - SERIALIZE(CollisionMeshesPrefix); - SERIALIZE(Scale); - SERIALIZE(Rotation); - SERIALIZE(Translation); - SERIALIZE(CenterGeometry); - SERIALIZE(Duration); - SERIALIZE(FramesRange); - SERIALIZE(DefaultFrameRate); - SERIALIZE(SamplingRate); - SERIALIZE(SkipEmptyCurves); - SERIALIZE(OptimizeKeyframes); - SERIALIZE(ImportScaleTracks); - SERIALIZE(EnableRootMotion); - SERIALIZE(RootNodeName); - SERIALIZE(GenerateLODs); - SERIALIZE(BaseLOD); - SERIALIZE(LODCount); - SERIALIZE(TriangleReduction); - SERIALIZE(ImportMaterials); - SERIALIZE(ImportTextures); - SERIALIZE(RestoreMaterialsOnReimport); - SERIALIZE(GenerateSDF); - SERIALIZE(SDFResolution); - SERIALIZE(SplitObjects); - SERIALIZE(ObjectIndex); -} - -void ModelTool::Options::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) -{ - DESERIALIZE(Type); - DESERIALIZE(CalculateNormals); - DESERIALIZE(SmoothingNormalsAngle); - DESERIALIZE(FlipNormals); - DESERIALIZE(CalculateTangents); - DESERIALIZE(SmoothingTangentsAngle); - DESERIALIZE(OptimizeMeshes); - DESERIALIZE(MergeMeshes); - DESERIALIZE(ImportLODs); - DESERIALIZE(ImportVertexColors); - DESERIALIZE(ImportBlendShapes); - DESERIALIZE(LightmapUVsSource); - DESERIALIZE(CollisionMeshesPrefix); - DESERIALIZE(Scale); - DESERIALIZE(Rotation); - DESERIALIZE(Translation); - DESERIALIZE(CenterGeometry); - DESERIALIZE(Duration); - DESERIALIZE(FramesRange); - DESERIALIZE(DefaultFrameRate); - DESERIALIZE(SamplingRate); - DESERIALIZE(SkipEmptyCurves); - DESERIALIZE(OptimizeKeyframes); - DESERIALIZE(ImportScaleTracks); - DESERIALIZE(EnableRootMotion); - DESERIALIZE(RootNodeName); - DESERIALIZE(GenerateLODs); - DESERIALIZE(BaseLOD); - DESERIALIZE(LODCount); - DESERIALIZE(TriangleReduction); - DESERIALIZE(ImportMaterials); - DESERIALIZE(ImportTextures); - DESERIALIZE(RestoreMaterialsOnReimport); - DESERIALIZE(GenerateSDF); - DESERIALIZE(SDFResolution); - DESERIALIZE(SplitObjects); - DESERIALIZE(ObjectIndex); - - // [Deprecated on 23.11.2021, expires on 21.11.2023] - int32 AnimationIndex = -1; - DESERIALIZE(AnimationIndex); - if (AnimationIndex != -1) - ObjectIndex = AnimationIndex; -} - -#endif diff --git a/Source/Engine/Tools/ModelTool/ModelTool.cpp b/Source/Engine/Tools/ModelTool/ModelTool.cpp index c766f9525..f2dfd6927 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.cpp +++ b/Source/Engine/Tools/ModelTool/ModelTool.cpp @@ -31,6 +31,7 @@ #include "Engine/ContentImporters/AssetsImportingManager.h" #include "Engine/ContentImporters/CreateMaterial.h" #include "Engine/ContentImporters/CreateCollisionData.h" +#include "Engine/Serialization/Serialization.h" #include "Editor/Utilities/EditorUtilities.h" #include #endif @@ -328,6 +329,116 @@ bool ModelTool::GenerateModelSDF(Model* inputModel, ModelData* modelData, float #if USE_EDITOR +BoundingBox ImportedModelData::LOD::GetBox() const +{ + if (Meshes.IsEmpty()) + return BoundingBox::Empty; + + BoundingBox box; + Meshes[0]->CalculateBox(box); + for (int32 i = 1; i < Meshes.Count(); i++) + { + if (Meshes[i]->Positions.HasItems()) + { + BoundingBox t; + Meshes[i]->CalculateBox(t); + BoundingBox::Merge(box, t, box); + } + } + + return box; +} + +void ModelTool::Options::Serialize(SerializeStream& stream, const void* otherObj) +{ + SERIALIZE_GET_OTHER_OBJ(ModelTool::Options); + + SERIALIZE(Type); + SERIALIZE(CalculateNormals); + SERIALIZE(SmoothingNormalsAngle); + SERIALIZE(FlipNormals); + SERIALIZE(CalculateTangents); + SERIALIZE(SmoothingTangentsAngle); + SERIALIZE(OptimizeMeshes); + SERIALIZE(MergeMeshes); + SERIALIZE(ImportLODs); + SERIALIZE(ImportVertexColors); + SERIALIZE(ImportBlendShapes); + SERIALIZE(LightmapUVsSource); + SERIALIZE(CollisionMeshesPrefix); + SERIALIZE(Scale); + SERIALIZE(Rotation); + SERIALIZE(Translation); + SERIALIZE(CenterGeometry); + SERIALIZE(Duration); + SERIALIZE(FramesRange); + SERIALIZE(DefaultFrameRate); + SERIALIZE(SamplingRate); + SERIALIZE(SkipEmptyCurves); + SERIALIZE(OptimizeKeyframes); + SERIALIZE(ImportScaleTracks); + SERIALIZE(EnableRootMotion); + SERIALIZE(RootNodeName); + SERIALIZE(GenerateLODs); + SERIALIZE(BaseLOD); + SERIALIZE(LODCount); + SERIALIZE(TriangleReduction); + SERIALIZE(ImportMaterials); + SERIALIZE(ImportTextures); + SERIALIZE(RestoreMaterialsOnReimport); + SERIALIZE(GenerateSDF); + SERIALIZE(SDFResolution); + SERIALIZE(SplitObjects); + SERIALIZE(ObjectIndex); +} + +void ModelTool::Options::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) +{ + DESERIALIZE(Type); + DESERIALIZE(CalculateNormals); + DESERIALIZE(SmoothingNormalsAngle); + DESERIALIZE(FlipNormals); + DESERIALIZE(CalculateTangents); + DESERIALIZE(SmoothingTangentsAngle); + DESERIALIZE(OptimizeMeshes); + DESERIALIZE(MergeMeshes); + DESERIALIZE(ImportLODs); + DESERIALIZE(ImportVertexColors); + DESERIALIZE(ImportBlendShapes); + DESERIALIZE(LightmapUVsSource); + DESERIALIZE(CollisionMeshesPrefix); + DESERIALIZE(Scale); + DESERIALIZE(Rotation); + DESERIALIZE(Translation); + DESERIALIZE(CenterGeometry); + DESERIALIZE(Duration); + DESERIALIZE(FramesRange); + DESERIALIZE(DefaultFrameRate); + DESERIALIZE(SamplingRate); + DESERIALIZE(SkipEmptyCurves); + DESERIALIZE(OptimizeKeyframes); + DESERIALIZE(ImportScaleTracks); + DESERIALIZE(EnableRootMotion); + DESERIALIZE(RootNodeName); + DESERIALIZE(GenerateLODs); + DESERIALIZE(BaseLOD); + DESERIALIZE(LODCount); + DESERIALIZE(TriangleReduction); + DESERIALIZE(ImportMaterials); + DESERIALIZE(ImportTextures); + DESERIALIZE(RestoreMaterialsOnReimport); + DESERIALIZE(GenerateSDF); + DESERIALIZE(SDFResolution); + DESERIALIZE(SplitObjects); + DESERIALIZE(ObjectIndex); + + // [Deprecated on 23.11.2021, expires on 21.11.2023] + int32 AnimationIndex = -1; + DESERIALIZE(AnimationIndex); + if (AnimationIndex != -1) + ObjectIndex = AnimationIndex; +} + void RemoveNamespace(String& name) { const int32 namespaceStart = name.Find(':'); diff --git a/Source/Engine/Tools/ModelTool/ModelTool.h b/Source/Engine/Tools/ModelTool/ModelTool.h index b29bed71f..985bd3ccc 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.h +++ b/Source/Engine/Tools/ModelTool/ModelTool.h @@ -60,7 +60,6 @@ DECLARE_ENUM_OPERATORS(ImportDataTypes); class ImportedModelData { public: - struct LOD { Array Meshes; @@ -87,7 +86,6 @@ public: }; public: - /// /// The import data types types. /// @@ -124,7 +122,6 @@ public: AnimationData Animation; public: - /// /// Initializes a new instance of the class. /// @@ -179,83 +176,181 @@ struct ModelSDFMip }; /// -/// Models data importing and processing utility. +/// Models data importing and processing utility. /// -class FLAXENGINE_API ModelTool +API_CLASS(Namespace="FlaxEngine.Tools", Static) class FLAXENGINE_API ModelTool { -public: + DECLARE_SCRIPTING_TYPE_MINIMAL(ModelTool); // Optional: inputModel or modelData // Optional: outputSDF or null, outputStream or null static bool GenerateModelSDF(class Model* inputModel, class ModelData* modelData, float resolutionScale, int32 lodIndex, ModelBase::SDFData* outputSDF, class MemoryWriteStream* outputStream, const StringView& assetName, float backfacesThreshold = 0.6f); #if USE_EDITOR + public: /// /// Declares the imported data type. /// - DECLARE_ENUM_EX_3(ModelType, int32, 0, Model, SkinnedModel, Animation); + API_ENUM(Attributes="HideInEditor") enum class ModelType : int32 + { + // The model asset. + Model = 0, + // The skinned model asset. + SkinnedModel = 1, + // The animation asset. + Animation = 2, + }; /// /// Declares the imported animation clip duration. /// - DECLARE_ENUM_EX_2(AnimationDuration, int32, 0, Imported, Custom); + API_ENUM(Attributes="HideInEditor") enum class AnimationDuration : int32 + { + // The imported duration. + Imported = 0, + // The custom duration specified via keyframes range. + Custom = 1, + }; /// - /// Importing model options + /// Model import options. /// - struct Options : public ISerializable + API_STRUCT(Attributes="HideInEditor") struct FLAXENGINE_API Options : public ISerializable { + DECLARE_SCRIPTING_TYPE_MINIMAL(Options); + + // Type of the imported asset. + API_FIELD(Attributes="EditorOrder(0)") ModelType Type = ModelType::Model; - // Geometry - bool CalculateNormals = false; - float SmoothingNormalsAngle = 175.0f; - bool FlipNormals = false; - float SmoothingTangentsAngle = 45.0f; - bool CalculateTangents = false; - bool OptimizeMeshes = true; - bool MergeMeshes = true; - bool ImportLODs = true; - bool ImportVertexColors = true; - bool ImportBlendShapes = false; - ModelLightmapUVsSource LightmapUVsSource = ModelLightmapUVsSource::Disable; - String CollisionMeshesPrefix; + public: // Geometry - // Transform + // Enable model normal vectors recalculating. + API_FIELD(Attributes="EditorOrder(20), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowGeometry))") + bool CalculateNormals = false; + // Specifies the maximum angle (in degrees) that may be between two face normals at the same vertex position that their are smoothed together. The default value is 175. + API_FIELD(Attributes="EditorOrder(30), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowSmoothingNormalsAngle)), Limit(0, 175, 0.1f)") + float SmoothingNormalsAngle = 175.0f; + // If checked, the imported normal vectors of the mesh will be flipped (scaled by -1). + API_FIELD(Attributes="EditorOrder(35), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowGeometry))") + bool FlipNormals = false; + // Enable model tangent vectors recalculating. + API_FIELD(Attributes="EditorOrder(40), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowGeometry))") + bool CalculateTangents = false; + // Specifies the maximum angle (in degrees) that may be between two vertex tangents that their tangents and bi-tangents are smoothed. The default value is 45. + API_FIELD(Attributes="EditorOrder(45), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowSmoothingTangentsAngle)), Limit(0, 45, 0.1f)") + float SmoothingTangentsAngle = 45.0f; + // Enable/disable meshes geometry optimization. + API_FIELD(Attributes="EditorOrder(50), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowGeometry))") + bool OptimizeMeshes = true; + // Enable/disable geometry merge for meshes with the same materials. + API_FIELD(Attributes="EditorOrder(60), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowGeometry))") + bool MergeMeshes = true; + // Enable/disable importing meshes Level of Details. + API_FIELD(Attributes="EditorOrder(70), EditorDisplay(\"Geometry\", \"Import LODs\"), VisibleIf(nameof(ShowGeometry))") + bool ImportLODs = true; + // Enable/disable importing vertex colors (channel 0 only). + API_FIELD(Attributes="EditorOrder(80), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowModel))") + bool ImportVertexColors = true; + // Enable/disable importing blend shapes (morph targets). + API_FIELD(Attributes="EditorOrder(85), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowSkinnedModel))") + bool ImportBlendShapes = false; + // The lightmap UVs source. + API_FIELD(Attributes="EditorOrder(90), EditorDisplay(\"Geometry\", \"Lightmap UVs Source\"), VisibleIf(nameof(ShowModel))") + ModelLightmapUVsSource LightmapUVsSource = ModelLightmapUVsSource::Disable; + // If specified, all meshes which name starts with this prefix will be imported as a separate collision data (excluded used for rendering). + API_FIELD(Attributes="EditorOrder(100), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowGeometry))") + String CollisionMeshesPrefix = TEXT(""); + + public: // Transform + + // Custom uniform import scale. + API_FIELD(Attributes="EditorOrder(500), EditorDisplay(\"Transform\")") float Scale = 1.0f; + // Custom import geometry rotation. + API_FIELD(Attributes="EditorOrder(510), EditorDisplay(\"Transform\")") Quaternion Rotation = Quaternion::Identity; + // Custom import geometry offset. + API_FIELD(Attributes="EditorOrder(520), EditorDisplay(\"Transform\")") Float3 Translation = Float3::Zero; + // If checked, the imported geometry will be shifted to the center of mass. + API_FIELD(Attributes="EditorOrder(530), EditorDisplay(\"Transform\")") bool CenterGeometry = false; - // Animation - AnimationDuration Duration = AnimationDuration::Imported; - Float2 FramesRange = Float2::Zero; - float DefaultFrameRate = 0.0f; - float SamplingRate = 0.0f; - bool SkipEmptyCurves = true; - bool OptimizeKeyframes = true; - bool ImportScaleTracks = false; - bool EnableRootMotion = false; - String RootNodeName; + public: // Animation - // Level Of Detail + // Imported animation duration mode. Can use the original value or overriden by settings. + API_FIELD(Attributes="EditorOrder(1000), EditorDisplay(\"Animation\"), VisibleIf(nameof(ShowAnimation))") + AnimationDuration Duration = AnimationDuration::Imported; + // Imported animation first/last frame index. Used only if Duration mode is set to Custom. + API_FIELD(Attributes="EditorOrder(1010), EditorDisplay(\"Animation\"), VisibleIf(nameof(ShowFramesRange)), Limit(0)") + Float2 FramesRange = Float2::Zero; + // The imported animation default frame rate. Can specify the default frames per second amount for imported animation. If value is 0 then the original animation frame rate will be used. + API_FIELD(Attributes="EditorOrder(1020), EditorDisplay(\"Animation\"), VisibleIf(nameof(ShowAnimation)), Limit(0, 1000, 0.01f)") + float DefaultFrameRate = 0.0f; + // The imported animation sampling rate. If value is 0 then the original animation speed will be used. + API_FIELD(Attributes="EditorOrder(1030), EditorDisplay(\"Animation\"), VisibleIf(nameof(ShowAnimation)), Limit(0, 1000, 0.01f)") + float SamplingRate = 0.0f; + // The imported animation will have removed tracks with no keyframes or unspecified data. + API_FIELD(Attributes="EditorOrder(1040), EditorDisplay(\"Animation\"), VisibleIf(nameof(ShowAnimation))") + bool SkipEmptyCurves = true; + // The imported animation channels will be optimized to remove redundant keyframes. + API_FIELD(Attributes="EditorOrder(1050), EditorDisplay(\"Animation\"), VisibleIf(nameof(ShowAnimation))") + bool OptimizeKeyframes = true; + // If checked, the importer will import scale animation tracks (otherwise scale animation will be ignored). + API_FIELD(Attributes="EditorOrder(1055), EditorDisplay(\"Animation\"), VisibleIf(nameof(ShowAnimation))") + bool ImportScaleTracks = false; + // Enables root motion extraction support from this animation. + API_FIELD(Attributes="EditorOrder(1060), EditorDisplay(\"Animation\"), VisibleIf(nameof(ShowAnimation))") + bool EnableRootMotion = false; + // The custom node name to be used as a root motion source. If not specified the actual root node will be used. + API_FIELD(Attributes="EditorOrder(1070), EditorDisplay(\"Animation\"), VisibleIf(nameof(ShowAnimation))") + String RootNodeName = TEXT(""); + + public: // Level Of Detail + + // If checked, the importer will generate a sequence of LODs based on the base LOD index. + API_FIELD(Attributes="EditorOrder(1100), EditorDisplay(\"Level Of Detail\", \"Generate LODs\"), VisibleIf(nameof(ShowGeometry))") bool GenerateLODs = false; + // The index of the LOD from the source model data to use as a reference for following LODs generation. + API_FIELD(Attributes="EditorOrder(1110), EditorDisplay(\"Level Of Detail\", \"Base LOD\"), VisibleIf(nameof(ShowGeometry)), Limit(0, 5)") int32 BaseLOD = 0; + // The amount of LODs to include in the model (all remaining ones starting from Base LOD will be generated). + API_FIELD(Attributes="EditorOrder(1120), EditorDisplay(\"Level Of Detail\", \"LOD Count\"), VisibleIf(nameof(ShowGeometry)), Limit(1, 6)") int32 LODCount = 4; + // The target amount of triangles for the generated LOD (based on the higher LOD). Normalized to range 0-1. For instance 0.4 cuts the triangle count to 40%. + API_FIELD(Attributes="EditorOrder(1130), EditorDisplay(\"Level Of Detail\"), VisibleIf(nameof(ShowGeometry)), Limit(0, 1, 0.001f)") float TriangleReduction = 0.5f; - // Materials + public: // Materials + + // If checked, the importer will create materials for model meshes as specified in the file. + API_FIELD(Attributes="EditorOrder(400), EditorDisplay(\"Materials\"), VisibleIf(nameof(ShowGeometry))") bool ImportMaterials = true; + // If checked, the importer will import texture files used by the model and any embedded texture resources. + API_FIELD(Attributes="EditorOrder(410), EditorDisplay(\"Materials\"), VisibleIf(nameof(ShowGeometry))") bool ImportTextures = true; + // If checked, the importer will try to restore the model material slots. + API_FIELD(Attributes="EditorOrder(420), EditorDisplay(\"Materials\", \"Restore Materials On Reimport\"), VisibleIf(nameof(ShowGeometry))") bool RestoreMaterialsOnReimport = true; - // SDF + public: // SDF + + // If checked, enables generation of Signed Distance Field (SDF). + API_FIELD(Attributes="EditorOrder(1500), EditorDisplay(\"SDF\"), VisibleIf(nameof(ShowModel))") bool GenerateSDF = false; + // Resolution scale for generated Signed Distance Field (SDF) texture. Higher values improve accuracy but increase memory usage and reduce performance. + API_FIELD(Attributes="EditorOrder(1510), EditorDisplay(\"SDF\"), VisibleIf(nameof(ShowModel)), Limit(0.0001f, 100.0f)") float SDFResolution = 1.0f; - // Splitting + public: // Splitting + + // If checked, the imported mesh/animations are splitted into separate assets. Used if ObjectIndex is set to -1. + API_FIELD(Attributes="EditorOrder(2000), EditorDisplay(\"Splitting\")") bool SplitObjects = false; + // The zero-based index for the mesh/animation clip to import. If the source file has more than one mesh/animation it can be used to pick a desire object. Default -1 imports all objects. + API_FIELD(Attributes="EditorOrder(2010), EditorDisplay(\"Splitting\")") int32 ObjectIndex = -1; // Runtime data for objects splitting during import (used internally) @@ -263,14 +358,12 @@ public: Function OnSplitImport; public: - // [ISerializable] void Serialize(SerializeStream& stream, const void* otherObj) override; void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override; }; public: - /// /// Imports the model source file data. /// @@ -293,7 +386,6 @@ public: static bool ImportModel(const String& path, ModelData& meshData, Options& options, String& errorMsg, const String& autoImportOutput = String::Empty); public: - static int32 DetectLodIndex(const String& nodeName); static bool FindTexture(const String& sourcePath, const String& file, String& path); @@ -321,7 +413,6 @@ public: } private: - #if USE_ASSIMP static bool ImportDataAssimp(const char* path, ImportedModelData& data, Options& options, String& errorMsg); #endif diff --git a/Source/Engine/Tools/TextureTool/TextureTool.cpp b/Source/Engine/Tools/TextureTool/TextureTool.cpp index 8dc94deb3..0f9c8729c 100644 --- a/Source/Engine/Tools/TextureTool/TextureTool.cpp +++ b/Source/Engine/Tools/TextureTool/TextureTool.cpp @@ -12,6 +12,7 @@ #include "Engine/Platform/FileSystem.h" #include "Engine/Serialization/JsonWriter.h" #include "Engine/Serialization/JsonTools.h" +#include "Engine/Scripting/Enums.h" #include "Engine/Graphics/Textures/TextureData.h" #include "Engine/Graphics/PixelFormatExtensions.h" @@ -23,30 +24,10 @@ namespace } #endif -TextureTool::Options::Options() -{ - Type = TextureFormatType::ColorRGB; - IsAtlas = false; - NeverStream = false; - Compress = true; - IndependentChannels = false; - sRGB = false; - GenerateMipMaps = true; - FlipY = false; - Resize = false; - PreserveAlphaCoverage = false; - PreserveAlphaCoverageReference = 0.5f; - TextureGroup = -1; - Scale = 1.0f; - SizeX = 1024; - SizeY = 1024; - MaxSize = GPU_MAX_TEXTURE_SIZE; -} - String TextureTool::Options::ToString() const { return String::Format(TEXT("Type: {}, IsAtlas: {}, NeverStream: {}, IndependentChannels: {}, sRGB: {}, GenerateMipMaps: {}, FlipY: {}, Scale: {}, MaxSize: {}, Resize: {}, PreserveAlphaCoverage: {}, PreserveAlphaCoverageReference: {}, SizeX: {}, SizeY: {}"), - ::ToString(Type), + ScriptingEnum::ToString(Type), IsAtlas, NeverStream, IndependentChannels, diff --git a/Source/Engine/Tools/TextureTool/TextureTool.h b/Source/Engine/Tools/TextureTool/TextureTool.h index b71c6555b..f21025bf6 100644 --- a/Source/Engine/Tools/TextureTool/TextureTool.h +++ b/Source/Engine/Tools/TextureTool/TextureTool.h @@ -14,128 +14,97 @@ class JsonWriter; /// /// Textures importing, processing and exporting utilities. /// -class FLAXENGINE_API TextureTool +API_CLASS(Namespace="FlaxEngine.Tools", Static) class FLAXENGINE_API TextureTool { -public: + DECLARE_SCRIPTING_TYPE_MINIMAL(TextureTool); /// - /// Importing texture options + /// Texture import options. /// - struct Options : public ISerializable + API_STRUCT(Attributes="HideInEditor") struct FLAXENGINE_API Options : public ISerializable { - /// - /// Texture format type - /// - TextureFormatType Type; + DECLARE_SCRIPTING_TYPE_MINIMAL(Options); - /// - /// True if texture should be imported as a texture atlas resource - /// - bool IsAtlas; + // Texture format type. + API_FIELD(Attributes="EditorOrder(0)") + TextureFormatType Type = TextureFormatType::ColorRGB; - /// - /// True if disable dynamic texture streaming - /// - bool NeverStream; + // True if texture should be imported as a texture atlas (with sprites). + API_FIELD(Attributes="EditorOrder(10)") + bool IsAtlas = false; - /// - /// Enables/disables texture data compression. - /// - bool Compress; + // True if disable dynamic texture streaming. + API_FIELD(Attributes="EditorOrder(20)") + bool NeverStream = false; - /// - /// True if texture channels have independent data - /// - bool IndependentChannels; + // True if disable dynamic texture streaming. + API_FIELD(Attributes="EditorOrder(30)") + bool Compress = true; - /// - /// True if use sRGB format for texture data. Recommended for color maps and diffuse color textures. - /// - bool sRGB; + // True if texture channels have independent data (for compression methods). + API_FIELD(Attributes="EditorOrder(40)") + bool IndependentChannels = false; - /// - /// True if generate mip maps chain for the texture. - /// - bool GenerateMipMaps; + // True if use sRGB format for texture data. Recommended for color maps and diffuse color textures. + API_FIELD(Attributes="EditorOrder(50), EditorDisplay(null, \"sRGB\")") + bool sRGB = false; - /// - /// True if flip Y coordinate of the texture. - /// - bool FlipY; + // True if generate mip maps chain for the texture. + API_FIELD(Attributes="EditorOrder(60)") + bool GenerateMipMaps = true; - /// - /// True if resize the texture. - /// - bool Resize; + // True if flip Y coordinate of the texture. + API_FIELD(Attributes="EditorOrder(70)") + bool FlipY = false; - /// - /// True if preserve alpha coverage in generated mips for alpha test reference. Scales mipmap alpha values to preserve alpha coverage based on an alpha test reference value. - /// - bool PreserveAlphaCoverage; + // Texture size scale. Default is 1. + API_FIELD(Attributes="EditorOrder(80), Limit(0.0001f, 1000.0f, 0.01f)") + float Scale = 1.0f; - /// - /// The reference value for the alpha coverage preserving. - /// - float PreserveAlphaCoverageReference; + // Maximum size of the texture (for both width and height). Higher resolution textures will be resized during importing process. + API_FIELD(Attributes="HideInEditor") + int32 MaxSize = 8192; - /// - /// Texture group for streaming (negative if unused). See Streaming Settings. - /// - int32 TextureGroup; + // True if resize texture on import. Use SizeX/SizeY properties to define texture width and height. Texture scale property will be ignored. + API_FIELD(Attributes="EditorOrder(100)") + bool Resize = false; - /// - /// The import texture scale. - /// - float Scale; + // The width of the imported texture. If Resize property is set to true then texture will be resized during the import to this value. Otherwise it will be ignored. + API_FIELD(Attributes="HideInEditor") + int32 SizeX = 1024; - /// - /// Custom texture size X, use only if Resize texture flag is set. - /// - int32 SizeX; + // The height of the imported texture. If Resize property is set to true then texture will be resized during the import to this value. Otherwise it will be ignored. + API_FIELD(Attributes="HideInEditor") + int32 SizeY = 1024; - /// - /// Custom texture size Y, use only if Resize texture flag is set. - /// - int32 SizeY; + // Check to preserve alpha coverage in generated mips for alpha test reference. Scales mipmap alpha values to preserve alpha coverage based on an alpha test reference value. + API_FIELD(Attributes="EditorOrder(200)") + bool PreserveAlphaCoverage = false; - /// - /// Maximum size of the texture (for both width and height). - /// Higher resolution textures will be resized during importing process. - /// - int32 MaxSize; + // The reference value for the alpha coverage preserving. + API_FIELD(Attributes="EditorOrder(210), VisibleIf(\"PreserveAlphaCoverage\")") + float PreserveAlphaCoverageReference = 0.5f; - /// - /// Function used for fast importing textures used by internal parts of the engine - /// - Function InternalLoad; + // Texture group for streaming (negative if unused). See Streaming Settings. + API_FIELD(Attributes="EditorOrder(300), CustomEditor(typeof(FlaxEditor.CustomEditors.Dedicated.TextureGroupEditor))") + int32 TextureGroup = -1; - /// - /// The sprites for the sprite sheet import mode. - /// + // The sprites for the sprite sheet import mode. + API_FIELD(Attributes="HideInEditor") Array Sprites; + // Function used for fast importing textures used by internal parts of the engine + Function InternalLoad; + public: - - /// - /// Init - /// - Options(); - - /// - /// Gets string that contains information about options - /// - /// String String ToString() const; - public: - // [ISerializable] void Serialize(SerializeStream& stream, const void* otherObj) override; void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override; }; public: - #if USE_EDITOR /// @@ -193,7 +162,6 @@ public: static bool Resize(TextureData& dst, const TextureData& src, int32 dstWidth, int32 dstHeight); public: - typedef Color (*ReadPixel)(const void*); typedef void (*WritePixel)(const void*, const Color&); @@ -269,7 +237,6 @@ public: static Color SampleLinear(const PixelFormatSampler* sampler, const Float2& uv, const void* data, const Int2& size, int32 rowPitch); private: - enum class ImageType { DDS, diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs index eb35e475b..3250a3262 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs @@ -1416,13 +1416,12 @@ namespace Flax.Build.Bindings toManagedContent.Append($"return new {structureInfo.Name}() {{ "); bool useSeparator = false; + contents.AppendLine(); foreach (var fieldInfo in structureInfo.Fields) { if (fieldInfo.IsStatic || fieldInfo.IsConstexpr) continue; - contents.AppendLine(); - string type, originalType; if (fieldInfo.Type.IsArray && (fieldInfo.NoArray || structureInfo.IsPod)) {