diff options
author | Robert Adams | 2012-07-12 11:29:45 -0700 |
---|---|---|
committer | Robert Adams | 2012-07-20 14:02:22 -0700 |
commit | f9913b6ef7e7f18075e1e42ed5e347ce2a8b8ef5 (patch) | |
tree | 4fd98992014819aaede4a53243ab35324b0f1fea /OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |
parent | As per opensim-dev mailing list discussion, extend llGetDetectedType() to ret... (diff) | |
download | opensim-SC-f9913b6ef7e7f18075e1e42ed5e347ce2a8b8ef5.zip opensim-SC-f9913b6ef7e7f18075e1e42ed5e347ce2a8b8ef5.tar.gz opensim-SC-f9913b6ef7e7f18075e1e42ed5e347ce2a8b8ef5.tar.bz2 opensim-SC-f9913b6ef7e7f18075e1e42ed5e347ce2a8b8ef5.tar.xz |
BulletSim: Add detailed and voluminous debug logging that is enabled
with an ini configuration parameter.
Correct computation of relative offsets of children in a linkset.
Remove a prim from any link relationship before deleting it.
Minor code flow cleanups.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 130f1ca..9b28a06 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -42,6 +42,8 @@ public sealed class BSPrim : PhysicsActor | |||
42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
43 | private static readonly string LogHeader = "[BULLETS PRIM]"; | 43 | private static readonly string LogHeader = "[BULLETS PRIM]"; |
44 | 44 | ||
45 | private void DebugLog(string mm, params Object[] xx) { if (_scene.shouldDebugLog) m_log.DebugFormat(mm, xx); } | ||
46 | |||
45 | private IMesh _mesh; | 47 | private IMesh _mesh; |
46 | private PrimitiveBaseShape _pbs; | 48 | private PrimitiveBaseShape _pbs; |
47 | private ShapeData.PhysicsShapeType _shapeType; | 49 | private ShapeData.PhysicsShapeType _shapeType; |
@@ -86,8 +88,8 @@ public sealed class BSPrim : PhysicsActor | |||
86 | private bool _kinematic; | 88 | private bool _kinematic; |
87 | private float _buoyancy; | 89 | private float _buoyancy; |
88 | 90 | ||
89 | private List<BSPrim> _childrenPrims; | ||
90 | private BSPrim _parentPrim; | 91 | private BSPrim _parentPrim; |
92 | private List<BSPrim> _childrenPrims; | ||
91 | 93 | ||
92 | private int _subscribedEventsMs = 0; | 94 | private int _subscribedEventsMs = 0; |
93 | private int _nextCollisionOkTime = 0; | 95 | private int _nextCollisionOkTime = 0; |
@@ -148,6 +150,15 @@ public sealed class BSPrim : PhysicsActor | |||
148 | // Undo any vehicle properties | 150 | // Undo any vehicle properties |
149 | _vehicle.ProcessTypeChange(Vehicle.TYPE_NONE); | 151 | _vehicle.ProcessTypeChange(Vehicle.TYPE_NONE); |
150 | _scene.RemoveVehiclePrim(this); // just to make sure | 152 | _scene.RemoveVehiclePrim(this); // just to make sure |
153 | |||
154 | // undo any dependance with/on other objects | ||
155 | if (_parentPrim != null) | ||
156 | { | ||
157 | // If I'm someone's child, tell them to forget about me. | ||
158 | _parentPrim.RemoveChildFromLinkset(this); | ||
159 | _parentPrim = null; | ||
160 | } | ||
161 | |||
151 | _scene.TaintedObject(delegate() | 162 | _scene.TaintedObject(delegate() |
152 | { | 163 | { |
153 | // everything in the C# world will get garbage collected. Tell the C++ world to free stuff. | 164 | // everything in the C# world will get garbage collected. Tell the C++ world to free stuff. |
@@ -202,7 +213,7 @@ public sealed class BSPrim : PhysicsActor | |||
202 | // link me to the specified parent | 213 | // link me to the specified parent |
203 | public override void link(PhysicsActor obj) { | 214 | public override void link(PhysicsActor obj) { |
204 | BSPrim parent = obj as BSPrim; | 215 | BSPrim parent = obj as BSPrim; |
205 | // m_log.DebugFormat("{0}: link {1}/{2} to {3}", LogHeader, _avName, _localID, obj.LocalID); | 216 | DebugLog("{0}: link {1}/{2} to {3}", LogHeader, _avName, _localID, obj.LocalID); |
206 | // TODO: decide if this parent checking needs to happen at taint time | 217 | // TODO: decide if this parent checking needs to happen at taint time |
207 | if (_parentPrim == null) | 218 | if (_parentPrim == null) |
208 | { | 219 | { |
@@ -225,7 +236,7 @@ public sealed class BSPrim : PhysicsActor | |||
225 | else | 236 | else |
226 | { | 237 | { |
227 | // asking to reparent a prim should not happen | 238 | // asking to reparent a prim should not happen |
228 | m_log.ErrorFormat("{0}: Reparenting a prim. ", LogHeader); | 239 | m_log.ErrorFormat("{0}: link(): Reparenting a prim. ", LogHeader); |
229 | } | 240 | } |
230 | } | 241 | } |
231 | } | 242 | } |
@@ -236,7 +247,8 @@ public sealed class BSPrim : PhysicsActor | |||
236 | public override void delink() { | 247 | public override void delink() { |
237 | // TODO: decide if this parent checking needs to happen at taint time | 248 | // TODO: decide if this parent checking needs to happen at taint time |
238 | // Race condition here: if link() and delink() in same simulation tick, the delink will not happen | 249 | // Race condition here: if link() and delink() in same simulation tick, the delink will not happen |
239 | // m_log.DebugFormat("{0}: delink {1}/{2}", LogHeader, _avName, _localID); | 250 | DebugLog("{0}: delink {1}/{2}. Parent={3}", LogHeader, _avName, _localID, |
251 | (_parentPrim==null ? "NULL" : _parentPrim._avName+"/"+_parentPrim.LocalID.ToString())); | ||
240 | if (_parentPrim != null) | 252 | if (_parentPrim != null) |
241 | { | 253 | { |
242 | _parentPrim.RemoveChildFromLinkset(this); | 254 | _parentPrim.RemoveChildFromLinkset(this); |
@@ -252,8 +264,9 @@ public sealed class BSPrim : PhysicsActor | |||
252 | { | 264 | { |
253 | if (!_childrenPrims.Contains(child)) | 265 | if (!_childrenPrims.Contains(child)) |
254 | { | 266 | { |
267 | DebugLog("{0}: AddChildToLinkset: adding child {1} to {2}", LogHeader, child.LocalID, this.LocalID); | ||
255 | _childrenPrims.Add(child); | 268 | _childrenPrims.Add(child); |
256 | child.ParentPrim = this; // the child has gained a parent | 269 | child._parentPrim = this; // the child has gained a parent |
257 | RecreateGeomAndObject(); // rebuild my shape with the new child added | 270 | RecreateGeomAndObject(); // rebuild my shape with the new child added |
258 | } | 271 | } |
259 | }); | 272 | }); |
@@ -269,9 +282,13 @@ public sealed class BSPrim : PhysicsActor | |||
269 | { | 282 | { |
270 | if (_childrenPrims.Contains(child)) | 283 | if (_childrenPrims.Contains(child)) |
271 | { | 284 | { |
272 | BulletSimAPI.RemoveConstraint(_scene.WorldID, child.LocalID, this.LocalID); | 285 | DebugLog("{0}: RemoveChildFromLinkset: Removing constraint to {1}", LogHeader, child.LocalID); |
286 | if (!BulletSimAPI.RemoveConstraintByID(_scene.WorldID, child.LocalID)) | ||
287 | { | ||
288 | m_log.ErrorFormat("{0}: RemoveChildFromLinkset: Failed remove constraint for {1}", LogHeader, child.LocalID); | ||
289 | } | ||
273 | _childrenPrims.Remove(child); | 290 | _childrenPrims.Remove(child); |
274 | child.ParentPrim = null; // the child has lost its parent | 291 | child._parentPrim = null; // the child has lost its parent |
275 | RecreateGeomAndObject(); // rebuild my shape with the child removed | 292 | RecreateGeomAndObject(); // rebuild my shape with the child removed |
276 | } | 293 | } |
277 | else | 294 | else |
@@ -282,11 +299,6 @@ public sealed class BSPrim : PhysicsActor | |||
282 | return; | 299 | return; |
283 | } | 300 | } |
284 | 301 | ||
285 | public BSPrim ParentPrim | ||
286 | { | ||
287 | set { _parentPrim = value; } | ||
288 | } | ||
289 | |||
290 | // return true if we are the root of a linkset (there are children to manage) | 302 | // return true if we are the root of a linkset (there are children to manage) |
291 | public bool IsRootOfLinkset | 303 | public bool IsRootOfLinkset |
292 | { | 304 | { |
@@ -981,7 +993,6 @@ public sealed class BSPrim : PhysicsActor | |||
981 | int vi = 0; | 993 | int vi = 0; |
982 | foreach (OMV.Vector3 vv in vertices) | 994 | foreach (OMV.Vector3 vv in vertices) |
983 | { | 995 | { |
984 | // m_log.DebugFormat("{0}: {1}: <{2:0.00}, {3:0.00}, {4:0.00}>", LogHeader, vi / 3, vv.X, vv.Y, vv.Z); | ||
985 | verticesAsFloats[vi++] = vv.X; | 996 | verticesAsFloats[vi++] = vv.X; |
986 | verticesAsFloats[vi++] = vv.Y; | 997 | verticesAsFloats[vi++] = vv.Y; |
987 | verticesAsFloats[vi++] = vv.Z; | 998 | verticesAsFloats[vi++] = vv.Z; |
@@ -1129,7 +1140,6 @@ public sealed class BSPrim : PhysicsActor | |||
1129 | if (IsRootOfLinkset) | 1140 | if (IsRootOfLinkset) |
1130 | { | 1141 | { |
1131 | // Create a linkset around this object | 1142 | // Create a linkset around this object |
1132 | // CreateLinksetWithCompoundHull(); | ||
1133 | CreateLinksetWithConstraints(); | 1143 | CreateLinksetWithConstraints(); |
1134 | } | 1144 | } |
1135 | else | 1145 | else |
@@ -1191,33 +1201,33 @@ public sealed class BSPrim : PhysicsActor | |||
1191 | // TODO: make this more effeicient: a large linkset gets rebuilt over and over and prims are added | 1201 | // TODO: make this more effeicient: a large linkset gets rebuilt over and over and prims are added |
1192 | void CreateLinksetWithConstraints() | 1202 | void CreateLinksetWithConstraints() |
1193 | { | 1203 | { |
1194 | // m_log.DebugFormat("{0}: CreateLinkset. Root prim={1}, prims={2}", LogHeader, LocalID, _childrenPrims.Count+1); | 1204 | DebugLog("{0}: CreateLinkset. Root prim={1}, prims={2}", LogHeader, LocalID, _childrenPrims.Count+1); |
1195 | 1205 | ||
1196 | // remove any constraints that might be in place | 1206 | // remove any constraints that might be in place |
1197 | foreach (BSPrim prim in _childrenPrims) | 1207 | foreach (BSPrim prim in _childrenPrims) |
1198 | { | 1208 | { |
1199 | // m_log.DebugFormat("{0}: CreateLinkset: RemoveConstraint between root prim {1} and child prim {2}", LogHeader, LocalID, prim.LocalID); | 1209 | DebugLog("{0}: CreateLinkset: RemoveConstraint between root prim {1} and child prim {2}", LogHeader, LocalID, prim.LocalID); |
1200 | BulletSimAPI.RemoveConstraint(_scene.WorldID, LocalID, prim.LocalID); | 1210 | BulletSimAPI.RemoveConstraint(_scene.WorldID, LocalID, prim.LocalID); |
1201 | } | 1211 | } |
1202 | // create constraints between the root prim and each of the children | 1212 | // create constraints between the root prim and each of the children |
1203 | foreach (BSPrim prim in _childrenPrims) | 1213 | foreach (BSPrim prim in _childrenPrims) |
1204 | { | 1214 | { |
1205 | // m_log.DebugFormat("{0}: CreateLinkset: AddConstraint between root prim {1} and child prim {2}", LogHeader, LocalID, prim.LocalID); | ||
1206 | |||
1207 | // Zero motion for children so they don't interpolate | 1215 | // Zero motion for children so they don't interpolate |
1208 | prim.ZeroMotion(); | 1216 | prim.ZeroMotion(); |
1209 | 1217 | ||
1210 | // relative position normalized to the root prim | 1218 | // relative position normalized to the root prim |
1211 | OMV.Vector3 childRelativePosition = (prim._position - this._position) * OMV.Quaternion.Inverse(this._orientation); | 1219 | OMV.Quaternion invThisOrientation = OMV.Quaternion.Inverse(this._orientation); |
1220 | OMV.Vector3 childRelativePosition = (prim._position - this._position) * invThisOrientation; | ||
1212 | 1221 | ||
1213 | // relative rotation of the child to the parent | 1222 | // relative rotation of the child to the parent |
1214 | OMV.Quaternion relativeRotation = OMV.Quaternion.Inverse(prim._orientation) * this._orientation; | 1223 | OMV.Quaternion childRelativeRotation = invThisOrientation * prim._orientation; |
1215 | 1224 | ||
1216 | // this is a constraint that allows no freedom of movement between the two objects | 1225 | // this is a constraint that allows no freedom of movement between the two objects |
1217 | // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818 | 1226 | // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818 |
1227 | DebugLog("{0}: CreateLinkset: Adding a constraint between root prim {1} and child prim {2}", LogHeader, LocalID, prim.LocalID); | ||
1218 | BulletSimAPI.AddConstraint(_scene.WorldID, LocalID, prim.LocalID, | 1228 | BulletSimAPI.AddConstraint(_scene.WorldID, LocalID, prim.LocalID, |
1219 | childRelativePosition, | 1229 | childRelativePosition, |
1220 | relativeRotation, | 1230 | childRelativeRotation, |
1221 | OMV.Vector3.Zero, | 1231 | OMV.Vector3.Zero, |
1222 | OMV.Quaternion.Identity, | 1232 | OMV.Quaternion.Identity, |
1223 | OMV.Vector3.Zero, OMV.Vector3.Zero, | 1233 | OMV.Vector3.Zero, OMV.Vector3.Zero, |