From 428bd7a74bd9e1df3af29dd285fe385e5c4d526d Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Mon, 26 Oct 2009 13:57:27 -0700 Subject: No need to create dupe TriMeshData for ODE. A previous patch created a dictionary to store unique meshes in Meshmerizer based on creation params. This patch contains a dictionary to map each of those unique meshes to its ODE TriMeshData. This eliminated hundreds of megabytes of memory consumption in the unmanaged heap when there are lots of the same prim (roof tiles, bricks, siding, decks, chairs, etc). The objects do not need to be physical to benefit from this patch. --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 412f84d..09c8582 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -801,6 +801,8 @@ namespace OpenSim.Region.Physics.OdePlugin m_collisionscore = 0; } + private static Dictionary m_MeshToTriMeshMap = new Dictionary(); + public void setMesh(OdeScene parent_scene, IMesh mesh) { // This sleeper is there to moderate how long it takes between @@ -832,19 +834,24 @@ namespace OpenSim.Region.Physics.OdePlugin mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount); // Also fixed, needs release after usage mesh.releaseSourceMeshData(); // free up the original mesh data to save memory + if (m_MeshToTriMeshMap.ContainsKey(mesh)) + { + _triMeshData = m_MeshToTriMeshMap[mesh]; + } + else + { + _triMeshData = d.GeomTriMeshDataCreate(); - _triMeshData = d.GeomTriMeshDataCreate(); - - d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride); - d.GeomTriMeshDataPreprocess(_triMeshData); + d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride); + d.GeomTriMeshDataPreprocess(_triMeshData); + m_MeshToTriMeshMap[mesh] = _triMeshData; + } _parent_scene.waitForSpaceUnlock(m_targetSpace); - try { if (prim_geom == IntPtr.Zero) { -//Console.WriteLine(" setMesh 1"); SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null)); } } @@ -854,6 +861,7 @@ namespace OpenSim.Region.Physics.OdePlugin return; } + // if (IsPhysical && Body == (IntPtr) 0) // { // Recreate the body -- cgit v1.1