|
|
|
@ -37,32 +37,71 @@ public class BrushModel |
|
|
|
modelGO.transform.SetParent(rootGameObject.transform); |
|
|
|
|
|
|
|
var headNode = subModels[modelIdx].GetHeadNode(model); |
|
|
|
CreateNodeMeshes(headNode, surfaces, modelGO); |
|
|
|
|
|
|
|
var surfaceGroups = new Dictionary<(string, int), List<QSurface>>(); |
|
|
|
GroupSurfaces(headNode, surfaces, surfaceGroups); |
|
|
|
|
|
|
|
foreach (var group in surfaceGroups) |
|
|
|
{ |
|
|
|
var key = group.Key; |
|
|
|
var groupGO = new GameObject($"T{key.Item1}_L{key.Item2}"); |
|
|
|
groupGO.transform.SetParent(modelGO.transform); |
|
|
|
|
|
|
|
for (int i = 0; i < group.Value.Count; ++i) |
|
|
|
{ |
|
|
|
CreateSurfaceMeshes(group.Value[i], $"{i}", groupGO); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void CreateNodeMeshes(QNode node, QSurface[] surfaces, GameObject parentGO) |
|
|
|
private void GroupSurfaces(QNode node, QSurface[] surfaces, Dictionary<(string, int), List<QSurface>> surfaceGroups) |
|
|
|
{ |
|
|
|
if (node.contents < 0) // Leaf node
|
|
|
|
return; |
|
|
|
|
|
|
|
var nodeGO = new GameObject("Node"); |
|
|
|
nodeGO.transform.SetParent(parentGO.transform); |
|
|
|
for (int surfIdx = 0; surfIdx < node.numSurfaces; ++surfIdx) |
|
|
|
{ |
|
|
|
var surface = surfaces[node.firstSurface + surfIdx]; |
|
|
|
|
|
|
|
CreateSurfaceMeshes(node, surfaces, nodeGO); |
|
|
|
string texName = surface.TextureInfo.Texture.name; |
|
|
|
int lightNum = surface.lightmapTextureNum; |
|
|
|
var key = (texName, lightNum); |
|
|
|
|
|
|
|
if (!surfaceGroups.ContainsKey(key)) |
|
|
|
surfaceGroups[key] = new List<QSurface>(); |
|
|
|
|
|
|
|
surfaceGroups[key].Add(surface); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var childNode in node.Children) |
|
|
|
{ |
|
|
|
CreateNodeMeshes(childNode, surfaces, nodeGO); |
|
|
|
GroupSurfaces(childNode, surfaces, surfaceGroups); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void CreateSurfaceMeshes(QNode node, QSurface[] surfaces, GameObject nodeGO) |
|
|
|
private void CreateNodeMeshes(QNode node, QSurface[] surfaces, GameObject parentGO) |
|
|
|
{ |
|
|
|
if (node.contents < 0) // Leaf node
|
|
|
|
return; |
|
|
|
|
|
|
|
var nodeGO = new GameObject("Node"); |
|
|
|
nodeGO.transform.SetParent(parentGO.transform); |
|
|
|
|
|
|
|
for (int surfIdx = 0; surfIdx < node.numSurfaces; ++surfIdx) |
|
|
|
{ |
|
|
|
var surface = surfaces[node.firstSurface + surfIdx]; |
|
|
|
CreateSurfaceMeshes(surface, $"{node.firstSurface + surfIdx}", nodeGO); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var childNode in node.Children) |
|
|
|
{ |
|
|
|
CreateNodeMeshes(childNode, surfaces, nodeGO); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void CreateSurfaceMeshes(QSurface surface, string key, GameObject nodeGO) |
|
|
|
{ |
|
|
|
foreach (var polyVerts in surface.GetPolygons()) |
|
|
|
{ |
|
|
|
tempVertices.Clear(); |
|
|
|
@ -86,7 +125,7 @@ public class BrushModel |
|
|
|
} |
|
|
|
|
|
|
|
Mesh mesh = new Mesh(); |
|
|
|
mesh.name = $"Surface_{node.firstSurface + surfIdx}"; |
|
|
|
mesh.name = $"Surface_{key}"; |
|
|
|
mesh.SetVertices(tempVertices); |
|
|
|
mesh.SetUVs(0, tempTextureUVs); |
|
|
|
mesh.SetUVs(1, tempLightmapUVs); |
|
|
|
@ -97,9 +136,6 @@ public class BrushModel |
|
|
|
|
|
|
|
CreateMeshObject(mesh, nodeGO); |
|
|
|
} |
|
|
|
|
|
|
|
var texNum = surface.TextureInfo.Texture.TextureNum; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void CreateMeshObject(Mesh mesh, GameObject parentGO) |
|
|
|
|