aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs9
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs155
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs3
3 files changed, 88 insertions, 79 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
index 777c5cb..ce0fbe6 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
@@ -124,7 +124,7 @@ public abstract class BSLinkset
124 get { return ComputeLinksetGeometricCenter(); } 124 get { return ComputeLinksetGeometricCenter(); }
125 } 125 }
126 126
127 protected void Initialize(BSScene scene, BSPhysObject parent) 127 protected BSLinkset(BSScene scene, BSPhysObject parent)
128 { 128 {
129 // A simple linkset of one (no children) 129 // A simple linkset of one (no children)
130 LinksetID = m_nextLinksetID++; 130 LinksetID = m_nextLinksetID++;
@@ -135,6 +135,7 @@ public abstract class BSLinkset
135 LinksetRoot = parent; 135 LinksetRoot = parent;
136 m_children = new HashSet<BSPhysObject>(); 136 m_children = new HashSet<BSPhysObject>();
137 m_mass = parent.RawMass; 137 m_mass = parent.RawMass;
138 Rebuilding = false;
138 } 139 }
139 140
140 // Link to a linkset where the child knows the parent. 141 // Link to a linkset where the child knows the parent.
@@ -227,7 +228,7 @@ public abstract class BSLinkset
227 // I am the root of a linkset and a new child is being added 228 // I am the root of a linkset and a new child is being added
228 // Called while LinkActivity is locked. 229 // Called while LinkActivity is locked.
229 protected abstract void AddChildToLinkset(BSPhysObject child); 230 protected abstract void AddChildToLinkset(BSPhysObject child);
230 231
231 // I am the root of a linkset and one of my children is being removed. 232 // I am the root of a linkset and one of my children is being removed.
232 // Safe to call even if the child is not really in my linkset. 233 // Safe to call even if the child is not really in my linkset.
233 protected abstract void RemoveChildFromLinkset(BSPhysObject child); 234 protected abstract void RemoveChildFromLinkset(BSPhysObject child);
@@ -237,6 +238,10 @@ public abstract class BSLinkset
237 // May be called at runtime or taint-time. 238 // May be called at runtime or taint-time.
238 public abstract void Refresh(BSPhysObject requestor); 239 public abstract void Refresh(BSPhysObject requestor);
239 240
241 // Flag denoting the linkset is in the process of being rebuilt.
242 // Used to know not the schedule a rebuild in the middle of a rebuild.
243 protected bool Rebuilding { get; set; }
244
240 // The object is going dynamic (physical). Do any setup necessary 245 // The object is going dynamic (physical). Do any setup necessary
241 // for a dynamic linkset. 246 // for a dynamic linkset.
242 // Only the state of the passed object can be modified. The rest of the linkset 247 // Only the state of the passed object can be modified. The rest of the linkset
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
index 6cabe3a..2189468 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
@@ -61,9 +61,8 @@ public sealed class BSLinksetCompound : BSLinkset
61{ 61{
62 private static string LogHeader = "[BULLETSIM LINKSET COMPOUND]"; 62 private static string LogHeader = "[BULLETSIM LINKSET COMPOUND]";
63 63
64 public BSLinksetCompound(BSScene scene, BSPhysObject parent) 64 public BSLinksetCompound(BSScene scene, BSPhysObject parent) : base(scene, parent)
65 { 65 {
66 base.Initialize(scene, parent);
67 } 66 }
68 67
69 // For compound implimented linksets, if there are children, use compound shape for the root. 68 // For compound implimented linksets, if there are children, use compound shape for the root.
@@ -81,8 +80,6 @@ public sealed class BSLinksetCompound : BSLinkset
81 80
82 // When physical properties are changed the linkset needs to recalculate 81 // When physical properties are changed the linkset needs to recalculate
83 // its internal properties. 82 // its internal properties.
84 // This is queued in the 'post taint' queue so the
85 // refresh will happen once after all the other taints are applied.
86 public override void Refresh(BSPhysObject requestor) 83 public override void Refresh(BSPhysObject requestor)
87 { 84 {
88 // External request for Refresh (from BSPrim) doesn't need to do anything 85 // External request for Refresh (from BSPrim) doesn't need to do anything
@@ -92,12 +89,18 @@ public sealed class BSLinksetCompound : BSLinkset
92 // Schedule a refresh to happen after all the other taint processing. 89 // Schedule a refresh to happen after all the other taint processing.
93 private void InternalRefresh(BSPhysObject requestor) 90 private void InternalRefresh(BSPhysObject requestor)
94 { 91 {
95 DetailLog("{0},BSLinksetCompound.Refresh,schedulingRefresh,requestor={1}", LinksetRoot.LocalID, requestor.LocalID); 92 DetailLog("{0},BSLinksetCompound.Refresh,schedulingRefresh,requestor={1},rebuilding={2}",
96 PhysicsScene.PostTaintObject("BSLinksetCompound.Refresh", requestor.LocalID, delegate() 93 LinksetRoot.LocalID, requestor.LocalID, Rebuilding);
94 // When rebuilding, it is possible to set properties that would normally require a rebuild.
95 // If already rebuilding, don't request another rebuild.
96 if (!Rebuilding)
97 { 97 {
98 if (IsRoot(requestor) && HasAnyChildren) 98 PhysicsScene.PostTaintObject("BSLinksetCompound.Refresh", requestor.LocalID, delegate()
99 RecomputeLinksetCompound(); 99 {
100 }); 100 if (IsRoot(requestor) && HasAnyChildren)
101 RecomputeLinksetCompound();
102 });
103 }
101 } 104 }
102 105
103 // The object is going dynamic (physical). Do any setup necessary 106 // The object is going dynamic (physical). Do any setup necessary
@@ -115,11 +118,7 @@ public sealed class BSLinksetCompound : BSLinkset
115 // The root is going dynamic. Make sure mass is properly set. 118 // The root is going dynamic. Make sure mass is properly set.
116 m_mass = ComputeLinksetMass(); 119 m_mass = ComputeLinksetMass();
117 if (HasAnyChildren) 120 if (HasAnyChildren)
118 {
119 // Schedule a rebuilding as this will construct the complete compound shape
120 // and set all the properties correctly.
121 InternalRefresh(LinksetRoot); 121 InternalRefresh(LinksetRoot);
122 }
123 } 122 }
124 else 123 else
125 { 124 {
@@ -149,16 +148,13 @@ public sealed class BSLinksetCompound : BSLinkset
149 if (IsRoot(child)) 148 if (IsRoot(child))
150 { 149 {
151 if (HasAnyChildren) 150 if (HasAnyChildren)
152 {
153 // Schedule a rebuilding as this will construct the complete compound shape
154 // and set all the properties correctly.
155 InternalRefresh(LinksetRoot); 151 InternalRefresh(LinksetRoot);
156 }
157 } 152 }
158 else 153 else
159 { 154 {
160 // The non-physical children can come back to life. 155 // The non-physical children can come back to life.
161 BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); 156 BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE);
157
162 child.PhysBody.collisionType = CollisionType.LinksetChild; 158 child.PhysBody.collisionType = CollisionType.LinksetChild;
163 159
164 // Don't force activation so setting of DISABLE_SIMULATION can stay if used. 160 // Don't force activation so setting of DISABLE_SIMULATION can stay if used.
@@ -307,74 +303,83 @@ public sealed class BSLinksetCompound : BSLinkset
307 // Called at taint time!! 303 // Called at taint time!!
308 private void RecomputeLinksetCompound() 304 private void RecomputeLinksetCompound()
309 { 305 {
310 // Cause the root shape to be rebuilt as a compound object with just the root in it 306 try
311 LinksetRoot.ForceBodyShapeRebuild(true); 307 {
308 // Suppress rebuilding while rebuilding
309 Rebuilding = true;
312 310
313 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,start,rBody={1},rShape={2},numChildren={3}", 311 // Cause the root shape to be rebuilt as a compound object with just the root in it
314 LinksetRoot.LocalID, LinksetRoot.PhysBody, LinksetRoot.PhysShape, NumberOfChildren); 312 LinksetRoot.ForceBodyShapeRebuild(true);
315 313
316 // Add a shape for each of the other children in the linkset 314 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,start,rBody={1},rShape={2},numChildren={3}",
317 ForEachMember(delegate(BSPhysObject cPrim) 315 LinksetRoot.LocalID, LinksetRoot.PhysBody, LinksetRoot.PhysShape, NumberOfChildren);
318 { 316
319 if (!IsRoot(cPrim)) 317 // Add a shape for each of the other children in the linkset
318 ForEachMember(delegate(BSPhysObject cPrim)
320 { 319 {
321 // Compute the displacement of the child from the root of the linkset. 320 if (!IsRoot(cPrim))
322 // This info is saved in the child prim so the relationship does not
323 // change over time and the new child position can be computed
324 // when the linkset is being disassembled (the linkset may have moved).
325 BSLinksetCompoundInfo lci = cPrim.LinksetInfo as BSLinksetCompoundInfo;
326 if (lci == null)
327 { 321 {
328 // Each child position and rotation is given relative to the root. 322 // Compute the displacement of the child from the root of the linkset.
329 OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(LinksetRoot.RawOrientation); 323 // This info is saved in the child prim so the relationship does not
330 OMV.Vector3 displacementPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation; 324 // change over time and the new child position can be computed
331 OMV.Quaternion displacementRot = cPrim.RawOrientation * invRootOrientation; 325 // when the linkset is being disassembled (the linkset may have moved).
332 326 BSLinksetCompoundInfo lci = cPrim.LinksetInfo as BSLinksetCompoundInfo;
333 // Save relative position for recomputing child's world position after moving linkset. 327 if (lci == null)
334 lci = new BSLinksetCompoundInfo(displacementPos, displacementRot); 328 {
335 cPrim.LinksetInfo = lci; 329 // Each child position and rotation is given relative to the root.
336 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,creatingRelPos,lci={1}", cPrim.LocalID, lci); 330 OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(LinksetRoot.RawOrientation);
337 } 331 OMV.Vector3 displacementPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation;
332 OMV.Quaternion displacementRot = cPrim.RawOrientation * invRootOrientation;
333
334 // Save relative position for recomputing child's world position after moving linkset.
335 lci = new BSLinksetCompoundInfo(displacementPos, displacementRot);
336 cPrim.LinksetInfo = lci;
337 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,creatingRelPos,lci={1}", cPrim.LocalID, lci);
338 }
338 339
339 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addMemberToShape,mID={1},mShape={2},dispPos={3},dispRot={4}", 340 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addMemberToShape,mID={1},mShape={2},dispPos={3},dispRot={4}",
340 LinksetRoot.LocalID, cPrim.LocalID, cPrim.PhysShape, lci.OffsetPos, lci.OffsetRot); 341 LinksetRoot.LocalID, cPrim.LocalID, cPrim.PhysShape, lci.OffsetPos, lci.OffsetRot);
341 342
342 if (cPrim.PhysShape.isNativeShape) 343 if (cPrim.PhysShape.isNativeShape)
343 { 344 {
344 // A native shape is turning into a hull collision shape because native 345 // A native shape is turning into a hull collision shape because native
345 // shapes are not shared so we have to hullify it so it will be tracked 346 // shapes are not shared so we have to hullify it so it will be tracked
346 // and freed at the correct time. This also solves the scaling problem 347 // and freed at the correct time. This also solves the scaling problem
347 // (native shapes scaled but hull/meshes are assumed to not be). 348 // (native shapes scaled but hull/meshes are assumed to not be).
348 // TODO: decide of the native shape can just be used in the compound shape. 349 // TODO: decide of the native shape can just be used in the compound shape.
349 // Use call to CreateGeomNonSpecial(). 350 // Use call to CreateGeomNonSpecial().
350 BulletShape saveShape = cPrim.PhysShape; 351 BulletShape saveShape = cPrim.PhysShape;
351 cPrim.PhysShape.Clear(); // Don't let the create free the child's shape 352 cPrim.PhysShape.Clear(); // Don't let the create free the child's shape
352 // PhysicsScene.Shapes.CreateGeomNonSpecial(true, cPrim, null); 353 // PhysicsScene.Shapes.CreateGeomNonSpecial(true, cPrim, null);
353 PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null); 354 PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null);
354 BulletShape newShape = cPrim.PhysShape; 355 BulletShape newShape = cPrim.PhysShape;
355 cPrim.PhysShape = saveShape; 356 cPrim.PhysShape = saveShape;
356 BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, newShape.ptr, lci.OffsetPos , lci.OffsetRot); 357 BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, newShape.ptr, lci.OffsetPos, lci.OffsetRot);
357 } 358 }
358 else 359 else
359 {
360 // For the shared shapes (meshes and hulls), just use the shape in the child.
361 // The reference count added here will be decremented when the compound shape
362 // is destroyed in BSShapeCollection (the child shapes are looped over and dereferenced).
363 if (PhysicsScene.Shapes.ReferenceShape(cPrim.PhysShape))
364 { 360 {
365 PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}", 361 // For the shared shapes (meshes and hulls), just use the shape in the child.
366 LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape); 362 // The reference count added here will be decremented when the compound shape
363 // is destroyed in BSShapeCollection (the child shapes are looped over and dereferenced).
364 if (PhysicsScene.Shapes.ReferenceShape(cPrim.PhysShape))
365 {
366 PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}",
367 LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape);
368 }
369 BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, lci.OffsetPos, lci.OffsetRot);
367 } 370 }
368 BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, lci.OffsetPos , lci.OffsetRot);
369 } 371 }
370 } 372 return false; // 'false' says to move onto the next child in the list
371 373 });
372 return false; // 'false' says to move onto the next child in the list
373 });
374 374
375 // With all of the linkset packed into the root prim, it has the mass of everyone. 375 // With all of the linkset packed into the root prim, it has the mass of everyone.
376 float linksetMass = LinksetMass; 376 float linksetMass = LinksetMass;
377 LinksetRoot.UpdatePhysicalMassProperties(linksetMass); 377 LinksetRoot.UpdatePhysicalMassProperties(linksetMass);
378 }
379 finally
380 {
381 Rebuilding = false;
382 }
378 383
379 BulletSimAPI.RecalculateCompoundShapeLocalAabb2(LinksetRoot.PhysShape.ptr); 384 BulletSimAPI.RecalculateCompoundShapeLocalAabb2(LinksetRoot.PhysShape.ptr);
380 385
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
index c855fda..732c084 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
@@ -36,9 +36,8 @@ public sealed class BSLinksetConstraints : BSLinkset
36{ 36{
37 // private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]"; 37 // private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]";
38 38
39 public BSLinksetConstraints(BSScene scene, BSPhysObject parent) 39 public BSLinksetConstraints(BSScene scene, BSPhysObject parent) : base(scene, parent)
40 { 40 {
41 base.Initialize(scene, parent);
42 } 41 }
43 42
44 // When physical properties are changed the linkset needs to recalculate 43 // When physical properties are changed the linkset needs to recalculate