diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index a77dee9..d6e2fe9 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | |||
@@ -126,6 +126,11 @@ public sealed class BSShapeCollection : IDisposable | |||
126 | return ret; | 126 | return ret; |
127 | } | 127 | } |
128 | 128 | ||
129 | public bool GetBodyAndShape(bool forceRebuild, BulletSim sim, BSPhysObject prim) | ||
130 | { | ||
131 | return GetBodyAndShape(forceRebuild, sim, prim, null, null); | ||
132 | } | ||
133 | |||
129 | // Track another user of a body. | 134 | // Track another user of a body. |
130 | // We presume the caller has allocated the body. | 135 | // We presume the caller has allocated the body. |
131 | // Bodies only have one user so the body is just put into the world if not already there. | 136 | // Bodies only have one user so the body is just put into the world if not already there. |
@@ -149,7 +154,7 @@ public sealed class BSShapeCollection : IDisposable | |||
149 | // Called when releasing use of a BSBody. BSShape is handled separately. | 154 | // Called when releasing use of a BSBody. BSShape is handled separately. |
150 | public void DereferenceBody(BulletBody body, bool inTaintTime, BodyDestructionCallback bodyCallback ) | 155 | public void DereferenceBody(BulletBody body, bool inTaintTime, BodyDestructionCallback bodyCallback ) |
151 | { | 156 | { |
152 | if (body.ptr == IntPtr.Zero) | 157 | if (!body.HasPhysicalBody) |
153 | return; | 158 | return; |
154 | 159 | ||
155 | lock (m_collectionActivityLock) | 160 | lock (m_collectionActivityLock) |
@@ -243,12 +248,12 @@ public sealed class BSShapeCollection : IDisposable | |||
243 | // Release the usage of a shape. | 248 | // Release the usage of a shape. |
244 | public void DereferenceShape(BulletShape shape, bool inTaintTime, ShapeDestructionCallback shapeCallback) | 249 | public void DereferenceShape(BulletShape shape, bool inTaintTime, ShapeDestructionCallback shapeCallback) |
245 | { | 250 | { |
246 | if (shape.ptr == IntPtr.Zero) | 251 | if (!shape.HasPhysicalShape) |
247 | return; | 252 | return; |
248 | 253 | ||
249 | PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceShape", delegate() | 254 | PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceShape", delegate() |
250 | { | 255 | { |
251 | if (shape.ptr != IntPtr.Zero) | 256 | if (shape.HasPhysicalShape) |
252 | { | 257 | { |
253 | if (shape.isNativeShape) | 258 | if (shape.isNativeShape) |
254 | { | 259 | { |
@@ -440,7 +445,7 @@ public sealed class BSShapeCollection : IDisposable | |||
440 | } | 445 | } |
441 | 446 | ||
442 | // Create a mesh/hull shape or a native shape if 'nativeShapePossible' is 'true'. | 447 | // Create a mesh/hull shape or a native shape if 'nativeShapePossible' is 'true'. |
443 | private bool CreateGeomNonSpecial(bool forceRebuild, BSPhysObject prim, ShapeDestructionCallback shapeCallback) | 448 | public bool CreateGeomNonSpecial(bool forceRebuild, BSPhysObject prim, ShapeDestructionCallback shapeCallback) |
444 | { | 449 | { |
445 | bool ret = false; | 450 | bool ret = false; |
446 | bool haveShape = false; | 451 | bool haveShape = false; |
@@ -460,6 +465,11 @@ public sealed class BSShapeCollection : IDisposable | |||
460 | && pbs.PathScaleX == 100 && pbs.PathScaleY == 100 | 465 | && pbs.PathScaleX == 100 && pbs.PathScaleY == 100 |
461 | && pbs.PathShearX == 0 && pbs.PathShearY == 0) ) ) | 466 | && pbs.PathShearX == 0 && pbs.PathShearY == 0) ) ) |
462 | { | 467 | { |
468 | // Get the scale of any existing shape so we can see if the new shape is same native type and same size. | ||
469 | OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero; | ||
470 | if (prim.PhysShape.HasPhysicalShape) | ||
471 | scaleOfExistingShape = BulletSimAPI.GetLocalScaling2(prim.PhysShape.ptr); | ||
472 | |||
463 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}", | 473 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}", |
464 | prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.type); | 474 | prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.type); |
465 | 475 | ||
@@ -469,7 +479,7 @@ public sealed class BSShapeCollection : IDisposable | |||
469 | { | 479 | { |
470 | haveShape = true; | 480 | haveShape = true; |
471 | if (forceRebuild | 481 | if (forceRebuild |
472 | || prim.Scale != prim.Size | 482 | || prim.Scale != scaleOfExistingShape |
473 | || prim.PhysShape.type != BSPhysicsShapeType.SHAPE_SPHERE | 483 | || prim.PhysShape.type != BSPhysicsShapeType.SHAPE_SPHERE |
474 | ) | 484 | ) |
475 | { | 485 | { |
@@ -483,7 +493,7 @@ public sealed class BSShapeCollection : IDisposable | |||
483 | { | 493 | { |
484 | haveShape = true; | 494 | haveShape = true; |
485 | if (forceRebuild | 495 | if (forceRebuild |
486 | || prim.Scale != prim.Size | 496 | || prim.Scale != scaleOfExistingShape |
487 | || prim.PhysShape.type != BSPhysicsShapeType.SHAPE_BOX | 497 | || prim.PhysShape.type != BSPhysicsShapeType.SHAPE_BOX |
488 | ) | 498 | ) |
489 | { | 499 | { |
@@ -542,7 +552,6 @@ public sealed class BSShapeCollection : IDisposable | |||
542 | prim.LocalID, newShape, prim.Scale); | 552 | prim.LocalID, newShape, prim.Scale); |
543 | 553 | ||
544 | // native shapes are scaled by Bullet | 554 | // native shapes are scaled by Bullet |
545 | prim.Scale = prim.Size; | ||
546 | prim.PhysShape = newShape; | 555 | prim.PhysShape = newShape; |
547 | return true; | 556 | return true; |
548 | } | 557 | } |
@@ -555,8 +564,8 @@ public sealed class BSShapeCollection : IDisposable | |||
555 | ShapeData nativeShapeData = new ShapeData(); | 564 | ShapeData nativeShapeData = new ShapeData(); |
556 | nativeShapeData.Type = shapeType; | 565 | nativeShapeData.Type = shapeType; |
557 | nativeShapeData.ID = prim.LocalID; | 566 | nativeShapeData.ID = prim.LocalID; |
558 | nativeShapeData.Scale = prim.Size; | 567 | nativeShapeData.Scale = prim.Scale; |
559 | nativeShapeData.Size = prim.Size; // unneeded, I think. | 568 | nativeShapeData.Size = prim.Scale; // unneeded, I think. |
560 | nativeShapeData.MeshKey = (ulong)shapeKey; | 569 | nativeShapeData.MeshKey = (ulong)shapeKey; |
561 | nativeShapeData.HullKey = (ulong)shapeKey; | 570 | nativeShapeData.HullKey = (ulong)shapeKey; |
562 | 571 | ||
@@ -573,7 +582,7 @@ public sealed class BSShapeCollection : IDisposable | |||
573 | // Native shapes are scaled in Bullet so set the scaling to the size | 582 | // Native shapes are scaled in Bullet so set the scaling to the size |
574 | newShape = new BulletShape(BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, nativeShapeData), shapeType); | 583 | newShape = new BulletShape(BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, nativeShapeData), shapeType); |
575 | } | 584 | } |
576 | if (newShape.ptr == IntPtr.Zero) | 585 | if (!newShape.HasPhysicalShape) |
577 | { | 586 | { |
578 | PhysicsScene.Logger.ErrorFormat("{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}", | 587 | PhysicsScene.Logger.ErrorFormat("{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}", |
579 | LogHeader, prim.LocalID, shapeType); | 588 | LogHeader, prim.LocalID, shapeType); |
@@ -590,7 +599,7 @@ public sealed class BSShapeCollection : IDisposable | |||
590 | // Called at taint-time! | 599 | // Called at taint-time! |
591 | private bool GetReferenceToMesh(BSPhysObject prim, ShapeDestructionCallback shapeCallback) | 600 | private bool GetReferenceToMesh(BSPhysObject prim, ShapeDestructionCallback shapeCallback) |
592 | { | 601 | { |
593 | BulletShape newShape = new BulletShape(IntPtr.Zero); | 602 | BulletShape newShape = new BulletShape(); |
594 | 603 | ||
595 | float lod; | 604 | float lod; |
596 | System.UInt64 newMeshKey = ComputeShapeKey(prim.Size, prim.BaseShape, out lod); | 605 | System.UInt64 newMeshKey = ComputeShapeKey(prim.Size, prim.BaseShape, out lod); |
@@ -611,8 +620,6 @@ public sealed class BSShapeCollection : IDisposable | |||
611 | 620 | ||
612 | ReferenceShape(newShape); | 621 | ReferenceShape(newShape); |
613 | 622 | ||
614 | // meshes are already scaled by the meshmerizer | ||
615 | prim.Scale = new OMV.Vector3(1f, 1f, 1f); | ||
616 | prim.PhysShape = newShape; | 623 | prim.PhysShape = newShape; |
617 | 624 | ||
618 | return true; // 'true' means a new shape has been added to this prim | 625 | return true; // 'true' means a new shape has been added to this prim |
@@ -683,8 +690,6 @@ public sealed class BSShapeCollection : IDisposable | |||
683 | 690 | ||
684 | ReferenceShape(newShape); | 691 | ReferenceShape(newShape); |
685 | 692 | ||
686 | // hulls are already scaled by the meshmerizer | ||
687 | prim.Scale = new OMV.Vector3(1f, 1f, 1f); | ||
688 | prim.PhysShape = newShape; | 693 | prim.PhysShape = newShape; |
689 | return true; // 'true' means a new shape has been added to this prim | 694 | return true; // 'true' means a new shape has been added to this prim |
690 | } | 695 | } |
@@ -793,7 +798,7 @@ public sealed class BSShapeCollection : IDisposable | |||
793 | BulletShape newShape = new BulletShape(hullPtr, BSPhysicsShapeType.SHAPE_HULL); | 798 | BulletShape newShape = new BulletShape(hullPtr, BSPhysicsShapeType.SHAPE_HULL); |
794 | newShape.shapeKey = newHullKey; | 799 | newShape.shapeKey = newHullKey; |
795 | 800 | ||
796 | return newShape; // 'true' means a new shape has been added to this prim | 801 | return newShape; |
797 | } | 802 | } |
798 | 803 | ||
799 | // Callback from convex hull creater with a newly created hull. | 804 | // Callback from convex hull creater with a newly created hull. |
@@ -860,7 +865,7 @@ public sealed class BSShapeCollection : IDisposable | |||
860 | private BulletShape VerifyMeshCreated(BulletShape newShape, BSPhysObject prim) | 865 | private BulletShape VerifyMeshCreated(BulletShape newShape, BSPhysObject prim) |
861 | { | 866 | { |
862 | // If the shape was successfully created, nothing more to do | 867 | // If the shape was successfully created, nothing more to do |
863 | if (newShape.ptr != IntPtr.Zero) | 868 | if (newShape.HasPhysicalShape) |
864 | return newShape; | 869 | return newShape; |
865 | 870 | ||
866 | // If this mesh has an underlying asset and we have not failed getting it before, fetch the asset | 871 | // If this mesh has an underlying asset and we have not failed getting it before, fetch the asset |
@@ -919,7 +924,7 @@ public sealed class BSShapeCollection : IDisposable | |||
919 | bool ret = false; | 924 | bool ret = false; |
920 | 925 | ||
921 | // the mesh, hull or native shape must have already been created in Bullet | 926 | // the mesh, hull or native shape must have already been created in Bullet |
922 | bool mustRebuild = (prim.PhysBody.ptr == IntPtr.Zero); | 927 | bool mustRebuild = !prim.PhysBody.HasPhysicalBody; |
923 | 928 | ||
924 | // If there is an existing body, verify it's of an acceptable type. | 929 | // If there is an existing body, verify it's of an acceptable type. |
925 | // If not a solid object, body is a GhostObject. Otherwise a RigidBody. | 930 | // If not a solid object, body is a GhostObject. Otherwise a RigidBody. |