Skip to content

Commit 525d747

Browse files
committed
Fix cubemap & video clip reporting
1 parent 4bb96da commit 525d747

File tree

9 files changed

+168
-5
lines changed

9 files changed

+168
-5
lines changed

Analyzer/Properties/Resources.Designer.cs

+42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Analyzer/Properties/Resources.resx

+3
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,7 @@
142142
<data name="Texture2D" type="System.Resources.ResXFileRef, System.Windows.Forms">
143143
<value>..\Resources\Texture2D.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
144144
</data>
145+
<data name="VideoClip" type="System.Resources.ResXFileRef, System.Windows.Forms">
146+
<value>..\Resources\VideoClip.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
147+
</data>
145148
</root>

Analyzer/Resources/Texture2D.sql

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CREATE TABLE textures
1010
id INTEGER,
1111
width INTEGER,
1212
height INTEGER,
13+
image_count INTEGER,
1314
format INTEGER,
1415
mip_count INTEGER,
1516
rw_enabled INTEGER,
@@ -21,6 +22,7 @@ SELECT
2122
o.*,
2223
t.width,
2324
t.height,
25+
t.image_count,
2426
f.name AS format,
2527
t.mip_count,
2628
t.rw_enabled

Analyzer/Resources/VideoClip.sql

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CREATE TABLE video_clips
2+
(
3+
id INTEGER,
4+
width INTEGER,
5+
height INTEGER,
6+
frame_rate REAL,
7+
frame_count INTEGER,
8+
PRIMARY KEY (id)
9+
);
10+
11+
CREATE VIEW video_clip_view AS
12+
SELECT
13+
o.*,
14+
v.width,
15+
v.height,
16+
v.frame_rate,
17+
v.frame_count,
18+
FROM object_view o
19+
INNER JOIN video_clips v ON o.id = v.id

Analyzer/SQLite/Handlers/Texture2DHandler.cs

