aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs164
1 files changed, 146 insertions, 18 deletions
diff --git a/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs b/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs
index a04df81..a550342 100644
--- a/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs
@@ -308,7 +308,7 @@ namespace OpenSim.Region.Physics.Meshing
308 } 308 }
309 309
310 310
311 // mesh.DumpRaw("c:\\lixo", "lixo", "lixo"); 311// mesh.DumpRaw("c:\\lixo", "lixo", "lixo");
312 mesh.DumpRaw(".", "lixo", "lixo"); 312 mesh.DumpRaw(".", "lixo", "lixo");
313 313
314 return mesh; 314 return mesh;
@@ -329,7 +329,7 @@ namespace OpenSim.Region.Physics.Meshing
329// m_log.DebugFormat("[MESH]: experimental mesh proxy generation for {0}", primName); 329// m_log.DebugFormat("[MESH]: experimental mesh proxy generation for {0}", primName);
330 330
331 331
332 bool convex = true; // this will be a input 332 bool convex = false; // this will be a input
333 bool usemesh = false; 333 bool usemesh = false;
334 334
335 coords = new List<Coord>(); 335 coords = new List<Coord>();
@@ -430,7 +430,6 @@ namespace OpenSim.Region.Physics.Meshing
430 return false; 430 return false;
431 } 431 }
432 432
433
434 if (usemesh) 433 if (usemesh)
435 { 434 {
436 OSDArray decodedMeshOsdArray = null; 435 OSDArray decodedMeshOsdArray = null;
@@ -465,10 +464,14 @@ namespace OpenSim.Region.Physics.Meshing
465 464
466 float3 f3; 465 float3 f3;
467 PHullResult hullr = new PHullResult(); 466 PHullResult hullr = new PHullResult();
468 Mesh m = new Mesh(); 467
469 468 Coord c;
469 Face f;
470
470 Vector3 range; 471 Vector3 range;
471 Vector3 min; 472 Vector3 min;
473 int nverts;
474 int nindexs;
472 475
473 if (cmap.ContainsKey("Max")) 476 if (cmap.ContainsKey("Max"))
474 range = cmap["Max"].AsVector3(); 477 range = cmap["Max"].AsVector3();
@@ -482,27 +485,125 @@ namespace OpenSim.Region.Physics.Meshing
482 485
483 range = range - min; 486 range = range - min;
484 range *= invMaxU16; 487 range *= invMaxU16;
485/* 488
486 // if (!convex && cmap.ContainsKey("HullList")) 489 if (!convex && cmap.ContainsKey("HullList") && cmap.ContainsKey("Positions"))
487 if (cmap.ContainsKey("HullList"))
488 { 490 {
489 List<int> hsizes = new List<int>(); 491 List<int> hsizes = new List<int>();
490 492 int totalpoints = 0;
491 data = cmap["HullList"].AsBinary(); 493 data = cmap["HullList"].AsBinary();
492 for (i = 0; i < data.Length; i++) 494 for (i = 0; i < data.Length; i++)
493 { 495 {
494 t1 = data[i]; 496 t1 = data[i];
495 if (t1 == 0) 497 if (t1 == 0)
496 t1 = 256; 498 t1 = 256;
499 totalpoints += t1;
497 hsizes.Add(t1); 500 hsizes.Add(t1);
498 } 501 }
499 502
500bla bla 503 data = cmap["Positions"].AsBinary();
504 int ptr = 0;
505 int vertsoffset = 0;
506
507 if (totalpoints == data.Length / 6) // 2 bytes per coord, 3 coords per point
508 {
509 foreach (int hullsize in hsizes)
510 {
511 for (i = 0; i < hullsize; i++ )
512 {
513 t1 = data[ptr++];
514 t1 += data[ptr++] << 8;
515 t2 = data[ptr++];
516 t2 += data[ptr++] << 8;
517 t3 = data[ptr++];
518 t3 += data[ptr++] << 8;
519
520 f3 = new float3((t1 * range.X + min.X) * size.X,
521 (t2 * range.Y + min.Y) * size.Y,
522 (t3 * range.Z + min.Z) * size.Z);
523 vs.Add(f3);
524 }
525
526 if(hullsize <3)
527 {
528 vs.Clear();
529 continue;
530 }
531
532 if (hullsize <5)
533 {
534 foreach (float3 point in vs)
535 {
536 c.X = point.x;
537 c.Y = point.y;
538 c.Z = point.z;
539 coords.Add(c);
540 }
541 f = new Face(vertsoffset, vertsoffset + 1, vertsoffset + 2);
542 faces.Add(f);
543
544 if (hullsize == 4)
545 {
546 // not sure about orientation..
547 f = new Face(vertsoffset, vertsoffset + 2, vertsoffset + 3);
548 faces.Add(f);
549 f = new Face(vertsoffset, vertsoffset + 3, vertsoffset + 1);
550 faces.Add(f);
551 f = new Face(vertsoffset + 3, vertsoffset + 2, vertsoffset + 1);
552 faces.Add(f);
553 }
554 vertsoffset += vs.Count;
555 vs.Clear();
556 continue;
557 }
558
559 if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f))
560 {
561 vs.Clear();
562 continue;
563 }
564
565 nverts = hullr.Vertices.Count;
566 nindexs = hullr.Indices.Count;
501 567
568 if (nindexs % 3 != 0)
569 {
570 vs.Clear();
571 continue;
572 }
502 573
574 for (i = 0; i < nverts; i++)
575 {
576 c.X = hullr.Vertices[i].x;
577 c.Y = hullr.Vertices[i].y;
578 c.Z = hullr.Vertices[i].z;
579 coords.Add(c);
580 }
581
503 582
583 for (i = 0; i < nindexs; i += 3)
584 {
585 t1 = hullr.Indices[i];
586 if (t1 > nverts)
587 break;
588 t2 = hullr.Indices[i + 1];
589 if (t2 > nverts)
590 break;
591 t3 = hullr.Indices[i + 2];
592 if (t3 > nverts)
593 break;
594 f = new Face(vertsoffset + t1, vertsoffset + t2, vertsoffset + t3);
595 faces.Add(f);
596 }
597 vertsoffset += nverts;
598 vs.Clear();
599 }
600 }
601 if (coords.Count > 0 && faces.Count > 0)
602 return true;
603
504 } 604 }
505 */ 605
606 vs.Clear();
506 607
507 if (cmap.ContainsKey("BoundingVerts")) 608 if (cmap.ContainsKey("BoundingVerts"))
508 { 609 {
@@ -523,17 +624,47 @@ bla bla
523 vs.Add(f3); 624 vs.Add(f3);
524 } 625 }
525 626
627 if (vs.Count < 3)
628 {
629 vs.Clear();
630 return false;
631 }
632
633 if (vs.Count < 5)
634 {
635 foreach (float3 point in vs)
636 {
637 c.X = point.x;
638 c.Y = point.y;
639 c.Z = point.z;
640 coords.Add(c);
641 }
642 f = new Face(0, 1, 2);
643 faces.Add(f);
644
645 if (vs.Count == 4)
646 {
647 // not sure about orientation..
648 f = new Face(0, 2, 3);
649 faces.Add(f);
650 f = new Face(0, 3, 1);
651 faces.Add(f);
652 f = new Face( 3, 2, 1);
653 faces.Add(f);
654 }
655 vs.Clear();
656 return true;
657 }
526 658
527 if (!HullUtils.ComputeHull(vs, ref hullr, 300, 0.0f)) 659 if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f))
528 return false; 660 return false;
529 661
530 int nverts = hullr.Vertices.Count; 662 nverts = hullr.Vertices.Count;
531 int nindexs = hullr.Indices.Count; 663 nindexs = hullr.Indices.Count;
532 664
533 if (nindexs % 3 != 0) 665 if (nindexs % 3 != 0)
534 return false; 666 return false;
535 667
536 Coord c;
537 for (i = 0; i < nverts; i++) 668 for (i = 0; i < nverts; i++)
538 { 669 {
539 c.X = hullr.Vertices[i].x; 670 c.X = hullr.Vertices[i].x;
@@ -541,9 +672,6 @@ bla bla
541 c.Z = hullr.Vertices[i].z; 672 c.Z = hullr.Vertices[i].z;
542 coords.Add(c); 673 coords.Add(c);
543 } 674 }
544
545 Face f;
546
547 for (i = 0; i < nindexs; i += 3) 675 for (i = 0; i < nindexs; i += 3)
548 { 676 {
549 t1 = hullr.Indices[i]; 677 t1 = hullr.Indices[i];