aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorRobert Adams2012-11-03 18:26:00 -0700
committerRobert Adams2012-11-03 21:15:54 -0700
commit894bb4893b8bb269f8561737e4603a9b31183f2c (patch)
tree03a9af547b801be262b4c4f956aa3152db1e90f2 /OpenSim/Region
parentBulletSim: Move construction of compound linkset from ShapeCollection (diff)
downloadopensim-SC_OLD-894bb4893b8bb269f8561737e4603a9b31183f2c.zip
opensim-SC_OLD-894bb4893b8bb269f8561737e4603a9b31183f2c.tar.gz
opensim-SC_OLD-894bb4893b8bb269f8561737e4603a9b31183f2c.tar.bz2
opensim-SC_OLD-894bb4893b8bb269f8561737e4603a9b31183f2c.tar.xz
BulletSim: search the mesh and hull lists to find shapes if type is not known. This makes sure the correct accounting is done for the particular shape.
Diffstat (limited to 'OpenSim/Region')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs10
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs2
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSScene.cs2
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs102
4 files changed, 96 insertions, 20 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
index adf4aff..6e68695 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
@@ -134,7 +134,7 @@ public sealed class BSLinksetCompound : BSLinkset
134 } 134 }
135 135
136 // Routine called when rebuilding the body of some member of the linkset. 136 // Routine called when rebuilding the body of some member of the linkset.
137 // Since we don't keep in-physical world relationships, do nothing unless it's a child changing. 137 // Since we don't keep in world relationships, do nothing unless it's a child changing.
138 // Returns 'true' of something was actually removed and would need restoring 138 // Returns 'true' of something was actually removed and would need restoring
139 // Called at taint-time!! 139 // Called at taint-time!!
140 public override bool RemoveBodyDependencies(BSPrim child) 140 public override bool RemoveBodyDependencies(BSPrim child)
@@ -221,10 +221,12 @@ public sealed class BSLinksetCompound : BSLinkset
221 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,start,rBody={1},rShape={2},numChildren={3}", 221 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,start,rBody={1},rShape={2},numChildren={3}",
222 LinksetRoot.LocalID, LinksetRoot.PhysBody, LinksetRoot.PhysShape, NumberOfChildren); 222 LinksetRoot.LocalID, LinksetRoot.PhysBody, LinksetRoot.PhysShape, NumberOfChildren);
223 223
224 // Add a shape for each of the other children in the linkset
224 ForEachMember(delegate(BSPhysObject cPrim) 225 ForEachMember(delegate(BSPhysObject cPrim)
225 { 226 {
226 if (!IsRoot(cPrim)) 227 if (!IsRoot(cPrim))
227 { 228 {
229 // Each child position and rotation is given relative to the root.
228 OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(LinksetRoot.RawOrientation); 230 OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(LinksetRoot.RawOrientation);
229 OMV.Vector3 displacementPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation; 231 OMV.Vector3 displacementPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation;
230 OMV.Quaternion displacementRot = cPrim.RawOrientation * invRootOrientation; 232 OMV.Quaternion displacementRot = cPrim.RawOrientation * invRootOrientation;
@@ -245,7 +247,7 @@ public sealed class BSLinksetCompound : BSLinkset
245 } 247 }
246 else 248 else
247 { 249 {
248 // For the shared shapes (meshes and hulls) just use the shape in the child 250 // For the shared shapes (meshes and hulls), just use the shape in the child.
249 if (PhysicsScene.Shapes.ReferenceShape(cPrim.PhysShape)) 251 if (PhysicsScene.Shapes.ReferenceShape(cPrim.PhysShape))
250 { 252 {
251 PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}", 253 PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}",
@@ -254,10 +256,10 @@ public sealed class BSLinksetCompound : BSLinkset
254 BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, displacementPos, displacementRot); 256 BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, displacementPos, displacementRot);
255 } 257 }
256 } 258 }
257 return false; 259 return false; // 'false' says to move onto the next child in the list
258 }); 260 });
259 261
260 262 // With all of the linkset packed into the root prim, it has the mass of everyone.
261 float linksetMass = LinksetMass; 263 float linksetMass = LinksetMass;
262 LinksetRoot.UpdatePhysicalMassProperties(linksetMass); 264 LinksetRoot.UpdatePhysicalMassProperties(linksetMass);
263 265
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
index 67a59ef..d2387fb 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
@@ -294,7 +294,7 @@ public sealed class BSLinksetConstraints : BSLinkset
294 float linksetMass = LinksetMass; 294 float linksetMass = LinksetMass;
295 LinksetRoot.UpdatePhysicalMassProperties(linksetMass); 295 LinksetRoot.UpdatePhysicalMassProperties(linksetMass);
296 296
297 // DEBUG: see of inter-linkset collisions are causing problems 297 // DEBUG: see of inter-linkset collisions are causing problems
298 // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr, 298 // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr,
299 // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask); 299 // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask);
300 DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}", 300 DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}",
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index de35359..c2e0ef1 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -1472,7 +1472,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
1472 public void DetailLog(string msg, params Object[] args) 1472 public void DetailLog(string msg, params Object[] args)
1473 { 1473 {
1474 PhysicsLogging.Write(msg, args); 1474 PhysicsLogging.Write(msg, args);
1475 // Add the Flush() if debugging crashes to get all the messages written out. 1475 // Add the Flush() if debugging crashes. Gets all the messages written out.
1476 PhysicsLogging.Flush(); 1476 PhysicsLogging.Flush();
1477 } 1477 }
1478 // Used to fill in the LocalID when there isn't one. It's the correct number of characters. 1478 // Used to fill in the LocalID when there isn't one. It's the correct number of characters.
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index 662b19d..4a31c7d 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -48,6 +48,7 @@ public sealed class BSShapeCollection : IDisposable
48 public IntPtr ptr; 48 public IntPtr ptr;
49 public int referenceCount; 49 public int referenceCount;
50 public DateTime lastReferenced; 50 public DateTime lastReferenced;
51 public UInt64 shapeKey;
51 } 52 }
52 53
53 // Description of a hull. 54 // Description of a hull.
@@ -57,6 +58,7 @@ public sealed class BSShapeCollection : IDisposable
57 public IntPtr ptr; 58 public IntPtr ptr;
58 public int referenceCount; 59 public int referenceCount;
59 public DateTime lastReferenced; 60 public DateTime lastReferenced;
61 public UInt64 shapeKey;
60 } 62 }
61 63
62 // The sharable set of meshes and hulls. Indexed by their shape hash. 64 // The sharable set of meshes and hulls. Indexed by their shape hash.
@@ -116,7 +118,7 @@ public sealed class BSShapeCollection : IDisposable
116 return ret; 118 return ret;
117 } 119 }
118 120
119 // Track another user of a body 121 // Track another user of a body.
120 // We presume the caller has allocated the body. 122 // We presume the caller has allocated the body.
121 // Bodies only have one user so the body is just put into the world if not already there. 123 // Bodies only have one user so the body is just put into the world if not already there.
122 public void ReferenceBody(BulletBody body, bool inTaintTime) 124 public void ReferenceBody(BulletBody body, bool inTaintTime)
@@ -146,13 +148,16 @@ public sealed class BSShapeCollection : IDisposable
146 { 148 {
147 PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceBody", delegate() 149 PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceBody", delegate()
148 { 150 {
149 DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody. ptr={1}, inTaintTime={2}", 151 DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody,body={1},inTaintTime={2}",
150 body.ID, body.ptr.ToString("X"), inTaintTime); 152 body.ID, body, inTaintTime);
151 // If the caller needs to know the old body is going away, pass the event up. 153 // If the caller needs to know the old body is going away, pass the event up.
152 if (bodyCallback != null) bodyCallback(body); 154 if (bodyCallback != null) bodyCallback(body);
153 155
154 // It may have already been removed from the world in which case the next is a NOOP. 156 if (BulletSimAPI.IsInWorld2(body.ptr))
155 BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, body.ptr); 157 {
158 BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, body.ptr);
159 DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body);
160 }
156 161
157 // Zero any reference to the shape so it is not freed when the body is deleted. 162 // Zero any reference to the shape so it is not freed when the body is deleted.
158 BulletSimAPI.SetCollisionShape2(PhysicsScene.World.ptr, body.ptr, IntPtr.Zero); 163 BulletSimAPI.SetCollisionShape2(PhysicsScene.World.ptr, body.ptr, IntPtr.Zero);
@@ -185,6 +190,7 @@ public sealed class BSShapeCollection : IDisposable
185 { 190 {
186 // This is a new reference to a mesh 191 // This is a new reference to a mesh
187 meshDesc.ptr = shape.ptr; 192 meshDesc.ptr = shape.ptr;
193 meshDesc.shapeKey = shape.shapeKey;
188 // We keep a reference to the underlying IMesh data so a hull can be built 194 // We keep a reference to the underlying IMesh data so a hull can be built
189 meshDesc.referenceCount = 1; 195 meshDesc.referenceCount = 1;
190 DetailLog("{0},BSShapeCollection.ReferenceShape,newMesh,key={1},cnt={2}", 196 DetailLog("{0},BSShapeCollection.ReferenceShape,newMesh,key={1},cnt={2}",
@@ -207,6 +213,7 @@ public sealed class BSShapeCollection : IDisposable
207 { 213 {
208 // This is a new reference to a hull 214 // This is a new reference to a hull
209 hullDesc.ptr = shape.ptr; 215 hullDesc.ptr = shape.ptr;
216 hullDesc.shapeKey = shape.shapeKey;
210 hullDesc.referenceCount = 1; 217 hullDesc.referenceCount = 1;
211 DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}", 218 DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}",
212 BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); 219 BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount);
@@ -306,7 +313,7 @@ public sealed class BSShapeCollection : IDisposable
306 313
307 // Remove a reference to a compound shape. 314 // Remove a reference to a compound shape.
308 // Taking a compound shape apart is a little tricky because if you just delete the 315 // Taking a compound shape apart is a little tricky because if you just delete the
309 // physical object, it will free all the underlying children. We can't do that because 316 // physical shape, it will free all the underlying children. We can't do that because
310 // they could be shared. So, this removes each of the children from the compound and 317 // they could be shared. So, this removes each of the children from the compound and
311 // dereferences them separately before destroying the compound collision object itself. 318 // dereferences them separately before destroying the compound collision object itself.
312 // Called at taint-time. 319 // Called at taint-time.
@@ -335,22 +342,53 @@ public sealed class BSShapeCollection : IDisposable
335 342
336 // Sometimes we have a pointer to a collision shape but don't know what type it is. 343 // Sometimes we have a pointer to a collision shape but don't know what type it is.
337 // Figure out type and call the correct dereference routine. 344 // Figure out type and call the correct dereference routine.
338 // This is coming from a compound shape that we created so we know it is either native or mesh.
339 // Called at taint-time. 345 // Called at taint-time.
340 private void DereferenceAnonCollisionShape(IntPtr cShape) 346 private void DereferenceAnonCollisionShape(IntPtr cShape)
341 { 347 {
342 BulletShape shapeInfo = new BulletShape(cShape, ShapeData.PhysicsShapeType.SHAPE_MESH); 348 MeshDesc meshDesc;
343 if (BulletSimAPI.IsCompound2(cShape)) 349 HullDesc hullDesc;
344 shapeInfo.type = ShapeData.PhysicsShapeType.SHAPE_COMPOUND;
345 350
346 if (BulletSimAPI.IsNativeShape2(cShape)) 351 BulletShape shapeInfo = new BulletShape(cShape);
352 if (TryGetMeshByPtr(cShape, out meshDesc))
353 {
354 shapeInfo.type = ShapeData.PhysicsShapeType.SHAPE_MESH;
355 shapeInfo.shapeKey = meshDesc.shapeKey;
356 }
357 else
347 { 358 {
348 shapeInfo.isNativeShape = true; 359 if (TryGetHullByPtr(cShape, out hullDesc))
349 shapeInfo.type = ShapeData.PhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter) 360 {
361 shapeInfo.type = ShapeData.PhysicsShapeType.SHAPE_HULL;
362 shapeInfo.shapeKey = hullDesc.shapeKey;
363 }
364 else
365 {
366 if (BulletSimAPI.IsCompound2(cShape))
367 {
368 shapeInfo.type = ShapeData.PhysicsShapeType.SHAPE_COMPOUND;
369 }
370 else
371 {
372 if (BulletSimAPI.IsNativeShape2(cShape))
373 {
374 shapeInfo.isNativeShape = true;
375 shapeInfo.type = ShapeData.PhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter)
376 }
377 }
378 }
350 } 379 }
380
351 DetailLog("{0},BSShapeCollection.DereferenceAnonCollisionShape,shape={1}", BSScene.DetailLogZero, shapeInfo); 381 DetailLog("{0},BSShapeCollection.DereferenceAnonCollisionShape,shape={1}", BSScene.DetailLogZero, shapeInfo);
352 382
353 DereferenceShape(shapeInfo, true, null); 383 if (shapeInfo.type != ShapeData.PhysicsShapeType.SHAPE_UNKNOWN)
384 {
385 DereferenceShape(shapeInfo, true, null);
386 }
387 else
388 {
389 PhysicsScene.Logger.ErrorFormat("{0} Could not decypher shape type. Region={1}, addr={2}",
390 LogHeader, PhysicsScene.RegionName, cShape.ToString("X"));
391 }
354 } 392 }
355 393
356 // Create the geometry information in Bullet for later use. 394 // Create the geometry information in Bullet for later use.
@@ -913,6 +951,42 @@ public sealed class BSShapeCollection : IDisposable
913 return ret; 951 return ret;
914 } 952 }
915 953
954 private bool TryGetMeshByPtr(IntPtr addr, out MeshDesc outDesc)
955 {
956 bool ret = false;
957 MeshDesc foundDesc = new MeshDesc();
958 foreach (MeshDesc md in Meshes.Values)
959 {
960 if (md.ptr == addr)
961 {
962 foundDesc = md;
963 ret = true;
964 break;
965 }
966
967 }
968 outDesc = foundDesc;
969 return ret;
970 }
971
972 private bool TryGetHullByPtr(IntPtr addr, out HullDesc outDesc)
973 {
974 bool ret = false;
975 HullDesc foundDesc = new HullDesc();
976 foreach (HullDesc hd in Hulls.Values)
977 {
978 if (hd.ptr == addr)
979 {
980 foundDesc = hd;
981 ret = true;
982 break;
983 }
984
985 }
986 outDesc = foundDesc;
987 return ret;
988 }
989
916 private void DetailLog(string msg, params Object[] args) 990 private void DetailLog(string msg, params Object[] args)
917 { 991 {
918 if (PhysicsScene.PhysicsLogging.Enabled) 992 if (PhysicsScene.PhysicsLogging.Enabled)