From 122e01949df847d865d4ae5320ae926e5189c2ee Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sat, 30 Jul 2011 02:08:32 +0100
Subject: refactor: move the code that generates physics meshs from prim mesh
data into a separate method, in order to make the code more readable.
---
OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 222 ++++++++++++++------------
1 file changed, 123 insertions(+), 99 deletions(-)
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
index 8a9260c..f97449c 100644
--- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
@@ -301,131 +301,155 @@ namespace OpenSim.Region.Physics.Meshing
}
}
- private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, Vector3 size, float lod)
+ ///
+ /// Generate the co-ords and faces necessary to construct a mesh from the mesh data the accompanies a prim.
+ ///
+ ///
+ ///
+ ///
+ /// Coords are added to this list by the method.
+ /// Faces are added to this list by the method.
+ /// true if coords and faces were successfully generated, false if not
+ private bool GenerateCoordsAndFacesFromPrimMeshData(string primName, PrimitiveBaseShape primShape, Vector3 size, List coords, List faces)
{
-// m_log.DebugFormat(
-// "[MESH]: Creating physics proxy for {0}, shape {1}",
-// primName, (OpenMetaverse.SculptType)primShape.SculptType);
+ m_log.DebugFormat("[MESH]: experimental mesh proxy generation for {0}", primName);
- PrimMesh primMesh;
- PrimMesher.SculptMesh sculptMesh;
-
- List coords = new List();
- List faces = new List();
+ OSD meshOsd = null;
- Image idata = null;
- string decodedSculptFileName = "";
+ if (primShape.SculptData.Length <= 0)
+ {
+ m_log.Error("[MESH]: asset data is zero length");
+ return false;
+ }
- if (primShape.SculptEntry)
+ long start = 0;
+ using (MemoryStream data = new MemoryStream(primShape.SculptData))
{
- if (((OpenMetaverse.SculptType)primShape.SculptType) == SculptType.Mesh)
+ try
{
- if (!useMeshiesPhysicsMesh)
- return null;
-
- m_log.DebugFormat("[MESH]: experimental mesh proxy generation for {0}", primName);
-
- OSD meshOsd = null;
-
- if (primShape.SculptData.Length <= 0)
+ OSD osd = OSDParser.DeserializeLLSDBinary(data);
+ if (osd is OSDMap)
+ meshOsd = (OSDMap)osd;
+ else
{
- m_log.Error("[MESH]: asset data is zero length");
- return null;
+ m_log.Warn("[Mesh}: unable to cast mesh asset to OSDMap");
+ return false;
}
+ }
+ catch (Exception e)
+ {
+ m_log.Error("[MESH]: Exception deserializing mesh asset header:" + e.ToString());
+ }
- long start = 0;
- using (MemoryStream data = new MemoryStream(primShape.SculptData))
- {
- try
- {
- OSD osd = OSDParser.DeserializeLLSDBinary(data);
- if (osd is OSDMap)
- meshOsd = (OSDMap)osd;
- else
- {
- m_log.Warn("[Mesh}: unable to cast mesh asset to OSDMap");
- return null;
- }
- }
- catch (Exception e)
- {
- m_log.Error("[MESH]: Exception deserializing mesh asset header:" + e.ToString());
- }
-
- start = data.Position;
- }
+ start = data.Position;
+ }
- if (meshOsd is OSDMap)
- {
- OSDMap physicsParms = null;
- OSDMap map = (OSDMap)meshOsd;
- if (map.ContainsKey("physics_shape"))
- physicsParms = (OSDMap)map["physics_shape"]; // old asset format
- else if (map.ContainsKey("physics_mesh"))
- physicsParms = (OSDMap)map["physics_mesh"]; // new asset format
-
- if (physicsParms == null)
- {
- m_log.Warn("[MESH]: no recognized physics mesh found in mesh asset");
- return null;
- }
+ if (meshOsd is OSDMap)
+ {
+ OSDMap physicsParms = null;
+ OSDMap map = (OSDMap)meshOsd;
+ if (map.ContainsKey("physics_shape"))
+ physicsParms = (OSDMap)map["physics_shape"]; // old asset format
+ else if (map.ContainsKey("physics_mesh"))
+ physicsParms = (OSDMap)map["physics_mesh"]; // new asset format
+
+ if (physicsParms == null)
+ {
+ m_log.Warn("[MESH]: no recognized physics mesh found in mesh asset");
+ return false;
+ }
- int physOffset = physicsParms["offset"].AsInteger() + (int)start;
- int physSize = physicsParms["size"].AsInteger();
+ int physOffset = physicsParms["offset"].AsInteger() + (int)start;
+ int physSize = physicsParms["size"].AsInteger();
- if (physOffset < 0 || physSize == 0)
- return null; // no mesh data in asset
+ if (physOffset < 0 || physSize == 0)
+ return false; // no mesh data in asset
- OSD decodedMeshOsd = new OSD();
- byte[] meshBytes = new byte[physSize];
- System.Buffer.BlockCopy(primShape.SculptData, physOffset, meshBytes, 0, physSize);
+ OSD decodedMeshOsd = new OSD();
+ byte[] meshBytes = new byte[physSize];
+ System.Buffer.BlockCopy(primShape.SculptData, physOffset, meshBytes, 0, physSize);
// byte[] decompressed = new byte[physSize * 5];
- try
+ try
+ {
+ using (MemoryStream inMs = new MemoryStream(meshBytes))
+ {
+ using (MemoryStream outMs = new MemoryStream())
{
- using (MemoryStream inMs = new MemoryStream(meshBytes))
+ using (ZOutputStream zOut = new ZOutputStream(outMs))
{
- using (MemoryStream outMs = new MemoryStream())
+ byte[] readBuffer = new byte[2048];
+ int readLen = 0;
+ while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0)
{
- using (ZOutputStream zOut = new ZOutputStream(outMs))
- {
- byte[] readBuffer = new byte[2048];
- int readLen = 0;
- while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0)
- {
- zOut.Write(readBuffer, 0, readLen);
- }
- zOut.Flush();
- outMs.Seek(0, SeekOrigin.Begin);
-
- byte[] decompressedBuf = outMs.GetBuffer();
-
- decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
- }
+ zOut.Write(readBuffer, 0, readLen);
}
+ zOut.Flush();
+ outMs.Seek(0, SeekOrigin.Begin);
+
+ byte[] decompressedBuf = outMs.GetBuffer();
+
+ decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
}
}
- catch (Exception e)
- {
- m_log.Error("[MESH]: exception decoding physical mesh: " + e.ToString());
- return null;
- }
+ }
+ }
+ catch (Exception e)
+ {
+ m_log.Error("[MESH]: exception decoding physical mesh: " + e.ToString());
+ return false;
+ }
- OSDArray decodedMeshOsdArray = null;
+ OSDArray decodedMeshOsdArray = null;
- // physics_shape is an array of OSDMaps, one for each submesh
- if (decodedMeshOsd is OSDArray)
- {
+ // physics_shape is an array of OSDMaps, one for each submesh
+ if (decodedMeshOsd is OSDArray)
+ {
// Console.WriteLine("decodedMeshOsd for {0} - {1}", primName, Util.GetFormattedXml(decodedMeshOsd));
- decodedMeshOsdArray = (OSDArray)decodedMeshOsd;
- foreach (OSD subMeshOsd in decodedMeshOsdArray)
- {
- if (subMeshOsd is OSDMap)
- AddSubMesh(subMeshOsd as OSDMap, size, coords, faces);
- }
- }
+ decodedMeshOsdArray = (OSDArray)decodedMeshOsd;
+ foreach (OSD subMeshOsd in decodedMeshOsdArray)
+ {
+ if (subMeshOsd is OSDMap)
+ AddSubMesh(subMeshOsd as OSDMap, size, coords, faces);
}
}
+ }
+
+ return true;
+ }
+
+ ///
+ /// Create a physics mesh from data that comes with the prim. The actual data used depends on the prim type.
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ 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 coords = new List();
+ List faces = new List();
+
+ 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
{
if (cacheSculptMaps && primShape.SculptTexture != UUID.Zero)
--
cgit v1.1