+15-4
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,29 @@ namespace UnityDataTools.Analyzer.SQLite.Handlers;
1010
public class Texture2DHandler : ISQLiteHandler
1111
{
1212
SQLiteCommand m_InsertCommand;
13+
bool m_skipCreateDatabase;
14+
15+
public Texture2DHandler(bool skipCreateDatabase)
16+
{
17+
m_skipCreateDatabase = skipCreateDatabase;
18+
}
1319

1420
public void Init(SQLiteConnection db)
1521
{
16-
using var command = new SQLiteCommand(db);
22+
if (!m_skipCreateDatabase)
23+
{
24+
using var command = new SQLiteCommand(db);
1725

18-
command.CommandText = Properties.Resources.Texture2D;
19-
command.ExecuteNonQuery();
26+
command.CommandText = Properties.Resources.Texture2D;
27+
command.ExecuteNonQuery();
28+
}
2029

2130
m_InsertCommand = new SQLiteCommand(db);
22-
m_InsertCommand.CommandText = "INSERT INTO textures(id, width, height, format, rw_enabled, mip_count) VALUES(@id, @width, @height, @format, @rw_enabled, @mip_count)";
31+
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)";
2332
m_InsertCommand.Parameters.Add("@id", DbType.Int64);
2433
m_InsertCommand.Parameters.Add("@width", DbType.Int32);
2534
m_InsertCommand.Parameters.Add("@height", DbType.Int32);
35+
m_InsertCommand.Parameters.Add("@image_count", DbType.Int32);
2636
m_InsertCommand.Parameters.Add("@format", DbType.Int32);
2737
m_InsertCommand.Parameters.Add("@rw_enabled", DbType.Int32);
2838
m_InsertCommand.Parameters.Add("@mip_count", DbType.Int32);
@@ -35,6 +45,7 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
3545
m_InsertCommand.Parameters["@id"].Value = objectId;
3646
m_InsertCommand.Parameters["@width"].Value = texture2d.Width;
3747
m_InsertCommand.Parameters["@height"].Value = texture2d.Height;
48+
m_InsertCommand.Parameters["@image_count"].Value = texture2d.ImageCount;
3849
m_InsertCommand.Parameters["@format"].Value = texture2d.Format;
3950
m_InsertCommand.Parameters["@rw_enabled"].Value = texture2d.RwEnabled;
4051
m_InsertCommand.Parameters["@mip_count"].Value = texture2d.MipCount;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Data;
3+
using System.Data.SQLite;
4+
using UnityDataTools.Analyzer.SerializedObjects;
5+
using UnityDataTools.FileSystem.TypeTreeReaders;
6+
7+
namespace UnityDataTools.Analyzer.SQLite.Handlers;
8+
9+
public class VideoClipHandler : ISQLiteHandler
10+
{
11+
SQLiteCommand m_InsertCommand;
12+
13+
public void Init(SQLiteConnection db)
14+
{
15+
using var command = new SQLiteCommand(db);
16+
17+
command.CommandText = Properties.Resources.VideoClip;
18+
command.ExecuteNonQuery();
19+
20+
m_InsertCommand = new SQLiteCommand(db);
21+
m_InsertCommand.CommandText = "INSERT INTO video_clips(id, width, height, frame_rate, frame_count) VALUES(@id, @width, @height, @frame_rate, @frame_count, @format)";
22+
m_InsertCommand.Parameters.Add("@id", DbType.Int64);
23+
m_InsertCommand.Parameters.Add("@width", DbType.UInt32);
24+
m_InsertCommand.Parameters.Add("@height", DbType.UInt32);
25+
m_InsertCommand.Parameters.Add("@frame_rate", DbType.Double);
26+
m_InsertCommand.Parameters.Add("@frame_count", DbType.UInt64);
27+
}
28+
29+
public void Process(Context ctx, long objectId, RandomAccessReader reader, out string name, out long streamDataSize)
30+
{
31+
var videoClip = VideoClip.Read(reader);
32+
33+
m_InsertCommand.Parameters["@id"].Value = objectId;
34+
m_InsertCommand.Parameters["@width"].Value = videoClip.Width;
35+
m_InsertCommand.Parameters["@height"].Value = videoClip.Height;
36+
m_InsertCommand.Parameters["@frame_rate"].Value = videoClip.FrameRate;
37+
m_InsertCommand.Parameters["@frame_count"].Value = videoClip.FrameCount;
38+
39+
m_InsertCommand.ExecuteNonQuery();
40+
41+
streamDataSize = (long)videoClip.StreamDataSize;
42+
name = videoClip.Name;
43+
}
44+
45+
public void Finalize(SQLiteConnection db)
46+
{
47+
}
48+
49+
void IDisposable.Dispose()
50+
{
51+
m_InsertCommand.Dispose();
52+
}
53+
}

Analyzer/SQLite/SQLiteWriter.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ public class SQLiteWriter : IWriter
3333
private Dictionary<string, ISQLiteHandler> m_Handlers = new ()
3434
{
3535
{ "Mesh", new MeshHandler() },
36-
{ "Texture2D", new Texture2DHandler() },
36+
{ "Texture2D", new Texture2DHandler(false) },
37+
{ "Cubemap", new Texture2DHandler(true) },
3738
{ "Shader", new ShaderHandler() },
3839
{ "AudioClip", new AudioClipHandler() },
3940
{ "AnimationClip", new AnimationClipHandler() },
4041
{ "AssetBundle", new AssetBundleHandler() },
4142
{ "PreloadData", new PreloadDataHandler() },
43+
{ "VideoClip", new VideoClipHandler() },
4244
};
4345

4446
private SQLiteConnection m_Database;

Analyzer/SerializedObjects/Texture2D.cs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class Texture2D
88
public int StreamDataSize { get; init; }
99
public int Width { get; init; }
1010
public int Height { get; init; }
11+
public int ImageCount { get; init; }
1112
public int Format { get; init; }
1213
public int MipCount { get; init; }
1314
public bool RwEnabled { get; init; }
@@ -21,6 +22,7 @@ public static Texture2D Read(RandomAccessReader reader)
2122
Name = reader["m_Name"].GetValue<string>(),
2223
Width = reader["m_Width"].GetValue<int>(),
2324
Height = reader["m_Height"].GetValue<int>(),
25+
ImageCount = reader["m_ImageCount"].GetValue<int>(),
2426
Format = reader["m_TextureFormat"].GetValue<int>(),
2527
RwEnabled = reader["m_IsReadable"].GetValue<int>() != 0,
2628
MipCount = reader["m_MipCount"].GetValue<int>(),
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using UnityDataTools.FileSystem.TypeTreeReaders;
3+
4+
namespace UnityDataTools.Analyzer.SerializedObjects;
5+
6+
public class VideoClip
7+
{
8+
public string Name { get; init; }
9+
public double FrameRate { get; init; }
10+
public uint Width { get; init; }
11+
public uint Height { get; init; }
12+
public UInt64 FrameCount { get; init; }
13+
public long StreamDataSize { get; init; }
14+
15+
private VideoClip() {}
16+
17+
public static VideoClip Read(RandomAccessReader reader)
18+
{
19+
return new VideoClip()
20+
{
21+
Name = reader["m_Name"].GetValue<string>(),
22+
FrameRate = reader["m_FrameRate"].GetValue<double>(),
23+
Width = reader["Width"].GetValue<uint>(),
24+
Height = reader["Height"].GetValue<uint>(),
25+
FrameCount = reader["m_FrameCount"].GetValue<UInt64>(),
26+
StreamDataSize = reader["m_ExternalResources"]["m_Size"].GetValue<long>()
27+
};
28+
}
29+
}

0 commit comments

Comments
 (0)