mirror of
https://github.com/AssetRipper/AssetRipper.git
synced 2025-12-11 20:15:29 +01:00
Add setting for lightmap texture format
This commit is contained in:
parent
08327b9a08
commit
f937b982ee
@ -96,6 +96,8 @@
|
||||
"json": "Json",
|
||||
"length": "Length",
|
||||
"licenses": "Licenses",
|
||||
"lightmap_texture_export_title": "Lightmap Texture Export Format",
|
||||
"lightmap_texture_format_description": "This affects all exported lightmap textures.",
|
||||
"load": "Load",
|
||||
"loading_game_content_from": "Loading Game Content From {0}\n{1}",
|
||||
"loading_step_begin_scheme_processing": "Starting Scheme Processing",
|
||||
|
||||
@ -14,6 +14,11 @@ public sealed record class ExportSettings
|
||||
/// </summary>
|
||||
public ImageExportFormat ImageExportFormat { get; set; } = ImageExportFormat.Png;
|
||||
|
||||
/// <summary>
|
||||
/// The file format that images (like textures) get exported in.
|
||||
/// </summary>
|
||||
public LightmapTextureExportFormat LightmapTextureExportFormat { get; set; } = LightmapTextureExportFormat.Yaml;
|
||||
|
||||
/// <summary>
|
||||
/// The format that meshes get exported in. Recommended: Native
|
||||
/// </summary>
|
||||
@ -55,6 +60,7 @@ public sealed record class ExportSettings
|
||||
{
|
||||
Logger.Info(LogCategory.General, $"{nameof(AudioExportFormat)}: {AudioExportFormat}");
|
||||
Logger.Info(LogCategory.General, $"{nameof(ImageExportFormat)}: {ImageExportFormat}");
|
||||
Logger.Info(LogCategory.General, $"{nameof(LightmapTextureExportFormat)}: {LightmapTextureExportFormat}");
|
||||
Logger.Info(LogCategory.General, $"{nameof(MeshExportFormat)}: {MeshExportFormat}");
|
||||
Logger.Info(LogCategory.General, $"{nameof(ScriptExportMode)}: {ScriptExportMode}");
|
||||
Logger.Info(LogCategory.General, $"{nameof(ScriptLanguageVersion)}: {ScriptLanguageVersion}");
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
namespace AssetRipper.Export.UnityProjects.Configuration;
|
||||
|
||||
public enum LightmapTextureExportFormat
|
||||
{
|
||||
/// <summary>
|
||||
/// Use <see cref="ImageExportFormat.Exr"/>
|
||||
/// </summary>
|
||||
Exr,
|
||||
/// <summary>
|
||||
/// Use <see cref="ExportSettings.ImageExportFormat"/>
|
||||
/// </summary>
|
||||
Image,
|
||||
/// <summary>
|
||||
/// The internal Unity format
|
||||
/// </summary>
|
||||
Yaml,
|
||||
}
|
||||
@ -109,6 +109,12 @@ partial class ProjectExporter
|
||||
OverrideExporter<ISprite>(spriteExporter);
|
||||
OverrideExporter<ISpriteAtlas>(spriteExporter);
|
||||
}
|
||||
if (settings.ExportSettings.LightmapTextureExportFormat is not LightmapTextureExportFormat.Yaml)
|
||||
{
|
||||
OverrideExporter<ITexture2D>(new LightmapTextureAssetExporter(settings.ExportSettings.LightmapTextureExportFormat is LightmapTextureExportFormat.Exr
|
||||
? ImageExportFormat.Exr
|
||||
: settings.ExportSettings.ImageExportFormat));
|
||||
}
|
||||
|
||||
//Texture Array exporters
|
||||
if (settings.Version.GreaterThanOrEquals(2020, 2))
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
using AssetRipper.Assets;
|
||||
using AssetRipper.Assets.Export;
|
||||
using AssetRipper.Export.UnityProjects.Configuration;
|
||||
using AssetRipper.Import.Logging;
|
||||
using AssetRipper.SourceGenerated.Classes.ClassID_1120;
|
||||
using AssetRipper.SourceGenerated.Classes.ClassID_28;
|
||||
using AssetRipper.SourceGenerated.Extensions;
|
||||
using DirectBitmap = AssetRipper.Export.UnityProjects.Utils.DirectBitmap<AssetRipper.TextureDecoder.Rgb.Formats.ColorBGRA32, byte>;
|
||||
|
||||
namespace AssetRipper.Export.UnityProjects.Textures;
|
||||
|
||||
public class LightmapTextureAssetExporter : BinaryAssetExporter
|
||||
{
|
||||
public ImageExportFormat ImageExportFormat { get; private set; }
|
||||
|
||||
public LightmapTextureAssetExporter(ImageExportFormat imageExportFormat)
|
||||
{
|
||||
ImageExportFormat = imageExportFormat;
|
||||
}
|
||||
|
||||
public override bool TryCreateCollection(IUnityObjectBase asset, [NotNullWhen(true)] out IExportCollection? exportCollection)
|
||||
{
|
||||
if (asset.MainAsset is ILightingDataAsset)
|
||||
{
|
||||
exportCollection = new AssetExportCollection<IUnityObjectBase>(this, asset);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
exportCollection = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Export(IExportContainer container, IUnityObjectBase asset, string path)
|
||||
{
|
||||
ITexture2D texture = (ITexture2D)asset;
|
||||
if (!texture.CheckAssetIntegrity())
|
||||
{
|
||||
Logger.Log(LogType.Warning, LogCategory.Export, $"Can't export '{texture.Name}' because resources file '{texture.StreamData_C28?.Path}' hasn't been found");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TextureConverter.TryConvertToBitmap(texture, out DirectBitmap bitmap))
|
||||
{
|
||||
using FileStream stream = File.Create(path);
|
||||
bitmap.Save(stream, ImageExportFormat);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Log(LogType.Warning, LogCategory.Export, $"Unable to convert '{texture.Name}' to bitmap");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -494,6 +494,16 @@ partial class Localization
|
||||
/// </summary>
|
||||
public static string Licenses => Get("licenses");
|
||||
|
||||
/// <summary>
|
||||
/// Lightmap Texture Export Format
|
||||
/// </summary>
|
||||
public static string LightmapTextureExportTitle => Get("lightmap_texture_export_title");
|
||||
|
||||
/// <summary>
|
||||
/// This affects all exported lightmap textures.
|
||||
/// </summary>
|
||||
public static string LightmapTextureFormatDescription => Get("lightmap_texture_format_description");
|
||||
|
||||
/// <summary>
|
||||
/// Load
|
||||
/// </summary>
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
using AssetRipper.Export.UnityProjects.Configuration;
|
||||
|
||||
namespace AssetRipper.GUI.Web.Pages.Settings.DropDown;
|
||||
|
||||
public sealed class LightmapTextureExportFormatDropDownSetting : DropDownSetting<LightmapTextureExportFormat>
|
||||
{
|
||||
public static LightmapTextureExportFormatDropDownSetting Instance { get; } = new();
|
||||
|
||||
public override string Title => Localization.LightmapTextureExportTitle;
|
||||
|
||||
protected override string? GetDescription(LightmapTextureExportFormat value)
|
||||
{
|
||||
return Localization.LightmapTextureFormatDescription;
|
||||
}
|
||||
}
|
||||
@ -113,7 +113,7 @@ public sealed partial class SettingsPage : DefaultPage
|
||||
|
||||
using (new Div(writer).WithClass("col").End())
|
||||
{
|
||||
WriteDropDownForMeshExportFormat(writer);
|
||||
WriteDropDownForLightmapTextureExportFormat(writer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,6 +153,7 @@ public sealed partial class SettingsPage : DefaultPage
|
||||
{
|
||||
using (new Div(writer).WithClass("col").End())
|
||||
{
|
||||
WriteDropDownForMeshExportFormat(writer);
|
||||
}
|
||||
using (new Div(writer).WithClass("col").End())
|
||||
{
|
||||
|
||||
@ -32,6 +32,9 @@ partial class SettingsPage
|
||||
case nameof(ExportSettings.ImageExportFormat):
|
||||
Configuration.ExportSettings.ImageExportFormat = TryParseEnum<ImageExportFormat>(value);
|
||||
break;
|
||||
case nameof(ExportSettings.LightmapTextureExportFormat):
|
||||
Configuration.ExportSettings.LightmapTextureExportFormat = TryParseEnum<LightmapTextureExportFormat>(value);
|
||||
break;
|
||||
case nameof(ExportSettings.MeshExportFormat):
|
||||
Configuration.ExportSettings.MeshExportFormat = TryParseEnum<MeshExportFormat>(value);
|
||||
break;
|
||||
@ -110,6 +113,11 @@ partial class SettingsPage
|
||||
WriteDropDown(writer, ImageExportFormatDropDownSetting.Instance, Configuration.ExportSettings.ImageExportFormat, nameof(ExportSettings.ImageExportFormat));
|
||||
}
|
||||
|
||||
private static void WriteDropDownForLightmapTextureExportFormat(TextWriter writer)
|
||||
{
|
||||
WriteDropDown(writer, LightmapTextureExportFormatDropDownSetting.Instance, Configuration.ExportSettings.LightmapTextureExportFormat, nameof(ExportSettings.LightmapTextureExportFormat));
|
||||
}
|
||||
|
||||
private static void WriteDropDownForMeshExportFormat(TextWriter writer)
|
||||
{
|
||||
WriteDropDown(writer, MeshExportFormatDropDownSetting.Instance, Configuration.ExportSettings.MeshExportFormat, nameof(ExportSettings.MeshExportFormat));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user