aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapes.cs55
1 files changed, 51 insertions, 4 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
index 0152233..b7f7e6c 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
@@ -31,6 +31,7 @@ using System.Text;
31 31
32using OpenSim.Framework; 32using OpenSim.Framework;
33using OpenSim.Region.Physics.Manager; 33using OpenSim.Region.Physics.Manager;
34using OpenSim.Region.Physics.Meshing;
34using OpenSim.Region.Physics.ConvexDecompositionDotNet; 35using OpenSim.Region.Physics.ConvexDecompositionDotNet;
35 36
36using OMV = OpenMetaverse; 37using OMV = OpenMetaverse;
@@ -573,9 +574,56 @@ public class BSShapeHull : BSShape
573 PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) 574 PrimitiveBaseShape pbs, OMV.Vector3 size, float lod)
574 { 575 {
575 BulletShape newShape = new BulletShape(); 576 BulletShape newShape = new BulletShape();
576 IntPtr hullPtr = IntPtr.Zero; 577 newShape.shapeKey = newHullKey;
577 578
578 if (BSParam.ShouldUseBulletHACD) 579 // Pass true for physicalness as this prevents the creation of bounding box which is not needed
580 IMesh meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod, true /* isPhysical */, false /* shouldCache */);
581
582 // If there is hull data in the mesh asset, build the hull from that
583 if (meshData != null && BSParam.ShouldUseAssetHulls)
584 {
585 Meshmerizer realMesher = physicsScene.mesher as Meshmerizer;
586 if (realMesher != null)
587 {
588 List<List<OMV.Vector3>> allHulls = realMesher.GetConvexHulls(size);
589 if (allHulls != null)
590 {
591 int hullCount = allHulls.Count;
592 int totalVertices = 1; // include one for the count of the hulls
593 // Using the structure described for HACD hulls, create the memory sturcture
594 // to pass the hull data to the creater.
595 foreach (List<OMV.Vector3> hullVerts in allHulls)
596 {
597 totalVertices += 4; // add four for the vertex count and centroid
598 totalVertices += hullVerts.Count * 3; // one vertex is three dimensions
599 }
600 float[] convHulls = new float[totalVertices];
601
602 convHulls[0] = (float)hullCount;
603 int jj = 1;
604 foreach (List<OMV.Vector3> hullVerts in allHulls)
605 {
606 convHulls[jj + 0] = hullVerts.Count;
607 convHulls[jj + 1] = 0f; // centroid x,y,z
608 convHulls[jj + 2] = 0f;
609 convHulls[jj + 3] = 0f;
610 jj += 4;
611 foreach (OMV.Vector3 oneVert in hullVerts)
612 {
613 convHulls[jj + 0] = oneVert.X;
614 convHulls[jj + 1] = oneVert.Y;
615 convHulls[jj + 2] = oneVert.Z;
616 jj += 3;
617 }
618 }
619
620 // create the hull data structure in Bullet
621 newShape = physicsScene.PE.CreateHullShape(physicsScene.World, hullCount, convHulls);
622 }
623 }
624 }
625 // If no hull specified in the asset and we should use Bullet's HACD approximation...
626 if (!newShape.HasPhysicalShape && BSParam.ShouldUseBulletHACD)
579 { 627 {
580 // Build the hull shape from an existing mesh shape. 628 // Build the hull shape from an existing mesh shape.
581 // The mesh should have already been created in Bullet. 629 // The mesh should have already been created in Bullet.
@@ -604,11 +652,10 @@ public class BSShapeHull : BSShape
604 } 652 }
605 physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,shouldUseBulletHACD,exit,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape); 653 physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,shouldUseBulletHACD,exit,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape);
606 } 654 }
655 // If no hull specified, use our HACD hull approximation.
607 if (!newShape.HasPhysicalShape) 656 if (!newShape.HasPhysicalShape)
608 { 657 {
609 // Build a new hull in the physical world using the C# HACD algorigthm. 658 // Build a new hull in the physical world using the C# HACD algorigthm.
610 // Pass true for physicalness as this prevents the creation of bounding box which is not needed
611 IMesh meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod, true /* isPhysical */, false /* shouldCache */);
612 if (meshData != null) 659 if (meshData != null)
613 { 660 {
614 if (prim.PrimAssetState == BSPhysObject.PrimAssetCondition.Fetched) 661 if (prim.PrimAssetState == BSPhysObject.PrimAssetCondition.Fetched)