diff options
Diffstat (limited to 'OpenSim/Region/Physics')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 15 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | 11 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs | 5 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 3 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 2 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | 15 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | 130 |
7 files changed, 167 insertions, 14 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs index 231f0f8..12a0c17 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | |||
@@ -251,6 +251,16 @@ public override BulletShape CreateMeshShape(BulletWorld world, | |||
251 | BSPhysicsShapeType.SHAPE_MESH); | 251 | BSPhysicsShapeType.SHAPE_MESH); |
252 | } | 252 | } |
253 | 253 | ||
254 | public override BulletShape CreateGImpactShape(BulletWorld world, | ||
255 | int indicesCount, int[] indices, | ||
256 | int verticesCount, float[] vertices) | ||
257 | { | ||
258 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
259 | return new BulletShapeUnman( | ||
260 | BSAPICPP.CreateGImpactShape2(worldu.ptr, indicesCount, indices, verticesCount, vertices), | ||
261 | BSPhysicsShapeType.SHAPE_GIMPACT); | ||
262 | } | ||
263 | |||
254 | public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls) | 264 | public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls) |
255 | { | 265 | { |
256 | BulletWorldUnman worldu = world as BulletWorldUnman; | 266 | BulletWorldUnman worldu = world as BulletWorldUnman; |
@@ -1426,6 +1436,11 @@ public static extern IntPtr CreateMeshShape2(IntPtr world, | |||
1426 | int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices ); | 1436 | int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices ); |
1427 | 1437 | ||
1428 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 1438 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
1439 | public static extern IntPtr CreateGImpactShape2(IntPtr world, | ||
1440 | int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices, | ||
1441 | int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices ); | ||
1442 | |||
1443 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1429 | public static extern IntPtr CreateHullShape2(IntPtr world, | 1444 | public static extern IntPtr CreateHullShape2(IntPtr world, |
1430 | int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls); | 1445 | int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls); |
1431 | 1446 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs index 59780ae..6db5f5e 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | |||
@@ -1475,7 +1475,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1475 | ret = BSPhysicsShapeType.SHAPE_UNKNOWN; | 1475 | ret = BSPhysicsShapeType.SHAPE_UNKNOWN; |
1476 | break; | 1476 | break; |
1477 | case BroadphaseNativeTypes.CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE: | 1477 | case BroadphaseNativeTypes.CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE: |
1478 | ret = BSPhysicsShapeType.SHAPE_MESH; | 1478 | ret = BSPhysicsShapeType.SHAPE_CONVEXHULL; |
1479 | break; | 1479 | break; |
1480 | case BroadphaseNativeTypes.CONVEX_HULL_SHAPE_PROXYTYPE: | 1480 | case BroadphaseNativeTypes.CONVEX_HULL_SHAPE_PROXYTYPE: |
1481 | ret = BSPhysicsShapeType.SHAPE_HULL; | 1481 | ret = BSPhysicsShapeType.SHAPE_HULL; |
@@ -1503,7 +1503,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1503 | ret = BSPhysicsShapeType.SHAPE_CONE; | 1503 | ret = BSPhysicsShapeType.SHAPE_CONE; |
1504 | break; | 1504 | break; |
1505 | case BroadphaseNativeTypes.CONVEX_SHAPE_PROXYTYPE: | 1505 | case BroadphaseNativeTypes.CONVEX_SHAPE_PROXYTYPE: |
1506 | ret = BSPhysicsShapeType.SHAPE_UNKNOWN; | 1506 | ret = BSPhysicsShapeType.SHAPE_CONVEXHULL; |
1507 | break; | 1507 | break; |
1508 | case BroadphaseNativeTypes.CYLINDER_SHAPE_PROXYTYPE: | 1508 | case BroadphaseNativeTypes.CYLINDER_SHAPE_PROXYTYPE: |
1509 | ret = BSPhysicsShapeType.SHAPE_CYLINDER; | 1509 | ret = BSPhysicsShapeType.SHAPE_CYLINDER; |
@@ -1547,7 +1547,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1547 | break; | 1547 | break; |
1548 | ///Used for GIMPACT Trimesh integration | 1548 | ///Used for GIMPACT Trimesh integration |
1549 | case BroadphaseNativeTypes.GIMPACT_SHAPE_PROXYTYPE: | 1549 | case BroadphaseNativeTypes.GIMPACT_SHAPE_PROXYTYPE: |
1550 | ret = BSPhysicsShapeType.SHAPE_MESH; | 1550 | ret = BSPhysicsShapeType.SHAPE_GIMPACT; |
1551 | break; | 1551 | break; |
1552 | ///Multimaterial mesh | 1552 | ///Multimaterial mesh |
1553 | case BroadphaseNativeTypes.MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE: | 1553 | case BroadphaseNativeTypes.MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE: |
@@ -1820,6 +1820,11 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1820 | return new BulletShapeXNA(meshShape, BSPhysicsShapeType.SHAPE_MESH); | 1820 | return new BulletShapeXNA(meshShape, BSPhysicsShapeType.SHAPE_MESH); |
1821 | 1821 | ||
1822 | } | 1822 | } |
1823 | public override BulletShape CreateGImpactShape(BulletWorld pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats) | ||
1824 | { | ||
1825 | // TODO: | ||
1826 | return null; | ||
1827 | } | ||
1823 | public static void DumpRaw(ObjectArray<int>indices, ObjectArray<float> vertices, int pIndicesCount,int pVerticesCount ) | 1828 | public static void DumpRaw(ObjectArray<int>indices, ObjectArray<float> vertices, int pIndicesCount,int pVerticesCount ) |
1824 | { | 1829 | { |
1825 | 1830 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs index 3378c93..6cdc112 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs | |||
@@ -71,6 +71,7 @@ public enum BSPhysicsShapeType | |||
71 | SHAPE_HEIGHTMAP = 23, | 71 | SHAPE_HEIGHTMAP = 23, |
72 | SHAPE_AVATAR = 24, | 72 | SHAPE_AVATAR = 24, |
73 | SHAPE_CONVEXHULL= 25, | 73 | SHAPE_CONVEXHULL= 25, |
74 | SHAPE_GIMPACT = 26, | ||
74 | }; | 75 | }; |
75 | 76 | ||
76 | // The native shapes have predefined shape hash keys | 77 | // The native shapes have predefined shape hash keys |
@@ -321,6 +322,10 @@ public abstract BulletShape CreateMeshShape(BulletWorld world, | |||
321 | int indicesCount, int[] indices, | 322 | int indicesCount, int[] indices, |
322 | int verticesCount, float[] vertices ); | 323 | int verticesCount, float[] vertices ); |
323 | 324 | ||
325 | public abstract BulletShape CreateGImpactShape(BulletWorld world, | ||
326 | int indicesCount, int[] indices, | ||
327 | int verticesCount, float[] vertices ); | ||
328 | |||
324 | public abstract BulletShape CreateHullShape(BulletWorld world, | 329 | public abstract BulletShape CreateHullShape(BulletWorld world, |
325 | int hullCount, float[] hulls); | 330 | int hullCount, float[] hulls); |
326 | 331 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index d33292f..9a9e527 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | |||
@@ -89,6 +89,7 @@ public static class BSParam | |||
89 | public static bool ShouldRemoveZeroWidthTriangles { get; private set; } | 89 | public static bool ShouldRemoveZeroWidthTriangles { get; private set; } |
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 | 93 | ||
93 | public static float TerrainImplementation { get; set; } | 94 | public static float TerrainImplementation { get; set; } |
94 | public static int TerrainMeshMagnification { get; private set; } | 95 | public static int TerrainMeshMagnification { get; private set; } |
@@ -369,6 +370,8 @@ public static class BSParam | |||
369 | false ), | 370 | false ), |
370 | new ParameterDefn<bool>("ShouldUseSingleConvexHullForPrims", "If true, use a single convex hull shape for physical prims", | 371 | new ParameterDefn<bool>("ShouldUseSingleConvexHullForPrims", "If true, use a single convex hull shape for physical prims", |
371 | true ), | 372 | true ), |
373 | new ParameterDefn<bool>("ShouldUseGImpactShapeForPrims", "If true, use a GImpact shape for prims with cuts and twists", | ||
374 | false ), | ||
372 | 375 | ||
373 | new ParameterDefn<int>("CrossingFailuresBeforeOutOfBounds", "How forgiving we are about getting into adjactent regions", | 376 | new ParameterDefn<int>("CrossingFailuresBeforeOutOfBounds", "How forgiving we are about getting into adjactent regions", |
374 | 5 ), | 377 | 5 ), |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 9ed2d06..39f5b0a 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | |||
@@ -328,6 +328,8 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
328 | BSParam.ShouldUseBulletHACD = false; | 328 | BSParam.ShouldUseBulletHACD = false; |
329 | m_log.InfoFormat("{0} Disabling ShouldUseSingleConvexHullForPrims", LogHeader); | 329 | m_log.InfoFormat("{0} Disabling ShouldUseSingleConvexHullForPrims", LogHeader); |
330 | BSParam.ShouldUseSingleConvexHullForPrims = false; | 330 | BSParam.ShouldUseSingleConvexHullForPrims = false; |
331 | m_log.InfoFormat("{0} Disabling ShouldUseGImpactShapeForPrims", LogHeader); | ||
332 | BSParam.ShouldUseGImpactShapeForPrims = false; | ||
331 | m_log.InfoFormat("{0} Setting terrain implimentation to Heightmap", LogHeader); | 333 | m_log.InfoFormat("{0} Setting terrain implimentation to Heightmap", LogHeader); |
332 | BSParam.TerrainImplementation = (float)BSTerrainPhys.TerrainImplementation.Heightmap; | 334 | BSParam.TerrainImplementation = (float)BSTerrainPhys.TerrainImplementation.Heightmap; |
333 | break; | 335 | break; |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 64aaa15..32bbc8f 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | |||
@@ -230,6 +230,7 @@ public sealed class BSShapeCollection : IDisposable | |||
230 | BSShape potentialHull = null; | 230 | BSShape potentialHull = null; |
231 | 231 | ||
232 | PrimitiveBaseShape pbs = prim.BaseShape; | 232 | PrimitiveBaseShape pbs = prim.BaseShape; |
233 | // Use a simple, one section convex shape for prims that are probably convex (no cuts or twists) | ||
233 | if (BSParam.ShouldUseSingleConvexHullForPrims | 234 | if (BSParam.ShouldUseSingleConvexHullForPrims |
234 | && pbs != null | 235 | && pbs != null |
235 | && !pbs.SculptEntry | 236 | && !pbs.SculptEntry |
@@ -238,7 +239,17 @@ public sealed class BSShapeCollection : IDisposable | |||
238 | { | 239 | { |
239 | potentialHull = BSShapeConvexHull.GetReference(m_physicsScene, false /* forceRebuild */, prim); | 240 | potentialHull = BSShapeConvexHull.GetReference(m_physicsScene, false /* forceRebuild */, prim); |
240 | } | 241 | } |
241 | else | 242 | // Use the GImpact shape if it is a prim that has some concaveness |
243 | if (potentialHull == null | ||
244 | && BSParam.ShouldUseGImpactShapeForPrims | ||
245 | && pbs != null | ||
246 | && !pbs.SculptEntry | ||
247 | ) | ||
248 | { | ||
249 | potentialHull = BSShapeGImpact.GetReference(m_physicsScene, false /* forceRebuild */, prim); | ||
250 | } | ||
251 | // If not any of the simple cases, just make a hull | ||
252 | if (potentialHull == null) | ||
242 | { | 253 | { |
243 | potentialHull = BSShapeHull.GetReference(m_physicsScene, false /*forceRebuild*/, prim); | 254 | potentialHull = BSShapeHull.GetReference(m_physicsScene, false /*forceRebuild*/, prim); |
244 | } | 255 | } |
@@ -261,7 +272,7 @@ public sealed class BSShapeCollection : IDisposable | |||
261 | } | 272 | } |
262 | else | 273 | else |
263 | { | 274 | { |
264 | // Update prim.BSShape to reference a mesh of this shape. | 275 | // Non-physical objects should be just meshes. |
265 | BSShape potentialMesh = BSShapeMesh.GetReference(m_physicsScene, false /*forceRebuild*/, prim); | 276 | BSShape potentialMesh = BSShapeMesh.GetReference(m_physicsScene, false /*forceRebuild*/, prim); |
266 | // If the current shape is not what is on the prim at the moment, time to change. | 277 | // If the current shape is not what is on the prim at the moment, time to change. |
267 | if (!prim.PhysShape.HasPhysicalShape | 278 | if (!prim.PhysShape.HasPhysicalShape |
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 | // ============================================================================================================ | ||
962 | public 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 | // ============================================================================================================ |
942 | public class BSShapeAvatar : BSShape | 1054 | public class BSShapeAvatar : BSShape |