mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-27 22:00:23 -04:00
try to fix combined mesh export error
This commit is contained in:
parent
66a2dbe730
commit
9b1e3435d6
@ -5,10 +5,18 @@ using System.Text;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public class StaticBatchInfo
|
||||
{
|
||||
public ushort firstSubMesh;
|
||||
public ushort subMeshCount;
|
||||
}
|
||||
|
||||
public class MeshRenderer
|
||||
{
|
||||
public PPtr m_GameObject;
|
||||
public PPtr[] m_Materials;
|
||||
public StaticBatchInfo m_StaticBatchInfo;
|
||||
public uint[] m_SubsetIndices;
|
||||
|
||||
protected MeshRenderer() { }
|
||||
|
||||
@ -56,6 +64,27 @@ namespace AssetStudio
|
||||
{
|
||||
m_Materials[m] = sourceFile.ReadPPtr();
|
||||
}
|
||||
|
||||
if (version[0] < 3)
|
||||
{
|
||||
reader.Position += 16;//m_LightmapTilingOffset vector4d
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 5) || sourceFile.version[0] > 5)//5.5.0 and up
|
||||
{
|
||||
m_StaticBatchInfo = new StaticBatchInfo
|
||||
{
|
||||
firstSubMesh = reader.ReadUInt16(),
|
||||
subMeshCount = reader.ReadUInt16()
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
int numSubsetIndices = reader.ReadInt32();
|
||||
m_SubsetIndices = reader.ReadUInt32Array(numSubsetIndices);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,12 +64,16 @@ namespace AssetStudio
|
||||
{
|
||||
if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 5) || sourceFile.version[0] > 5)//5.5.0 and up
|
||||
{
|
||||
reader.Position += 4;//m_StaticBatchInfo
|
||||
m_StaticBatchInfo = new StaticBatchInfo
|
||||
{
|
||||
firstSubMesh = reader.ReadUInt16(),
|
||||
subMeshCount = reader.ReadUInt16()
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
int m_SubsetIndices_size = reader.ReadInt32();
|
||||
reader.Position += m_SubsetIndices_size * 4;
|
||||
int numSubsetIndices = reader.ReadInt32();
|
||||
m_SubsetIndices = reader.ReadUInt32Array(numSubsetIndices);
|
||||
}
|
||||
|
||||
var m_StaticBatchRoot = sourceFile.ReadPPtr();
|
||||
|
@ -228,10 +228,35 @@ namespace AssetStudio
|
||||
assetsfileList.TryGetGameObject(meshR.m_GameObject, out var m_GameObject2);
|
||||
assetsfileList.TryGetTransform(m_GameObject2.m_Transform, out var meshTransform);
|
||||
iMesh.Name = GetTransformPath(meshTransform);
|
||||
iMesh.SubmeshList = new List<ImportedSubmesh>(mesh.m_SubMeshes.Count);
|
||||
int sum = 0;
|
||||
iMesh.SubmeshList = new List<ImportedSubmesh>();
|
||||
var subHashSet = new HashSet<int>();
|
||||
var combine = false;
|
||||
if (meshR.m_StaticBatchInfo != null && meshR.m_StaticBatchInfo.subMeshCount > 0)
|
||||
{
|
||||
var finalSubMesh = meshR.m_StaticBatchInfo.firstSubMesh + meshR.m_StaticBatchInfo.subMeshCount;
|
||||
for (int i = meshR.m_StaticBatchInfo.firstSubMesh; i < finalSubMesh; i++)
|
||||
{
|
||||
subHashSet.Add(i);
|
||||
}
|
||||
combine = true;
|
||||
}
|
||||
else if (meshR.m_SubsetIndices != null)
|
||||
{
|
||||
foreach (var index in meshR.m_SubsetIndices)
|
||||
{
|
||||
subHashSet.Add((int)index);
|
||||
}
|
||||
combine = true;
|
||||
}
|
||||
int firstFace = 0;
|
||||
for (int i = 0; i < mesh.m_SubMeshes.Count; i++)
|
||||
{
|
||||
int numFaces = (int)mesh.m_SubMeshes[i].indexCount / 3;
|
||||
if (subHashSet.Count > 0 && !subHashSet.Contains(i))
|
||||
{
|
||||
firstFace += numFaces;
|
||||
continue;
|
||||
}
|
||||
var submesh = mesh.m_SubMeshes[i];
|
||||
var iSubmesh = new ImportedSubmesh();
|
||||
Material mat = null;
|
||||
@ -310,10 +335,9 @@ namespace AssetStudio
|
||||
iSubmesh.VertexList.Add(iVertex);
|
||||
}
|
||||
//Face
|
||||
int numFaces = (int)mesh.m_SubMeshes[i].indexCount / 3;
|
||||
iSubmesh.FaceList = new List<ImportedFace>(numFaces);
|
||||
var end = sum + numFaces;
|
||||
for (int f = sum; f < end; f++)
|
||||
var end = firstFace + numFaces;
|
||||
for (int f = firstFace; f < end; f++)
|
||||
{
|
||||
var face = new ImportedFace();
|
||||
face.VertexIndices = new int[3];
|
||||
@ -322,7 +346,7 @@ namespace AssetStudio
|
||||
face.VertexIndices[2] = (int)(mesh.m_Indices[f * 3] - submesh.firstVertex);
|
||||
iSubmesh.FaceList.Add(face);
|
||||
}
|
||||
sum = end;
|
||||
firstFace = end;
|
||||
iMesh.SubmeshList.Add(iSubmesh);
|
||||
}
|
||||
|
||||
@ -435,6 +459,35 @@ namespace AssetStudio
|
||||
}
|
||||
}
|
||||
}
|
||||
//TODO
|
||||
if (combine)
|
||||
{
|
||||
assetsfileList.TryGetGameObject(meshR.m_GameObject, out var m_GameObject);
|
||||
foreach (var root in FrameList)
|
||||
{
|
||||
var frame = ImportedHelpers.FindFrame(m_GameObject.m_Name, root);
|
||||
if (frame != null)
|
||||
{
|
||||
if (frame.Parent != null)
|
||||
{
|
||||
var parent = frame;
|
||||
while (true)
|
||||
{
|
||||
if (parent.Parent != null)
|
||||
{
|
||||
parent = parent.Parent;
|
||||
}
|
||||
else
|
||||
{
|
||||
frame.Matrix = parent.Matrix;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MeshList.Add(iMesh);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user