From c5549d27306c71cd5ed96e7cba68bd28d5e6d9b0 Mon Sep 17 00:00:00 2001 From: dahlia Date: Thu, 23 May 2013 15:47:47 -0700 Subject: [PATCH] add decoder for bounding convex hull --- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 57 +++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index adc0dc9dd1..fd45efe126 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -83,6 +83,7 @@ namespace OpenSim.Region.Physics.Meshing private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh private List> mConvexHulls = null; + private List mBoundingHull = null; private Dictionary m_uniqueMeshes = new Dictionary(); @@ -324,6 +325,9 @@ namespace OpenSim.Region.Physics.Meshing faces = new List(); OSD meshOsd = null; + mConvexHulls = null; + mBoundingHull = null; + if (primShape.SculptData.Length <= 0) { // XXX: At the moment we can not log here since ODEPrim, for instance, ends up triggering this @@ -385,13 +389,41 @@ namespace OpenSim.Region.Physics.Meshing try { OSDMap convexBlock = (OSDMap)map["physics_convex"]; + + Vector3 min = new Vector3(-0.5f, -0.5f, -0.5f); + if (convexBlock.ContainsKey("Min")) min = convexBlock["Min"].AsVector3(); + Vector3 max = new Vector3(0.5f, 0.5f, 0.5f); + if (convexBlock.ContainsKey("Max")) max = convexBlock["Max"].AsVector3(); + + List boundingHull = null; + + if (convexBlock.ContainsKey("BoundingVerts")) + { + // decompress and decode bounding hull points + byte[] boundingVertsBytes = DecompressOsd(convexBlock["BoundingVerts"].AsBinary()).AsBinary(); + boundingHull = new List(); + for (int i = 0; i < boundingVertsBytes.Length;) + { + ushort uX = Utils.BytesToUInt16(boundingVertsBytes, i); i += 2; + ushort uY = Utils.BytesToUInt16(boundingVertsBytes, i); i += 2; + ushort uZ = Utils.BytesToUInt16(boundingVertsBytes, i); i += 2; + + Vector3 pos = new Vector3( + Utils.UInt16ToFloat(uX, min.X, max.X), + Utils.UInt16ToFloat(uY, min.Y, max.Y), + Utils.UInt16ToFloat(uZ, min.Z, max.Z) + ); + + boundingHull.Add(pos); + } + + mBoundingHull = boundingHull; + if (debugDetail) m_log.DebugFormat("{0} prim='{1}': parsed bounding hull. nHulls={2}", LogHeader, primName, mBoundingHull.Count); + } + if (convexBlock.ContainsKey("HullList")) { byte[] hullList = convexBlock["HullList"].AsBinary(); - Vector3 min = new Vector3(-0.5f, -0.5f, -0.5f); - if (convexBlock.ContainsKey("Min")) min = convexBlock["Min"].AsVector3(); - Vector3 max = new Vector3(0.5f, 0.5f, 0.5f); - if (convexBlock.ContainsKey("Max")) max = convexBlock["Max"].AsVector3(); // decompress and decode hull points byte[] posBytes = DecompressOsd(convexBlock["Positions"].AsBinary()).AsBinary(); @@ -795,6 +827,23 @@ namespace OpenSim.Region.Physics.Meshing return true; } + /// + /// temporary prototype code - please do not use until the interface has been finalized! + /// + /// value to scale the hull points by + /// a list of vertices in the bounding hull if it exists and has been successfully decoded, otherwise null + public List GetBoundingHull(Vector3 size) + { + if (mBoundingHull == null) + return null; + + List verts = new List(); + foreach (var vert in mBoundingHull) + verts.Add(vert * size); + + return verts; + } + /// /// temporary prototype code - please do not use until the interface has been finalized! ///