aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
diff options
context:
space:
mode:
authorRobert Adams2013-05-17 21:17:54 -0700
committerRobert Adams2013-05-21 15:32:10 -0700
commit9de3979f5b91ae4bf9b05b89ec59999c43514f90 (patch)
treefc4c8e08c77806d6fe08ae8a8eff5172abd70af0 /OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
parentMerge branch 'master' of git://opensimulator.org/git/opensim (diff)
downloadopensim-SC-9de3979f5b91ae4bf9b05b89ec59999c43514f90.zip
opensim-SC-9de3979f5b91ae4bf9b05b89ec59999c43514f90.tar.gz
opensim-SC-9de3979f5b91ae4bf9b05b89ec59999c43514f90.tar.bz2
opensim-SC-9de3979f5b91ae4bf9b05b89ec59999c43514f90.tar.xz
BulletSim: add gImpact shape type. Add logic to use gImpact shape
for prims that have cuts or holes. Default logic to 'off' as it needs debugging.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapes.cs130
1 files changed, 121 insertions, 9 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
index 72d039b..0152233 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
@@ -422,9 +422,22 @@ public class BSShapeMesh : BSShape
422 outMesh = foundDesc; 422 outMesh = foundDesc;
423 return ret; 423 return ret;
424 } 424 }
425
426 public delegate BulletShape CreateShapeCall(BulletWorld world, int indicesCount, int[] indices, int verticesCount, float[] vertices );
425 private BulletShape CreatePhysicalMesh(BSScene physicsScene, BSPhysObject prim, System.UInt64 newMeshKey, 427 private BulletShape CreatePhysicalMesh(BSScene physicsScene, BSPhysObject prim, System.UInt64 newMeshKey,
426 PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) 428 PrimitiveBaseShape pbs, OMV.Vector3 size, float lod)
427 { 429 {
430 return BSShapeMesh.CreatePhysicalMeshShape(physicsScene, prim, newMeshKey, pbs, size, lod,
431 (w, iC, i, vC, v) => physicsScene.PE.CreateMeshShape(w, iC, i, vC, v) );
432 }
433
434 // Code that uses the mesher to create the index/vertices info for a trimesh shape.
435 // This is used by the passed 'makeShape' call to create the Bullet mesh shape.
436 // The actual build call is passed so this logic can be used by several of the shapes that use a
437 // simple mesh as their base shape.
438 public static BulletShape CreatePhysicalMeshShape(BSScene physicsScene, BSPhysObject prim, System.UInt64 newMeshKey,
439 PrimitiveBaseShape pbs, OMV.Vector3 size, float lod, CreateShapeCall makeShape)
440 {
428 BulletShape newShape = new BulletShape(); 441 BulletShape newShape = new BulletShape();
429 442
430 IMesh meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod, 443 IMesh meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod,
@@ -482,8 +495,7 @@ public class BSShapeMesh : BSShape
482 495
483 if (realIndicesIndex != 0) 496 if (realIndicesIndex != 0)
484 { 497 {
485 newShape = physicsScene.PE.CreateMeshShape(physicsScene.World, 498 newShape = makeShape(physicsScene.World, realIndicesIndex, indices, verticesAsFloats.Length / 3, verticesAsFloats);
486 realIndicesIndex, indices, verticesAsFloats.Length / 3, verticesAsFloats);
487 } 499 }
488 else 500 else
489 { 501 {
@@ -803,6 +815,7 @@ public class BSShapeCompound : BSShape
803 // Called at taint-time. 815 // Called at taint-time.
804 private void DereferenceAnonCollisionShape(BSScene physicsScene, BulletShape pShape) 816 private void DereferenceAnonCollisionShape(BSScene physicsScene, BulletShape pShape)
805 { 817 {
818 // TODO: figure a better way to go through all the shape types and find a possible instance.
806 BSShapeMesh meshDesc; 819 BSShapeMesh meshDesc;
807 if (BSShapeMesh.TryGetMeshByPtr(pShape, out meshDesc)) 820 if (BSShapeMesh.TryGetMeshByPtr(pShape, out meshDesc))
808 { 821 {
@@ -824,17 +837,25 @@ public class BSShapeCompound : BSShape
824 } 837 }
825 else 838 else
826 { 839 {
827 if (physicsScene.PE.IsCompound(pShape)) 840 BSShapeGImpact gImpactDesc;
841 if (BSShapeGImpact.TryGetGImpactByPtr(pShape, out gImpactDesc))
828 { 842 {
829 BSShapeCompound recursiveCompound = new BSShapeCompound(pShape); 843 gImpactDesc.Dereference(physicsScene);
830 recursiveCompound.Dereference(physicsScene);
831 } 844 }
832 else 845 else
833 { 846 {
834 if (physicsScene.PE.IsNativeShape(pShape)) 847 if (physicsScene.PE.IsCompound(pShape))
848 {
849 BSShapeCompound recursiveCompound = new BSShapeCompound(pShape);
850 recursiveCompound.Dereference(physicsScene);
851 }
852 else
835 { 853 {
836 BSShapeNative nativeShape = new BSShapeNative(pShape); 854 if (physicsScene.PE.IsNativeShape(pShape))
837 nativeShape.Dereference(physicsScene); 855 {
856 BSShapeNative nativeShape = new BSShapeNative(pShape);
857 nativeShape.Dereference(physicsScene);
858 }
838 } 859 }
839 } 860 }
840 } 861 }
@@ -857,7 +878,7 @@ public class BSShapeConvexHull : BSShape
857 float lod; 878 float lod;
858 System.UInt64 newMeshKey = BSShape.ComputeShapeKey(prim.Size, prim.BaseShape, out lod); 879 System.UInt64 newMeshKey = BSShape.ComputeShapeKey(prim.Size, prim.BaseShape, out lod);
859 880
860 physicsScene.DetailLog("{0},BSShapeMesh,getReference,newKey={1},size={2},lod={3}", 881 physicsScene.DetailLog("{0},BSShapeConvexHull,getReference,newKey={1},size={2},lod={3}",
861 prim.LocalID, newMeshKey.ToString("X"), prim.Size, lod); 882 prim.LocalID, newMeshKey.ToString("X"), prim.Size, lod);
862 883
863 BSShapeConvexHull retConvexHull = null; 884 BSShapeConvexHull retConvexHull = null;
@@ -937,6 +958,97 @@ public class BSShapeConvexHull : BSShape
937 return ret; 958 return ret;
938 } 959 }
939} 960}
961// ============================================================================================================
962public class BSShapeGImpact : BSShape
963{
964 private static string LogHeader = "[BULLETSIM SHAPE GIMPACT]";
965 public static Dictionary<System.UInt64, BSShapeGImpact> GImpacts = new Dictionary<System.UInt64, BSShapeGImpact>();
966
967 public BSShapeGImpact(BulletShape pShape) : base(pShape)
968 {
969 }
970 public static BSShape GetReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
971 {
972 float lod;
973 System.UInt64 newMeshKey = BSShape.ComputeShapeKey(prim.Size, prim.BaseShape, out lod);
974
975 physicsScene.DetailLog("{0},BSShapeGImpact,getReference,newKey={1},size={2},lod={3}",
976 prim.LocalID, newMeshKey.ToString("X"), prim.Size, lod);
977
978 BSShapeGImpact retGImpact = null;
979 lock (GImpacts)
980 {
981 if (GImpacts.TryGetValue(newMeshKey, out retGImpact))
982 {
983 // The mesh has already been created. Return a new reference to same.
984 retGImpact.IncrementReference();
985 }
986 else
987 {
988 retGImpact = new BSShapeGImpact(new BulletShape());
989 BulletShape newShape = retGImpact.CreatePhysicalGImpact(physicsScene, prim, newMeshKey, prim.BaseShape, prim.Size, lod);
990
991 // Check to see if mesh was created (might require an asset).
992 newShape = VerifyMeshCreated(physicsScene, newShape, prim);
993 if (!newShape.isNativeShape || prim.PrimAssetState == BSPhysObject.PrimAssetCondition.Failed)
994 {
995 // If a mesh was what was created, remember the built shape for later sharing.
996 // Also note that if meshing failed we put it in the mesh list as there is nothing else to do about the mesh.
997 GImpacts.Add(newMeshKey, retGImpact);
998 }
999
1000 retGImpact.physShapeInfo = newShape;
1001 }
1002 }
1003 return retGImpact;
1004 }
1005
1006 private BulletShape CreatePhysicalGImpact(BSScene physicsScene, BSPhysObject prim, System.UInt64 newMeshKey,
1007 PrimitiveBaseShape pbs, OMV.Vector3 size, float lod)
1008 {
1009 return BSShapeMesh.CreatePhysicalMeshShape(physicsScene, prim, newMeshKey, pbs, size, lod,
1010 (w, iC, i, vC, v) => physicsScene.PE.CreateGImpactShape(w, iC, i, vC, v) );
1011 }
1012
1013 public override BSShape GetReference(BSScene physicsScene, BSPhysObject prim)
1014 {
1015 // Calling this reference means we want another handle to an existing shape
1016 // (usually linksets) so return this copy.
1017 IncrementReference();
1018 return this;
1019 }
1020 // Dereferencing a compound shape releases the hold on all the child shapes.
1021 public override void Dereference(BSScene physicsScene)
1022 {
1023 lock (GImpacts)
1024 {
1025 this.DecrementReference();
1026 physicsScene.DetailLog("{0},BSShapeGImpact.Dereference,shape={1}", BSScene.DetailLogZero, this);
1027 // TODO: schedule aging and destruction of unused meshes.
1028 }
1029 }
1030 // Loop through all the known hulls and return the description based on the physical address.
1031 public static bool TryGetGImpactByPtr(BulletShape pShape, out BSShapeGImpact outHull)
1032 {
1033 bool ret = false;
1034 BSShapeGImpact foundDesc = null;
1035 lock (GImpacts)
1036 {
1037 foreach (BSShapeGImpact sh in GImpacts.Values)
1038 {
1039 if (sh.physShapeInfo.ReferenceSame(pShape))
1040 {
1041 foundDesc = sh;
1042 ret = true;
1043 break;
1044 }
1045
1046 }
1047 }
1048 outHull = foundDesc;
1049 return ret;
1050 }
1051}
940 1052
941// ============================================================================================================ 1053// ============================================================================================================
942public class BSShapeAvatar : BSShape 1054public class BSShapeAvatar : BSShape