aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/Meshing
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/Meshing')
-rw-r--r--OpenSim/Region/Physics/Meshing/Meshmerizer.cs84
1 files changed, 78 insertions, 6 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
index db5d962..ffdee0f 100644
--- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
@@ -64,6 +64,7 @@ namespace OpenSim.Region.Physics.Meshing
64 public class Meshmerizer : IMesher 64 public class Meshmerizer : IMesher
65 { 65 {
66 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 66 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
67 private static string LogHeader = "[MESH]";
67 68
68 // Setting baseDir to a path will enable the dumping of raw files 69 // Setting baseDir to a path will enable the dumping of raw files
69 // raw files can be imported by blender so a visual inspection of the results can be done 70 // raw files can be imported by blender so a visual inspection of the results can be done
@@ -72,6 +73,8 @@ namespace OpenSim.Region.Physics.Meshing
72#else 73#else
73 private const string baseDir = null; //"rawFiles"; 74 private const string baseDir = null; //"rawFiles";
74#endif 75#endif
76 // If 'true', lots of DEBUG logging of asset parsing details
77 private bool debugDetail = true;
75 78
76 private bool cacheSculptMaps = true; 79 private bool cacheSculptMaps = true;
77 private string decodedSculptMapPath = null; 80 private string decodedSculptMapPath = null;
@@ -80,6 +83,7 @@ namespace OpenSim.Region.Physics.Meshing
80 private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh 83 private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh
81 84
82 private List<List<Vector3>> mConvexHulls = null; 85 private List<List<Vector3>> mConvexHulls = null;
86 private List<Vector3> mBoundingHull = null;
83 87
84 private Dictionary<ulong, Mesh> m_uniqueMeshes = new Dictionary<ulong, Mesh>(); 88 private Dictionary<ulong, Mesh> m_uniqueMeshes = new Dictionary<ulong, Mesh>();
85 89
@@ -321,6 +325,9 @@ namespace OpenSim.Region.Physics.Meshing
321 faces = new List<Face>(); 325 faces = new List<Face>();
322 OSD meshOsd = null; 326 OSD meshOsd = null;
323 327
328 mConvexHulls = null;
329 mBoundingHull = null;
330
324 if (primShape.SculptData.Length <= 0) 331 if (primShape.SculptData.Length <= 0)
325 { 332 {
326 // XXX: At the moment we can not log here since ODEPrim, for instance, ends up triggering this 333 // XXX: At the moment we can not log here since ODEPrim, for instance, ends up triggering this
@@ -357,26 +364,66 @@ namespace OpenSim.Region.Physics.Meshing
357 OSDMap physicsParms = null; 364 OSDMap physicsParms = null;
358 OSDMap map = (OSDMap)meshOsd; 365 OSDMap map = (OSDMap)meshOsd;
359 if (map.ContainsKey("physics_shape")) 366 if (map.ContainsKey("physics_shape"))
367 {
360 physicsParms = (OSDMap)map["physics_shape"]; // old asset format 368 physicsParms = (OSDMap)map["physics_shape"]; // old asset format
369 if (debugDetail) m_log.DebugFormat("{0} prim='{1}': using 'physics_shape' mesh data", LogHeader, primName);
370 }
361 else if (map.ContainsKey("physics_mesh")) 371 else if (map.ContainsKey("physics_mesh"))
372 {
362 physicsParms = (OSDMap)map["physics_mesh"]; // new asset format 373 physicsParms = (OSDMap)map["physics_mesh"]; // new asset format
374 if (debugDetail) m_log.DebugFormat("{0} prim='{1}':using 'physics_mesh' mesh data", LogHeader, primName);
375 }
363 else if (map.ContainsKey("medium_lod")) 376 else if (map.ContainsKey("medium_lod"))
377 {
364 physicsParms = (OSDMap)map["medium_lod"]; // if no physics mesh, try to fall back to medium LOD display mesh 378 physicsParms = (OSDMap)map["medium_lod"]; // if no physics mesh, try to fall back to medium LOD display mesh
379 if (debugDetail) m_log.DebugFormat("{0} prim='{1}':using 'medium_lod' mesh data", LogHeader, primName);
380 }
365 else if (map.ContainsKey("high_lod")) 381 else if (map.ContainsKey("high_lod"))
382 {
366 physicsParms = (OSDMap)map["high_lod"]; // if all else fails, use highest LOD display mesh and hope it works :) 383 physicsParms = (OSDMap)map["high_lod"]; // if all else fails, use highest LOD display mesh and hope it works :)
384 if (debugDetail) m_log.DebugFormat("{0} prim='{1}':using 'high_lod' mesh data", LogHeader, primName);
385 }
367 386
368 if (map.ContainsKey("physics_convex")) 387 if (map.ContainsKey("physics_convex"))
369 { // pull this out also in case physics engine can use it 388 { // pull this out also in case physics engine can use it
370 try 389 try
371 { 390 {
372 OSDMap convexBlock = (OSDMap)map["physics_convex"]; 391 OSDMap convexBlock = (OSDMap)map["physics_convex"];
392
393 Vector3 min = new Vector3(-0.5f, -0.5f, -0.5f);
394 if (convexBlock.ContainsKey("Min")) min = convexBlock["Min"].AsVector3();
395 Vector3 max = new Vector3(0.5f, 0.5f, 0.5f);
396 if (convexBlock.ContainsKey("Max")) max = convexBlock["Max"].AsVector3();
397
398 List<Vector3> boundingHull = null;
399
400 if (convexBlock.ContainsKey("BoundingVerts"))
401 {
402 // decompress and decode bounding hull points
403 byte[] boundingVertsBytes = DecompressOsd(convexBlock["BoundingVerts"].AsBinary()).AsBinary();
404 boundingHull = new List<Vector3>();
405 for (int i = 0; i < boundingVertsBytes.Length;)
406 {
407 ushort uX = Utils.BytesToUInt16(boundingVertsBytes, i); i += 2;
408 ushort uY = Utils.BytesToUInt16(boundingVertsBytes, i); i += 2;
409 ushort uZ = Utils.BytesToUInt16(boundingVertsBytes, i); i += 2;
410
411 Vector3 pos = new Vector3(
412 Utils.UInt16ToFloat(uX, min.X, max.X),
413 Utils.UInt16ToFloat(uY, min.Y, max.Y),
414 Utils.UInt16ToFloat(uZ, min.Z, max.Z)
415 );
416
417 boundingHull.Add(pos);
418 }
419
420 mBoundingHull = boundingHull;
421 if (debugDetail) m_log.DebugFormat("{0} prim='{1}': parsed bounding hull. nHulls={2}", LogHeader, primName, mBoundingHull.Count);
422 }
423
373 if (convexBlock.ContainsKey("HullList")) 424 if (convexBlock.ContainsKey("HullList"))
374 { 425 {
375 byte[] hullList = convexBlock["HullList"].AsBinary(); 426 byte[] hullList = convexBlock["HullList"].AsBinary();
376 Vector3 min = new Vector3(-0.5f, -0.5f, -0.5f);
377 if (convexBlock.ContainsKey("Min")) min = convexBlock["Min"].AsVector3();
378 Vector3 max = new Vector3(0.5f, 0.5f, 0.5f);
379 if (convexBlock.ContainsKey("Max")) max = convexBlock["Max"].AsVector3();
380 427
381 // decompress and decode hull points 428 // decompress and decode hull points
382 byte[] posBytes = DecompressOsd(convexBlock["Positions"].AsBinary()).AsBinary(); 429 byte[] posBytes = DecompressOsd(convexBlock["Positions"].AsBinary()).AsBinary();
@@ -408,11 +455,16 @@ namespace OpenSim.Region.Physics.Meshing
408 } 455 }
409 456
410 mConvexHulls = hulls; 457 mConvexHulls = hulls;
458 if (debugDetail) m_log.DebugFormat("{0} prim='{1}': parsed hulls. nHulls={2}", LogHeader, primName, mConvexHulls.Count);
459 }
460 else
461 {
462 if (debugDetail) m_log.DebugFormat("{0} prim='{1}' has physics_convex but no HullList", LogHeader, primName);
411 } 463 }
412 } 464 }
413 catch (Exception e) 465 catch (Exception e)
414 { 466 {
415 m_log.WarnFormat("[MESH]: exception decoding convex block: {0}", e.Message); 467 m_log.WarnFormat("{0} exception decoding convex block: {1}", LogHeader, e);
416 } 468 }
417 } 469 }
418 470
@@ -438,7 +490,7 @@ namespace OpenSim.Region.Physics.Meshing
438 } 490 }
439 catch (Exception e) 491 catch (Exception e)
440 { 492 {
441 m_log.Error("[MESH]: exception decoding physical mesh: " + e.ToString()); 493 m_log.ErrorFormat("{0} prim='{1}': exception decoding physical mesh: {2}", LogHeader, primName, e);
442 return false; 494 return false;
443 } 495 }
444 496
@@ -455,6 +507,9 @@ namespace OpenSim.Region.Physics.Meshing
455 if (subMeshOsd is OSDMap) 507 if (subMeshOsd is OSDMap)
456 AddSubMesh(subMeshOsd as OSDMap, size, coords, faces); 508 AddSubMesh(subMeshOsd as OSDMap, size, coords, faces);
457 } 509 }
510 if (debugDetail)
511 m_log.DebugFormat("{0} {1}: mesh decoded. offset={2}, size={3}, nCoords={4}, nFaces={5}",
512 LogHeader, primName, physOffset, physSize, coords.Count, faces.Count);
458 } 513 }
459 } 514 }
460 515
@@ -776,6 +831,23 @@ namespace OpenSim.Region.Physics.Meshing
776 /// temporary prototype code - please do not use until the interface has been finalized! 831 /// temporary prototype code - please do not use until the interface has been finalized!
777 /// </summary> 832 /// </summary>
778 /// <param name="size">value to scale the hull points by</param> 833 /// <param name="size">value to scale the hull points by</param>
834 /// <returns>a list of vertices in the bounding hull if it exists and has been successfully decoded, otherwise null</returns>
835 public List<Vector3> GetBoundingHull(Vector3 size)
836 {
837 if (mBoundingHull == null)
838 return null;
839
840 List<Vector3> verts = new List<Vector3>();
841 foreach (var vert in mBoundingHull)
842 verts.Add(vert * size);
843
844 return verts;
845 }
846
847 /// <summary>
848 /// temporary prototype code - please do not use until the interface has been finalized!
849 /// </summary>
850 /// <param name="size">value to scale the hull points by</param>
779 /// <returns>a list of hulls if they exist and have been successfully decoded, otherwise null</returns> 851 /// <returns>a list of hulls if they exist and have been successfully decoded, otherwise null</returns>
780 public List<List<Vector3>> GetConvexHulls(Vector3 size) 852 public List<List<Vector3>> GetConvexHulls(Vector3 size)
781 { 853 {