From b42770bf7a2915e6e551660872006a4b08900d4a Mon Sep 17 00:00:00 2001 From: Dahlia Trimble Date: Fri, 11 Jul 2008 20:32:58 +0000 Subject: [PATCH] Trim out nulls from mesh vertex and triangle lists to try and save more memory --- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index 55a1bec2b7..df850a0d1f 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -1858,7 +1858,6 @@ namespace OpenSim.Region.Physics.Meshing Console.WriteLine("skew: " + skew.ToString() + " profileXComp: " + profileXComp.ToString()); #endif - foreach (Vertex v in m.vertices) if (v != null) { @@ -2173,14 +2172,31 @@ namespace OpenSim.Region.Physics.Meshing // } //} - if (mesh != null && size.X < minSizeForComplexMesh && size.Y < minSizeForComplexMesh && size.Z < minSizeForComplexMesh) - { + if (mesh != null) + if (size.X < minSizeForComplexMesh && size.Y < minSizeForComplexMesh && size.Z < minSizeForComplexMesh) + { #if SPAM Console.WriteLine("Meshmerizer: prim " + primName + " has a size of " + size.ToString() + " which is below threshold of " + minSizeForComplexMesh.ToString() + " - creating simple bounding box" ); #endif - mesh = CreateBoundingBoxMesh(mesh); - mesh.DumpRaw(baseDir, primName, "Z extruded"); - } + mesh = CreateBoundingBoxMesh(mesh); + mesh.DumpRaw(baseDir, primName, "Z extruded"); + + // trim the vertex and triangle lists to free up memory + //mesh.vertices.TrimExcess(); + //mesh.triangles.TrimExcess(); + + int vertCount = 0; + foreach (Vertex v in mesh.vertices) + if (v != null) + vertCount++; + mesh.vertices.Capacity = vertCount; + + int triCount = 0; + foreach (Triangle t in mesh.triangles) + if ( t != null ) + triCount++; + mesh.triangles.Capacity = triCount; + } return mesh; }