aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
diff options
context:
space:
mode:
authorMelanie2013-01-02 11:52:37 +0000
committerMelanie2013-01-02 11:52:37 +0000
commit7943c8d11cbcac3ab16fb347d0c4116adc6437a5 (patch)
treea8f099569905001bdedf144a77fd7b9191aa6427 /OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
parentMerge branch 'master' into careminster (diff)
parentBulletSim: add parameter to have Bullet output performance statistics (diff)
downloadopensim-SC-7943c8d11cbcac3ab16fb347d0c4116adc6437a5.zip
opensim-SC-7943c8d11cbcac3ab16fb347d0c4116adc6437a5.tar.gz
opensim-SC-7943c8d11cbcac3ab16fb347d0c4116adc6437a5.tar.bz2
opensim-SC-7943c8d11cbcac3ab16fb347d0c4116adc6437a5.tar.xz
Merge branch 'master' into careminster
Conflicts: OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs106
1 files changed, 49 insertions, 57 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index 4008ff6..a7855f0 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -45,7 +45,7 @@ public sealed class BSShapeCollection : IDisposable
45 // Description of a Mesh 45 // Description of a Mesh
46 private struct MeshDesc 46 private struct MeshDesc
47 { 47 {
48 public IntPtr ptr; 48 public BulletShape shape;
49 public int referenceCount; 49 public int referenceCount;
50 public DateTime lastReferenced; 50 public DateTime lastReferenced;
51 public UInt64 shapeKey; 51 public UInt64 shapeKey;
@@ -55,7 +55,7 @@ public sealed class BSShapeCollection : IDisposable
55 // Meshes and hulls have the same shape hash key but we only need hulls for efficient collision calculations. 55 // Meshes and hulls have the same shape hash key but we only need hulls for efficient collision calculations.
56 private struct HullDesc 56 private struct HullDesc
57 { 57 {
58 public IntPtr ptr; 58 public BulletShape shape;
59 public int referenceCount; 59 public int referenceCount;
60 public DateTime lastReferenced; 60 public DateTime lastReferenced;
61 public UInt64 shapeKey; 61 public UInt64 shapeKey;
@@ -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(PhysicsScene.World, 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(PhysicsScene.World, 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, null);
177 BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, body.ptr); 177 PhysicsScene.PE.DestroyObject(PhysicsScene.World, body);
178 }); 178 });
179 } 179 }
180 } 180 }
@@ -202,7 +202,7 @@ public sealed class BSShapeCollection : IDisposable
202 else 202 else
203 { 203 {
204 // This is a new reference to a mesh 204 // This is a new reference to a mesh
205 meshDesc.ptr = shape.ptr; 205 meshDesc.shape = shape.Clone();
206 meshDesc.shapeKey = shape.shapeKey; 206 meshDesc.shapeKey = shape.shapeKey;
207 // We keep a reference to the underlying IMesh data so a hull can be built 207 // We keep a reference to the underlying IMesh data so a hull can be built
208 meshDesc.referenceCount = 1; 208 meshDesc.referenceCount = 1;
@@ -225,7 +225,7 @@ public sealed class BSShapeCollection : IDisposable
225 else 225 else
226 { 226 {
227 // This is a new reference to a hull 227 // This is a new reference to a hull
228 hullDesc.ptr = shape.ptr; 228 hullDesc.shape = shape.Clone();
229 hullDesc.shapeKey = shape.shapeKey; 229 hullDesc.shapeKey = shape.shapeKey;
230 hullDesc.referenceCount = 1; 230 hullDesc.referenceCount = 1;
231 if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}", 231 if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}",
@@ -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,57 +332,56 @@ 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 if (TryGetMeshByPtr(shapeInfo, out meshDesc))
365 if (TryGetMeshByPtr(cShape, out meshDesc))
366 { 365 {
367 shapeInfo.type = BSPhysicsShapeType.SHAPE_MESH; 366 shapeInfo.type = BSPhysicsShapeType.SHAPE_MESH;
368 shapeInfo.shapeKey = meshDesc.shapeKey; 367 shapeInfo.shapeKey = meshDesc.shapeKey;
369 } 368 }
370 else 369 else
371 { 370 {
372 if (TryGetHullByPtr(cShape, out hullDesc)) 371 if (TryGetHullByPtr(shapeInfo, out hullDesc))
373 { 372 {
374 shapeInfo.type = BSPhysicsShapeType.SHAPE_HULL; 373 shapeInfo.type = BSPhysicsShapeType.SHAPE_HULL;
375 shapeInfo.shapeKey = hullDesc.shapeKey; 374 shapeInfo.shapeKey = hullDesc.shapeKey;
376 } 375 }
377 else 376 else
378 { 377 {
379 if (BulletSimAPI.IsCompound2(cShape)) 378 if (PhysicsScene.PE.IsCompound(shapeInfo))
380 { 379 {
381 shapeInfo.type = BSPhysicsShapeType.SHAPE_COMPOUND; 380 shapeInfo.type = BSPhysicsShapeType.SHAPE_COMPOUND;
382 } 381 }
383 else 382 else
384 { 383 {
385 if (BulletSimAPI.IsNativeShape2(cShape)) 384 if (PhysicsScene.PE.IsNativeShape(shapeInfo))
386 { 385 {
387 shapeInfo.isNativeShape = true; 386 shapeInfo.isNativeShape = true;
388 shapeInfo.type = BSPhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter) 387 shapeInfo.type = BSPhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter)
@@ -400,7 +399,7 @@ public sealed class BSShapeCollection : IDisposable
400 else 399 else
401 { 400 {
402 PhysicsScene.Logger.ErrorFormat("{0} Could not decypher shape type. Region={1}, addr={2}", 401 PhysicsScene.Logger.ErrorFormat("{0} Could not decypher shape type. Region={1}, addr={2}",
403 LogHeader, PhysicsScene.RegionName, cShape.ToString("X")); 402 LogHeader, PhysicsScene.RegionName, shapeInfo.AddrString);
404 } 403 }
405 } 404 }
406 405
@@ -467,7 +466,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. 466 // 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; 467 OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero;
469 if (prim.PhysShape.HasPhysicalShape) 468 if (prim.PhysShape.HasPhysicalShape)
470 scaleOfExistingShape = BulletSimAPI.GetLocalScaling2(prim.PhysShape.ptr); 469 scaleOfExistingShape = PhysicsScene.PE.GetLocalScaling(prim.PhysShape);
471 470
472 if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}", 471 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); 472 prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.type);
@@ -570,19 +569,15 @@ public sealed class BSShapeCollection : IDisposable
570 569
571 if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE) 570 if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE)
572 { 571 {
573 // The proper scale has been calculated in the prim. 572
574 newShape = new BulletShape( 573 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); 574 if (DDetail) DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale);
581 } 575 }
582 else 576 else
583 { 577 {
584 // Native shapes are scaled in Bullet so set the scaling to the size 578 // Native shapes are scaled in Bullet so set the scaling to the size
585 newShape = new BulletShape(BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, nativeShapeData), shapeType); 579 newShape = PhysicsScene.PE.BuildNativeShape(PhysicsScene.World, nativeShapeData);
580
586 } 581 }
587 if (!newShape.HasPhysicalShape) 582 if (!newShape.HasPhysicalShape)
588 { 583 {
@@ -629,13 +624,14 @@ public sealed class BSShapeCollection : IDisposable
629 624
630 private BulletShape CreatePhysicalMesh(string objName, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) 625 private BulletShape CreatePhysicalMesh(string objName, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod)
631 { 626 {
627 BulletShape newShape = new BulletShape();
632 IMesh meshData = null; 628 IMesh meshData = null;
633 IntPtr meshPtr = IntPtr.Zero; 629
634 MeshDesc meshDesc; 630 MeshDesc meshDesc;
635 if (Meshes.TryGetValue(newMeshKey, out meshDesc)) 631 if (Meshes.TryGetValue(newMeshKey, out meshDesc))
636 { 632 {
637 // If the mesh has already been built just use it. 633 // If the mesh has already been built just use it.
638 meshPtr = meshDesc.ptr; 634 newShape = meshDesc.shape.Clone();
639 } 635 }
640 else 636 else
641 { 637 {
@@ -658,11 +654,10 @@ public sealed class BSShapeCollection : IDisposable
658 // m_log.DebugFormat("{0}: BSShapeCollection.CreatePhysicalMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}", 654 // 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); 655 // LogHeader, prim.LocalID, newMeshKey, indices.Length, vertices.Count);
660 656
661 meshPtr = BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr, 657 newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World,
662 indices.GetLength(0), indices, vertices.Count, verticesAsFloats); 658 indices.GetLength(0), indices, vertices.Count, verticesAsFloats);
663 } 659 }
664 } 660 }
665 BulletShape newShape = new BulletShape(meshPtr, BSPhysicsShapeType.SHAPE_MESH);
666 newShape.shapeKey = newMeshKey; 661 newShape.shapeKey = newMeshKey;
667 662
668 return newShape; 663 return newShape;
@@ -700,12 +695,14 @@ public sealed class BSShapeCollection : IDisposable
700 private BulletShape CreatePhysicalHull(string objName, System.UInt64 newHullKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) 695 private BulletShape CreatePhysicalHull(string objName, System.UInt64 newHullKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod)
701 { 696 {
702 697
698 BulletShape newShape = new BulletShape();
703 IntPtr hullPtr = IntPtr.Zero; 699 IntPtr hullPtr = IntPtr.Zero;
700
704 HullDesc hullDesc; 701 HullDesc hullDesc;
705 if (Hulls.TryGetValue(newHullKey, out hullDesc)) 702 if (Hulls.TryGetValue(newHullKey, out hullDesc))
706 { 703 {
707 // If the hull shape already is created, just use it. 704 // If the hull shape already is created, just use it.
708 hullPtr = hullDesc.ptr; 705 newShape = hullDesc.shape.Clone();
709 } 706 }
710 else 707 else
711 { 708 {
@@ -793,11 +790,10 @@ public sealed class BSShapeCollection : IDisposable
793 } 790 }
794 } 791 }
795 // create the hull data structure in Bullet 792 // create the hull data structure in Bullet
796 hullPtr = BulletSimAPI.CreateHullShape2(PhysicsScene.World.ptr, hullCount, convHulls); 793 newShape = PhysicsScene.PE.CreateHullShape(PhysicsScene.World, hullCount, convHulls);
797 } 794 }
798 } 795 }
799 796
800 BulletShape newShape = new BulletShape(hullPtr, BSPhysicsShapeType.SHAPE_HULL);
801 newShape.shapeKey = newHullKey; 797 newShape.shapeKey = newHullKey;
802 798
803 return newShape; 799 return newShape;
@@ -819,12 +815,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. 815 // 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); 816 // DereferenceShape(prim.PhysShape, true, shapeCallback);
821 817
822 BulletShape cShape = new BulletShape( 818
823 BulletSimAPI.CreateCompoundShape2(PhysicsScene.World.ptr, false), BSPhysicsShapeType.SHAPE_COMPOUND); 819 BulletShape cShape = PhysicsScene.PE.CreateCompoundShape(PhysicsScene.World, false);
824 820
825 // Create the shape for the root prim and add it to the compound shape. Cannot be a native shape. 821 // Create the shape for the root prim and add it to the compound shape. Cannot be a native shape.
826 CreateGeomMeshOrHull(prim, shapeCallback); 822 CreateGeomMeshOrHull(prim, shapeCallback);
827 BulletSimAPI.AddChildShapeToCompoundShape2(cShape.ptr, prim.PhysShape.ptr, OMV.Vector3.Zero, OMV.Quaternion.Identity); 823 PhysicsScene.PE.AddChildShapeToCompoundShape(cShape, prim.PhysShape, OMV.Vector3.Zero, OMV.Quaternion.Identity);
828 if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addRootPrim,compShape={1},rootShape={2}", 824 if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addRootPrim,compShape={1},rootShape={2}",
829 prim.LocalID, cShape, prim.PhysShape); 825 prim.LocalID, cShape, prim.PhysShape);
830 826
@@ -932,7 +928,7 @@ public sealed class BSShapeCollection : IDisposable
932 // If not a solid object, body is a GhostObject. Otherwise a RigidBody. 928 // If not a solid object, body is a GhostObject. Otherwise a RigidBody.
933 if (!mustRebuild) 929 if (!mustRebuild)
934 { 930 {
935 CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(prim.PhysBody.ptr); 931 CollisionObjectTypes bodyType = (CollisionObjectTypes)PhysicsScene.PE.GetBodyType(prim.PhysBody);
936 if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY 932 if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY
937 || !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT) 933 || !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT)
938 { 934 {
@@ -947,20 +943,16 @@ public sealed class BSShapeCollection : IDisposable
947 DereferenceBody(prim.PhysBody, true, bodyCallback); 943 DereferenceBody(prim.PhysBody, true, bodyCallback);
948 944
949 BulletBody aBody; 945 BulletBody aBody;
950 IntPtr bodyPtr = IntPtr.Zero;
951 if (prim.IsSolid) 946 if (prim.IsSolid)
952 { 947 {
953 bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, 948 aBody = PhysicsScene.PE.CreateBodyFromShape(sim, shape, prim.LocalID, prim.RawPosition, prim.RawOrientation);
954 prim.LocalID, prim.RawPosition, prim.RawOrientation); 949 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 } 950 }
957 else 951 else
958 { 952 {
959 bodyPtr = BulletSimAPI.CreateGhostFromShape2(sim.ptr, shape.ptr, 953 aBody = PhysicsScene.PE.CreateGhostFromShape(sim, shape, prim.LocalID, prim.RawPosition, prim.RawOrientation);
960 prim.LocalID, prim.RawPosition, prim.RawOrientation); 954 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 } 955 }
963 aBody = new BulletBody(prim.LocalID, bodyPtr);
964 956
965 ReferenceBody(aBody, true); 957 ReferenceBody(aBody, true);
966 958
@@ -972,13 +964,13 @@ public sealed class BSShapeCollection : IDisposable
972 return ret; 964 return ret;
973 } 965 }
974 966
975 private bool TryGetMeshByPtr(IntPtr addr, out MeshDesc outDesc) 967 private bool TryGetMeshByPtr(BulletShape shape, out MeshDesc outDesc)
976 { 968 {
977 bool ret = false; 969 bool ret = false;
978 MeshDesc foundDesc = new MeshDesc(); 970 MeshDesc foundDesc = new MeshDesc();
979 foreach (MeshDesc md in Meshes.Values) 971 foreach (MeshDesc md in Meshes.Values)
980 { 972 {
981 if (md.ptr == addr) 973 if (md.shape.ReferenceSame(shape))
982 { 974 {
983 foundDesc = md; 975 foundDesc = md;
984 ret = true; 976 ret = true;
@@ -990,13 +982,13 @@ public sealed class BSShapeCollection : IDisposable
990 return ret; 982 return ret;
991 } 983 }
992 984
993 private bool TryGetHullByPtr(IntPtr addr, out HullDesc outDesc) 985 private bool TryGetHullByPtr(BulletShape shape, out HullDesc outDesc)
994 { 986 {
995 bool ret = false; 987 bool ret = false;
996 HullDesc foundDesc = new HullDesc(); 988 HullDesc foundDesc = new HullDesc();
997 foreach (HullDesc hd in Hulls.Values) 989 foreach (HullDesc hd in Hulls.Values)
998 { 990 {
999 if (hd.ptr == addr) 991 if (hd.shape.ReferenceSame(shape))
1000 { 992 {
1001 foundDesc = hd; 993 foundDesc = hd;
1002 ret = true; 994 ret = true;