diff --git a/Analyzer/Properties/Resources.Designer.cs b/Analyzer/Properties/Resources.Designer.cs index 487a20a..e84501f 100644 --- a/Analyzer/Properties/Resources.Designer.cs +++ b/Analyzer/Properties/Resources.Designer.cs @@ -274,6 +274,7 @@ internal static string Shader { /// id INTEGER, /// width INTEGER, /// height INTEGER, + /// image_count INTEGER, /// format INTEGER, /// mip_count INTEGER, /// rw_enabled INTEGER, @@ -285,6 +286,7 @@ internal static string Shader { /// o.*, /// t.width, /// t.height, + /// t.image_count, /// f.name AS format, /// t.mip_count, /// t.rw_enabled @@ -297,5 +299,45 @@ internal static string Texture2D { return ResourceManager.GetString("Texture2D", resourceCulture); } } + + /// + /// Looks up a localized string similar to --CREATE TABLE texture_formats + ///--( + ///-- id INTEGER, + ///-- name TEXT, + ///-- PRIMARY KEY (id) + ///--); + /// + ///CREATE TABLE video_clips + ///( + /// id INTEGER, + /// width INTEGER, + /// height INTEGER, + /// format INTEGER, + /// frame_rate REAL, + /// frame_count INTEGER, + /// PRIMARY KEY (id) + ///); + /// + ///CREATE VIEW video_clip_view AS + ///SELECT + /// o.*, + /// v.width, + /// v.height, + /// v.frame_rate, + /// v.frame_count, + /// v.format + ///FROM object_view o + ///INNER JOIN video_clips v ON o.id = v.id + /// + ///--INSERT INTO texture_formats (id, name) + ///--VALUES + ///--(0, [rest of string was truncated]";. + /// + internal static string VideoClip { + get { + return ResourceManager.GetString("VideoClip", resourceCulture); + } + } } } diff --git a/Analyzer/Properties/Resources.resx b/Analyzer/Properties/Resources.resx index 1144559..7fe5eb4 100644 --- a/Analyzer/Properties/Resources.resx +++ b/Analyzer/Properties/Resources.resx @@ -142,4 +142,7 @@ ..\Resources\Texture2D.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + ..\Resources\VideoClip.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + \ No newline at end of file diff --git a/Analyzer/Resources/Texture2D.sql b/Analyzer/Resources/Texture2D.sql index 5a9ba02..1a7d4eb 100644 --- a/Analyzer/Resources/Texture2D.sql +++ b/Analyzer/Resources/Texture2D.sql @@ -10,6 +10,7 @@ CREATE TABLE textures id INTEGER, width INTEGER, height INTEGER, + image_count INTEGER, format INTEGER, mip_count INTEGER, rw_enabled INTEGER, @@ -21,6 +22,7 @@ SELECT o.*, t.width, t.height, + t.image_count, f.name AS format, t.mip_count, t.rw_enabled diff --git a/Analyzer/Resources/VideoClip.sql b/Analyzer/Resources/VideoClip.sql new file mode 100644 index 0000000..b2763ce --- /dev/null +++ b/Analyzer/Resources/VideoClip.sql @@ -0,0 +1,19 @@ +CREATE TABLE video_clips +( + id INTEGER, + width INTEGER, + height INTEGER, + frame_rate REAL, + frame_count INTEGER, + PRIMARY KEY (id) +); + +CREATE VIEW video_clip_view AS +SELECT + o.*, + v.width, + v.height, + v.frame_rate, + v.frame_count +FROM object_view o +INNER JOIN video_clips v ON o.id = v.id diff --git a/Analyzer/SQLite/Handlers/Texture2DHandler.cs b/Analyzer/SQLite/Handlers/Texture2DHandler.cs index dfa9103..a22609c 100644 --- a/Analyzer/SQLite/Handlers/Texture2DHandler.cs +++ b/Analyzer/SQLite/Handlers/Texture2DHandler.cs @@ -10,19 +10,29 @@ namespace UnityDataTools.Analyzer.SQLite.Handlers; public class Texture2DHandler : ISQLiteHandler { SQLiteCommand m_InsertCommand; + bool m_skipCreateDatabase; + + public Texture2DHandler(bool skipCreateDatabase) + { + m_skipCreateDatabase = skipCreateDatabase; + } public void Init(SQLiteConnection db) { - using var command = new SQLiteCommand(db); + if (!m_skipCreateDatabase) + { + using var command = new SQLiteCommand(db); - command.CommandText = Properties.Resources.Texture2D; - command.ExecuteNonQuery(); + command.CommandText = Properties.Resources.Texture2D; + command.ExecuteNonQuery(); + } m_InsertCommand = new SQLiteCommand(db); - m_InsertCommand.CommandText = "INSERT INTO textures(id, width, height, format, rw_enabled, mip_count) VALUES(@id, @width, @height, @format, @rw_enabled, @mip_count)"; + m_InsertCommand.CommandText = "INSERT INTO textures(id, width, height, image_count, format, rw_enabled, mip_count) VALUES(@id, @width, @height, @image_count, @format, @rw_enabled, @mip_count)"; m_InsertCommand.Parameters.Add("@id", DbType.Int64); m_InsertCommand.Parameters.Add("@width", DbType.Int32); m_InsertCommand.Parameters.Add("@height", DbType.Int32); + m_InsertCommand.Parameters.Add("@image_count", DbType.Int32); m_InsertCommand.Parameters.Add("@format", DbType.Int32); m_InsertCommand.Parameters.Add("@rw_enabled", DbType.Int32); m_InsertCommand.Parameters.Add("@mip_count", DbType.Int32); @@ -35,6 +45,7 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s m_InsertCommand.Parameters["@id"].Value = objectId; m_InsertCommand.Parameters["@width"].Value = texture2d.Width; m_InsertCommand.Parameters["@height"].Value = texture2d.Height; + m_InsertCommand.Parameters["@image_count"].Value = texture2d.ImageCount; m_InsertCommand.Parameters["@format"].Value = texture2d.Format; m_InsertCommand.Parameters["@rw_enabled"].Value = texture2d.RwEnabled; m_InsertCommand.Parameters["@mip_count"].Value = texture2d.MipCount; diff --git a/Analyzer/SQLite/Handlers/VideoClipHandler.cs b/Analyzer/SQLite/Handlers/VideoClipHandler.cs new file mode 100644 index 0000000..b5876a4 --- /dev/null +++ b/Analyzer/SQLite/Handlers/VideoClipHandler.cs @@ -0,0 +1,53 @@ +using System; +using System.Data; +using System.Data.SQLite; +using UnityDataTools.Analyzer.SerializedObjects; +using UnityDataTools.FileSystem.TypeTreeReaders; + +namespace UnityDataTools.Analyzer.SQLite.Handlers; + +public class VideoClipHandler : ISQLiteHandler +{ + SQLiteCommand m_InsertCommand; + + public void Init(SQLiteConnection db) + { + using var command = new SQLiteCommand(db); + + command.CommandText = Properties.Resources.VideoClip; + command.ExecuteNonQuery(); + + m_InsertCommand = new SQLiteCommand(db); + m_InsertCommand.CommandText = "INSERT INTO video_clips(id, width, height, frame_rate, frame_count) VALUES(@id, @width, @height, @frame_rate, @frame_count)"; + m_InsertCommand.Parameters.Add("@id", DbType.Int64); + m_InsertCommand.Parameters.Add("@width", DbType.UInt32); + m_InsertCommand.Parameters.Add("@height", DbType.UInt32); + m_InsertCommand.Parameters.Add("@frame_rate", DbType.Double); + m_InsertCommand.Parameters.Add("@frame_count", DbType.UInt64); + } + + public void Process(Context ctx, long objectId, RandomAccessReader reader, out string name, out long streamDataSize) + { + var videoClip = VideoClip.Read(reader); + + m_InsertCommand.Parameters["@id"].Value = objectId; + m_InsertCommand.Parameters["@width"].Value = videoClip.Width; + m_InsertCommand.Parameters["@height"].Value = videoClip.Height; + m_InsertCommand.Parameters["@frame_rate"].Value = videoClip.FrameRate; + m_InsertCommand.Parameters["@frame_count"].Value = videoClip.FrameCount; + + m_InsertCommand.ExecuteNonQuery(); + + streamDataSize = (long)videoClip.StreamDataSize; + name = videoClip.Name; + } + + public void Finalize(SQLiteConnection db) + { + } + + void IDisposable.Dispose() + { + m_InsertCommand.Dispose(); + } +} \ No newline at end of file diff --git a/Analyzer/SQLite/SQLiteWriter.cs b/Analyzer/SQLite/SQLiteWriter.cs index b65b3bc..e530c72 100644 --- a/Analyzer/SQLite/SQLiteWriter.cs +++ b/Analyzer/SQLite/SQLiteWriter.cs @@ -33,12 +33,14 @@ public class SQLiteWriter : IWriter private Dictionary m_Handlers = new () { { "Mesh", new MeshHandler() }, - { "Texture2D", new Texture2DHandler() }, + { "Texture2D", new Texture2DHandler(false) }, + { "Cubemap", new Texture2DHandler(true) }, { "Shader", new ShaderHandler() }, { "AudioClip", new AudioClipHandler() }, { "AnimationClip", new AnimationClipHandler() }, { "AssetBundle", new AssetBundleHandler() }, { "PreloadData", new PreloadDataHandler() }, + { "VideoClip", new VideoClipHandler() }, }; private SQLiteConnection m_Database; diff --git a/Analyzer/SerializedObjects/Texture2D.cs b/Analyzer/SerializedObjects/Texture2D.cs index ddd7630..7a46d06 100644 --- a/Analyzer/SerializedObjects/Texture2D.cs +++ b/Analyzer/SerializedObjects/Texture2D.cs @@ -8,6 +8,7 @@ public class Texture2D public int StreamDataSize { get; init; } public int Width { get; init; } public int Height { get; init; } + public int ImageCount { get; init; } public int Format { get; init; } public int MipCount { get; init; } public bool RwEnabled { get; init; } @@ -21,6 +22,7 @@ public static Texture2D Read(RandomAccessReader reader) Name = reader["m_Name"].GetValue(), Width = reader["m_Width"].GetValue(), Height = reader["m_Height"].GetValue(), + ImageCount = reader["m_ImageCount"].GetValue(), Format = reader["m_TextureFormat"].GetValue(), RwEnabled = reader["m_IsReadable"].GetValue() != 0, MipCount = reader["m_MipCount"].GetValue(), diff --git a/Analyzer/SerializedObjects/VideeClip.cs b/Analyzer/SerializedObjects/VideeClip.cs new file mode 100644 index 0000000..567e821 --- /dev/null +++ b/Analyzer/SerializedObjects/VideeClip.cs @@ -0,0 +1,29 @@ +using System; +using UnityDataTools.FileSystem.TypeTreeReaders; + +namespace UnityDataTools.Analyzer.SerializedObjects; + +public class VideoClip +{ + public string Name { get; init; } + public double FrameRate { get; init; } + public uint Width { get; init; } + public uint Height { get; init; } + public UInt64 FrameCount { get; init; } + public long StreamDataSize { get; init; } + + private VideoClip() {} + + public static VideoClip Read(RandomAccessReader reader) + { + return new VideoClip() + { + Name = reader["m_Name"].GetValue(), + FrameRate = reader["m_FrameRate"].GetValue(), + Width = reader["Width"].GetValue(), + Height = reader["Height"].GetValue(), + FrameCount = reader["m_FrameCount"].GetValue(), + StreamDataSize = reader["m_ExternalResources"]["m_Size"].GetValue() + }; + } +} \ No newline at end of file