add a rudimentary version control to ubOde meshs cache

0.9.0-post-fixes
UbitUmarov 2017-07-23 14:23:44 +01:00
parent 04eeb0e5cb
commit 8b2e95d1c1
1 changed files with 90 additions and 90 deletions

View File

@ -36,7 +36,7 @@ using OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.StructuredData; using OpenMetaverse.StructuredData;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Threading;
using System.IO.Compression; using System.IO.Compression;
using PrimMesher; using PrimMesher;
using log4net; using log4net;
@ -56,15 +56,15 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
// Setting baseDir to a path will enable the dumping of raw files // Setting baseDir to a path will enable the dumping of raw files
// raw files can be imported by blender so a visual inspection of the results can be done // raw files can be imported by blender so a visual inspection of the results can be done
private static string cacheControlFilename = "cntr";
private bool m_Enabled = false; private bool m_Enabled = false;
public static object diskLock = new object(); public static object diskLock = new object();
public bool doMeshFileCache = true; public bool doMeshFileCache = true;
public bool doCacheExpire = true;
public string cachePath = "MeshCache"; public string cachePath = "MeshCache";
public TimeSpan CacheExpire; public TimeSpan CacheExpire;
public bool doCacheExpire = true;
// const string baseDir = "rawFiles"; // const string baseDir = "rawFiles";
private const string baseDir = null; //"rawFiles"; private const string baseDir = null; //"rawFiles";
@ -101,10 +101,8 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
if (mesh_config != null) if (mesh_config != null)
{ {
useMeshiesPhysicsMesh = mesh_config.GetBoolean("UseMeshiesPhysicsMesh", useMeshiesPhysicsMesh); useMeshiesPhysicsMesh = mesh_config.GetBoolean("UseMeshiesPhysicsMesh", useMeshiesPhysicsMesh);
doConvexPrims = mesh_config.GetBoolean("ConvexPrims",doConvexPrims); doConvexPrims = mesh_config.GetBoolean("ConvexPrims",doConvexPrims);
doConvexSculpts = mesh_config.GetBoolean("ConvexSculpts",doConvexPrims); doConvexSculpts = mesh_config.GetBoolean("ConvexSculpts",doConvexPrims);
doMeshFileCache = mesh_config.GetBoolean("MeshFileCache", doMeshFileCache); doMeshFileCache = mesh_config.GetBoolean("MeshFileCache", doMeshFileCache);
cachePath = mesh_config.GetString("MeshFileCachePath", cachePath); cachePath = mesh_config.GetString("MeshFileCachePath", cachePath);
fcache = mesh_config.GetFloat("MeshFileCacheExpireHours", fcache); fcache = mesh_config.GetFloat("MeshFileCacheExpireHours", fcache);
@ -115,22 +113,19 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
CacheExpire = TimeSpan.FromHours(fcache); CacheExpire = TimeSpan.FromHours(fcache);
lock (diskLock) if(String.IsNullOrEmpty(cachePath))
doMeshFileCache = false;
if(doMeshFileCache)
{ {
if(doMeshFileCache && cachePath != "") if(!checkCache())
{
try
{
if (!Directory.Exists(cachePath))
Directory.CreateDirectory(cachePath);
}
catch
{ {
doMeshFileCache = false; doMeshFileCache = false;
doCacheExpire = false; doCacheExpire = false;
} }
} }
} else
doCacheExpire = false;
} }
} }
@ -283,7 +278,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
{ {
List<Coord> convexcoords; List<Coord> convexcoords;
List<Face> convexfaces; List<Face> convexfaces;
if(CreateHull(coords, out convexcoords, out convexfaces) && convexcoords != null && convexfaces != null) if(CreateBoundingHull(coords, out convexcoords, out convexfaces) && convexcoords != null && convexfaces != null)
{ {
coords.Clear(); coords.Clear();
coords = convexcoords; coords = convexcoords;
@ -565,45 +560,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
vs.Clear(); vs.Clear();
continue; continue;
} }
/*
if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f))
{
vs.Clear();
continue;
}
nverts = hullr.Vertices.Count;
nindexs = hullr.Indices.Count;
if (nindexs % 3 != 0)
{
vs.Clear();
continue;
}
for (i = 0; i < nverts; i++)
{
c.X = hullr.Vertices[i].x;
c.Y = hullr.Vertices[i].y;
c.Z = hullr.Vertices[i].z;
coords.Add(c);
}
for (i = 0; i < nindexs; i += 3)
{
t1 = hullr.Indices[i];
if (t1 > nverts)
break;
t2 = hullr.Indices[i + 1];
if (t2 > nverts)
break;
t3 = hullr.Indices[i + 2];
if (t3 > nverts)
break;
f = new Face(vertsoffset + t1, vertsoffset + t2, vertsoffset + t3);
faces.Add(f);
}
*/
List<int> indices; List<int> indices;
if (!HullUtils.ComputeHull(vs, out indices)) if (!HullUtils.ComputeHull(vs, out indices))
{ {
@ -709,38 +666,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
vs.Clear(); vs.Clear();
return true; return true;
} }
/*
if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f))
return false;
nverts = hullr.Vertices.Count;
nindexs = hullr.Indices.Count;
if (nindexs % 3 != 0)
return false;
for (i = 0; i < nverts; i++)
{
c.X = hullr.Vertices[i].x;
c.Y = hullr.Vertices[i].y;
c.Z = hullr.Vertices[i].z;
coords.Add(c);
}
for (i = 0; i < nindexs; i += 3)
{
t1 = hullr.Indices[i];
if (t1 > nverts)
break;
t2 = hullr.Indices[i + 1];
if (t2 > nverts)
break;
t3 = hullr.Indices[i + 2];
if (t3 > nverts)
break;
f = new Face(t1, t2, t3);
faces.Add(f);
}
*/
List<int> indices; List<int> indices;
if (!HullUtils.ComputeHull(vs, out indices)) if (!HullUtils.ComputeHull(vs, out indices))
return false; return false;
@ -1470,7 +1396,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
if (!doCacheExpire) if (!doCacheExpire)
return; return;
string controlfile = System.IO.Path.Combine(cachePath, "cntr"); string controlfile = System.IO.Path.Combine(cachePath, cacheControlFilename);
lock (diskLock) lock (diskLock)
{ {
@ -1524,7 +1450,81 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
} }
} }
public bool CreateHull(List<Coord> inputVertices, out List<Coord> convexcoords, out List<Face> newfaces) public bool checkCache()
{
string controlfile = System.IO.Path.Combine(cachePath, cacheControlFilename);
lock (diskLock)
{
try
{
if (!Directory.Exists(cachePath))
{
Directory.CreateDirectory(cachePath);
Thread.Sleep(100);
FileStream fs = File.Create(controlfile, 4096, FileOptions.WriteThrough);
fs.Close();
return true;
}
}
catch
{
doMeshFileCache = false;
doCacheExpire = false;
return false;
}
finally {}
if (File.Exists(controlfile))
return true;
try
{
Directory.Delete(cachePath, true);
while(Directory.Exists(cachePath))
Thread.Sleep(100);
}
catch(Exception e)
{
m_log.Error("[MESH CACHE]: failed to delete old version of the cache: " + e.Message);
doMeshFileCache = false;
doCacheExpire = false;
return false;
}
finally {}
try
{
Directory.CreateDirectory(cachePath);
while(!Directory.Exists(cachePath))
Thread.Sleep(100);
}
catch(Exception e)
{
m_log.Error("[MESH CACHE]: failed to create new cache folder: " + e.Message);
doMeshFileCache = false;
doCacheExpire = false;
return false;
}
finally {}
try
{
FileStream fs = File.Create(controlfile, 4096, FileOptions.WriteThrough);
fs.Close();
}
catch(Exception e)
{
m_log.Error("[MESH CACHE]: failed to create new control file: " + e.Message);
doMeshFileCache = false;
doCacheExpire = false;
return false;
}
finally {}
return true;
}
}
public bool CreateBoundingHull(List<Coord> inputVertices, out List<Coord> convexcoords, out List<Face> newfaces)
{ {
convexcoords = null; convexcoords = null;
newfaces = null; newfaces = null;