aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/Meshing/Meshmerizer.cs131
1 files changed, 110 insertions, 21 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
index 2d102de..825e622 100644
--- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
@@ -79,6 +79,8 @@ namespace OpenSim.Region.Physics.Meshing
79 79
80 private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh 80 private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh
81 81
82 private List<List<Vector3>> mConvexHulls = null;
83
82 private Dictionary<ulong, Mesh> m_uniqueMeshes = new Dictionary<ulong, Mesh>(); 84 private Dictionary<ulong, Mesh> m_uniqueMeshes = new Dictionary<ulong, Mesh>();
83 85
84 public Meshmerizer(IConfigSource config) 86 public Meshmerizer(IConfigSource config)
@@ -363,6 +365,57 @@ namespace OpenSim.Region.Physics.Meshing
363 else if (map.ContainsKey("high_lod")) 365 else if (map.ContainsKey("high_lod"))
364 physicsParms = (OSDMap)map["high_lod"]; // if all else fails, use highest LOD display mesh and hope it works :) 366 physicsParms = (OSDMap)map["high_lod"]; // if all else fails, use highest LOD display mesh and hope it works :)
365 367
368 if (map.ContainsKey("physics_convex"))
369 { // pull this out also in case physics engine can use it
370 try
371 {
372 OSDMap convexBlock = (OSDMap)map["physics_convex"];
373 if (convexBlock.ContainsKey("HullList"))
374 {
375 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
381 // decompress and decode hull points
382 byte[] posBytes = DecompressOsd(convexBlock["Positions"].AsBinary()).AsBinary();
383
384 List<List<Vector3>> hulls = new List<List<Vector3>>();
385 int posNdx = 0;
386
387 foreach (byte cnt in hullList)
388 {
389 int count = cnt == 0 ? 256 : cnt;
390 List<Vector3> hull = new List<Vector3>();
391
392 for (int i = 0; i < cnt; i++)
393 {
394 ushort uX = Utils.BytesToUInt16(posBytes, posNdx); posNdx += 2;
395 ushort uY = Utils.BytesToUInt16(posBytes, posNdx); posNdx += 2;
396 ushort uZ = Utils.BytesToUInt16(posBytes, posNdx); posNdx += 2;
397
398 Vector3 pos = new Vector3(
399 Utils.UInt16ToFloat(uX, min.X, max.X) * size.X,
400 Utils.UInt16ToFloat(uY, min.Y, max.Y) * size.Y,
401 Utils.UInt16ToFloat(uZ, min.Z, max.Z) * size.Z
402 );
403
404 hull.Add(pos);
405 }
406
407 hulls.Add(hull);
408 }
409
410 mConvexHulls = hulls;
411 }
412 }
413 catch (Exception e)
414 {
415 m_log.WarnFormat("[MESH]: exception decoding convex block: {0}", e.Message);
416 }
417 }
418
366 if (physicsParms == null) 419 if (physicsParms == null)
367 { 420 {
368 m_log.WarnFormat("[MESH]: No recognized physics mesh found in mesh asset for {0}", primName); 421 m_log.WarnFormat("[MESH]: No recognized physics mesh found in mesh asset for {0}", primName);
@@ -381,27 +434,7 @@ namespace OpenSim.Region.Physics.Meshing
381// byte[] decompressed = new byte[physSize * 5]; 434// byte[] decompressed = new byte[physSize * 5];
382 try 435 try
383 { 436 {
384 using (MemoryStream inMs = new MemoryStream(meshBytes)) 437 decodedMeshOsd = DecompressOsd(meshBytes);
385 {
386 using (MemoryStream outMs = new MemoryStream())
387 {
388 using (ZOutputStream zOut = new ZOutputStream(outMs))
389 {
390 byte[] readBuffer = new byte[2048];
391 int readLen = 0;
392 while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0)
393 {
394 zOut.Write(readBuffer, 0, readLen);
395 }
396 zOut.Flush();
397 outMs.Seek(0, SeekOrigin.Begin);
398
399 byte[] decompressedBuf = outMs.GetBuffer();
400
401 decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
402 }
403 }
404 }
405 } 438 }
406 catch (Exception e) 439 catch (Exception e)
407 { 440 {
@@ -428,6 +461,41 @@ namespace OpenSim.Region.Physics.Meshing
428 return true; 461 return true;
429 } 462 }
430 463
464
465 /// <summary>
466 /// decompresses a gzipped OSD object
467 /// </summary>
468 /// <param name="decodedOsd"></param> the OSD object
469 /// <param name="meshBytes"></param>
470 /// <returns></returns>
471 private static OSD DecompressOsd(byte[] meshBytes)
472 {
473 OSD decodedOsd = null;
474
475 using (MemoryStream inMs = new MemoryStream(meshBytes))
476 {
477 using (MemoryStream outMs = new MemoryStream())
478 {
479 using (ZOutputStream zOut = new ZOutputStream(outMs))
480 {
481 byte[] readBuffer = new byte[2048];
482 int readLen = 0;
483 while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0)
484 {
485 zOut.Write(readBuffer, 0, readLen);
486 }
487 zOut.Flush();
488 outMs.Seek(0, SeekOrigin.Begin);
489
490 byte[] decompressedBuf = outMs.GetBuffer();
491
492 decodedOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
493 }
494 }
495 }
496 return decodedOsd;
497 }
498
431 /// <summary> 499 /// <summary>
432 /// Generate the co-ords and faces necessary to construct a mesh from the sculpt data the accompanies a prim. 500 /// Generate the co-ords and faces necessary to construct a mesh from the sculpt data the accompanies a prim.
433 /// </summary> 501 /// </summary>
@@ -704,6 +772,27 @@ namespace OpenSim.Region.Physics.Meshing
704 return true; 772 return true;
705 } 773 }
706 774
775 /// <summary>
776 /// temporary prototype code - please do not use until the interface has been finalized!
777 /// </summary>
778 /// <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>
780 public List<List<Vector3>> GetConvexHulls(Vector3 size)
781 {
782 if (mConvexHulls == null)
783 return null;
784
785 List<List<Vector3>> hulls = new List<List<Vector3>>();
786 foreach (var hull in mConvexHulls)
787 {
788 List<Vector3> verts = new List<Vector3>();
789 foreach (var vert in hull)
790 verts.Add(vert * size);
791 }
792
793 return hulls;
794 }
795
707 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod) 796 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod)
708 { 797 {
709 return CreateMesh(primName, primShape, size, lod, false, true); 798 return CreateMesh(primName, primShape, size, lod, false, true);