Browse Source

Marshal only one polygon per brush model surface for conversion into a Unity mesh. Any subsequent polygons are pre-tessellated versions meant for the water warping effect, which we won't need as this will be handled by GPU tessellation. Fixed garbled water surface caused by having two polygon meshes overlapping.

console
Nico de Poel 5 years ago
parent
commit
59a64473b0
  1. 18
      Assets/Scripts/Data/QModel.cs
  2. 33
      Assets/Scripts/Support/BrushModel.cs

18
Assets/Scripts/Data/QModel.cs

@ -309,21 +309,13 @@ public struct QSurface
// This is safe as the Quake engine guarantees this pointer is never null (see: Mod_LoadFaces) // This is safe as the Quake engine guarantees this pointer is never null (see: Mod_LoadFaces)
public QTexInfo TextureInfo => Marshal.PtrToStructure<QTexInfo>(texInfo); public QTexInfo TextureInfo => Marshal.PtrToStructure<QTexInfo>(texInfo);
public IEnumerable<QGLPolyVert[]> GetPolygons()
public QGLPolyVert[] GetPolygon()
{ {
// This is so nasty. We have to deconstruct a linked list of variable-sized structs. Yuck.
// We have to calculate the position inside the struct where the variable-sized array of vertices starts
int offset = Marshal.SizeOf<IntPtr>() * 2 + Marshal.SizeOf<int>(); int offset = Marshal.SizeOf<IntPtr>() * 2 + Marshal.SizeOf<int>();
IntPtr polyPtr = polys;
while (polyPtr != IntPtr.Zero)
{
QGLPoly polygon = Marshal.PtrToStructure<QGLPoly>(polyPtr);
QGLPolyVert[] vertices = IntPtr.Add(polyPtr, offset).ToStructArray<QGLPolyVert>(polygon.numVerts);
yield return vertices;
polyPtr = polygon.next;
}
QGLPoly polygon = Marshal.PtrToStructure<QGLPoly>(polys);
return IntPtr.Add(polys, offset).ToStructArray<QGLPolyVert>(polygon.numVerts);
} }
} }

33
Assets/Scripts/Support/BrushModel.cs

@ -100,25 +100,24 @@ public class BrushModel
for (int surfIdx = 0; surfIdx < surfaces.Count; ++surfIdx) for (int surfIdx = 0; surfIdx < surfaces.Count; ++surfIdx)
{ {
foreach (var polyVerts in surfaces[surfIdx].GetPolygons())
var polyVerts = surfaces[surfIdx].GetPolygon();
for (int vertIdx = 0; vertIdx < polyVerts.Length; ++vertIdx)
{ {
for (int vertIdx = 0; vertIdx < polyVerts.Length; ++vertIdx)
{
tempVertices.Add(polyVerts[vertIdx].position.ToUnityPosition());
tempTextureUVs.Add(polyVerts[vertIdx].textureUV.ToVector2());
tempLightmapUVs.Add(polyVerts[vertIdx].lightmapUV.ToVector2());
}
// Reconstruct triangle fan
for (ushort index = 2; index < polyVerts.Length; ++index)
{
tempIndices.Add((ushort)vertOffset);
tempIndices.Add((ushort)(vertOffset + index - 1));
tempIndices.Add((ushort)(vertOffset + index));
}
vertOffset += polyVerts.Length;
tempVertices.Add(polyVerts[vertIdx].position.ToUnityPosition());
tempTextureUVs.Add(polyVerts[vertIdx].textureUV.ToVector2());
tempLightmapUVs.Add(polyVerts[vertIdx].lightmapUV.ToVector2());
}
// Reconstruct triangle fan
for (ushort index = 2; index < polyVerts.Length; ++index)
{
tempIndices.Add((ushort)vertOffset);
tempIndices.Add((ushort)(vertOffset + index - 1));
tempIndices.Add((ushort)(vertOffset + index));
} }
vertOffset += polyVerts.Length;
} }
Mesh mesh = new Mesh(); Mesh mesh = new Mesh();

Loading…
Cancel
Save