aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorRobert Adams2013-05-21 21:32:30 -0700
committerRobert Adams2013-05-21 21:32:30 -0700
commit2fd8819a043269f9308cb46c71893e6eb35a426e (patch)
treee046b5ff47b2b243d8355b53339293d62aaa17cc /OpenSim
parentBulletSim: add gImpact shape type. Add logic to use gImpact shape (diff)
downloadopensim-SC_OLD-2fd8819a043269f9308cb46c71893e6eb35a426e.zip
opensim-SC_OLD-2fd8819a043269f9308cb46c71893e6eb35a426e.tar.gz
opensim-SC_OLD-2fd8819a043269f9308cb46c71893e6eb35a426e.tar.bz2
opensim-SC_OLD-2fd8819a043269f9308cb46c71893e6eb35a426e.tar.xz
BulletSim: add code to experimentally use asset hull data.
Default to 'off' as it needs debugging.
Diffstat (limited to 'OpenSim')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSParam.cs3
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapes.cs55
2 files changed, 54 insertions, 4 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
index 9a9e527..5cff668 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
@@ -90,6 +90,7 @@ public static class BSParam
90 public static bool ShouldUseBulletHACD { get; set; } 90 public static bool ShouldUseBulletHACD { get; set; }
91 public static bool ShouldUseSingleConvexHullForPrims { get; set; } 91 public static bool ShouldUseSingleConvexHullForPrims { get; set; }
92 public static bool ShouldUseGImpactShapeForPrims { get; set; } 92 public static bool ShouldUseGImpactShapeForPrims { get; set; }
93 public static bool ShouldUseAssetHulls { get; set; }
93 94
94 public static float TerrainImplementation { get; set; } 95 public static float TerrainImplementation { get; set; }
95 public static int TerrainMeshMagnification { get; private set; } 96 public static int TerrainMeshMagnification { get; private set; }
@@ -372,6 +373,8 @@ public static class BSParam
372 true ), 373 true ),
373 new ParameterDefn<bool>("ShouldUseGImpactShapeForPrims", "If true, use a GImpact shape for prims with cuts and twists", 374 new ParameterDefn<bool>("ShouldUseGImpactShapeForPrims", "If true, use a GImpact shape for prims with cuts and twists",
374 false ), 375 false ),
376 new ParameterDefn<bool>("UseAssetHulls", "If true, use hull if specified in the mesh asset info",
377 false ),
375 378
376 new ParameterDefn<int>("CrossingFailuresBeforeOutOfBounds", "How forgiving we are about getting into adjactent regions", 379 new ParameterDefn<int>("CrossingFailuresBeforeOutOfBounds", "How forgiving we are about getting into adjactent regions",
377 5 ), 380 5 ),
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)