diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | 85 |
1 files changed, 42 insertions, 43 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 107befe..662b19d 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | |||
@@ -92,6 +92,8 @@ public sealed class BSShapeCollection : IDisposable | |||
92 | public bool GetBodyAndShape(bool forceRebuild, BulletSim sim, BSPhysObject prim, | 92 | public bool GetBodyAndShape(bool forceRebuild, BulletSim sim, BSPhysObject prim, |
93 | ShapeDestructionCallback shapeCallback, BodyDestructionCallback bodyCallback) | 93 | ShapeDestructionCallback shapeCallback, BodyDestructionCallback bodyCallback) |
94 | { | 94 | { |
95 | PhysicsScene.AssertInTaintTime("BSShapeCollection.GetBodyAndShape"); | ||
96 | |||
95 | bool ret = false; | 97 | bool ret = false; |
96 | 98 | ||
97 | // This lock could probably be pushed down lower but building shouldn't take long | 99 | // This lock could probably be pushed down lower but building shouldn't take long |
@@ -121,7 +123,7 @@ public sealed class BSShapeCollection : IDisposable | |||
121 | { | 123 | { |
122 | lock (m_collectionActivityLock) | 124 | lock (m_collectionActivityLock) |
123 | { | 125 | { |
124 | DetailLog("{0},BSShapeCollection.ReferenceBody,newBody", body.ID, body); | 126 | DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body); |
125 | PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.ReferenceBody", delegate() | 127 | PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.ReferenceBody", delegate() |
126 | { | 128 | { |
127 | if (!BulletSimAPI.IsInWorld2(body.ptr)) | 129 | if (!BulletSimAPI.IsInWorld2(body.ptr)) |
@@ -165,7 +167,7 @@ public sealed class BSShapeCollection : IDisposable | |||
165 | // Meshes and hulls for the same shape have the same hash key. | 167 | // Meshes and hulls for the same shape have the same hash key. |
166 | // NOTE that native shapes are not added to the mesh list or removed. | 168 | // NOTE that native shapes are not added to the mesh list or removed. |
167 | // Returns 'true' if this is the initial reference to the shape. Otherwise reused. | 169 | // Returns 'true' if this is the initial reference to the shape. Otherwise reused. |
168 | private bool ReferenceShape(BulletShape shape) | 170 | public bool ReferenceShape(BulletShape shape) |
169 | { | 171 | { |
170 | bool ret = false; | 172 | bool ret = false; |
171 | switch (shape.type) | 173 | switch (shape.type) |
@@ -276,8 +278,8 @@ public sealed class BSShapeCollection : IDisposable | |||
276 | if (shapeCallback != null) shapeCallback(shape); | 278 | if (shapeCallback != null) shapeCallback(shape); |
277 | meshDesc.lastReferenced = System.DateTime.Now; | 279 | meshDesc.lastReferenced = System.DateTime.Now; |
278 | Meshes[shape.shapeKey] = meshDesc; | 280 | Meshes[shape.shapeKey] = meshDesc; |
279 | DetailLog("{0},BSShapeCollection.DereferenceMesh,key={1},refCnt={2}", | 281 | DetailLog("{0},BSShapeCollection.DereferenceMesh,shape={1},refCnt={2}", |
280 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); | 282 | BSScene.DetailLogZero, shape, meshDesc.referenceCount); |
281 | 283 | ||
282 | } | 284 | } |
283 | } | 285 | } |
@@ -297,8 +299,8 @@ public sealed class BSShapeCollection : IDisposable | |||
297 | 299 | ||
298 | hullDesc.lastReferenced = System.DateTime.Now; | 300 | hullDesc.lastReferenced = System.DateTime.Now; |
299 | Hulls[shape.shapeKey] = hullDesc; | 301 | Hulls[shape.shapeKey] = hullDesc; |
300 | DetailLog("{0},BSShapeCollection.DereferenceHull,key={1},refCnt={2}", | 302 | DetailLog("{0},BSShapeCollection.DereferenceHull,shape={1},refCnt={2}", |
301 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); | 303 | BSScene.DetailLogZero, shape, hullDesc.referenceCount); |
302 | } | 304 | } |
303 | } | 305 | } |
304 | 306 | ||
@@ -319,8 +321,11 @@ public sealed class BSShapeCollection : IDisposable | |||
319 | BSScene.DetailLogZero, shape.type, shape.ptr.ToString("X")); | 321 | BSScene.DetailLogZero, shape.type, shape.ptr.ToString("X")); |
320 | return; | 322 | return; |
321 | } | 323 | } |
324 | |||
322 | int numChildren = BulletSimAPI.GetNumberOfCompoundChildren2(shape.ptr); | 325 | int numChildren = BulletSimAPI.GetNumberOfCompoundChildren2(shape.ptr); |
323 | for (int ii = 0; ii < numChildren; ii++) | 326 | DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", BSScene.DetailLogZero, shape, numChildren); |
327 | |||
328 | for (int ii = numChildren - 1; ii >= 0; ii--) | ||
324 | { | 329 | { |
325 | IntPtr childShape = BulletSimAPI.RemoveChildShapeFromCompoundShapeIndex2(shape.ptr, ii); | 330 | IntPtr childShape = BulletSimAPI.RemoveChildShapeFromCompoundShapeIndex2(shape.ptr, ii); |
326 | DereferenceAnonCollisionShape(childShape); | 331 | DereferenceAnonCollisionShape(childShape); |
@@ -343,6 +348,7 @@ public sealed class BSShapeCollection : IDisposable | |||
343 | shapeInfo.isNativeShape = true; | 348 | shapeInfo.isNativeShape = true; |
344 | shapeInfo.type = ShapeData.PhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter) | 349 | shapeInfo.type = ShapeData.PhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter) |
345 | } | 350 | } |
351 | DetailLog("{0},BSShapeCollection.DereferenceAnonCollisionShape,shape={1}", BSScene.DetailLogZero, shapeInfo); | ||
346 | 352 | ||
347 | DereferenceShape(shapeInfo, true, null); | 353 | DereferenceShape(shapeInfo, true, null); |
348 | } | 354 | } |
@@ -440,23 +446,32 @@ public sealed class BSShapeCollection : IDisposable | |||
440 | } | 446 | } |
441 | 447 | ||
442 | // If a simple shape is not happening, create a mesh and possibly a hull. | 448 | // If a simple shape is not happening, create a mesh and possibly a hull. |
449 | if (!haveShape && pbs != null) | ||
450 | { | ||
451 | ret = CreateGeomMeshOrHull(prim, shapeCallback); | ||
452 | } | ||
453 | |||
454 | return ret; | ||
455 | } | ||
456 | |||
457 | public bool CreateGeomMeshOrHull(BSPhysObject prim, ShapeDestructionCallback shapeCallback) | ||
458 | { | ||
459 | |||
460 | bool ret = false; | ||
443 | // Note that if it's a native shape, the check for physical/non-physical is not | 461 | // Note that if it's a native shape, the check for physical/non-physical is not |
444 | // made. Native shapes work in either case. | 462 | // made. Native shapes work in either case. |
445 | if (!haveShape && pbs != null) | 463 | if (prim.IsPhysical && PhysicsScene.ShouldUseHullsForPhysicalObjects) |
446 | { | 464 | { |
447 | if (prim.IsPhysical && PhysicsScene.ShouldUseHullsForPhysicalObjects) | 465 | // Update prim.BSShape to reference a hull of this shape. |
448 | { | 466 | ret = GetReferenceToHull(prim,shapeCallback); |
449 | // Update prim.BSShape to reference a hull of this shape. | 467 | DetailLog("{0},BSShapeCollection.CreateGeom,hull,shape={1},key={2}", |
450 | ret = GetReferenceToHull(prim,shapeCallback); | 468 | prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X")); |
451 | DetailLog("{0},BSShapeCollection.CreateGeom,hull,shape={1},key={2}", | 469 | } |
452 | prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X")); | 470 | else |
453 | } | 471 | { |
454 | else | 472 | ret = GetReferenceToMesh(prim, shapeCallback); |
455 | { | 473 | DetailLog("{0},BSShapeCollection.CreateGeom,mesh,shape={1},key={2}", |
456 | ret = GetReferenceToMesh(prim, shapeCallback); | 474 | prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X")); |
457 | DetailLog("{0},BSShapeCollection.CreateGeom,mesh,shape={1},key={2}", | ||
458 | prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X")); | ||
459 | } | ||
460 | } | 475 | } |
461 | return ret; | 476 | return ret; |
462 | } | 477 | } |
@@ -743,32 +758,16 @@ public sealed class BSShapeCollection : IDisposable | |||
743 | // This shouldn't be to bad since most of the parts will be meshes that had been built previously. | 758 | // This shouldn't be to bad since most of the parts will be meshes that had been built previously. |
744 | private bool GetReferenceToCompoundShape(BSPhysObject prim, ShapeDestructionCallback shapeCallback) | 759 | private bool GetReferenceToCompoundShape(BSPhysObject prim, ShapeDestructionCallback shapeCallback) |
745 | { | 760 | { |
761 | // Remove reference to the old shape | ||
762 | // Don't need to do this as the shape is freed when we create the new root shape below. | ||
763 | // DereferenceShape(prim.PhysShape, true, shapeCallback); | ||
764 | |||
746 | BulletShape cShape = new BulletShape( | 765 | BulletShape cShape = new BulletShape( |
747 | BulletSimAPI.CreateCompoundShape2(PhysicsScene.World.ptr), ShapeData.PhysicsShapeType.SHAPE_COMPOUND); | 766 | BulletSimAPI.CreateCompoundShape2(PhysicsScene.World.ptr), ShapeData.PhysicsShapeType.SHAPE_COMPOUND); |
748 | 767 | ||
749 | // The prim's linkset is the source of the children. | 768 | // Create the shape for the root prim and add it to the compound shape |
750 | // TODO: there is too much knowledge here about the internals of linksets and too much | ||
751 | // dependency on the relationship of compound shapes and linksets (what if we want to use | ||
752 | // compound shapes for something else?). Think through this and clean up so the | ||
753 | // appropriate knowledge is used at the correct software levels. | ||
754 | |||
755 | // Recreate the geometry of the root prim (might have been a linkset root in the past) | ||
756 | CreateGeomNonSpecial(true, prim, null); | 769 | CreateGeomNonSpecial(true, prim, null); |
757 | 770 | BulletSimAPI.AddChildShapeToCompoundShape2(cShape.ptr, prim.PhysShape.ptr, OMV.Vector3.Zero, OMV.Quaternion.Identity); | |
758 | BSPhysObject rootPrim = prim.Linkset.LinksetRoot; | ||
759 | |||
760 | prim.Linkset.ForEachMember(delegate(BSPhysObject cPrim) | ||
761 | { | ||
762 | OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(rootPrim.RawOrientation); | ||
763 | OMV.Vector3 displacementPos = (cPrim.RawPosition - rootPrim.RawPosition) * invRootOrientation; | ||
764 | OMV.Quaternion displacementRot = cPrim.RawOrientation * invRootOrientation; | ||
765 | |||
766 | DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addMemberToShape,mID={1},mShape={2},dispPos={3},dispRot={4}", | ||
767 | prim.LocalID, cPrim.LocalID, cPrim.PhysShape.ptr.ToString("X"), displacementPos, displacementRot); | ||
768 | |||
769 | BulletSimAPI.AddChildShapeToCompoundShape2(cShape.ptr, cPrim.PhysShape.ptr, displacementPos, displacementRot); | ||
770 | return false; | ||
771 | }); | ||
772 | 771 | ||
773 | prim.PhysShape = cShape; | 772 | prim.PhysShape = cShape; |
774 | 773 | ||