correct some errors in decoding of mesh asset convex decomposition data

user_profiles
dahlia 2013-05-24 01:53:37 -07:00
parent e597a7d94e
commit 0cdea5c2f3
1 changed files with 83 additions and 53 deletions

View File

@ -386,9 +386,40 @@ namespace OpenSim.Region.Physics.Meshing
if (map.ContainsKey("physics_convex")) if (map.ContainsKey("physics_convex"))
{ // pull this out also in case physics engine can use it { // pull this out also in case physics engine can use it
OSD convexBlockOsd = null;
try try
{ {
OSDMap convexBlock = (OSDMap)map["physics_convex"]; OSDMap convexBlock = (OSDMap)map["physics_convex"];
{
int convexOffset = convexBlock["offset"].AsInteger() + (int)start;
int convexSize = convexBlock["size"].AsInteger();
byte[] convexBytes = new byte[convexSize];
System.Buffer.BlockCopy(primShape.SculptData, convexOffset, convexBytes, 0, convexSize);
try
{
convexBlockOsd = DecompressOsd(convexBytes);
}
catch (Exception e)
{
m_log.ErrorFormat("{0} prim='{1}': exception decoding convex block: {2}", LogHeader, primName, e);
//return false;
}
}
if (convexBlockOsd != null && convexBlockOsd is OSDMap)
{
convexBlock = convexBlockOsd as OSDMap;
if (debugDetail)
{
string keys = "[MESH]: keys found in convexBlock: ";
foreach (KeyValuePair<string, OSD> kvp in convexBlock)
keys += "'" + kvp.Key + "' ";
m_log.Info(keys);
}
Vector3 min = new Vector3(-0.5f, -0.5f, -0.5f); Vector3 min = new Vector3(-0.5f, -0.5f, -0.5f);
if (convexBlock.ContainsKey("Min")) min = convexBlock["Min"].AsVector3(); if (convexBlock.ContainsKey("Min")) min = convexBlock["Min"].AsVector3();
@ -399,10 +430,9 @@ namespace OpenSim.Region.Physics.Meshing
if (convexBlock.ContainsKey("BoundingVerts")) if (convexBlock.ContainsKey("BoundingVerts"))
{ {
// decompress and decode bounding hull points byte[] boundingVertsBytes = convexBlock["BoundingVerts"].AsBinary();
byte[] boundingVertsBytes = DecompressOsd(convexBlock["BoundingVerts"].AsBinary()).AsBinary();
boundingHull = new List<Vector3>(); boundingHull = new List<Vector3>();
for (int i = 0; i < boundingVertsBytes.Length;) for (int i = 0; i < boundingVertsBytes.Length; )
{ {
ushort uX = Utils.BytesToUInt16(boundingVertsBytes, i); i += 2; ushort uX = Utils.BytesToUInt16(boundingVertsBytes, i); i += 2;
ushort uY = Utils.BytesToUInt16(boundingVertsBytes, i); i += 2; ushort uY = Utils.BytesToUInt16(boundingVertsBytes, i); i += 2;
@ -418,15 +448,14 @@ namespace OpenSim.Region.Physics.Meshing
} }
mBoundingHull = boundingHull; mBoundingHull = boundingHull;
if (debugDetail) m_log.DebugFormat("{0} prim='{1}': parsed bounding hull. nHulls={2}", LogHeader, primName, mBoundingHull.Count); if (debugDetail) m_log.DebugFormat("{0} prim='{1}': parsed bounding hull. nVerts={2}", LogHeader, primName, mBoundingHull.Count);
} }
if (convexBlock.ContainsKey("HullList")) if (convexBlock.ContainsKey("HullList"))
{ {
byte[] hullList = convexBlock["HullList"].AsBinary(); byte[] hullList = convexBlock["HullList"].AsBinary();
// decompress and decode hull points byte[] posBytes = convexBlock["Positions"].AsBinary();
byte[] posBytes = DecompressOsd(convexBlock["Positions"].AsBinary()).AsBinary();
List<List<Vector3>> hulls = new List<List<Vector3>>(); List<List<Vector3>> hulls = new List<List<Vector3>>();
int posNdx = 0; int posNdx = 0;
@ -462,6 +491,7 @@ namespace OpenSim.Region.Physics.Meshing
if (debugDetail) m_log.DebugFormat("{0} prim='{1}' has physics_convex but no HullList", LogHeader, primName); if (debugDetail) m_log.DebugFormat("{0} prim='{1}' has physics_convex but no HullList", LogHeader, primName);
} }
} }
}
catch (Exception e) catch (Exception e)
{ {
m_log.WarnFormat("{0} exception decoding convex block: {1}", LogHeader, e); m_log.WarnFormat("{0} exception decoding convex block: {1}", LogHeader, e);
@ -483,7 +513,7 @@ namespace OpenSim.Region.Physics.Meshing
OSD decodedMeshOsd = new OSD(); OSD decodedMeshOsd = new OSD();
byte[] meshBytes = new byte[physSize]; byte[] meshBytes = new byte[physSize];
System.Buffer.BlockCopy(primShape.SculptData, physOffset, meshBytes, 0, physSize); System.Buffer.BlockCopy(primShape.SculptData, physOffset, meshBytes, 0, physSize);
// byte[] decompressed = new byte[physSize * 5]; // byte[] decompressed = new byte[physSize * 5];
try try
{ {
decodedMeshOsd = DecompressOsd(meshBytes); decodedMeshOsd = DecompressOsd(meshBytes);
@ -499,7 +529,7 @@ namespace OpenSim.Region.Physics.Meshing
// physics_shape is an array of OSDMaps, one for each submesh // physics_shape is an array of OSDMaps, one for each submesh
if (decodedMeshOsd is OSDArray) if (decodedMeshOsd is OSDArray)
{ {
// Console.WriteLine("decodedMeshOsd for {0} - {1}", primName, Util.GetFormattedXml(decodedMeshOsd)); // Console.WriteLine("decodedMeshOsd for {0} - {1}", primName, Util.GetFormattedXml(decodedMeshOsd));
decodedMeshOsdArray = (OSDArray)decodedMeshOsd; decodedMeshOsdArray = (OSDArray)decodedMeshOsd;
foreach (OSD subMeshOsd in decodedMeshOsdArray) foreach (OSD subMeshOsd in decodedMeshOsdArray)