Refactor various Editor APIs to use auto-generated bindings instead of manual code

This commit is contained in:
Wojtek Figat
2023-06-12 14:34:07 +02:00
parent 7140c4a2d8
commit 979168e82c
26 changed files with 611 additions and 1899 deletions

View File

@@ -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

View File

@@ -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 <ThirdParty/meshoptimizer/meshoptimizer.h>
#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(':');

View File

@@ -60,7 +60,6 @@ DECLARE_ENUM_OPERATORS(ImportDataTypes);
class ImportedModelData
{
public:
struct LOD
{
Array<MeshData*> Meshes;
@@ -87,7 +86,6 @@ public:
};
public:
/// <summary>
/// The import data types types.
/// </summary>
@@ -124,7 +122,6 @@ public:
AnimationData Animation;
public:
/// <summary>
/// Initializes a new instance of the <see cref="ImportedModelData"/> class.
/// </summary>
@@ -179,83 +176,181 @@ struct ModelSDFMip
};
/// <summary>
/// Models data importing and processing utility.
/// Models data importing and processing utility.
/// </summary>
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:
/// <summary>
/// Declares the imported data type.
/// </summary>
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,
};
/// <summary>
/// Declares the imported animation clip duration.
/// </summary>
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,
};
/// <summary>
/// Importing model options
/// Model import options.
/// </summary>
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<bool(Options& splitOptions, const String& objectName)> OnSplitImport;
public:
// [ISerializable]
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
};
public:
/// <summary>
/// Imports the model source file data.
/// </summary>
@@ -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

View File

@@ -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,

View File

@@ -14,128 +14,97 @@ class JsonWriter;
/// <summary>
/// Textures importing, processing and exporting utilities.
/// </summary>
class FLAXENGINE_API TextureTool
API_CLASS(Namespace="FlaxEngine.Tools", Static) class FLAXENGINE_API TextureTool
{
public:
DECLARE_SCRIPTING_TYPE_MINIMAL(TextureTool);
/// <summary>
/// Importing texture options
/// Texture import options.
/// </summary>
struct Options : public ISerializable
API_STRUCT(Attributes="HideInEditor") struct FLAXENGINE_API Options : public ISerializable
{
/// <summary>
/// Texture format type
/// </summary>
TextureFormatType Type;
DECLARE_SCRIPTING_TYPE_MINIMAL(Options);
/// <summary>
/// True if texture should be imported as a texture atlas resource
/// </summary>
bool IsAtlas;
// Texture format type.
API_FIELD(Attributes="EditorOrder(0)")
TextureFormatType Type = TextureFormatType::ColorRGB;
/// <summary>
/// True if disable dynamic texture streaming
/// </summary>
bool NeverStream;
// True if texture should be imported as a texture atlas (with sprites).
API_FIELD(Attributes="EditorOrder(10)")
bool IsAtlas = false;
/// <summary>
/// Enables/disables texture data compression.
/// </summary>
bool Compress;
// True if disable dynamic texture streaming.
API_FIELD(Attributes="EditorOrder(20)")
bool NeverStream = false;
/// <summary>
/// True if texture channels have independent data
/// </summary>
bool IndependentChannels;
// True if disable dynamic texture streaming.
API_FIELD(Attributes="EditorOrder(30)")
bool Compress = true;
/// <summary>
/// True if use sRGB format for texture data. Recommended for color maps and diffuse color textures.
/// </summary>
bool sRGB;
// True if texture channels have independent data (for compression methods).
API_FIELD(Attributes="EditorOrder(40)")
bool IndependentChannels = false;
/// <summary>
/// True if generate mip maps chain for the texture.
/// </summary>
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;
/// <summary>
/// True if flip Y coordinate of the texture.
/// </summary>
bool FlipY;
// True if generate mip maps chain for the texture.
API_FIELD(Attributes="EditorOrder(60)")
bool GenerateMipMaps = true;
/// <summary>
/// True if resize the texture.
/// </summary>
bool Resize;
// True if flip Y coordinate of the texture.
API_FIELD(Attributes="EditorOrder(70)")
bool FlipY = false;
/// <summary>
/// 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.
/// </summary>
bool PreserveAlphaCoverage;
// Texture size scale. Default is 1.
API_FIELD(Attributes="EditorOrder(80), Limit(0.0001f, 1000.0f, 0.01f)")
float Scale = 1.0f;
/// <summary>
/// The reference value for the alpha coverage preserving.
/// </summary>
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;
/// <summary>
/// Texture group for streaming (negative if unused). See Streaming Settings.
/// </summary>
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;
/// <summary>
/// The import texture scale.
/// </summary>
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;
/// <summary>
/// Custom texture size X, use only if Resize texture flag is set.
/// </summary>
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;
/// <summary>
/// Custom texture size Y, use only if Resize texture flag is set.
/// </summary>
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;
/// <summary>
/// Maximum size of the texture (for both width and height).
/// Higher resolution textures will be resized during importing process.
/// </summary>
int32 MaxSize;
// The reference value for the alpha coverage preserving.
API_FIELD(Attributes="EditorOrder(210), VisibleIf(\"PreserveAlphaCoverage\")")
float PreserveAlphaCoverageReference = 0.5f;
/// <summary>
/// Function used for fast importing textures used by internal parts of the engine
/// </summary>
Function<bool(TextureData&)> 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;
/// <summary>
/// The sprites for the sprite sheet import mode.
/// </summary>
// The sprites for the sprite sheet import mode.
API_FIELD(Attributes="HideInEditor")
Array<Sprite> Sprites;
// Function used for fast importing textures used by internal parts of the engine
Function<bool(TextureData&)> InternalLoad;
public:
/// <summary>
/// Init
/// </summary>
Options();
/// <summary>
/// Gets string that contains information about options
/// </summary>
/// <returns>String</returns>
String ToString() const;
public:
// [ISerializable]
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
};
public:
#if USE_EDITOR
/// <summary>
@@ -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,