Skip to content

Fix cubemap & video clip reporting #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Analyzer/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Analyzer/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,7 @@
<data name="Texture2D" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Texture2D.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="VideoClip" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\VideoClip.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
</root>
2 changes: 2 additions & 0 deletions Analyzer/Resources/Texture2D.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CREATE TABLE textures
id INTEGER,
width INTEGER,
height INTEGER,
image_count INTEGER,
format INTEGER,
mip_count INTEGER,
rw_enabled INTEGER,
Expand All @@ -21,6 +22,7 @@ SELECT
o.*,
t.width,
t.height,
t.image_count,
f.name AS format,
t.mip_count,
t.rw_enabled
Expand Down
19 changes: 19 additions & 0 deletions Analyzer/Resources/VideoClip.sql
Original file line number Diff line number Diff line change
@@ -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
19 changes: 15 additions & 4 deletions Analyzer/SQLite/Handlers/Texture2DHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
53 changes: 53 additions & 0 deletions Analyzer/SQLite/Handlers/VideoClipHandler.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
4 changes: 3 additions & 1 deletion Analyzer/SQLite/SQLiteWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ public class SQLiteWriter : IWriter
private Dictionary<string, ISQLiteHandler> 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;
Expand Down
2 changes: 2 additions & 0 deletions Analyzer/SerializedObjects/Texture2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -21,6 +22,7 @@ public static Texture2D Read(RandomAccessReader reader)
Name = reader["m_Name"].GetValue<string>(),
Width = reader["m_Width"].GetValue<int>(),
Height = reader["m_Height"].GetValue<int>(),
ImageCount = reader["m_ImageCount"].GetValue<int>(),
Format = reader["m_TextureFormat"].GetValue<int>(),
RwEnabled = reader["m_IsReadable"].GetValue<int>() != 0,
MipCount = reader["m_MipCount"].GetValue<int>(),
Expand Down
29 changes: 29 additions & 0 deletions Analyzer/SerializedObjects/VideeClip.cs
Original file line number Diff line number Diff line change
@@ -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<string>(),
FrameRate = reader["m_FrameRate"].GetValue<double>(),
Width = reader["Width"].GetValue<uint>(),
Height = reader["Height"].GetValue<uint>(),
FrameCount = reader["m_FrameCount"].GetValue<UInt64>(),
StreamDataSize = reader["m_ExternalResources"]["m_Size"].GetValue<long>()
};
}
}