Skip to content

Commit 05918fd

Browse files
committed
fix for Mesh with StreamData
1 parent d832d96 commit 05918fd

7 files changed

Lines changed: 69 additions & 19 deletions

File tree

UnityAsset.NET.TypeTreeHelper/Compiler/Helper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public static class Helper
5858
"Rectf",
5959
"SecondarySpriteTexture",
6060
"BoneWeights4",
61+
"ChannelInfo",
6162
];
6263

6364
public static HashSet<string> NoInterfaceTypes =
@@ -76,6 +77,7 @@ public static class Helper
7677
"Quaternionf", // workaround
7778
"Rectf",
7879
"BoneWeights4",
80+
"ChannelInfo",
7981
];
8082

8183
public static HashSet<string> IncludedPPTrGenricTypes =

UnityAsset.NET/AssetHelper/MeshHelper.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ public static ProcessedMesh GetProcessedMesh(AssetManager assetManager, IMesh me
275275

276276
// ReadVertexData
277277
var vertexData = mesh.m_VertexData;
278+
var dataSize = vertexData.m_DataSize;
279+
var streamData = mesh.m_StreamData;
280+
if (streamData is not null && streamData.size > 0)
281+
{
282+
if (streamData.TryGetData(assetManager, out var data))
283+
dataSize = data;
284+
}
278285
var streams = vertexData.GetStreams(version!);
279286
var vertexCount = vertexData.m_VertexCount;
280287
processedMesh.m_VertexCount = (int)vertexCount;
@@ -305,7 +312,7 @@ public static ProcessedMesh GetProcessedMesh(AssetManager assetManager, IMesh me
305312
for (int d = 0; d < dimension; d++)
306313
{
307314
var componentOffset = vertexOffset + componentByteSize * d;
308-
Buffer.BlockCopy(vertexData.m_DataSize.data, componentOffset, componentBytes, componentByteSize * (v * dimension + d), componentByteSize);
315+
Buffer.BlockCopy(dataSize.data, componentOffset, componentBytes, componentByteSize * (v * dimension + d), componentByteSize);
309316
}
310317
}
311318

UnityAsset.NET/TypeTree/PreDefined/Generated/Interfaces/IChannelInfo.g.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

UnityAsset.NET/TypeTree/PreDefined/Generated/Interfaces/IVertexData.g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public int? m_CurrentChannels
1717
}
1818

1919
public uint m_VertexCount { get; }
20-
public IChannelInfo[] m_Channels { get; }
20+
public ChannelInfo[] m_Channels { get; }
2121
public TypelessData m_DataSize { get; }
2222
}
2323
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using UnityAsset.NET.IO;
2+
3+
namespace UnityAsset.NET.TypeTree.PreDefined.Types;
4+
5+
public struct ChannelInfo : IPreDefinedInterface
6+
{
7+
public string ClassName => "ChannelInfo";
8+
public byte stream { get; }
9+
public byte offset { get; }
10+
public byte format { get; }
11+
public byte dimension { get; }
12+
13+
public ChannelInfo(IReader reader)
14+
{
15+
stream = reader.ReadByte();
16+
offset = reader.ReadByte();
17+
format = reader.ReadByte();
18+
dimension = (Byte)(reader.ReadByte() & 0xF);
19+
}
20+
21+
public AssetNode? ToAssetNode(string name = "Base")
22+
{
23+
var rootAssetNode = new AssetNode
24+
{
25+
Name = name,
26+
TypeName = "ChannelInfo"
27+
};
28+
rootAssetNode.Children.Add(new AssetNode { Name = "stream", TypeName = "UInt8", Value = stream });
29+
rootAssetNode.Children.Add(new AssetNode { Name = "offset", TypeName = "UInt8", Value = offset });
30+
rootAssetNode.Children.Add(new AssetNode { Name = "format", TypeName = "UInt8", Value = format });
31+
rootAssetNode.Children.Add(new AssetNode { Name = "dimension", TypeName = "UInt8", Value = dimension });
32+
return rootAssetNode;
33+
}
34+
}

UnityAsset.NET/TypeTree/PreDefined/Types/StreamingInfo.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Text;
1+
using System.Diagnostics.CodeAnalysis;
22
using UnityAsset.NET.Files;
33
using UnityAsset.NET.IO;
44
using UnityAsset.NET.IO.Reader;
@@ -32,4 +32,21 @@ public StreamingInfo(IReader reader)
3232
root.Children.Add(new AssetNode { Name = "path", TypeName = "string", Value = this.path });
3333
return root;
3434
}
35+
36+
public bool TryGetData(AssetManager mgr, [NotNullWhen(true)]out TypelessData? data)
37+
{
38+
data = null;
39+
var filePath = path.Split("/")[^1];
40+
if (mgr.LoadedFiles.TryGetValue(filePath, out var file))
41+
{
42+
if (file is IReaderProvider rp)
43+
{
44+
var reader = rp.CreateReader();
45+
reader.Position = (long)offset;
46+
data = new TypelessData((int)size, reader.ReadBytes((int)size));
47+
return true;
48+
}
49+
}
50+
return false;
51+
}
3552
}

UnityAsset.NET/TypeTree/PreDefined/Types/TypelessData.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ public TypelessData(IReader reader)
1313
size = reader.ReadInt32();
1414
data = reader.ReadBytes(size);
1515
}
16+
17+
public TypelessData(int size, byte[] data)
18+
{
19+
this.size = size;
20+
this.data = data;
21+
}
1622

1723
public AssetNode? ToAssetNode(string name = "Base")
1824
{

0 commit comments

Comments
 (0)