diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | 87 |
1 files changed, 40 insertions, 47 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 0cc51b0..cd77581 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | |||
@@ -141,9 +141,9 @@ public sealed class BSShapeCollection : IDisposable | |||
141 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body); | 141 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body); |
142 | PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.ReferenceBody", delegate() | 142 | PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.ReferenceBody", delegate() |
143 | { | 143 | { |
144 | if (!BulletSimAPI.IsInWorld2(body.ptr)) | 144 | if (!PhysicsScene.PE.IsInWorld(body)) |
145 | { | 145 | { |
146 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, body.ptr); | 146 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, body); |
147 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body); | 147 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body); |
148 | } | 148 | } |
149 | }); | 149 | }); |
@@ -166,15 +166,15 @@ public sealed class BSShapeCollection : IDisposable | |||
166 | // If the caller needs to know the old body is going away, pass the event up. | 166 | // If the caller needs to know the old body is going away, pass the event up. |
167 | if (bodyCallback != null) bodyCallback(body); | 167 | if (bodyCallback != null) bodyCallback(body); |
168 | 168 | ||
169 | if (BulletSimAPI.IsInWorld2(body.ptr)) | 169 | if (PhysicsScene.PE.IsInWorld(body)) |
170 | { | 170 | { |
171 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, body.ptr); | 171 | PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, body); |
172 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body); | 172 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body); |
173 | } | 173 | } |
174 | 174 | ||
175 | // Zero any reference to the shape so it is not freed when the body is deleted. | 175 | // Zero any reference to the shape so it is not freed when the body is deleted. |
176 | BulletSimAPI.SetCollisionShape2(PhysicsScene.World.ptr, body.ptr, IntPtr.Zero); | 176 | PhysicsScene.PE.SetCollisionShape(PhysicsScene.World, body, new BulletShape()); |
177 | BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, body.ptr); | 177 | PhysicsScene.PE.DestroyObject(PhysicsScene.World, body); |
178 | }); | 178 | }); |
179 | } | 179 | } |
180 | } | 180 | } |
@@ -259,9 +259,9 @@ public sealed class BSShapeCollection : IDisposable | |||
259 | { | 259 | { |
260 | // Native shapes are not tracked and are released immediately | 260 | // Native shapes are not tracked and are released immediately |
261 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1},taintTime={2}", | 261 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1},taintTime={2}", |
262 | BSScene.DetailLogZero, shape.ptr.ToString("X"), inTaintTime); | 262 | BSScene.DetailLogZero, shape.AddrString, inTaintTime); |
263 | if (shapeCallback != null) shapeCallback(shape); | 263 | if (shapeCallback != null) shapeCallback(shape); |
264 | BulletSimAPI.DeleteCollisionShape2(PhysicsScene.World.ptr, shape.ptr); | 264 | PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape); |
265 | } | 265 | } |
266 | else | 266 | else |
267 | { | 267 | { |
@@ -332,36 +332,36 @@ public sealed class BSShapeCollection : IDisposable | |||
332 | // Called at taint-time. | 332 | // Called at taint-time. |
333 | private void DereferenceCompound(BulletShape shape, ShapeDestructionCallback shapeCallback) | 333 | private void DereferenceCompound(BulletShape shape, ShapeDestructionCallback shapeCallback) |
334 | { | 334 | { |
335 | if (!BulletSimAPI.IsCompound2(shape.ptr)) | 335 | if (!PhysicsScene.PE.IsCompound(shape)) |
336 | { | 336 | { |
337 | // Failed the sanity check!! | 337 | // Failed the sanity check!! |
338 | PhysicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}", | 338 | PhysicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}", |
339 | LogHeader, shape.type, shape.ptr.ToString("X")); | 339 | LogHeader, shape.type, shape.AddrString); |
340 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}", | 340 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}", |
341 | BSScene.DetailLogZero, shape.type, shape.ptr.ToString("X")); | 341 | BSScene.DetailLogZero, shape.type, shape.AddrString); |
342 | return; | 342 | return; |
343 | } | 343 | } |
344 | 344 | ||
345 | int numChildren = BulletSimAPI.GetNumberOfCompoundChildren2(shape.ptr); | 345 | int numChildren = PhysicsScene.PE.GetNumberOfCompoundChildren(shape); |
346 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", BSScene.DetailLogZero, shape, numChildren); | 346 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", BSScene.DetailLogZero, shape, numChildren); |
347 | 347 | ||
348 | for (int ii = numChildren - 1; ii >= 0; ii--) | 348 | for (int ii = numChildren - 1; ii >= 0; ii--) |
349 | { | 349 | { |
350 | IntPtr childShape = BulletSimAPI.RemoveChildShapeFromCompoundShapeIndex2(shape.ptr, ii); | 350 | BulletShape childShape = PhysicsScene.PE.RemoveChildShapeFromCompoundShapeIndex(shape, ii); |
351 | DereferenceAnonCollisionShape(childShape); | 351 | DereferenceAnonCollisionShape(childShape); |
352 | } | 352 | } |
353 | BulletSimAPI.DeleteCollisionShape2(PhysicsScene.World.ptr, shape.ptr); | 353 | PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape); |
354 | } | 354 | } |
355 | 355 | ||
356 | // Sometimes we have a pointer to a collision shape but don't know what type it is. | 356 | // Sometimes we have a pointer to a collision shape but don't know what type it is. |
357 | // Figure out type and call the correct dereference routine. | 357 | // Figure out type and call the correct dereference routine. |
358 | // Called at taint-time. | 358 | // Called at taint-time. |
359 | private void DereferenceAnonCollisionShape(IntPtr cShape) | 359 | private void DereferenceAnonCollisionShape(BulletShape shapeInfo) |
360 | { | 360 | { |
361 | MeshDesc meshDesc; | 361 | MeshDesc meshDesc; |
362 | HullDesc hullDesc; | 362 | HullDesc hullDesc; |
363 | 363 | ||
364 | BulletShape shapeInfo = new BulletShape(cShape); | 364 | IntPtr cShape = shapeInfo.ptr; |
365 | if (TryGetMeshByPtr(cShape, out meshDesc)) | 365 | if (TryGetMeshByPtr(cShape, out meshDesc)) |
366 | { | 366 | { |
367 | shapeInfo.type = BSPhysicsShapeType.SHAPE_MESH; | 367 | shapeInfo.type = BSPhysicsShapeType.SHAPE_MESH; |
@@ -376,13 +376,13 @@ public sealed class BSShapeCollection : IDisposable | |||
376 | } | 376 | } |
377 | else | 377 | else |
378 | { | 378 | { |
379 | if (BulletSimAPI.IsCompound2(cShape)) | 379 | if (PhysicsScene.PE.IsCompound(shapeInfo)) |
380 | { | 380 | { |
381 | shapeInfo.type = BSPhysicsShapeType.SHAPE_COMPOUND; | 381 | shapeInfo.type = BSPhysicsShapeType.SHAPE_COMPOUND; |
382 | } | 382 | } |
383 | else | 383 | else |
384 | { | 384 | { |
385 | if (BulletSimAPI.IsNativeShape2(cShape)) | 385 | if (PhysicsScene.PE.IsNativeShape(shapeInfo)) |
386 | { | 386 | { |
387 | shapeInfo.isNativeShape = true; | 387 | shapeInfo.isNativeShape = true; |
388 | shapeInfo.type = BSPhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter) | 388 | shapeInfo.type = BSPhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter) |
@@ -400,7 +400,7 @@ public sealed class BSShapeCollection : IDisposable | |||
400 | else | 400 | else |
401 | { | 401 | { |
402 | PhysicsScene.Logger.ErrorFormat("{0} Could not decypher shape type. Region={1}, addr={2}", | 402 | PhysicsScene.Logger.ErrorFormat("{0} Could not decypher shape type. Region={1}, addr={2}", |
403 | LogHeader, PhysicsScene.RegionName, cShape.ToString("X")); | 403 | LogHeader, PhysicsScene.RegionName, shapeInfo.AddrString); |
404 | } | 404 | } |
405 | } | 405 | } |
406 | 406 | ||
@@ -467,7 +467,7 @@ public sealed class BSShapeCollection : IDisposable | |||
467 | // Get the scale of any existing shape so we can see if the new shape is same native type and same size. | 467 | // Get the scale of any existing shape so we can see if the new shape is same native type and same size. |
468 | OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero; | 468 | OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero; |
469 | if (prim.PhysShape.HasPhysicalShape) | 469 | if (prim.PhysShape.HasPhysicalShape) |
470 | scaleOfExistingShape = BulletSimAPI.GetLocalScaling2(prim.PhysShape.ptr); | 470 | scaleOfExistingShape = PhysicsScene.PE.GetLocalScaling(prim.PhysShape); |
471 | 471 | ||
472 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}", | 472 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}", |
473 | prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.type); | 473 | prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.type); |
@@ -570,19 +570,15 @@ public sealed class BSShapeCollection : IDisposable | |||
570 | 570 | ||
571 | if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE) | 571 | if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE) |
572 | { | 572 | { |
573 | // The proper scale has been calculated in the prim. | 573 | |
574 | newShape = new BulletShape( | 574 | newShape = PhysicsScene.PE.BuildCapsuleShape(PhysicsScene.World, 1f, 1f, prim.Scale); |
575 | // Bullet's capsule total height is the passed "height + (radius * 2)" so, the base | ||
576 | // capsule is radius of 0.5f (1 diameter) and height of two (1.0f + 0.5f * 2)". | ||
577 | // This must be taken into account when computing the scaling of the capsule. | ||
578 | BulletSimAPI.BuildCapsuleShape2(PhysicsScene.World.ptr, 1f, 1f, prim.Scale) | ||
579 | , shapeType); | ||
580 | if (DDetail) DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale); | 575 | if (DDetail) DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale); |
581 | } | 576 | } |
582 | else | 577 | else |
583 | { | 578 | { |
584 | // Native shapes are scaled in Bullet so set the scaling to the size | 579 | // Native shapes are scaled in Bullet so set the scaling to the size |
585 | newShape = new BulletShape(BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, nativeShapeData), shapeType); | 580 | newShape = PhysicsScene.PE.BuildNativeShape(PhysicsScene.World, nativeShapeData); |
581 | |||
586 | } | 582 | } |
587 | if (!newShape.HasPhysicalShape) | 583 | if (!newShape.HasPhysicalShape) |
588 | { | 584 | { |
@@ -629,13 +625,14 @@ public sealed class BSShapeCollection : IDisposable | |||
629 | 625 | ||
630 | private BulletShape CreatePhysicalMesh(string objName, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) | 626 | private BulletShape CreatePhysicalMesh(string objName, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) |
631 | { | 627 | { |
628 | BulletShape newShape = new BulletShape(); | ||
632 | IMesh meshData = null; | 629 | IMesh meshData = null; |
633 | IntPtr meshPtr = IntPtr.Zero; | 630 | |
634 | MeshDesc meshDesc; | 631 | MeshDesc meshDesc; |
635 | if (Meshes.TryGetValue(newMeshKey, out meshDesc)) | 632 | if (Meshes.TryGetValue(newMeshKey, out meshDesc)) |
636 | { | 633 | { |
637 | // If the mesh has already been built just use it. | 634 | // If the mesh has already been built just use it. |
638 | meshPtr = meshDesc.ptr; | 635 | newShape = new BulletShape(meshDesc.ptr, BSPhysicsShapeType.SHAPE_MESH); |
639 | } | 636 | } |
640 | else | 637 | else |
641 | { | 638 | { |
@@ -658,11 +655,10 @@ public sealed class BSShapeCollection : IDisposable | |||
658 | // m_log.DebugFormat("{0}: BSShapeCollection.CreatePhysicalMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}", | 655 | // m_log.DebugFormat("{0}: BSShapeCollection.CreatePhysicalMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}", |
659 | // LogHeader, prim.LocalID, newMeshKey, indices.Length, vertices.Count); | 656 | // LogHeader, prim.LocalID, newMeshKey, indices.Length, vertices.Count); |
660 | 657 | ||
661 | meshPtr = BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr, | 658 | newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, |
662 | indices.GetLength(0), indices, vertices.Count, verticesAsFloats); | 659 | indices.GetLength(0), indices, vertices.Count, verticesAsFloats); |
663 | } | 660 | } |
664 | } | 661 | } |
665 | BulletShape newShape = new BulletShape(meshPtr, BSPhysicsShapeType.SHAPE_MESH); | ||
666 | newShape.shapeKey = newMeshKey; | 662 | newShape.shapeKey = newMeshKey; |
667 | 663 | ||
668 | return newShape; | 664 | return newShape; |
@@ -700,12 +696,14 @@ public sealed class BSShapeCollection : IDisposable | |||
700 | private BulletShape CreatePhysicalHull(string objName, System.UInt64 newHullKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) | 696 | private BulletShape CreatePhysicalHull(string objName, System.UInt64 newHullKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) |
701 | { | 697 | { |
702 | 698 | ||
699 | BulletShape newShape = new BulletShape(); | ||
703 | IntPtr hullPtr = IntPtr.Zero; | 700 | IntPtr hullPtr = IntPtr.Zero; |
701 | |||
704 | HullDesc hullDesc; | 702 | HullDesc hullDesc; |
705 | if (Hulls.TryGetValue(newHullKey, out hullDesc)) | 703 | if (Hulls.TryGetValue(newHullKey, out hullDesc)) |
706 | { | 704 | { |
707 | // If the hull shape already is created, just use it. | 705 | // If the hull shape already is created, just use it. |
708 | hullPtr = hullDesc.ptr; | 706 | newShape = new BulletShape(hullDesc.ptr, BSPhysicsShapeType.SHAPE_HULL); |
709 | } | 707 | } |
710 | else | 708 | else |
711 | { | 709 | { |
@@ -793,11 +791,10 @@ public sealed class BSShapeCollection : IDisposable | |||
793 | } | 791 | } |
794 | } | 792 | } |
795 | // create the hull data structure in Bullet | 793 | // create the hull data structure in Bullet |
796 | hullPtr = BulletSimAPI.CreateHullShape2(PhysicsScene.World.ptr, hullCount, convHulls); | 794 | newShape = PhysicsScene.PE.CreateHullShape(PhysicsScene.World, hullCount, convHulls); |
797 | } | 795 | } |
798 | } | 796 | } |
799 | 797 | ||
800 | BulletShape newShape = new BulletShape(hullPtr, BSPhysicsShapeType.SHAPE_HULL); | ||
801 | newShape.shapeKey = newHullKey; | 798 | newShape.shapeKey = newHullKey; |
802 | 799 | ||
803 | return newShape; | 800 | return newShape; |
@@ -819,12 +816,12 @@ public sealed class BSShapeCollection : IDisposable | |||
819 | // Don't need to do this as the shape is freed when the new root shape is created below. | 816 | // Don't need to do this as the shape is freed when the new root shape is created below. |
820 | // DereferenceShape(prim.PhysShape, true, shapeCallback); | 817 | // DereferenceShape(prim.PhysShape, true, shapeCallback); |
821 | 818 | ||
822 | BulletShape cShape = new BulletShape( | 819 | |
823 | BulletSimAPI.CreateCompoundShape2(PhysicsScene.World.ptr, false), BSPhysicsShapeType.SHAPE_COMPOUND); | 820 | BulletShape cShape = PhysicsScene.PE.CreateCompoundShape(PhysicsScene.World, false); |
824 | 821 | ||
825 | // Create the shape for the root prim and add it to the compound shape. Cannot be a native shape. | 822 | // Create the shape for the root prim and add it to the compound shape. Cannot be a native shape. |
826 | CreateGeomMeshOrHull(prim, shapeCallback); | 823 | CreateGeomMeshOrHull(prim, shapeCallback); |
827 | BulletSimAPI.AddChildShapeToCompoundShape2(cShape.ptr, prim.PhysShape.ptr, OMV.Vector3.Zero, OMV.Quaternion.Identity); | 824 | PhysicsScene.PE.AddChildShapeToCompoundShape(cShape, prim.PhysShape, OMV.Vector3.Zero, OMV.Quaternion.Identity); |
828 | if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addRootPrim,compShape={1},rootShape={2}", | 825 | if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addRootPrim,compShape={1},rootShape={2}", |
829 | prim.LocalID, cShape, prim.PhysShape); | 826 | prim.LocalID, cShape, prim.PhysShape); |
830 | 827 | ||
@@ -932,7 +929,7 @@ public sealed class BSShapeCollection : IDisposable | |||
932 | // If not a solid object, body is a GhostObject. Otherwise a RigidBody. | 929 | // If not a solid object, body is a GhostObject. Otherwise a RigidBody. |
933 | if (!mustRebuild) | 930 | if (!mustRebuild) |
934 | { | 931 | { |
935 | CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(prim.PhysBody.ptr); | 932 | CollisionObjectTypes bodyType = (CollisionObjectTypes)PhysicsScene.PE.GetBodyType(prim.PhysBody); |
936 | if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY | 933 | if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY |
937 | || !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT) | 934 | || !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT) |
938 | { | 935 | { |
@@ -947,20 +944,16 @@ public sealed class BSShapeCollection : IDisposable | |||
947 | DereferenceBody(prim.PhysBody, true, bodyCallback); | 944 | DereferenceBody(prim.PhysBody, true, bodyCallback); |
948 | 945 | ||
949 | BulletBody aBody; | 946 | BulletBody aBody; |
950 | IntPtr bodyPtr = IntPtr.Zero; | ||
951 | if (prim.IsSolid) | 947 | if (prim.IsSolid) |
952 | { | 948 | { |
953 | bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, | 949 | aBody = PhysicsScene.PE.CreateBodyFromShape(sim, shape, prim.LocalID, prim.RawPosition, prim.RawOrientation); |
954 | prim.LocalID, prim.RawPosition, prim.RawOrientation); | 950 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,mesh,body={1}", prim.LocalID, aBody); |
955 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); | ||
956 | } | 951 | } |
957 | else | 952 | else |
958 | { | 953 | { |
959 | bodyPtr = BulletSimAPI.CreateGhostFromShape2(sim.ptr, shape.ptr, | 954 | aBody = PhysicsScene.PE.CreateGhostFromShape(sim, shape, prim.LocalID, prim.RawPosition, prim.RawOrientation); |
960 | prim.LocalID, prim.RawPosition, prim.RawOrientation); | 955 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,ghost,body={1}", prim.LocalID, aBody); |
961 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,ghost,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); | ||
962 | } | 956 | } |
963 | aBody = new BulletBody(prim.LocalID, bodyPtr); | ||
964 | 957 | ||
965 | ReferenceBody(aBody, true); | 958 | ReferenceBody(aBody, true); |
966 | 959 | ||