diff options
Diffstat (limited to '')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs | 72 |
1 files changed, 56 insertions, 16 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index 8b97ebb..adf4aff 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs | |||
@@ -34,7 +34,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
34 | { | 34 | { |
35 | public sealed class BSLinksetCompound : BSLinkset | 35 | public sealed class BSLinksetCompound : BSLinkset |
36 | { | 36 | { |
37 | // private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]"; | 37 | private static string LogHeader = "[BULLETSIM LINKSET COMPOUND]"; |
38 | 38 | ||
39 | public BSLinksetCompound(BSScene scene, BSPhysObject parent) | 39 | public BSLinksetCompound(BSScene scene, BSPhysObject parent) |
40 | { | 40 | { |
@@ -59,6 +59,12 @@ public sealed class BSLinksetCompound : BSLinkset | |||
59 | // refresh will happen once after all the other taints are applied. | 59 | // refresh will happen once after all the other taints are applied. |
60 | public override void Refresh(BSPhysObject requestor) | 60 | public override void Refresh(BSPhysObject requestor) |
61 | { | 61 | { |
62 | // External request for Refresh (from BSPrim) is not necessary | ||
63 | // InternalRefresh(requestor); | ||
64 | } | ||
65 | |||
66 | private void InternalRefresh(BSPhysObject requestor) | ||
67 | { | ||
62 | DetailLog("{0},BSLinksetCompound.Refresh,schedulingRefresh,requestor={1}", LinksetRoot.LocalID, requestor.LocalID); | 68 | DetailLog("{0},BSLinksetCompound.Refresh,schedulingRefresh,requestor={1}", LinksetRoot.LocalID, requestor.LocalID); |
63 | // Queue to happen after all the other taint processing | 69 | // Queue to happen after all the other taint processing |
64 | PhysicsScene.PostTaintObject("BSLinksetCompound.Refresh", requestor.LocalID, delegate() | 70 | PhysicsScene.PostTaintObject("BSLinksetCompound.Refresh", requestor.LocalID, delegate() |
@@ -135,13 +141,13 @@ public sealed class BSLinksetCompound : BSLinkset | |||
135 | { | 141 | { |
136 | bool ret = false; | 142 | bool ret = false; |
137 | 143 | ||
138 | DetailLog("{0},BSLinksetCompound.RemoveBodyDependencies,removeChildrenForRoot,rID={1},rBody={2},isRoot={3}", | 144 | DetailLog("{0},BSLinksetCompound.RemoveBodyDependencies,refreshIfChild,rID={1},rBody={2},isRoot={3}", |
139 | child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"), IsRoot(child)); | 145 | child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"), IsRoot(child)); |
140 | 146 | ||
141 | if (!IsRoot(child)) | 147 | if (!IsRoot(child)) |
142 | { | 148 | { |
143 | // Cause the current shape to be freed and the new one to be built. | 149 | // Cause the current shape to be freed and the new one to be built. |
144 | Refresh(LinksetRoot); | 150 | InternalRefresh(LinksetRoot); |
145 | ret = true; | 151 | ret = true; |
146 | } | 152 | } |
147 | 153 | ||
@@ -169,7 +175,7 @@ public sealed class BSLinksetCompound : BSLinkset | |||
169 | DetailLog("{0},BSLinksetCompound.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID); | 175 | DetailLog("{0},BSLinksetCompound.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID); |
170 | 176 | ||
171 | // Cause constraints and assorted properties to be recomputed before the next simulation step. | 177 | // Cause constraints and assorted properties to be recomputed before the next simulation step. |
172 | Refresh(LinksetRoot); | 178 | InternalRefresh(LinksetRoot); |
173 | } | 179 | } |
174 | return; | 180 | return; |
175 | } | 181 | } |
@@ -196,34 +202,68 @@ public sealed class BSLinksetCompound : BSLinkset | |||
196 | else | 202 | else |
197 | { | 203 | { |
198 | // Schedule a rebuild of the linkset before the next simulation tick. | 204 | // Schedule a rebuild of the linkset before the next simulation tick. |
199 | Refresh(LinksetRoot); | 205 | InternalRefresh(LinksetRoot); |
200 | } | 206 | } |
201 | } | 207 | } |
202 | return; | 208 | return; |
203 | } | 209 | } |
204 | 210 | ||
205 | 211 | // Called before the simulation step to make sure the compound based linkset | |
206 | // Call each of the constraints that make up this linkset and recompute the | ||
207 | // various transforms and variables. Create constraints of not created yet. | ||
208 | // Called before the simulation step to make sure the constraint based linkset | ||
209 | // is all initialized. | 212 | // is all initialized. |
213 | // Constraint linksets are rebuilt every time. | ||
214 | // Note that this works for rebuilding just the root after a linkset is taken apart. | ||
210 | // Called at taint time!! | 215 | // Called at taint time!! |
211 | private void RecomputeLinksetCompound() | 216 | private void RecomputeLinksetCompound() |
212 | { | 217 | { |
213 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,start,rBody={1},numChildren={2}", | 218 | // Cause the root shape to be rebuilt as a compound object with just the root in it |
214 | LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"), NumberOfChildren); | ||
215 | |||
216 | LinksetRoot.ForceBodyShapeRebuild(true); | 219 | LinksetRoot.ForceBodyShapeRebuild(true); |
217 | 220 | ||
221 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,start,rBody={1},rShape={2},numChildren={3}", | ||
222 | LinksetRoot.LocalID, LinksetRoot.PhysBody, LinksetRoot.PhysShape, NumberOfChildren); | ||
223 | |||
224 | ForEachMember(delegate(BSPhysObject cPrim) | ||
225 | { | ||
226 | if (!IsRoot(cPrim)) | ||
227 | { | ||
228 | OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(LinksetRoot.RawOrientation); | ||
229 | OMV.Vector3 displacementPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation; | ||
230 | OMV.Quaternion displacementRot = cPrim.RawOrientation * invRootOrientation; | ||
231 | |||
232 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addMemberToShape,mID={1},mShape={2},dispPos={3},dispRot={4}", | ||
233 | LinksetRoot.LocalID, cPrim.LocalID, cPrim.PhysShape, displacementPos, displacementRot); | ||
234 | |||
235 | if (cPrim.PhysShape.isNativeShape) | ||
236 | { | ||
237 | // Native shapes are not shared so we need to create a new one. | ||
238 | // A mesh or hull is created because scale is not available on a native shape. | ||
239 | // (TODO: Bullet does have a btScaledCollisionShape. Can that be used?) | ||
240 | BulletShape saveShape = cPrim.PhysShape; | ||
241 | PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null); | ||
242 | BulletShape newShape = cPrim.PhysShape; | ||
243 | cPrim.PhysShape = saveShape; | ||
244 | BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, newShape.ptr, displacementPos, displacementRot); | ||
245 | } | ||
246 | else | ||
247 | { | ||
248 | // For the shared shapes (meshes and hulls) just use the shape in the child | ||
249 | if (PhysicsScene.Shapes.ReferenceShape(cPrim.PhysShape)) | ||
250 | { | ||
251 | PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}", | ||
252 | LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape); | ||
253 | } | ||
254 | BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, displacementPos, displacementRot); | ||
255 | } | ||
256 | } | ||
257 | return false; | ||
258 | }); | ||
259 | |||
260 | |||
218 | float linksetMass = LinksetMass; | 261 | float linksetMass = LinksetMass; |
219 | LinksetRoot.UpdatePhysicalMassProperties(linksetMass); | 262 | LinksetRoot.UpdatePhysicalMassProperties(linksetMass); |
220 | 263 | ||
221 | // DEBUG: see of inter-linkset collisions are causing problems | 264 | // DEBUG: see of inter-linkset collisions are causing problems |
222 | // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr, | 265 | // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr, |
223 | // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask); | 266 | // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask); |
224 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,end,rBody={1},linksetMass={2}", | ||
225 | LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"), linksetMass); | ||
226 | |||
227 | 267 | ||
228 | } | 268 | } |
229 | } | 269 | } |