remove duplicate verts
This commit is contained in:
@@ -21,6 +21,7 @@ namespace Game
|
||||
{
|
||||
public MapBrush brush;
|
||||
public Vector3[] vertices; // all vertices
|
||||
public Vector3 offset;
|
||||
public BrushGeometryMesh[] meshes;
|
||||
public Model model;
|
||||
public Dictionary<string, MaterialBase> brushMaterials;
|
||||
@@ -135,6 +136,29 @@ namespace Game
|
||||
planePoints.Add(intersection);
|
||||
}
|
||||
|
||||
// remove duplicate points
|
||||
var planePoints3 = planePoints;
|
||||
planePoints = new HashSet<Vector3>();
|
||||
|
||||
foreach (var p1 in planePoints3)
|
||||
{
|
||||
bool found = false;
|
||||
foreach (var p2 in planePoints)
|
||||
{
|
||||
if (Mathf.Abs((p1 - p2).Length) < 0.00001f)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
planePoints.Add(p1);
|
||||
}
|
||||
|
||||
if (planePoints.Count != planePoints3.Count)
|
||||
Console.Print("culled " + (planePoints3.Count - planePoints.Count) + " points while triangulation");
|
||||
|
||||
// pass 2: cull points behind clipping planes
|
||||
var planePoints2 = planePoints;
|
||||
planePoints = new HashSet<Vector3>();
|
||||
@@ -217,6 +241,13 @@ namespace Game
|
||||
|
||||
Assert.IsTrue(geom.vertices.Length > 0);
|
||||
|
||||
foreach (var vert in geom.vertices)
|
||||
geom.offset += vert;
|
||||
geom.offset /= geom.vertices.Length;
|
||||
|
||||
for (int i=0; i<geom.vertices.Length; i++)
|
||||
geom.vertices[i] -= geom.offset;
|
||||
|
||||
Dictionary<string, MaterialBase> brushMaterials = new Dictionary<string, MaterialBase>();
|
||||
foreach (var brushPlane in geom.brush.planes)
|
||||
{
|
||||
@@ -260,6 +291,7 @@ namespace Game
|
||||
Console.Print("Pass 1: triangulation: " + sw.Elapsed.TotalMilliseconds + "ms");
|
||||
|
||||
// pass 2: texturing
|
||||
brushIndex = 0;
|
||||
sw.Restart();
|
||||
foreach (var geom in brushGeometries)
|
||||
{
|
||||
@@ -293,7 +325,7 @@ namespace Game
|
||||
}
|
||||
|
||||
if (!found)
|
||||
Console.Print("no matching plane found, bad geometry?");
|
||||
Console.Print("no matching plane found for brush " + brushIndex + ", bad geometry?");
|
||||
|
||||
Vector2 uv1, uv2, uv3;
|
||||
// if quake format
|
||||
@@ -338,9 +370,9 @@ namespace Game
|
||||
: axisForward2,
|
||||
uvRotation * Mathf.DegreesToRadians);
|
||||
|
||||
uv1 = ((Vector2)(v1 * rot) + uvOffset) * uvScale;
|
||||
uv2 = ((Vector2)(v2 * rot) + uvOffset) * uvScale;
|
||||
uv3 = ((Vector2)(v3 * rot) + uvOffset) * uvScale;
|
||||
uv1 = ((Vector2)((v1 + geom.offset) * rot) + uvOffset) * uvScale;
|
||||
uv2 = ((Vector2)((v2 + geom.offset) * rot) + uvOffset) * uvScale;
|
||||
uv3 = ((Vector2)((v3 + geom.offset) * rot) + uvOffset) * uvScale;
|
||||
}
|
||||
var mesh = geom.meshes[meshIndex];
|
||||
|
||||
@@ -376,6 +408,7 @@ namespace Game
|
||||
geom.model.LODs[0].Meshes[i].MaterialSlotIndex = i;
|
||||
geom.model.MaterialSlots[i].Material = geom.meshes[i].material;
|
||||
}
|
||||
brushIndex++;
|
||||
}
|
||||
sw.Stop();
|
||||
Console.Print("Pass 2: texturing: " + sw.Elapsed.TotalMilliseconds + "ms");
|
||||
@@ -389,6 +422,7 @@ namespace Game
|
||||
childModel.Name = "Brush_" + brushIndex;
|
||||
childModel.Parent = mapRootActor;
|
||||
childModel.Model = geom.model;
|
||||
childModel.Position = geom.offset;
|
||||
|
||||
for (int i = 0; i < geom.meshes.Length; i++)
|
||||
childModel.SetMaterial(i, geom.meshes[i].material);
|
||||
|
||||
Reference in New Issue
Block a user