refactor: move the code that generates physics meshs from prim mesh data into a separate method, in order to make the code more readable.

bulletsim
Justin Clark-Casey (justincc) 2011-07-30 02:08:32 +01:00
parent 7791c1fd1e
commit 122e01949d
1 changed files with 126 additions and 102 deletions

View File

@ -301,28 +301,17 @@ namespace OpenSim.Region.Physics.Meshing
}
}
private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, Vector3 size, float lod)
/// <summary>
/// Generate the co-ords and faces necessary to construct a mesh from the mesh data the accompanies a prim.
/// </summary>
/// <param name="primName"></param>
/// <param name="primShape"></param>
/// <param name="size"></param>
/// <param name="coords">Coords are added to this list by the method.</param>
/// <param name="faces">Faces are added to this list by the method.</param>
/// <returns>true if coords and faces were successfully generated, false if not</returns>
private bool GenerateCoordsAndFacesFromPrimMeshData(string primName, PrimitiveBaseShape primShape, Vector3 size, List<Coord> coords, List<Face> faces)
{
// m_log.DebugFormat(
// "[MESH]: Creating physics proxy for {0}, shape {1}",
// primName, (OpenMetaverse.SculptType)primShape.SculptType);
PrimMesh primMesh;
PrimMesher.SculptMesh sculptMesh;
List<Coord> coords = new List<Coord>();
List<Face> faces = new List<Face>();
Image idata = null;
string decodedSculptFileName = "";
if (primShape.SculptEntry)
{
if (((OpenMetaverse.SculptType)primShape.SculptType) == SculptType.Mesh)
{
if (!useMeshiesPhysicsMesh)
return null;
m_log.DebugFormat("[MESH]: experimental mesh proxy generation for {0}", primName);
OSD meshOsd = null;
@ -330,7 +319,7 @@ namespace OpenSim.Region.Physics.Meshing
if (primShape.SculptData.Length <= 0)
{
m_log.Error("[MESH]: asset data is zero length");
return null;
return false;
}
long start = 0;
@ -344,7 +333,7 @@ namespace OpenSim.Region.Physics.Meshing
else
{
m_log.Warn("[Mesh}: unable to cast mesh asset to OSDMap");
return null;
return false;
}
}
catch (Exception e)
@ -367,14 +356,14 @@ namespace OpenSim.Region.Physics.Meshing
if (physicsParms == null)
{
m_log.Warn("[MESH]: no recognized physics mesh found in mesh asset");
return null;
return false;
}
int physOffset = physicsParms["offset"].AsInteger() + (int)start;
int physSize = physicsParms["size"].AsInteger();
if (physOffset < 0 || physSize == 0)
return null; // no mesh data in asset
return false; // no mesh data in asset
OSD decodedMeshOsd = new OSD();
byte[] meshBytes = new byte[physSize];
@ -407,7 +396,7 @@ namespace OpenSim.Region.Physics.Meshing
catch (Exception e)
{
m_log.Error("[MESH]: exception decoding physical mesh: " + e.ToString());
return null;
return false;
}
OSDArray decodedMeshOsdArray = null;
@ -425,6 +414,41 @@ namespace OpenSim.Region.Physics.Meshing
}
}
}
return true;
}
/// <summary>
/// Create a physics mesh from data that comes with the prim. The actual data used depends on the prim type.
/// </summary>
/// <param name="primName"></param>
/// <param name="primShape"></param>
/// <param name="size"></param>
/// <param name="lod"></param>
/// <returns></returns>
private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, Vector3 size, float lod)
{
// m_log.DebugFormat(
// "[MESH]: Creating physics proxy for {0}, shape {1}",
// primName, (OpenMetaverse.SculptType)primShape.SculptType);
PrimMesh primMesh;
PrimMesher.SculptMesh sculptMesh;
List<Coord> coords = new List<Coord>();
List<Face> faces = new List<Face>();
Image idata = null;
string decodedSculptFileName = "";
if (primShape.SculptEntry)
{
if (((OpenMetaverse.SculptType)primShape.SculptType) == SculptType.Mesh)
{
if (!useMeshiesPhysicsMesh)
return null;
GeneratePointsAndFacesFromPrimMeshData(primName, primShape, size, coords, faces);
}
else
{