remove duplicate verts

This commit is contained in:
GoaLitiuM
2021-09-06 19:59:33 +03:00
parent a49be3af7c
commit 90e0a999bd
3 changed files with 56 additions and 15 deletions

View File

@@ -272,16 +272,20 @@
}
// brush 30
{
( -64 640 160 ) ( -64 641 160 ) ( -64 640 161 ) dev/dev_128_gray 0 0 0 0.0625 0.0625 0 0 0
( -64 640 160 ) ( -64 640 161 ) ( -63 640 160 ) common/slick 0 0 0 1 1 0 0 0
( -64 640 160 ) ( -63 640 160 ) ( -64 641 160 ) dev/dev_128_red 0 0 0 0.0625 0.0625 0 0 0
( 48 736 224 ) ( 48 737 224 ) ( 49 736 224 ) dev/dev_128_red 0 0 0 0.0625 0.0625 0 0 0
( 48 704 176 ) ( 49 704 176 ) ( 48 704 177 ) common/slick 0 0 0 1 1 0 0 0
( 0 736 176 ) ( 0 736 177 ) ( 0 737 176 ) dev/dev_128_gray 0 0 0 0.0625 0.0625 0 0 0
( -128 544 0 ) ( -128 545 0 ) ( -128 544 1 ) dev/dev_128_gray 0 0 0 0.0625 0.0625 0 0 0
( -128 544 0 ) ( -128 544 1 ) ( -127 544 0 ) common/slick 0 0 0 1 1 0 0 0
( -128 544 0 ) ( -127 544 0 ) ( -128 545 0 ) dev/dev_128_red 0 0 0 0.0625 0.0625 0 0 0
( -16 640 64 ) ( -16 641 64 ) ( -15 640 64 ) dev/dev_128_red 0 0 0 0.0625 0.0625 0 0 0
( -16 608 16 ) ( -15 608 16 ) ( -16 608 17 ) common/slick 0 0 0 1 1 0 0 0
( -64 640 16 ) ( -64 640 17 ) ( -64 641 16 ) dev/dev_128_gray 0 0 0 0.0625 0.0625 0 0 0
}
}
// entity 1
// brush 31
{
"classname" "info_player_deathmatch"
"origin" "-368 544 120"
( -752 464 64 ) ( -752 465 64 ) ( -752 464 65 ) dev/dev_128_red 0 0 0 0.0625 0.0625 0 0 0
( -752 464 64 ) ( -752 464 65 ) ( -751 464 64 ) dev/dev_128_red 0 0 0 0.0625 0.0625 0 0 0
( -752 464 64 ) ( -751 464 64 ) ( -752 465 64 ) dev/dev_128_red 0 0 0 0.0625 0.0625 0 0 0
( -672 592 80 ) ( -672 593 80 ) ( -671 592 80 ) dev/dev_128_red 0 0 0 0.0625 0.0625 0 0 0
( -672 592 80 ) ( -671 592 80 ) ( -672 592 81 ) dev/dev_128_red 0 0 0 0.0625 0.0625 0 0 0
( -672 592 80 ) ( -672 592 81 ) ( -672 593 80 ) dev/dev_128_red 0 0 0 0.0625 0.0625 0 0 0
}
}

View File

@@ -9,7 +9,10 @@
"ForDistribution": false,
"SkipPackaging": false,
"AdditionalAssets": [],
"AdditionalAssetFolders": [],
"AdditionalAssetFolders": [
"Content/Materials",
"Content/Textures"
],
"ShadersNoOptimize": false,
"ShadersGenerateDebugData": false,
"Presets": [

View File

@@ -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);