diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin')
37 files changed, 6560 insertions, 3294 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs index 77ea3ed..3bd81d4 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | |||
@@ -75,11 +75,11 @@ private sealed class BulletBodyUnman : BulletBody | |||
75 | private sealed class BulletShapeUnman : BulletShape | 75 | private sealed class BulletShapeUnman : BulletShape |
76 | { | 76 | { |
77 | public IntPtr ptr; | 77 | public IntPtr ptr; |
78 | public BulletShapeUnman(IntPtr xx, BSPhysicsShapeType typ) | 78 | public BulletShapeUnman(IntPtr xx, BSPhysicsShapeType typ) |
79 | : base() | 79 | : base() |
80 | { | 80 | { |
81 | ptr = xx; | 81 | ptr = xx; |
82 | type = typ; | 82 | shapeType = typ; |
83 | } | 83 | } |
84 | public override bool HasPhysicalShape | 84 | public override bool HasPhysicalShape |
85 | { | 85 | { |
@@ -91,7 +91,7 @@ private sealed class BulletShapeUnman : BulletShape | |||
91 | } | 91 | } |
92 | public override BulletShape Clone() | 92 | public override BulletShape Clone() |
93 | { | 93 | { |
94 | return new BulletShapeUnman(ptr, type); | 94 | return new BulletShapeUnman(ptr, shapeType); |
95 | } | 95 | } |
96 | public override bool ReferenceSame(BulletShape other) | 96 | public override bool ReferenceSame(BulletShape other) |
97 | { | 97 | { |
@@ -251,23 +251,52 @@ public override BulletShape CreateMeshShape(BulletWorld world, | |||
251 | BSPhysicsShapeType.SHAPE_MESH); | 251 | BSPhysicsShapeType.SHAPE_MESH); |
252 | } | 252 | } |
253 | 253 | ||
254 | public override BulletShape CreateGImpactShape(BulletWorld world, | ||
255 | int indicesCount, int[] indices, | ||
256 | int verticesCount, float[] vertices) | ||
257 | { | ||
258 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
259 | return new BulletShapeUnman( | ||
260 | BSAPICPP.CreateGImpactShape2(worldu.ptr, indicesCount, indices, verticesCount, vertices), | ||
261 | BSPhysicsShapeType.SHAPE_GIMPACT); | ||
262 | } | ||
263 | |||
254 | public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls) | 264 | public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls) |
255 | { | 265 | { |
256 | BulletWorldUnman worldu = world as BulletWorldUnman; | 266 | BulletWorldUnman worldu = world as BulletWorldUnman; |
257 | return new BulletShapeUnman( | 267 | return new BulletShapeUnman( |
258 | BSAPICPP.CreateHullShape2(worldu.ptr, hullCount, hulls), | 268 | BSAPICPP.CreateHullShape2(worldu.ptr, hullCount, hulls), |
259 | BSPhysicsShapeType.SHAPE_HULL); | 269 | BSPhysicsShapeType.SHAPE_HULL); |
260 | } | 270 | } |
261 | 271 | ||
262 | public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape) | 272 | public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape, HACDParams parms) |
263 | { | 273 | { |
264 | BulletWorldUnman worldu = world as BulletWorldUnman; | 274 | BulletWorldUnman worldu = world as BulletWorldUnman; |
265 | BulletShapeUnman shapeu = meshShape as BulletShapeUnman; | 275 | BulletShapeUnman shapeu = meshShape as BulletShapeUnman; |
266 | return new BulletShapeUnman( | 276 | return new BulletShapeUnman( |
267 | BSAPICPP.BuildHullShapeFromMesh2(worldu.ptr, shapeu.ptr), | 277 | BSAPICPP.BuildHullShapeFromMesh2(worldu.ptr, shapeu.ptr, parms), |
268 | BSPhysicsShapeType.SHAPE_HULL); | 278 | BSPhysicsShapeType.SHAPE_HULL); |
269 | } | 279 | } |
270 | 280 | ||
281 | public override BulletShape BuildConvexHullShapeFromMesh(BulletWorld world, BulletShape meshShape) | ||
282 | { | ||
283 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
284 | BulletShapeUnman shapeu = meshShape as BulletShapeUnman; | ||
285 | return new BulletShapeUnman( | ||
286 | BSAPICPP.BuildConvexHullShapeFromMesh2(worldu.ptr, shapeu.ptr), | ||
287 | BSPhysicsShapeType.SHAPE_CONVEXHULL); | ||
288 | } | ||
289 | |||
290 | public override BulletShape CreateConvexHullShape(BulletWorld world, | ||
291 | int indicesCount, int[] indices, | ||
292 | int verticesCount, float[] vertices) | ||
293 | { | ||
294 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
295 | return new BulletShapeUnman( | ||
296 | BSAPICPP.CreateConvexHullShape2(worldu.ptr, indicesCount, indices, verticesCount, vertices), | ||
297 | BSPhysicsShapeType.SHAPE_CONVEXHULL); | ||
298 | } | ||
299 | |||
271 | public override BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData) | 300 | public override BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData) |
272 | { | 301 | { |
273 | BulletWorldUnman worldu = world as BulletWorldUnman; | 302 | BulletWorldUnman worldu = world as BulletWorldUnman; |
@@ -356,7 +385,7 @@ public override BulletShape DuplicateCollisionShape(BulletWorld world, BulletSha | |||
356 | { | 385 | { |
357 | BulletWorldUnman worldu = world as BulletWorldUnman; | 386 | BulletWorldUnman worldu = world as BulletWorldUnman; |
358 | BulletShapeUnman srcShapeu = srcShape as BulletShapeUnman; | 387 | BulletShapeUnman srcShapeu = srcShape as BulletShapeUnman; |
359 | return new BulletShapeUnman(BSAPICPP.DuplicateCollisionShape2(worldu.ptr, srcShapeu.ptr, id), srcShape.type); | 388 | return new BulletShapeUnman(BSAPICPP.DuplicateCollisionShape2(worldu.ptr, srcShapeu.ptr, id), srcShape.shapeType); |
360 | } | 389 | } |
361 | 390 | ||
362 | public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape) | 391 | public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape) |
@@ -567,6 +596,60 @@ public override bool SetBreakingImpulseThreshold(BulletConstraint constrain, flo | |||
567 | return BSAPICPP.SetBreakingImpulseThreshold2(constrainu.ptr, threshold); | 596 | return BSAPICPP.SetBreakingImpulseThreshold2(constrainu.ptr, threshold); |
568 | } | 597 | } |
569 | 598 | ||
599 | public override bool HingeSetLimits(BulletConstraint constrain, float low, float high, float softness, float bias, float relaxation) | ||
600 | { | ||
601 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
602 | return BSAPICPP.HingeSetLimits2(constrainu.ptr, low, high, softness, bias, relaxation); | ||
603 | } | ||
604 | |||
605 | public override bool SpringEnable(BulletConstraint constrain, int index, float numericTrueFalse) | ||
606 | { | ||
607 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
608 | return BSAPICPP.ConstraintSpringEnable2(constrainu.ptr, index, numericTrueFalse); | ||
609 | } | ||
610 | |||
611 | public override bool SpringSetEquilibriumPoint(BulletConstraint constrain, int index, float equilibriumPoint) | ||
612 | { | ||
613 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
614 | return BSAPICPP.ConstraintSpringSetEquilibriumPoint2(constrainu.ptr, index, equilibriumPoint); | ||
615 | } | ||
616 | |||
617 | public override bool SpringSetStiffness(BulletConstraint constrain, int index, float stiffnesss) | ||
618 | { | ||
619 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
620 | return BSAPICPP.ConstraintSpringSetStiffness2(constrainu.ptr, index, stiffnesss); | ||
621 | } | ||
622 | |||
623 | public override bool SpringSetDamping(BulletConstraint constrain, int index, float damping) | ||
624 | { | ||
625 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
626 | return BSAPICPP.ConstraintSpringSetDamping2(constrainu.ptr, index, damping); | ||
627 | } | ||
628 | |||
629 | public override bool SliderSetLimits(BulletConstraint constrain, int lowerUpper, int linAng, float val) | ||
630 | { | ||
631 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
632 | return BSAPICPP.SliderSetLimits2(constrainu.ptr, lowerUpper, linAng, val); | ||
633 | } | ||
634 | |||
635 | public override bool SliderSet(BulletConstraint constrain, int softRestDamp, int dirLimOrtho, int linAng, float val) | ||
636 | { | ||
637 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
638 | return BSAPICPP.SliderSet2(constrainu.ptr, softRestDamp, dirLimOrtho, linAng, val); | ||
639 | } | ||
640 | |||
641 | public override bool SliderMotorEnable(BulletConstraint constrain, int linAng, float numericTrueFalse) | ||
642 | { | ||
643 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
644 | return BSAPICPP.SliderMotorEnable2(constrainu.ptr, linAng, numericTrueFalse); | ||
645 | } | ||
646 | |||
647 | public override bool SliderMotor(BulletConstraint constrain, int forceVel, int linAng, float val) | ||
648 | { | ||
649 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | ||
650 | return BSAPICPP.SliderMotor2(constrainu.ptr, forceVel, linAng, val); | ||
651 | } | ||
652 | |||
570 | public override bool CalculateTransforms(BulletConstraint constrain) | 653 | public override bool CalculateTransforms(BulletConstraint constrain) |
571 | { | 654 | { |
572 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; | 655 | BulletConstraintUnman constrainu = constrain as BulletConstraintUnman; |
@@ -642,6 +725,13 @@ public override bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj) | |||
642 | return BSAPICPP.RemoveObjectFromWorld2(worldu.ptr, bodyu.ptr); | 725 | return BSAPICPP.RemoveObjectFromWorld2(worldu.ptr, bodyu.ptr); |
643 | } | 726 | } |
644 | 727 | ||
728 | public override bool ClearCollisionProxyCache(BulletWorld world, BulletBody obj) | ||
729 | { | ||
730 | BulletWorldUnman worldu = world as BulletWorldUnman; | ||
731 | BulletBodyUnman bodyu = obj as BulletBodyUnman; | ||
732 | return BSAPICPP.ClearCollisionProxyCache2(worldu.ptr, bodyu.ptr); | ||
733 | } | ||
734 | |||
645 | public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects) | 735 | public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects) |
646 | { | 736 | { |
647 | BulletWorldUnman worldu = world as BulletWorldUnman; | 737 | BulletWorldUnman worldu = world as BulletWorldUnman; |
@@ -1407,11 +1497,24 @@ public static extern IntPtr CreateMeshShape2(IntPtr world, | |||
1407 | int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices ); | 1497 | int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices ); |
1408 | 1498 | ||
1409 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 1499 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
1500 | public static extern IntPtr CreateGImpactShape2(IntPtr world, | ||
1501 | int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices, | ||
1502 | int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices ); | ||
1503 | |||
1504 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1410 | public static extern IntPtr CreateHullShape2(IntPtr world, | 1505 | public static extern IntPtr CreateHullShape2(IntPtr world, |
1411 | int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls); | 1506 | int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls); |
1412 | 1507 | ||
1413 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 1508 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
1414 | public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape); | 1509 | public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape, HACDParams parms); |
1510 | |||
1511 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1512 | public static extern IntPtr BuildConvexHullShapeFromMesh2(IntPtr world, IntPtr meshShape); | ||
1513 | |||
1514 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1515 | public static extern IntPtr CreateConvexHullShape2(IntPtr world, | ||
1516 | int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices, | ||
1517 | int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices ); | ||
1415 | 1518 | ||
1416 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 1519 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
1417 | public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData); | 1520 | public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData); |
@@ -1476,7 +1579,7 @@ public static extern void DestroyObject2(IntPtr sim, IntPtr obj); | |||
1476 | public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin); | 1579 | public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin); |
1477 | 1580 | ||
1478 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 1581 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
1479 | public static extern IntPtr CreateTerrainShape2(uint id, Vector3 size, float minHeight, float maxHeight, | 1582 | public static extern IntPtr CreateTerrainShape2(uint id, Vector3 size, float minHeight, float maxHeight, |
1480 | [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, | 1583 | [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, |
1481 | float scaleFactor, float collisionMargin); | 1584 | float scaleFactor, float collisionMargin); |
1482 | 1585 | ||
@@ -1559,6 +1662,33 @@ public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enabl | |||
1559 | public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold); | 1662 | public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold); |
1560 | 1663 | ||
1561 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 1664 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
1665 | public static extern bool HingeSetLimits2(IntPtr constrain, float low, float high, float softness, float bias, float relaxation); | ||
1666 | |||
1667 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1668 | public static extern bool ConstraintSpringEnable2(IntPtr constrain, int index, float numericTrueFalse); | ||
1669 | |||
1670 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1671 | public static extern bool ConstraintSpringSetEquilibriumPoint2(IntPtr constrain, int index, float equilibriumPoint); | ||
1672 | |||
1673 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1674 | public static extern bool ConstraintSpringSetStiffness2(IntPtr constrain, int index, float stiffness); | ||
1675 | |||
1676 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1677 | public static extern bool ConstraintSpringSetDamping2(IntPtr constrain, int index, float damping); | ||
1678 | |||
1679 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1680 | public static extern bool SliderSetLimits2(IntPtr constrain, int lowerUpper, int linAng, float val); | ||
1681 | |||
1682 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1683 | public static extern bool SliderSet2(IntPtr constrain, int softRestDamp, int dirLimOrtho, int linAng, float val); | ||
1684 | |||
1685 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1686 | public static extern bool SliderMotorEnable2(IntPtr constrain, int linAng, float numericTrueFalse); | ||
1687 | |||
1688 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1689 | public static extern bool SliderMotor2(IntPtr constrain, int forceVel, int linAng, float val); | ||
1690 | |||
1691 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1562 | public static extern bool CalculateTransforms2(IntPtr constrain); | 1692 | public static extern bool CalculateTransforms2(IntPtr constrain); |
1563 | 1693 | ||
1564 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 1694 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
@@ -1590,6 +1720,9 @@ public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj); | |||
1590 | public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj); | 1720 | public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj); |
1591 | 1721 | ||
1592 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 1722 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
1723 | public static extern bool ClearCollisionProxyCache2(IntPtr world, IntPtr obj); | ||
1724 | |||
1725 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
1593 | public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects); | 1726 | public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects); |
1594 | 1727 | ||
1595 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 1728 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs index 6fc10e9..17ebed2 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | |||
@@ -81,11 +81,11 @@ private sealed class BulletBodyXNA : BulletBody | |||
81 | private sealed class BulletShapeXNA : BulletShape | 81 | private sealed class BulletShapeXNA : BulletShape |
82 | { | 82 | { |
83 | public CollisionShape shape; | 83 | public CollisionShape shape; |
84 | public BulletShapeXNA(CollisionShape xx, BSPhysicsShapeType typ) | 84 | public BulletShapeXNA(CollisionShape xx, BSPhysicsShapeType typ) |
85 | : base() | 85 | : base() |
86 | { | 86 | { |
87 | shape = xx; | 87 | shape = xx; |
88 | type = typ; | 88 | shapeType = typ; |
89 | } | 89 | } |
90 | public override bool HasPhysicalShape | 90 | public override bool HasPhysicalShape |
91 | { | 91 | { |
@@ -97,7 +97,7 @@ private sealed class BulletShapeXNA : BulletShape | |||
97 | } | 97 | } |
98 | public override BulletShape Clone() | 98 | public override BulletShape Clone() |
99 | { | 99 | { |
100 | return new BulletShapeXNA(shape, type); | 100 | return new BulletShapeXNA(shape, shapeType); |
101 | } | 101 | } |
102 | public override bool ReferenceSame(BulletShape other) | 102 | public override bool ReferenceSame(BulletShape other) |
103 | { | 103 | { |
@@ -137,8 +137,8 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
137 | internal int LastEntityProperty = 0; | 137 | internal int LastEntityProperty = 0; |
138 | 138 | ||
139 | internal EntityProperties[] UpdatedObjects; | 139 | internal EntityProperties[] UpdatedObjects; |
140 | internal Dictionary<uint, GhostObject> specialCollisionObjects; | 140 | internal Dictionary<uint, GhostObject> specialCollisionObjects; |
141 | 141 | ||
142 | private static int m_collisionsThisFrame; | 142 | private static int m_collisionsThisFrame; |
143 | private BSScene PhysicsScene { get; set; } | 143 | private BSScene PhysicsScene { get; set; } |
144 | 144 | ||
@@ -151,7 +151,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
151 | } | 151 | } |
152 | 152 | ||
153 | /// <summary> | 153 | /// <summary> |
154 | /// | 154 | /// |
155 | /// </summary> | 155 | /// </summary> |
156 | /// <param name="p"></param> | 156 | /// <param name="p"></param> |
157 | /// <param name="p_2"></param> | 157 | /// <param name="p_2"></param> |
@@ -169,12 +169,25 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
169 | return true; | 169 | return true; |
170 | } | 170 | } |
171 | 171 | ||
172 | public override bool ClearCollisionProxyCache(BulletWorld pWorld, BulletBody pBody) | ||
173 | { | ||
174 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
175 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | ||
176 | CollisionObject collisionObject = ((BulletBodyXNA)pBody).body; | ||
177 | if (body != null && collisionObject != null && collisionObject.GetBroadphaseHandle() != null) | ||
178 | { | ||
179 | world.RemoveCollisionObject(collisionObject); | ||
180 | world.AddCollisionObject(collisionObject); | ||
181 | } | ||
182 | return true; | ||
183 | } | ||
184 | |||
172 | public override bool AddConstraintToWorld(BulletWorld pWorld, BulletConstraint pConstraint, bool pDisableCollisionsBetweenLinkedObjects) | 185 | public override bool AddConstraintToWorld(BulletWorld pWorld, BulletConstraint pConstraint, bool pDisableCollisionsBetweenLinkedObjects) |
173 | { | 186 | { |
174 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | 187 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
175 | TypedConstraint constraint = (pConstraint as BulletConstraintXNA).constrain; | 188 | TypedConstraint constraint = (pConstraint as BulletConstraintXNA).constrain; |
176 | world.AddConstraint(constraint, pDisableCollisionsBetweenLinkedObjects); | 189 | world.AddConstraint(constraint, pDisableCollisionsBetweenLinkedObjects); |
177 | 190 | ||
178 | return true; | 191 | return true; |
179 | 192 | ||
180 | } | 193 | } |
@@ -300,7 +313,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
300 | public override bool GetForceUpdateAllAabbs(BulletWorld pWorld) { | 313 | public override bool GetForceUpdateAllAabbs(BulletWorld pWorld) { |
301 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | 314 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
302 | return world.GetForceUpdateAllAabbs(); | 315 | return world.GetForceUpdateAllAabbs(); |
303 | 316 | ||
304 | } | 317 | } |
305 | public override void SetForceUpdateAllAabbs(BulletWorld pWorld, bool pForce) | 318 | public override void SetForceUpdateAllAabbs(BulletWorld pWorld, bool pForce) |
306 | { | 319 | { |
@@ -404,7 +417,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
404 | IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(vquaternion); | 417 | IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(vquaternion); |
405 | mat._origin = vposition; | 418 | mat._origin = vposition; |
406 | collisionObject.SetWorldTransform(mat); | 419 | collisionObject.SetWorldTransform(mat); |
407 | 420 | ||
408 | } | 421 | } |
409 | 422 | ||
410 | public override Vector3 GetPosition(BulletBody pCollisionObject) | 423 | public override Vector3 GetPosition(BulletBody pCollisionObject) |
@@ -457,7 +470,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
457 | { | 470 | { |
458 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | 471 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
459 | collisionObject.Activate(pforceactivation); | 472 | collisionObject.Activate(pforceactivation); |
460 | 473 | ||
461 | } | 474 | } |
462 | 475 | ||
463 | public override Quaternion GetOrientation(BulletBody pCollisionObject) | 476 | public override Quaternion GetOrientation(BulletBody pCollisionObject) |
@@ -486,7 +499,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
486 | { | 499 | { |
487 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | 500 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
488 | return collisionObject.GetCcdSweptSphereRadius(); | 501 | return collisionObject.GetCcdSweptSphereRadius(); |
489 | 502 | ||
490 | } | 503 | } |
491 | 504 | ||
492 | public override IntPtr GetUserPointer(BulletBody pCollisionObject) | 505 | public override IntPtr GetUserPointer(BulletBody pCollisionObject) |
@@ -559,8 +572,8 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
559 | } | 572 | } |
560 | 573 | ||
561 | 574 | ||
562 | public override BulletConstraint Create6DofConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, | 575 | public override BulletConstraint Create6DofConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, |
563 | Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot, | 576 | Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot, |
564 | bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) | 577 | bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) |
565 | 578 | ||
566 | { | 579 | { |
@@ -604,7 +617,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
604 | } | 617 | } |
605 | 618 | ||
606 | /// <summary> | 619 | /// <summary> |
607 | /// | 620 | /// |
608 | /// </summary> | 621 | /// </summary> |
609 | /// <param name="pWorld"></param> | 622 | /// <param name="pWorld"></param> |
610 | /// <param name="pBody1"></param> | 623 | /// <param name="pBody1"></param> |
@@ -752,6 +765,214 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
752 | constraint.SetBreakingImpulseThreshold(threshold); | 765 | constraint.SetBreakingImpulseThreshold(threshold); |
753 | return true; | 766 | return true; |
754 | } | 767 | } |
768 | public override bool HingeSetLimits(BulletConstraint pConstraint, float low, float high, float softness, float bias, float relaxation) | ||
769 | { | ||
770 | HingeConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as HingeConstraint; | ||
771 | if (softness == HINGE_NOT_SPECIFIED) | ||
772 | constraint.SetLimit(low, high); | ||
773 | else | ||
774 | constraint.SetLimit(low, high, softness, bias, relaxation); | ||
775 | return true; | ||
776 | } | ||
777 | public override bool SpringEnable(BulletConstraint pConstraint, int index, float numericTrueFalse) | ||
778 | { | ||
779 | Generic6DofSpringConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofSpringConstraint; | ||
780 | constraint.EnableSpring(index, (numericTrueFalse == 0f ? false : true)); | ||
781 | return true; | ||
782 | } | ||
783 | |||
784 | public override bool SpringSetEquilibriumPoint(BulletConstraint pConstraint, int index, float equilibriumPoint) | ||
785 | { | ||
786 | Generic6DofSpringConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofSpringConstraint; | ||
787 | if (index == SPRING_NOT_SPECIFIED) | ||
788 | { | ||
789 | constraint.SetEquilibriumPoint(); | ||
790 | } | ||
791 | else | ||
792 | { | ||
793 | if (equilibriumPoint == SPRING_NOT_SPECIFIED) | ||
794 | constraint.SetEquilibriumPoint(index); | ||
795 | else | ||
796 | constraint.SetEquilibriumPoint(index, equilibriumPoint); | ||
797 | } | ||
798 | return true; | ||
799 | } | ||
800 | |||
801 | public override bool SpringSetStiffness(BulletConstraint pConstraint, int index, float stiffness) | ||
802 | { | ||
803 | Generic6DofSpringConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofSpringConstraint; | ||
804 | constraint.SetStiffness(index, stiffness); | ||
805 | return true; | ||
806 | } | ||
807 | |||
808 | public override bool SpringSetDamping(BulletConstraint pConstraint, int index, float damping) | ||
809 | { | ||
810 | Generic6DofSpringConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofSpringConstraint; | ||
811 | constraint.SetDamping(index, damping); | ||
812 | return true; | ||
813 | } | ||
814 | |||
815 | public override bool SliderSetLimits(BulletConstraint pConstraint, int lowerUpper, int linAng, float val) | ||
816 | { | ||
817 | SliderConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as SliderConstraint; | ||
818 | switch (lowerUpper) | ||
819 | { | ||
820 | case SLIDER_LOWER_LIMIT: | ||
821 | switch (linAng) | ||
822 | { | ||
823 | case SLIDER_LINEAR: | ||
824 | constraint.SetLowerLinLimit(val); | ||
825 | break; | ||
826 | case SLIDER_ANGULAR: | ||
827 | constraint.SetLowerAngLimit(val); | ||
828 | break; | ||
829 | } | ||
830 | break; | ||
831 | case SLIDER_UPPER_LIMIT: | ||
832 | switch (linAng) | ||
833 | { | ||
834 | case SLIDER_LINEAR: | ||
835 | constraint.SetUpperLinLimit(val); | ||
836 | break; | ||
837 | case SLIDER_ANGULAR: | ||
838 | constraint.SetUpperAngLimit(val); | ||
839 | break; | ||
840 | } | ||
841 | break; | ||
842 | } | ||
843 | return true; | ||
844 | } | ||
845 | public override bool SliderSet(BulletConstraint pConstraint, int softRestDamp, int dirLimOrtho, int linAng, float val) | ||
846 | { | ||
847 | SliderConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as SliderConstraint; | ||
848 | switch (softRestDamp) | ||
849 | { | ||
850 | case SLIDER_SET_SOFTNESS: | ||
851 | switch (dirLimOrtho) | ||
852 | { | ||
853 | case SLIDER_SET_DIRECTION: | ||
854 | switch (linAng) | ||
855 | { | ||
856 | case SLIDER_LINEAR: constraint.SetSoftnessDirLin(val); break; | ||
857 | case SLIDER_ANGULAR: constraint.SetSoftnessDirAng(val); break; | ||
858 | } | ||
859 | break; | ||
860 | case SLIDER_SET_LIMIT: | ||
861 | switch (linAng) | ||
862 | { | ||
863 | case SLIDER_LINEAR: constraint.SetSoftnessLimLin(val); break; | ||
864 | case SLIDER_ANGULAR: constraint.SetSoftnessLimAng(val); break; | ||
865 | } | ||
866 | break; | ||
867 | case SLIDER_SET_ORTHO: | ||
868 | switch (linAng) | ||
869 | { | ||
870 | case SLIDER_LINEAR: constraint.SetSoftnessOrthoLin(val); break; | ||
871 | case SLIDER_ANGULAR: constraint.SetSoftnessOrthoAng(val); break; | ||
872 | } | ||
873 | break; | ||
874 | } | ||
875 | break; | ||
876 | case SLIDER_SET_RESTITUTION: | ||
877 | switch (dirLimOrtho) | ||
878 | { | ||
879 | case SLIDER_SET_DIRECTION: | ||
880 | switch (linAng) | ||
881 | { | ||
882 | case SLIDER_LINEAR: constraint.SetRestitutionDirLin(val); break; | ||
883 | case SLIDER_ANGULAR: constraint.SetRestitutionDirAng(val); break; | ||
884 | } | ||
885 | break; | ||
886 | case SLIDER_SET_LIMIT: | ||
887 | switch (linAng) | ||
888 | { | ||
889 | case SLIDER_LINEAR: constraint.SetRestitutionLimLin(val); break; | ||
890 | case SLIDER_ANGULAR: constraint.SetRestitutionLimAng(val); break; | ||
891 | } | ||
892 | break; | ||
893 | case SLIDER_SET_ORTHO: | ||
894 | switch (linAng) | ||
895 | { | ||
896 | case SLIDER_LINEAR: constraint.SetRestitutionOrthoLin(val); break; | ||
897 | case SLIDER_ANGULAR: constraint.SetRestitutionOrthoAng(val); break; | ||
898 | } | ||
899 | break; | ||
900 | } | ||
901 | break; | ||
902 | case SLIDER_SET_DAMPING: | ||
903 | switch (dirLimOrtho) | ||
904 | { | ||
905 | case SLIDER_SET_DIRECTION: | ||
906 | switch (linAng) | ||
907 | { | ||
908 | case SLIDER_LINEAR: constraint.SetDampingDirLin(val); break; | ||
909 | case SLIDER_ANGULAR: constraint.SetDampingDirAng(val); break; | ||
910 | } | ||
911 | break; | ||
912 | case SLIDER_SET_LIMIT: | ||
913 | switch (linAng) | ||
914 | { | ||
915 | case SLIDER_LINEAR: constraint.SetDampingLimLin(val); break; | ||
916 | case SLIDER_ANGULAR: constraint.SetDampingLimAng(val); break; | ||
917 | } | ||
918 | break; | ||
919 | case SLIDER_SET_ORTHO: | ||
920 | switch (linAng) | ||
921 | { | ||
922 | case SLIDER_LINEAR: constraint.SetDampingOrthoLin(val); break; | ||
923 | case SLIDER_ANGULAR: constraint.SetDampingOrthoAng(val); break; | ||
924 | } | ||
925 | break; | ||
926 | } | ||
927 | break; | ||
928 | } | ||
929 | return true; | ||
930 | } | ||
931 | public override bool SliderMotorEnable(BulletConstraint pConstraint, int linAng, float numericTrueFalse) | ||
932 | { | ||
933 | SliderConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as SliderConstraint; | ||
934 | switch (linAng) | ||
935 | { | ||
936 | case SLIDER_LINEAR: | ||
937 | constraint.SetPoweredLinMotor(numericTrueFalse == 0.0 ? false : true); | ||
938 | break; | ||
939 | case SLIDER_ANGULAR: | ||
940 | constraint.SetPoweredAngMotor(numericTrueFalse == 0.0 ? false : true); | ||
941 | break; | ||
942 | } | ||
943 | return true; | ||
944 | } | ||
945 | public override bool SliderMotor(BulletConstraint pConstraint, int forceVel, int linAng, float val) | ||
946 | { | ||
947 | SliderConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as SliderConstraint; | ||
948 | switch (forceVel) | ||
949 | { | ||
950 | case SLIDER_MOTOR_VELOCITY: | ||
951 | switch (linAng) | ||
952 | { | ||
953 | case SLIDER_LINEAR: | ||
954 | constraint.SetTargetLinMotorVelocity(val); | ||
955 | break; | ||
956 | case SLIDER_ANGULAR: | ||
957 | constraint.SetTargetAngMotorVelocity(val); | ||
958 | break; | ||
959 | } | ||
960 | break; | ||
961 | case SLIDER_MAX_MOTOR_FORCE: | ||
962 | switch (linAng) | ||
963 | { | ||
964 | case SLIDER_LINEAR: | ||
965 | constraint.SetMaxLinMotorForce(val); | ||
966 | break; | ||
967 | case SLIDER_ANGULAR: | ||
968 | constraint.SetMaxAngMotorForce(val); | ||
969 | break; | ||
970 | } | ||
971 | break; | ||
972 | } | ||
973 | return true; | ||
974 | } | ||
975 | |||
755 | //BulletSimAPI.SetAngularDamping(Prim.PhysBody.ptr, angularDamping); | 976 | //BulletSimAPI.SetAngularDamping(Prim.PhysBody.ptr, angularDamping); |
756 | public override void SetAngularDamping(BulletBody pBody, float angularDamping) | 977 | public override void SetAngularDamping(BulletBody pBody, float angularDamping) |
757 | { | 978 | { |
@@ -824,7 +1045,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
824 | { | 1045 | { |
825 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | 1046 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
826 | float angularDamping = body.GetAngularDamping(); | 1047 | float angularDamping = body.GetAngularDamping(); |
827 | body.SetDamping(lin_damping, angularDamping); | 1048 | body.SetDamping(lin_damping, angularDamping); |
828 | } | 1049 | } |
829 | 1050 | ||
830 | public override float GetLinearDamping(BulletBody pBody) | 1051 | public override float GetLinearDamping(BulletBody pBody) |
@@ -907,7 +1128,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
907 | RigidBody bo = co as RigidBody; | 1128 | RigidBody bo = co as RigidBody; |
908 | if (bo == null) | 1129 | if (bo == null) |
909 | { | 1130 | { |
910 | 1131 | ||
911 | if (world.IsInWorld(co)) | 1132 | if (world.IsInWorld(co)) |
912 | { | 1133 | { |
913 | world.RemoveCollisionObject(co); | 1134 | world.RemoveCollisionObject(co); |
@@ -915,7 +1136,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
915 | } | 1136 | } |
916 | else | 1137 | else |
917 | { | 1138 | { |
918 | 1139 | ||
919 | if (world.IsInWorld(bo)) | 1140 | if (world.IsInWorld(bo)) |
920 | { | 1141 | { |
921 | world.RemoveRigidBody(bo); | 1142 | world.RemoveRigidBody(bo); |
@@ -947,7 +1168,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
947 | 1168 | ||
948 | // TODO: Turn this from a reference copy to a Value Copy. | 1169 | // TODO: Turn this from a reference copy to a Value Copy. |
949 | BulletShapeXNA shape2 = new BulletShapeXNA(shape1, BSShapeTypeFromBroadPhaseNativeType(shape1.GetShapeType())); | 1170 | BulletShapeXNA shape2 = new BulletShapeXNA(shape1, BSShapeTypeFromBroadPhaseNativeType(shape1.GetShapeType())); |
950 | 1171 | ||
951 | return shape2; | 1172 | return shape2; |
952 | } | 1173 | } |
953 | 1174 | ||
@@ -957,7 +1178,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
957 | return false; | 1178 | return false; |
958 | } | 1179 | } |
959 | //(sim.ptr, shape.ptr, prim.LocalID, prim.RawPosition, prim.RawOrientation); | 1180 | //(sim.ptr, shape.ptr, prim.LocalID, prim.RawPosition, prim.RawOrientation); |
960 | 1181 | ||
961 | public override BulletBody CreateBodyFromShape(BulletWorld pWorld, BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation) | 1182 | public override BulletBody CreateBodyFromShape(BulletWorld pWorld, BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation) |
962 | { | 1183 | { |
963 | CollisionWorld world = (pWorld as BulletWorldXNA).world; | 1184 | CollisionWorld world = (pWorld as BulletWorldXNA).world; |
@@ -993,11 +1214,11 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
993 | m_startWorldTransform = IndexedMatrix.Identity; | 1214 | m_startWorldTransform = IndexedMatrix.Identity; |
994 | */ | 1215 | */ |
995 | body.SetUserPointer(pLocalID); | 1216 | body.SetUserPointer(pLocalID); |
996 | 1217 | ||
997 | return new BulletBodyXNA(pLocalID, body); | 1218 | return new BulletBodyXNA(pLocalID, body); |
998 | } | 1219 | } |
999 | 1220 | ||
1000 | 1221 | ||
1001 | public override BulletBody CreateBodyWithDefaultMotionState( BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation) | 1222 | public override BulletBody CreateBodyWithDefaultMotionState( BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation) |
1002 | { | 1223 | { |
1003 | 1224 | ||
@@ -1025,7 +1246,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1025 | public override Vector3 GetAnisotripicFriction(BulletConstraint pconstrain) | 1246 | public override Vector3 GetAnisotripicFriction(BulletConstraint pconstrain) |
1026 | { | 1247 | { |
1027 | 1248 | ||
1028 | /* TODO */ | 1249 | /* TODO */ |
1029 | return Vector3.Zero; | 1250 | return Vector3.Zero; |
1030 | } | 1251 | } |
1031 | public override Vector3 SetAnisotripicFriction(BulletConstraint pconstrain, Vector3 frict) { /* TODO */ return Vector3.Zero; } | 1252 | public override Vector3 SetAnisotripicFriction(BulletConstraint pconstrain, Vector3 frict) { /* TODO */ return Vector3.Zero; } |
@@ -1035,7 +1256,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1035 | { | 1256 | { |
1036 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | 1257 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
1037 | return collisionObject.IsStaticObject(); | 1258 | return collisionObject.IsStaticObject(); |
1038 | 1259 | ||
1039 | } | 1260 | } |
1040 | public override bool IsKinematicObject(BulletBody pCollisionObject) | 1261 | public override bool IsKinematicObject(BulletBody pCollisionObject) |
1041 | { | 1262 | { |
@@ -1098,10 +1319,10 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1098 | return new BulletWorldXNA(1, PhysicsScene, BSAPIXNA.Initialize2(worldExtent, configparms, maxCollisions, ref collisionArray, maxUpdates, ref updateArray, null)); | 1319 | return new BulletWorldXNA(1, PhysicsScene, BSAPIXNA.Initialize2(worldExtent, configparms, maxCollisions, ref collisionArray, maxUpdates, ref updateArray, null)); |
1099 | } | 1320 | } |
1100 | 1321 | ||
1101 | private static DiscreteDynamicsWorld Initialize2(Vector3 worldExtent, | 1322 | private static DiscreteDynamicsWorld Initialize2(Vector3 worldExtent, |
1102 | ConfigurationParameters[] o, | 1323 | ConfigurationParameters[] o, |
1103 | int mMaxCollisionsPerFrame, ref CollisionDesc[] collisionArray, | 1324 | int mMaxCollisionsPerFrame, ref CollisionDesc[] collisionArray, |
1104 | int mMaxUpdatesPerFrame, ref EntityProperties[] updateArray, | 1325 | int mMaxUpdatesPerFrame, ref EntityProperties[] updateArray, |
1105 | object mDebugLogCallbackHandle) | 1326 | object mDebugLogCallbackHandle) |
1106 | { | 1327 | { |
1107 | CollisionWorld.WorldData.ParamData p = new CollisionWorld.WorldData.ParamData(); | 1328 | CollisionWorld.WorldData.ParamData p = new CollisionWorld.WorldData.ParamData(); |
@@ -1138,9 +1359,9 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1138 | p.avatarCapsuleDepth = BSParam.AvatarCapsuleDepth; | 1359 | p.avatarCapsuleDepth = BSParam.AvatarCapsuleDepth; |
1139 | p.avatarCapsuleHeight = BSParam.AvatarCapsuleHeight; | 1360 | p.avatarCapsuleHeight = BSParam.AvatarCapsuleHeight; |
1140 | p.avatarContactProcessingThreshold = BSParam.AvatarContactProcessingThreshold; | 1361 | p.avatarContactProcessingThreshold = BSParam.AvatarContactProcessingThreshold; |
1141 | 1362 | ||
1142 | p.vehicleAngularDamping = BSParam.VehicleAngularDamping; | 1363 | p.vehicleAngularDamping = BSParam.VehicleAngularDamping; |
1143 | 1364 | ||
1144 | p.maxPersistantManifoldPoolSize = o[0].maxPersistantManifoldPoolSize; | 1365 | p.maxPersistantManifoldPoolSize = o[0].maxPersistantManifoldPoolSize; |
1145 | p.maxCollisionAlgorithmPoolSize = o[0].maxCollisionAlgorithmPoolSize; | 1366 | p.maxCollisionAlgorithmPoolSize = o[0].maxCollisionAlgorithmPoolSize; |
1146 | p.shouldDisableContactPoolDynamicAllocation = o[0].shouldDisableContactPoolDynamicAllocation; | 1367 | p.shouldDisableContactPoolDynamicAllocation = o[0].shouldDisableContactPoolDynamicAllocation; |
@@ -1160,7 +1381,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1160 | p.linkConstraintSolverIterations = BSParam.LinkConstraintSolverIterations; | 1381 | p.linkConstraintSolverIterations = BSParam.LinkConstraintSolverIterations; |
1161 | p.physicsLoggingFrames = o[0].physicsLoggingFrames; | 1382 | p.physicsLoggingFrames = o[0].physicsLoggingFrames; |
1162 | DefaultCollisionConstructionInfo ccci = new DefaultCollisionConstructionInfo(); | 1383 | DefaultCollisionConstructionInfo ccci = new DefaultCollisionConstructionInfo(); |
1163 | 1384 | ||
1164 | DefaultCollisionConfiguration cci = new DefaultCollisionConfiguration(); | 1385 | DefaultCollisionConfiguration cci = new DefaultCollisionConfiguration(); |
1165 | CollisionDispatcher m_dispatcher = new CollisionDispatcher(cci); | 1386 | CollisionDispatcher m_dispatcher = new CollisionDispatcher(cci); |
1166 | 1387 | ||
@@ -1221,6 +1442,50 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1221 | //BSParam.TerrainImplementation = 0; | 1442 | //BSParam.TerrainImplementation = 0; |
1222 | world.SetGravity(new IndexedVector3(0,0,p.gravity)); | 1443 | world.SetGravity(new IndexedVector3(0,0,p.gravity)); |
1223 | 1444 | ||
1445 | // Turn off Pooling since globals and pooling are bad for threading. | ||
1446 | BulletGlobals.VoronoiSimplexSolverPool.SetPoolingEnabled(false); | ||
1447 | BulletGlobals.SubSimplexConvexCastPool.SetPoolingEnabled(false); | ||
1448 | BulletGlobals.ManifoldPointPool.SetPoolingEnabled(false); | ||
1449 | BulletGlobals.CastResultPool.SetPoolingEnabled(false); | ||
1450 | BulletGlobals.SphereShapePool.SetPoolingEnabled(false); | ||
1451 | BulletGlobals.DbvtNodePool.SetPoolingEnabled(false); | ||
1452 | BulletGlobals.SingleRayCallbackPool.SetPoolingEnabled(false); | ||
1453 | BulletGlobals.SubSimplexClosestResultPool.SetPoolingEnabled(false); | ||
1454 | BulletGlobals.GjkPairDetectorPool.SetPoolingEnabled(false); | ||
1455 | BulletGlobals.DbvtTreeColliderPool.SetPoolingEnabled(false); | ||
1456 | BulletGlobals.SingleSweepCallbackPool.SetPoolingEnabled(false); | ||
1457 | BulletGlobals.BroadphaseRayTesterPool.SetPoolingEnabled(false); | ||
1458 | BulletGlobals.ClosestNotMeConvexResultCallbackPool.SetPoolingEnabled(false); | ||
1459 | BulletGlobals.GjkEpaPenetrationDepthSolverPool.SetPoolingEnabled(false); | ||
1460 | BulletGlobals.ContinuousConvexCollisionPool.SetPoolingEnabled(false); | ||
1461 | BulletGlobals.DbvtStackDataBlockPool.SetPoolingEnabled(false); | ||
1462 | |||
1463 | BulletGlobals.BoxBoxCollisionAlgorithmPool.SetPoolingEnabled(false); | ||
1464 | BulletGlobals.CompoundCollisionAlgorithmPool.SetPoolingEnabled(false); | ||
1465 | BulletGlobals.ConvexConcaveCollisionAlgorithmPool.SetPoolingEnabled(false); | ||
1466 | BulletGlobals.ConvexConvexAlgorithmPool.SetPoolingEnabled(false); | ||
1467 | BulletGlobals.ConvexPlaneAlgorithmPool.SetPoolingEnabled(false); | ||
1468 | BulletGlobals.SphereBoxCollisionAlgorithmPool.SetPoolingEnabled(false); | ||
1469 | BulletGlobals.SphereSphereCollisionAlgorithmPool.SetPoolingEnabled(false); | ||
1470 | BulletGlobals.SphereTriangleCollisionAlgorithmPool.SetPoolingEnabled(false); | ||
1471 | BulletGlobals.GImpactCollisionAlgorithmPool.SetPoolingEnabled(false); | ||
1472 | BulletGlobals.GjkEpaSolver2MinkowskiDiffPool.SetPoolingEnabled(false); | ||
1473 | BulletGlobals.PersistentManifoldPool.SetPoolingEnabled(false); | ||
1474 | BulletGlobals.ManifoldResultPool.SetPoolingEnabled(false); | ||
1475 | BulletGlobals.GJKPool.SetPoolingEnabled(false); | ||
1476 | BulletGlobals.GIM_ShapeRetrieverPool.SetPoolingEnabled(false); | ||
1477 | BulletGlobals.TriangleShapePool.SetPoolingEnabled(false); | ||
1478 | BulletGlobals.SphereTriangleDetectorPool.SetPoolingEnabled(false); | ||
1479 | BulletGlobals.CompoundLeafCallbackPool.SetPoolingEnabled(false); | ||
1480 | BulletGlobals.GjkConvexCastPool.SetPoolingEnabled(false); | ||
1481 | BulletGlobals.LocalTriangleSphereCastCallbackPool.SetPoolingEnabled(false); | ||
1482 | BulletGlobals.BridgeTriangleRaycastCallbackPool.SetPoolingEnabled(false); | ||
1483 | BulletGlobals.BridgeTriangleConcaveRaycastCallbackPool.SetPoolingEnabled(false); | ||
1484 | BulletGlobals.BridgeTriangleConvexcastCallbackPool.SetPoolingEnabled(false); | ||
1485 | BulletGlobals.MyNodeOverlapCallbackPool.SetPoolingEnabled(false); | ||
1486 | BulletGlobals.ClosestRayResultCallbackPool.SetPoolingEnabled(false); | ||
1487 | BulletGlobals.DebugDrawcallbackPool.SetPoolingEnabled(false); | ||
1488 | |||
1224 | return world; | 1489 | return world; |
1225 | } | 1490 | } |
1226 | //m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL | 1491 | //m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL |
@@ -1263,7 +1528,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1263 | } | 1528 | } |
1264 | } | 1529 | } |
1265 | return ret; | 1530 | return ret; |
1266 | 1531 | ||
1267 | } | 1532 | } |
1268 | 1533 | ||
1269 | public override float GetAngularMotionDisc(BulletShape pShape) | 1534 | public override float GetAngularMotionDisc(BulletShape pShape) |
@@ -1353,10 +1618,10 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1353 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | 1618 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
1354 | gObj.SetCollisionShape(shape); | 1619 | gObj.SetCollisionShape(shape); |
1355 | gObj.SetUserPointer(pLocalID); | 1620 | gObj.SetUserPointer(pLocalID); |
1356 | 1621 | ||
1357 | if (specialCollisionObjects.ContainsKey(pLocalID)) | 1622 | if (specialCollisionObjects.ContainsKey(pLocalID)) |
1358 | specialCollisionObjects[pLocalID] = gObj; | 1623 | specialCollisionObjects[pLocalID] = gObj; |
1359 | else | 1624 | else |
1360 | specialCollisionObjects.Add(pLocalID, gObj); | 1625 | specialCollisionObjects.Add(pLocalID, gObj); |
1361 | 1626 | ||
1362 | // TODO: Add to Special CollisionObjects! | 1627 | // TODO: Add to Special CollisionObjects! |
@@ -1447,8 +1712,8 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1447 | return new BulletShapeXNA(ret, BSShapeTypeFromBroadPhaseNativeType(ret.GetShapeType())); | 1712 | return new BulletShapeXNA(ret, BSShapeTypeFromBroadPhaseNativeType(ret.GetShapeType())); |
1448 | } | 1713 | } |
1449 | 1714 | ||
1450 | public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) { | 1715 | public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) { |
1451 | 1716 | ||
1452 | if (cShape == null) | 1717 | if (cShape == null) |
1453 | return null; | 1718 | return null; |
1454 | CompoundShape compoundShape = (cShape as BulletShapeXNA).shape as CompoundShape; | 1719 | CompoundShape compoundShape = (cShape as BulletShapeXNA).shape as CompoundShape; |
@@ -1456,7 +1721,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1456 | BulletShape retShape = new BulletShapeXNA(shape, BSShapeTypeFromBroadPhaseNativeType(shape.GetShapeType())); | 1721 | BulletShape retShape = new BulletShapeXNA(shape, BSShapeTypeFromBroadPhaseNativeType(shape.GetShapeType())); |
1457 | 1722 | ||
1458 | 1723 | ||
1459 | return retShape; | 1724 | return retShape; |
1460 | } | 1725 | } |
1461 | 1726 | ||
1462 | public BSPhysicsShapeType BSShapeTypeFromBroadPhaseNativeType(BroadphaseNativeTypes pin) | 1727 | public BSPhysicsShapeType BSShapeTypeFromBroadPhaseNativeType(BroadphaseNativeTypes pin) |
@@ -1475,7 +1740,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1475 | ret = BSPhysicsShapeType.SHAPE_UNKNOWN; | 1740 | ret = BSPhysicsShapeType.SHAPE_UNKNOWN; |
1476 | break; | 1741 | break; |
1477 | case BroadphaseNativeTypes.CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE: | 1742 | case BroadphaseNativeTypes.CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE: |
1478 | ret = BSPhysicsShapeType.SHAPE_MESH; | 1743 | ret = BSPhysicsShapeType.SHAPE_CONVEXHULL; |
1479 | break; | 1744 | break; |
1480 | case BroadphaseNativeTypes.CONVEX_HULL_SHAPE_PROXYTYPE: | 1745 | case BroadphaseNativeTypes.CONVEX_HULL_SHAPE_PROXYTYPE: |
1481 | ret = BSPhysicsShapeType.SHAPE_HULL; | 1746 | ret = BSPhysicsShapeType.SHAPE_HULL; |
@@ -1503,7 +1768,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1503 | ret = BSPhysicsShapeType.SHAPE_CONE; | 1768 | ret = BSPhysicsShapeType.SHAPE_CONE; |
1504 | break; | 1769 | break; |
1505 | case BroadphaseNativeTypes.CONVEX_SHAPE_PROXYTYPE: | 1770 | case BroadphaseNativeTypes.CONVEX_SHAPE_PROXYTYPE: |
1506 | ret = BSPhysicsShapeType.SHAPE_UNKNOWN; | 1771 | ret = BSPhysicsShapeType.SHAPE_CONVEXHULL; |
1507 | break; | 1772 | break; |
1508 | case BroadphaseNativeTypes.CYLINDER_SHAPE_PROXYTYPE: | 1773 | case BroadphaseNativeTypes.CYLINDER_SHAPE_PROXYTYPE: |
1509 | ret = BSPhysicsShapeType.SHAPE_CYLINDER; | 1774 | ret = BSPhysicsShapeType.SHAPE_CYLINDER; |
@@ -1547,7 +1812,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1547 | break; | 1812 | break; |
1548 | ///Used for GIMPACT Trimesh integration | 1813 | ///Used for GIMPACT Trimesh integration |
1549 | case BroadphaseNativeTypes.GIMPACT_SHAPE_PROXYTYPE: | 1814 | case BroadphaseNativeTypes.GIMPACT_SHAPE_PROXYTYPE: |
1550 | ret = BSPhysicsShapeType.SHAPE_MESH; | 1815 | ret = BSPhysicsShapeType.SHAPE_GIMPACT; |
1551 | break; | 1816 | break; |
1552 | ///Multimaterial mesh | 1817 | ///Multimaterial mesh |
1553 | case BroadphaseNativeTypes.MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE: | 1818 | case BroadphaseNativeTypes.MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE: |
@@ -1598,8 +1863,8 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1598 | return new BulletShapeXNA(m_planeshape, BSPhysicsShapeType.SHAPE_GROUNDPLANE); | 1863 | return new BulletShapeXNA(m_planeshape, BSPhysicsShapeType.SHAPE_GROUNDPLANE); |
1599 | } | 1864 | } |
1600 | 1865 | ||
1601 | public override BulletConstraint Create6DofSpringConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, | 1866 | public override BulletConstraint Create6DofSpringConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, |
1602 | Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot, | 1867 | Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot, |
1603 | bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) | 1868 | bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) |
1604 | 1869 | ||
1605 | { | 1870 | { |
@@ -1745,7 +2010,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1745 | { | 2010 | { |
1746 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | 2011 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
1747 | CompoundShape compoundshape = new CompoundShape(false); | 2012 | CompoundShape compoundshape = new CompoundShape(false); |
1748 | 2013 | ||
1749 | compoundshape.SetMargin(world.WorldSettings.Params.collisionMargin); | 2014 | compoundshape.SetMargin(world.WorldSettings.Params.collisionMargin); |
1750 | int ii = 1; | 2015 | int ii = 1; |
1751 | 2016 | ||
@@ -1761,7 +2026,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1761 | int ender = ((ii + 4) + (vertexCount*3)); | 2026 | int ender = ((ii + 4) + (vertexCount*3)); |
1762 | for (int iii = ii + 4; iii < ender; iii+=3) | 2027 | for (int iii = ii + 4; iii < ender; iii+=3) |
1763 | { | 2028 | { |
1764 | 2029 | ||
1765 | virts.Add(new IndexedVector3(pConvHulls[iii], pConvHulls[iii + 1], pConvHulls[iii +2])); | 2030 | virts.Add(new IndexedVector3(pConvHulls[iii], pConvHulls[iii + 1], pConvHulls[iii +2])); |
1766 | } | 2031 | } |
1767 | ConvexHullShape convexShape = new ConvexHullShape(virts, vertexCount); | 2032 | ConvexHullShape convexShape = new ConvexHullShape(virts, vertexCount); |
@@ -1769,26 +2034,35 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1769 | compoundshape.AddChildShape(ref childTrans, convexShape); | 2034 | compoundshape.AddChildShape(ref childTrans, convexShape); |
1770 | ii += (vertexCount*3 + 4); | 2035 | ii += (vertexCount*3 + 4); |
1771 | } | 2036 | } |
1772 | 2037 | ||
1773 | return new BulletShapeXNA(compoundshape, BSPhysicsShapeType.SHAPE_HULL); | 2038 | return new BulletShapeXNA(compoundshape, BSPhysicsShapeType.SHAPE_HULL); |
1774 | } | 2039 | } |
1775 | 2040 | ||
1776 | public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape) | 2041 | public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape, HACDParams parms) |
1777 | { | 2042 | { |
1778 | /* TODO */ return null; | 2043 | /* TODO */ return null; |
2044 | } | ||
1779 | 2045 | ||
2046 | public override BulletShape BuildConvexHullShapeFromMesh(BulletWorld world, BulletShape meshShape) | ||
2047 | { | ||
2048 | /* TODO */ return null; | ||
2049 | } | ||
2050 | |||
2051 | public override BulletShape CreateConvexHullShape(BulletWorld pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats) | ||
2052 | { | ||
2053 | /* TODO */ return null; | ||
1780 | } | 2054 | } |
1781 | 2055 | ||
1782 | public override BulletShape CreateMeshShape(BulletWorld pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats) | 2056 | public override BulletShape CreateMeshShape(BulletWorld pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats) |
1783 | { | 2057 | { |
1784 | //DumpRaw(indices,verticesAsFloats,pIndicesCount,pVerticesCount); | 2058 | //DumpRaw(indices,verticesAsFloats,pIndicesCount,pVerticesCount); |
1785 | 2059 | ||
1786 | for (int iter = 0; iter < pVerticesCount; iter++) | 2060 | for (int iter = 0; iter < pVerticesCount; iter++) |
1787 | { | 2061 | { |
1788 | if (verticesAsFloats[iter] > 0 && verticesAsFloats[iter] < 0.0001) verticesAsFloats[iter] = 0; | 2062 | if (verticesAsFloats[iter] > 0 && verticesAsFloats[iter] < 0.0001) verticesAsFloats[iter] = 0; |
1789 | if (verticesAsFloats[iter] < 0 && verticesAsFloats[iter] > -0.0001) verticesAsFloats[iter] = 0; | 2063 | if (verticesAsFloats[iter] < 0 && verticesAsFloats[iter] > -0.0001) verticesAsFloats[iter] = 0; |
1790 | } | 2064 | } |
1791 | 2065 | ||
1792 | ObjectArray<int> indicesarr = new ObjectArray<int>(indices); | 2066 | ObjectArray<int> indicesarr = new ObjectArray<int>(indices); |
1793 | ObjectArray<float> vertices = new ObjectArray<float>(verticesAsFloats); | 2067 | ObjectArray<float> vertices = new ObjectArray<float>(verticesAsFloats); |
1794 | DumpRaw(indicesarr,vertices,pIndicesCount,pVerticesCount); | 2068 | DumpRaw(indicesarr,vertices,pIndicesCount,pVerticesCount); |
@@ -1802,7 +2076,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1802 | mesh.m_vertexStride = 3; | 2076 | mesh.m_vertexStride = 3; |
1803 | mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT; | 2077 | mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT; |
1804 | mesh.m_triangleIndexStride = 3; | 2078 | mesh.m_triangleIndexStride = 3; |
1805 | 2079 | ||
1806 | TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray(); | 2080 | TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray(); |
1807 | tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER); | 2081 | tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER); |
1808 | BvhTriangleMeshShape meshShape = new BvhTriangleMeshShape(tribuilder, true,true); | 2082 | BvhTriangleMeshShape meshShape = new BvhTriangleMeshShape(tribuilder, true,true); |
@@ -1811,9 +2085,14 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1811 | return new BulletShapeXNA(meshShape, BSPhysicsShapeType.SHAPE_MESH); | 2085 | return new BulletShapeXNA(meshShape, BSPhysicsShapeType.SHAPE_MESH); |
1812 | 2086 | ||
1813 | } | 2087 | } |
2088 | public override BulletShape CreateGImpactShape(BulletWorld pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats) | ||
2089 | { | ||
2090 | // TODO: | ||
2091 | return null; | ||
2092 | } | ||
1814 | public static void DumpRaw(ObjectArray<int>indices, ObjectArray<float> vertices, int pIndicesCount,int pVerticesCount ) | 2093 | public static void DumpRaw(ObjectArray<int>indices, ObjectArray<float> vertices, int pIndicesCount,int pVerticesCount ) |
1815 | { | 2094 | { |
1816 | 2095 | ||
1817 | String fileName = "objTest3.raw"; | 2096 | String fileName = "objTest3.raw"; |
1818 | String completePath = System.IO.Path.Combine(Util.configDir(), fileName); | 2097 | String completePath = System.IO.Path.Combine(Util.configDir(), fileName); |
1819 | StreamWriter sw = new StreamWriter(completePath); | 2098 | StreamWriter sw = new StreamWriter(completePath); |
@@ -1839,7 +2118,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1839 | string s = vertices[indices[i * 3]].ToString("0.0000"); | 2118 | string s = vertices[indices[i * 3]].ToString("0.0000"); |
1840 | s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000"); | 2119 | s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000"); |
1841 | s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000"); | 2120 | s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000"); |
1842 | 2121 | ||
1843 | sw.Write(s + "\n"); | 2122 | sw.Write(s + "\n"); |
1844 | } | 2123 | } |
1845 | 2124 | ||
@@ -1861,7 +2140,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1861 | mesh.m_vertexStride = 3; | 2140 | mesh.m_vertexStride = 3; |
1862 | mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT; | 2141 | mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT; |
1863 | mesh.m_triangleIndexStride = 3; | 2142 | mesh.m_triangleIndexStride = 3; |
1864 | 2143 | ||
1865 | TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray(); | 2144 | TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray(); |
1866 | tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER); | 2145 | tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER); |
1867 | 2146 | ||
@@ -1892,7 +2171,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1892 | sw.Close(); | 2171 | sw.Close(); |
1893 | } | 2172 | } |
1894 | 2173 | ||
1895 | public override BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap, | 2174 | public override BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap, |
1896 | float scaleFactor, float collisionMargin) | 2175 | float scaleFactor, float collisionMargin) |
1897 | { | 2176 | { |
1898 | const int upAxis = 2; | 2177 | const int upAxis = 2; |
@@ -1900,7 +2179,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1900 | heightMap, scaleFactor, | 2179 | heightMap, scaleFactor, |
1901 | minHeight, maxHeight, upAxis, | 2180 | minHeight, maxHeight, upAxis, |
1902 | false); | 2181 | false); |
1903 | terrainShape.SetMargin(collisionMargin + 0.5f); | 2182 | terrainShape.SetMargin(collisionMargin); |
1904 | terrainShape.SetUseDiamondSubdivision(true); | 2183 | terrainShape.SetUseDiamondSubdivision(true); |
1905 | terrainShape.SetUserPointer(id); | 2184 | terrainShape.SetUserPointer(id); |
1906 | return new BulletShapeXNA(terrainShape, BSPhysicsShapeType.SHAPE_TERRAIN); | 2185 | return new BulletShapeXNA(terrainShape, BSPhysicsShapeType.SHAPE_TERRAIN); |
@@ -1934,14 +2213,14 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1934 | /* TODO */ | 2213 | /* TODO */ |
1935 | updatedEntityCount = 0; | 2214 | updatedEntityCount = 0; |
1936 | collidersCount = 0; | 2215 | collidersCount = 0; |
1937 | 2216 | ||
1938 | 2217 | ||
1939 | int ret = PhysicsStep2(world,timeStep,maxSubSteps,fixedTimeStep,out updatedEntityCount,out world.physicsScene.m_updateArray, out collidersCount, out world.physicsScene.m_collisionArray); | 2218 | int ret = PhysicsStep2(world,timeStep,maxSubSteps,fixedTimeStep,out updatedEntityCount,out world.physicsScene.m_updateArray, out collidersCount, out world.physicsScene.m_collisionArray); |
1940 | 2219 | ||
1941 | return ret; | 2220 | return ret; |
1942 | } | 2221 | } |
1943 | 2222 | ||
1944 | private int PhysicsStep2(BulletWorld pWorld, float timeStep, int m_maxSubSteps, float m_fixedTimeStep, | 2223 | private int PhysicsStep2(BulletWorld pWorld, float timeStep, int m_maxSubSteps, float m_fixedTimeStep, |
1945 | out int updatedEntityCount, out EntityProperties[] updatedEntities, | 2224 | out int updatedEntityCount, out EntityProperties[] updatedEntities, |
1946 | out int collidersCount, out CollisionDesc[] colliders) | 2225 | out int collidersCount, out CollisionDesc[] colliders) |
1947 | { | 2226 | { |
@@ -1950,24 +2229,24 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1950 | return epic; | 2229 | return epic; |
1951 | } | 2230 | } |
1952 | 2231 | ||
1953 | private int PhysicsStepint(BulletWorld pWorld,float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount, | 2232 | private int PhysicsStepint(BulletWorld pWorld,float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount, |
1954 | out EntityProperties[] updatedEntities, out int collidersCount, out CollisionDesc[] colliders, int maxCollisions, int maxUpdates) | 2233 | out EntityProperties[] updatedEntities, out int collidersCount, out CollisionDesc[] colliders, int maxCollisions, int maxUpdates) |
1955 | { | 2234 | { |
1956 | int numSimSteps = 0; | 2235 | int numSimSteps = 0; |
1957 | Array.Clear(UpdatedObjects, 0, UpdatedObjects.Length); | 2236 | Array.Clear(UpdatedObjects, 0, UpdatedObjects.Length); |
1958 | Array.Clear(UpdatedCollisions, 0, UpdatedCollisions.Length); | 2237 | Array.Clear(UpdatedCollisions, 0, UpdatedCollisions.Length); |
1959 | LastEntityProperty=0; | 2238 | LastEntityProperty=0; |
1960 | 2239 | ||
1961 | 2240 | ||
1962 | 2241 | ||
1963 | 2242 | ||
1964 | 2243 | ||
1965 | 2244 | ||
1966 | LastCollisionDesc=0; | 2245 | LastCollisionDesc=0; |
1967 | 2246 | ||
1968 | updatedEntityCount = 0; | 2247 | updatedEntityCount = 0; |
1969 | collidersCount = 0; | 2248 | collidersCount = 0; |
1970 | 2249 | ||
1971 | 2250 | ||
1972 | if (pWorld is BulletWorldXNA) | 2251 | if (pWorld is BulletWorldXNA) |
1973 | { | 2252 | { |
@@ -2024,7 +2303,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
2024 | 2303 | ||
2025 | collidersCount = LastCollisionDesc; | 2304 | collidersCount = LastCollisionDesc; |
2026 | colliders = UpdatedCollisions; | 2305 | colliders = UpdatedCollisions; |
2027 | 2306 | ||
2028 | 2307 | ||
2029 | } | 2308 | } |
2030 | else | 2309 | else |
@@ -2032,15 +2311,15 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
2032 | //if (updatedEntities is null) | 2311 | //if (updatedEntities is null) |
2033 | //updatedEntities = new List<BulletXNA.EntityProperties>(); | 2312 | //updatedEntities = new List<BulletXNA.EntityProperties>(); |
2034 | //updatedEntityCount = 0; | 2313 | //updatedEntityCount = 0; |
2035 | 2314 | ||
2036 | 2315 | ||
2037 | //collidersCount = 0; | 2316 | //collidersCount = 0; |
2038 | 2317 | ||
2039 | updatedEntities = new EntityProperties[0]; | 2318 | updatedEntities = new EntityProperties[0]; |
2040 | 2319 | ||
2041 | 2320 | ||
2042 | colliders = new CollisionDesc[0]; | 2321 | colliders = new CollisionDesc[0]; |
2043 | 2322 | ||
2044 | } | 2323 | } |
2045 | return numSimSteps; | 2324 | return numSimSteps; |
2046 | } | 2325 | } |
@@ -2048,7 +2327,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
2048 | { | 2327 | { |
2049 | IOverlappingPairCache cache = obj.GetOverlappingPairCache(); | 2328 | IOverlappingPairCache cache = obj.GetOverlappingPairCache(); |
2050 | ObjectArray<BroadphasePair> pairs = cache.GetOverlappingPairArray(); | 2329 | ObjectArray<BroadphasePair> pairs = cache.GetOverlappingPairArray(); |
2051 | 2330 | ||
2052 | DiscreteDynamicsWorld world = (PhysicsScene.World as BulletWorldXNA).world; | 2331 | DiscreteDynamicsWorld world = (PhysicsScene.World as BulletWorldXNA).world; |
2053 | PersistentManifoldArray manifoldArray = new PersistentManifoldArray(); | 2332 | PersistentManifoldArray manifoldArray = new PersistentManifoldArray(); |
2054 | BroadphasePair collisionPair; | 2333 | BroadphasePair collisionPair; |
@@ -2060,7 +2339,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
2060 | ManifoldPoint pt; | 2339 | ManifoldPoint pt; |
2061 | 2340 | ||
2062 | int numPairs = pairs.Count; | 2341 | int numPairs = pairs.Count; |
2063 | 2342 | ||
2064 | for (int i = 0; i < numPairs; i++) | 2343 | for (int i = 0; i < numPairs; i++) |
2065 | { | 2344 | { |
2066 | manifoldArray.Clear(); | 2345 | manifoldArray.Clear(); |
@@ -2069,7 +2348,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
2069 | collisionPair = world.GetPairCache().FindPair(pairs[i].m_pProxy0, pairs[i].m_pProxy1); | 2348 | collisionPair = world.GetPairCache().FindPair(pairs[i].m_pProxy0, pairs[i].m_pProxy1); |
2070 | if (collisionPair == null) | 2349 | if (collisionPair == null) |
2071 | continue; | 2350 | continue; |
2072 | 2351 | ||
2073 | collisionPair.m_algorithm.GetAllContactManifolds(manifoldArray); | 2352 | collisionPair.m_algorithm.GetAllContactManifolds(manifoldArray); |
2074 | for (int j = 0; j < manifoldArray.Count; j++) | 2353 | for (int j = 0; j < manifoldArray.Count; j++) |
2075 | { | 2354 | { |
@@ -2092,7 +2371,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
2092 | } | 2371 | } |
2093 | private static void RecordCollision(BSAPIXNA world, CollisionObject objA, CollisionObject objB, IndexedVector3 contact, IndexedVector3 norm, float penetration) | 2372 | private static void RecordCollision(BSAPIXNA world, CollisionObject objA, CollisionObject objB, IndexedVector3 contact, IndexedVector3 norm, float penetration) |
2094 | { | 2373 | { |
2095 | 2374 | ||
2096 | IndexedVector3 contactNormal = norm; | 2375 | IndexedVector3 contactNormal = norm; |
2097 | if ((objA.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0 && | 2376 | if ((objA.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0 && |
2098 | (objB.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0) | 2377 | (objB.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0) |
@@ -2162,11 +2441,11 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
2162 | if (NotMe is BulletBodyXNA && NotMe.HasPhysicalBody) | 2441 | if (NotMe is BulletBodyXNA && NotMe.HasPhysicalBody) |
2163 | { | 2442 | { |
2164 | CollisionObject AvoidBody = (NotMe as BulletBodyXNA).body; | 2443 | CollisionObject AvoidBody = (NotMe as BulletBodyXNA).body; |
2165 | 2444 | ||
2166 | IndexedVector3 rOrigin = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z); | 2445 | IndexedVector3 rOrigin = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z); |
2167 | IndexedVector3 rEnd = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z - pRayHeight); | 2446 | IndexedVector3 rEnd = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z - pRayHeight); |
2168 | using ( | 2447 | using ( |
2169 | ClosestNotMeRayResultCallback rayCallback = | 2448 | ClosestNotMeRayResultCallback rayCallback = |
2170 | new ClosestNotMeRayResultCallback(rOrigin, rEnd, AvoidBody) | 2449 | new ClosestNotMeRayResultCallback(rOrigin, rEnd, AvoidBody) |
2171 | ) | 2450 | ) |
2172 | { | 2451 | { |
@@ -2182,9 +2461,9 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
2182 | return false; | 2461 | return false; |
2183 | } | 2462 | } |
2184 | } | 2463 | } |
2185 | |||
2186 | 2464 | ||
2187 | 2465 | ||
2466 | |||
2188 | 2467 | ||
2189 | public class SimMotionState : DefaultMotionState | 2468 | public class SimMotionState : DefaultMotionState |
2190 | { | 2469 | { |
@@ -2277,12 +2556,12 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
2277 | m_lastProperties = m_properties; | 2556 | m_lastProperties = m_properties; |
2278 | if (m_world.LastEntityProperty < m_world.UpdatedObjects.Length) | 2557 | if (m_world.LastEntityProperty < m_world.UpdatedObjects.Length) |
2279 | m_world.UpdatedObjects[m_world.LastEntityProperty++]=(m_properties); | 2558 | m_world.UpdatedObjects[m_world.LastEntityProperty++]=(m_properties); |
2280 | 2559 | ||
2281 | //(*m_updatesThisFrame)[m_properties.ID] = &m_properties; | 2560 | //(*m_updatesThisFrame)[m_properties.ID] = &m_properties; |
2282 | } | 2561 | } |
2283 | 2562 | ||
2284 | 2563 | ||
2285 | 2564 | ||
2286 | 2565 | ||
2287 | } | 2566 | } |
2288 | public override void SetRigidBody(RigidBody body) | 2567 | public override void SetRigidBody(RigidBody body) |
@@ -2305,7 +2584,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
2305 | (((v1.Z - nEpsilon) < v2.Z) && (v2.Z < (v1.Z + nEpsilon))) && | 2584 | (((v1.Z - nEpsilon) < v2.Z) && (v2.Z < (v1.Z + nEpsilon))) && |
2306 | (((v1.W - nEpsilon) < v2.W) && (v2.W < (v1.W + nEpsilon))); | 2585 | (((v1.W - nEpsilon) < v2.W) && (v2.W < (v1.W + nEpsilon))); |
2307 | } | 2586 | } |
2308 | 2587 | ||
2309 | } | 2588 | } |
2310 | } | 2589 | } |
2311 | 2590 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs new file mode 100755 index 0000000..1bcf879 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs | |||
@@ -0,0 +1,411 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Text; | ||
32 | |||
33 | using OpenSim.Region.Physics.Manager; | ||
34 | |||
35 | using OMV = OpenMetaverse; | ||
36 | |||
37 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
38 | { | ||
39 | public class BSActorAvatarMove : BSActor | ||
40 | { | ||
41 | BSVMotor m_velocityMotor; | ||
42 | |||
43 | // Set to true if we think we're going up stairs. | ||
44 | // This state is remembered because collisions will turn on and off as we go up stairs. | ||
45 | int m_walkingUpStairs; | ||
46 | // The amount the step up is applying. Used to smooth stair walking. | ||
47 | float m_lastStepUp; | ||
48 | |||
49 | // Jumping happens over several frames. If use applies up force while colliding, start the | ||
50 | // jump and allow the jump to continue for this number of frames. | ||
51 | int m_jumpFrames = 0; | ||
52 | float m_jumpVelocity = 0f; | ||
53 | |||
54 | public BSActorAvatarMove(BSScene physicsScene, BSPhysObject pObj, string actorName) | ||
55 | : base(physicsScene, pObj, actorName) | ||
56 | { | ||
57 | m_velocityMotor = null; | ||
58 | m_walkingUpStairs = 0; | ||
59 | m_physicsScene.DetailLog("{0},BSActorAvatarMove,constructor", m_controllingPrim.LocalID); | ||
60 | } | ||
61 | |||
62 | // BSActor.isActive | ||
63 | public override bool isActive | ||
64 | { | ||
65 | get { return Enabled && m_controllingPrim.IsPhysicallyActive; } | ||
66 | } | ||
67 | |||
68 | // Release any connections and resources used by the actor. | ||
69 | // BSActor.Dispose() | ||
70 | public override void Dispose() | ||
71 | { | ||
72 | base.SetEnabled(false); | ||
73 | // Now that turned off, remove any state we have in the scene. | ||
74 | Refresh(); | ||
75 | } | ||
76 | |||
77 | // Called when physical parameters (properties set in Bullet) need to be re-applied. | ||
78 | // Called at taint-time. | ||
79 | // BSActor.Refresh() | ||
80 | public override void Refresh() | ||
81 | { | ||
82 | m_physicsScene.DetailLog("{0},BSActorAvatarMove,refresh", m_controllingPrim.LocalID); | ||
83 | |||
84 | // If the object is physically active, add the hoverer prestep action | ||
85 | if (isActive) | ||
86 | { | ||
87 | ActivateAvatarMove(); | ||
88 | } | ||
89 | else | ||
90 | { | ||
91 | DeactivateAvatarMove(); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). | ||
96 | // Register a prestep action to restore physical requirements before the next simulation step. | ||
97 | // Called at taint-time. | ||
98 | // BSActor.RemoveDependencies() | ||
99 | public override void RemoveDependencies() | ||
100 | { | ||
101 | // Nothing to do for the hoverer since it is all software at pre-step action time. | ||
102 | } | ||
103 | |||
104 | // Usually called when target velocity changes to set the current velocity and the target | ||
105 | // into the movement motor. | ||
106 | public void SetVelocityAndTarget(OMV.Vector3 vel, OMV.Vector3 targ, bool inTaintTime) | ||
107 | { | ||
108 | m_physicsScene.TaintedObject(inTaintTime, m_controllingPrim.LocalID, "BSActorAvatarMove.setVelocityAndTarget", delegate() | ||
109 | { | ||
110 | if (m_velocityMotor != null) | ||
111 | { | ||
112 | m_velocityMotor.Reset(); | ||
113 | m_velocityMotor.SetTarget(targ); | ||
114 | m_velocityMotor.SetCurrent(vel); | ||
115 | m_velocityMotor.Enabled = true; | ||
116 | } | ||
117 | }); | ||
118 | } | ||
119 | |||
120 | // If a hover motor has not been created, create one and start the hovering. | ||
121 | private void ActivateAvatarMove() | ||
122 | { | ||
123 | if (m_velocityMotor == null) | ||
124 | { | ||
125 | // Infinite decay and timescale values so motor only changes current to target values. | ||
126 | m_velocityMotor = new BSVMotor("BSCharacter.Velocity", | ||
127 | 0.2f, // time scale | ||
128 | BSMotor.Infinite, // decay time scale | ||
129 | 1f // efficiency | ||
130 | ); | ||
131 | m_velocityMotor.ErrorZeroThreshold = BSParam.AvatarStopZeroThreshold; | ||
132 | // _velocityMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. | ||
133 | SetVelocityAndTarget(m_controllingPrim.RawVelocity, m_controllingPrim.TargetVelocity, true /* inTaintTime */); | ||
134 | |||
135 | m_physicsScene.BeforeStep += Mover; | ||
136 | m_controllingPrim.OnPreUpdateProperty += Process_OnPreUpdateProperty; | ||
137 | |||
138 | m_walkingUpStairs = 0; | ||
139 | } | ||
140 | } | ||
141 | |||
142 | private void DeactivateAvatarMove() | ||
143 | { | ||
144 | if (m_velocityMotor != null) | ||
145 | { | ||
146 | m_controllingPrim.OnPreUpdateProperty -= Process_OnPreUpdateProperty; | ||
147 | m_physicsScene.BeforeStep -= Mover; | ||
148 | m_velocityMotor = null; | ||
149 | } | ||
150 | } | ||
151 | |||
152 | // Called just before the simulation step. Update the vertical position for hoverness. | ||
153 | private void Mover(float timeStep) | ||
154 | { | ||
155 | // Don't do movement while the object is selected. | ||
156 | if (!isActive) | ||
157 | return; | ||
158 | |||
159 | // TODO: Decide if the step parameters should be changed depending on the avatar's | ||
160 | // state (flying, colliding, ...). There is code in ODE to do this. | ||
161 | |||
162 | // COMMENTARY: when the user is making the avatar walk, except for falling, the velocity | ||
163 | // specified for the avatar is the one that should be used. For falling, if the avatar | ||
164 | // is not flying and is not colliding then it is presumed to be falling and the Z | ||
165 | // component is not fooled with (thus allowing gravity to do its thing). | ||
166 | // When the avatar is standing, though, the user has specified a velocity of zero and | ||
167 | // the avatar should be standing. But if the avatar is pushed by something in the world | ||
168 | // (raising elevator platform, moving vehicle, ...) the avatar should be allowed to | ||
169 | // move. Thus, the velocity cannot be forced to zero. The problem is that small velocity | ||
170 | // errors can creap in and the avatar will slowly float off in some direction. | ||
171 | // So, the problem is that, when an avatar is standing, we cannot tell creaping error | ||
172 | // from real pushing. | ||
173 | // The code below uses whether the collider is static or moving to decide whether to zero motion. | ||
174 | |||
175 | m_velocityMotor.Step(timeStep); | ||
176 | m_controllingPrim.IsStationary = false; | ||
177 | |||
178 | // If we're not supposed to be moving, make sure things are zero. | ||
179 | if (m_velocityMotor.ErrorIsZero() && m_velocityMotor.TargetValue == OMV.Vector3.Zero) | ||
180 | { | ||
181 | // The avatar shouldn't be moving | ||
182 | m_velocityMotor.Zero(); | ||
183 | |||
184 | if (m_controllingPrim.IsColliding) | ||
185 | { | ||
186 | // If we are colliding with a stationary object, presume we're standing and don't move around | ||
187 | if (!m_controllingPrim.ColliderIsMoving && !m_controllingPrim.ColliderIsVolumeDetect) | ||
188 | { | ||
189 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,collidingWithStationary,zeroingMotion", m_controllingPrim.LocalID); | ||
190 | m_controllingPrim.IsStationary = true; | ||
191 | m_controllingPrim.ZeroMotion(true /* inTaintTime */); | ||
192 | } | ||
193 | |||
194 | // Standing has more friction on the ground | ||
195 | if (m_controllingPrim.Friction != BSParam.AvatarStandingFriction) | ||
196 | { | ||
197 | m_controllingPrim.Friction = BSParam.AvatarStandingFriction; | ||
198 | m_physicsScene.PE.SetFriction(m_controllingPrim.PhysBody, m_controllingPrim.Friction); | ||
199 | } | ||
200 | } | ||
201 | else | ||
202 | { | ||
203 | if (m_controllingPrim.Flying) | ||
204 | { | ||
205 | // Flying and not colliding and velocity nearly zero. | ||
206 | m_controllingPrim.ZeroMotion(true /* inTaintTime */); | ||
207 | } | ||
208 | } | ||
209 | |||
210 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1},colliding={2}", | ||
211 | m_controllingPrim.LocalID, m_velocityMotor.TargetValue, m_controllingPrim.IsColliding); | ||
212 | } | ||
213 | else | ||
214 | { | ||
215 | // Supposed to be moving. | ||
216 | OMV.Vector3 stepVelocity = m_velocityMotor.CurrentValue; | ||
217 | |||
218 | if (m_controllingPrim.Friction != BSParam.AvatarFriction) | ||
219 | { | ||
220 | // Probably starting to walk. Set friction to moving friction. | ||
221 | m_controllingPrim.Friction = BSParam.AvatarFriction; | ||
222 | m_physicsScene.PE.SetFriction(m_controllingPrim.PhysBody, m_controllingPrim.Friction); | ||
223 | } | ||
224 | |||
225 | if (!m_controllingPrim.Flying && !m_controllingPrim.IsColliding) | ||
226 | { | ||
227 | stepVelocity.Z = m_controllingPrim.RawVelocity.Z; | ||
228 | } | ||
229 | |||
230 | |||
231 | // Colliding and not flying with an upward force. The avatar must be trying to jump. | ||
232 | if (!m_controllingPrim.Flying && m_controllingPrim.IsColliding && stepVelocity.Z > 0) | ||
233 | { | ||
234 | // We allow the upward force to happen for this many frames. | ||
235 | m_jumpFrames = BSParam.AvatarJumpFrames; | ||
236 | m_jumpVelocity = stepVelocity.Z; | ||
237 | } | ||
238 | |||
239 | // The case where the avatar is not colliding and is not flying is special. | ||
240 | // The avatar is either falling or jumping and the user can be applying force to the avatar | ||
241 | // (force in some direction or force up or down). | ||
242 | // If the avatar has negative Z velocity and is not colliding, presume we're falling and keep the velocity. | ||
243 | // If the user is trying to apply upward force but we're not colliding, assume the avatar | ||
244 | // is trying to jump and don't apply the upward force if not touching the ground any more. | ||
245 | if (!m_controllingPrim.Flying && !m_controllingPrim.IsColliding) | ||
246 | { | ||
247 | // If upward velocity is being applied, this must be a jump and only allow that to go on so long | ||
248 | if (m_jumpFrames > 0) | ||
249 | { | ||
250 | // Since not touching the ground, only apply upward force for so long. | ||
251 | m_jumpFrames--; | ||
252 | stepVelocity.Z = m_jumpVelocity; | ||
253 | } | ||
254 | else | ||
255 | { | ||
256 | // Since we're not affected by anything, whatever vertical motion the avatar has, continue that. | ||
257 | stepVelocity.Z = m_controllingPrim.RawVelocity.Z; | ||
258 | } | ||
259 | // DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity); | ||
260 | } | ||
261 | |||
262 | // 'stepVelocity' is now the speed we'd like the avatar to move in. Turn that into an instantanous force. | ||
263 | OMV.Vector3 moveForce = (stepVelocity - m_controllingPrim.RawVelocity) * m_controllingPrim.Mass; | ||
264 | |||
265 | // Add special movement force to allow avatars to walk up stepped surfaces. | ||
266 | moveForce += WalkUpStairs(); | ||
267 | |||
268 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", | ||
269 | m_controllingPrim.LocalID, stepVelocity, m_controllingPrim.RawVelocity, m_controllingPrim.Mass, moveForce); | ||
270 | m_physicsScene.PE.ApplyCentralImpulse(m_controllingPrim.PhysBody, moveForce); | ||
271 | } | ||
272 | } | ||
273 | |||
274 | // Called just as the property update is received from the physics engine. | ||
275 | // Do any mode necessary for avatar movement. | ||
276 | private void Process_OnPreUpdateProperty(ref EntityProperties entprop) | ||
277 | { | ||
278 | // Don't change position if standing on a stationary object. | ||
279 | if (m_controllingPrim.IsStationary) | ||
280 | { | ||
281 | entprop.Position = m_controllingPrim.RawPosition; | ||
282 | entprop.Velocity = OMV.Vector3.Zero; | ||
283 | m_physicsScene.PE.SetTranslation(m_controllingPrim.PhysBody, entprop.Position, entprop.Rotation); | ||
284 | } | ||
285 | |||
286 | } | ||
287 | |||
288 | // Decide if the character is colliding with a low object and compute a force to pop the | ||
289 | // avatar up so it can walk up and over the low objects. | ||
290 | private OMV.Vector3 WalkUpStairs() | ||
291 | { | ||
292 | OMV.Vector3 ret = OMV.Vector3.Zero; | ||
293 | |||
294 | m_physicsScene.DetailLog("{0},BSCharacter.WalkUpStairs,IsColliding={1},flying={2},targSpeed={3},collisions={4},avHeight={5}", | ||
295 | m_controllingPrim.LocalID, m_controllingPrim.IsColliding, m_controllingPrim.Flying, | ||
296 | m_controllingPrim.TargetVelocitySpeed, m_controllingPrim.CollisionsLastTick.Count, m_controllingPrim.Size.Z); | ||
297 | |||
298 | // Check for stairs climbing if colliding, not flying and moving forward | ||
299 | if ( m_controllingPrim.IsColliding | ||
300 | && !m_controllingPrim.Flying | ||
301 | && m_controllingPrim.TargetVelocitySpeed > 0.1f ) | ||
302 | { | ||
303 | // The range near the character's feet where we will consider stairs | ||
304 | // float nearFeetHeightMin = m_controllingPrim.RawPosition.Z - (m_controllingPrim.Size.Z / 2f) + 0.05f; | ||
305 | // Note: there is a problem with the computation of the capsule height. Thus RawPosition is off | ||
306 | // from the height. Revisit size and this computation when height is scaled properly. | ||
307 | float nearFeetHeightMin = m_controllingPrim.RawPosition.Z - (m_controllingPrim.Size.Z / 2f) - 0.05f; | ||
308 | float nearFeetHeightMax = nearFeetHeightMin + BSParam.AvatarStepHeight; | ||
309 | |||
310 | // Look for a collision point that is near the character's feet and is oriented the same as the charactor is. | ||
311 | // Find the highest 'good' collision. | ||
312 | OMV.Vector3 highestTouchPosition = OMV.Vector3.Zero; | ||
313 | foreach (KeyValuePair<uint, ContactPoint> kvp in m_controllingPrim.CollisionsLastTick.m_objCollisionList) | ||
314 | { | ||
315 | // Don't care about collisions with the terrain | ||
316 | if (kvp.Key > m_physicsScene.TerrainManager.HighestTerrainID) | ||
317 | { | ||
318 | BSPhysObject collisionObject; | ||
319 | if (m_physicsScene.PhysObjects.TryGetValue(kvp.Key, out collisionObject)) | ||
320 | { | ||
321 | if (!collisionObject.IsVolumeDetect) | ||
322 | { | ||
323 | OMV.Vector3 touchPosition = kvp.Value.Position; | ||
324 | m_physicsScene.DetailLog("{0},BSCharacter.WalkUpStairs,min={1},max={2},touch={3}", | ||
325 | m_controllingPrim.LocalID, nearFeetHeightMin, nearFeetHeightMax, touchPosition); | ||
326 | if (touchPosition.Z >= nearFeetHeightMin && touchPosition.Z <= nearFeetHeightMax) | ||
327 | { | ||
328 | // This contact is within the 'near the feet' range. | ||
329 | // The normal should be our contact point to the object so it is pointing away | ||
330 | // thus the difference between our facing orientation and the normal should be small. | ||
331 | OMV.Vector3 directionFacing = OMV.Vector3.UnitX * m_controllingPrim.RawOrientation; | ||
332 | OMV.Vector3 touchNormal = OMV.Vector3.Normalize(kvp.Value.SurfaceNormal); | ||
333 | float diff = Math.Abs(OMV.Vector3.Distance(directionFacing, touchNormal)); | ||
334 | if (diff < BSParam.AvatarStepApproachFactor) | ||
335 | { | ||
336 | if (highestTouchPosition.Z < touchPosition.Z) | ||
337 | highestTouchPosition = touchPosition; | ||
338 | } | ||
339 | } | ||
340 | } | ||
341 | } | ||
342 | } | ||
343 | } | ||
344 | m_walkingUpStairs = 0; | ||
345 | // If there is a good step sensing, move the avatar over the step. | ||
346 | if (highestTouchPosition != OMV.Vector3.Zero) | ||
347 | { | ||
348 | // Remember that we are going up stairs. This is needed because collisions | ||
349 | // will stop when we move up so this smoothes out that effect. | ||
350 | m_walkingUpStairs = BSParam.AvatarStepSmoothingSteps; | ||
351 | |||
352 | m_lastStepUp = highestTouchPosition.Z - nearFeetHeightMin; | ||
353 | ret = ComputeStairCorrection(m_lastStepUp); | ||
354 | m_physicsScene.DetailLog("{0},BSCharacter.WalkUpStairs,touchPos={1},nearFeetMin={2},ret={3}", | ||
355 | m_controllingPrim.LocalID, highestTouchPosition, nearFeetHeightMin, ret); | ||
356 | } | ||
357 | } | ||
358 | else | ||
359 | { | ||
360 | // If we used to be going up stairs but are not now, smooth the case where collision goes away while | ||
361 | // we are bouncing up the stairs. | ||
362 | if (m_walkingUpStairs > 0) | ||
363 | { | ||
364 | m_walkingUpStairs--; | ||
365 | ret = ComputeStairCorrection(m_lastStepUp); | ||
366 | } | ||
367 | } | ||
368 | |||
369 | return ret; | ||
370 | } | ||
371 | |||
372 | private OMV.Vector3 ComputeStairCorrection(float stepUp) | ||
373 | { | ||
374 | OMV.Vector3 ret = OMV.Vector3.Zero; | ||
375 | OMV.Vector3 displacement = OMV.Vector3.Zero; | ||
376 | |||
377 | if (stepUp > 0f) | ||
378 | { | ||
379 | // Found the stairs contact point. Push up a little to raise the character. | ||
380 | if (BSParam.AvatarStepForceFactor > 0f) | ||
381 | { | ||
382 | float upForce = stepUp * m_controllingPrim.Mass * BSParam.AvatarStepForceFactor; | ||
383 | ret = new OMV.Vector3(0f, 0f, upForce); | ||
384 | } | ||
385 | |||
386 | // Also move the avatar up for the new height | ||
387 | if (BSParam.AvatarStepUpCorrectionFactor > 0f) | ||
388 | { | ||
389 | // Move the avatar up related to the height of the collision | ||
390 | displacement = new OMV.Vector3(0f, 0f, stepUp * BSParam.AvatarStepUpCorrectionFactor); | ||
391 | m_controllingPrim.ForcePosition = m_controllingPrim.RawPosition + displacement; | ||
392 | } | ||
393 | else | ||
394 | { | ||
395 | if (BSParam.AvatarStepUpCorrectionFactor < 0f) | ||
396 | { | ||
397 | // Move the avatar up about the specified step height | ||
398 | displacement = new OMV.Vector3(0f, 0f, BSParam.AvatarStepHeight); | ||
399 | m_controllingPrim.ForcePosition = m_controllingPrim.RawPosition + displacement; | ||
400 | } | ||
401 | } | ||
402 | m_physicsScene.DetailLog("{0},BSCharacter.WalkUpStairs.ComputeStairCorrection,disp={1},force={2}", | ||
403 | m_controllingPrim.LocalID, displacement, ret); | ||
404 | |||
405 | } | ||
406 | return ret; | ||
407 | } | ||
408 | } | ||
409 | } | ||
410 | |||
411 | |||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs new file mode 100755 index 0000000..8a79809 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs | |||
@@ -0,0 +1,173 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Text; | ||
32 | |||
33 | using OpenSim.Region.Physics.Manager; | ||
34 | |||
35 | using OMV = OpenMetaverse; | ||
36 | |||
37 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
38 | { | ||
39 | public class BSActorHover : BSActor | ||
40 | { | ||
41 | private BSFMotor m_hoverMotor; | ||
42 | |||
43 | public BSActorHover(BSScene physicsScene, BSPhysObject pObj, string actorName) | ||
44 | : base(physicsScene, pObj, actorName) | ||
45 | { | ||
46 | m_hoverMotor = null; | ||
47 | m_physicsScene.DetailLog("{0},BSActorHover,constructor", m_controllingPrim.LocalID); | ||
48 | } | ||
49 | |||
50 | // BSActor.isActive | ||
51 | public override bool isActive | ||
52 | { | ||
53 | get { return Enabled; } | ||
54 | } | ||
55 | |||
56 | // Release any connections and resources used by the actor. | ||
57 | // BSActor.Dispose() | ||
58 | public override void Dispose() | ||
59 | { | ||
60 | Enabled = false; | ||
61 | } | ||
62 | |||
63 | // Called when physical parameters (properties set in Bullet) need to be re-applied. | ||
64 | // Called at taint-time. | ||
65 | // BSActor.Refresh() | ||
66 | public override void Refresh() | ||
67 | { | ||
68 | m_physicsScene.DetailLog("{0},BSActorHover,refresh", m_controllingPrim.LocalID); | ||
69 | |||
70 | // If not active any more, turn me off | ||
71 | if (!m_controllingPrim.HoverActive) | ||
72 | { | ||
73 | SetEnabled(false); | ||
74 | } | ||
75 | |||
76 | // If the object is physically active, add the hoverer prestep action | ||
77 | if (isActive) | ||
78 | { | ||
79 | ActivateHover(); | ||
80 | } | ||
81 | else | ||
82 | { | ||
83 | DeactivateHover(); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). | ||
88 | // Register a prestep action to restore physical requirements before the next simulation step. | ||
89 | // Called at taint-time. | ||
90 | // BSActor.RemoveDependencies() | ||
91 | public override void RemoveDependencies() | ||
92 | { | ||
93 | // Nothing to do for the hoverer since it is all software at pre-step action time. | ||
94 | } | ||
95 | |||
96 | // If a hover motor has not been created, create one and start the hovering. | ||
97 | private void ActivateHover() | ||
98 | { | ||
99 | if (m_hoverMotor == null) | ||
100 | { | ||
101 | // Turning the target on | ||
102 | m_hoverMotor = new BSFMotor("BSActorHover", | ||
103 | m_controllingPrim.HoverTau, // timeScale | ||
104 | BSMotor.Infinite, // decay time scale | ||
105 | 1f // efficiency | ||
106 | ); | ||
107 | m_hoverMotor.SetTarget(ComputeCurrentHoverHeight()); | ||
108 | m_hoverMotor.SetCurrent(m_controllingPrim.RawPosition.Z); | ||
109 | m_hoverMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG so motor will output detail log messages. | ||
110 | |||
111 | m_physicsScene.BeforeStep += Hoverer; | ||
112 | } | ||
113 | } | ||
114 | |||
115 | private void DeactivateHover() | ||
116 | { | ||
117 | if (m_hoverMotor != null) | ||
118 | { | ||
119 | m_physicsScene.BeforeStep -= Hoverer; | ||
120 | m_hoverMotor = null; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | // Called just before the simulation step. Update the vertical position for hoverness. | ||
125 | private void Hoverer(float timeStep) | ||
126 | { | ||
127 | // Don't do hovering while the object is selected. | ||
128 | if (!isActive) | ||
129 | return; | ||
130 | |||
131 | m_hoverMotor.SetCurrent(m_controllingPrim.RawPosition.Z); | ||
132 | m_hoverMotor.SetTarget(ComputeCurrentHoverHeight()); | ||
133 | float targetHeight = m_hoverMotor.Step(timeStep); | ||
134 | |||
135 | // 'targetHeight' is where we'd like the Z of the prim to be at this moment. | ||
136 | // Compute the amount of force to push us there. | ||
137 | float moveForce = (targetHeight - m_controllingPrim.RawPosition.Z) * m_controllingPrim.RawMass; | ||
138 | // Undo anything the object thinks it's doing at the moment | ||
139 | moveForce = -m_controllingPrim.RawVelocity.Z * m_controllingPrim.Mass; | ||
140 | |||
141 | m_physicsScene.PE.ApplyCentralImpulse(m_controllingPrim.PhysBody, new OMV.Vector3(0f, 0f, moveForce)); | ||
142 | m_physicsScene.DetailLog("{0},BSPrim.Hover,move,targHt={1},moveForce={2},mass={3}", | ||
143 | m_controllingPrim.LocalID, targetHeight, moveForce, m_controllingPrim.RawMass); | ||
144 | } | ||
145 | |||
146 | // Based on current position, determine what we should be hovering at now. | ||
147 | // Must recompute often. What if we walked offa cliff> | ||
148 | private float ComputeCurrentHoverHeight() | ||
149 | { | ||
150 | float ret = m_controllingPrim.HoverHeight; | ||
151 | float groundHeight = m_physicsScene.TerrainManager.GetTerrainHeightAtXYZ(m_controllingPrim.RawPosition); | ||
152 | |||
153 | switch (m_controllingPrim.HoverType) | ||
154 | { | ||
155 | case PIDHoverType.Ground: | ||
156 | ret = groundHeight + m_controllingPrim.HoverHeight; | ||
157 | break; | ||
158 | case PIDHoverType.GroundAndWater: | ||
159 | float waterHeight = m_physicsScene.TerrainManager.GetWaterLevelAtXYZ(m_controllingPrim.RawPosition); | ||
160 | if (groundHeight > waterHeight) | ||
161 | { | ||
162 | ret = groundHeight + m_controllingPrim.HoverHeight; | ||
163 | } | ||
164 | else | ||
165 | { | ||
166 | ret = waterHeight + m_controllingPrim.HoverHeight; | ||
167 | } | ||
168 | break; | ||
169 | } | ||
170 | return ret; | ||
171 | } | ||
172 | } | ||
173 | } | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs new file mode 100755 index 0000000..8b0fdeb --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs | |||
@@ -0,0 +1,187 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Text; | ||
32 | |||
33 | using OMV = OpenMetaverse; | ||
34 | |||
35 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
36 | { | ||
37 | public class BSActorLockAxis : BSActor | ||
38 | { | ||
39 | BSConstraint LockAxisConstraint = null; | ||
40 | |||
41 | public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) | ||
42 | : base(physicsScene, pObj, actorName) | ||
43 | { | ||
44 | m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID); | ||
45 | LockAxisConstraint = null; | ||
46 | } | ||
47 | |||
48 | // BSActor.isActive | ||
49 | public override bool isActive | ||
50 | { | ||
51 | get { return Enabled && m_controllingPrim.IsPhysicallyActive; } | ||
52 | } | ||
53 | |||
54 | // Release any connections and resources used by the actor. | ||
55 | // BSActor.Dispose() | ||
56 | public override void Dispose() | ||
57 | { | ||
58 | RemoveAxisLockConstraint(); | ||
59 | } | ||
60 | |||
61 | // Called when physical parameters (properties set in Bullet) need to be re-applied. | ||
62 | // Called at taint-time. | ||
63 | // BSActor.Refresh() | ||
64 | public override void Refresh() | ||
65 | { | ||
66 | m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}", | ||
67 | m_controllingPrim.LocalID, m_controllingPrim.LockedAngularAxis, Enabled, m_controllingPrim.IsPhysicallyActive); | ||
68 | // If all the axis are free, we don't need to exist | ||
69 | if (m_controllingPrim.LockedAngularAxis == m_controllingPrim.LockedAxisFree) | ||
70 | { | ||
71 | Enabled = false; | ||
72 | } | ||
73 | |||
74 | // If the object is physically active, add the axis locking constraint | ||
75 | if (isActive) | ||
76 | { | ||
77 | AddAxisLockConstraint(); | ||
78 | } | ||
79 | else | ||
80 | { | ||
81 | RemoveAxisLockConstraint(); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). | ||
86 | // Register a prestep action to restore physical requirements before the next simulation step. | ||
87 | // Called at taint-time. | ||
88 | // BSActor.RemoveDependencies() | ||
89 | public override void RemoveDependencies() | ||
90 | { | ||
91 | if (LockAxisConstraint != null) | ||
92 | { | ||
93 | // If a constraint is set up, remove it from the physical scene | ||
94 | RemoveAxisLockConstraint(); | ||
95 | // Schedule a call before the next simulation step to restore the constraint. | ||
96 | m_physicsScene.PostTaintObject("BSActorLockAxis:" + ActorName, m_controllingPrim.LocalID, delegate() | ||
97 | { | ||
98 | Refresh(); | ||
99 | }); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | private void AddAxisLockConstraint() | ||
104 | { | ||
105 | if (LockAxisConstraint == null) | ||
106 | { | ||
107 | // Lock that axis by creating a 6DOF constraint that has one end in the world and | ||
108 | // the other in the object. | ||
109 | // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817 | ||
110 | // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380 | ||
111 | |||
112 | // Remove any existing axis constraint (just to be sure) | ||
113 | RemoveAxisLockConstraint(); | ||
114 | |||
115 | BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(m_physicsScene.World, m_controllingPrim.PhysBody, | ||
116 | OMV.Vector3.Zero, OMV.Quaternion.Identity, | ||
117 | false /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); | ||
118 | LockAxisConstraint = axisConstrainer; | ||
119 | m_physicsScene.Constraints.AddConstraint(LockAxisConstraint); | ||
120 | |||
121 | // The constraint is tied to the world and oriented to the prim. | ||
122 | |||
123 | // Free to move linearly in the region | ||
124 | OMV.Vector3 linearLow = OMV.Vector3.Zero; | ||
125 | OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize; | ||
126 | if (m_controllingPrim.LockedLinearAxis.X != BSPhysObject.FreeAxis) | ||
127 | { | ||
128 | linearLow.X = m_controllingPrim.RawPosition.X; | ||
129 | linearHigh.X = m_controllingPrim.RawPosition.X; | ||
130 | } | ||
131 | if (m_controllingPrim.LockedLinearAxis.Y != BSPhysObject.FreeAxis) | ||
132 | { | ||
133 | linearLow.Y = m_controllingPrim.RawPosition.Y; | ||
134 | linearHigh.Y = m_controllingPrim.RawPosition.Y; | ||
135 | } | ||
136 | if (m_controllingPrim.LockedLinearAxis.Z != BSPhysObject.FreeAxis) | ||
137 | { | ||
138 | linearLow.Z = m_controllingPrim.RawPosition.Z; | ||
139 | linearHigh.Z = m_controllingPrim.RawPosition.Z; | ||
140 | } | ||
141 | axisConstrainer.SetLinearLimits(linearLow, linearHigh); | ||
142 | |||
143 | // Angular with some axis locked | ||
144 | float fPI = (float)Math.PI; | ||
145 | OMV.Vector3 angularLow = new OMV.Vector3(-fPI, -fPI, -fPI); | ||
146 | OMV.Vector3 angularHigh = new OMV.Vector3(fPI, fPI, fPI); | ||
147 | if (m_controllingPrim.LockedAngularAxis.X != BSPhysObject.FreeAxis) | ||
148 | { | ||
149 | angularLow.X = 0f; | ||
150 | angularHigh.X = 0f; | ||
151 | } | ||
152 | if (m_controllingPrim.LockedAngularAxis.Y != BSPhysObject.FreeAxis) | ||
153 | { | ||
154 | angularLow.Y = 0f; | ||
155 | angularHigh.Y = 0f; | ||
156 | } | ||
157 | if (m_controllingPrim.LockedAngularAxis.Z != BSPhysObject.FreeAxis) | ||
158 | { | ||
159 | angularLow.Z = 0f; | ||
160 | angularHigh.Z = 0f; | ||
161 | } | ||
162 | if (!axisConstrainer.SetAngularLimits(angularLow, angularHigh)) | ||
163 | { | ||
164 | m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", m_controllingPrim.LocalID); | ||
165 | } | ||
166 | |||
167 | m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}", | ||
168 | m_controllingPrim.LocalID, linearLow, linearHigh, angularLow, angularHigh); | ||
169 | |||
170 | // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. | ||
171 | axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); | ||
172 | |||
173 | axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass); | ||
174 | } | ||
175 | } | ||
176 | |||
177 | private void RemoveAxisLockConstraint() | ||
178 | { | ||
179 | if (LockAxisConstraint != null) | ||
180 | { | ||
181 | m_physicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); | ||
182 | LockAxisConstraint = null; | ||
183 | m_physicsScene.DetailLog("{0},BSActorLockAxis.RemoveAxisLockConstraint,destroyingConstraint", m_controllingPrim.LocalID); | ||
184 | } | ||
185 | } | ||
186 | } | ||
187 | } | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs new file mode 100755 index 0000000..bdf4bc0 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs | |||
@@ -0,0 +1,219 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Text; | ||
32 | |||
33 | using OpenSim.Region.Physics.Manager; | ||
34 | |||
35 | using OMV = OpenMetaverse; | ||
36 | |||
37 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
38 | { | ||
39 | public class BSActorMoveToTarget : BSActor | ||
40 | { | ||
41 | private BSVMotor m_targetMotor; | ||
42 | |||
43 | public BSActorMoveToTarget(BSScene physicsScene, BSPhysObject pObj, string actorName) | ||
44 | : base(physicsScene, pObj, actorName) | ||
45 | { | ||
46 | m_targetMotor = null; | ||
47 | m_physicsScene.DetailLog("{0},BSActorMoveToTarget,constructor", m_controllingPrim.LocalID); | ||
48 | } | ||
49 | |||
50 | // BSActor.isActive | ||
51 | public override bool isActive | ||
52 | { | ||
53 | // MoveToTarget only works on physical prims | ||
54 | get { return Enabled && m_controllingPrim.IsPhysicallyActive; } | ||
55 | } | ||
56 | |||
57 | // Release any connections and resources used by the actor. | ||
58 | // BSActor.Dispose() | ||
59 | public override void Dispose() | ||
60 | { | ||
61 | Enabled = false; | ||
62 | } | ||
63 | |||
64 | // Called when physical parameters (properties set in Bullet) need to be re-applied. | ||
65 | // Called at taint-time. | ||
66 | // BSActor.Refresh() | ||
67 | public override void Refresh() | ||
68 | { | ||
69 | m_physicsScene.DetailLog("{0},BSActorMoveToTarget,refresh,enabled={1},active={2},target={3},tau={4}", | ||
70 | m_controllingPrim.LocalID, Enabled, m_controllingPrim.MoveToTargetActive, | ||
71 | m_controllingPrim.MoveToTargetTarget, m_controllingPrim.MoveToTargetTau ); | ||
72 | |||
73 | // If not active any more... | ||
74 | if (!m_controllingPrim.MoveToTargetActive) | ||
75 | { | ||
76 | Enabled = false; | ||
77 | } | ||
78 | |||
79 | if (isActive) | ||
80 | { | ||
81 | ActivateMoveToTarget(); | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | DeactivateMoveToTarget(); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). | ||
90 | // Register a prestep action to restore physical requirements before the next simulation step. | ||
91 | // Called at taint-time. | ||
92 | // BSActor.RemoveDependencies() | ||
93 | public override void RemoveDependencies() | ||
94 | { | ||
95 | // Nothing to do for the moveToTarget since it is all software at pre-step action time. | ||
96 | } | ||
97 | |||
98 | // If a hover motor has not been created, create one and start the hovering. | ||
99 | private void ActivateMoveToTarget() | ||
100 | { | ||
101 | if (m_targetMotor == null) | ||
102 | { | ||
103 | // We're taking over after this. | ||
104 | m_controllingPrim.ZeroMotion(true); | ||
105 | |||
106 | /* Someday use the PID controller | ||
107 | m_targetMotor = new BSPIDVMotor("BSActorMoveToTarget-" + m_controllingPrim.LocalID.ToString()); | ||
108 | m_targetMotor.TimeScale = m_controllingPrim.MoveToTargetTau; | ||
109 | m_targetMotor.Efficiency = 1f; | ||
110 | */ | ||
111 | m_targetMotor = new BSVMotor("BSActorMoveToTarget-" + m_controllingPrim.LocalID.ToString(), | ||
112 | m_controllingPrim.MoveToTargetTau, // timeScale | ||
113 | BSMotor.Infinite, // decay time scale | ||
114 | 1f // efficiency | ||
115 | ); | ||
116 | m_targetMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG so motor will output detail log messages. | ||
117 | m_targetMotor.SetTarget(m_controllingPrim.MoveToTargetTarget); | ||
118 | m_targetMotor.SetCurrent(m_controllingPrim.RawPosition); | ||
119 | |||
120 | // m_physicsScene.BeforeStep += Mover; | ||
121 | m_physicsScene.BeforeStep += Mover2; | ||
122 | } | ||
123 | else | ||
124 | { | ||
125 | // If already allocated, make sure the target and other paramters are current | ||
126 | m_targetMotor.SetTarget(m_controllingPrim.MoveToTargetTarget); | ||
127 | m_targetMotor.SetCurrent(m_controllingPrim.RawPosition); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | private void DeactivateMoveToTarget() | ||
132 | { | ||
133 | if (m_targetMotor != null) | ||
134 | { | ||
135 | // m_physicsScene.BeforeStep -= Mover; | ||
136 | m_physicsScene.BeforeStep -= Mover2; | ||
137 | m_targetMotor = null; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | // Origional mover that set the objects position to move to the target. | ||
142 | // The problem was that gravity would keep trying to push the object down so | ||
143 | // the overall downward velocity would increase to infinity. | ||
144 | // Called just before the simulation step. | ||
145 | private void Mover(float timeStep) | ||
146 | { | ||
147 | // Don't do hovering while the object is selected. | ||
148 | if (!isActive) | ||
149 | return; | ||
150 | |||
151 | OMV.Vector3 origPosition = m_controllingPrim.RawPosition; // DEBUG DEBUG (for printout below) | ||
152 | |||
153 | // 'movePosition' is where we'd like the prim to be at this moment. | ||
154 | OMV.Vector3 movePosition = m_controllingPrim.RawPosition + m_targetMotor.Step(timeStep); | ||
155 | |||
156 | // If we are very close to our target, turn off the movement motor. | ||
157 | if (m_targetMotor.ErrorIsZero()) | ||
158 | { | ||
159 | m_physicsScene.DetailLog("{0},BSActorMoveToTarget.Mover,zeroMovement,movePos={1},pos={2},mass={3}", | ||
160 | m_controllingPrim.LocalID, movePosition, m_controllingPrim.RawPosition, m_controllingPrim.Mass); | ||
161 | m_controllingPrim.ForcePosition = m_targetMotor.TargetValue; | ||
162 | m_controllingPrim.ForceVelocity = OMV.Vector3.Zero; | ||
163 | // Setting the position does not cause the physics engine to generate a property update. Force it. | ||
164 | m_physicsScene.PE.PushUpdate(m_controllingPrim.PhysBody); | ||
165 | } | ||
166 | else | ||
167 | { | ||
168 | m_controllingPrim.ForcePosition = movePosition; | ||
169 | // Setting the position does not cause the physics engine to generate a property update. Force it. | ||
170 | m_physicsScene.PE.PushUpdate(m_controllingPrim.PhysBody); | ||
171 | } | ||
172 | m_physicsScene.DetailLog("{0},BSActorMoveToTarget.Mover,move,fromPos={1},movePos={2}", | ||
173 | m_controllingPrim.LocalID, origPosition, movePosition); | ||
174 | } | ||
175 | |||
176 | // Version of mover that applies forces to move the physical object to the target. | ||
177 | // Also overcomes gravity so the object doesn't just drop to the ground. | ||
178 | // Called just before the simulation step. | ||
179 | private void Mover2(float timeStep) | ||
180 | { | ||
181 | // Don't do hovering while the object is selected. | ||
182 | if (!isActive) | ||
183 | return; | ||
184 | |||
185 | OMV.Vector3 origPosition = m_controllingPrim.RawPosition; // DEBUG DEBUG (for printout below) | ||
186 | OMV.Vector3 addedForce = OMV.Vector3.Zero; | ||
187 | |||
188 | // CorrectionVector is the movement vector required this step | ||
189 | OMV.Vector3 correctionVector = m_targetMotor.Step(timeStep, m_controllingPrim.RawPosition); | ||
190 | |||
191 | // If we are very close to our target, turn off the movement motor. | ||
192 | if (m_targetMotor.ErrorIsZero()) | ||
193 | { | ||
194 | m_physicsScene.DetailLog("{0},BSActorMoveToTarget.Mover3,zeroMovement,pos={1},mass={2}", | ||
195 | m_controllingPrim.LocalID, m_controllingPrim.RawPosition, m_controllingPrim.Mass); | ||
196 | m_controllingPrim.ForcePosition = m_targetMotor.TargetValue; | ||
197 | m_controllingPrim.ForceVelocity = OMV.Vector3.Zero; | ||
198 | // Setting the position does not cause the physics engine to generate a property update. Force it. | ||
199 | m_physicsScene.PE.PushUpdate(m_controllingPrim.PhysBody); | ||
200 | } | ||
201 | else | ||
202 | { | ||
203 | // First force to move us there -- the motor return a timestep scaled value. | ||
204 | addedForce = correctionVector / timeStep; | ||
205 | // Remove the existing velocity (only the moveToTarget force counts) | ||
206 | addedForce -= m_controllingPrim.RawVelocity; | ||
207 | // Overcome gravity. | ||
208 | addedForce -= m_controllingPrim.Gravity; | ||
209 | |||
210 | // Add enough force to overcome the mass of the object | ||
211 | addedForce *= m_controllingPrim.Mass; | ||
212 | |||
213 | m_controllingPrim.AddForce(addedForce, false /* pushForce */, true /* inTaintTime */); | ||
214 | } | ||
215 | m_physicsScene.DetailLog("{0},BSActorMoveToTarget.Mover3,move,fromPos={1},addedForce={2}", | ||
216 | m_controllingPrim.LocalID, origPosition, addedForce); | ||
217 | } | ||
218 | } | ||
219 | } | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs new file mode 100755 index 0000000..96fa0b6 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs | |||
@@ -0,0 +1,137 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Text; | ||
32 | |||
33 | using OpenSim.Region.Physics.Manager; | ||
34 | |||
35 | using OMV = OpenMetaverse; | ||
36 | |||
37 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
38 | { | ||
39 | public class BSActorSetForce : BSActor | ||
40 | { | ||
41 | BSFMotor m_forceMotor; | ||
42 | |||
43 | public BSActorSetForce(BSScene physicsScene, BSPhysObject pObj, string actorName) | ||
44 | : base(physicsScene, pObj, actorName) | ||
45 | { | ||
46 | m_forceMotor = null; | ||
47 | m_physicsScene.DetailLog("{0},BSActorSetForce,constructor", m_controllingPrim.LocalID); | ||
48 | } | ||
49 | |||
50 | // BSActor.isActive | ||
51 | public override bool isActive | ||
52 | { | ||
53 | get { return Enabled && m_controllingPrim.IsPhysicallyActive; } | ||
54 | } | ||
55 | |||
56 | // Release any connections and resources used by the actor. | ||
57 | // BSActor.Dispose() | ||
58 | public override void Dispose() | ||
59 | { | ||
60 | Enabled = false; | ||
61 | } | ||
62 | |||
63 | // Called when physical parameters (properties set in Bullet) need to be re-applied. | ||
64 | // Called at taint-time. | ||
65 | // BSActor.Refresh() | ||
66 | public override void Refresh() | ||
67 | { | ||
68 | m_physicsScene.DetailLog("{0},BSActorSetForce,refresh", m_controllingPrim.LocalID); | ||
69 | |||
70 | // If not active any more, get rid of me (shouldn't ever happen, but just to be safe) | ||
71 | if (m_controllingPrim.RawForce == OMV.Vector3.Zero) | ||
72 | { | ||
73 | m_physicsScene.DetailLog("{0},BSActorSetForce,refresh,notSetForce,removing={1}", m_controllingPrim.LocalID, ActorName); | ||
74 | Enabled = false; | ||
75 | return; | ||
76 | } | ||
77 | |||
78 | // If the object is physically active, add the hoverer prestep action | ||
79 | if (isActive) | ||
80 | { | ||
81 | ActivateSetForce(); | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | DeactivateSetForce(); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). | ||
90 | // Register a prestep action to restore physical requirements before the next simulation step. | ||
91 | // Called at taint-time. | ||
92 | // BSActor.RemoveDependencies() | ||
93 | public override void RemoveDependencies() | ||
94 | { | ||
95 | // Nothing to do for the hoverer since it is all software at pre-step action time. | ||
96 | } | ||
97 | |||
98 | // If a hover motor has not been created, create one and start the hovering. | ||
99 | private void ActivateSetForce() | ||
100 | { | ||
101 | if (m_forceMotor == null) | ||
102 | { | ||
103 | // A fake motor that might be used someday | ||
104 | m_forceMotor = new BSFMotor("setForce", 1f, 1f, 1f); | ||
105 | |||
106 | m_physicsScene.BeforeStep += Mover; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | private void DeactivateSetForce() | ||
111 | { | ||
112 | if (m_forceMotor != null) | ||
113 | { | ||
114 | m_physicsScene.BeforeStep -= Mover; | ||
115 | m_forceMotor = null; | ||
116 | } | ||
117 | } | ||
118 | |||
119 | // Called just before the simulation step. Update the vertical position for hoverness. | ||
120 | private void Mover(float timeStep) | ||
121 | { | ||
122 | // Don't do force while the object is selected. | ||
123 | if (!isActive) | ||
124 | return; | ||
125 | |||
126 | m_physicsScene.DetailLog("{0},BSActorSetForce,preStep,force={1}", m_controllingPrim.LocalID, m_controllingPrim.RawForce); | ||
127 | if (m_controllingPrim.PhysBody.HasPhysicalBody) | ||
128 | { | ||
129 | m_physicsScene.PE.ApplyCentralForce(m_controllingPrim.PhysBody, m_controllingPrim.RawForce); | ||
130 | m_controllingPrim.ActivateIfPhysical(false); | ||
131 | } | ||
132 | |||
133 | // TODO: | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | |||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs new file mode 100755 index 0000000..65098e1 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs | |||
@@ -0,0 +1,138 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Text; | ||
32 | |||
33 | using OpenSim.Region.Physics.Manager; | ||
34 | |||
35 | using OMV = OpenMetaverse; | ||
36 | |||
37 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
38 | { | ||
39 | public class BSActorSetTorque : BSActor | ||
40 | { | ||
41 | BSFMotor m_torqueMotor; | ||
42 | |||
43 | public BSActorSetTorque(BSScene physicsScene, BSPhysObject pObj, string actorName) | ||
44 | : base(physicsScene, pObj, actorName) | ||
45 | { | ||
46 | m_torqueMotor = null; | ||
47 | m_physicsScene.DetailLog("{0},BSActorSetTorque,constructor", m_controllingPrim.LocalID); | ||
48 | } | ||
49 | |||
50 | // BSActor.isActive | ||
51 | public override bool isActive | ||
52 | { | ||
53 | get { return Enabled && m_controllingPrim.IsPhysicallyActive; } | ||
54 | } | ||
55 | |||
56 | // Release any connections and resources used by the actor. | ||
57 | // BSActor.Dispose() | ||
58 | public override void Dispose() | ||
59 | { | ||
60 | Enabled = false; | ||
61 | } | ||
62 | |||
63 | // Called when physical parameters (properties set in Bullet) need to be re-applied. | ||
64 | // Called at taint-time. | ||
65 | // BSActor.Refresh() | ||
66 | public override void Refresh() | ||
67 | { | ||
68 | m_physicsScene.DetailLog("{0},BSActorSetTorque,refresh,torque={1}", m_controllingPrim.LocalID, m_controllingPrim.RawTorque); | ||
69 | |||
70 | // If not active any more, get rid of me (shouldn't ever happen, but just to be safe) | ||
71 | if (m_controllingPrim.RawTorque == OMV.Vector3.Zero) | ||
72 | { | ||
73 | m_physicsScene.DetailLog("{0},BSActorSetTorque,refresh,notSetTorque,disabling={1}", m_controllingPrim.LocalID, ActorName); | ||
74 | Enabled = false; | ||
75 | return; | ||
76 | } | ||
77 | |||
78 | // If the object is physically active, add the hoverer prestep action | ||
79 | if (isActive) | ||
80 | { | ||
81 | ActivateSetTorque(); | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | DeactivateSetTorque(); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). | ||
90 | // Register a prestep action to restore physical requirements before the next simulation step. | ||
91 | // Called at taint-time. | ||
92 | // BSActor.RemoveDependencies() | ||
93 | public override void RemoveDependencies() | ||
94 | { | ||
95 | // Nothing to do for the hoverer since it is all software at pre-step action time. | ||
96 | } | ||
97 | |||
98 | // If a hover motor has not been created, create one and start the hovering. | ||
99 | private void ActivateSetTorque() | ||
100 | { | ||
101 | if (m_torqueMotor == null) | ||
102 | { | ||
103 | // A fake motor that might be used someday | ||
104 | m_torqueMotor = new BSFMotor("setTorque", 1f, 1f, 1f); | ||
105 | |||
106 | m_physicsScene.BeforeStep += Mover; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | private void DeactivateSetTorque() | ||
111 | { | ||
112 | if (m_torqueMotor != null) | ||
113 | { | ||
114 | m_physicsScene.BeforeStep -= Mover; | ||
115 | m_torqueMotor = null; | ||
116 | } | ||
117 | } | ||
118 | |||
119 | // Called just before the simulation step. Update the vertical position for hoverness. | ||
120 | private void Mover(float timeStep) | ||
121 | { | ||
122 | // Don't do force while the object is selected. | ||
123 | if (!isActive) | ||
124 | return; | ||
125 | |||
126 | m_physicsScene.DetailLog("{0},BSActorSetTorque,preStep,force={1}", m_controllingPrim.LocalID, m_controllingPrim.RawTorque); | ||
127 | if (m_controllingPrim.PhysBody.HasPhysicalBody) | ||
128 | { | ||
129 | m_controllingPrim.AddAngularForce(m_controllingPrim.RawTorque, false, true); | ||
130 | m_controllingPrim.ActivateIfPhysical(false); | ||
131 | } | ||
132 | |||
133 | // TODO: | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | |||
138 | |||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs new file mode 100755 index 0000000..e0ccc50 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs | |||
@@ -0,0 +1,156 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | |||
31 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
32 | { | ||
33 | public class BSActorCollection | ||
34 | { | ||
35 | private BSScene m_physicsScene { get; set; } | ||
36 | private Dictionary<string, BSActor> m_actors; | ||
37 | |||
38 | public BSActorCollection(BSScene physicsScene) | ||
39 | { | ||
40 | m_physicsScene = physicsScene; | ||
41 | m_actors = new Dictionary<string, BSActor>(); | ||
42 | } | ||
43 | public void Add(string name, BSActor actor) | ||
44 | { | ||
45 | lock (m_actors) | ||
46 | { | ||
47 | if (!m_actors.ContainsKey(name)) | ||
48 | { | ||
49 | m_actors[name] = actor; | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | public bool RemoveAndRelease(string name) | ||
54 | { | ||
55 | bool ret = false; | ||
56 | lock (m_actors) | ||
57 | { | ||
58 | if (m_actors.ContainsKey(name)) | ||
59 | { | ||
60 | BSActor beingRemoved = m_actors[name]; | ||
61 | m_actors.Remove(name); | ||
62 | beingRemoved.Dispose(); | ||
63 | ret = true; | ||
64 | } | ||
65 | } | ||
66 | return ret; | ||
67 | } | ||
68 | public void Clear() | ||
69 | { | ||
70 | lock (m_actors) | ||
71 | { | ||
72 | ForEachActor(a => a.Dispose()); | ||
73 | m_actors.Clear(); | ||
74 | } | ||
75 | } | ||
76 | public void Dispose() | ||
77 | { | ||
78 | Clear(); | ||
79 | } | ||
80 | public bool HasActor(string name) | ||
81 | { | ||
82 | return m_actors.ContainsKey(name); | ||
83 | } | ||
84 | public bool TryGetActor(string actorName, out BSActor theActor) | ||
85 | { | ||
86 | return m_actors.TryGetValue(actorName, out theActor); | ||
87 | } | ||
88 | public void ForEachActor(Action<BSActor> act) | ||
89 | { | ||
90 | lock (m_actors) | ||
91 | { | ||
92 | foreach (KeyValuePair<string, BSActor> kvp in m_actors) | ||
93 | act(kvp.Value); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | public void Enable(bool enabl) | ||
98 | { | ||
99 | ForEachActor(a => a.SetEnabled(enabl)); | ||
100 | } | ||
101 | public void Refresh() | ||
102 | { | ||
103 | ForEachActor(a => a.Refresh()); | ||
104 | } | ||
105 | public void RemoveDependencies() | ||
106 | { | ||
107 | ForEachActor(a => a.RemoveDependencies()); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | // ============================================================================= | ||
112 | /// <summary> | ||
113 | /// Each physical object can have 'actors' who are pushing the object around. | ||
114 | /// This can be used for hover, locking axis, making vehicles, etc. | ||
115 | /// Each physical object can have multiple actors acting on it. | ||
116 | /// | ||
117 | /// An actor usually registers itself with physics scene events (pre-step action) | ||
118 | /// and modifies the parameters on the host physical object. | ||
119 | /// </summary> | ||
120 | public abstract class BSActor | ||
121 | { | ||
122 | protected BSScene m_physicsScene { get; private set; } | ||
123 | protected BSPhysObject m_controllingPrim { get; private set; } | ||
124 | public virtual bool Enabled { get; set; } | ||
125 | public string ActorName { get; private set; } | ||
126 | |||
127 | public BSActor(BSScene physicsScene, BSPhysObject pObj, string actorName) | ||
128 | { | ||
129 | m_physicsScene = physicsScene; | ||
130 | m_controllingPrim = pObj; | ||
131 | ActorName = actorName; | ||
132 | Enabled = true; | ||
133 | } | ||
134 | |||
135 | // Return 'true' if activily updating the prim | ||
136 | public virtual bool isActive | ||
137 | { | ||
138 | get { return Enabled; } | ||
139 | } | ||
140 | |||
141 | // Turn the actor on an off. Only used by ActorCollection to set all enabled/disabled. | ||
142 | // Anyone else should assign true/false to 'Enabled'. | ||
143 | public void SetEnabled(bool setEnabled) | ||
144 | { | ||
145 | Enabled = setEnabled; | ||
146 | } | ||
147 | // Release any connections and resources used by the actor. | ||
148 | public abstract void Dispose(); | ||
149 | // Called when physical parameters (properties set in Bullet) need to be re-applied. | ||
150 | public abstract void Refresh(); | ||
151 | // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). | ||
152 | // Register a prestep action to restore physical requirements before the next simulation step. | ||
153 | public abstract void RemoveDependencies(); | ||
154 | |||
155 | } | ||
156 | } | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs index 5765b0d..be6f152 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs | |||
@@ -43,7 +43,9 @@ public enum ConstraintType : int | |||
43 | SLIDER_CONSTRAINT_TYPE, | 43 | SLIDER_CONSTRAINT_TYPE, |
44 | CONTACT_CONSTRAINT_TYPE, | 44 | CONTACT_CONSTRAINT_TYPE, |
45 | D6_SPRING_CONSTRAINT_TYPE, | 45 | D6_SPRING_CONSTRAINT_TYPE, |
46 | MAX_CONSTRAINT_TYPE | 46 | MAX_CONSTRAINT_TYPE, // last type defined by Bullet |
47 | // | ||
48 | FIXED_CONSTRAINT_TYPE = 1234 // BulletSim constraint that is fixed and unmoving | ||
47 | } | 49 | } |
48 | 50 | ||
49 | // =============================================================================== | 51 | // =============================================================================== |
@@ -70,6 +72,8 @@ public enum BSPhysicsShapeType | |||
70 | SHAPE_COMPOUND = 22, | 72 | SHAPE_COMPOUND = 22, |
71 | SHAPE_HEIGHTMAP = 23, | 73 | SHAPE_HEIGHTMAP = 23, |
72 | SHAPE_AVATAR = 24, | 74 | SHAPE_AVATAR = 24, |
75 | SHAPE_CONVEXHULL= 25, | ||
76 | SHAPE_GIMPACT = 26, | ||
73 | }; | 77 | }; |
74 | 78 | ||
75 | // The native shapes have predefined shape hash keys | 79 | // The native shapes have predefined shape hash keys |
@@ -191,6 +195,21 @@ public struct ConfigurationParameters | |||
191 | public const float numericFalse = 0f; | 195 | public const float numericFalse = 0f; |
192 | } | 196 | } |
193 | 197 | ||
198 | // Parameters passed for the conversion of a mesh to a hull using Bullet's HACD library. | ||
199 | [StructLayout(LayoutKind.Sequential)] | ||
200 | public struct HACDParams | ||
201 | { | ||
202 | // usual default values | ||
203 | public float maxVerticesPerHull; // 100 | ||
204 | public float minClusters; // 2 | ||
205 | public float compacityWeight; // 0.1 | ||
206 | public float volumeWeight; // 0.0 | ||
207 | public float concavity; // 100 | ||
208 | public float addExtraDistPoints; // false | ||
209 | public float addNeighboursDistPoints; // false | ||
210 | public float addFacesPoints; // false | ||
211 | public float shouldAdjustCollisionMargin; // false | ||
212 | } | ||
194 | 213 | ||
195 | // The states a bullet collision object can have | 214 | // The states a bullet collision object can have |
196 | public enum ActivationState : uint | 215 | public enum ActivationState : uint |
@@ -230,7 +249,7 @@ public enum CollisionFlags : uint | |||
230 | BS_VEHICLE_COLLISIONS = 1 << 12, // return collisions for vehicle ground checking | 249 | BS_VEHICLE_COLLISIONS = 1 << 12, // return collisions for vehicle ground checking |
231 | BS_RETURN_ROOT_COMPOUND_SHAPE = 1 << 13, // return the pos/rot of the root shape in a compound shape | 250 | BS_RETURN_ROOT_COMPOUND_SHAPE = 1 << 13, // return the pos/rot of the root shape in a compound shape |
232 | BS_NONE = 0, | 251 | BS_NONE = 0, |
233 | BS_ALL = 0xFFFFFFFF | 252 | BS_ALL = 0x7FFF // collision flags are a signed short |
234 | }; | 253 | }; |
235 | 254 | ||
236 | // Values f collisions groups and masks | 255 | // Values f collisions groups and masks |
@@ -246,14 +265,14 @@ public enum CollisionFilterGroups : uint | |||
246 | BDebrisGroup = 1 << 3, // 0008 | 265 | BDebrisGroup = 1 << 3, // 0008 |
247 | BSensorTrigger = 1 << 4, // 0010 | 266 | BSensorTrigger = 1 << 4, // 0010 |
248 | BCharacterGroup = 1 << 5, // 0020 | 267 | BCharacterGroup = 1 << 5, // 0020 |
249 | BAllGroup = 0x000FFFFF, | 268 | BAllGroup = 0x0007FFF, // collision flags are a signed short |
250 | // Filter groups defined by BulletSim | 269 | // Filter groups defined by BulletSim |
251 | BGroundPlaneGroup = 1 << 10, // 0400 | 270 | BGroundPlaneGroup = 1 << 8, // 0400 |
252 | BTerrainGroup = 1 << 11, // 0800 | 271 | BTerrainGroup = 1 << 9, // 0800 |
253 | BRaycastGroup = 1 << 12, // 1000 | 272 | BRaycastGroup = 1 << 10, // 1000 |
254 | BSolidGroup = 1 << 13, // 2000 | 273 | BSolidGroup = 1 << 11, // 2000 |
255 | // BLinksetGroup = xx // a linkset proper is either static or dynamic | 274 | // BLinksetGroup = xx // a linkset proper is either static or dynamic |
256 | BLinksetChildGroup = 1 << 14, // 4000 | 275 | BLinksetChildGroup = 1 << 12, // 4000 |
257 | }; | 276 | }; |
258 | 277 | ||
259 | // CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0 | 278 | // CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0 |
@@ -273,7 +292,7 @@ public enum ConstraintParamAxis : int | |||
273 | AXIS_ANGULAR_X, | 292 | AXIS_ANGULAR_X, |
274 | AXIS_ANGULAR_Y, | 293 | AXIS_ANGULAR_Y, |
275 | AXIS_ANGULAR_Z, | 294 | AXIS_ANGULAR_Z, |
276 | AXIS_LINEAR_ALL = 20, // these last three added by BulletSim so we don't have to do zillions of calls | 295 | AXIS_LINEAR_ALL = 20, // added by BulletSim so we don't have to do zillions of calls |
277 | AXIS_ANGULAR_ALL, | 296 | AXIS_ANGULAR_ALL, |
278 | AXIS_ALL | 297 | AXIS_ALL |
279 | }; | 298 | }; |
@@ -282,7 +301,7 @@ public abstract class BSAPITemplate | |||
282 | { | 301 | { |
283 | // Returns the name of the underlying Bullet engine | 302 | // Returns the name of the underlying Bullet engine |
284 | public abstract string BulletEngineName { get; } | 303 | public abstract string BulletEngineName { get; } |
285 | public abstract string BulletEngineVersion { get; protected set;} | 304 | public abstract string BulletEngineVersion { get; protected set;} |
286 | 305 | ||
287 | // Initialization and simulation | 306 | // Initialization and simulation |
288 | public abstract BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms, | 307 | public abstract BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms, |
@@ -305,10 +324,20 @@ public abstract BulletShape CreateMeshShape(BulletWorld world, | |||
305 | int indicesCount, int[] indices, | 324 | int indicesCount, int[] indices, |
306 | int verticesCount, float[] vertices ); | 325 | int verticesCount, float[] vertices ); |
307 | 326 | ||
327 | public abstract BulletShape CreateGImpactShape(BulletWorld world, | ||
328 | int indicesCount, int[] indices, | ||
329 | int verticesCount, float[] vertices ); | ||
330 | |||
308 | public abstract BulletShape CreateHullShape(BulletWorld world, | 331 | public abstract BulletShape CreateHullShape(BulletWorld world, |
309 | int hullCount, float[] hulls); | 332 | int hullCount, float[] hulls); |
310 | 333 | ||
311 | public abstract BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape); | 334 | public abstract BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape, HACDParams parms); |
335 | |||
336 | public abstract BulletShape BuildConvexHullShapeFromMesh(BulletWorld world, BulletShape meshShape); | ||
337 | |||
338 | public abstract BulletShape CreateConvexHullShape(BulletWorld world, | ||
339 | int indicesCount, int[] indices, | ||
340 | int verticesCount, float[] vertices ); | ||
312 | 341 | ||
313 | public abstract BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData); | 342 | public abstract BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData); |
314 | 343 | ||
@@ -351,7 +380,7 @@ public abstract void DestroyObject(BulletWorld sim, BulletBody obj); | |||
351 | // ===================================================================================== | 380 | // ===================================================================================== |
352 | public abstract BulletShape CreateGroundPlaneShape(UInt32 id, float height, float collisionMargin); | 381 | public abstract BulletShape CreateGroundPlaneShape(UInt32 id, float height, float collisionMargin); |
353 | 382 | ||
354 | public abstract BulletShape CreateTerrainShape(UInt32 id, Vector3 size, float minHeight, float maxHeight, float[] heightMap, | 383 | public abstract BulletShape CreateTerrainShape(UInt32 id, Vector3 size, float minHeight, float maxHeight, float[] heightMap, |
355 | float scaleFactor, float collisionMargin); | 384 | float scaleFactor, float collisionMargin); |
356 | 385 | ||
357 | // ===================================================================================== | 386 | // ===================================================================================== |
@@ -366,7 +395,7 @@ public abstract BulletConstraint Create6DofConstraintToPoint(BulletWorld world, | |||
366 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); | 395 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); |
367 | 396 | ||
368 | public abstract BulletConstraint Create6DofConstraintFixed(BulletWorld world, BulletBody obj1, | 397 | public abstract BulletConstraint Create6DofConstraintFixed(BulletWorld world, BulletBody obj1, |
369 | Vector3 frameInBloc, Quaternion frameInBrot, | 398 | Vector3 frameInBloc, Quaternion frameInBrot, |
370 | bool useLinearReferenceFrameB, bool disableCollisionsBetweenLinkedBodies); | 399 | bool useLinearReferenceFrameB, bool disableCollisionsBetweenLinkedBodies); |
371 | 400 | ||
372 | public abstract BulletConstraint Create6DofSpringConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, | 401 | public abstract BulletConstraint Create6DofSpringConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, |
@@ -414,6 +443,38 @@ public abstract bool TranslationalLimitMotor(BulletConstraint constrain, float e | |||
414 | 443 | ||
415 | public abstract bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold); | 444 | public abstract bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold); |
416 | 445 | ||
446 | public const int HINGE_NOT_SPECIFIED = -1; | ||
447 | public abstract bool HingeSetLimits(BulletConstraint constrain, float low, float high, float softness, float bias, float relaxation); | ||
448 | |||
449 | public abstract bool SpringEnable(BulletConstraint constrain, int index, float numericTrueFalse); | ||
450 | |||
451 | public const int SPRING_NOT_SPECIFIED = -1; | ||
452 | public abstract bool SpringSetEquilibriumPoint(BulletConstraint constrain, int index, float equilibriumPoint); | ||
453 | |||
454 | public abstract bool SpringSetStiffness(BulletConstraint constrain, int index, float stiffnesss); | ||
455 | |||
456 | public abstract bool SpringSetDamping(BulletConstraint constrain, int index, float damping); | ||
457 | |||
458 | public const int SLIDER_LOWER_LIMIT = 0; | ||
459 | public const int SLIDER_UPPER_LIMIT = 1; | ||
460 | public const int SLIDER_LINEAR = 2; | ||
461 | public const int SLIDER_ANGULAR = 3; | ||
462 | public abstract bool SliderSetLimits(BulletConstraint constrain, int lowerUpper, int linAng, float val); | ||
463 | |||
464 | public const int SLIDER_SET_SOFTNESS = 4; | ||
465 | public const int SLIDER_SET_RESTITUTION = 5; | ||
466 | public const int SLIDER_SET_DAMPING = 6; | ||
467 | public const int SLIDER_SET_DIRECTION = 7; | ||
468 | public const int SLIDER_SET_LIMIT = 8; | ||
469 | public const int SLIDER_SET_ORTHO = 9; | ||
470 | public abstract bool SliderSet(BulletConstraint constrain, int softRestDamp, int dirLimOrtho, int linAng, float val); | ||
471 | |||
472 | public abstract bool SliderMotorEnable(BulletConstraint constrain, int linAng, float numericTrueFalse); | ||
473 | |||
474 | public const int SLIDER_MOTOR_VELOCITY = 10; | ||
475 | public const int SLIDER_MAX_MOTOR_FORCE = 11; | ||
476 | public abstract bool SliderMotor(BulletConstraint constrain, int forceVel, int linAng, float val); | ||
477 | |||
417 | public abstract bool CalculateTransforms(BulletConstraint constrain); | 478 | public abstract bool CalculateTransforms(BulletConstraint constrain); |
418 | 479 | ||
419 | public abstract bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis); | 480 | public abstract bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis); |
@@ -437,6 +498,8 @@ public abstract bool AddObjectToWorld(BulletWorld world, BulletBody obj); | |||
437 | 498 | ||
438 | public abstract bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj); | 499 | public abstract bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj); |
439 | 500 | ||
501 | public abstract bool ClearCollisionProxyCache(BulletWorld world, BulletBody obj); | ||
502 | |||
440 | public abstract bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects); | 503 | public abstract bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects); |
441 | 504 | ||
442 | public abstract bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain); | 505 | public abstract bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain); |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 90c2d9c..fc18960 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
@@ -43,15 +43,10 @@ public sealed class BSCharacter : BSPhysObject | |||
43 | private OMV.Vector3 _size; | 43 | private OMV.Vector3 _size; |
44 | private bool _grabbed; | 44 | private bool _grabbed; |
45 | private bool _selected; | 45 | private bool _selected; |
46 | private OMV.Vector3 _position; | ||
47 | private float _mass; | 46 | private float _mass; |
48 | private float _avatarVolume; | 47 | private float _avatarVolume; |
49 | private OMV.Vector3 _force; | ||
50 | private OMV.Vector3 _velocity; | ||
51 | private OMV.Vector3 _torque; | ||
52 | private float _collisionScore; | 48 | private float _collisionScore; |
53 | private OMV.Vector3 _acceleration; | 49 | private OMV.Vector3 _acceleration; |
54 | private OMV.Quaternion _orientation; | ||
55 | private int _physicsActorType; | 50 | private int _physicsActorType; |
56 | private bool _isPhysical; | 51 | private bool _isPhysical; |
57 | private bool _flying; | 52 | private bool _flying; |
@@ -62,28 +57,25 @@ public sealed class BSCharacter : BSPhysObject | |||
62 | private bool _kinematic; | 57 | private bool _kinematic; |
63 | private float _buoyancy; | 58 | private float _buoyancy; |
64 | 59 | ||
65 | private BSVMotor _velocityMotor; | 60 | private BSActorAvatarMove m_moveActor; |
61 | private const string AvatarMoveActorName = "BSCharacter.AvatarMove"; | ||
66 | 62 | ||
67 | private OMV.Vector3 _PIDTarget; | 63 | private OMV.Vector3 _PIDTarget; |
68 | private bool _usePID; | 64 | private bool _usePID; |
69 | private float _PIDTau; | 65 | private float _PIDTau; |
70 | private bool _useHoverPID; | ||
71 | private float _PIDHoverHeight; | ||
72 | private PIDHoverType _PIDHoverType; | ||
73 | private float _PIDHoverTao; | ||
74 | 66 | ||
75 | public BSCharacter(uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, bool isFlying) | 67 | public BSCharacter(uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, bool isFlying) |
76 | : base(parent_scene, localID, avName, "BSCharacter") | 68 | : base(parent_scene, localID, avName, "BSCharacter") |
77 | { | 69 | { |
78 | _physicsActorType = (int)ActorTypes.Agent; | 70 | _physicsActorType = (int)ActorTypes.Agent; |
79 | _position = pos; | 71 | RawPosition = pos; |
80 | 72 | ||
81 | _flying = isFlying; | 73 | _flying = isFlying; |
82 | _orientation = OMV.Quaternion.Identity; | 74 | RawOrientation = OMV.Quaternion.Identity; |
83 | _velocity = OMV.Vector3.Zero; | 75 | RawVelocity = OMV.Vector3.Zero; |
84 | _buoyancy = ComputeBuoyancyFromFlying(isFlying); | 76 | _buoyancy = ComputeBuoyancyFromFlying(isFlying); |
85 | Friction = BSParam.AvatarStandingFriction; | 77 | Friction = BSParam.AvatarStandingFriction; |
86 | Density = BSParam.AvatarDensity / BSParam.DensityScaleFactor; | 78 | Density = BSParam.AvatarDensity; |
87 | 79 | ||
88 | // Old versions of ScenePresence passed only the height. If width and/or depth are zero, | 80 | // Old versions of ScenePresence passed only the height. If width and/or depth are zero, |
89 | // replace with the default values. | 81 | // replace with the default values. |
@@ -97,19 +89,26 @@ public sealed class BSCharacter : BSPhysObject | |||
97 | // set _avatarVolume and _mass based on capsule size, _density and Scale | 89 | // set _avatarVolume and _mass based on capsule size, _density and Scale |
98 | ComputeAvatarVolumeAndMass(); | 90 | ComputeAvatarVolumeAndMass(); |
99 | 91 | ||
100 | SetupMovementMotor(); | 92 | DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5},pos={6}", |
101 | 93 | LocalID, _size, Scale, Density, _avatarVolume, RawMass, pos); | |
102 | DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5}", | ||
103 | LocalID, _size, Scale, Density, _avatarVolume, RawMass); | ||
104 | 94 | ||
105 | // do actual creation in taint time | 95 | // do actual creation in taint time |
106 | PhysicsScene.TaintedObject("BSCharacter.create", delegate() | 96 | PhysScene.TaintedObject(LocalID, "BSCharacter.create", delegate() |
107 | { | 97 | { |
108 | DetailLog("{0},BSCharacter.create,taint", LocalID); | 98 | DetailLog("{0},BSCharacter.create,taint", LocalID); |
109 | // New body and shape into PhysBody and PhysShape | 99 | // New body and shape into PhysBody and PhysShape |
110 | PhysicsScene.Shapes.GetBodyAndShape(true, PhysicsScene.World, this); | 100 | PhysScene.Shapes.GetBodyAndShape(true, PhysScene.World, this); |
101 | |||
102 | // The avatar's movement is controlled by this motor that speeds up and slows down | ||
103 | // the avatar seeking to reach the motor's target speed. | ||
104 | // This motor runs as a prestep action for the avatar so it will keep the avatar | ||
105 | // standing as well as moving. Destruction of the avatar will destroy the pre-step action. | ||
106 | m_moveActor = new BSActorAvatarMove(PhysScene, this, AvatarMoveActorName); | ||
107 | PhysicalActors.Add(AvatarMoveActorName, m_moveActor); | ||
111 | 108 | ||
112 | SetPhysicalProperties(); | 109 | SetPhysicalProperties(); |
110 | |||
111 | IsInitialized = true; | ||
113 | }); | 112 | }); |
114 | return; | 113 | return; |
115 | } | 114 | } |
@@ -117,217 +116,68 @@ public sealed class BSCharacter : BSPhysObject | |||
117 | // called when this character is being destroyed and the resources should be released | 116 | // called when this character is being destroyed and the resources should be released |
118 | public override void Destroy() | 117 | public override void Destroy() |
119 | { | 118 | { |
119 | IsInitialized = false; | ||
120 | |||
120 | base.Destroy(); | 121 | base.Destroy(); |
121 | 122 | ||
122 | DetailLog("{0},BSCharacter.Destroy", LocalID); | 123 | DetailLog("{0},BSCharacter.Destroy", LocalID); |
123 | PhysicsScene.TaintedObject("BSCharacter.destroy", delegate() | 124 | PhysScene.TaintedObject(LocalID, "BSCharacter.destroy", delegate() |
124 | { | 125 | { |
125 | PhysicsScene.Shapes.DereferenceBody(PhysBody, null /* bodyCallback */); | 126 | PhysScene.Shapes.DereferenceBody(PhysBody, null /* bodyCallback */); |
126 | PhysBody.Clear(); | 127 | PhysBody.Clear(); |
127 | PhysicsScene.Shapes.DereferenceShape(PhysShape, null /* bodyCallback */); | 128 | PhysShape.Dereference(PhysScene); |
128 | PhysShape.Clear(); | 129 | PhysShape = new BSShapeNull(); |
129 | }); | 130 | }); |
130 | } | 131 | } |
131 | 132 | ||
132 | private void SetPhysicalProperties() | 133 | private void SetPhysicalProperties() |
133 | { | 134 | { |
134 | PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, PhysBody); | 135 | PhysScene.PE.RemoveObjectFromWorld(PhysScene.World, PhysBody); |
135 | 136 | ||
136 | ZeroMotion(true); | 137 | ZeroMotion(true); |
137 | ForcePosition = _position; | 138 | ForcePosition = RawPosition; |
138 | 139 | ||
139 | // Set the velocity | 140 | // Set the velocity |
140 | _velocityMotor.Reset(); | 141 | if (m_moveActor != null) |
141 | _velocityMotor.SetTarget(_velocity); | 142 | m_moveActor.SetVelocityAndTarget(RawVelocity, RawVelocity, false); |
142 | _velocityMotor.SetCurrent(_velocity); | 143 | |
143 | ForceVelocity = _velocity; | 144 | ForceVelocity = RawVelocity; |
144 | 145 | ||
145 | // This will enable or disable the flying buoyancy of the avatar. | 146 | // This will enable or disable the flying buoyancy of the avatar. |
146 | // Needs to be reset especially when an avatar is recreated after crossing a region boundry. | 147 | // Needs to be reset especially when an avatar is recreated after crossing a region boundry. |
147 | Flying = _flying; | 148 | Flying = _flying; |
148 | 149 | ||
149 | PhysicsScene.PE.SetRestitution(PhysBody, BSParam.AvatarRestitution); | 150 | PhysScene.PE.SetRestitution(PhysBody, BSParam.AvatarRestitution); |
150 | PhysicsScene.PE.SetMargin(PhysShape, PhysicsScene.Params.collisionMargin); | 151 | PhysScene.PE.SetMargin(PhysShape.physShapeInfo, PhysScene.Params.collisionMargin); |
151 | PhysicsScene.PE.SetLocalScaling(PhysShape, Scale); | 152 | PhysScene.PE.SetLocalScaling(PhysShape.physShapeInfo, Scale); |
152 | PhysicsScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold); | 153 | PhysScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold); |
153 | if (BSParam.CcdMotionThreshold > 0f) | 154 | if (BSParam.CcdMotionThreshold > 0f) |
154 | { | 155 | { |
155 | PhysicsScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold); | 156 | PhysScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold); |
156 | PhysicsScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius); | 157 | PhysScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius); |
157 | } | 158 | } |
158 | 159 | ||
159 | UpdatePhysicalMassProperties(RawMass, false); | 160 | UpdatePhysicalMassProperties(RawMass, false); |
160 | 161 | ||
161 | // Make so capsule does not fall over | 162 | // Make so capsule does not fall over |
162 | PhysicsScene.PE.SetAngularFactorV(PhysBody, OMV.Vector3.Zero); | 163 | PhysScene.PE.SetAngularFactorV(PhysBody, OMV.Vector3.Zero); |
164 | |||
165 | // The avatar mover sets some parameters. | ||
166 | PhysicalActors.Refresh(); | ||
163 | 167 | ||
164 | PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_CHARACTER_OBJECT); | 168 | PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_CHARACTER_OBJECT); |
165 | 169 | ||
166 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody); | 170 | PhysScene.PE.AddObjectToWorld(PhysScene.World, PhysBody); |
167 | 171 | ||
168 | // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG); | 172 | // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG); |
169 | PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.DISABLE_DEACTIVATION); | 173 | PhysScene.PE.ForceActivationState(PhysBody, ActivationState.DISABLE_DEACTIVATION); |
170 | PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, PhysBody); | 174 | PhysScene.PE.UpdateSingleAabb(PhysScene.World, PhysBody); |
171 | 175 | ||
172 | // Do this after the object has been added to the world | 176 | // Do this after the object has been added to the world |
173 | PhysBody.collisionType = CollisionType.Avatar; | 177 | PhysBody.collisionType = CollisionType.Avatar; |
174 | PhysBody.ApplyCollisionMask(PhysicsScene); | 178 | PhysBody.ApplyCollisionMask(PhysScene); |
175 | } | ||
176 | |||
177 | // The avatar's movement is controlled by this motor that speeds up and slows down | ||
178 | // the avatar seeking to reach the motor's target speed. | ||
179 | // This motor runs as a prestep action for the avatar so it will keep the avatar | ||
180 | // standing as well as moving. Destruction of the avatar will destroy the pre-step action. | ||
181 | private void SetupMovementMotor() | ||
182 | { | ||
183 | // Infinite decay and timescale values so motor only changes current to target values. | ||
184 | _velocityMotor = new BSVMotor("BSCharacter.Velocity", | ||
185 | 0.2f, // time scale | ||
186 | BSMotor.Infinite, // decay time scale | ||
187 | BSMotor.InfiniteVector, // friction timescale | ||
188 | 1f // efficiency | ||
189 | ); | ||
190 | // _velocityMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. | ||
191 | |||
192 | RegisterPreStepAction("BSCharactor.Movement", LocalID, delegate(float timeStep) | ||
193 | { | ||
194 | // TODO: Decide if the step parameters should be changed depending on the avatar's | ||
195 | // state (flying, colliding, ...). There is code in ODE to do this. | ||
196 | |||
197 | // COMMENTARY: when the user is making the avatar walk, except for falling, the velocity | ||
198 | // specified for the avatar is the one that should be used. For falling, if the avatar | ||
199 | // is not flying and is not colliding then it is presumed to be falling and the Z | ||
200 | // component is not fooled with (thus allowing gravity to do its thing). | ||
201 | // When the avatar is standing, though, the user has specified a velocity of zero and | ||
202 | // the avatar should be standing. But if the avatar is pushed by something in the world | ||
203 | // (raising elevator platform, moving vehicle, ...) the avatar should be allowed to | ||
204 | // move. Thus, the velocity cannot be forced to zero. The problem is that small velocity | ||
205 | // errors can creap in and the avatar will slowly float off in some direction. | ||
206 | // So, the problem is that, when an avatar is standing, we cannot tell creaping error | ||
207 | // from real pushing. | ||
208 | // The code below uses whether the collider is static or moving to decide whether to zero motion. | ||
209 | |||
210 | _velocityMotor.Step(timeStep); | ||
211 | |||
212 | // If we're not supposed to be moving, make sure things are zero. | ||
213 | if (_velocityMotor.ErrorIsZero() && _velocityMotor.TargetValue == OMV.Vector3.Zero) | ||
214 | { | ||
215 | // The avatar shouldn't be moving | ||
216 | _velocityMotor.Zero(); | ||
217 | |||
218 | if (IsColliding) | ||
219 | { | ||
220 | // If we are colliding with a stationary object, presume we're standing and don't move around | ||
221 | if (!ColliderIsMoving) | ||
222 | { | ||
223 | DetailLog("{0},BSCharacter.MoveMotor,collidingWithStationary,zeroingMotion", LocalID); | ||
224 | ZeroMotion(true /* inTaintTime */); | ||
225 | } | ||
226 | |||
227 | // Standing has more friction on the ground | ||
228 | if (Friction != BSParam.AvatarStandingFriction) | ||
229 | { | ||
230 | Friction = BSParam.AvatarStandingFriction; | ||
231 | PhysicsScene.PE.SetFriction(PhysBody, Friction); | ||
232 | } | ||
233 | } | ||
234 | else | ||
235 | { | ||
236 | if (Flying) | ||
237 | { | ||
238 | // Flying and not collising and velocity nearly zero. | ||
239 | ZeroMotion(true /* inTaintTime */); | ||
240 | } | ||
241 | } | ||
242 | |||
243 | DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1},colliding={2}", LocalID, _velocityMotor.TargetValue, IsColliding); | ||
244 | } | ||
245 | else | ||
246 | { | ||
247 | // Supposed to be moving. | ||
248 | OMV.Vector3 stepVelocity = _velocityMotor.CurrentValue; | ||
249 | |||
250 | if (Friction != BSParam.AvatarFriction) | ||
251 | { | ||
252 | // Probably starting up walking. Set friction to moving friction. | ||
253 | Friction = BSParam.AvatarFriction; | ||
254 | PhysicsScene.PE.SetFriction(PhysBody, Friction); | ||
255 | } | ||
256 | |||
257 | // If falling, we keep the world's downward vector no matter what the other axis specify. | ||
258 | // The check for _velocity.Z < 0 makes jumping work (temporary upward force). | ||
259 | if (!Flying && !IsColliding) | ||
260 | { | ||
261 | if (_velocity.Z < 0) | ||
262 | stepVelocity.Z = _velocity.Z; | ||
263 | // DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity); | ||
264 | } | ||
265 | |||
266 | // 'stepVelocity' is now the speed we'd like the avatar to move in. Turn that into an instantanous force. | ||
267 | OMV.Vector3 moveForce = (stepVelocity - _velocity) * Mass; | ||
268 | |||
269 | // Should we check for move force being small and forcing velocity to zero? | ||
270 | |||
271 | // Add special movement force to allow avatars to walk up stepped surfaces. | ||
272 | moveForce += WalkUpStairs(); | ||
273 | |||
274 | DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce); | ||
275 | PhysicsScene.PE.ApplyCentralImpulse(PhysBody, moveForce); | ||
276 | } | ||
277 | }); | ||
278 | } | 179 | } |
279 | 180 | ||
280 | // Decide if the character is colliding with a low object and compute a force to pop the | ||
281 | // avatar up so it can walk up and over the low objects. | ||
282 | private OMV.Vector3 WalkUpStairs() | ||
283 | { | ||
284 | OMV.Vector3 ret = OMV.Vector3.Zero; | ||
285 | |||
286 | // This test is done if moving forward, not flying and is colliding with something. | ||
287 | // DetailLog("{0},BSCharacter.WalkUpStairs,IsColliding={1},flying={2},targSpeed={3},collisions={4}", | ||
288 | // LocalID, IsColliding, Flying, TargetSpeed, CollisionsLastTick.Count); | ||
289 | if (IsColliding && !Flying && TargetVelocitySpeed > 0.1f /* && ForwardSpeed < 0.1f */) | ||
290 | { | ||
291 | // The range near the character's feet where we will consider stairs | ||
292 | float nearFeetHeightMin = RawPosition.Z - (Size.Z / 2f) + 0.05f; | ||
293 | float nearFeetHeightMax = nearFeetHeightMin + BSParam.AvatarStepHeight; | ||
294 | |||
295 | // Look for a collision point that is near the character's feet and is oriented the same as the charactor is | ||
296 | foreach (KeyValuePair<uint, ContactPoint> kvp in CollisionsLastTick.m_objCollisionList) | ||
297 | { | ||
298 | // Don't care about collisions with the terrain | ||
299 | if (kvp.Key > PhysicsScene.TerrainManager.HighestTerrainID) | ||
300 | { | ||
301 | OMV.Vector3 touchPosition = kvp.Value.Position; | ||
302 | // DetailLog("{0},BSCharacter.WalkUpStairs,min={1},max={2},touch={3}", | ||
303 | // LocalID, nearFeetHeightMin, nearFeetHeightMax, touchPosition); | ||
304 | if (touchPosition.Z >= nearFeetHeightMin && touchPosition.Z <= nearFeetHeightMax) | ||
305 | { | ||
306 | // This contact is within the 'near the feet' range. | ||
307 | // The normal should be our contact point to the object so it is pointing away | ||
308 | // thus the difference between our facing orientation and the normal should be small. | ||
309 | OMV.Vector3 directionFacing = OMV.Vector3.UnitX * RawOrientation; | ||
310 | OMV.Vector3 touchNormal = OMV.Vector3.Normalize(kvp.Value.SurfaceNormal); | ||
311 | float diff = Math.Abs(OMV.Vector3.Distance(directionFacing, touchNormal)); | ||
312 | if (diff < BSParam.AvatarStepApproachFactor) | ||
313 | { | ||
314 | // Found the stairs contact point. Push up a little to raise the character. | ||
315 | float upForce = (touchPosition.Z - nearFeetHeightMin) * Mass * BSParam.AvatarStepForceFactor; | ||
316 | ret = new OMV.Vector3(0f, 0f, upForce); | ||
317 | |||
318 | // Also move the avatar up for the new height | ||
319 | OMV.Vector3 displacement = new OMV.Vector3(0f, 0f, BSParam.AvatarStepHeight / 2f); | ||
320 | ForcePosition = RawPosition + displacement; | ||
321 | } | ||
322 | DetailLog("{0},BSCharacter.WalkUpStairs,touchPos={1},nearFeetMin={2},faceDir={3},norm={4},diff={5},ret={6}", | ||
323 | LocalID, touchPosition, nearFeetHeightMin, directionFacing, touchNormal, diff, ret); | ||
324 | } | ||
325 | } | ||
326 | } | ||
327 | } | ||
328 | |||
329 | return ret; | ||
330 | } | ||
331 | 181 | ||
332 | public override void RequestPhysicsterseUpdate() | 182 | public override void RequestPhysicsterseUpdate() |
333 | { | 183 | { |
@@ -344,6 +194,10 @@ public sealed class BSCharacter : BSPhysObject | |||
344 | } | 194 | } |
345 | 195 | ||
346 | set { | 196 | set { |
197 | // This is how much the avatar size is changing. Positive means getting bigger. | ||
198 | // The avatar altitude must be adjusted for this change. | ||
199 | float heightChange = value.Z - _size.Z; | ||
200 | |||
347 | _size = value; | 201 | _size = value; |
348 | // Old versions of ScenePresence passed only the height. If width and/or depth are zero, | 202 | // Old versions of ScenePresence passed only the height. If width and/or depth are zero, |
349 | // replace with the default values. | 203 | // replace with the default values. |
@@ -355,14 +209,18 @@ public sealed class BSCharacter : BSPhysObject | |||
355 | DetailLog("{0},BSCharacter.setSize,call,size={1},scale={2},density={3},volume={4},mass={5}", | 209 | DetailLog("{0},BSCharacter.setSize,call,size={1},scale={2},density={3},volume={4},mass={5}", |
356 | LocalID, _size, Scale, Density, _avatarVolume, RawMass); | 210 | LocalID, _size, Scale, Density, _avatarVolume, RawMass); |
357 | 211 | ||
358 | PhysicsScene.TaintedObject("BSCharacter.setSize", delegate() | 212 | PhysScene.TaintedObject(LocalID, "BSCharacter.setSize", delegate() |
359 | { | 213 | { |
360 | if (PhysBody.HasPhysicalBody && PhysShape.HasPhysicalShape) | 214 | if (PhysBody.HasPhysicalBody && PhysShape.physShapeInfo.HasPhysicalShape) |
361 | { | 215 | { |
362 | PhysicsScene.PE.SetLocalScaling(PhysShape, Scale); | 216 | PhysScene.PE.SetLocalScaling(PhysShape.physShapeInfo, Scale); |
363 | UpdatePhysicalMassProperties(RawMass, true); | 217 | UpdatePhysicalMassProperties(RawMass, true); |
218 | |||
219 | // Adjust the avatar's position to account for the increase/decrease in size | ||
220 | ForcePosition = new OMV.Vector3(RawPosition.X, RawPosition.Y, RawPosition.Z + heightChange / 2f); | ||
221 | |||
364 | // Make sure this change appears as a property update event | 222 | // Make sure this change appears as a property update event |
365 | PhysicsScene.PE.PushUpdate(PhysBody); | 223 | PhysScene.PE.PushUpdate(PhysBody); |
366 | } | 224 | } |
367 | }); | 225 | }); |
368 | 226 | ||
@@ -373,11 +231,6 @@ public sealed class BSCharacter : BSPhysObject | |||
373 | { | 231 | { |
374 | set { BaseShape = value; } | 232 | set { BaseShape = value; } |
375 | } | 233 | } |
376 | // I want the physics engine to make an avatar capsule | ||
377 | public override BSPhysicsShapeType PreferredPhysicalShape | ||
378 | { | ||
379 | get {return BSPhysicsShapeType.SHAPE_CAPSULE; } | ||
380 | } | ||
381 | 234 | ||
382 | public override bool Grabbed { | 235 | public override bool Grabbed { |
383 | set { _grabbed = value; } | 236 | set { _grabbed = value; } |
@@ -399,29 +252,29 @@ public sealed class BSCharacter : BSPhysObject | |||
399 | // Called at taint time! | 252 | // Called at taint time! |
400 | public override void ZeroMotion(bool inTaintTime) | 253 | public override void ZeroMotion(bool inTaintTime) |
401 | { | 254 | { |
402 | _velocity = OMV.Vector3.Zero; | 255 | RawVelocity = OMV.Vector3.Zero; |
403 | _acceleration = OMV.Vector3.Zero; | 256 | _acceleration = OMV.Vector3.Zero; |
404 | _rotationalVelocity = OMV.Vector3.Zero; | 257 | _rotationalVelocity = OMV.Vector3.Zero; |
405 | 258 | ||
406 | // Zero some other properties directly into the physics engine | 259 | // Zero some other properties directly into the physics engine |
407 | PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate() | 260 | PhysScene.TaintedObject(inTaintTime, LocalID, "BSCharacter.ZeroMotion", delegate() |
408 | { | 261 | { |
409 | if (PhysBody.HasPhysicalBody) | 262 | if (PhysBody.HasPhysicalBody) |
410 | PhysicsScene.PE.ClearAllForces(PhysBody); | 263 | PhysScene.PE.ClearAllForces(PhysBody); |
411 | }); | 264 | }); |
412 | } | 265 | } |
413 | public override void ZeroAngularMotion(bool inTaintTime) | 266 | public override void ZeroAngularMotion(bool inTaintTime) |
414 | { | 267 | { |
415 | _rotationalVelocity = OMV.Vector3.Zero; | 268 | _rotationalVelocity = OMV.Vector3.Zero; |
416 | 269 | ||
417 | PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate() | 270 | PhysScene.TaintedObject(inTaintTime, LocalID, "BSCharacter.ZeroMotion", delegate() |
418 | { | 271 | { |
419 | if (PhysBody.HasPhysicalBody) | 272 | if (PhysBody.HasPhysicalBody) |
420 | { | 273 | { |
421 | PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, OMV.Vector3.Zero); | 274 | PhysScene.PE.SetInterpolationAngularVelocity(PhysBody, OMV.Vector3.Zero); |
422 | PhysicsScene.PE.SetAngularVelocity(PhysBody, OMV.Vector3.Zero); | 275 | PhysScene.PE.SetAngularVelocity(PhysBody, OMV.Vector3.Zero); |
423 | // The next also get rid of applied linear force but the linear velocity is untouched. | 276 | // The next also get rid of applied linear force but the linear velocity is untouched. |
424 | PhysicsScene.PE.ClearForces(PhysBody); | 277 | PhysScene.PE.ClearForces(PhysBody); |
425 | } | 278 | } |
426 | }); | 279 | }); |
427 | } | 280 | } |
@@ -429,38 +282,33 @@ public sealed class BSCharacter : BSPhysObject | |||
429 | 282 | ||
430 | public override void LockAngularMotion(OMV.Vector3 axis) { return; } | 283 | public override void LockAngularMotion(OMV.Vector3 axis) { return; } |
431 | 284 | ||
432 | public override OMV.Vector3 RawPosition | ||
433 | { | ||
434 | get { return _position; } | ||
435 | set { _position = value; } | ||
436 | } | ||
437 | public override OMV.Vector3 Position { | 285 | public override OMV.Vector3 Position { |
438 | get { | 286 | get { |
439 | // Don't refetch the position because this function is called a zillion times | 287 | // Don't refetch the position because this function is called a zillion times |
440 | // _position = PhysicsScene.PE.GetObjectPosition(Scene.World, LocalID); | 288 | // RawPosition = PhysicsScene.PE.GetObjectPosition(Scene.World, LocalID); |
441 | return _position; | 289 | return RawPosition; |
442 | } | 290 | } |
443 | set { | 291 | set { |
444 | _position = value; | 292 | RawPosition = value; |
445 | 293 | ||
446 | PhysicsScene.TaintedObject("BSCharacter.setPosition", delegate() | 294 | PhysScene.TaintedObject(LocalID, "BSCharacter.setPosition", delegate() |
447 | { | 295 | { |
448 | DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 296 | DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, RawPosition, RawOrientation); |
449 | PositionSanityCheck(); | 297 | PositionSanityCheck(); |
450 | ForcePosition = _position; | 298 | ForcePosition = RawPosition; |
451 | }); | 299 | }); |
452 | } | 300 | } |
453 | } | 301 | } |
454 | public override OMV.Vector3 ForcePosition { | 302 | public override OMV.Vector3 ForcePosition { |
455 | get { | 303 | get { |
456 | _position = PhysicsScene.PE.GetPosition(PhysBody); | 304 | RawPosition = PhysScene.PE.GetPosition(PhysBody); |
457 | return _position; | 305 | return RawPosition; |
458 | } | 306 | } |
459 | set { | 307 | set { |
460 | _position = value; | 308 | RawPosition = value; |
461 | if (PhysBody.HasPhysicalBody) | 309 | if (PhysBody.HasPhysicalBody) |
462 | { | 310 | { |
463 | PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); | 311 | PhysScene.PE.SetTranslation(PhysBody, RawPosition, RawOrientation); |
464 | } | 312 | } |
465 | } | 313 | } |
466 | } | 314 | } |
@@ -474,30 +322,30 @@ public sealed class BSCharacter : BSPhysObject | |||
474 | bool ret = false; | 322 | bool ret = false; |
475 | 323 | ||
476 | // TODO: check for out of bounds | 324 | // TODO: check for out of bounds |
477 | if (!PhysicsScene.TerrainManager.IsWithinKnownTerrain(RawPosition)) | 325 | if (!PhysScene.TerrainManager.IsWithinKnownTerrain(RawPosition)) |
478 | { | 326 | { |
479 | // The character is out of the known/simulated area. | 327 | // The character is out of the known/simulated area. |
480 | // Force the avatar position to be within known. ScenePresence will use the position | 328 | // Force the avatar position to be within known. ScenePresence will use the position |
481 | // plus the velocity to decide if the avatar is moving out of the region. | 329 | // plus the velocity to decide if the avatar is moving out of the region. |
482 | RawPosition = PhysicsScene.TerrainManager.ClampPositionIntoKnownTerrain(RawPosition); | 330 | RawPosition = PhysScene.TerrainManager.ClampPositionIntoKnownTerrain(RawPosition); |
483 | DetailLog("{0},BSCharacter.PositionSanityCheck,notWithinKnownTerrain,clampedPos={1}", LocalID, RawPosition); | 331 | DetailLog("{0},BSCharacter.PositionSanityCheck,notWithinKnownTerrain,clampedPos={1}", LocalID, RawPosition); |
484 | return true; | 332 | return true; |
485 | } | 333 | } |
486 | 334 | ||
487 | // If below the ground, move the avatar up | 335 | // If below the ground, move the avatar up |
488 | float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(RawPosition); | 336 | float terrainHeight = PhysScene.TerrainManager.GetTerrainHeightAtXYZ(RawPosition); |
489 | if (Position.Z < terrainHeight) | 337 | if (Position.Z < terrainHeight) |
490 | { | 338 | { |
491 | DetailLog("{0},BSCharacter.PositionSanityCheck,adjustForUnderGround,pos={1},terrain={2}", LocalID, _position, terrainHeight); | 339 | DetailLog("{0},BSCharacter.PositionSanityCheck,adjustForUnderGround,pos={1},terrain={2}", LocalID, RawPosition, terrainHeight); |
492 | _position.Z = terrainHeight + BSParam.AvatarBelowGroundUpCorrectionMeters; | 340 | RawPosition = new OMV.Vector3(RawPosition.X, RawPosition.Y, terrainHeight + BSParam.AvatarBelowGroundUpCorrectionMeters); |
493 | ret = true; | 341 | ret = true; |
494 | } | 342 | } |
495 | if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0) | 343 | if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0) |
496 | { | 344 | { |
497 | float waterHeight = PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(_position); | 345 | float waterHeight = PhysScene.TerrainManager.GetWaterLevelAtXYZ(RawPosition); |
498 | if (Position.Z < waterHeight) | 346 | if (Position.Z < waterHeight) |
499 | { | 347 | { |
500 | _position.Z = waterHeight; | 348 | RawPosition = new OMV.Vector3(RawPosition.X, RawPosition.Y, waterHeight); |
501 | ret = true; | 349 | ret = true; |
502 | } | 350 | } |
503 | } | 351 | } |
@@ -515,10 +363,10 @@ public sealed class BSCharacter : BSPhysObject | |||
515 | { | 363 | { |
516 | // The new position value must be pushed into the physics engine but we can't | 364 | // The new position value must be pushed into the physics engine but we can't |
517 | // just assign to "Position" because of potential call loops. | 365 | // just assign to "Position" because of potential call loops. |
518 | PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.PositionSanityCheck", delegate() | 366 | PhysScene.TaintedObject(inTaintTime, LocalID, "BSCharacter.PositionSanityCheck", delegate() |
519 | { | 367 | { |
520 | DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 368 | DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, RawPosition, RawOrientation); |
521 | ForcePosition = _position; | 369 | ForcePosition = RawPosition; |
522 | }); | 370 | }); |
523 | ret = true; | 371 | ret = true; |
524 | } | 372 | } |
@@ -528,25 +376,25 @@ public sealed class BSCharacter : BSPhysObject | |||
528 | public override float Mass { get { return _mass; } } | 376 | public override float Mass { get { return _mass; } } |
529 | 377 | ||
530 | // used when we only want this prim's mass and not the linkset thing | 378 | // used when we only want this prim's mass and not the linkset thing |
531 | public override float RawMass { | 379 | public override float RawMass { |
532 | get {return _mass; } | 380 | get {return _mass; } |
533 | } | 381 | } |
534 | public override void UpdatePhysicalMassProperties(float physMass, bool inWorld) | 382 | public override void UpdatePhysicalMassProperties(float physMass, bool inWorld) |
535 | { | 383 | { |
536 | OMV.Vector3 localInertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass); | 384 | OMV.Vector3 localInertia = PhysScene.PE.CalculateLocalInertia(PhysShape.physShapeInfo, physMass); |
537 | PhysicsScene.PE.SetMassProps(PhysBody, physMass, localInertia); | 385 | PhysScene.PE.SetMassProps(PhysBody, physMass, localInertia); |
538 | } | 386 | } |
539 | 387 | ||
540 | public override OMV.Vector3 Force { | 388 | public override OMV.Vector3 Force { |
541 | get { return _force; } | 389 | get { return RawForce; } |
542 | set { | 390 | set { |
543 | _force = value; | 391 | RawForce = value; |
544 | // m_log.DebugFormat("{0}: Force = {1}", LogHeader, _force); | 392 | // m_log.DebugFormat("{0}: Force = {1}", LogHeader, _force); |
545 | PhysicsScene.TaintedObject("BSCharacter.SetForce", delegate() | 393 | PhysScene.TaintedObject(LocalID, "BSCharacter.SetForce", delegate() |
546 | { | 394 | { |
547 | DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force); | 395 | DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, RawForce); |
548 | if (PhysBody.HasPhysicalBody) | 396 | if (PhysBody.HasPhysicalBody) |
549 | PhysicsScene.PE.SetObjectForce(PhysBody, _force); | 397 | PhysScene.PE.SetObjectForce(PhysBody, RawForce); |
550 | }); | 398 | }); |
551 | } | 399 | } |
552 | } | 400 | } |
@@ -560,6 +408,7 @@ public sealed class BSCharacter : BSPhysObject | |||
560 | 408 | ||
561 | // Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more | 409 | // Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more |
562 | public override void SetVolumeDetect(int param) { return; } | 410 | public override void SetVolumeDetect(int param) { return; } |
411 | public override bool IsVolumeDetect { get { return false; } } | ||
563 | 412 | ||
564 | public override OMV.Vector3 GeometricCenter { get { return OMV.Vector3.Zero; } } | 413 | public override OMV.Vector3 GeometricCenter { get { return OMV.Vector3.Zero; } } |
565 | public override OMV.Vector3 CenterOfMass { get { return OMV.Vector3.Zero; } } | 414 | public override OMV.Vector3 CenterOfMass { get { return OMV.Vector3.Zero; } } |
@@ -569,61 +418,49 @@ public sealed class BSCharacter : BSPhysObject | |||
569 | { | 418 | { |
570 | get | 419 | get |
571 | { | 420 | { |
572 | return m_targetVelocity; | 421 | return base.m_targetVelocity; |
573 | } | 422 | } |
574 | set | 423 | set |
575 | { | 424 | { |
576 | DetailLog("{0},BSCharacter.setTargetVelocity,call,vel={1}", LocalID, value); | 425 | DetailLog("{0},BSCharacter.setTargetVelocity,call,vel={1}", LocalID, value); |
577 | m_targetVelocity = value; | 426 | m_targetVelocity = value; |
578 | OMV.Vector3 targetVel = value; | 427 | OMV.Vector3 targetVel = value; |
579 | if (_setAlwaysRun) | 428 | if (_setAlwaysRun && !_flying) |
580 | targetVel *= new OMV.Vector3(BSParam.AvatarAlwaysRunFactor, BSParam.AvatarAlwaysRunFactor, 0f); | 429 | targetVel *= new OMV.Vector3(BSParam.AvatarAlwaysRunFactor, BSParam.AvatarAlwaysRunFactor, 0f); |
581 | 430 | ||
582 | PhysicsScene.TaintedObject("BSCharacter.setTargetVelocity", delegate() | 431 | if (m_moveActor != null) |
583 | { | 432 | m_moveActor.SetVelocityAndTarget(RawVelocity, targetVel, false /* inTaintTime */); |
584 | _velocityMotor.Reset(); | ||
585 | _velocityMotor.SetTarget(targetVel); | ||
586 | _velocityMotor.SetCurrent(_velocity); | ||
587 | _velocityMotor.Enabled = true; | ||
588 | }); | ||
589 | } | 433 | } |
590 | } | 434 | } |
591 | public override OMV.Vector3 RawVelocity | ||
592 | { | ||
593 | get { return _velocity; } | ||
594 | set { _velocity = value; } | ||
595 | } | ||
596 | // Directly setting velocity means this is what the user really wants now. | 435 | // Directly setting velocity means this is what the user really wants now. |
597 | public override OMV.Vector3 Velocity { | 436 | public override OMV.Vector3 Velocity { |
598 | get { return _velocity; } | 437 | get { return RawVelocity; } |
599 | set { | 438 | set { |
600 | _velocity = value; | 439 | RawVelocity = value; |
601 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); | 440 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, RawVelocity); |
602 | PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate() | 441 | PhysScene.TaintedObject(LocalID, "BSCharacter.setVelocity", delegate() |
603 | { | 442 | { |
604 | _velocityMotor.Reset(); | 443 | if (m_moveActor != null) |
605 | _velocityMotor.SetCurrent(_velocity); | 444 | m_moveActor.SetVelocityAndTarget(RawVelocity, RawVelocity, true /* inTaintTime */); |
606 | _velocityMotor.SetTarget(_velocity); | ||
607 | _velocityMotor.Enabled = false; | ||
608 | 445 | ||
609 | DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); | 446 | DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, RawVelocity); |
610 | ForceVelocity = _velocity; | 447 | ForceVelocity = RawVelocity; |
611 | }); | 448 | }); |
612 | } | 449 | } |
613 | } | 450 | } |
614 | public override OMV.Vector3 ForceVelocity { | 451 | public override OMV.Vector3 ForceVelocity { |
615 | get { return _velocity; } | 452 | get { return RawVelocity; } |
616 | set { | 453 | set { |
617 | PhysicsScene.AssertInTaintTime("BSCharacter.ForceVelocity"); | 454 | PhysScene.AssertInTaintTime("BSCharacter.ForceVelocity"); |
618 | 455 | ||
619 | _velocity = value; | 456 | RawVelocity = value; |
620 | PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity); | 457 | PhysScene.PE.SetLinearVelocity(PhysBody, RawVelocity); |
621 | PhysicsScene.PE.Activate(PhysBody, true); | 458 | PhysScene.PE.Activate(PhysBody, true); |
622 | } | 459 | } |
623 | } | 460 | } |
624 | public override OMV.Vector3 Torque { | 461 | public override OMV.Vector3 Torque { |
625 | get { return _torque; } | 462 | get { return RawTorque; } |
626 | set { _torque = value; | 463 | set { RawTorque = value; |
627 | } | 464 | } |
628 | } | 465 | } |
629 | public override float CollisionScore { | 466 | public override float CollisionScore { |
@@ -635,22 +472,27 @@ public sealed class BSCharacter : BSPhysObject | |||
635 | get { return _acceleration; } | 472 | get { return _acceleration; } |
636 | set { _acceleration = value; } | 473 | set { _acceleration = value; } |
637 | } | 474 | } |
638 | public override OMV.Quaternion RawOrientation | ||
639 | { | ||
640 | get { return _orientation; } | ||
641 | set { _orientation = value; } | ||
642 | } | ||
643 | public override OMV.Quaternion Orientation { | 475 | public override OMV.Quaternion Orientation { |
644 | get { return _orientation; } | 476 | get { return RawOrientation; } |
645 | set { | 477 | set { |
646 | // Orientation is set zillions of times when an avatar is walking. It's like | 478 | // Orientation is set zillions of times when an avatar is walking. It's like |
647 | // the viewer doesn't trust us. | 479 | // the viewer doesn't trust us. |
648 | if (_orientation != value) | 480 | if (RawOrientation != value) |
649 | { | 481 | { |
650 | _orientation = value; | 482 | RawOrientation = value; |
651 | PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate() | 483 | PhysScene.TaintedObject(LocalID, "BSCharacter.setOrientation", delegate() |
652 | { | 484 | { |
653 | ForceOrientation = _orientation; | 485 | // Bullet assumes we know what we are doing when forcing orientation |
486 | // so it lets us go against all the rules and just compensates for them later. | ||
487 | // This forces rotation to be only around the Z axis and doesn't change any of the other axis. | ||
488 | // This keeps us from flipping the capsule over which the veiwer does not understand. | ||
489 | float oRoll, oPitch, oYaw; | ||
490 | RawOrientation.GetEulerAngles(out oRoll, out oPitch, out oYaw); | ||
491 | OMV.Quaternion trimmedOrientation = OMV.Quaternion.CreateFromEulers(0f, 0f, oYaw); | ||
492 | // DetailLog("{0},BSCharacter.setOrientation,taint,val={1},valDir={2},conv={3},convDir={4}", | ||
493 | // LocalID, RawOrientation, OMV.Vector3.UnitX * RawOrientation, | ||
494 | // trimmedOrientation, OMV.Vector3.UnitX * trimmedOrientation); | ||
495 | ForceOrientation = trimmedOrientation; | ||
654 | }); | 496 | }); |
655 | } | 497 | } |
656 | } | 498 | } |
@@ -660,16 +502,16 @@ public sealed class BSCharacter : BSPhysObject | |||
660 | { | 502 | { |
661 | get | 503 | get |
662 | { | 504 | { |
663 | _orientation = PhysicsScene.PE.GetOrientation(PhysBody); | 505 | RawOrientation = PhysScene.PE.GetOrientation(PhysBody); |
664 | return _orientation; | 506 | return RawOrientation; |
665 | } | 507 | } |
666 | set | 508 | set |
667 | { | 509 | { |
668 | _orientation = value; | 510 | RawOrientation = value; |
669 | if (PhysBody.HasPhysicalBody) | 511 | if (PhysBody.HasPhysicalBody) |
670 | { | 512 | { |
671 | // _position = PhysicsScene.PE.GetPosition(BSBody); | 513 | // RawPosition = PhysicsScene.PE.GetPosition(BSBody); |
672 | PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); | 514 | PhysScene.PE.SetTranslation(PhysBody, RawPosition, RawOrientation); |
673 | } | 515 | } |
674 | } | 516 | } |
675 | } | 517 | } |
@@ -718,14 +560,14 @@ public sealed class BSCharacter : BSPhysObject | |||
718 | public override bool FloatOnWater { | 560 | public override bool FloatOnWater { |
719 | set { | 561 | set { |
720 | _floatOnWater = value; | 562 | _floatOnWater = value; |
721 | PhysicsScene.TaintedObject("BSCharacter.setFloatOnWater", delegate() | 563 | PhysScene.TaintedObject(LocalID, "BSCharacter.setFloatOnWater", delegate() |
722 | { | 564 | { |
723 | if (PhysBody.HasPhysicalBody) | 565 | if (PhysBody.HasPhysicalBody) |
724 | { | 566 | { |
725 | if (_floatOnWater) | 567 | if (_floatOnWater) |
726 | CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); | 568 | CurrentCollisionFlags = PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); |
727 | else | 569 | else |
728 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); | 570 | CurrentCollisionFlags = PhysScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); |
729 | } | 571 | } |
730 | }); | 572 | }); |
731 | } | 573 | } |
@@ -746,7 +588,7 @@ public sealed class BSCharacter : BSPhysObject | |||
746 | public override float Buoyancy { | 588 | public override float Buoyancy { |
747 | get { return _buoyancy; } | 589 | get { return _buoyancy; } |
748 | set { _buoyancy = value; | 590 | set { _buoyancy = value; |
749 | PhysicsScene.TaintedObject("BSCharacter.setBuoyancy", delegate() | 591 | PhysScene.TaintedObject(LocalID, "BSCharacter.setBuoyancy", delegate() |
750 | { | 592 | { |
751 | DetailLog("{0},BSCharacter.setBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 593 | DetailLog("{0},BSCharacter.setBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
752 | ForceBuoyancy = _buoyancy; | 594 | ForceBuoyancy = _buoyancy; |
@@ -755,8 +597,8 @@ public sealed class BSCharacter : BSPhysObject | |||
755 | } | 597 | } |
756 | public override float ForceBuoyancy { | 598 | public override float ForceBuoyancy { |
757 | get { return _buoyancy; } | 599 | get { return _buoyancy; } |
758 | set { | 600 | set { |
759 | PhysicsScene.AssertInTaintTime("BSCharacter.ForceBuoyancy"); | 601 | PhysScene.AssertInTaintTime("BSCharacter.ForceBuoyancy"); |
760 | 602 | ||
761 | _buoyancy = value; | 603 | _buoyancy = value; |
762 | DetailLog("{0},BSCharacter.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 604 | DetailLog("{0},BSCharacter.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
@@ -764,7 +606,7 @@ public sealed class BSCharacter : BSPhysObject | |||
764 | float grav = BSParam.Gravity * (1f - _buoyancy); | 606 | float grav = BSParam.Gravity * (1f - _buoyancy); |
765 | Gravity = new OMV.Vector3(0f, 0f, grav); | 607 | Gravity = new OMV.Vector3(0f, 0f, grav); |
766 | if (PhysBody.HasPhysicalBody) | 608 | if (PhysBody.HasPhysicalBody) |
767 | PhysicsScene.PE.SetGravity(PhysBody, Gravity); | 609 | PhysScene.PE.SetGravity(PhysBody, Gravity); |
768 | } | 610 | } |
769 | } | 611 | } |
770 | 612 | ||
@@ -779,46 +621,25 @@ public sealed class BSCharacter : BSPhysObject | |||
779 | set { _PIDTau = value; } | 621 | set { _PIDTau = value; } |
780 | } | 622 | } |
781 | 623 | ||
782 | // Used for llSetHoverHeight and maybe vehicle height | ||
783 | // Hover Height will override MoveTo target's Z | ||
784 | public override bool PIDHoverActive { | ||
785 | set { _useHoverPID = value; } | ||
786 | } | ||
787 | public override float PIDHoverHeight { | ||
788 | set { _PIDHoverHeight = value; } | ||
789 | } | ||
790 | public override PIDHoverType PIDHoverType { | ||
791 | set { _PIDHoverType = value; } | ||
792 | } | ||
793 | public override float PIDHoverTau { | ||
794 | set { _PIDHoverTao = value; } | ||
795 | } | ||
796 | |||
797 | // For RotLookAt | ||
798 | public override OMV.Quaternion APIDTarget { set { return; } } | ||
799 | public override bool APIDActive { set { return; } } | ||
800 | public override float APIDStrength { set { return; } } | ||
801 | public override float APIDDamping { set { return; } } | ||
802 | |||
803 | public override void AddForce(OMV.Vector3 force, bool pushforce) | 624 | public override void AddForce(OMV.Vector3 force, bool pushforce) |
804 | { | 625 | { |
805 | // Since this force is being applied in only one step, make this a force per second. | 626 | // Since this force is being applied in only one step, make this a force per second. |
806 | OMV.Vector3 addForce = force / PhysicsScene.LastTimeStep; | 627 | OMV.Vector3 addForce = force / PhysScene.LastTimeStep; |
807 | AddForce(addForce, pushforce, false); | 628 | AddForce(addForce, pushforce, false); |
808 | } | 629 | } |
809 | private void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) { | 630 | public override void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) { |
810 | if (force.IsFinite()) | 631 | if (force.IsFinite()) |
811 | { | 632 | { |
812 | OMV.Vector3 addForce = Util.ClampV(force, BSParam.MaxAddForceMagnitude); | 633 | OMV.Vector3 addForce = Util.ClampV(force, BSParam.MaxAddForceMagnitude); |
813 | // DetailLog("{0},BSCharacter.addForce,call,force={1}", LocalID, addForce); | 634 | // DetailLog("{0},BSCharacter.addForce,call,force={1}", LocalID, addForce); |
814 | 635 | ||
815 | PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.AddForce", delegate() | 636 | PhysScene.TaintedObject(inTaintTime, LocalID, "BSCharacter.AddForce", delegate() |
816 | { | 637 | { |
817 | // Bullet adds this central force to the total force for this tick | 638 | // Bullet adds this central force to the total force for this tick |
818 | // DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce); | 639 | // DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce); |
819 | if (PhysBody.HasPhysicalBody) | 640 | if (PhysBody.HasPhysicalBody) |
820 | { | 641 | { |
821 | PhysicsScene.PE.ApplyCentralForce(PhysBody, addForce); | 642 | PhysScene.PE.ApplyCentralForce(PhysBody, addForce); |
822 | } | 643 | } |
823 | }); | 644 | }); |
824 | } | 645 | } |
@@ -829,7 +650,7 @@ public sealed class BSCharacter : BSPhysObject | |||
829 | } | 650 | } |
830 | } | 651 | } |
831 | 652 | ||
832 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { | 653 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) { |
833 | } | 654 | } |
834 | public override void SetMomentum(OMV.Vector3 momentum) { | 655 | public override void SetMomentum(OMV.Vector3 momentum) { |
835 | } | 656 | } |
@@ -837,14 +658,14 @@ public sealed class BSCharacter : BSPhysObject | |||
837 | private OMV.Vector3 ComputeAvatarScale(OMV.Vector3 size) | 658 | private OMV.Vector3 ComputeAvatarScale(OMV.Vector3 size) |
838 | { | 659 | { |
839 | OMV.Vector3 newScale; | 660 | OMV.Vector3 newScale; |
840 | 661 | ||
841 | // Bullet's capsule total height is the "passed height + radius * 2"; | 662 | // Bullet's capsule total height is the "passed height + radius * 2"; |
842 | // The base capsule is 1 diameter and 2 height (passed radius=0.5, passed height = 1) | 663 | // The base capsule is 1 unit in diameter and 2 units in height (passed radius=0.5, passed height = 1) |
843 | // The number we pass in for 'scaling' is the multiplier to get that base | 664 | // The number we pass in for 'scaling' is the multiplier to get that base |
844 | // shape to be the size desired. | 665 | // shape to be the size desired. |
845 | // So, when creating the scale for the avatar height, we take the passed height | 666 | // So, when creating the scale for the avatar height, we take the passed height |
846 | // (size.Z) and remove the caps. | 667 | // (size.Z) and remove the caps. |
847 | // Another oddity of the Bullet capsule implementation is that it presumes the Y | 668 | // An oddity of the Bullet capsule implementation is that it presumes the Y |
848 | // dimension is the radius of the capsule. Even though some of the code allows | 669 | // dimension is the radius of the capsule. Even though some of the code allows |
849 | // for a asymmetrical capsule, other parts of the code presume it is cylindrical. | 670 | // for a asymmetrical capsule, other parts of the code presume it is cylindrical. |
850 | 671 | ||
@@ -852,12 +673,36 @@ public sealed class BSCharacter : BSPhysObject | |||
852 | newScale.X = size.X / 2f; | 673 | newScale.X = size.X / 2f; |
853 | newScale.Y = size.Y / 2f; | 674 | newScale.Y = size.Y / 2f; |
854 | 675 | ||
676 | float heightAdjust = BSParam.AvatarHeightMidFudge; | ||
677 | if (BSParam.AvatarHeightLowFudge != 0f || BSParam.AvatarHeightHighFudge != 0f) | ||
678 | { | ||
679 | const float AVATAR_LOW = 1.1f; | ||
680 | const float AVATAR_MID = 1.775f; // 1.87f | ||
681 | const float AVATAR_HI = 2.45f; | ||
682 | // An avatar is between 1.1 and 2.45 meters. Midpoint is 1.775m. | ||
683 | float midHeightOffset = size.Z - AVATAR_MID; | ||
684 | if (midHeightOffset < 0f) | ||
685 | { | ||
686 | // Small avatar. Add the adjustment based on the distance from midheight | ||
687 | heightAdjust += ((-1f * midHeightOffset) / (AVATAR_MID - AVATAR_LOW)) * BSParam.AvatarHeightLowFudge; | ||
688 | } | ||
689 | else | ||
690 | { | ||
691 | // Large avatar. Add the adjustment based on the distance from midheight | ||
692 | heightAdjust += ((midHeightOffset) / (AVATAR_HI - AVATAR_MID)) * BSParam.AvatarHeightHighFudge; | ||
693 | } | ||
694 | } | ||
855 | // The total scale height is the central cylindar plus the caps on the two ends. | 695 | // The total scale height is the central cylindar plus the caps on the two ends. |
856 | newScale.Z = (size.Z + (Math.Min(size.X, size.Y) * 2)) / 2f; | 696 | newScale.Z = (size.Z + (Math.Min(size.X, size.Y) * 2) + heightAdjust) / 2f; |
697 | // m_log.DebugFormat("{0} ComputeAvatarScale: size={1},adj={2},scale={3}", LogHeader, size, heightAdjust, newScale); | ||
698 | |||
857 | // If smaller than the endcaps, just fake like we're almost that small | 699 | // If smaller than the endcaps, just fake like we're almost that small |
858 | if (newScale.Z < 0) | 700 | if (newScale.Z < 0) |
859 | newScale.Z = 0.1f; | 701 | newScale.Z = 0.1f; |
860 | 702 | ||
703 | DetailLog("{0},BSCharacter.ComputerAvatarScale,size={1},lowF={2},midF={3},hiF={4},adj={5},newScale={6}", | ||
704 | LocalID, size, BSParam.AvatarHeightLowFudge, BSParam.AvatarHeightMidFudge, BSParam.AvatarHeightHighFudge, heightAdjust, newScale); | ||
705 | |||
861 | return newScale; | 706 | return newScale; |
862 | } | 707 | } |
863 | 708 | ||
@@ -882,15 +727,18 @@ public sealed class BSCharacter : BSPhysObject | |||
882 | // the world that things have changed. | 727 | // the world that things have changed. |
883 | public override void UpdateProperties(EntityProperties entprop) | 728 | public override void UpdateProperties(EntityProperties entprop) |
884 | { | 729 | { |
885 | _position = entprop.Position; | 730 | // Let anyone (like the actors) modify the updated properties before they are pushed into the object and the simulator. |
886 | _orientation = entprop.Rotation; | 731 | TriggerPreUpdatePropertyAction(ref entprop); |
732 | |||
733 | RawPosition = entprop.Position; | ||
734 | RawOrientation = entprop.Rotation; | ||
887 | 735 | ||
888 | // Smooth velocity. OpenSimulator is VERY sensitive to changes in velocity of the avatar | 736 | // Smooth velocity. OpenSimulator is VERY sensitive to changes in velocity of the avatar |
889 | // and will send agent updates to the clients if velocity changes by more than | 737 | // and will send agent updates to the clients if velocity changes by more than |
890 | // 0.001m/s. Bullet introduces a lot of jitter in the velocity which causes many | 738 | // 0.001m/s. Bullet introduces a lot of jitter in the velocity which causes many |
891 | // extra updates. | 739 | // extra updates. |
892 | if (!entprop.Velocity.ApproxEquals(_velocity, 0.1f)) | 740 | if (!entprop.Velocity.ApproxEquals(RawVelocity, 0.1f)) |
893 | _velocity = entprop.Velocity; | 741 | RawVelocity = entprop.Velocity; |
894 | 742 | ||
895 | _acceleration = entprop.Acceleration; | 743 | _acceleration = entprop.Acceleration; |
896 | _rotationalVelocity = entprop.RotationalVelocity; | 744 | _rotationalVelocity = entprop.RotationalVelocity; |
@@ -898,8 +746,8 @@ public sealed class BSCharacter : BSPhysObject | |||
898 | // Do some sanity checking for the avatar. Make sure it's above ground and inbounds. | 746 | // Do some sanity checking for the avatar. Make sure it's above ground and inbounds. |
899 | if (PositionSanityCheck(true)) | 747 | if (PositionSanityCheck(true)) |
900 | { | 748 | { |
901 | DetailLog("{0},BSCharacter.UpdateProperties,updatePosForSanity,pos={1}", LocalID, _position); | 749 | DetailLog("{0},BSCharacter.UpdateProperties,updatePosForSanity,pos={1}", LocalID, RawPosition); |
902 | entprop.Position = _position; | 750 | entprop.Position = RawPosition; |
903 | } | 751 | } |
904 | 752 | ||
905 | // remember the current and last set values | 753 | // remember the current and last set values |
@@ -910,10 +758,10 @@ public sealed class BSCharacter : BSPhysObject | |||
910 | // Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this); | 758 | // Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this); |
911 | 759 | ||
912 | // Avatars don't report their changes the usual way. Changes are checked for in the heartbeat loop. | 760 | // Avatars don't report their changes the usual way. Changes are checked for in the heartbeat loop. |
913 | // base.RequestPhysicsterseUpdate(); | 761 | // PhysScene.PostUpdate(this); |
914 | 762 | ||
915 | DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", | 763 | DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", |
916 | LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); | 764 | LocalID, RawPosition, RawOrientation, RawVelocity, _acceleration, _rotationalVelocity); |
917 | } | 765 | } |
918 | } | 766 | } |
919 | } | 767 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs index b813974..b47e9a8 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs | |||
@@ -64,7 +64,7 @@ public abstract class BSConstraint : IDisposable | |||
64 | { | 64 | { |
65 | bool success = PhysicsScene.PE.DestroyConstraint(m_world, m_constraint); | 65 | bool success = PhysicsScene.PE.DestroyConstraint(m_world, m_constraint); |
66 | m_world.physicsScene.DetailLog("{0},BSConstraint.Dispose,taint,id1={1},body1={2},id2={3},body2={4},success={5}", | 66 | m_world.physicsScene.DetailLog("{0},BSConstraint.Dispose,taint,id1={1},body1={2},id2={3},body2={4},success={5}", |
67 | BSScene.DetailLogZero, | 67 | m_body1.ID, |
68 | m_body1.ID, m_body1.AddrString, | 68 | m_body1.ID, m_body1.AddrString, |
69 | m_body2.ID, m_body2.AddrString, | 69 | m_body2.ID, m_body2.AddrString, |
70 | success); | 70 | success); |
@@ -77,7 +77,10 @@ public abstract class BSConstraint : IDisposable | |||
77 | { | 77 | { |
78 | bool ret = false; | 78 | bool ret = false; |
79 | if (m_enabled) | 79 | if (m_enabled) |
80 | { | ||
81 | m_world.physicsScene.DetailLog("{0},BSConstraint.SetLinearLimits,taint,low={1},high={2}", m_body1.ID, low, high); | ||
80 | ret = PhysicsScene.PE.SetLinearLimits(m_constraint, low, high); | 82 | ret = PhysicsScene.PE.SetLinearLimits(m_constraint, low, high); |
83 | } | ||
81 | return ret; | 84 | return ret; |
82 | } | 85 | } |
83 | 86 | ||
@@ -85,7 +88,10 @@ public abstract class BSConstraint : IDisposable | |||
85 | { | 88 | { |
86 | bool ret = false; | 89 | bool ret = false; |
87 | if (m_enabled) | 90 | if (m_enabled) |
91 | { | ||
92 | m_world.physicsScene.DetailLog("{0},BSConstraint.SetAngularLimits,taint,low={1},high={2}", m_body1.ID, low, high); | ||
88 | ret = PhysicsScene.PE.SetAngularLimits(m_constraint, low, high); | 93 | ret = PhysicsScene.PE.SetAngularLimits(m_constraint, low, high); |
94 | } | ||
89 | return ret; | 95 | return ret; |
90 | } | 96 | } |
91 | 97 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs index 476a0e5..7fcb75c 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs | |||
@@ -32,12 +32,19 @@ using OpenMetaverse; | |||
32 | namespace OpenSim.Region.Physics.BulletSPlugin | 32 | namespace OpenSim.Region.Physics.BulletSPlugin |
33 | { | 33 | { |
34 | 34 | ||
35 | public sealed class BSConstraint6Dof : BSConstraint | 35 | public class BSConstraint6Dof : BSConstraint |
36 | { | 36 | { |
37 | private static string LogHeader = "[BULLETSIM 6DOF CONSTRAINT]"; | 37 | private static string LogHeader = "[BULLETSIM 6DOF CONSTRAINT]"; |
38 | 38 | ||
39 | public override ConstraintType Type { get { return ConstraintType.D6_CONSTRAINT_TYPE; } } | 39 | public override ConstraintType Type { get { return ConstraintType.D6_CONSTRAINT_TYPE; } } |
40 | 40 | ||
41 | public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2) :base(world) | ||
42 | { | ||
43 | m_body1 = obj1; | ||
44 | m_body2 = obj2; | ||
45 | m_enabled = false; | ||
46 | } | ||
47 | |||
41 | // Create a btGeneric6DofConstraint | 48 | // Create a btGeneric6DofConstraint |
42 | public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2, | 49 | public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2, |
43 | Vector3 frame1, Quaternion frame1rot, | 50 | Vector3 frame1, Quaternion frame1rot, |
@@ -52,9 +59,11 @@ public sealed class BSConstraint6Dof : BSConstraint | |||
52 | frame2, frame2rot, | 59 | frame2, frame2rot, |
53 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); | 60 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); |
54 | m_enabled = true; | 61 | m_enabled = true; |
55 | world.physicsScene.DetailLog("{0},BS6DofConstraint,createFrame,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", | 62 | PhysicsScene.DetailLog("{0},BS6DofConstraint,create,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", |
56 | BSScene.DetailLogZero, world.worldID, | 63 | m_body1.ID, world.worldID, |
57 | obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString); | 64 | obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString); |
65 | PhysicsScene.DetailLog("{0},BS6DofConstraint,create, f1Loc={1},f1Rot={2},f2Loc={3},f2Rot={4},usefA={5},disCol={6}", | ||
66 | m_body1.ID, frame1, frame1rot, frame2, frame2rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); | ||
58 | } | 67 | } |
59 | 68 | ||
60 | // 6 Dof constraint based on a midpoint between the two constrained bodies | 69 | // 6 Dof constraint based on a midpoint between the two constrained bodies |
@@ -79,9 +88,11 @@ public sealed class BSConstraint6Dof : BSConstraint | |||
79 | m_constraint = PhysicsScene.PE.Create6DofConstraintToPoint(m_world, m_body1, m_body2, | 88 | m_constraint = PhysicsScene.PE.Create6DofConstraintToPoint(m_world, m_body1, m_body2, |
80 | joinPoint, | 89 | joinPoint, |
81 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); | 90 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); |
91 | |||
82 | PhysicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}", | 92 | PhysicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}", |
83 | BSScene.DetailLogZero, world.worldID, m_constraint.AddrString, | 93 | m_body1.ID, world.worldID, m_constraint.AddrString, |
84 | obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString); | 94 | obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString); |
95 | |||
85 | if (!m_constraint.HasPhysicalConstraint) | 96 | if (!m_constraint.HasPhysicalConstraint) |
86 | { | 97 | { |
87 | world.physicsScene.Logger.ErrorFormat("{0} Failed creation of 6Dof constraint. rootID={1}, childID={2}", | 98 | world.physicsScene.Logger.ErrorFormat("{0} Failed creation of 6Dof constraint. rootID={1}, childID={2}", |
@@ -97,17 +108,19 @@ public sealed class BSConstraint6Dof : BSConstraint | |||
97 | 108 | ||
98 | // A 6 Dof constraint that is fixed in the world and constrained to a on-the-fly created static object | 109 | // A 6 Dof constraint that is fixed in the world and constrained to a on-the-fly created static object |
99 | public BSConstraint6Dof(BulletWorld world, BulletBody obj1, Vector3 frameInBloc, Quaternion frameInBrot, | 110 | public BSConstraint6Dof(BulletWorld world, BulletBody obj1, Vector3 frameInBloc, Quaternion frameInBrot, |
100 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) | 111 | bool useLinearReferenceFrameB, bool disableCollisionsBetweenLinkedBodies) |
101 | : base(world) | 112 | : base(world) |
102 | { | 113 | { |
103 | m_body1 = obj1; | 114 | m_body1 = obj1; |
104 | m_body2 = obj1; // Look out for confusion down the road | 115 | m_body2 = obj1; // Look out for confusion down the road |
105 | m_constraint = PhysicsScene.PE.Create6DofConstraintFixed(m_world, m_body1, | 116 | m_constraint = PhysicsScene.PE.Create6DofConstraintFixed(m_world, m_body1, |
106 | frameInBloc, frameInBrot, | 117 | frameInBloc, frameInBrot, |
107 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); | 118 | useLinearReferenceFrameB, disableCollisionsBetweenLinkedBodies); |
108 | m_enabled = true; | 119 | m_enabled = true; |
109 | world.physicsScene.DetailLog("{0},BS6DofConstraint,createFixed,wID={1},rID={2},rBody={3}", | 120 | PhysicsScene.DetailLog("{0},BS6DofConstraint,createFixed,wID={1},rID={2},rBody={3}", |
110 | BSScene.DetailLogZero, world.worldID, obj1.ID, obj1.AddrString); | 121 | m_body1.ID, world.worldID, obj1.ID, obj1.AddrString); |
122 | PhysicsScene.DetailLog("{0},BS6DofConstraint,createFixed, fBLoc={1},fBRot={2},usefA={3},disCol={4}", | ||
123 | m_body1.ID, frameInBloc, frameInBrot, useLinearReferenceFrameB, disableCollisionsBetweenLinkedBodies); | ||
111 | } | 124 | } |
112 | 125 | ||
113 | public bool SetFrames(Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot) | 126 | public bool SetFrames(Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot) |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintConeTwist.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintConeTwist.cs new file mode 100755 index 0000000..7a76a9a --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintConeTwist.cs | |||
@@ -0,0 +1,54 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | using OpenMetaverse; | ||
31 | |||
32 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
33 | { | ||
34 | |||
35 | public sealed class BSConstraintConeTwist : BSConstraint | ||
36 | { | ||
37 | public override ConstraintType Type { get { return ConstraintType.CONETWIST_CONSTRAINT_TYPE; } } | ||
38 | |||
39 | public BSConstraintConeTwist(BulletWorld world, BulletBody obj1, BulletBody obj2, | ||
40 | Vector3 frameInAloc, Quaternion frameInArot, | ||
41 | Vector3 frameInBloc, Quaternion frameInBrot, | ||
42 | bool disableCollisionsBetweenLinkedBodies) | ||
43 | : base(world) | ||
44 | { | ||
45 | m_body1 = obj1; | ||
46 | m_body2 = obj2; | ||
47 | m_constraint = PhysicsScene.PE.CreateConeTwistConstraint(world, obj1, obj2, | ||
48 | frameInAloc, frameInArot, frameInBloc, frameInBrot, | ||
49 | disableCollisionsBetweenLinkedBodies); | ||
50 | m_enabled = true; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | } | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs index 7714a03..ed89f63 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs | |||
@@ -45,7 +45,7 @@ public sealed class BSConstraintHinge : BSConstraint | |||
45 | m_body1 = obj1; | 45 | m_body1 = obj1; |
46 | m_body2 = obj2; | 46 | m_body2 = obj2; |
47 | m_constraint = PhysicsScene.PE.CreateHingeConstraint(world, obj1, obj2, | 47 | m_constraint = PhysicsScene.PE.CreateHingeConstraint(world, obj1, obj2, |
48 | pivotInA, pivotInB, axisInA, axisInB, | 48 | pivotInA, pivotInB, axisInA, axisInB, |
49 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); | 49 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); |
50 | m_enabled = true; | 50 | m_enabled = true; |
51 | } | 51 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintSlider.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintSlider.cs new file mode 100755 index 0000000..37cfa07 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintSlider.cs | |||
@@ -0,0 +1,55 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | using OpenMetaverse; | ||
31 | |||
32 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
33 | { | ||
34 | |||
35 | public sealed class BSConstraintSlider : BSConstraint | ||
36 | { | ||
37 | public override ConstraintType Type { get { return ConstraintType.SLIDER_CONSTRAINT_TYPE; } } | ||
38 | |||
39 | public BSConstraintSlider(BulletWorld world, BulletBody obj1, BulletBody obj2, | ||
40 | Vector3 frameInAloc, Quaternion frameInArot, | ||
41 | Vector3 frameInBloc, Quaternion frameInBrot, | ||
42 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) | ||
43 | : base(world) | ||
44 | { | ||
45 | m_body1 = obj1; | ||
46 | m_body2 = obj2; | ||
47 | m_constraint = PhysicsScene.PE.CreateSliderConstraint(world, obj1, obj2, | ||
48 | frameInAloc, frameInArot, frameInBloc, frameInBrot, | ||
49 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); | ||
50 | m_enabled = true; | ||
51 | } | ||
52 | |||
53 | } | ||
54 | |||
55 | } | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintSpring.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintSpring.cs new file mode 100755 index 0000000..8e7ddff --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintSpring.cs | |||
@@ -0,0 +1,103 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | using OpenMetaverse; | ||
31 | |||
32 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
33 | { | ||
34 | |||
35 | public sealed class BSConstraintSpring : BSConstraint6Dof | ||
36 | { | ||
37 | public override ConstraintType Type { get { return ConstraintType.D6_SPRING_CONSTRAINT_TYPE; } } | ||
38 | |||
39 | public BSConstraintSpring(BulletWorld world, BulletBody obj1, BulletBody obj2, | ||
40 | Vector3 frame1Loc, Quaternion frame1Rot, | ||
41 | Vector3 frame2Loc, Quaternion frame2Rot, | ||
42 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) | ||
43 | :base(world, obj1, obj2) | ||
44 | { | ||
45 | m_constraint = PhysicsScene.PE.Create6DofSpringConstraint(world, obj1, obj2, | ||
46 | frame1Loc, frame1Rot, frame2Loc, frame2Rot, | ||
47 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); | ||
48 | m_enabled = true; | ||
49 | |||
50 | PhysicsScene.DetailLog("{0},BSConstraintSpring,create,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", | ||
51 | obj1.ID, world.worldID, obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString); | ||
52 | PhysicsScene.DetailLog("{0},BSConstraintSpring,create, f1Loc={1},f1Rot={2},f2Loc={3},f2Rot={4},usefA={5},disCol={6}", | ||
53 | m_body1.ID, frame1Loc, frame1Rot, frame2Loc, frame2Rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); | ||
54 | } | ||
55 | |||
56 | public bool SetAxisEnable(int pIndex, bool pAxisEnable) | ||
57 | { | ||
58 | PhysicsScene.DetailLog("{0},BSConstraintSpring.SetEnable,obj1ID={1},obj2ID={2},indx={3},enable={4}", | ||
59 | m_body1.ID, m_body1.ID, m_body2.ID, pIndex, pAxisEnable); | ||
60 | PhysicsScene.PE.SpringEnable(m_constraint, pIndex, BSParam.NumericBool(pAxisEnable)); | ||
61 | return true; | ||
62 | } | ||
63 | |||
64 | public bool SetStiffness(int pIndex, float pStiffness) | ||
65 | { | ||
66 | PhysicsScene.DetailLog("{0},BSConstraintSpring.SetStiffness,obj1ID={1},obj2ID={2},indx={3},stiff={4}", | ||
67 | m_body1.ID, m_body1.ID, m_body2.ID, pIndex, pStiffness); | ||
68 | PhysicsScene.PE.SpringSetStiffness(m_constraint, pIndex, pStiffness); | ||
69 | return true; | ||
70 | } | ||
71 | |||
72 | public bool SetDamping(int pIndex, float pDamping) | ||
73 | { | ||
74 | PhysicsScene.DetailLog("{0},BSConstraintSpring.SetDamping,obj1ID={1},obj2ID={2},indx={3},damp={4}", | ||
75 | m_body1.ID, m_body1.ID, m_body2.ID, pIndex, pDamping); | ||
76 | PhysicsScene.PE.SpringSetDamping(m_constraint, pIndex, pDamping); | ||
77 | return true; | ||
78 | } | ||
79 | |||
80 | public bool SetEquilibriumPoint(int pIndex, float pEqPoint) | ||
81 | { | ||
82 | PhysicsScene.DetailLog("{0},BSConstraintSpring.SetEquilibriumPoint,obj1ID={1},obj2ID={2},indx={3},eqPoint={4}", | ||
83 | m_body1.ID, m_body1.ID, m_body2.ID, pIndex, pEqPoint); | ||
84 | PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, pIndex, pEqPoint); | ||
85 | return true; | ||
86 | } | ||
87 | |||
88 | public bool SetEquilibriumPoint(Vector3 linearEq, Vector3 angularEq) | ||
89 | { | ||
90 | PhysicsScene.DetailLog("{0},BSConstraintSpring.SetEquilibriumPoint,obj1ID={1},obj2ID={2},linearEq={3},angularEq={4}", | ||
91 | m_body1.ID, m_body1.ID, m_body2.ID, linearEq, angularEq); | ||
92 | PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 0, linearEq.X); | ||
93 | PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 1, linearEq.Y); | ||
94 | PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 2, linearEq.Z); | ||
95 | PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 3, angularEq.X); | ||
96 | PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 4, angularEq.Y); | ||
97 | PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 5, angularEq.Z); | ||
98 | return true; | ||
99 | } | ||
100 | |||
101 | } | ||
102 | |||
103 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 65df741..7b98f9d 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -40,13 +40,14 @@ using OpenSim.Region.Physics.Manager; | |||
40 | 40 | ||
41 | namespace OpenSim.Region.Physics.BulletSPlugin | 41 | namespace OpenSim.Region.Physics.BulletSPlugin |
42 | { | 42 | { |
43 | public sealed class BSDynamics | 43 | public sealed class BSDynamics : BSActor |
44 | { | 44 | { |
45 | private static string LogHeader = "[BULLETSIM VEHICLE]"; | 45 | private static string LogHeader = "[BULLETSIM VEHICLE]"; |
46 | 46 | ||
47 | private BSScene PhysicsScene { get; set; } | ||
48 | // the prim this dynamic controller belongs to | 47 | // the prim this dynamic controller belongs to |
49 | private BSPrim Prim { get; set; } | 48 | private BSPrimLinkable ControllingPrim { get; set; } |
49 | |||
50 | private bool m_haveRegisteredForSceneEvents; | ||
50 | 51 | ||
51 | // mass of the vehicle fetched each time we're calles | 52 | // mass of the vehicle fetched each time we're calles |
52 | private float m_vehicleMass; | 53 | private float m_vehicleMass; |
@@ -124,38 +125,24 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
124 | static readonly float PIOverFour = ((float)Math.PI) / 4f; | 125 | static readonly float PIOverFour = ((float)Math.PI) / 4f; |
125 | static readonly float PIOverTwo = ((float)Math.PI) / 2f; | 126 | static readonly float PIOverTwo = ((float)Math.PI) / 2f; |
126 | 127 | ||
127 | // For debugging, flags to turn on and off individual corrections. | 128 | public BSDynamics(BSScene myScene, BSPrim myPrim, string actorName) |
128 | public bool enableAngularVerticalAttraction; | 129 | : base(myScene, myPrim, actorName) |
129 | public bool enableAngularDeflection; | ||
130 | public bool enableAngularBanking; | ||
131 | |||
132 | public BSDynamics(BSScene myScene, BSPrim myPrim) | ||
133 | { | 130 | { |
134 | PhysicsScene = myScene; | ||
135 | Prim = myPrim; | ||
136 | Type = Vehicle.TYPE_NONE; | 131 | Type = Vehicle.TYPE_NONE; |
137 | SetupVehicleDebugging(); | 132 | m_haveRegisteredForSceneEvents = false; |
138 | } | ||
139 | 133 | ||
140 | // Stopgap debugging enablement. Allows source level debugging but still checking | 134 | ControllingPrim = myPrim as BSPrimLinkable; |
141 | // in changes by making enablement of debugging flags from INI file. | 135 | if (ControllingPrim == null) |
142 | public void SetupVehicleDebugging() | ||
143 | { | ||
144 | enableAngularVerticalAttraction = true; | ||
145 | enableAngularDeflection = false; | ||
146 | enableAngularBanking = true; | ||
147 | if (BSParam.VehicleDebuggingEnabled) | ||
148 | { | 136 | { |
149 | enableAngularVerticalAttraction = true; | 137 | // THIS CANNOT HAPPEN!! |
150 | enableAngularDeflection = false; | ||
151 | enableAngularBanking = false; | ||
152 | } | 138 | } |
139 | VDetailLog("{0},Creation", ControllingPrim.LocalID); | ||
153 | } | 140 | } |
154 | 141 | ||
155 | // Return 'true' if this vehicle is doing vehicle things | 142 | // Return 'true' if this vehicle is doing vehicle things |
156 | public bool IsActive | 143 | public bool IsActive |
157 | { | 144 | { |
158 | get { return (Type != Vehicle.TYPE_NONE && Prim.IsPhysicallyActive); } | 145 | get { return (Type != Vehicle.TYPE_NONE && ControllingPrim.IsPhysicallyActive); } |
159 | } | 146 | } |
160 | 147 | ||
161 | // Return 'true' if this a vehicle that should be sitting on the ground | 148 | // Return 'true' if this a vehicle that should be sitting on the ground |
@@ -167,11 +154,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
167 | #region Vehicle parameter setting | 154 | #region Vehicle parameter setting |
168 | public void ProcessFloatVehicleParam(Vehicle pParam, float pValue) | 155 | public void ProcessFloatVehicleParam(Vehicle pParam, float pValue) |
169 | { | 156 | { |
170 | VDetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue); | 157 | VDetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", ControllingPrim.LocalID, pParam, pValue); |
171 | switch (pParam) | 158 | switch (pParam) |
172 | { | 159 | { |
173 | case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY: | 160 | case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY: |
174 | m_angularDeflectionEfficiency = Math.Max(pValue, 0.01f); | 161 | m_angularDeflectionEfficiency = ClampInRange(0f, pValue, 1f); |
175 | break; | 162 | break; |
176 | case Vehicle.ANGULAR_DEFLECTION_TIMESCALE: | 163 | case Vehicle.ANGULAR_DEFLECTION_TIMESCALE: |
177 | m_angularDeflectionTimescale = Math.Max(pValue, 0.01f); | 164 | m_angularDeflectionTimescale = Math.Max(pValue, 0.01f); |
@@ -195,7 +182,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
195 | break; | 182 | break; |
196 | case Vehicle.BUOYANCY: | 183 | case Vehicle.BUOYANCY: |
197 | m_VehicleBuoyancy = ClampInRange(-1f, pValue, 1f); | 184 | m_VehicleBuoyancy = ClampInRange(-1f, pValue, 1f); |
198 | m_VehicleGravity = Prim.ComputeGravity(m_VehicleBuoyancy); | 185 | m_VehicleGravity = ControllingPrim.ComputeGravity(m_VehicleBuoyancy); |
199 | break; | 186 | break; |
200 | case Vehicle.HOVER_EFFICIENCY: | 187 | case Vehicle.HOVER_EFFICIENCY: |
201 | m_VhoverEfficiency = ClampInRange(0f, pValue, 1f); | 188 | m_VhoverEfficiency = ClampInRange(0f, pValue, 1f); |
@@ -207,7 +194,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
207 | m_VhoverTimescale = Math.Max(pValue, 0.01f); | 194 | m_VhoverTimescale = Math.Max(pValue, 0.01f); |
208 | break; | 195 | break; |
209 | case Vehicle.LINEAR_DEFLECTION_EFFICIENCY: | 196 | case Vehicle.LINEAR_DEFLECTION_EFFICIENCY: |
210 | m_linearDeflectionEfficiency = Math.Max(pValue, 0.01f); | 197 | m_linearDeflectionEfficiency = ClampInRange(0f, pValue, 1f); |
211 | break; | 198 | break; |
212 | case Vehicle.LINEAR_DEFLECTION_TIMESCALE: | 199 | case Vehicle.LINEAR_DEFLECTION_TIMESCALE: |
213 | m_linearDeflectionTimescale = Math.Max(pValue, 0.01f); | 200 | m_linearDeflectionTimescale = Math.Max(pValue, 0.01f); |
@@ -233,7 +220,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
233 | // set all of the components to the same value | 220 | // set all of the components to the same value |
234 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: | 221 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: |
235 | m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue); | 222 | m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue); |
236 | m_angularMotor.FrictionTimescale = m_angularFrictionTimescale; | ||
237 | break; | 223 | break; |
238 | case Vehicle.ANGULAR_MOTOR_DIRECTION: | 224 | case Vehicle.ANGULAR_MOTOR_DIRECTION: |
239 | m_angularMotorDirection = new Vector3(pValue, pValue, pValue); | 225 | m_angularMotorDirection = new Vector3(pValue, pValue, pValue); |
@@ -242,7 +228,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
242 | break; | 228 | break; |
243 | case Vehicle.LINEAR_FRICTION_TIMESCALE: | 229 | case Vehicle.LINEAR_FRICTION_TIMESCALE: |
244 | m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue); | 230 | m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue); |
245 | m_linearMotor.FrictionTimescale = m_linearFrictionTimescale; | ||
246 | break; | 231 | break; |
247 | case Vehicle.LINEAR_MOTOR_DIRECTION: | 232 | case Vehicle.LINEAR_MOTOR_DIRECTION: |
248 | m_linearMotorDirection = new Vector3(pValue, pValue, pValue); | 233 | m_linearMotorDirection = new Vector3(pValue, pValue, pValue); |
@@ -258,12 +243,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
258 | 243 | ||
259 | internal void ProcessVectorVehicleParam(Vehicle pParam, Vector3 pValue) | 244 | internal void ProcessVectorVehicleParam(Vehicle pParam, Vector3 pValue) |
260 | { | 245 | { |
261 | VDetailLog("{0},ProcessVectorVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue); | 246 | VDetailLog("{0},ProcessVectorVehicleParam,param={1},val={2}", ControllingPrim.LocalID, pParam, pValue); |
262 | switch (pParam) | 247 | switch (pParam) |
263 | { | 248 | { |
264 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: | 249 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: |
265 | m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); | 250 | m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); |
266 | m_angularMotor.FrictionTimescale = m_angularFrictionTimescale; | ||
267 | break; | 251 | break; |
268 | case Vehicle.ANGULAR_MOTOR_DIRECTION: | 252 | case Vehicle.ANGULAR_MOTOR_DIRECTION: |
269 | // Limit requested angular speed to 2 rps= 4 pi rads/sec | 253 | // Limit requested angular speed to 2 rps= 4 pi rads/sec |
@@ -276,7 +260,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
276 | break; | 260 | break; |
277 | case Vehicle.LINEAR_FRICTION_TIMESCALE: | 261 | case Vehicle.LINEAR_FRICTION_TIMESCALE: |
278 | m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); | 262 | m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); |
279 | m_linearMotor.FrictionTimescale = m_linearFrictionTimescale; | ||
280 | break; | 263 | break; |
281 | case Vehicle.LINEAR_MOTOR_DIRECTION: | 264 | case Vehicle.LINEAR_MOTOR_DIRECTION: |
282 | m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); | 265 | m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); |
@@ -294,7 +277,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
294 | 277 | ||
295 | internal void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue) | 278 | internal void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue) |
296 | { | 279 | { |
297 | VDetailLog("{0},ProcessRotationalVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue); | 280 | VDetailLog("{0},ProcessRotationalVehicleParam,param={1},val={2}", ControllingPrim.LocalID, pParam, pValue); |
298 | switch (pParam) | 281 | switch (pParam) |
299 | { | 282 | { |
300 | case Vehicle.REFERENCE_FRAME: | 283 | case Vehicle.REFERENCE_FRAME: |
@@ -308,7 +291,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
308 | 291 | ||
309 | internal void ProcessVehicleFlags(int pParam, bool remove) | 292 | internal void ProcessVehicleFlags(int pParam, bool remove) |
310 | { | 293 | { |
311 | VDetailLog("{0},ProcessVehicleFlags,param={1},remove={2}", Prim.LocalID, pParam, remove); | 294 | VDetailLog("{0},ProcessVehicleFlags,param={1},remove={2}", ControllingPrim.LocalID, pParam, remove); |
312 | VehicleFlag parm = (VehicleFlag)pParam; | 295 | VehicleFlag parm = (VehicleFlag)pParam; |
313 | if (pParam == -1) | 296 | if (pParam == -1) |
314 | m_flags = (VehicleFlag)0; | 297 | m_flags = (VehicleFlag)0; |
@@ -323,7 +306,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
323 | 306 | ||
324 | public void ProcessTypeChange(Vehicle pType) | 307 | public void ProcessTypeChange(Vehicle pType) |
325 | { | 308 | { |
326 | VDetailLog("{0},ProcessTypeChange,type={1}", Prim.LocalID, pType); | 309 | VDetailLog("{0},ProcessTypeChange,type={1}", ControllingPrim.LocalID, pType); |
327 | // Set Defaults For Type | 310 | // Set Defaults For Type |
328 | Type = pType; | 311 | Type = pType; |
329 | switch (pType) | 312 | switch (pType) |
@@ -557,34 +540,40 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
557 | break; | 540 | break; |
558 | } | 541 | } |
559 | 542 | ||
560 | // Update any physical parameters based on this type. | 543 | m_linearMotor = new BSVMotor("LinearMotor", m_linearMotorTimescale, m_linearMotorDecayTimescale, 1f); |
561 | Refresh(); | 544 | // m_linearMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG DEBUG (enables detail logging) |
562 | |||
563 | m_linearMotor = new BSVMotor("LinearMotor", m_linearMotorTimescale, | ||
564 | m_linearMotorDecayTimescale, m_linearFrictionTimescale, | ||
565 | 1f); | ||
566 | m_linearMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) | ||
567 | 545 | ||
568 | m_angularMotor = new BSVMotor("AngularMotor", m_angularMotorTimescale, | 546 | m_angularMotor = new BSVMotor("AngularMotor", m_angularMotorTimescale, m_angularMotorDecayTimescale, 1f); |
569 | m_angularMotorDecayTimescale, m_angularFrictionTimescale, | 547 | // m_angularMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG DEBUG (enables detail logging) |
570 | 1f); | ||
571 | m_angularMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) | ||
572 | 548 | ||
573 | /* Not implemented | 549 | /* Not implemented |
574 | m_verticalAttractionMotor = new BSVMotor("VerticalAttraction", m_verticalAttractionTimescale, | 550 | m_verticalAttractionMotor = new BSVMotor("VerticalAttraction", m_verticalAttractionTimescale, |
575 | BSMotor.Infinite, BSMotor.InfiniteVector, | 551 | BSMotor.Infinite, BSMotor.InfiniteVector, |
576 | m_verticalAttractionEfficiency); | 552 | m_verticalAttractionEfficiency); |
577 | // Z goes away and we keep X and Y | 553 | // Z goes away and we keep X and Y |
578 | m_verticalAttractionMotor.FrictionTimescale = new Vector3(BSMotor.Infinite, BSMotor.Infinite, 0.1f); | ||
579 | m_verticalAttractionMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) | 554 | m_verticalAttractionMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) |
580 | */ | 555 | */ |
556 | |||
557 | if (this.Type == Vehicle.TYPE_NONE) | ||
558 | { | ||
559 | UnregisterForSceneEvents(); | ||
560 | } | ||
561 | else | ||
562 | { | ||
563 | RegisterForSceneEvents(); | ||
564 | } | ||
565 | |||
566 | // Update any physical parameters based on this type. | ||
567 | Refresh(); | ||
581 | } | 568 | } |
582 | #endregion // Vehicle parameter setting | 569 | #endregion // Vehicle parameter setting |
583 | 570 | ||
584 | public void Refresh() | 571 | // BSActor.Refresh() |
572 | public override void Refresh() | ||
585 | { | 573 | { |
586 | // If asking for a refresh, reset the physical parameters before the next simulation step. | 574 | // If asking for a refresh, reset the physical parameters before the next simulation step. |
587 | PhysicsScene.PostTaintObject("BSDynamics.Refresh", Prim.LocalID, delegate() | 575 | // Called whether active or not since the active state may be updated before the next step. |
576 | m_physicsScene.PostTaintObject("BSDynamics.Refresh", ControllingPrim.LocalID, delegate() | ||
588 | { | 577 | { |
589 | SetPhysicalParameters(); | 578 | SetPhysicalParameters(); |
590 | }); | 579 | }); |
@@ -597,49 +586,98 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
597 | if (IsActive) | 586 | if (IsActive) |
598 | { | 587 | { |
599 | // Remember the mass so we don't have to fetch it every step | 588 | // Remember the mass so we don't have to fetch it every step |
600 | m_vehicleMass = Prim.TotalMass; | 589 | m_vehicleMass = ControllingPrim.TotalMass; |
601 | 590 | ||
602 | // Friction affects are handled by this vehicle code | 591 | // Friction affects are handled by this vehicle code |
603 | PhysicsScene.PE.SetFriction(Prim.PhysBody, BSParam.VehicleFriction); | 592 | // m_physicsScene.PE.SetFriction(ControllingPrim.PhysBody, BSParam.VehicleFriction); |
604 | PhysicsScene.PE.SetRestitution(Prim.PhysBody, BSParam.VehicleRestitution); | 593 | // m_physicsScene.PE.SetRestitution(ControllingPrim.PhysBody, BSParam.VehicleRestitution); |
594 | ControllingPrim.Linkset.SetPhysicalFriction(BSParam.VehicleFriction); | ||
595 | ControllingPrim.Linkset.SetPhysicalRestitution(BSParam.VehicleRestitution); | ||
605 | 596 | ||
606 | // Moderate angular movement introduced by Bullet. | 597 | // Moderate angular movement introduced by Bullet. |
607 | // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle. | 598 | // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle. |
608 | // Maybe compute linear and angular factor and damping from params. | 599 | // Maybe compute linear and angular factor and damping from params. |
609 | PhysicsScene.PE.SetAngularDamping(Prim.PhysBody, BSParam.VehicleAngularDamping); | 600 | m_physicsScene.PE.SetAngularDamping(ControllingPrim.PhysBody, BSParam.VehicleAngularDamping); |
610 | PhysicsScene.PE.SetLinearFactor(Prim.PhysBody, BSParam.VehicleLinearFactor); | 601 | m_physicsScene.PE.SetLinearFactor(ControllingPrim.PhysBody, BSParam.VehicleLinearFactor); |
611 | PhysicsScene.PE.SetAngularFactorV(Prim.PhysBody, BSParam.VehicleAngularFactor); | 602 | m_physicsScene.PE.SetAngularFactorV(ControllingPrim.PhysBody, BSParam.VehicleAngularFactor); |
612 | 603 | ||
613 | // Vehicles report collision events so we know when it's on the ground | 604 | // Vehicles report collision events so we know when it's on the ground |
614 | PhysicsScene.PE.AddToCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); | 605 | // m_physicsScene.PE.AddToCollisionFlags(ControllingPrim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); |
606 | ControllingPrim.Linkset.AddToPhysicalCollisionFlags(CollisionFlags.BS_VEHICLE_COLLISIONS); | ||
615 | 607 | ||
616 | Prim.Inertia = PhysicsScene.PE.CalculateLocalInertia(Prim.PhysShape, m_vehicleMass); | 608 | // Vector3 inertia = m_physicsScene.PE.CalculateLocalInertia(ControllingPrim.PhysShape.physShapeInfo, m_vehicleMass); |
617 | PhysicsScene.PE.SetMassProps(Prim.PhysBody, m_vehicleMass, Prim.Inertia); | 609 | // ControllingPrim.Inertia = inertia * BSParam.VehicleInertiaFactor; |
618 | PhysicsScene.PE.UpdateInertiaTensor(Prim.PhysBody); | 610 | // m_physicsScene.PE.SetMassProps(ControllingPrim.PhysBody, m_vehicleMass, ControllingPrim.Inertia); |
611 | // m_physicsScene.PE.UpdateInertiaTensor(ControllingPrim.PhysBody); | ||
612 | ControllingPrim.Linkset.ComputeAndSetLocalInertia(BSParam.VehicleInertiaFactor, m_vehicleMass); | ||
619 | 613 | ||
620 | // Set the gravity for the vehicle depending on the buoyancy | 614 | // Set the gravity for the vehicle depending on the buoyancy |
621 | // TODO: what should be done if prim and vehicle buoyancy differ? | 615 | // TODO: what should be done if prim and vehicle buoyancy differ? |
622 | m_VehicleGravity = Prim.ComputeGravity(m_VehicleBuoyancy); | 616 | m_VehicleGravity = ControllingPrim.ComputeGravity(m_VehicleBuoyancy); |
623 | // The actual vehicle gravity is set to zero in Bullet so we can do all the application of same. | 617 | // The actual vehicle gravity is set to zero in Bullet so we can do all the application of same. |
624 | PhysicsScene.PE.SetGravity(Prim.PhysBody, Vector3.Zero); | 618 | // m_physicsScene.PE.SetGravity(ControllingPrim.PhysBody, Vector3.Zero); |
619 | ControllingPrim.Linkset.SetPhysicalGravity(Vector3.Zero); | ||
625 | 620 | ||
626 | VDetailLog("{0},BSDynamics.SetPhysicalParameters,mass={1},inert={2},vehGrav={3},aDamp={4},frict={5},rest={6},lFact={7},aFact={8}", | 621 | VDetailLog("{0},BSDynamics.SetPhysicalParameters,mass={1},inert={2},vehGrav={3},aDamp={4},frict={5},rest={6},lFact={7},aFact={8}", |
627 | Prim.LocalID, m_vehicleMass, Prim.Inertia, m_VehicleGravity, | 622 | ControllingPrim.LocalID, m_vehicleMass, ControllingPrim.Inertia, m_VehicleGravity, |
628 | BSParam.VehicleAngularDamping, BSParam.VehicleFriction, BSParam.VehicleRestitution, | 623 | BSParam.VehicleAngularDamping, BSParam.VehicleFriction, BSParam.VehicleRestitution, |
629 | BSParam.VehicleLinearFactor, BSParam.VehicleAngularFactor | 624 | BSParam.VehicleLinearFactor, BSParam.VehicleAngularFactor |
630 | ); | 625 | ); |
631 | } | 626 | } |
632 | else | 627 | else |
633 | { | 628 | { |
634 | if (Prim.PhysBody.HasPhysicalBody) | 629 | if (ControllingPrim.PhysBody.HasPhysicalBody) |
635 | PhysicsScene.PE.RemoveFromCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); | 630 | m_physicsScene.PE.RemoveFromCollisionFlags(ControllingPrim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); |
631 | // ControllingPrim.Linkset.RemoveFromPhysicalCollisionFlags(CollisionFlags.BS_VEHICLE_COLLISIONS); | ||
636 | } | 632 | } |
637 | } | 633 | } |
638 | 634 | ||
639 | public bool RemoveBodyDependencies(BSPhysObject prim) | 635 | // BSActor.RemoveBodyDependencies |
636 | public override void RemoveDependencies() | ||
640 | { | 637 | { |
641 | Refresh(); | 638 | Refresh(); |
642 | return IsActive; | 639 | } |
640 | |||
641 | // BSActor.Release() | ||
642 | public override void Dispose() | ||
643 | { | ||
644 | VDetailLog("{0},Dispose", ControllingPrim.LocalID); | ||
645 | UnregisterForSceneEvents(); | ||
646 | Type = Vehicle.TYPE_NONE; | ||
647 | Enabled = false; | ||
648 | return; | ||
649 | } | ||
650 | |||
651 | private void RegisterForSceneEvents() | ||
652 | { | ||
653 | if (!m_haveRegisteredForSceneEvents) | ||
654 | { | ||
655 | m_physicsScene.BeforeStep += this.Step; | ||
656 | m_physicsScene.AfterStep += this.PostStep; | ||
657 | ControllingPrim.OnPreUpdateProperty += this.PreUpdateProperty; | ||
658 | m_haveRegisteredForSceneEvents = true; | ||
659 | } | ||
660 | } | ||
661 | |||
662 | private void UnregisterForSceneEvents() | ||
663 | { | ||
664 | if (m_haveRegisteredForSceneEvents) | ||
665 | { | ||
666 | m_physicsScene.BeforeStep -= this.Step; | ||
667 | m_physicsScene.AfterStep -= this.PostStep; | ||
668 | ControllingPrim.OnPreUpdateProperty -= this.PreUpdateProperty; | ||
669 | m_haveRegisteredForSceneEvents = false; | ||
670 | } | ||
671 | } | ||
672 | |||
673 | private void PreUpdateProperty(ref EntityProperties entprop) | ||
674 | { | ||
675 | // A temporary kludge to suppress the rotational effects introduced on vehicles by Bullet | ||
676 | // TODO: handle physics introduced by Bullet with computed vehicle physics. | ||
677 | if (IsActive) | ||
678 | { | ||
679 | entprop.RotationalVelocity = Vector3.Zero; | ||
680 | } | ||
643 | } | 681 | } |
644 | 682 | ||
645 | #region Known vehicle value functions | 683 | #region Known vehicle value functions |
@@ -661,7 +699,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
661 | private Vector3 m_knownRotationalVelocity; | 699 | private Vector3 m_knownRotationalVelocity; |
662 | private Vector3 m_knownRotationalForce; | 700 | private Vector3 m_knownRotationalForce; |
663 | private Vector3 m_knownRotationalImpulse; | 701 | private Vector3 m_knownRotationalImpulse; |
664 | private Vector3 m_knownForwardVelocity; // vehicle relative forward speed | ||
665 | 702 | ||
666 | private const int m_knownChangedPosition = 1 << 0; | 703 | private const int m_knownChangedPosition = 1 << 0; |
667 | private const int m_knownChangedVelocity = 1 << 1; | 704 | private const int m_knownChangedVelocity = 1 << 1; |
@@ -673,7 +710,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
673 | private const int m_knownChangedRotationalImpulse = 1 << 7; | 710 | private const int m_knownChangedRotationalImpulse = 1 << 7; |
674 | private const int m_knownChangedTerrainHeight = 1 << 8; | 711 | private const int m_knownChangedTerrainHeight = 1 << 8; |
675 | private const int m_knownChangedWaterLevel = 1 << 9; | 712 | private const int m_knownChangedWaterLevel = 1 << 9; |
676 | private const int m_knownChangedForwardVelocity = 1 <<10; | ||
677 | 713 | ||
678 | public void ForgetKnownVehicleProperties() | 714 | public void ForgetKnownVehicleProperties() |
679 | { | 715 | { |
@@ -686,14 +722,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
686 | if (m_knownChanged != 0) | 722 | if (m_knownChanged != 0) |
687 | { | 723 | { |
688 | if ((m_knownChanged & m_knownChangedPosition) != 0) | 724 | if ((m_knownChanged & m_knownChangedPosition) != 0) |
689 | Prim.ForcePosition = m_knownPosition; | 725 | ControllingPrim.ForcePosition = m_knownPosition; |
690 | 726 | ||
691 | if ((m_knownChanged & m_knownChangedOrientation) != 0) | 727 | if ((m_knownChanged & m_knownChangedOrientation) != 0) |
692 | Prim.ForceOrientation = m_knownOrientation; | 728 | ControllingPrim.ForceOrientation = m_knownOrientation; |
693 | 729 | ||
694 | if ((m_knownChanged & m_knownChangedVelocity) != 0) | 730 | if ((m_knownChanged & m_knownChangedVelocity) != 0) |
695 | { | 731 | { |
696 | Prim.ForceVelocity = m_knownVelocity; | 732 | ControllingPrim.ForceVelocity = m_knownVelocity; |
697 | // Fake out Bullet by making it think the velocity is the same as last time. | 733 | // Fake out Bullet by making it think the velocity is the same as last time. |
698 | // Bullet does a bunch of smoothing for changing parameters. | 734 | // Bullet does a bunch of smoothing for changing parameters. |
699 | // Since the vehicle is demanding this setting, we override Bullet's smoothing | 735 | // Since the vehicle is demanding this setting, we override Bullet's smoothing |
@@ -702,41 +738,41 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
702 | } | 738 | } |
703 | 739 | ||
704 | if ((m_knownChanged & m_knownChangedForce) != 0) | 740 | if ((m_knownChanged & m_knownChangedForce) != 0) |
705 | Prim.AddForce((Vector3)m_knownForce, false /*pushForce*/, true /*inTaintTime*/); | 741 | ControllingPrim.AddForce((Vector3)m_knownForce, false /*pushForce*/, true /*inTaintTime*/); |
706 | 742 | ||
707 | if ((m_knownChanged & m_knownChangedForceImpulse) != 0) | 743 | if ((m_knownChanged & m_knownChangedForceImpulse) != 0) |
708 | Prim.AddForceImpulse((Vector3)m_knownForceImpulse, false /*pushforce*/, true /*inTaintTime*/); | 744 | ControllingPrim.AddForceImpulse((Vector3)m_knownForceImpulse, false /*pushforce*/, true /*inTaintTime*/); |
709 | 745 | ||
710 | if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0) | 746 | if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0) |
711 | { | 747 | { |
712 | Prim.ForceRotationalVelocity = m_knownRotationalVelocity; | 748 | ControllingPrim.ForceRotationalVelocity = m_knownRotationalVelocity; |
713 | // PhysicsScene.PE.SetInterpolationAngularVelocity(Prim.PhysBody, m_knownRotationalVelocity); | 749 | // PhysicsScene.PE.SetInterpolationAngularVelocity(Prim.PhysBody, m_knownRotationalVelocity); |
714 | } | 750 | } |
715 | 751 | ||
716 | if ((m_knownChanged & m_knownChangedRotationalImpulse) != 0) | 752 | if ((m_knownChanged & m_knownChangedRotationalImpulse) != 0) |
717 | Prim.ApplyTorqueImpulse((Vector3)m_knownRotationalImpulse, true /*inTaintTime*/); | 753 | ControllingPrim.ApplyTorqueImpulse((Vector3)m_knownRotationalImpulse, true /*inTaintTime*/); |
718 | 754 | ||
719 | if ((m_knownChanged & m_knownChangedRotationalForce) != 0) | 755 | if ((m_knownChanged & m_knownChangedRotationalForce) != 0) |
720 | { | 756 | { |
721 | Prim.AddAngularForce((Vector3)m_knownRotationalForce, false /*pushForce*/, true /*inTaintTime*/); | 757 | ControllingPrim.AddAngularForce((Vector3)m_knownRotationalForce, false /*pushForce*/, true /*inTaintTime*/); |
722 | } | 758 | } |
723 | 759 | ||
724 | // If we set one of the values (ie, the physics engine didn't do it) we must force | 760 | // If we set one of the values (ie, the physics engine didn't do it) we must force |
725 | // an UpdateProperties event to send the changes up to the simulator. | 761 | // an UpdateProperties event to send the changes up to the simulator. |
726 | PhysicsScene.PE.PushUpdate(Prim.PhysBody); | 762 | m_physicsScene.PE.PushUpdate(ControllingPrim.PhysBody); |
727 | } | 763 | } |
728 | m_knownChanged = 0; | 764 | m_knownChanged = 0; |
729 | } | 765 | } |
730 | 766 | ||
731 | // Since the computation of terrain height can be a little involved, this routine | 767 | // Since the computation of terrain height can be a little involved, this routine |
732 | // is used to fetch the height only once for each vehicle simulation step. | 768 | // is used to fetch the height only once for each vehicle simulation step. |
733 | Vector3 lastRememberedHeightPos; | 769 | Vector3 lastRememberedHeightPos = new Vector3(-1, -1, -1); |
734 | private float GetTerrainHeight(Vector3 pos) | 770 | private float GetTerrainHeight(Vector3 pos) |
735 | { | 771 | { |
736 | if ((m_knownHas & m_knownChangedTerrainHeight) == 0 || pos != lastRememberedHeightPos) | 772 | if ((m_knownHas & m_knownChangedTerrainHeight) == 0 || pos != lastRememberedHeightPos) |
737 | { | 773 | { |
738 | lastRememberedHeightPos = pos; | 774 | lastRememberedHeightPos = pos; |
739 | m_knownTerrainHeight = Prim.PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos); | 775 | m_knownTerrainHeight = ControllingPrim.PhysScene.TerrainManager.GetTerrainHeightAtXYZ(pos); |
740 | m_knownHas |= m_knownChangedTerrainHeight; | 776 | m_knownHas |= m_knownChangedTerrainHeight; |
741 | } | 777 | } |
742 | return m_knownTerrainHeight; | 778 | return m_knownTerrainHeight; |
@@ -744,14 +780,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
744 | 780 | ||
745 | // Since the computation of water level can be a little involved, this routine | 781 | // Since the computation of water level can be a little involved, this routine |
746 | // is used ot fetch the level only once for each vehicle simulation step. | 782 | // is used ot fetch the level only once for each vehicle simulation step. |
783 | Vector3 lastRememberedWaterHeightPos = new Vector3(-1, -1, -1); | ||
747 | private float GetWaterLevel(Vector3 pos) | 784 | private float GetWaterLevel(Vector3 pos) |
748 | { | 785 | { |
749 | if ((m_knownHas & m_knownChangedWaterLevel) == 0) | 786 | if ((m_knownHas & m_knownChangedWaterLevel) == 0 || pos != lastRememberedWaterHeightPos) |
750 | { | 787 | { |
751 | m_knownWaterLevel = Prim.PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(pos); | 788 | lastRememberedWaterHeightPos = pos; |
789 | m_knownWaterLevel = ControllingPrim.PhysScene.TerrainManager.GetWaterLevelAtXYZ(pos); | ||
752 | m_knownHas |= m_knownChangedWaterLevel; | 790 | m_knownHas |= m_knownChangedWaterLevel; |
753 | } | 791 | } |
754 | return (float)m_knownWaterLevel; | 792 | return m_knownWaterLevel; |
755 | } | 793 | } |
756 | 794 | ||
757 | private Vector3 VehiclePosition | 795 | private Vector3 VehiclePosition |
@@ -760,7 +798,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
760 | { | 798 | { |
761 | if ((m_knownHas & m_knownChangedPosition) == 0) | 799 | if ((m_knownHas & m_knownChangedPosition) == 0) |
762 | { | 800 | { |
763 | m_knownPosition = Prim.ForcePosition; | 801 | m_knownPosition = ControllingPrim.ForcePosition; |
764 | m_knownHas |= m_knownChangedPosition; | 802 | m_knownHas |= m_knownChangedPosition; |
765 | } | 803 | } |
766 | return m_knownPosition; | 804 | return m_knownPosition; |
@@ -779,7 +817,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
779 | { | 817 | { |
780 | if ((m_knownHas & m_knownChangedOrientation) == 0) | 818 | if ((m_knownHas & m_knownChangedOrientation) == 0) |
781 | { | 819 | { |
782 | m_knownOrientation = Prim.ForceOrientation; | 820 | m_knownOrientation = ControllingPrim.ForceOrientation; |
783 | m_knownHas |= m_knownChangedOrientation; | 821 | m_knownHas |= m_knownChangedOrientation; |
784 | } | 822 | } |
785 | return m_knownOrientation; | 823 | return m_knownOrientation; |
@@ -798,7 +836,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
798 | { | 836 | { |
799 | if ((m_knownHas & m_knownChangedVelocity) == 0) | 837 | if ((m_knownHas & m_knownChangedVelocity) == 0) |
800 | { | 838 | { |
801 | m_knownVelocity = Prim.ForceVelocity; | 839 | m_knownVelocity = ControllingPrim.ForceVelocity; |
802 | m_knownHas |= m_knownChangedVelocity; | 840 | m_knownHas |= m_knownChangedVelocity; |
803 | } | 841 | } |
804 | return m_knownVelocity; | 842 | return m_knownVelocity; |
@@ -839,7 +877,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
839 | { | 877 | { |
840 | if ((m_knownHas & m_knownChangedRotationalVelocity) == 0) | 878 | if ((m_knownHas & m_knownChangedRotationalVelocity) == 0) |
841 | { | 879 | { |
842 | m_knownRotationalVelocity = Prim.ForceRotationalVelocity; | 880 | m_knownRotationalVelocity = ControllingPrim.ForceRotationalVelocity; |
843 | m_knownHas |= m_knownChangedRotationalVelocity; | 881 | m_knownHas |= m_knownChangedRotationalVelocity; |
844 | } | 882 | } |
845 | return (Vector3)m_knownRotationalVelocity; | 883 | return (Vector3)m_knownRotationalVelocity; |
@@ -877,14 +915,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
877 | { | 915 | { |
878 | get | 916 | get |
879 | { | 917 | { |
880 | if ((m_knownHas & m_knownChangedForwardVelocity) == 0) | 918 | return VehicleVelocity * Quaternion.Inverse(Quaternion.Normalize(VehicleOrientation)); |
881 | { | ||
882 | m_knownForwardVelocity = VehicleVelocity * Quaternion.Inverse(Quaternion.Normalize(VehicleOrientation)); | ||
883 | m_knownHas |= m_knownChangedForwardVelocity; | ||
884 | } | ||
885 | return m_knownForwardVelocity; | ||
886 | } | 919 | } |
887 | } | 920 | } |
921 | |||
888 | private float VehicleForwardSpeed | 922 | private float VehicleForwardSpeed |
889 | { | 923 | { |
890 | get | 924 | get |
@@ -914,11 +948,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
914 | // for the physics engine to note the changes so an UpdateProperties event will happen. | 948 | // for the physics engine to note the changes so an UpdateProperties event will happen. |
915 | PushKnownChanged(); | 949 | PushKnownChanged(); |
916 | 950 | ||
917 | if (PhysicsScene.VehiclePhysicalLoggingEnabled) | 951 | if (m_physicsScene.VehiclePhysicalLoggingEnabled) |
918 | PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody); | 952 | m_physicsScene.PE.DumpRigidBody(m_physicsScene.World, ControllingPrim.PhysBody); |
919 | 953 | ||
920 | VDetailLog("{0},BSDynamics.Step,done,pos={1}, force={2},velocity={3},angvel={4}", | 954 | VDetailLog("{0},BSDynamics.Step,done,pos={1}, force={2},velocity={3},angvel={4}", |
921 | Prim.LocalID, VehiclePosition, m_knownForce, VehicleVelocity, VehicleRotationalVelocity); | 955 | ControllingPrim.LocalID, VehiclePosition, m_knownForce, VehicleVelocity, VehicleRotationalVelocity); |
922 | } | 956 | } |
923 | 957 | ||
924 | // Called after the simulation step | 958 | // Called after the simulation step |
@@ -926,8 +960,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
926 | { | 960 | { |
927 | if (!IsActive) return; | 961 | if (!IsActive) return; |
928 | 962 | ||
929 | if (PhysicsScene.VehiclePhysicalLoggingEnabled) | 963 | if (m_physicsScene.VehiclePhysicalLoggingEnabled) |
930 | PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody); | 964 | m_physicsScene.PE.DumpRigidBody(m_physicsScene.World, ControllingPrim.PhysBody); |
931 | } | 965 | } |
932 | 966 | ||
933 | // Apply the effect of the linear motor and other linear motions (like hover and float). | 967 | // Apply the effect of the linear motor and other linear motions (like hover and float). |
@@ -935,6 +969,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
935 | { | 969 | { |
936 | ComputeLinearVelocity(pTimestep); | 970 | ComputeLinearVelocity(pTimestep); |
937 | 971 | ||
972 | ComputeLinearDeflection(pTimestep); | ||
973 | |||
938 | ComputeLinearTerrainHeightCorrection(pTimestep); | 974 | ComputeLinearTerrainHeightCorrection(pTimestep); |
939 | 975 | ||
940 | ComputeLinearHover(pTimestep); | 976 | ComputeLinearHover(pTimestep); |
@@ -950,11 +986,17 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
950 | { | 986 | { |
951 | Vector3 vel = VehicleVelocity; | 987 | Vector3 vel = VehicleVelocity; |
952 | if ((m_flags & (VehicleFlag.NO_X)) != 0) | 988 | if ((m_flags & (VehicleFlag.NO_X)) != 0) |
989 | { | ||
953 | vel.X = 0; | 990 | vel.X = 0; |
991 | } | ||
954 | if ((m_flags & (VehicleFlag.NO_Y)) != 0) | 992 | if ((m_flags & (VehicleFlag.NO_Y)) != 0) |
993 | { | ||
955 | vel.Y = 0; | 994 | vel.Y = 0; |
995 | } | ||
956 | if ((m_flags & (VehicleFlag.NO_Z)) != 0) | 996 | if ((m_flags & (VehicleFlag.NO_Z)) != 0) |
997 | { | ||
957 | vel.Z = 0; | 998 | vel.Z = 0; |
999 | } | ||
958 | VehicleVelocity = vel; | 1000 | VehicleVelocity = vel; |
959 | } | 1001 | } |
960 | 1002 | ||
@@ -966,13 +1008,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
966 | Vector3 origVelW = VehicleVelocity; // DEBUG DEBUG | 1008 | Vector3 origVelW = VehicleVelocity; // DEBUG DEBUG |
967 | VehicleVelocity /= VehicleVelocity.Length(); | 1009 | VehicleVelocity /= VehicleVelocity.Length(); |
968 | VehicleVelocity *= BSParam.VehicleMaxLinearVelocity; | 1010 | VehicleVelocity *= BSParam.VehicleMaxLinearVelocity; |
969 | VDetailLog("{0}, MoveLinear,clampMax,origVelW={1},lenSq={2},maxVelSq={3},,newVelW={4}", | 1011 | VDetailLog("{0}, MoveLinear,clampMax,origVelW={1},lenSq={2},maxVelSq={3},,newVelW={4}", |
970 | Prim.LocalID, origVelW, newVelocityLengthSq, BSParam.VehicleMaxLinearVelocitySquared, VehicleVelocity); | 1012 | ControllingPrim.LocalID, origVelW, newVelocityLengthSq, BSParam.VehicleMaxLinearVelocitySquared, VehicleVelocity); |
971 | } | 1013 | } |
972 | else if (newVelocityLengthSq < 0.001f) | 1014 | else if (newVelocityLengthSq < 0.001f) |
973 | VehicleVelocity = Vector3.Zero; | 1015 | VehicleVelocity = Vector3.Zero; |
974 | 1016 | ||
975 | VDetailLog("{0}, MoveLinear,done,isColl={1},newVel={2}", Prim.LocalID, Prim.IsColliding, VehicleVelocity ); | 1017 | VDetailLog("{0}, MoveLinear,done,isColl={1},newVel={2}", ControllingPrim.LocalID, ControllingPrim.HasSomeCollision, VehicleVelocity ); |
976 | 1018 | ||
977 | } // end MoveLinear() | 1019 | } // end MoveLinear() |
978 | 1020 | ||
@@ -980,9 +1022,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
980 | { | 1022 | { |
981 | // Step the motor from the current value. Get the correction needed this step. | 1023 | // Step the motor from the current value. Get the correction needed this step. |
982 | Vector3 origVelW = VehicleVelocity; // DEBUG | 1024 | Vector3 origVelW = VehicleVelocity; // DEBUG |
983 | Vector3 currentVelV = VehicleVelocity * Quaternion.Inverse(VehicleOrientation); | 1025 | Vector3 currentVelV = VehicleForwardVelocity; |
984 | Vector3 linearMotorCorrectionV = m_linearMotor.Step(pTimestep, currentVelV); | 1026 | Vector3 linearMotorCorrectionV = m_linearMotor.Step(pTimestep, currentVelV); |
985 | 1027 | ||
1028 | // Friction reduces vehicle motion based on absolute speed. Slow vehicle down by friction. | ||
1029 | Vector3 frictionFactorV = ComputeFrictionFactor(m_linearFrictionTimescale, pTimestep); | ||
1030 | linearMotorCorrectionV -= (currentVelV * frictionFactorV); | ||
1031 | |||
986 | // Motor is vehicle coordinates. Rotate it to world coordinates | 1032 | // Motor is vehicle coordinates. Rotate it to world coordinates |
987 | Vector3 linearMotorVelocityW = linearMotorCorrectionV * VehicleOrientation; | 1033 | Vector3 linearMotorVelocityW = linearMotorCorrectionV * VehicleOrientation; |
988 | 1034 | ||
@@ -996,8 +1042,49 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
996 | // Add this correction to the velocity to make it faster/slower. | 1042 | // Add this correction to the velocity to make it faster/slower. |
997 | VehicleVelocity += linearMotorVelocityW; | 1043 | VehicleVelocity += linearMotorVelocityW; |
998 | 1044 | ||
999 | VDetailLog("{0}, MoveLinear,velocity,origVelW={1},velV={2},correctV={3},correctW={4},newVelW={5}", | 1045 | VDetailLog("{0}, MoveLinear,velocity,origVelW={1},velV={2},tgt={3},correctV={4},correctW={5},newVelW={6},fricFact={7}", |
1000 | Prim.LocalID, origVelW, currentVelV, linearMotorCorrectionV, linearMotorVelocityW, VehicleVelocity); | 1046 | ControllingPrim.LocalID, origVelW, currentVelV, m_linearMotor.TargetValue, linearMotorCorrectionV, |
1047 | linearMotorVelocityW, VehicleVelocity, frictionFactorV); | ||
1048 | } | ||
1049 | |||
1050 | //Given a Deflection Effiency and a Velocity, Returns a Velocity that is Partially Deflected onto the X Axis | ||
1051 | //Clamped so that a DeflectionTimescale of less then 1 does not increase force over original velocity | ||
1052 | private void ComputeLinearDeflection(float pTimestep) | ||
1053 | { | ||
1054 | Vector3 linearDeflectionV = Vector3.Zero; | ||
1055 | Vector3 velocityV = VehicleForwardVelocity; | ||
1056 | |||
1057 | if (BSParam.VehicleEnableLinearDeflection) | ||
1058 | { | ||
1059 | // Velocity in Y and Z dimensions is movement to the side or turning. | ||
1060 | // Compute deflection factor from the to the side and rotational velocity | ||
1061 | linearDeflectionV.Y = SortedClampInRange(0, (velocityV.Y * m_linearDeflectionEfficiency) / m_linearDeflectionTimescale, velocityV.Y); | ||
1062 | linearDeflectionV.Z = SortedClampInRange(0, (velocityV.Z * m_linearDeflectionEfficiency) / m_linearDeflectionTimescale, velocityV.Z); | ||
1063 | |||
1064 | // Velocity to the side and around is corrected and moved into the forward direction | ||
1065 | linearDeflectionV.X += Math.Abs(linearDeflectionV.Y); | ||
1066 | linearDeflectionV.X += Math.Abs(linearDeflectionV.Z); | ||
1067 | |||
1068 | // Scale the deflection to the fractional simulation time | ||
1069 | linearDeflectionV *= pTimestep; | ||
1070 | |||
1071 | // Subtract the sideways and rotational velocity deflection factors while adding the correction forward | ||
1072 | linearDeflectionV *= new Vector3(1, -1, -1); | ||
1073 | |||
1074 | // Correction is vehicle relative. Convert to world coordinates. | ||
1075 | Vector3 linearDeflectionW = linearDeflectionV * VehicleOrientation; | ||
1076 | |||
1077 | // Optionally, if not colliding, don't effect world downward velocity. Let falling things fall. | ||
1078 | if (BSParam.VehicleLinearDeflectionNotCollidingNoZ && !m_controllingPrim.HasSomeCollision) | ||
1079 | { | ||
1080 | linearDeflectionW.Z = 0f; | ||
1081 | } | ||
1082 | |||
1083 | VehicleVelocity += linearDeflectionW; | ||
1084 | |||
1085 | VDetailLog("{0}, MoveLinear,LinearDeflection,linDefEff={1},linDefTS={2},linDeflectionV={3}", | ||
1086 | ControllingPrim.LocalID, m_linearDeflectionEfficiency, m_linearDeflectionTimescale, linearDeflectionV); | ||
1087 | } | ||
1001 | } | 1088 | } |
1002 | 1089 | ||
1003 | public void ComputeLinearTerrainHeightCorrection(float pTimestep) | 1090 | public void ComputeLinearTerrainHeightCorrection(float pTimestep) |
@@ -1011,7 +1098,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1011 | newPosition.Z = GetTerrainHeight(VehiclePosition) + 1f; | 1098 | newPosition.Z = GetTerrainHeight(VehiclePosition) + 1f; |
1012 | VehiclePosition = newPosition; | 1099 | VehiclePosition = newPosition; |
1013 | VDetailLog("{0}, MoveLinear,terrainHeight,terrainHeight={1},pos={2}", | 1100 | VDetailLog("{0}, MoveLinear,terrainHeight,terrainHeight={1},pos={2}", |
1014 | Prim.LocalID, GetTerrainHeight(VehiclePosition), VehiclePosition); | 1101 | ControllingPrim.LocalID, GetTerrainHeight(VehiclePosition), VehiclePosition); |
1015 | } | 1102 | } |
1016 | } | 1103 | } |
1017 | 1104 | ||
@@ -1034,14 +1121,25 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1034 | { | 1121 | { |
1035 | m_VhoverTargetHeight = m_VhoverHeight; | 1122 | m_VhoverTargetHeight = m_VhoverHeight; |
1036 | } | 1123 | } |
1037 | |||
1038 | if ((m_flags & VehicleFlag.HOVER_UP_ONLY) != 0) | 1124 | if ((m_flags & VehicleFlag.HOVER_UP_ONLY) != 0) |
1039 | { | 1125 | { |
1040 | // If body is already heigher, use its height as target height | 1126 | // If body is already heigher, use its height as target height |
1041 | if (VehiclePosition.Z > m_VhoverTargetHeight) | 1127 | if (VehiclePosition.Z > m_VhoverTargetHeight) |
1128 | { | ||
1042 | m_VhoverTargetHeight = VehiclePosition.Z; | 1129 | m_VhoverTargetHeight = VehiclePosition.Z; |
1130 | |||
1131 | // A 'misfeature' of this flag is that if the vehicle is above it's hover height, | ||
1132 | // the vehicle's buoyancy goes away. This is an SL bug that got used by so many | ||
1133 | // scripts that it could not be changed. | ||
1134 | // So, if above the height, reapply gravity if buoyancy had it turned off. | ||
1135 | if (m_VehicleBuoyancy != 0) | ||
1136 | { | ||
1137 | Vector3 appliedGravity = ControllingPrim.ComputeGravity(ControllingPrim.Buoyancy) * m_vehicleMass; | ||
1138 | VehicleAddForce(appliedGravity); | ||
1139 | } | ||
1140 | } | ||
1043 | } | 1141 | } |
1044 | 1142 | ||
1045 | if ((m_flags & VehicleFlag.LOCK_HOVER_HEIGHT) != 0) | 1143 | if ((m_flags & VehicleFlag.LOCK_HOVER_HEIGHT) != 0) |
1046 | { | 1144 | { |
1047 | if (Math.Abs(VehiclePosition.Z - m_VhoverTargetHeight) > 0.2f) | 1145 | if (Math.Abs(VehiclePosition.Z - m_VhoverTargetHeight) > 0.2f) |
@@ -1050,7 +1148,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1050 | pos.Z = m_VhoverTargetHeight; | 1148 | pos.Z = m_VhoverTargetHeight; |
1051 | VehiclePosition = pos; | 1149 | VehiclePosition = pos; |
1052 | 1150 | ||
1053 | VDetailLog("{0}, MoveLinear,hover,pos={1},lockHoverHeight", Prim.LocalID, pos); | 1151 | VDetailLog("{0}, MoveLinear,hover,pos={1},lockHoverHeight", ControllingPrim.LocalID, pos); |
1054 | } | 1152 | } |
1055 | } | 1153 | } |
1056 | else | 1154 | else |
@@ -1079,11 +1177,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1079 | */ | 1177 | */ |
1080 | 1178 | ||
1081 | VDetailLog("{0}, MoveLinear,hover,pos={1},eff={2},hoverTS={3},height={4},target={5},err={6},corr={7}", | 1179 | VDetailLog("{0}, MoveLinear,hover,pos={1},eff={2},hoverTS={3},height={4},target={5},err={6},corr={7}", |
1082 | Prim.LocalID, VehiclePosition, m_VhoverEfficiency, | 1180 | ControllingPrim.LocalID, VehiclePosition, m_VhoverEfficiency, |
1083 | m_VhoverTimescale, m_VhoverHeight, m_VhoverTargetHeight, | 1181 | m_VhoverTimescale, m_VhoverHeight, m_VhoverTargetHeight, |
1084 | verticalError, verticalCorrection); | 1182 | verticalError, verticalCorrection); |
1085 | } | 1183 | } |
1086 | |||
1087 | } | 1184 | } |
1088 | } | 1185 | } |
1089 | 1186 | ||
@@ -1124,7 +1221,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1124 | { | 1221 | { |
1125 | VehiclePosition = pos; | 1222 | VehiclePosition = pos; |
1126 | VDetailLog("{0}, MoveLinear,blockingEndPoint,block={1},origPos={2},pos={3}", | 1223 | VDetailLog("{0}, MoveLinear,blockingEndPoint,block={1},origPos={2},pos={3}", |
1127 | Prim.LocalID, m_BlockingEndPoint, posChange, pos); | 1224 | ControllingPrim.LocalID, m_BlockingEndPoint, posChange, pos); |
1128 | } | 1225 | } |
1129 | } | 1226 | } |
1130 | return changed; | 1227 | return changed; |
@@ -1135,7 +1232,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1135 | // used with conjunction with banking: the strength of the banking will decay when the | 1232 | // used with conjunction with banking: the strength of the banking will decay when the |
1136 | // vehicle no longer experiences collisions. The decay timescale is the same as | 1233 | // vehicle no longer experiences collisions. The decay timescale is the same as |
1137 | // VEHICLE_BANKING_TIMESCALE. This is to help prevent ground vehicles from steering | 1234 | // VEHICLE_BANKING_TIMESCALE. This is to help prevent ground vehicles from steering |
1138 | // when they are in mid jump. | 1235 | // when they are in mid jump. |
1139 | // TODO: this code is wrong. Also, what should it do for boats (height from water)? | 1236 | // TODO: this code is wrong. Also, what should it do for boats (height from water)? |
1140 | // This is just using the ground and a general collision check. Should really be using | 1237 | // This is just using the ground and a general collision check. Should really be using |
1141 | // a downward raycast to find what is below. | 1238 | // a downward raycast to find what is below. |
@@ -1148,7 +1245,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1148 | float targetHeight = Type == Vehicle.TYPE_BOAT ? GetWaterLevel(VehiclePosition) : GetTerrainHeight(VehiclePosition); | 1245 | float targetHeight = Type == Vehicle.TYPE_BOAT ? GetWaterLevel(VehiclePosition) : GetTerrainHeight(VehiclePosition); |
1149 | distanceAboveGround = VehiclePosition.Z - targetHeight; | 1246 | distanceAboveGround = VehiclePosition.Z - targetHeight; |
1150 | // Not colliding if the vehicle is off the ground | 1247 | // Not colliding if the vehicle is off the ground |
1151 | if (!Prim.IsColliding) | 1248 | if (!Prim.HasSomeCollision) |
1152 | { | 1249 | { |
1153 | // downForce = new Vector3(0, 0, -distanceAboveGround / m_bankingTimescale); | 1250 | // downForce = new Vector3(0, 0, -distanceAboveGround / m_bankingTimescale); |
1154 | VehicleVelocity += new Vector3(0, 0, -distanceAboveGround); | 1251 | VehicleVelocity += new Vector3(0, 0, -distanceAboveGround); |
@@ -1159,12 +1256,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1159 | // be computed with a motor. | 1256 | // be computed with a motor. |
1160 | // TODO: add interaction with banking. | 1257 | // TODO: add interaction with banking. |
1161 | VDetailLog("{0}, MoveLinear,limitMotorUp,distAbove={1},colliding={2},ret={3}", | 1258 | VDetailLog("{0}, MoveLinear,limitMotorUp,distAbove={1},colliding={2},ret={3}", |
1162 | Prim.LocalID, distanceAboveGround, Prim.IsColliding, ret); | 1259 | Prim.LocalID, distanceAboveGround, Prim.HasSomeCollision, ret); |
1163 | */ | 1260 | */ |
1164 | 1261 | ||
1165 | // Another approach is to measure if we're going up. If going up and not colliding, | 1262 | // Another approach is to measure if we're going up. If going up and not colliding, |
1166 | // the vehicle is in the air. Fix that by pushing down. | 1263 | // the vehicle is in the air. Fix that by pushing down. |
1167 | if (!Prim.IsColliding && VehicleVelocity.Z > 0.1) | 1264 | if (!ControllingPrim.HasSomeCollision && VehicleVelocity.Z > 0.1) |
1168 | { | 1265 | { |
1169 | // Get rid of any of the velocity vector that is pushing us up. | 1266 | // Get rid of any of the velocity vector that is pushing us up. |
1170 | float upVelocity = VehicleVelocity.Z; | 1267 | float upVelocity = VehicleVelocity.Z; |
@@ -1186,7 +1283,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1186 | } | 1283 | } |
1187 | */ | 1284 | */ |
1188 | VDetailLog("{0}, MoveLinear,limitMotorUp,collide={1},upVel={2},newVel={3}", | 1285 | VDetailLog("{0}, MoveLinear,limitMotorUp,collide={1},upVel={2},newVel={3}", |
1189 | Prim.LocalID, Prim.IsColliding, upVelocity, VehicleVelocity); | 1286 | ControllingPrim.LocalID, ControllingPrim.HasSomeCollision, upVelocity, VehicleVelocity); |
1190 | } | 1287 | } |
1191 | } | 1288 | } |
1192 | } | 1289 | } |
@@ -1196,14 +1293,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1196 | Vector3 appliedGravity = m_VehicleGravity * m_vehicleMass; | 1293 | Vector3 appliedGravity = m_VehicleGravity * m_vehicleMass; |
1197 | 1294 | ||
1198 | // Hack to reduce downward force if the vehicle is probably sitting on the ground | 1295 | // Hack to reduce downward force if the vehicle is probably sitting on the ground |
1199 | if (Prim.IsColliding && IsGroundVehicle) | 1296 | if (ControllingPrim.HasSomeCollision && IsGroundVehicle) |
1200 | appliedGravity *= BSParam.VehicleGroundGravityFudge; | 1297 | appliedGravity *= BSParam.VehicleGroundGravityFudge; |
1201 | 1298 | ||
1202 | VehicleAddForce(appliedGravity); | 1299 | VehicleAddForce(appliedGravity); |
1203 | 1300 | ||
1204 | VDetailLog("{0}, MoveLinear,applyGravity,vehGrav={1},collid={2},fudge={3},mass={4},appliedForce={3}", | 1301 | VDetailLog("{0}, MoveLinear,applyGravity,vehGrav={1},collid={2},fudge={3},mass={4},appliedForce={5}", |
1205 | Prim.LocalID, m_VehicleGravity, | 1302 | ControllingPrim.LocalID, m_VehicleGravity, |
1206 | Prim.IsColliding, BSParam.VehicleGroundGravityFudge, m_vehicleMass, appliedGravity); | 1303 | ControllingPrim.HasSomeCollision, BSParam.VehicleGroundGravityFudge, m_vehicleMass, appliedGravity); |
1207 | } | 1304 | } |
1208 | 1305 | ||
1209 | // ======================================================================= | 1306 | // ======================================================================= |
@@ -1227,11 +1324,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1227 | { | 1324 | { |
1228 | // The vehicle is not adding anything angular wise. | 1325 | // The vehicle is not adding anything angular wise. |
1229 | VehicleRotationalVelocity = Vector3.Zero; | 1326 | VehicleRotationalVelocity = Vector3.Zero; |
1230 | VDetailLog("{0}, MoveAngular,done,zero", Prim.LocalID); | 1327 | VDetailLog("{0}, MoveAngular,done,zero", ControllingPrim.LocalID); |
1231 | } | 1328 | } |
1232 | else | 1329 | else |
1233 | { | 1330 | { |
1234 | VDetailLog("{0}, MoveAngular,done,nonZero,angVel={1}", Prim.LocalID, VehicleRotationalVelocity); | 1331 | VDetailLog("{0}, MoveAngular,done,nonZero,angVel={1}", ControllingPrim.LocalID, VehicleRotationalVelocity); |
1235 | } | 1332 | } |
1236 | 1333 | ||
1237 | // ================================================================== | 1334 | // ================================================================== |
@@ -1262,7 +1359,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1262 | torqueFromOffset.Z = 0; | 1359 | torqueFromOffset.Z = 0; |
1263 | 1360 | ||
1264 | VehicleAddAngularForce(torqueFromOffset * m_vehicleMass); | 1361 | VehicleAddAngularForce(torqueFromOffset * m_vehicleMass); |
1265 | VDetailLog("{0}, BSDynamic.MoveAngular,motorOffset,applyTorqueImpulse={1}", Prim.LocalID, torqueFromOffset); | 1362 | VDetailLog("{0}, BSDynamic.MoveAngular,motorOffset,applyTorqueImpulse={1}", ControllingPrim.LocalID, torqueFromOffset); |
1266 | } | 1363 | } |
1267 | 1364 | ||
1268 | } | 1365 | } |
@@ -1270,6 +1367,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1270 | private void ComputeAngularTurning(float pTimestep) | 1367 | private void ComputeAngularTurning(float pTimestep) |
1271 | { | 1368 | { |
1272 | // The user wants this many radians per second angular change? | 1369 | // The user wants this many radians per second angular change? |
1370 | Vector3 origVehicleRotationalVelocity = VehicleRotationalVelocity; // DEBUG DEBUG | ||
1273 | Vector3 currentAngularV = VehicleRotationalVelocity * Quaternion.Inverse(VehicleOrientation); | 1371 | Vector3 currentAngularV = VehicleRotationalVelocity * Quaternion.Inverse(VehicleOrientation); |
1274 | Vector3 angularMotorContributionV = m_angularMotor.Step(pTimestep, currentAngularV); | 1372 | Vector3 angularMotorContributionV = m_angularMotor.Step(pTimestep, currentAngularV); |
1275 | 1373 | ||
@@ -1277,18 +1375,25 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1277 | // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags : | 1375 | // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags : |
1278 | // This flag prevents linear deflection parallel to world z-axis. This is useful | 1376 | // This flag prevents linear deflection parallel to world z-axis. This is useful |
1279 | // for preventing ground vehicles with large linear deflection, like bumper cars, | 1377 | // for preventing ground vehicles with large linear deflection, like bumper cars, |
1280 | // from climbing their linear deflection into the sky. | 1378 | // from climbing their linear deflection into the sky. |
1281 | // That is, NO_DEFLECTION_UP says angular motion should not add any pitch or roll movement | 1379 | // That is, NO_DEFLECTION_UP says angular motion should not add any pitch or roll movement |
1282 | // TODO: This is here because this is where ODE put it but documentation says it | 1380 | // TODO: This is here because this is where ODE put it but documentation says it |
1283 | // is a linear effect. Where should this check go? | 1381 | // is a linear effect. Where should this check go? |
1284 | //if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0) | 1382 | //if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0) |
1285 | // { | 1383 | // { |
1286 | // angularMotorContributionV.X = 0f; | 1384 | // angularMotorContributionV.X = 0f; |
1287 | // angularMotorContributionV.Y = 0f; | 1385 | // angularMotorContributionV.Y = 0f; |
1288 | // } | 1386 | // } |
1387 | |||
1388 | // Reduce any velocity by friction. | ||
1389 | Vector3 frictionFactorW = ComputeFrictionFactor(m_angularFrictionTimescale, pTimestep); | ||
1390 | angularMotorContributionV -= (currentAngularV * frictionFactorW); | ||
1391 | |||
1392 | Vector3 angularMotorContributionW = angularMotorContributionV * VehicleOrientation; | ||
1393 | VehicleRotationalVelocity += angularMotorContributionW; | ||
1289 | 1394 | ||
1290 | VehicleRotationalVelocity += angularMotorContributionV * VehicleOrientation; | 1395 | VDetailLog("{0}, MoveAngular,angularTurning,curAngVelV={1},origVehRotVel={2},vehRotVel={3},frictFact={4}, angContribV={5},angContribW={6}", |
1291 | VDetailLog("{0}, MoveAngular,angularTurning,angularMotorContrib={1}", Prim.LocalID, angularMotorContributionV); | 1396 | ControllingPrim.LocalID, currentAngularV, origVehicleRotationalVelocity, VehicleRotationalVelocity, frictionFactorW, angularMotorContributionV, angularMotorContributionW); |
1292 | } | 1397 | } |
1293 | 1398 | ||
1294 | // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial: | 1399 | // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial: |
@@ -1303,86 +1408,136 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1303 | { | 1408 | { |
1304 | 1409 | ||
1305 | // If vertical attaction timescale is reasonable | 1410 | // If vertical attaction timescale is reasonable |
1306 | if (enableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) | 1411 | if (BSParam.VehicleEnableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) |
1307 | { | 1412 | { |
1308 | // Possible solution derived from a discussion at: | 1413 | Vector3 vehicleUpAxis = Vector3.UnitZ * VehicleOrientation; |
1309 | // http://stackoverflow.com/questions/14939657/computing-vector-from-quaternion-works-computing-quaternion-from-vector-does-no | 1414 | switch (BSParam.VehicleAngularVerticalAttractionAlgorithm) |
1310 | |||
1311 | // Create a rotation that is only the vehicle's rotation around Z | ||
1312 | Vector3 currentEuler = Vector3.Zero; | ||
1313 | VehicleOrientation.GetEulerAngles(out currentEuler.X, out currentEuler.Y, out currentEuler.Z); | ||
1314 | Quaternion justZOrientation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, currentEuler.Z); | ||
1315 | |||
1316 | // Create the axis that is perpendicular to the up vector and the rotated up vector. | ||
1317 | Vector3 differenceAxis = Vector3.Cross(Vector3.UnitZ * justZOrientation, Vector3.UnitZ * VehicleOrientation); | ||
1318 | // Compute the angle between those to vectors. | ||
1319 | double differenceAngle = Math.Acos((double)Vector3.Dot(Vector3.UnitZ, Vector3.Normalize(Vector3.UnitZ * VehicleOrientation))); | ||
1320 | // 'differenceAngle' is the angle to rotate and 'differenceAxis' is the plane to rotate in to get the vehicle vertical | ||
1321 | |||
1322 | // Reduce the change by the time period it is to change in. Timestep is handled when velocity is applied. | ||
1323 | // TODO: add 'efficiency'. | ||
1324 | differenceAngle /= m_verticalAttractionTimescale; | ||
1325 | |||
1326 | // Create the quaterian representing the correction angle | ||
1327 | Quaternion correctionRotation = Quaternion.CreateFromAxisAngle(differenceAxis, (float)differenceAngle); | ||
1328 | |||
1329 | // Turn that quaternion into Euler values to make it into velocities to apply. | ||
1330 | Vector3 vertContributionV = Vector3.Zero; | ||
1331 | correctionRotation.GetEulerAngles(out vertContributionV.X, out vertContributionV.Y, out vertContributionV.Z); | ||
1332 | vertContributionV *= -1f; | ||
1333 | |||
1334 | VehicleRotationalVelocity += vertContributionV; | ||
1335 | |||
1336 | VDetailLog("{0}, MoveAngular,verticalAttraction,diffAxis={1},diffAng={2},corrRot={3},contrib={4}", | ||
1337 | Prim.LocalID, | ||
1338 | differenceAxis, | ||
1339 | differenceAngle, | ||
1340 | correctionRotation, | ||
1341 | vertContributionV); | ||
1342 | |||
1343 | // =================================================================== | ||
1344 | /* | ||
1345 | Vector3 vertContributionV = Vector3.Zero; | ||
1346 | Vector3 origRotVelW = VehicleRotationalVelocity; // DEBUG DEBUG | ||
1347 | |||
1348 | // Take a vector pointing up and convert it from world to vehicle relative coords. | ||
1349 | Vector3 verticalError = Vector3.Normalize(Vector3.UnitZ * VehicleOrientation); | ||
1350 | |||
1351 | // If vertical attraction correction is needed, the vector that was pointing up (UnitZ) | ||
1352 | // is now: | ||
1353 | // leaning to one side: rotated around the X axis with the Y value going | ||
1354 | // from zero (nearly straight up) to one (completely to the side)) or | ||
1355 | // leaning front-to-back: rotated around the Y axis with the value of X being between | ||
1356 | // zero and one. | ||
1357 | // The value of Z is how far the rotation is off with 1 meaning none and 0 being 90 degrees. | ||
1358 | |||
1359 | // Y error means needed rotation around X axis and visa versa. | ||
1360 | // Since the error goes from zero to one, the asin is the corresponding angle. | ||
1361 | vertContributionV.X = (float)Math.Asin(verticalError.Y); | ||
1362 | // (Tilt forward (positive X) needs to tilt back (rotate negative) around Y axis.) | ||
1363 | vertContributionV.Y = -(float)Math.Asin(verticalError.X); | ||
1364 | |||
1365 | // If verticalError.Z is negative, the vehicle is upside down. Add additional push. | ||
1366 | if (verticalError.Z < 0f) | ||
1367 | { | 1415 | { |
1368 | vertContributionV.X += Math.Sign(vertContributionV.X) * PIOverFour; | 1416 | case 0: |
1369 | // vertContribution.Y -= PIOverFour; | 1417 | { |
1418 | //Another formula to try got from : | ||
1419 | //http://answers.unity3d.com/questions/10425/how-to-stabilize-angular-motion-alignment-of-hover.html | ||
1420 | |||
1421 | // Flipping what was originally a timescale into a speed variable and then multiplying it by 2 | ||
1422 | // since only computing half the distance between the angles. | ||
1423 | float verticalAttractionSpeed = (1 / m_verticalAttractionTimescale) * 2.0f; | ||
1424 | |||
1425 | // Make a prediction of where the up axis will be when this is applied rather then where it is now as | ||
1426 | // this makes for a smoother adjustment and less fighting between the various forces. | ||
1427 | Vector3 predictedUp = vehicleUpAxis * Quaternion.CreateFromAxisAngle(VehicleRotationalVelocity, 0f); | ||
1428 | |||
1429 | // This is only half the distance to the target so it will take 2 seconds to complete the turn. | ||
1430 | Vector3 torqueVector = Vector3.Cross(predictedUp, Vector3.UnitZ); | ||
1431 | |||
1432 | // Scale vector by our timescale since it is an acceleration it is r/s^2 or radians a timescale squared | ||
1433 | Vector3 vertContributionV = torqueVector * verticalAttractionSpeed * verticalAttractionSpeed; | ||
1434 | |||
1435 | VehicleRotationalVelocity += vertContributionV; | ||
1436 | |||
1437 | VDetailLog("{0}, MoveAngular,verticalAttraction,vertAttrSpeed={1},upAxis={2},PredictedUp={3},torqueVector={4},contrib={5}", | ||
1438 | ControllingPrim.LocalID, | ||
1439 | verticalAttractionSpeed, | ||
1440 | vehicleUpAxis, | ||
1441 | predictedUp, | ||
1442 | torqueVector, | ||
1443 | vertContributionV); | ||
1444 | break; | ||
1445 | } | ||
1446 | case 1: | ||
1447 | { | ||
1448 | // Possible solution derived from a discussion at: | ||
1449 | // http://stackoverflow.com/questions/14939657/computing-vector-from-quaternion-works-computing-quaternion-from-vector-does-no | ||
1450 | |||
1451 | // Create a rotation that is only the vehicle's rotation around Z | ||
1452 | Vector3 currentEulerW = Vector3.Zero; | ||
1453 | VehicleOrientation.GetEulerAngles(out currentEulerW.X, out currentEulerW.Y, out currentEulerW.Z); | ||
1454 | Quaternion justZOrientation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, currentEulerW.Z); | ||
1455 | |||
1456 | // Create the axis that is perpendicular to the up vector and the rotated up vector. | ||
1457 | Vector3 differenceAxisW = Vector3.Cross(Vector3.UnitZ * justZOrientation, Vector3.UnitZ * VehicleOrientation); | ||
1458 | // Compute the angle between those to vectors. | ||
1459 | double differenceAngle = Math.Acos((double)Vector3.Dot(Vector3.UnitZ, Vector3.Normalize(Vector3.UnitZ * VehicleOrientation))); | ||
1460 | // 'differenceAngle' is the angle to rotate and 'differenceAxis' is the plane to rotate in to get the vehicle vertical | ||
1461 | |||
1462 | // Reduce the change by the time period it is to change in. Timestep is handled when velocity is applied. | ||
1463 | // TODO: add 'efficiency'. | ||
1464 | // differenceAngle /= m_verticalAttractionTimescale; | ||
1465 | |||
1466 | // Create the quaterian representing the correction angle | ||
1467 | Quaternion correctionRotationW = Quaternion.CreateFromAxisAngle(differenceAxisW, (float)differenceAngle); | ||
1468 | |||
1469 | // Turn that quaternion into Euler values to make it into velocities to apply. | ||
1470 | Vector3 vertContributionW = Vector3.Zero; | ||
1471 | correctionRotationW.GetEulerAngles(out vertContributionW.X, out vertContributionW.Y, out vertContributionW.Z); | ||
1472 | vertContributionW *= -1f; | ||
1473 | vertContributionW /= m_verticalAttractionTimescale; | ||
1474 | |||
1475 | VehicleRotationalVelocity += vertContributionW; | ||
1476 | |||
1477 | VDetailLog("{0}, MoveAngular,verticalAttraction,upAxis={1},diffAxis={2},diffAng={3},corrRot={4},contrib={5}", | ||
1478 | ControllingPrim.LocalID, | ||
1479 | vehicleUpAxis, | ||
1480 | differenceAxisW, | ||
1481 | differenceAngle, | ||
1482 | correctionRotationW, | ||
1483 | vertContributionW); | ||
1484 | break; | ||
1485 | } | ||
1486 | case 2: | ||
1487 | { | ||
1488 | Vector3 vertContributionV = Vector3.Zero; | ||
1489 | Vector3 origRotVelW = VehicleRotationalVelocity; // DEBUG DEBUG | ||
1490 | |||
1491 | // Take a vector pointing up and convert it from world to vehicle relative coords. | ||
1492 | Vector3 verticalError = Vector3.Normalize(Vector3.UnitZ * VehicleOrientation); | ||
1493 | |||
1494 | // If vertical attraction correction is needed, the vector that was pointing up (UnitZ) | ||
1495 | // is now: | ||
1496 | // leaning to one side: rotated around the X axis with the Y value going | ||
1497 | // from zero (nearly straight up) to one (completely to the side)) or | ||
1498 | // leaning front-to-back: rotated around the Y axis with the value of X being between | ||
1499 | // zero and one. | ||
1500 | // The value of Z is how far the rotation is off with 1 meaning none and 0 being 90 degrees. | ||
1501 | |||
1502 | // Y error means needed rotation around X axis and visa versa. | ||
1503 | // Since the error goes from zero to one, the asin is the corresponding angle. | ||
1504 | vertContributionV.X = (float)Math.Asin(verticalError.Y); | ||
1505 | // (Tilt forward (positive X) needs to tilt back (rotate negative) around Y axis.) | ||
1506 | vertContributionV.Y = -(float)Math.Asin(verticalError.X); | ||
1507 | |||
1508 | // If verticalError.Z is negative, the vehicle is upside down. Add additional push. | ||
1509 | if (verticalError.Z < 0f) | ||
1510 | { | ||
1511 | vertContributionV.X += Math.Sign(vertContributionV.X) * PIOverFour; | ||
1512 | // vertContribution.Y -= PIOverFour; | ||
1513 | } | ||
1514 | |||
1515 | // 'vertContrbution' is now the necessary angular correction to correct tilt in one second. | ||
1516 | // Correction happens over a number of seconds. | ||
1517 | Vector3 unscaledContribVerticalErrorV = vertContributionV; // DEBUG DEBUG | ||
1518 | |||
1519 | // The correction happens over the user's time period | ||
1520 | vertContributionV /= m_verticalAttractionTimescale; | ||
1521 | |||
1522 | // Rotate the vehicle rotation to the world coordinates. | ||
1523 | VehicleRotationalVelocity += (vertContributionV * VehicleOrientation); | ||
1524 | |||
1525 | VDetailLog("{0}, MoveAngular,verticalAttraction,,upAxis={1},origRotVW={2},vertError={3},unscaledV={4},eff={5},ts={6},vertContribV={7}", | ||
1526 | ControllingPrim.LocalID, | ||
1527 | vehicleUpAxis, | ||
1528 | origRotVelW, | ||
1529 | verticalError, | ||
1530 | unscaledContribVerticalErrorV, | ||
1531 | m_verticalAttractionEfficiency, | ||
1532 | m_verticalAttractionTimescale, | ||
1533 | vertContributionV); | ||
1534 | break; | ||
1535 | } | ||
1536 | default: | ||
1537 | { | ||
1538 | break; | ||
1539 | } | ||
1370 | } | 1540 | } |
1371 | |||
1372 | // 'vertContrbution' is now the necessary angular correction to correct tilt in one second. | ||
1373 | // Correction happens over a number of seconds. | ||
1374 | Vector3 unscaledContribVerticalErrorV = vertContributionV; // DEBUG DEBUG | ||
1375 | |||
1376 | // The correction happens over the user's time period | ||
1377 | vertContributionV /= m_verticalAttractionTimescale; | ||
1378 | |||
1379 | // Rotate the vehicle rotation to the world coordinates. | ||
1380 | VehicleRotationalVelocity += (vertContributionV * VehicleOrientation); | ||
1381 | |||
1382 | VDetailLog("{0}, MoveAngular,verticalAttraction,,origRotVW={1},vertError={2},unscaledV={3},eff={4},ts={5},vertContribV={6}", | ||
1383 | Prim.LocalID, origRotVelW, verticalError, unscaledContribVerticalErrorV, | ||
1384 | m_verticalAttractionEfficiency, m_verticalAttractionTimescale, vertContributionV); | ||
1385 | */ | ||
1386 | } | 1541 | } |
1387 | } | 1542 | } |
1388 | 1543 | ||
@@ -1392,13 +1547,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1392 | // in that direction. | 1547 | // in that direction. |
1393 | // TODO: implement reference frame. | 1548 | // TODO: implement reference frame. |
1394 | public void ComputeAngularDeflection() | 1549 | public void ComputeAngularDeflection() |
1395 | { | 1550 | { |
1396 | // Since angularMotorUp and angularDeflection are computed independently, they will calculate | ||
1397 | // approximately the same X or Y correction. When added together (when contributions are combined) | ||
1398 | // this creates an over-correction and then wabbling as the target is overshot. | ||
1399 | // TODO: rethink how the different correction computations inter-relate. | ||
1400 | 1551 | ||
1401 | if (enableAngularDeflection && m_angularDeflectionEfficiency != 0 && VehicleForwardSpeed > 0.2) | 1552 | if (BSParam.VehicleEnableAngularDeflection && m_angularDeflectionEfficiency != 0 && VehicleForwardSpeed > 0.2) |
1402 | { | 1553 | { |
1403 | Vector3 deflectContributionV = Vector3.Zero; | 1554 | Vector3 deflectContributionV = Vector3.Zero; |
1404 | 1555 | ||
@@ -1411,10 +1562,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1411 | 1562 | ||
1412 | // The direction the vehicle is pointing | 1563 | // The direction the vehicle is pointing |
1413 | Vector3 pointingDirection = Vector3.UnitX * VehicleOrientation; | 1564 | Vector3 pointingDirection = Vector3.UnitX * VehicleOrientation; |
1414 | pointingDirection.Normalize(); | 1565 | //Predict where the Vehicle will be pointing after AngularVelocity change is applied. This will keep |
1566 | // from overshooting and allow this correction to merge with the Vertical Attraction peacefully. | ||
1567 | Vector3 predictedPointingDirection = pointingDirection * Quaternion.CreateFromAxisAngle(VehicleRotationalVelocity, 0f); | ||
1568 | predictedPointingDirection.Normalize(); | ||
1415 | 1569 | ||
1416 | // The difference between what is and what should be. | 1570 | // The difference between what is and what should be. |
1417 | Vector3 deflectionError = movingDirection - pointingDirection; | 1571 | // Vector3 deflectionError = movingDirection - predictedPointingDirection; |
1572 | Vector3 deflectionError = Vector3.Cross(movingDirection, predictedPointingDirection); | ||
1418 | 1573 | ||
1419 | // Don't try to correct very large errors (not our job) | 1574 | // Don't try to correct very large errors (not our job) |
1420 | // if (Math.Abs(deflectionError.X) > PIOverFour) deflectionError.X = PIOverTwo * Math.Sign(deflectionError.X); | 1575 | // if (Math.Abs(deflectionError.X) > PIOverFour) deflectionError.X = PIOverTwo * Math.Sign(deflectionError.X); |
@@ -1427,15 +1582,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1427 | // ret = m_angularDeflectionCorrectionMotor(1f, deflectionError); | 1582 | // ret = m_angularDeflectionCorrectionMotor(1f, deflectionError); |
1428 | 1583 | ||
1429 | // Scale the correction by recovery timescale and efficiency | 1584 | // Scale the correction by recovery timescale and efficiency |
1430 | deflectContributionV = (-deflectionError) * m_angularDeflectionEfficiency; | 1585 | // Not modeling a spring so clamp the scale to no more then the arc |
1431 | deflectContributionV /= m_angularDeflectionTimescale; | 1586 | deflectContributionV = (-deflectionError) * ClampInRange(0, m_angularDeflectionEfficiency/m_angularDeflectionTimescale,1f); |
1432 | 1587 | //deflectContributionV /= m_angularDeflectionTimescale; | |
1433 | VehicleRotationalVelocity += deflectContributionV * VehicleOrientation; | ||
1434 | 1588 | ||
1589 | // VehicleRotationalVelocity += deflectContributionV * VehicleOrientation; | ||
1590 | VehicleRotationalVelocity += deflectContributionV; | ||
1435 | VDetailLog("{0}, MoveAngular,Deflection,movingDir={1},pointingDir={2},deflectError={3},ret={4}", | 1591 | VDetailLog("{0}, MoveAngular,Deflection,movingDir={1},pointingDir={2},deflectError={3},ret={4}", |
1436 | Prim.LocalID, movingDirection, pointingDirection, deflectionError, deflectContributionV); | 1592 | ControllingPrim.LocalID, movingDirection, pointingDirection, deflectionError, deflectContributionV); |
1437 | VDetailLog("{0}, MoveAngular,Deflection,fwdSpd={1},defEff={2},defTS={3}", | 1593 | VDetailLog("{0}, MoveAngular,Deflection,fwdSpd={1},defEff={2},defTS={3},PredictedPointingDir={4}", |
1438 | Prim.LocalID, VehicleForwardSpeed, m_angularDeflectionEfficiency, m_angularDeflectionTimescale); | 1594 | ControllingPrim.LocalID, VehicleForwardSpeed, m_angularDeflectionEfficiency, m_angularDeflectionTimescale, predictedPointingDirection); |
1439 | } | 1595 | } |
1440 | } | 1596 | } |
1441 | 1597 | ||
@@ -1447,13 +1603,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1447 | // produce a angular velocity around the yaw-axis, causing the vehicle to turn. The magnitude | 1603 | // produce a angular velocity around the yaw-axis, causing the vehicle to turn. The magnitude |
1448 | // of the yaw effect will be proportional to the | 1604 | // of the yaw effect will be proportional to the |
1449 | // VEHICLE_BANKING_EFFICIENCY, the angle of the roll rotation, and sometimes the vehicle's | 1605 | // VEHICLE_BANKING_EFFICIENCY, the angle of the roll rotation, and sometimes the vehicle's |
1450 | // velocity along its preferred axis of motion. | 1606 | // velocity along its preferred axis of motion. |
1451 | // The VEHICLE_BANKING_EFFICIENCY can vary between -1 and +1. When it is positive then any | 1607 | // The VEHICLE_BANKING_EFFICIENCY can vary between -1 and +1. When it is positive then any |
1452 | // positive rotation (by the right-hand rule) about the roll-axis will effect a | 1608 | // positive rotation (by the right-hand rule) about the roll-axis will effect a |
1453 | // (negative) torque around the yaw-axis, making it turn to the right--that is the | 1609 | // (negative) torque around the yaw-axis, making it turn to the right--that is the |
1454 | // vehicle will lean into the turn, which is how real airplanes and motorcycle's work. | 1610 | // vehicle will lean into the turn, which is how real airplanes and motorcycle's work. |
1455 | // Negating the banking coefficient will make it so that the vehicle leans to the | 1611 | // Negating the banking coefficient will make it so that the vehicle leans to the |
1456 | // outside of the turn (not very "physical" but might allow interesting vehicles so why not?). | 1612 | // outside of the turn (not very "physical" but might allow interesting vehicles so why not?). |
1457 | // The VEHICLE_BANKING_MIX is a fake (i.e. non-physical) parameter that is useful for making | 1613 | // The VEHICLE_BANKING_MIX is a fake (i.e. non-physical) parameter that is useful for making |
1458 | // banking vehicles do what you want rather than what the laws of physics allow. | 1614 | // banking vehicles do what you want rather than what the laws of physics allow. |
1459 | // For example, consider a real motorcycle...it must be moving forward in order for | 1615 | // For example, consider a real motorcycle...it must be moving forward in order for |
@@ -1465,14 +1621,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1465 | // totally static (0.0) and totally dynamic (1.0). By "static" we mean that the | 1621 | // totally static (0.0) and totally dynamic (1.0). By "static" we mean that the |
1466 | // banking effect depends only on the vehicle's rotation about its roll-axis compared | 1622 | // banking effect depends only on the vehicle's rotation about its roll-axis compared |
1467 | // to "dynamic" where the banking is also proportional to its velocity along its | 1623 | // to "dynamic" where the banking is also proportional to its velocity along its |
1468 | // roll-axis. Finding the best value of the "mixture" will probably require trial and error. | 1624 | // roll-axis. Finding the best value of the "mixture" will probably require trial and error. |
1469 | // The time it takes for the banking behavior to defeat a preexisting angular velocity about the | 1625 | // The time it takes for the banking behavior to defeat a preexisting angular velocity about the |
1470 | // world z-axis is determined by the VEHICLE_BANKING_TIMESCALE. So if you want the vehicle to | 1626 | // world z-axis is determined by the VEHICLE_BANKING_TIMESCALE. So if you want the vehicle to |
1471 | // bank quickly then give it a banking timescale of about a second or less, otherwise you can | 1627 | // bank quickly then give it a banking timescale of about a second or less, otherwise you can |
1472 | // make a sluggish vehicle by giving it a timescale of several seconds. | 1628 | // make a sluggish vehicle by giving it a timescale of several seconds. |
1473 | public void ComputeAngularBanking() | 1629 | public void ComputeAngularBanking() |
1474 | { | 1630 | { |
1475 | if (enableAngularBanking && m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff) | 1631 | if (BSParam.VehicleEnableAngularBanking && m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff) |
1476 | { | 1632 | { |
1477 | Vector3 bankingContributionV = Vector3.Zero; | 1633 | Vector3 bankingContributionV = Vector3.Zero; |
1478 | 1634 | ||
@@ -1498,10 +1654,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1498 | 1654 | ||
1499 | //VehicleRotationalVelocity += bankingContributionV * VehicleOrientation; | 1655 | //VehicleRotationalVelocity += bankingContributionV * VehicleOrientation; |
1500 | VehicleRotationalVelocity += bankingContributionV; | 1656 | VehicleRotationalVelocity += bankingContributionV; |
1501 | 1657 | ||
1502 | 1658 | ||
1503 | VDetailLog("{0}, MoveAngular,Banking,rollComp={1},speed={2},rollComp={3},yAng={4},mYAng={5},ret={6}", | 1659 | VDetailLog("{0}, MoveAngular,Banking,rollComp={1},speed={2},rollComp={3},yAng={4},mYAng={5},ret={6}", |
1504 | Prim.LocalID, rollComponents, VehicleForwardSpeed, rollComponents, yawAngle, mixedYawAngle, bankingContributionV); | 1660 | ControllingPrim.LocalID, rollComponents, VehicleForwardSpeed, rollComponents, yawAngle, mixedYawAngle, bankingContributionV); |
1505 | } | 1661 | } |
1506 | } | 1662 | } |
1507 | 1663 | ||
@@ -1540,8 +1696,37 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1540 | if (rotq != m_rot) | 1696 | if (rotq != m_rot) |
1541 | { | 1697 | { |
1542 | VehicleOrientation = m_rot; | 1698 | VehicleOrientation = m_rot; |
1543 | VDetailLog("{0}, LimitRotation,done,orig={1},new={2}", Prim.LocalID, rotq, m_rot); | 1699 | VDetailLog("{0}, LimitRotation,done,orig={1},new={2}", ControllingPrim.LocalID, rotq, m_rot); |
1700 | } | ||
1701 | |||
1702 | } | ||
1703 | |||
1704 | // Given a friction vector (reduction in seconds) and a timestep, return the factor to reduce | ||
1705 | // some value by to apply this friction. | ||
1706 | private Vector3 ComputeFrictionFactor(Vector3 friction, float pTimestep) | ||
1707 | { | ||
1708 | Vector3 frictionFactor = Vector3.Zero; | ||
1709 | if (friction != BSMotor.InfiniteVector) | ||
1710 | { | ||
1711 | // frictionFactor = (Vector3.One / FrictionTimescale) * timeStep; | ||
1712 | // Individual friction components can be 'infinite' so compute each separately. | ||
1713 | frictionFactor.X = (friction.X == BSMotor.Infinite) ? 0f : (1f / friction.X); | ||
1714 | frictionFactor.Y = (friction.Y == BSMotor.Infinite) ? 0f : (1f / friction.Y); | ||
1715 | frictionFactor.Z = (friction.Z == BSMotor.Infinite) ? 0f : (1f / friction.Z); | ||
1716 | frictionFactor *= pTimestep; | ||
1717 | } | ||
1718 | return frictionFactor; | ||
1719 | } | ||
1720 | |||
1721 | private float SortedClampInRange(float clampa, float val, float clampb) | ||
1722 | { | ||
1723 | if (clampa > clampb) | ||
1724 | { | ||
1725 | float temp = clampa; | ||
1726 | clampa = clampb; | ||
1727 | clampb = temp; | ||
1544 | } | 1728 | } |
1729 | return ClampInRange(clampa, val, clampb); | ||
1545 | 1730 | ||
1546 | } | 1731 | } |
1547 | 1732 | ||
@@ -1554,8 +1739,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1554 | // Invoke the detailed logger and output something if it's enabled. | 1739 | // Invoke the detailed logger and output something if it's enabled. |
1555 | private void VDetailLog(string msg, params Object[] args) | 1740 | private void VDetailLog(string msg, params Object[] args) |
1556 | { | 1741 | { |
1557 | if (Prim.PhysicsScene.VehicleLoggingEnabled) | 1742 | if (ControllingPrim.PhysScene.VehicleLoggingEnabled) |
1558 | Prim.PhysicsScene.DetailLog(msg, args); | 1743 | ControllingPrim.PhysScene.DetailLog(msg, args); |
1559 | } | 1744 | } |
1560 | } | 1745 | } |
1561 | } | 1746 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs index 4ece1eb..77f69a5 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs | |||
@@ -33,14 +33,6 @@ using OMV = OpenMetaverse; | |||
33 | namespace OpenSim.Region.Physics.BulletSPlugin | 33 | namespace OpenSim.Region.Physics.BulletSPlugin |
34 | { | 34 | { |
35 | 35 | ||
36 | // A BSPrim can get individual information about its linkedness attached | ||
37 | // to it through an instance of a subclass of LinksetInfo. | ||
38 | // Each type of linkset will define the information needed for its type. | ||
39 | public abstract class BSLinksetInfo | ||
40 | { | ||
41 | public virtual void Clear() { } | ||
42 | } | ||
43 | |||
44 | public abstract class BSLinkset | 36 | public abstract class BSLinkset |
45 | { | 37 | { |
46 | // private static string LogHeader = "[BULLETSIM LINKSET]"; | 38 | // private static string LogHeader = "[BULLETSIM LINKSET]"; |
@@ -56,15 +48,15 @@ public abstract class BSLinkset | |||
56 | { | 48 | { |
57 | BSLinkset ret = null; | 49 | BSLinkset ret = null; |
58 | 50 | ||
59 | switch ((int)BSParam.LinksetImplementation) | 51 | switch (parent.LinksetType) |
60 | { | 52 | { |
61 | case (int)LinksetImplementation.Constraint: | 53 | case LinksetImplementation.Constraint: |
62 | ret = new BSLinksetConstraints(physScene, parent); | 54 | ret = new BSLinksetConstraints(physScene, parent); |
63 | break; | 55 | break; |
64 | case (int)LinksetImplementation.Compound: | 56 | case LinksetImplementation.Compound: |
65 | ret = new BSLinksetCompound(physScene, parent); | 57 | ret = new BSLinksetCompound(physScene, parent); |
66 | break; | 58 | break; |
67 | case (int)LinksetImplementation.Manual: | 59 | case LinksetImplementation.Manual: |
68 | // ret = new BSLinksetManual(physScene, parent); | 60 | // ret = new BSLinksetManual(physScene, parent); |
69 | break; | 61 | break; |
70 | default: | 62 | default: |
@@ -78,28 +70,37 @@ public abstract class BSLinkset | |||
78 | return ret; | 70 | return ret; |
79 | } | 71 | } |
80 | 72 | ||
73 | public class BSLinkInfo | ||
74 | { | ||
75 | public BSPrimLinkable member; | ||
76 | public BSLinkInfo(BSPrimLinkable pMember) | ||
77 | { | ||
78 | member = pMember; | ||
79 | } | ||
80 | public virtual void ResetLink() { } | ||
81 | public virtual void SetLinkParameters(BSConstraint constrain) { } | ||
82 | // Returns 'true' if physical property updates from the child should be reported to the simulator | ||
83 | public virtual bool ShouldUpdateChildProperties() { return false; } | ||
84 | } | ||
85 | |||
86 | public LinksetImplementation LinksetImpl { get; protected set; } | ||
87 | |||
81 | public BSPrimLinkable LinksetRoot { get; protected set; } | 88 | public BSPrimLinkable LinksetRoot { get; protected set; } |
82 | 89 | ||
83 | public BSScene PhysicsScene { get; private set; } | 90 | protected BSScene m_physicsScene { get; private set; } |
84 | 91 | ||
85 | static int m_nextLinksetID = 1; | 92 | static int m_nextLinksetID = 1; |
86 | public int LinksetID { get; private set; } | 93 | public int LinksetID { get; private set; } |
87 | 94 | ||
88 | // The children under the root in this linkset. | 95 | // The children under the root in this linkset. |
89 | protected HashSet<BSPrimLinkable> m_children; | 96 | // protected HashSet<BSPrimLinkable> m_children; |
97 | protected Dictionary<BSPrimLinkable, BSLinkInfo> m_children; | ||
90 | 98 | ||
91 | // We lock the diddling of linkset classes to prevent any badness. | 99 | // We lock the diddling of linkset classes to prevent any badness. |
92 | // This locks the modification of the instances of this class. Changes | 100 | // This locks the modification of the instances of this class. Changes |
93 | // to the physical representation is done via the tainting mechenism. | 101 | // to the physical representation is done via the tainting mechenism. |
94 | protected object m_linksetActivityLock = new Object(); | 102 | protected object m_linksetActivityLock = new Object(); |
95 | 103 | ||
96 | // Some linksets have a preferred physical shape. | ||
97 | // Returns SHAPE_UNKNOWN if there is no preference. Causes the correct shape to be selected. | ||
98 | public virtual BSPhysicsShapeType PreferredPhysicalShape(BSPrimLinkable requestor) | ||
99 | { | ||
100 | return BSPhysicsShapeType.SHAPE_UNKNOWN; | ||
101 | } | ||
102 | |||
103 | // We keep the prim's mass in the linkset structure since it could be dependent on other prims | 104 | // We keep the prim's mass in the linkset structure since it could be dependent on other prims |
104 | public float LinksetMass { get; protected set; } | 105 | public float LinksetMass { get; protected set; } |
105 | 106 | ||
@@ -122,9 +123,9 @@ public abstract class BSLinkset | |||
122 | // We create LOTS of linksets. | 123 | // We create LOTS of linksets. |
123 | if (m_nextLinksetID <= 0) | 124 | if (m_nextLinksetID <= 0) |
124 | m_nextLinksetID = 1; | 125 | m_nextLinksetID = 1; |
125 | PhysicsScene = scene; | 126 | m_physicsScene = scene; |
126 | LinksetRoot = parent; | 127 | LinksetRoot = parent; |
127 | m_children = new HashSet<BSPrimLinkable>(); | 128 | m_children = new Dictionary<BSPrimLinkable, BSLinkInfo>(); |
128 | LinksetMass = parent.RawMass; | 129 | LinksetMass = parent.RawMass; |
129 | Rebuilding = false; | 130 | Rebuilding = false; |
130 | 131 | ||
@@ -151,7 +152,7 @@ public abstract class BSLinkset | |||
151 | // Returns a new linkset for the child which is a linkset of one (just the | 152 | // Returns a new linkset for the child which is a linkset of one (just the |
152 | // orphened child). | 153 | // orphened child). |
153 | // Called at runtime. | 154 | // Called at runtime. |
154 | public BSLinkset RemoveMeFromLinkset(BSPrimLinkable child) | 155 | public BSLinkset RemoveMeFromLinkset(BSPrimLinkable child, bool inTaintTime) |
155 | { | 156 | { |
156 | lock (m_linksetActivityLock) | 157 | lock (m_linksetActivityLock) |
157 | { | 158 | { |
@@ -160,12 +161,12 @@ public abstract class BSLinkset | |||
160 | // Cannot remove the root from a linkset. | 161 | // Cannot remove the root from a linkset. |
161 | return this; | 162 | return this; |
162 | } | 163 | } |
163 | RemoveChildFromLinkset(child); | 164 | RemoveChildFromLinkset(child, inTaintTime); |
164 | LinksetMass = ComputeLinksetMass(); | 165 | LinksetMass = ComputeLinksetMass(); |
165 | } | 166 | } |
166 | 167 | ||
167 | // The child is down to a linkset of just itself | 168 | // The child is down to a linkset of just itself |
168 | return BSLinkset.Factory(PhysicsScene, child); | 169 | return BSLinkset.Factory(m_physicsScene, child); |
169 | } | 170 | } |
170 | 171 | ||
171 | // Return 'true' if the passed object is the root object of this linkset | 172 | // Return 'true' if the passed object is the root object of this linkset |
@@ -185,17 +186,7 @@ public abstract class BSLinkset | |||
185 | bool ret = false; | 186 | bool ret = false; |
186 | lock (m_linksetActivityLock) | 187 | lock (m_linksetActivityLock) |
187 | { | 188 | { |
188 | ret = m_children.Contains(child); | 189 | ret = m_children.ContainsKey(child); |
189 | /* Safer version but the above should work | ||
190 | foreach (BSPrimLinkable bp in m_children) | ||
191 | { | ||
192 | if (child.LocalID == bp.LocalID) | ||
193 | { | ||
194 | ret = true; | ||
195 | break; | ||
196 | } | ||
197 | } | ||
198 | */ | ||
199 | } | 190 | } |
200 | return ret; | 191 | return ret; |
201 | } | 192 | } |
@@ -209,7 +200,35 @@ public abstract class BSLinkset | |||
209 | lock (m_linksetActivityLock) | 200 | lock (m_linksetActivityLock) |
210 | { | 201 | { |
211 | action(LinksetRoot); | 202 | action(LinksetRoot); |
212 | foreach (BSPrimLinkable po in m_children) | 203 | foreach (BSPrimLinkable po in m_children.Keys) |
204 | { | ||
205 | if (action(po)) | ||
206 | break; | ||
207 | } | ||
208 | } | ||
209 | return ret; | ||
210 | } | ||
211 | |||
212 | public bool TryGetLinkInfo(BSPrimLinkable child, out BSLinkInfo foundInfo) | ||
213 | { | ||
214 | bool ret = false; | ||
215 | BSLinkInfo found = null; | ||
216 | lock (m_linksetActivityLock) | ||
217 | { | ||
218 | ret = m_children.TryGetValue(child, out found); | ||
219 | } | ||
220 | foundInfo = found; | ||
221 | return ret; | ||
222 | } | ||
223 | // Perform an action on each member of the linkset including root prim. | ||
224 | // Depends on the action on whether this should be done at taint time. | ||
225 | public delegate bool ForEachLinkInfoAction(BSLinkInfo obj); | ||
226 | public virtual bool ForEachLinkInfo(ForEachLinkInfoAction action) | ||
227 | { | ||
228 | bool ret = false; | ||
229 | lock (m_linksetActivityLock) | ||
230 | { | ||
231 | foreach (BSLinkInfo po in m_children.Values) | ||
213 | { | 232 | { |
214 | if (action(po)) | 233 | if (action(po)) |
215 | break; | 234 | break; |
@@ -218,13 +237,55 @@ public abstract class BSLinkset | |||
218 | return ret; | 237 | return ret; |
219 | } | 238 | } |
220 | 239 | ||
240 | // Check the type of the link and return 'true' if the link is flexible and the | ||
241 | // updates from the child should be sent to the simulator so things change. | ||
242 | public virtual bool ShouldReportPropertyUpdates(BSPrimLinkable child) | ||
243 | { | ||
244 | bool ret = false; | ||
245 | |||
246 | BSLinkInfo linkInfo; | ||
247 | if (m_children.TryGetValue(child, out linkInfo)) | ||
248 | { | ||
249 | ret = linkInfo.ShouldUpdateChildProperties(); | ||
250 | } | ||
251 | |||
252 | return ret; | ||
253 | } | ||
254 | |||
255 | // Called after a simulation step to post a collision with this object. | ||
256 | // Return 'true' if linkset processed the collision. 'false' says the linkset didn't have | ||
257 | // anything to add for the collision and it should be passed through normal processing. | ||
258 | // Default processing for a linkset. | ||
259 | public virtual bool HandleCollide(uint collidingWith, BSPhysObject collidee, | ||
260 | OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) | ||
261 | { | ||
262 | bool ret = false; | ||
263 | |||
264 | // prims in the same linkset cannot collide with each other | ||
265 | BSPrimLinkable convCollidee = collidee as BSPrimLinkable; | ||
266 | if (convCollidee != null && (LinksetID == convCollidee.Linkset.LinksetID)) | ||
267 | { | ||
268 | // By returning 'true', we tell the caller the collision has been 'handled' so it won't | ||
269 | // do anything about this collision and thus, effectivily, ignoring the collision. | ||
270 | ret = true; | ||
271 | } | ||
272 | else | ||
273 | { | ||
274 | // Not a collision between members of the linkset. Must be a real collision. | ||
275 | // So the linkset root can know if there is a collision anywhere in the linkset. | ||
276 | LinksetRoot.SomeCollisionSimulationStep = m_physicsScene.SimulationStep; | ||
277 | } | ||
278 | |||
279 | return ret; | ||
280 | } | ||
281 | |||
221 | // I am the root of a linkset and a new child is being added | 282 | // I am the root of a linkset and a new child is being added |
222 | // Called while LinkActivity is locked. | 283 | // Called while LinkActivity is locked. |
223 | protected abstract void AddChildToLinkset(BSPrimLinkable child); | 284 | protected abstract void AddChildToLinkset(BSPrimLinkable child); |
224 | 285 | ||
225 | // I am the root of a linkset and one of my children is being removed. | 286 | // I am the root of a linkset and one of my children is being removed. |
226 | // Safe to call even if the child is not really in my linkset. | 287 | // Safe to call even if the child is not really in my linkset. |
227 | protected abstract void RemoveChildFromLinkset(BSPrimLinkable child); | 288 | protected abstract void RemoveChildFromLinkset(BSPrimLinkable child, bool inTaintTime); |
228 | 289 | ||
229 | // When physical properties are changed the linkset needs to recalculate | 290 | // When physical properties are changed the linkset needs to recalculate |
230 | // its internal properties. | 291 | // its internal properties. |
@@ -263,9 +324,88 @@ public abstract class BSLinkset | |||
263 | // This is called when the root body is changing. | 324 | // This is called when the root body is changing. |
264 | // Returns 'true' of something was actually removed and would need restoring | 325 | // Returns 'true' of something was actually removed and would need restoring |
265 | // Called at taint-time!! | 326 | // Called at taint-time!! |
266 | public abstract bool RemoveBodyDependencies(BSPrimLinkable child); | 327 | public abstract bool RemoveDependencies(BSPrimLinkable child); |
267 | 328 | ||
268 | // ================================================================ | 329 | // ================================================================ |
330 | // Some physical setting happen to all members of the linkset | ||
331 | public virtual void SetPhysicalFriction(float friction) | ||
332 | { | ||
333 | ForEachMember((member) => | ||
334 | { | ||
335 | if (member.PhysBody.HasPhysicalBody) | ||
336 | m_physicsScene.PE.SetFriction(member.PhysBody, friction); | ||
337 | return false; // 'false' says to continue looping | ||
338 | } | ||
339 | ); | ||
340 | } | ||
341 | public virtual void SetPhysicalRestitution(float restitution) | ||
342 | { | ||
343 | ForEachMember((member) => | ||
344 | { | ||
345 | if (member.PhysBody.HasPhysicalBody) | ||
346 | m_physicsScene.PE.SetRestitution(member.PhysBody, restitution); | ||
347 | return false; // 'false' says to continue looping | ||
348 | } | ||
349 | ); | ||
350 | } | ||
351 | public virtual void SetPhysicalGravity(OMV.Vector3 gravity) | ||
352 | { | ||
353 | ForEachMember((member) => | ||
354 | { | ||
355 | if (member.PhysBody.HasPhysicalBody) | ||
356 | m_physicsScene.PE.SetGravity(member.PhysBody, gravity); | ||
357 | return false; // 'false' says to continue looping | ||
358 | } | ||
359 | ); | ||
360 | } | ||
361 | public virtual void ComputeAndSetLocalInertia(OMV.Vector3 inertiaFactor, float linksetMass) | ||
362 | { | ||
363 | ForEachMember((member) => | ||
364 | { | ||
365 | if (member.PhysBody.HasPhysicalBody) | ||
366 | { | ||
367 | OMV.Vector3 inertia = m_physicsScene.PE.CalculateLocalInertia(member.PhysShape.physShapeInfo, linksetMass); | ||
368 | member.Inertia = inertia * inertiaFactor; | ||
369 | m_physicsScene.PE.SetMassProps(member.PhysBody, linksetMass, member.Inertia); | ||
370 | m_physicsScene.PE.UpdateInertiaTensor(member.PhysBody); | ||
371 | DetailLog("{0},BSLinkset.ComputeAndSetLocalInertia,m.mass={1}, inertia={2}", member.LocalID, linksetMass, member.Inertia); | ||
372 | |||
373 | } | ||
374 | return false; // 'false' says to continue looping | ||
375 | } | ||
376 | ); | ||
377 | } | ||
378 | public virtual void SetPhysicalCollisionFlags(CollisionFlags collFlags) | ||
379 | { | ||
380 | ForEachMember((member) => | ||
381 | { | ||
382 | if (member.PhysBody.HasPhysicalBody) | ||
383 | m_physicsScene.PE.SetCollisionFlags(member.PhysBody, collFlags); | ||
384 | return false; // 'false' says to continue looping | ||
385 | } | ||
386 | ); | ||
387 | } | ||
388 | public virtual void AddToPhysicalCollisionFlags(CollisionFlags collFlags) | ||
389 | { | ||
390 | ForEachMember((member) => | ||
391 | { | ||
392 | if (member.PhysBody.HasPhysicalBody) | ||
393 | m_physicsScene.PE.AddToCollisionFlags(member.PhysBody, collFlags); | ||
394 | return false; // 'false' says to continue looping | ||
395 | } | ||
396 | ); | ||
397 | } | ||
398 | public virtual void RemoveFromPhysicalCollisionFlags(CollisionFlags collFlags) | ||
399 | { | ||
400 | ForEachMember((member) => | ||
401 | { | ||
402 | if (member.PhysBody.HasPhysicalBody) | ||
403 | m_physicsScene.PE.RemoveFromCollisionFlags(member.PhysBody, collFlags); | ||
404 | return false; // 'false' says to continue looping | ||
405 | } | ||
406 | ); | ||
407 | } | ||
408 | // ================================================================ | ||
269 | protected virtual float ComputeLinksetMass() | 409 | protected virtual float ComputeLinksetMass() |
270 | { | 410 | { |
271 | float mass = LinksetRoot.RawMass; | 411 | float mass = LinksetRoot.RawMass; |
@@ -273,7 +413,7 @@ public abstract class BSLinkset | |||
273 | { | 413 | { |
274 | lock (m_linksetActivityLock) | 414 | lock (m_linksetActivityLock) |
275 | { | 415 | { |
276 | foreach (BSPrimLinkable bp in m_children) | 416 | foreach (BSPrimLinkable bp in m_children.Keys) |
277 | { | 417 | { |
278 | mass += bp.RawMass; | 418 | mass += bp.RawMass; |
279 | } | 419 | } |
@@ -291,7 +431,7 @@ public abstract class BSLinkset | |||
291 | com = LinksetRoot.Position * LinksetRoot.RawMass; | 431 | com = LinksetRoot.Position * LinksetRoot.RawMass; |
292 | float totalMass = LinksetRoot.RawMass; | 432 | float totalMass = LinksetRoot.RawMass; |
293 | 433 | ||
294 | foreach (BSPrimLinkable bp in m_children) | 434 | foreach (BSPrimLinkable bp in m_children.Keys) |
295 | { | 435 | { |
296 | com += bp.Position * bp.RawMass; | 436 | com += bp.Position * bp.RawMass; |
297 | totalMass += bp.RawMass; | 437 | totalMass += bp.RawMass; |
@@ -310,7 +450,7 @@ public abstract class BSLinkset | |||
310 | { | 450 | { |
311 | com = LinksetRoot.Position; | 451 | com = LinksetRoot.Position; |
312 | 452 | ||
313 | foreach (BSPrimLinkable bp in m_children) | 453 | foreach (BSPrimLinkable bp in m_children.Keys) |
314 | { | 454 | { |
315 | com += bp.Position; | 455 | com += bp.Position; |
316 | } | 456 | } |
@@ -320,12 +460,18 @@ public abstract class BSLinkset | |||
320 | return com; | 460 | return com; |
321 | } | 461 | } |
322 | 462 | ||
463 | #region Extension | ||
464 | public virtual object Extension(string pFunct, params object[] pParams) | ||
465 | { | ||
466 | return null; | ||
467 | } | ||
468 | #endregion // Extension | ||
469 | |||
323 | // Invoke the detailed logger and output something if it's enabled. | 470 | // Invoke the detailed logger and output something if it's enabled. |
324 | protected void DetailLog(string msg, params Object[] args) | 471 | protected void DetailLog(string msg, params Object[] args) |
325 | { | 472 | { |
326 | if (PhysicsScene.PhysicsLogging.Enabled) | 473 | if (m_physicsScene.PhysicsLogging.Enabled) |
327 | PhysicsScene.DetailLog(msg, args); | 474 | m_physicsScene.DetailLog(msg, args); |
328 | } | 475 | } |
329 | |||
330 | } | 476 | } |
331 | } | 477 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index e05562a..8f12189 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs | |||
@@ -35,103 +35,78 @@ using OMV = OpenMetaverse; | |||
35 | namespace OpenSim.Region.Physics.BulletSPlugin | 35 | namespace OpenSim.Region.Physics.BulletSPlugin |
36 | { | 36 | { |
37 | 37 | ||
38 | // When a child is linked, the relationship position of the child to the parent | 38 | public sealed class BSLinksetCompound : BSLinkset |
39 | // is remembered so the child's world position can be recomputed when it is | ||
40 | // removed from the linkset. | ||
41 | sealed class BSLinksetCompoundInfo : BSLinksetInfo | ||
42 | { | 39 | { |
43 | public int Index; | 40 | private static string LogHeader = "[BULLETSIM LINKSET COMPOUND]"; |
44 | public OMV.Vector3 OffsetFromRoot; | 41 | |
45 | public OMV.Vector3 OffsetFromCenterOfMass; | 42 | public BSLinksetCompound(BSScene scene, BSPrimLinkable parent) |
46 | public OMV.Quaternion OffsetRot; | 43 | : base(scene, parent) |
47 | public BSLinksetCompoundInfo(int indx, OMV.Vector3 p, OMV.Quaternion r) | ||
48 | { | 44 | { |
49 | Index = indx; | 45 | LinksetImpl = LinksetImplementation.Compound; |
50 | OffsetFromRoot = p; | ||
51 | OffsetFromCenterOfMass = p; | ||
52 | OffsetRot = r; | ||
53 | } | 46 | } |
54 | // 'centerDisplacement' is the distance from the root the the center-of-mass (Bullet 'zero' of the shape) | 47 | |
55 | public BSLinksetCompoundInfo(int indx, BSPrimLinkable root, BSPrimLinkable child, OMV.Vector3 centerDisplacement) | 48 | // ================================================================ |
49 | // Changing the physical property of the linkset only needs to change the root | ||
50 | public override void SetPhysicalFriction(float friction) | ||
56 | { | 51 | { |
57 | // Each child position and rotation is given relative to the center-of-mass. | 52 | if (LinksetRoot.PhysBody.HasPhysicalBody) |
58 | OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(root.RawOrientation); | 53 | m_physicsScene.PE.SetFriction(LinksetRoot.PhysBody, friction); |
59 | OMV.Vector3 displacementFromRoot = (child.RawPosition - root.RawPosition) * invRootOrientation; | ||
60 | OMV.Vector3 displacementFromCOM = displacementFromRoot - centerDisplacement; | ||
61 | OMV.Quaternion displacementRot = child.RawOrientation * invRootOrientation; | ||
62 | |||
63 | // Save relative position for recomputing child's world position after moving linkset. | ||
64 | Index = indx; | ||
65 | OffsetFromRoot = displacementFromRoot; | ||
66 | OffsetFromCenterOfMass = displacementFromCOM; | ||
67 | OffsetRot = displacementRot; | ||
68 | } | 54 | } |
69 | public override void Clear() | 55 | public override void SetPhysicalRestitution(float restitution) |
70 | { | 56 | { |
71 | Index = 0; | 57 | if (LinksetRoot.PhysBody.HasPhysicalBody) |
72 | OffsetFromRoot = OMV.Vector3.Zero; | 58 | m_physicsScene.PE.SetRestitution(LinksetRoot.PhysBody, restitution); |
73 | OffsetFromCenterOfMass = OMV.Vector3.Zero; | ||
74 | OffsetRot = OMV.Quaternion.Identity; | ||
75 | } | 59 | } |
76 | public override string ToString() | 60 | public override void SetPhysicalGravity(OMV.Vector3 gravity) |
77 | { | 61 | { |
78 | StringBuilder buff = new StringBuilder(); | 62 | if (LinksetRoot.PhysBody.HasPhysicalBody) |
79 | buff.Append("<i="); | 63 | m_physicsScene.PE.SetGravity(LinksetRoot.PhysBody, gravity); |
80 | buff.Append(Index.ToString()); | ||
81 | buff.Append(",p="); | ||
82 | buff.Append(OffsetFromRoot.ToString()); | ||
83 | buff.Append(",m="); | ||
84 | buff.Append(OffsetFromCenterOfMass.ToString()); | ||
85 | buff.Append(",r="); | ||
86 | buff.Append(OffsetRot.ToString()); | ||
87 | buff.Append(">"); | ||
88 | return buff.ToString(); | ||
89 | } | 64 | } |
90 | }; | 65 | public override void ComputeAndSetLocalInertia(OMV.Vector3 inertiaFactor, float linksetMass) |
91 | |||
92 | public sealed class BSLinksetCompound : BSLinkset | ||
93 | { | ||
94 | private static string LogHeader = "[BULLETSIM LINKSET COMPOUND]"; | ||
95 | |||
96 | public BSLinksetCompound(BSScene scene, BSPrimLinkable parent) | ||
97 | : base(scene, parent) | ||
98 | { | 66 | { |
67 | OMV.Vector3 inertia = m_physicsScene.PE.CalculateLocalInertia(LinksetRoot.PhysShape.physShapeInfo, linksetMass); | ||
68 | LinksetRoot.Inertia = inertia * inertiaFactor; | ||
69 | m_physicsScene.PE.SetMassProps(LinksetRoot.PhysBody, linksetMass, LinksetRoot.Inertia); | ||
70 | m_physicsScene.PE.UpdateInertiaTensor(LinksetRoot.PhysBody); | ||
99 | } | 71 | } |
100 | 72 | public override void SetPhysicalCollisionFlags(CollisionFlags collFlags) | |
101 | // For compound implimented linksets, if there are children, use compound shape for the root. | 73 | { |
102 | public override BSPhysicsShapeType PreferredPhysicalShape(BSPrimLinkable requestor) | 74 | if (LinksetRoot.PhysBody.HasPhysicalBody) |
103 | { | 75 | m_physicsScene.PE.SetCollisionFlags(LinksetRoot.PhysBody, collFlags); |
104 | // Returning 'unknown' means we don't have a preference. | 76 | } |
105 | BSPhysicsShapeType ret = BSPhysicsShapeType.SHAPE_UNKNOWN; | 77 | public override void AddToPhysicalCollisionFlags(CollisionFlags collFlags) |
106 | if (IsRoot(requestor) && HasAnyChildren) | 78 | { |
107 | { | 79 | if (LinksetRoot.PhysBody.HasPhysicalBody) |
108 | ret = BSPhysicsShapeType.SHAPE_COMPOUND; | 80 | m_physicsScene.PE.AddToCollisionFlags(LinksetRoot.PhysBody, collFlags); |
109 | } | ||
110 | // DetailLog("{0},BSLinksetCompound.PreferredPhysicalShape,call,shape={1}", LinksetRoot.LocalID, ret); | ||
111 | return ret; | ||
112 | } | 81 | } |
82 | public override void RemoveFromPhysicalCollisionFlags(CollisionFlags collFlags) | ||
83 | { | ||
84 | if (LinksetRoot.PhysBody.HasPhysicalBody) | ||
85 | m_physicsScene.PE.RemoveFromCollisionFlags(LinksetRoot.PhysBody, collFlags); | ||
86 | } | ||
87 | // ================================================================ | ||
113 | 88 | ||
114 | // When physical properties are changed the linkset needs to recalculate | 89 | // When physical properties are changed the linkset needs to recalculate |
115 | // its internal properties. | 90 | // its internal properties. |
116 | public override void Refresh(BSPrimLinkable requestor) | 91 | public override void Refresh(BSPrimLinkable requestor) |
117 | { | 92 | { |
118 | base.Refresh(requestor); | ||
119 | |||
120 | // Something changed so do the rebuilding thing | 93 | // Something changed so do the rebuilding thing |
121 | // ScheduleRebuild(); | 94 | ScheduleRebuild(requestor); |
95 | base.Refresh(requestor); | ||
122 | } | 96 | } |
123 | 97 | ||
124 | // Schedule a refresh to happen after all the other taint processing. | 98 | // Schedule a refresh to happen after all the other taint processing. |
125 | private void ScheduleRebuild(BSPrimLinkable requestor) | 99 | private void ScheduleRebuild(BSPrimLinkable requestor) |
126 | { | 100 | { |
127 | DetailLog("{0},BSLinksetCompound.ScheduleRebuild,,rebuilding={1},hasChildren={2},actuallyScheduling={3}", | 101 | DetailLog("{0},BSLinksetCompound.ScheduleRebuild,,rebuilding={1},hasChildren={2},actuallyScheduling={3}", |
128 | requestor.LocalID, Rebuilding, HasAnyChildren, (!Rebuilding && HasAnyChildren)); | 102 | requestor.LocalID, Rebuilding, HasAnyChildren, (!Rebuilding && HasAnyChildren)); |
103 | |||
129 | // When rebuilding, it is possible to set properties that would normally require a rebuild. | 104 | // When rebuilding, it is possible to set properties that would normally require a rebuild. |
130 | // If already rebuilding, don't request another rebuild. | 105 | // If already rebuilding, don't request another rebuild. |
131 | // If a linkset with just a root prim (simple non-linked prim) don't bother rebuilding. | 106 | // If a linkset with just a root prim (simple non-linked prim) don't bother rebuilding. |
132 | if (!Rebuilding && HasAnyChildren) | 107 | if (!Rebuilding && HasAnyChildren) |
133 | { | 108 | { |
134 | PhysicsScene.PostTaintObject("BSLinksetCompound.ScheduleRebuild", LinksetRoot.LocalID, delegate() | 109 | m_physicsScene.PostTaintObject("BSLinksetCompound.ScheduleRebuild", LinksetRoot.LocalID, delegate() |
135 | { | 110 | { |
136 | if (HasAnyChildren) | 111 | if (HasAnyChildren) |
137 | RecomputeLinksetCompound(); | 112 | RecomputeLinksetCompound(); |
@@ -151,47 +126,24 @@ public sealed class BSLinksetCompound : BSLinkset | |||
151 | if (IsRoot(child)) | 126 | if (IsRoot(child)) |
152 | { | 127 | { |
153 | // The root is going dynamic. Rebuild the linkset so parts and mass get computed properly. | 128 | // The root is going dynamic. Rebuild the linkset so parts and mass get computed properly. |
154 | ScheduleRebuild(LinksetRoot); | 129 | Refresh(LinksetRoot); |
155 | } | ||
156 | else | ||
157 | { | ||
158 | // The origional prims are removed from the world as the shape of the root compound | ||
159 | // shape takes over. | ||
160 | PhysicsScene.PE.AddToCollisionFlags(child.PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE); | ||
161 | PhysicsScene.PE.ForceActivationState(child.PhysBody, ActivationState.DISABLE_SIMULATION); | ||
162 | // We don't want collisions from the old linkset children. | ||
163 | PhysicsScene.PE.RemoveFromCollisionFlags(child.PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | ||
164 | |||
165 | child.PhysBody.collisionType = CollisionType.LinksetChild; | ||
166 | |||
167 | ret = true; | ||
168 | } | 130 | } |
169 | return ret; | 131 | return ret; |
170 | } | 132 | } |
171 | 133 | ||
172 | // The object is going static (non-physical). Do any setup necessary for a static linkset. | 134 | // The object is going static (non-physical). We do not do anything for static linksets. |
173 | // Return 'true' if any properties updated on the passed object. | 135 | // Return 'true' if any properties updated on the passed object. |
174 | // This doesn't normally happen -- OpenSim removes the objects from the physical | ||
175 | // world if it is a static linkset. | ||
176 | // Called at taint-time! | 136 | // Called at taint-time! |
177 | public override bool MakeStatic(BSPrimLinkable child) | 137 | public override bool MakeStatic(BSPrimLinkable child) |
178 | { | 138 | { |
179 | bool ret = false; | 139 | bool ret = false; |
140 | |||
180 | DetailLog("{0},BSLinksetCompound.MakeStatic,call,IsRoot={1}", child.LocalID, IsRoot(child)); | 141 | DetailLog("{0},BSLinksetCompound.MakeStatic,call,IsRoot={1}", child.LocalID, IsRoot(child)); |
142 | child.ClearDisplacement(); | ||
181 | if (IsRoot(child)) | 143 | if (IsRoot(child)) |
182 | { | 144 | { |
183 | ScheduleRebuild(LinksetRoot); | 145 | // Schedule a rebuild to verify that the root shape is set to the real shape. |
184 | } | 146 | Refresh(LinksetRoot); |
185 | else | ||
186 | { | ||
187 | // The non-physical children can come back to life. | ||
188 | PhysicsScene.PE.RemoveFromCollisionFlags(child.PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE); | ||
189 | |||
190 | child.PhysBody.collisionType = CollisionType.LinksetChild; | ||
191 | |||
192 | // Don't force activation so setting of DISABLE_SIMULATION can stay if used. | ||
193 | PhysicsScene.PE.Activate(child.PhysBody, false); | ||
194 | ret = true; | ||
195 | } | 147 | } |
196 | return ret; | 148 | return ret; |
197 | } | 149 | } |
@@ -200,13 +152,20 @@ public sealed class BSLinksetCompound : BSLinkset | |||
200 | // Called at taint-time. | 152 | // Called at taint-time. |
201 | public override void UpdateProperties(UpdatedProperties whichUpdated, BSPrimLinkable updated) | 153 | public override void UpdateProperties(UpdatedProperties whichUpdated, BSPrimLinkable updated) |
202 | { | 154 | { |
155 | if (!LinksetRoot.IsPhysicallyActive) | ||
156 | { | ||
157 | // No reason to do this physical stuff for static linksets. | ||
158 | DetailLog("{0},BSLinksetCompound.UpdateProperties,notPhysical", LinksetRoot.LocalID); | ||
159 | return; | ||
160 | } | ||
161 | |||
203 | // The user moving a child around requires the rebuilding of the linkset compound shape | 162 | // The user moving a child around requires the rebuilding of the linkset compound shape |
204 | // One problem is this happens when a border is crossed -- the simulator implementation | 163 | // One problem is this happens when a border is crossed -- the simulator implementation |
205 | // stores the position into the group which causes the move of the object | 164 | // stores the position into the group which causes the move of the object |
206 | // but it also means all the child positions get updated. | 165 | // but it also means all the child positions get updated. |
207 | // What would cause an unnecessary rebuild so we make sure the linkset is in a | 166 | // What would cause an unnecessary rebuild so we make sure the linkset is in a |
208 | // region before bothering to do a rebuild. | 167 | // region before bothering to do a rebuild. |
209 | if (!IsRoot(updated) && PhysicsScene.TerrainManager.IsWithinKnownTerrain(LinksetRoot.RawPosition)) | 168 | if (!IsRoot(updated) && m_physicsScene.TerrainManager.IsWithinKnownTerrain(LinksetRoot.RawPosition)) |
210 | { | 169 | { |
211 | // If a child of the linkset is updating only the position or rotation, that can be done | 170 | // If a child of the linkset is updating only the position or rotation, that can be done |
212 | // without rebuilding the linkset. | 171 | // without rebuilding the linkset. |
@@ -218,22 +177,22 @@ public sealed class BSLinksetCompound : BSLinkset | |||
218 | // and that is caused by us updating the object. | 177 | // and that is caused by us updating the object. |
219 | if ((whichUpdated & ~(UpdatedProperties.Position | UpdatedProperties.Orientation)) == 0) | 178 | if ((whichUpdated & ~(UpdatedProperties.Position | UpdatedProperties.Orientation)) == 0) |
220 | { | 179 | { |
221 | // Find the physical instance of the child | 180 | // Find the physical instance of the child |
222 | if (LinksetRoot.PhysShape.HasPhysicalShape && PhysicsScene.PE.IsCompound(LinksetRoot.PhysShape)) | 181 | if (LinksetRoot.PhysShape.HasPhysicalShape && m_physicsScene.PE.IsCompound(LinksetRoot.PhysShape.physShapeInfo)) |
223 | { | 182 | { |
224 | // It is possible that the linkset is still under construction and the child is not yet | 183 | // It is possible that the linkset is still under construction and the child is not yet |
225 | // inserted into the compound shape. A rebuild of the linkset in a pre-step action will | 184 | // inserted into the compound shape. A rebuild of the linkset in a pre-step action will |
226 | // build the whole thing with the new position or rotation. | 185 | // build the whole thing with the new position or rotation. |
227 | // The index must be checked because Bullet references the child array but does no validity | 186 | // The index must be checked because Bullet references the child array but does no validity |
228 | // checking of the child index passed. | 187 | // checking of the child index passed. |
229 | int numLinksetChildren = PhysicsScene.PE.GetNumberOfCompoundChildren(LinksetRoot.PhysShape); | 188 | int numLinksetChildren = m_physicsScene.PE.GetNumberOfCompoundChildren(LinksetRoot.PhysShape.physShapeInfo); |
230 | if (updated.LinksetChildIndex < numLinksetChildren) | 189 | if (updated.LinksetChildIndex < numLinksetChildren) |
231 | { | 190 | { |
232 | BulletShape linksetChildShape = PhysicsScene.PE.GetChildShapeFromCompoundShapeIndex(LinksetRoot.PhysShape, updated.LinksetChildIndex); | 191 | BulletShape linksetChildShape = m_physicsScene.PE.GetChildShapeFromCompoundShapeIndex(LinksetRoot.PhysShape.physShapeInfo, updated.LinksetChildIndex); |
233 | if (linksetChildShape.HasPhysicalShape) | 192 | if (linksetChildShape.HasPhysicalShape) |
234 | { | 193 | { |
235 | // Found the child shape within the compound shape | 194 | // Found the child shape within the compound shape |
236 | PhysicsScene.PE.UpdateChildTransform(LinksetRoot.PhysShape, updated.LinksetChildIndex, | 195 | m_physicsScene.PE.UpdateChildTransform(LinksetRoot.PhysShape.physShapeInfo, updated.LinksetChildIndex, |
237 | updated.RawPosition - LinksetRoot.RawPosition, | 196 | updated.RawPosition - LinksetRoot.RawPosition, |
238 | updated.RawOrientation * OMV.Quaternion.Inverse(LinksetRoot.RawOrientation), | 197 | updated.RawOrientation * OMV.Quaternion.Inverse(LinksetRoot.RawOrientation), |
239 | true /* shouldRecalculateLocalAabb */); | 198 | true /* shouldRecalculateLocalAabb */); |
@@ -267,83 +226,29 @@ public sealed class BSLinksetCompound : BSLinkset | |||
267 | // there will already be a rebuild scheduled. | 226 | // there will already be a rebuild scheduled. |
268 | DetailLog("{0},BSLinksetCompound.UpdateProperties,couldNotUpdateChild.schedulingRebuild,whichUpdated={1}", | 227 | DetailLog("{0},BSLinksetCompound.UpdateProperties,couldNotUpdateChild.schedulingRebuild,whichUpdated={1}", |
269 | updated.LocalID, whichUpdated); | 228 | updated.LocalID, whichUpdated); |
270 | updated.LinksetInfo = null; // setting to 'null' causes relative position to be recomputed. | 229 | Refresh(updated); |
271 | ScheduleRebuild(updated); | ||
272 | } | 230 | } |
273 | } | 231 | } |
274 | } | 232 | } |
275 | } | 233 | } |
276 | 234 | ||
277 | // Routine called when rebuilding the body of some member of the linkset. | 235 | // Routine called when rebuilding the body of some member of the linkset. |
278 | // Since we don't keep in world relationships, do nothing unless it's a child changing. | 236 | // If one of the bodies is being changed, the linkset needs rebuilding. |
237 | // For instance, a linkset is built and then a mesh asset is read in and the mesh is recreated. | ||
279 | // Returns 'true' of something was actually removed and would need restoring | 238 | // Returns 'true' of something was actually removed and would need restoring |
280 | // Called at taint-time!! | 239 | // Called at taint-time!! |
281 | public override bool RemoveBodyDependencies(BSPrimLinkable child) | 240 | public override bool RemoveDependencies(BSPrimLinkable child) |
282 | { | 241 | { |
283 | bool ret = false; | 242 | bool ret = false; |
284 | 243 | ||
285 | DetailLog("{0},BSLinksetCompound.RemoveBodyDependencies,refreshIfChild,rID={1},rBody={2},isRoot={3}", | 244 | DetailLog("{0},BSLinksetCompound.RemoveDependencies,refreshIfChild,rID={1},rBody={2},isRoot={3}", |
286 | child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody, IsRoot(child)); | 245 | child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody, IsRoot(child)); |
287 | 246 | ||
288 | if (!IsRoot(child)) | 247 | Refresh(child); |
289 | { | ||
290 | // Because it is a convenient time, recompute child world position and rotation based on | ||
291 | // its position in the linkset. | ||
292 | RecomputeChildWorldPosition(child, true /* inTaintTime */); | ||
293 | child.LinksetInfo = null; | ||
294 | } | ||
295 | |||
296 | // Cannot schedule a refresh/rebuild here because this routine is called when | ||
297 | // the linkset is being rebuilt. | ||
298 | // InternalRefresh(LinksetRoot); | ||
299 | 248 | ||
300 | return ret; | 249 | return ret; |
301 | } | 250 | } |
302 | 251 | ||
303 | // When the linkset is built, the child shape is added to the compound shape relative to the | ||
304 | // root shape. The linkset then moves around but this does not move the actual child | ||
305 | // prim. The child prim's location must be recomputed based on the location of the root shape. | ||
306 | private void RecomputeChildWorldPosition(BSPrimLinkable child, bool inTaintTime) | ||
307 | { | ||
308 | // For the moment (20130201), disable this computation (converting the child physical addr back to | ||
309 | // a region address) until we have a good handle on center-of-mass offsets and what the physics | ||
310 | // engine moving a child actually means. | ||
311 | // The simulator keeps track of where children should be as the linkset moves. Setting | ||
312 | // the pos/rot here does not effect that knowledge as there is no good way for the | ||
313 | // physics engine to send the simulator an update for a child. | ||
314 | |||
315 | /* | ||
316 | BSLinksetCompoundInfo lci = child.LinksetInfo as BSLinksetCompoundInfo; | ||
317 | if (lci != null) | ||
318 | { | ||
319 | if (inTaintTime) | ||
320 | { | ||
321 | OMV.Vector3 oldPos = child.RawPosition; | ||
322 | child.ForcePosition = LinksetRoot.RawPosition + lci.OffsetFromRoot; | ||
323 | child.ForceOrientation = LinksetRoot.RawOrientation * lci.OffsetRot; | ||
324 | DetailLog("{0},BSLinksetCompound.RecomputeChildWorldPosition,oldPos={1},lci={2},newPos={3}", | ||
325 | child.LocalID, oldPos, lci, child.RawPosition); | ||
326 | } | ||
327 | else | ||
328 | { | ||
329 | // TaintedObject is not used here so the raw position is set now and not at taint-time. | ||
330 | child.Position = LinksetRoot.RawPosition + lci.OffsetFromRoot; | ||
331 | child.Orientation = LinksetRoot.RawOrientation * lci.OffsetRot; | ||
332 | } | ||
333 | } | ||
334 | else | ||
335 | { | ||
336 | // This happens when children have been added to the linkset but the linkset | ||
337 | // has not been constructed yet. So like, at taint time, adding children to a linkset | ||
338 | // and then changing properties of the children (makePhysical, for instance) | ||
339 | // but the post-print action of actually rebuilding the linkset has not yet happened. | ||
340 | // PhysicsScene.Logger.WarnFormat("{0} Restoring linkset child position failed because of no relative position computed. ID={1}", | ||
341 | // LogHeader, child.LocalID); | ||
342 | DetailLog("{0},BSLinksetCompound.recomputeChildWorldPosition,noRelativePositonInfo", child.LocalID); | ||
343 | } | ||
344 | */ | ||
345 | } | ||
346 | |||
347 | // ================================================================ | 252 | // ================================================================ |
348 | 253 | ||
349 | // Add a new child to the linkset. | 254 | // Add a new child to the linkset. |
@@ -352,19 +257,19 @@ public sealed class BSLinksetCompound : BSLinkset | |||
352 | { | 257 | { |
353 | if (!HasChild(child)) | 258 | if (!HasChild(child)) |
354 | { | 259 | { |
355 | m_children.Add(child); | 260 | m_children.Add(child, new BSLinkInfo(child)); |
356 | 261 | ||
357 | DetailLog("{0},BSLinksetCompound.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID); | 262 | DetailLog("{0},BSLinksetCompound.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID); |
358 | 263 | ||
359 | // Rebuild the compound shape with the new child shape included | 264 | // Rebuild the compound shape with the new child shape included |
360 | ScheduleRebuild(child); | 265 | Refresh(child); |
361 | } | 266 | } |
362 | return; | 267 | return; |
363 | } | 268 | } |
364 | 269 | ||
365 | // Remove the specified child from the linkset. | 270 | // Remove the specified child from the linkset. |
366 | // Safe to call even if the child is not really in the linkset. | 271 | // Safe to call even if the child is not really in the linkset. |
367 | protected override void RemoveChildFromLinkset(BSPrimLinkable child) | 272 | protected override void RemoveChildFromLinkset(BSPrimLinkable child, bool inTaintTime) |
368 | { | 273 | { |
369 | child.ClearDisplacement(); | 274 | child.ClearDisplacement(); |
370 | 275 | ||
@@ -376,19 +281,17 @@ public sealed class BSLinksetCompound : BSLinkset | |||
376 | child.LocalID, child.PhysBody.AddrString); | 281 | child.LocalID, child.PhysBody.AddrString); |
377 | 282 | ||
378 | // Cause the child's body to be rebuilt and thus restored to normal operation | 283 | // Cause the child's body to be rebuilt and thus restored to normal operation |
379 | RecomputeChildWorldPosition(child, false); | 284 | child.ForceBodyShapeRebuild(inTaintTime); |
380 | child.LinksetInfo = null; | ||
381 | child.ForceBodyShapeRebuild(false); | ||
382 | 285 | ||
383 | if (!HasAnyChildren) | 286 | if (!HasAnyChildren) |
384 | { | 287 | { |
385 | // The linkset is now empty. The root needs rebuilding. | 288 | // The linkset is now empty. The root needs rebuilding. |
386 | LinksetRoot.ForceBodyShapeRebuild(false); | 289 | LinksetRoot.ForceBodyShapeRebuild(inTaintTime); |
387 | } | 290 | } |
388 | else | 291 | else |
389 | { | 292 | { |
390 | // Rebuild the compound shape with the child removed | 293 | // Rebuild the compound shape with the child removed |
391 | ScheduleRebuild(LinksetRoot); | 294 | Refresh(LinksetRoot); |
392 | } | 295 | } |
393 | } | 296 | } |
394 | return; | 297 | return; |
@@ -399,108 +302,118 @@ public sealed class BSLinksetCompound : BSLinkset | |||
399 | // Constraint linksets are rebuilt every time. | 302 | // Constraint linksets are rebuilt every time. |
400 | // Note that this works for rebuilding just the root after a linkset is taken apart. | 303 | // Note that this works for rebuilding just the root after a linkset is taken apart. |
401 | // Called at taint time!! | 304 | // Called at taint time!! |
402 | private bool disableCOM = true; // DEBUG DEBUG: disable until we get this debugged | 305 | private bool UseBulletSimRootOffsetHack = false; // Attempt to have Bullet track the coords of root compound shape |
403 | private void RecomputeLinksetCompound() | 306 | private void RecomputeLinksetCompound() |
404 | { | 307 | { |
405 | try | 308 | try |
406 | { | 309 | { |
407 | // Suppress rebuilding while rebuilding. (We know rebuilding is on only one thread.) | ||
408 | Rebuilding = true; | 310 | Rebuilding = true; |
409 | 311 | ||
410 | // Cause the root shape to be rebuilt as a compound object with just the root in it | 312 | // No matter what is being done, force the root prim's PhysBody and PhysShape to get set |
411 | LinksetRoot.ForceBodyShapeRebuild(true /* inTaintTime */); | 313 | // to what they should be as if the root was not in a linkset. |
314 | // Not that bad since we only get into this routine if there are children in the linkset and | ||
315 | // something has been updated/changed. | ||
316 | // Have to do the rebuild before checking for physical because this might be a linkset | ||
317 | // being destructed and going non-physical. | ||
318 | LinksetRoot.ForceBodyShapeRebuild(true); | ||
412 | 319 | ||
413 | // The center of mass for the linkset is the geometric center of the group. | 320 | // There is no reason to build all this physical stuff for a non-physical or empty linkset. |
414 | // Compute a displacement for each component so it is relative to the center-of-mass. | 321 | if (!LinksetRoot.IsPhysicallyActive || !HasAnyChildren) |
415 | // Bullet presumes an object's origin (relative <0,0,0>) is its center-of-mass | ||
416 | OMV.Vector3 centerOfMassW = LinksetRoot.RawPosition; | ||
417 | if (!disableCOM) // DEBUG DEBUG | ||
418 | { | 322 | { |
419 | // Compute a center-of-mass in world coordinates. | 323 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,notPhysicalOrNoChildren", LinksetRoot.LocalID); |
420 | centerOfMassW = ComputeLinksetCenterOfMass(); | 324 | return; // Note the 'finally' clause at the botton which will get executed. |
421 | } | 325 | } |
422 | 326 | ||
423 | OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(LinksetRoot.RawOrientation); | 327 | // Get a new compound shape to build the linkset shape in. |
424 | 328 | BSShape linksetShape = BSShapeCompound.GetReference(m_physicsScene); | |
425 | // 'centerDisplacement' is the value to subtract from children to give physical offset position | ||
426 | OMV.Vector3 centerDisplacement = (centerOfMassW - LinksetRoot.RawPosition) * invRootOrientation; | ||
427 | LinksetRoot.SetEffectiveCenterOfMassW(centerDisplacement); | ||
428 | 329 | ||
429 | // This causes the physical position of the root prim to be offset to accomodate for the displacements | 330 | // Compute a displacement for each component so it is relative to the center-of-mass. |
430 | LinksetRoot.ForcePosition = LinksetRoot.RawPosition; | 331 | // Bullet presumes an object's origin (relative <0,0,0>) is its center-of-mass |
332 | OMV.Vector3 centerOfMassW = ComputeLinksetCenterOfMass(); | ||
431 | 333 | ||
432 | // Update the local transform for the root child shape so it is offset from the <0,0,0> which is COM | 334 | OMV.Quaternion invRootOrientation = OMV.Quaternion.Normalize(OMV.Quaternion.Inverse(LinksetRoot.RawOrientation)); |
433 | PhysicsScene.PE.UpdateChildTransform(LinksetRoot.PhysShape, 0 /* childIndex */, | 335 | OMV.Vector3 origRootPosition = LinksetRoot.RawPosition; |
434 | -centerDisplacement, | ||
435 | OMV.Quaternion.Identity, // LinksetRoot.RawOrientation, | ||
436 | false /* shouldRecalculateLocalAabb (is done later after linkset built) */); | ||
437 | 336 | ||
438 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,COM,com={1},rootPos={2},centerDisp={3}", | 337 | // 'centerDisplacementV' is the vehicle relative distance from the simulator root position to the center-of-mass |
439 | LinksetRoot.LocalID, centerOfMassW, LinksetRoot.RawPosition, centerDisplacement); | 338 | OMV.Vector3 centerDisplacementV = (centerOfMassW - LinksetRoot.RawPosition) * invRootOrientation; |
339 | if (UseBulletSimRootOffsetHack || !BSParam.LinksetOffsetCenterOfMass) | ||
340 | { | ||
341 | // Zero everything if center-of-mass displacement is not being done. | ||
342 | centerDisplacementV = OMV.Vector3.Zero; | ||
343 | LinksetRoot.ClearDisplacement(); | ||
344 | } | ||
345 | else | ||
346 | { | ||
347 | // The actual center-of-mass could have been set by the user. | ||
348 | centerDisplacementV = LinksetRoot.SetEffectiveCenterOfMassDisplacement(centerDisplacementV); | ||
349 | } | ||
440 | 350 | ||
441 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,start,rBody={1},rShape={2},numChildren={3}", | 351 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,COM,rootPos={1},com={2},comDisp={3}", |
442 | LinksetRoot.LocalID, LinksetRoot.PhysBody, LinksetRoot.PhysShape, NumberOfChildren); | 352 | LinksetRoot.LocalID, origRootPosition, centerOfMassW, centerDisplacementV); |
443 | 353 | ||
444 | // Add a shape for each of the other children in the linkset | 354 | // Add the shapes of all the components of the linkset |
445 | int memberIndex = 1; | 355 | int memberIndex = 1; |
446 | ForEachMember(delegate(BSPrimLinkable cPrim) | 356 | ForEachMember((cPrim) => |
447 | { | 357 | { |
448 | if (IsRoot(cPrim)) | 358 | if (IsRoot(cPrim)) |
449 | { | 359 | { |
360 | // Root shape is always index zero. | ||
450 | cPrim.LinksetChildIndex = 0; | 361 | cPrim.LinksetChildIndex = 0; |
451 | } | 362 | } |
452 | else | 363 | else |
453 | { | 364 | { |
454 | cPrim.LinksetChildIndex = memberIndex; | 365 | cPrim.LinksetChildIndex = memberIndex; |
366 | memberIndex++; | ||
367 | } | ||
455 | 368 | ||
456 | if (cPrim.PhysShape.isNativeShape) | 369 | // Get a reference to the shape of the child for adding of that shape to the linkset compound shape |
457 | { | 370 | BSShape childShape = cPrim.PhysShape.GetReference(m_physicsScene, cPrim); |
458 | // A native shape is turned into a hull collision shape because native | ||
459 | // shapes are not shared so we have to hullify it so it will be tracked | ||
460 | // and freed at the correct time. This also solves the scaling problem | ||
461 | // (native shapes scale but hull/meshes are assumed to not be). | ||
462 | // TODO: decide of the native shape can just be used in the compound shape. | ||
463 | // Use call to CreateGeomNonSpecial(). | ||
464 | BulletShape saveShape = cPrim.PhysShape; | ||
465 | cPrim.PhysShape.Clear(); // Don't let the create free the child's shape | ||
466 | PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null); | ||
467 | BulletShape newShape = cPrim.PhysShape; | ||
468 | cPrim.PhysShape = saveShape; | ||
469 | |||
470 | OMV.Vector3 offsetPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation - centerDisplacement; | ||
471 | OMV.Quaternion offsetRot = cPrim.RawOrientation * invRootOrientation; | ||
472 | PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, newShape, offsetPos, offsetRot); | ||
473 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addNative,indx={1},rShape={2},cShape={3},offPos={4},offRot={5}", | ||
474 | LinksetRoot.LocalID, memberIndex, LinksetRoot.PhysShape, newShape, offsetPos, offsetRot); | ||
475 | } | ||
476 | else | ||
477 | { | ||
478 | // For the shared shapes (meshes and hulls), just use the shape in the child. | ||
479 | // The reference count added here will be decremented when the compound shape | ||
480 | // is destroyed in BSShapeCollection (the child shapes are looped over and dereferenced). | ||
481 | if (PhysicsScene.Shapes.ReferenceShape(cPrim.PhysShape)) | ||
482 | { | ||
483 | PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}", | ||
484 | LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape); | ||
485 | } | ||
486 | OMV.Vector3 offsetPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation - centerDisplacement; | ||
487 | OMV.Quaternion offsetRot = cPrim.RawOrientation * invRootOrientation; | ||
488 | PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, cPrim.PhysShape, offsetPos, offsetRot); | ||
489 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addNonNative,indx={1},rShape={2},cShape={3},offPos={4},offRot={5}", | ||
490 | LinksetRoot.LocalID, memberIndex, LinksetRoot.PhysShape, cPrim.PhysShape, offsetPos, offsetRot); | ||
491 | 371 | ||
492 | } | 372 | // Offset the child shape from the center-of-mass and rotate it to vehicle relative. |
493 | memberIndex++; | 373 | OMV.Vector3 offsetPos = (cPrim.RawPosition - origRootPosition) * invRootOrientation - centerDisplacementV; |
374 | OMV.Quaternion offsetRot = OMV.Quaternion.Normalize(cPrim.RawOrientation) * invRootOrientation; | ||
375 | |||
376 | // Add the child shape to the compound shape being built | ||
377 | m_physicsScene.PE.AddChildShapeToCompoundShape(linksetShape.physShapeInfo, childShape.physShapeInfo, offsetPos, offsetRot); | ||
378 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addChild,indx={1},cShape={2},offPos={3},offRot={4}", | ||
379 | LinksetRoot.LocalID, cPrim.LinksetChildIndex, childShape, offsetPos, offsetRot); | ||
380 | |||
381 | // Since we are borrowing the shape of the child, disable the origional child body | ||
382 | if (!IsRoot(cPrim)) | ||
383 | { | ||
384 | m_physicsScene.PE.AddToCollisionFlags(cPrim.PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE); | ||
385 | m_physicsScene.PE.ForceActivationState(cPrim.PhysBody, ActivationState.DISABLE_SIMULATION); | ||
386 | // We don't want collisions from the old linkset children. | ||
387 | m_physicsScene.PE.RemoveFromCollisionFlags(cPrim.PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | ||
388 | cPrim.PhysBody.collisionType = CollisionType.LinksetChild; | ||
494 | } | 389 | } |
390 | |||
495 | return false; // 'false' says to move onto the next child in the list | 391 | return false; // 'false' says to move onto the next child in the list |
496 | }); | 392 | }); |
497 | 393 | ||
394 | // Replace the root shape with the built compound shape. | ||
395 | // Object removed and added to world to get collision cache rebuilt for new shape. | ||
396 | LinksetRoot.PhysShape.Dereference(m_physicsScene); | ||
397 | LinksetRoot.PhysShape = linksetShape; | ||
398 | m_physicsScene.PE.RemoveObjectFromWorld(m_physicsScene.World, LinksetRoot.PhysBody); | ||
399 | m_physicsScene.PE.SetCollisionShape(m_physicsScene.World, LinksetRoot.PhysBody, linksetShape.physShapeInfo); | ||
400 | m_physicsScene.PE.AddObjectToWorld(m_physicsScene.World, LinksetRoot.PhysBody); | ||
401 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addBody,body={1},shape={2}", | ||
402 | LinksetRoot.LocalID, LinksetRoot.PhysBody, linksetShape); | ||
403 | |||
498 | // With all of the linkset packed into the root prim, it has the mass of everyone. | 404 | // With all of the linkset packed into the root prim, it has the mass of everyone. |
499 | LinksetMass = ComputeLinksetMass(); | 405 | LinksetMass = ComputeLinksetMass(); |
500 | LinksetRoot.UpdatePhysicalMassProperties(LinksetMass, true); | 406 | LinksetRoot.UpdatePhysicalMassProperties(LinksetMass, true); |
501 | 407 | ||
502 | // Enable the physical position updator to return the position and rotation of the root shape | 408 | if (UseBulletSimRootOffsetHack) |
503 | PhysicsScene.PE.AddToCollisionFlags(LinksetRoot.PhysBody, CollisionFlags.BS_RETURN_ROOT_COMPOUND_SHAPE); | 409 | { |
410 | // Enable the physical position updator to return the position and rotation of the root shape. | ||
411 | // This enables a feature in the C++ code to return the world coordinates of the first shape in the | ||
412 | // compound shape. This aleviates the need to offset the returned physical position by the | ||
413 | // center-of-mass offset. | ||
414 | // TODO: either debug this feature or remove it. | ||
415 | m_physicsScene.PE.AddToCollisionFlags(LinksetRoot.PhysBody, CollisionFlags.BS_RETURN_ROOT_COMPOUND_SHAPE); | ||
416 | } | ||
504 | } | 417 | } |
505 | finally | 418 | finally |
506 | { | 419 | { |
@@ -508,7 +421,7 @@ public sealed class BSLinksetCompound : BSLinkset | |||
508 | } | 421 | } |
509 | 422 | ||
510 | // See that the Aabb surrounds the new shape | 423 | // See that the Aabb surrounds the new shape |
511 | PhysicsScene.PE.RecalculateCompoundShapeLocalAabb(LinksetRoot.PhysShape); | 424 | m_physicsScene.PE.RecalculateCompoundShapeLocalAabb(LinksetRoot.PhysShape.physShapeInfo); |
512 | } | 425 | } |
513 | } | 426 | } |
514 | } \ No newline at end of file | 427 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs index 6d252ca..aaf92c8 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
@@ -28,6 +28,8 @@ using System; | |||
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.Text; | 29 | using System.Text; |
30 | 30 | ||
31 | using OpenSim.Region.OptionalModules.Scripting; | ||
32 | |||
31 | using OMV = OpenMetaverse; | 33 | using OMV = OpenMetaverse; |
32 | 34 | ||
33 | namespace OpenSim.Region.Physics.BulletSPlugin | 35 | namespace OpenSim.Region.Physics.BulletSPlugin |
@@ -36,26 +38,194 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
36 | { | 38 | { |
37 | // private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]"; | 39 | // private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]"; |
38 | 40 | ||
41 | public class BSLinkInfoConstraint : BSLinkInfo | ||
42 | { | ||
43 | public ConstraintType constraintType; | ||
44 | public BSConstraint constraint; | ||
45 | public OMV.Vector3 linearLimitLow; | ||
46 | public OMV.Vector3 linearLimitHigh; | ||
47 | public OMV.Vector3 angularLimitLow; | ||
48 | public OMV.Vector3 angularLimitHigh; | ||
49 | public bool useFrameOffset; | ||
50 | public bool enableTransMotor; | ||
51 | public float transMotorMaxVel; | ||
52 | public float transMotorMaxForce; | ||
53 | public float cfm; | ||
54 | public float erp; | ||
55 | public float solverIterations; | ||
56 | // | ||
57 | public OMV.Vector3 frameInAloc; | ||
58 | public OMV.Quaternion frameInArot; | ||
59 | public OMV.Vector3 frameInBloc; | ||
60 | public OMV.Quaternion frameInBrot; | ||
61 | public bool useLinearReferenceFrameA; | ||
62 | // Spring | ||
63 | public bool[] springAxisEnable; | ||
64 | public float[] springDamping; | ||
65 | public float[] springStiffness; | ||
66 | public OMV.Vector3 springLinearEquilibriumPoint; | ||
67 | public OMV.Vector3 springAngularEquilibriumPoint; | ||
68 | |||
69 | public BSLinkInfoConstraint(BSPrimLinkable pMember) | ||
70 | : base(pMember) | ||
71 | { | ||
72 | constraint = null; | ||
73 | ResetLink(); | ||
74 | member.PhysScene.DetailLog("{0},BSLinkInfoConstraint.creation", member.LocalID); | ||
75 | } | ||
76 | |||
77 | // Set all the parameters for this constraint to a fixed, non-movable constraint. | ||
78 | public override void ResetLink() | ||
79 | { | ||
80 | // constraintType = ConstraintType.D6_CONSTRAINT_TYPE; | ||
81 | constraintType = ConstraintType.FIXED_CONSTRAINT_TYPE; | ||
82 | linearLimitLow = OMV.Vector3.Zero; | ||
83 | linearLimitHigh = OMV.Vector3.Zero; | ||
84 | angularLimitLow = OMV.Vector3.Zero; | ||
85 | angularLimitHigh = OMV.Vector3.Zero; | ||
86 | useFrameOffset = BSParam.LinkConstraintUseFrameOffset; | ||
87 | enableTransMotor = BSParam.LinkConstraintEnableTransMotor; | ||
88 | transMotorMaxVel = BSParam.LinkConstraintTransMotorMaxVel; | ||
89 | transMotorMaxForce = BSParam.LinkConstraintTransMotorMaxForce; | ||
90 | cfm = BSParam.LinkConstraintCFM; | ||
91 | erp = BSParam.LinkConstraintERP; | ||
92 | solverIterations = BSParam.LinkConstraintSolverIterations; | ||
93 | frameInAloc = OMV.Vector3.Zero; | ||
94 | frameInArot = OMV.Quaternion.Identity; | ||
95 | frameInBloc = OMV.Vector3.Zero; | ||
96 | frameInBrot = OMV.Quaternion.Identity; | ||
97 | useLinearReferenceFrameA = true; | ||
98 | springAxisEnable = new bool[6]; | ||
99 | springDamping = new float[6]; | ||
100 | springStiffness = new float[6]; | ||
101 | for (int ii = 0; ii < springAxisEnable.Length; ii++) | ||
102 | { | ||
103 | springAxisEnable[ii] = false; | ||
104 | springDamping[ii] = BSAPITemplate.SPRING_NOT_SPECIFIED; | ||
105 | springStiffness[ii] = BSAPITemplate.SPRING_NOT_SPECIFIED; | ||
106 | } | ||
107 | springLinearEquilibriumPoint = OMV.Vector3.Zero; | ||
108 | springAngularEquilibriumPoint = OMV.Vector3.Zero; | ||
109 | member.PhysScene.DetailLog("{0},BSLinkInfoConstraint.ResetLink", member.LocalID); | ||
110 | } | ||
111 | |||
112 | // Given a constraint, apply the current constraint parameters to same. | ||
113 | public override void SetLinkParameters(BSConstraint constrain) | ||
114 | { | ||
115 | member.PhysScene.DetailLog("{0},BSLinkInfoConstraint.SetLinkParameters,type={1}", member.LocalID, constraintType); | ||
116 | switch (constraintType) | ||
117 | { | ||
118 | case ConstraintType.FIXED_CONSTRAINT_TYPE: | ||
119 | case ConstraintType.D6_CONSTRAINT_TYPE: | ||
120 | BSConstraint6Dof constrain6dof = constrain as BSConstraint6Dof; | ||
121 | if (constrain6dof != null) | ||
122 | { | ||
123 | // NOTE: D6_SPRING_CONSTRAINT_TYPE should be updated if you change any of this code. | ||
124 | // zero linear and angular limits makes the objects unable to move in relation to each other | ||
125 | constrain6dof.SetLinearLimits(linearLimitLow, linearLimitHigh); | ||
126 | constrain6dof.SetAngularLimits(angularLimitLow, angularLimitHigh); | ||
127 | |||
128 | // tweek the constraint to increase stability | ||
129 | constrain6dof.UseFrameOffset(useFrameOffset); | ||
130 | constrain6dof.TranslationalLimitMotor(enableTransMotor, transMotorMaxVel, transMotorMaxForce); | ||
131 | constrain6dof.SetCFMAndERP(cfm, erp); | ||
132 | if (solverIterations != 0f) | ||
133 | { | ||
134 | constrain6dof.SetSolverIterations(solverIterations); | ||
135 | } | ||
136 | } | ||
137 | break; | ||
138 | case ConstraintType.D6_SPRING_CONSTRAINT_TYPE: | ||
139 | BSConstraintSpring constrainSpring = constrain as BSConstraintSpring; | ||
140 | if (constrainSpring != null) | ||
141 | { | ||
142 | // zero linear and angular limits makes the objects unable to move in relation to each other | ||
143 | constrainSpring.SetLinearLimits(linearLimitLow, linearLimitHigh); | ||
144 | constrainSpring.SetAngularLimits(angularLimitLow, angularLimitHigh); | ||
145 | |||
146 | // tweek the constraint to increase stability | ||
147 | constrainSpring.UseFrameOffset(useFrameOffset); | ||
148 | constrainSpring.TranslationalLimitMotor(enableTransMotor, transMotorMaxVel, transMotorMaxForce); | ||
149 | constrainSpring.SetCFMAndERP(cfm, erp); | ||
150 | if (solverIterations != 0f) | ||
151 | { | ||
152 | constrainSpring.SetSolverIterations(solverIterations); | ||
153 | } | ||
154 | for (int ii = 0; ii < springAxisEnable.Length; ii++) | ||
155 | { | ||
156 | constrainSpring.SetAxisEnable(ii, springAxisEnable[ii]); | ||
157 | if (springDamping[ii] != BSAPITemplate.SPRING_NOT_SPECIFIED) | ||
158 | constrainSpring.SetDamping(ii, springDamping[ii]); | ||
159 | if (springStiffness[ii] != BSAPITemplate.SPRING_NOT_SPECIFIED) | ||
160 | constrainSpring.SetStiffness(ii, springStiffness[ii]); | ||
161 | } | ||
162 | constrainSpring.CalculateTransforms(); | ||
163 | |||
164 | if (springLinearEquilibriumPoint != OMV.Vector3.Zero) | ||
165 | constrainSpring.SetEquilibriumPoint(springLinearEquilibriumPoint, springAngularEquilibriumPoint); | ||
166 | else | ||
167 | constrainSpring.SetEquilibriumPoint(BSAPITemplate.SPRING_NOT_SPECIFIED, BSAPITemplate.SPRING_NOT_SPECIFIED); | ||
168 | } | ||
169 | break; | ||
170 | default: | ||
171 | break; | ||
172 | } | ||
173 | } | ||
174 | |||
175 | // Return 'true' if the property updates from the physics engine should be reported | ||
176 | // to the simulator. | ||
177 | // If the constraint is fixed, we don't need to report as the simulator and viewer will | ||
178 | // report the right things. | ||
179 | public override bool ShouldUpdateChildProperties() | ||
180 | { | ||
181 | bool ret = true; | ||
182 | if (constraintType == ConstraintType.FIXED_CONSTRAINT_TYPE) | ||
183 | ret = false; | ||
184 | |||
185 | return ret; | ||
186 | } | ||
187 | } | ||
188 | |||
39 | public BSLinksetConstraints(BSScene scene, BSPrimLinkable parent) : base(scene, parent) | 189 | public BSLinksetConstraints(BSScene scene, BSPrimLinkable parent) : base(scene, parent) |
40 | { | 190 | { |
191 | LinksetImpl = LinksetImplementation.Constraint; | ||
41 | } | 192 | } |
42 | 193 | ||
194 | private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINT]"; | ||
195 | |||
43 | // When physical properties are changed the linkset needs to recalculate | 196 | // When physical properties are changed the linkset needs to recalculate |
44 | // its internal properties. | 197 | // its internal properties. |
45 | // This is queued in the 'post taint' queue so the | 198 | // This is queued in the 'post taint' queue so the |
46 | // refresh will happen once after all the other taints are applied. | 199 | // refresh will happen once after all the other taints are applied. |
47 | public override void Refresh(BSPrimLinkable requestor) | 200 | public override void Refresh(BSPrimLinkable requestor) |
48 | { | 201 | { |
202 | ScheduleRebuild(requestor); | ||
49 | base.Refresh(requestor); | 203 | base.Refresh(requestor); |
50 | 204 | ||
51 | if (HasAnyChildren && IsRoot(requestor)) | 205 | } |
206 | |||
207 | private void ScheduleRebuild(BSPrimLinkable requestor) | ||
208 | { | ||
209 | DetailLog("{0},BSLinksetConstraint.ScheduleRebuild,,rebuilding={1},hasChildren={2},actuallyScheduling={3}", | ||
210 | requestor.LocalID, Rebuilding, HasAnyChildren, (!Rebuilding && HasAnyChildren)); | ||
211 | |||
212 | // When rebuilding, it is possible to set properties that would normally require a rebuild. | ||
213 | // If already rebuilding, don't request another rebuild. | ||
214 | // If a linkset with just a root prim (simple non-linked prim) don't bother rebuilding. | ||
215 | if (!Rebuilding && HasAnyChildren) | ||
52 | { | 216 | { |
53 | // Queue to happen after all the other taint processing | 217 | // Queue to happen after all the other taint processing |
54 | PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate() | 218 | m_physicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate() |
219 | { | ||
220 | if (HasAnyChildren) | ||
55 | { | 221 | { |
56 | if (HasAnyChildren && IsRoot(requestor)) | 222 | // Constraints that have not been changed are not rebuild but make sure |
57 | RecomputeLinksetConstraints(); | 223 | // the constraint of the requestor is rebuilt. |
58 | }); | 224 | PhysicallyUnlinkAChildFromRoot(LinksetRoot, requestor); |
225 | // Rebuild the linkset and all its constraints. | ||
226 | RecomputeLinksetConstraints(); | ||
227 | } | ||
228 | }); | ||
59 | } | 229 | } |
60 | } | 230 | } |
61 | 231 | ||
@@ -67,8 +237,14 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
67 | // Called at taint-time! | 237 | // Called at taint-time! |
68 | public override bool MakeDynamic(BSPrimLinkable child) | 238 | public override bool MakeDynamic(BSPrimLinkable child) |
69 | { | 239 | { |
70 | // What is done for each object in BSPrim is what we want. | 240 | bool ret = false; |
71 | return false; | 241 | DetailLog("{0},BSLinksetConstraints.MakeDynamic,call,IsRoot={1}", child.LocalID, IsRoot(child)); |
242 | if (IsRoot(child)) | ||
243 | { | ||
244 | // The root is going dynamic. Rebuild the linkset so parts and mass get computed properly. | ||
245 | Refresh(LinksetRoot); | ||
246 | } | ||
247 | return ret; | ||
72 | } | 248 | } |
73 | 249 | ||
74 | // The object is going static (non-physical). Do any setup necessary for a static linkset. | 250 | // The object is going static (non-physical). Do any setup necessary for a static linkset. |
@@ -78,8 +254,16 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
78 | // Called at taint-time! | 254 | // Called at taint-time! |
79 | public override bool MakeStatic(BSPrimLinkable child) | 255 | public override bool MakeStatic(BSPrimLinkable child) |
80 | { | 256 | { |
81 | // What is done for each object in BSPrim is what we want. | 257 | bool ret = false; |
82 | return false; | 258 | |
259 | DetailLog("{0},BSLinksetConstraint.MakeStatic,call,IsRoot={1}", child.LocalID, IsRoot(child)); | ||
260 | child.ClearDisplacement(); | ||
261 | if (IsRoot(child)) | ||
262 | { | ||
263 | // Schedule a rebuild to verify that the root shape is set to the real shape. | ||
264 | Refresh(LinksetRoot); | ||
265 | } | ||
266 | return ret; | ||
83 | } | 267 | } |
84 | 268 | ||
85 | // Called at taint-time!! | 269 | // Called at taint-time!! |
@@ -93,11 +277,11 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
93 | // up to rebuild the constraints before the next simulation step. | 277 | // up to rebuild the constraints before the next simulation step. |
94 | // Returns 'true' of something was actually removed and would need restoring | 278 | // Returns 'true' of something was actually removed and would need restoring |
95 | // Called at taint-time!! | 279 | // Called at taint-time!! |
96 | public override bool RemoveBodyDependencies(BSPrimLinkable child) | 280 | public override bool RemoveDependencies(BSPrimLinkable child) |
97 | { | 281 | { |
98 | bool ret = false; | 282 | bool ret = false; |
99 | 283 | ||
100 | DetailLog("{0},BSLinksetConstraint.RemoveBodyDependencies,removeChildrenForRoot,rID={1},rBody={2}", | 284 | DetailLog("{0},BSLinksetConstraint.RemoveDependencies,removeChildrenForRoot,rID={1},rBody={2}", |
101 | child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString); | 285 | child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString); |
102 | 286 | ||
103 | lock (m_linksetActivityLock) | 287 | lock (m_linksetActivityLock) |
@@ -118,7 +302,7 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
118 | { | 302 | { |
119 | if (!HasChild(child)) | 303 | if (!HasChild(child)) |
120 | { | 304 | { |
121 | m_children.Add(child); | 305 | m_children.Add(child, new BSLinkInfoConstraint(child)); |
122 | 306 | ||
123 | DetailLog("{0},BSLinksetConstraints.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID); | 307 | DetailLog("{0},BSLinksetConstraints.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID); |
124 | 308 | ||
@@ -130,7 +314,7 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
130 | 314 | ||
131 | // Remove the specified child from the linkset. | 315 | // Remove the specified child from the linkset. |
132 | // Safe to call even if the child is not really in my linkset. | 316 | // Safe to call even if the child is not really in my linkset. |
133 | protected override void RemoveChildFromLinkset(BSPrimLinkable child) | 317 | protected override void RemoveChildFromLinkset(BSPrimLinkable child, bool inTaintTime) |
134 | { | 318 | { |
135 | if (m_children.Remove(child)) | 319 | if (m_children.Remove(child)) |
136 | { | 320 | { |
@@ -142,7 +326,7 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
142 | rootx.LocalID, rootx.PhysBody.AddrString, | 326 | rootx.LocalID, rootx.PhysBody.AddrString, |
143 | childx.LocalID, childx.PhysBody.AddrString); | 327 | childx.LocalID, childx.PhysBody.AddrString); |
144 | 328 | ||
145 | PhysicsScene.TaintedObject("BSLinksetConstraints.RemoveChildFromLinkset", delegate() | 329 | m_physicsScene.TaintedObject(inTaintTime, childx.LocalID, "BSLinksetConstraints.RemoveChildFromLinkset", delegate() |
146 | { | 330 | { |
147 | PhysicallyUnlinkAChildFromRoot(rootx, childx); | 331 | PhysicallyUnlinkAChildFromRoot(rootx, childx); |
148 | }); | 332 | }); |
@@ -165,73 +349,86 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
165 | Refresh(rootPrim); | 349 | Refresh(rootPrim); |
166 | } | 350 | } |
167 | 351 | ||
168 | private BSConstraint BuildConstraint(BSPrimLinkable rootPrim, BSPrimLinkable childPrim) | 352 | // Create a static constraint between the two passed objects |
353 | private BSConstraint BuildConstraint(BSPrimLinkable rootPrim, BSLinkInfo li) | ||
169 | { | 354 | { |
355 | BSLinkInfoConstraint linkInfo = li as BSLinkInfoConstraint; | ||
356 | if (linkInfo == null) | ||
357 | return null; | ||
358 | |||
170 | // Zero motion for children so they don't interpolate | 359 | // Zero motion for children so they don't interpolate |
171 | childPrim.ZeroMotion(true); | 360 | li.member.ZeroMotion(true); |
172 | 361 | ||
173 | // Relative position normalized to the root prim | 362 | BSConstraint constrain = null; |
174 | // Essentually a vector pointing from center of rootPrim to center of childPrim | 363 | |
175 | OMV.Vector3 childRelativePosition = childPrim.Position - rootPrim.Position; | 364 | switch (linkInfo.constraintType) |
176 | |||
177 | // real world coordinate of midpoint between the two objects | ||
178 | OMV.Vector3 midPoint = rootPrim.Position + (childRelativePosition / 2); | ||
179 | |||
180 | DetailLog("{0},BSLinksetConstraint.BuildConstraint,taint,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6},midLoc={7}", | ||
181 | rootPrim.LocalID, | ||
182 | rootPrim.LocalID, rootPrim.PhysBody.AddrString, | ||
183 | childPrim.LocalID, childPrim.PhysBody.AddrString, | ||
184 | rootPrim.Position, childPrim.Position, midPoint); | ||
185 | |||
186 | // create a constraint that allows no freedom of movement between the two objects | ||
187 | // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818 | ||
188 | |||
189 | BSConstraint6Dof constrain = new BSConstraint6Dof( | ||
190 | PhysicsScene.World, rootPrim.PhysBody, childPrim.PhysBody, midPoint, true, true ); | ||
191 | // PhysicsScene.World, childPrim.BSBody, rootPrim.BSBody, midPoint, true, true ); | ||
192 | |||
193 | /* NOTE: below is an attempt to build constraint with full frame computation, etc. | ||
194 | * Using the midpoint is easier since it lets the Bullet code manipulate the transforms | ||
195 | * of the objects. | ||
196 | * Code left for future programmers. | ||
197 | // ================================================================================== | ||
198 | // relative position normalized to the root prim | ||
199 | OMV.Quaternion invThisOrientation = OMV.Quaternion.Inverse(rootPrim.Orientation); | ||
200 | OMV.Vector3 childRelativePosition = (childPrim.Position - rootPrim.Position) * invThisOrientation; | ||
201 | |||
202 | // relative rotation of the child to the parent | ||
203 | OMV.Quaternion childRelativeRotation = invThisOrientation * childPrim.Orientation; | ||
204 | OMV.Quaternion inverseChildRelativeRotation = OMV.Quaternion.Inverse(childRelativeRotation); | ||
205 | |||
206 | DetailLog("{0},BSLinksetConstraint.PhysicallyLinkAChildToRoot,taint,root={1},child={2}", rootPrim.LocalID, rootPrim.LocalID, childPrim.LocalID); | ||
207 | BS6DofConstraint constrain = new BS6DofConstraint( | ||
208 | PhysicsScene.World, rootPrim.Body, childPrim.Body, | ||
209 | OMV.Vector3.Zero, | ||
210 | OMV.Quaternion.Inverse(rootPrim.Orientation), | ||
211 | OMV.Vector3.Zero, | ||
212 | OMV.Quaternion.Inverse(childPrim.Orientation), | ||
213 | true, | ||
214 | true | ||
215 | ); | ||
216 | // ================================================================================== | ||
217 | */ | ||
218 | |||
219 | PhysicsScene.Constraints.AddConstraint(constrain); | ||
220 | |||
221 | // zero linear and angular limits makes the objects unable to move in relation to each other | ||
222 | constrain.SetLinearLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); | ||
223 | constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); | ||
224 | |||
225 | // tweek the constraint to increase stability | ||
226 | constrain.UseFrameOffset(BSParam.LinkConstraintUseFrameOffset); | ||
227 | constrain.TranslationalLimitMotor(BSParam.LinkConstraintEnableTransMotor, | ||
228 | BSParam.LinkConstraintTransMotorMaxVel, | ||
229 | BSParam.LinkConstraintTransMotorMaxForce); | ||
230 | constrain.SetCFMAndERP(BSParam.LinkConstraintCFM, BSParam.LinkConstraintERP); | ||
231 | if (BSParam.LinkConstraintSolverIterations != 0f) | ||
232 | { | 365 | { |
233 | constrain.SetSolverIterations(BSParam.LinkConstraintSolverIterations); | 366 | case ConstraintType.FIXED_CONSTRAINT_TYPE: |
367 | case ConstraintType.D6_CONSTRAINT_TYPE: | ||
368 | // Relative position normalized to the root prim | ||
369 | // Essentually a vector pointing from center of rootPrim to center of li.member | ||
370 | OMV.Vector3 childRelativePosition = linkInfo.member.Position - rootPrim.Position; | ||
371 | |||
372 | // real world coordinate of midpoint between the two objects | ||
373 | OMV.Vector3 midPoint = rootPrim.Position + (childRelativePosition / 2); | ||
374 | |||
375 | DetailLog("{0},BSLinksetConstraint.BuildConstraint,6Dof,rBody={1},cBody={2},rLoc={3},cLoc={4},midLoc={5}", | ||
376 | rootPrim.LocalID, rootPrim.PhysBody, linkInfo.member.PhysBody, | ||
377 | rootPrim.Position, linkInfo.member.Position, midPoint); | ||
378 | |||
379 | // create a constraint that allows no freedom of movement between the two objects | ||
380 | // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818 | ||
381 | |||
382 | constrain = new BSConstraint6Dof( | ||
383 | m_physicsScene.World, rootPrim.PhysBody, linkInfo.member.PhysBody, midPoint, true, true ); | ||
384 | |||
385 | /* NOTE: below is an attempt to build constraint with full frame computation, etc. | ||
386 | * Using the midpoint is easier since it lets the Bullet code manipulate the transforms | ||
387 | * of the objects. | ||
388 | * Code left for future programmers. | ||
389 | // ================================================================================== | ||
390 | // relative position normalized to the root prim | ||
391 | OMV.Quaternion invThisOrientation = OMV.Quaternion.Inverse(rootPrim.Orientation); | ||
392 | OMV.Vector3 childRelativePosition = (liConstraint.member.Position - rootPrim.Position) * invThisOrientation; | ||
393 | |||
394 | // relative rotation of the child to the parent | ||
395 | OMV.Quaternion childRelativeRotation = invThisOrientation * liConstraint.member.Orientation; | ||
396 | OMV.Quaternion inverseChildRelativeRotation = OMV.Quaternion.Inverse(childRelativeRotation); | ||
397 | |||
398 | DetailLog("{0},BSLinksetConstraint.PhysicallyLinkAChildToRoot,taint,root={1},child={2}", rootPrim.LocalID, rootPrim.LocalID, liConstraint.member.LocalID); | ||
399 | constrain = new BS6DofConstraint( | ||
400 | PhysicsScene.World, rootPrim.Body, liConstraint.member.Body, | ||
401 | OMV.Vector3.Zero, | ||
402 | OMV.Quaternion.Inverse(rootPrim.Orientation), | ||
403 | OMV.Vector3.Zero, | ||
404 | OMV.Quaternion.Inverse(liConstraint.member.Orientation), | ||
405 | true, | ||
406 | true | ||
407 | ); | ||
408 | // ================================================================================== | ||
409 | */ | ||
410 | |||
411 | break; | ||
412 | case ConstraintType.D6_SPRING_CONSTRAINT_TYPE: | ||
413 | constrain = new BSConstraintSpring(m_physicsScene.World, rootPrim.PhysBody, linkInfo.member.PhysBody, | ||
414 | linkInfo.frameInAloc, linkInfo.frameInArot, linkInfo.frameInBloc, linkInfo.frameInBrot, | ||
415 | linkInfo.useLinearReferenceFrameA, | ||
416 | true /*disableCollisionsBetweenLinkedBodies*/); | ||
417 | DetailLog("{0},BSLinksetConstraint.BuildConstraint,spring,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6}", | ||
418 | rootPrim.LocalID, | ||
419 | rootPrim.LocalID, rootPrim.PhysBody.AddrString, | ||
420 | linkInfo.member.LocalID, linkInfo.member.PhysBody.AddrString, | ||
421 | rootPrim.Position, linkInfo.member.Position); | ||
422 | |||
423 | break; | ||
424 | default: | ||
425 | break; | ||
234 | } | 426 | } |
427 | |||
428 | linkInfo.SetLinkParameters(constrain); | ||
429 | |||
430 | m_physicsScene.Constraints.AddConstraint(constrain); | ||
431 | |||
235 | return constrain; | 432 | return constrain; |
236 | } | 433 | } |
237 | 434 | ||
@@ -247,13 +444,22 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
247 | rootPrim.LocalID, rootPrim.PhysBody.AddrString, | 444 | rootPrim.LocalID, rootPrim.PhysBody.AddrString, |
248 | childPrim.LocalID, childPrim.PhysBody.AddrString); | 445 | childPrim.LocalID, childPrim.PhysBody.AddrString); |
249 | 446 | ||
250 | // Find the constraint for this link and get rid of it from the overall collection and from my list | 447 | // If asked to unlink root from root, just remove all the constraints |
251 | if (PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody)) | 448 | if (rootPrim == childPrim || childPrim == LinksetRoot) |
252 | { | 449 | { |
253 | // Make the child refresh its location | 450 | PhysicallyUnlinkAllChildrenFromRoot(LinksetRoot); |
254 | PhysicsScene.PE.PushUpdate(childPrim.PhysBody); | ||
255 | ret = true; | 451 | ret = true; |
256 | } | 452 | } |
453 | else | ||
454 | { | ||
455 | // Find the constraint for this link and get rid of it from the overall collection and from my list | ||
456 | if (m_physicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody)) | ||
457 | { | ||
458 | // Make the child refresh its location | ||
459 | m_physicsScene.PE.PushUpdate(childPrim.PhysBody); | ||
460 | ret = true; | ||
461 | } | ||
462 | } | ||
257 | 463 | ||
258 | return ret; | 464 | return ret; |
259 | } | 465 | } |
@@ -265,7 +471,7 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
265 | { | 471 | { |
266 | DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAllChildren,taint", rootPrim.LocalID); | 472 | DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAllChildren,taint", rootPrim.LocalID); |
267 | 473 | ||
268 | return PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody); | 474 | return m_physicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody); |
269 | } | 475 | } |
270 | 476 | ||
271 | // Call each of the constraints that make up this linkset and recompute the | 477 | // Call each of the constraints that make up this linkset and recompute the |
@@ -281,24 +487,360 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
281 | DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}", | 487 | DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}", |
282 | LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, linksetMass); | 488 | LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, linksetMass); |
283 | 489 | ||
284 | foreach (BSPrimLinkable child in m_children) | 490 | try |
285 | { | 491 | { |
286 | // A child in the linkset physically shows the mass of the whole linkset. | 492 | Rebuilding = true; |
287 | // This allows Bullet to apply enough force on the child to move the whole linkset. | ||
288 | // (Also do the mass stuff before recomputing the constraint so mass is not zero.) | ||
289 | child.UpdatePhysicalMassProperties(linksetMass, true); | ||
290 | 493 | ||
291 | BSConstraint constrain; | 494 | // There is no reason to build all this physical stuff for a non-physical linkset. |
292 | if (!PhysicsScene.Constraints.TryGetConstraint(LinksetRoot.PhysBody, child.PhysBody, out constrain)) | 495 | if (!LinksetRoot.IsPhysicallyActive || !HasAnyChildren) |
293 | { | 496 | { |
294 | // If constraint doesn't exist yet, create it. | 497 | DetailLog("{0},BSLinksetConstraint.RecomputeLinksetCompound,notPhysicalOrNoChildren", LinksetRoot.LocalID); |
295 | constrain = BuildConstraint(LinksetRoot, child); | 498 | return; // Note the 'finally' clause at the botton which will get executed. |
296 | } | 499 | } |
297 | constrain.RecomputeConstraintVariables(linksetMass); | ||
298 | 500 | ||
299 | // PhysicsScene.PE.DumpConstraint(PhysicsScene.World, constrain.Constraint); // DEBUG DEBUG | 501 | ForEachLinkInfo((li) => |
502 | { | ||
503 | // A child in the linkset physically shows the mass of the whole linkset. | ||
504 | // This allows Bullet to apply enough force on the child to move the whole linkset. | ||
505 | // (Also do the mass stuff before recomputing the constraint so mass is not zero.) | ||
506 | li.member.UpdatePhysicalMassProperties(linksetMass, true); | ||
507 | |||
508 | BSConstraint constrain; | ||
509 | if (!m_physicsScene.Constraints.TryGetConstraint(LinksetRoot.PhysBody, li.member.PhysBody, out constrain)) | ||
510 | { | ||
511 | // If constraint doesn't exist yet, create it. | ||
512 | constrain = BuildConstraint(LinksetRoot, li); | ||
513 | } | ||
514 | li.SetLinkParameters(constrain); | ||
515 | constrain.RecomputeConstraintVariables(linksetMass); | ||
516 | |||
517 | // PhysicsScene.PE.DumpConstraint(PhysicsScene.World, constrain.Constraint); // DEBUG DEBUG | ||
518 | return false; // 'false' says to keep processing other members | ||
519 | }); | ||
300 | } | 520 | } |
521 | finally | ||
522 | { | ||
523 | Rebuilding = false; | ||
524 | } | ||
525 | } | ||
301 | 526 | ||
527 | #region Extension | ||
528 | public override object Extension(string pFunct, params object[] pParams) | ||
529 | { | ||
530 | object ret = null; | ||
531 | switch (pFunct) | ||
532 | { | ||
533 | // pParams = [ BSPhysObject root, BSPhysObject child, integer linkType ] | ||
534 | case ExtendedPhysics.PhysFunctChangeLinkType: | ||
535 | if (pParams.Length > 2) | ||
536 | { | ||
537 | int requestedType = (int)pParams[2]; | ||
538 | DetailLog("{0},BSLinksetConstraint.ChangeLinkType,requestedType={1}", LinksetRoot.LocalID, requestedType); | ||
539 | if (requestedType == (int)ConstraintType.FIXED_CONSTRAINT_TYPE | ||
540 | || requestedType == (int)ConstraintType.D6_CONSTRAINT_TYPE | ||
541 | || requestedType == (int)ConstraintType.D6_SPRING_CONSTRAINT_TYPE | ||
542 | || requestedType == (int)ConstraintType.HINGE_CONSTRAINT_TYPE | ||
543 | || requestedType == (int)ConstraintType.CONETWIST_CONSTRAINT_TYPE | ||
544 | || requestedType == (int)ConstraintType.SLIDER_CONSTRAINT_TYPE) | ||
545 | { | ||
546 | BSPrimLinkable child = pParams[1] as BSPrimLinkable; | ||
547 | if (child != null) | ||
548 | { | ||
549 | DetailLog("{0},BSLinksetConstraint.ChangeLinkType,rootID={1},childID={2},type={3}", | ||
550 | LinksetRoot.LocalID, LinksetRoot.LocalID, child.LocalID, requestedType); | ||
551 | m_physicsScene.TaintedObject(child.LocalID, "BSLinksetConstraint.PhysFunctChangeLinkType", delegate() | ||
552 | { | ||
553 | // Pick up all the constraints currently created. | ||
554 | RemoveDependencies(child); | ||
555 | |||
556 | BSLinkInfo linkInfo = null; | ||
557 | if (TryGetLinkInfo(child, out linkInfo)) | ||
558 | { | ||
559 | BSLinkInfoConstraint linkInfoC = linkInfo as BSLinkInfoConstraint; | ||
560 | if (linkInfoC != null) | ||
561 | { | ||
562 | linkInfoC.constraintType = (ConstraintType)requestedType; | ||
563 | ret = (object)true; | ||
564 | DetailLog("{0},BSLinksetConstraint.ChangeLinkType,link={1},type={2}", | ||
565 | linkInfo.member.LocalID, linkInfo.member.LocalID, linkInfoC.constraintType); | ||
566 | } | ||
567 | else | ||
568 | { | ||
569 | DetailLog("{0},BSLinksetConstraint.ChangeLinkType,linkInfoNotConstraint,childID={1}", LinksetRoot.LocalID, child.LocalID); | ||
570 | } | ||
571 | } | ||
572 | else | ||
573 | { | ||
574 | DetailLog("{0},BSLinksetConstraint.ChangeLinkType,noLinkInfoForChild,childID={1}", LinksetRoot.LocalID, child.LocalID); | ||
575 | } | ||
576 | // Cause the whole linkset to be rebuilt in post-taint time. | ||
577 | Refresh(child); | ||
578 | }); | ||
579 | } | ||
580 | else | ||
581 | { | ||
582 | DetailLog("{0},BSLinksetConstraint.SetLinkType,childNotBSPrimLinkable", LinksetRoot.LocalID); | ||
583 | } | ||
584 | } | ||
585 | else | ||
586 | { | ||
587 | DetailLog("{0},BSLinksetConstraint.SetLinkType,illegalRequestedType,reqested={1},spring={2}", | ||
588 | LinksetRoot.LocalID, requestedType, ((int)ConstraintType.D6_SPRING_CONSTRAINT_TYPE)); | ||
589 | } | ||
590 | } | ||
591 | break; | ||
592 | // pParams = [ BSPhysObject root, BSPhysObject child ] | ||
593 | case ExtendedPhysics.PhysFunctGetLinkType: | ||
594 | if (pParams.Length > 0) | ||
595 | { | ||
596 | BSPrimLinkable child = pParams[1] as BSPrimLinkable; | ||
597 | if (child != null) | ||
598 | { | ||
599 | BSLinkInfo linkInfo = null; | ||
600 | if (TryGetLinkInfo(child, out linkInfo)) | ||
601 | { | ||
602 | BSLinkInfoConstraint linkInfoC = linkInfo as BSLinkInfoConstraint; | ||
603 | if (linkInfoC != null) | ||
604 | { | ||
605 | ret = (object)(int)linkInfoC.constraintType; | ||
606 | DetailLog("{0},BSLinksetConstraint.GetLinkType,link={1},type={2}", | ||
607 | linkInfo.member.LocalID, linkInfo.member.LocalID, linkInfoC.constraintType); | ||
608 | |||
609 | } | ||
610 | } | ||
611 | } | ||
612 | } | ||
613 | break; | ||
614 | // pParams = [ BSPhysObject root, BSPhysObject child, int op, object opParams, int op, object opParams, ... ] | ||
615 | case ExtendedPhysics.PhysFunctChangeLinkParams: | ||
616 | // There should be two parameters: the childActor and a list of parameters to set | ||
617 | if (pParams.Length > 2) | ||
618 | { | ||
619 | BSPrimLinkable child = pParams[1] as BSPrimLinkable; | ||
620 | BSLinkInfo baseLinkInfo = null; | ||
621 | if (TryGetLinkInfo(child, out baseLinkInfo)) | ||
622 | { | ||
623 | BSLinkInfoConstraint linkInfo = baseLinkInfo as BSLinkInfoConstraint; | ||
624 | if (linkInfo != null) | ||
625 | { | ||
626 | int valueInt; | ||
627 | float valueFloat; | ||
628 | bool valueBool; | ||
629 | OMV.Vector3 valueVector; | ||
630 | OMV.Vector3 valueVector2; | ||
631 | OMV.Quaternion valueQuaternion; | ||
632 | int axisLow, axisHigh; | ||
633 | |||
634 | int opIndex = 2; | ||
635 | while (opIndex < pParams.Length) | ||
636 | { | ||
637 | int thisOp = 0; | ||
638 | string errMsg = ""; | ||
639 | try | ||
640 | { | ||
641 | thisOp = (int)pParams[opIndex]; | ||
642 | DetailLog("{0},BSLinksetConstraint.ChangeLinkParams2,op={1},val={2}", | ||
643 | linkInfo.member.LocalID, thisOp, pParams[opIndex + 1]); | ||
644 | switch (thisOp) | ||
645 | { | ||
646 | case ExtendedPhysics.PHYS_PARAM_LINK_TYPE: | ||
647 | valueInt = (int)pParams[opIndex + 1]; | ||
648 | ConstraintType valueType = (ConstraintType)valueInt; | ||
649 | if (valueType == ConstraintType.FIXED_CONSTRAINT_TYPE | ||
650 | || valueType == ConstraintType.D6_CONSTRAINT_TYPE | ||
651 | || valueType == ConstraintType.D6_SPRING_CONSTRAINT_TYPE | ||
652 | || valueType == ConstraintType.HINGE_CONSTRAINT_TYPE | ||
653 | || valueType == ConstraintType.CONETWIST_CONSTRAINT_TYPE | ||
654 | || valueType == ConstraintType.SLIDER_CONSTRAINT_TYPE) | ||
655 | { | ||
656 | linkInfo.constraintType = valueType; | ||
657 | } | ||
658 | opIndex += 2; | ||
659 | break; | ||
660 | case ExtendedPhysics.PHYS_PARAM_FRAMEINA_LOC: | ||
661 | errMsg = "PHYS_PARAM_FRAMEINA_LOC takes one parameter of type vector"; | ||
662 | valueVector = (OMV.Vector3)pParams[opIndex + 1]; | ||
663 | linkInfo.frameInAloc = valueVector; | ||
664 | opIndex += 2; | ||
665 | break; | ||
666 | case ExtendedPhysics.PHYS_PARAM_FRAMEINA_ROT: | ||
667 | errMsg = "PHYS_PARAM_FRAMEINA_ROT takes one parameter of type rotation"; | ||
668 | valueQuaternion = (OMV.Quaternion)pParams[opIndex + 1]; | ||
669 | linkInfo.frameInArot = valueQuaternion; | ||
670 | opIndex += 2; | ||
671 | break; | ||
672 | case ExtendedPhysics.PHYS_PARAM_FRAMEINB_LOC: | ||
673 | errMsg = "PHYS_PARAM_FRAMEINB_LOC takes one parameter of type vector"; | ||
674 | valueVector = (OMV.Vector3)pParams[opIndex + 1]; | ||
675 | linkInfo.frameInBloc = valueVector; | ||
676 | opIndex += 2; | ||
677 | break; | ||
678 | case ExtendedPhysics.PHYS_PARAM_FRAMEINB_ROT: | ||
679 | errMsg = "PHYS_PARAM_FRAMEINB_ROT takes one parameter of type rotation"; | ||
680 | valueQuaternion = (OMV.Quaternion)pParams[opIndex + 1]; | ||
681 | linkInfo.frameInBrot = valueQuaternion; | ||
682 | opIndex += 2; | ||
683 | break; | ||
684 | case ExtendedPhysics.PHYS_PARAM_LINEAR_LIMIT_LOW: | ||
685 | errMsg = "PHYS_PARAM_LINEAR_LIMIT_LOW takes one parameter of type vector"; | ||
686 | valueVector = (OMV.Vector3)pParams[opIndex + 1]; | ||
687 | linkInfo.linearLimitLow = valueVector; | ||
688 | opIndex += 2; | ||
689 | break; | ||
690 | case ExtendedPhysics.PHYS_PARAM_LINEAR_LIMIT_HIGH: | ||
691 | errMsg = "PHYS_PARAM_LINEAR_LIMIT_HIGH takes one parameter of type vector"; | ||
692 | valueVector = (OMV.Vector3)pParams[opIndex + 1]; | ||
693 | linkInfo.linearLimitHigh = valueVector; | ||
694 | opIndex += 2; | ||
695 | break; | ||
696 | case ExtendedPhysics.PHYS_PARAM_ANGULAR_LIMIT_LOW: | ||
697 | errMsg = "PHYS_PARAM_ANGULAR_LIMIT_LOW takes one parameter of type vector"; | ||
698 | valueVector = (OMV.Vector3)pParams[opIndex + 1]; | ||
699 | linkInfo.angularLimitLow = valueVector; | ||
700 | opIndex += 2; | ||
701 | break; | ||
702 | case ExtendedPhysics.PHYS_PARAM_ANGULAR_LIMIT_HIGH: | ||
703 | errMsg = "PHYS_PARAM_ANGULAR_LIMIT_HIGH takes one parameter of type vector"; | ||
704 | valueVector = (OMV.Vector3)pParams[opIndex + 1]; | ||
705 | linkInfo.angularLimitHigh = valueVector; | ||
706 | opIndex += 2; | ||
707 | break; | ||
708 | case ExtendedPhysics.PHYS_PARAM_USE_FRAME_OFFSET: | ||
709 | errMsg = "PHYS_PARAM_USE_FRAME_OFFSET takes one parameter of type integer (bool)"; | ||
710 | valueBool = ((int)pParams[opIndex + 1]) != 0; | ||
711 | linkInfo.useFrameOffset = valueBool; | ||
712 | opIndex += 2; | ||
713 | break; | ||
714 | case ExtendedPhysics.PHYS_PARAM_ENABLE_TRANSMOTOR: | ||
715 | errMsg = "PHYS_PARAM_ENABLE_TRANSMOTOR takes one parameter of type integer (bool)"; | ||
716 | valueBool = ((int)pParams[opIndex + 1]) != 0; | ||
717 | linkInfo.enableTransMotor = valueBool; | ||
718 | opIndex += 2; | ||
719 | break; | ||
720 | case ExtendedPhysics.PHYS_PARAM_TRANSMOTOR_MAXVEL: | ||
721 | errMsg = "PHYS_PARAM_TRANSMOTOR_MAXVEL takes one parameter of type float"; | ||
722 | valueFloat = (float)pParams[opIndex + 1]; | ||
723 | linkInfo.transMotorMaxVel = valueFloat; | ||
724 | opIndex += 2; | ||
725 | break; | ||
726 | case ExtendedPhysics.PHYS_PARAM_TRANSMOTOR_MAXFORCE: | ||
727 | errMsg = "PHYS_PARAM_TRANSMOTOR_MAXFORCE takes one parameter of type float"; | ||
728 | valueFloat = (float)pParams[opIndex + 1]; | ||
729 | linkInfo.transMotorMaxForce = valueFloat; | ||
730 | opIndex += 2; | ||
731 | break; | ||
732 | case ExtendedPhysics.PHYS_PARAM_CFM: | ||
733 | errMsg = "PHYS_PARAM_CFM takes one parameter of type float"; | ||
734 | valueFloat = (float)pParams[opIndex + 1]; | ||
735 | linkInfo.cfm = valueFloat; | ||
736 | opIndex += 2; | ||
737 | break; | ||
738 | case ExtendedPhysics.PHYS_PARAM_ERP: | ||
739 | errMsg = "PHYS_PARAM_ERP takes one parameter of type float"; | ||
740 | valueFloat = (float)pParams[opIndex + 1]; | ||
741 | linkInfo.erp = valueFloat; | ||
742 | opIndex += 2; | ||
743 | break; | ||
744 | case ExtendedPhysics.PHYS_PARAM_SOLVER_ITERATIONS: | ||
745 | errMsg = "PHYS_PARAM_SOLVER_ITERATIONS takes one parameter of type float"; | ||
746 | valueFloat = (float)pParams[opIndex + 1]; | ||
747 | linkInfo.solverIterations = valueFloat; | ||
748 | opIndex += 2; | ||
749 | break; | ||
750 | case ExtendedPhysics.PHYS_PARAM_SPRING_AXIS_ENABLE: | ||
751 | errMsg = "PHYS_PARAM_SPRING_AXIS_ENABLE takes two parameters of types integer and integer (bool)"; | ||
752 | valueInt = (int)pParams[opIndex + 1]; | ||
753 | valueBool = ((int)pParams[opIndex + 2]) != 0; | ||
754 | GetAxisRange(valueInt, out axisLow, out axisHigh); | ||
755 | for (int ii = axisLow; ii <= axisHigh; ii++) | ||
756 | linkInfo.springAxisEnable[ii] = valueBool; | ||
757 | opIndex += 3; | ||
758 | break; | ||
759 | case ExtendedPhysics.PHYS_PARAM_SPRING_DAMPING: | ||
760 | errMsg = "PHYS_PARAM_SPRING_DAMPING takes two parameters of types integer and float"; | ||
761 | valueInt = (int)pParams[opIndex + 1]; | ||
762 | valueFloat = (float)pParams[opIndex + 2]; | ||
763 | GetAxisRange(valueInt, out axisLow, out axisHigh); | ||
764 | for (int ii = axisLow; ii <= axisHigh; ii++) | ||
765 | linkInfo.springDamping[ii] = valueFloat; | ||
766 | opIndex += 3; | ||
767 | break; | ||
768 | case ExtendedPhysics.PHYS_PARAM_SPRING_STIFFNESS: | ||
769 | errMsg = "PHYS_PARAM_SPRING_STIFFNESS takes two parameters of types integer and float"; | ||
770 | valueInt = (int)pParams[opIndex + 1]; | ||
771 | valueFloat = (float)pParams[opIndex + 2]; | ||
772 | GetAxisRange(valueInt, out axisLow, out axisHigh); | ||
773 | for (int ii = axisLow; ii <= axisHigh; ii++) | ||
774 | linkInfo.springStiffness[ii] = valueFloat; | ||
775 | opIndex += 3; | ||
776 | break; | ||
777 | case ExtendedPhysics.PHYS_PARAM_SPRING_EQUILIBRIUM_POINT: | ||
778 | errMsg = "PHYS_PARAM_SPRING_EQUILIBRIUM_POINT takes two parameters of type vector"; | ||
779 | valueVector = (OMV.Vector3)pParams[opIndex + 1]; | ||
780 | valueVector2 = (OMV.Vector3)pParams[opIndex + 2]; | ||
781 | linkInfo.springLinearEquilibriumPoint = valueVector; | ||
782 | linkInfo.springAngularEquilibriumPoint = valueVector2; | ||
783 | opIndex += 3; | ||
784 | break; | ||
785 | case ExtendedPhysics.PHYS_PARAM_USE_LINEAR_FRAMEA: | ||
786 | errMsg = "PHYS_PARAM_USE_LINEAR_FRAMEA takes one parameter of type integer (bool)"; | ||
787 | valueBool = ((int)pParams[opIndex + 1]) != 0; | ||
788 | linkInfo.useLinearReferenceFrameA = valueBool; | ||
789 | opIndex += 2; | ||
790 | break; | ||
791 | default: | ||
792 | break; | ||
793 | } | ||
794 | } | ||
795 | catch (InvalidCastException e) | ||
796 | { | ||
797 | m_physicsScene.Logger.WarnFormat("{0} value of wrong type in physSetLinksetParams: {1}, err={2}", | ||
798 | LogHeader, errMsg, e); | ||
799 | } | ||
800 | catch (Exception e) | ||
801 | { | ||
802 | m_physicsScene.Logger.WarnFormat("{0} bad parameters in physSetLinksetParams: {1}", LogHeader, e); | ||
803 | } | ||
804 | } | ||
805 | } | ||
806 | // Something changed so a rebuild is in order | ||
807 | Refresh(child); | ||
808 | } | ||
809 | } | ||
810 | break; | ||
811 | default: | ||
812 | ret = base.Extension(pFunct, pParams); | ||
813 | break; | ||
814 | } | ||
815 | return ret; | ||
816 | } | ||
817 | |||
818 | // Bullet constraints keep some limit parameters for each linear and angular axis. | ||
819 | // Setting same is easier if there is an easy way to see all or types. | ||
820 | // This routine returns the array limits for the set of axis. | ||
821 | private void GetAxisRange(int rangeSpec, out int low, out int high) | ||
822 | { | ||
823 | switch (rangeSpec) | ||
824 | { | ||
825 | case ExtendedPhysics.PHYS_AXIS_LINEAR_ALL: | ||
826 | low = 0; | ||
827 | high = 2; | ||
828 | break; | ||
829 | case ExtendedPhysics.PHYS_AXIS_ANGULAR_ALL: | ||
830 | low = 3; | ||
831 | high = 5; | ||
832 | break; | ||
833 | case ExtendedPhysics.PHYS_AXIS_ALL: | ||
834 | low = 0; | ||
835 | high = 5; | ||
836 | break; | ||
837 | default: | ||
838 | low = high = rangeSpec; | ||
839 | break; | ||
840 | } | ||
841 | return; | ||
302 | } | 842 | } |
843 | #endregion // Extension | ||
844 | |||
303 | } | 845 | } |
304 | } | 846 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs index 9501e2d..7693195 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | |||
@@ -65,13 +65,11 @@ public abstract class BSMotor | |||
65 | } | 65 | } |
66 | 66 | ||
67 | // Motor which moves CurrentValue to TargetValue over TimeScale seconds. | 67 | // Motor which moves CurrentValue to TargetValue over TimeScale seconds. |
68 | // The TargetValue decays in TargetValueDecayTimeScale and | 68 | // The TargetValue decays in TargetValueDecayTimeScale. |
69 | // the CurrentValue will be held back by FrictionTimeScale. | ||
70 | // This motor will "zero itself" over time in that the targetValue will | 69 | // This motor will "zero itself" over time in that the targetValue will |
71 | // decay to zero and the currentValue will follow it to that zero. | 70 | // decay to zero and the currentValue will follow it to that zero. |
72 | // The overall effect is for the returned correction value to go from large | 71 | // The overall effect is for the returned correction value to go from large |
73 | // values (the total difference between current and target minus friction) | 72 | // values to small and eventually zero values. |
74 | // to small and eventually zero values. | ||
75 | // TimeScale and TargetDelayTimeScale may be 'infinite' which means no decay. | 73 | // TimeScale and TargetDelayTimeScale may be 'infinite' which means no decay. |
76 | 74 | ||
77 | // For instance, if something is moving at speed X and the desired speed is Y, | 75 | // For instance, if something is moving at speed X and the desired speed is Y, |
@@ -88,7 +86,6 @@ public class BSVMotor : BSMotor | |||
88 | 86 | ||
89 | public virtual float TimeScale { get; set; } | 87 | public virtual float TimeScale { get; set; } |
90 | public virtual float TargetValueDecayTimeScale { get; set; } | 88 | public virtual float TargetValueDecayTimeScale { get; set; } |
91 | public virtual Vector3 FrictionTimescale { get; set; } | ||
92 | public virtual float Efficiency { get; set; } | 89 | public virtual float Efficiency { get; set; } |
93 | 90 | ||
94 | public virtual float ErrorZeroThreshold { get; set; } | 91 | public virtual float ErrorZeroThreshold { get; set; } |
@@ -102,7 +99,7 @@ public class BSVMotor : BSMotor | |||
102 | return ErrorIsZero(LastError); | 99 | return ErrorIsZero(LastError); |
103 | } | 100 | } |
104 | public virtual bool ErrorIsZero(Vector3 err) | 101 | public virtual bool ErrorIsZero(Vector3 err) |
105 | { | 102 | { |
106 | return (err == Vector3.Zero || err.ApproxEquals(Vector3.Zero, ErrorZeroThreshold)); | 103 | return (err == Vector3.Zero || err.ApproxEquals(Vector3.Zero, ErrorZeroThreshold)); |
107 | } | 104 | } |
108 | 105 | ||
@@ -111,16 +108,14 @@ public class BSVMotor : BSMotor | |||
111 | { | 108 | { |
112 | TimeScale = TargetValueDecayTimeScale = BSMotor.Infinite; | 109 | TimeScale = TargetValueDecayTimeScale = BSMotor.Infinite; |
113 | Efficiency = 1f; | 110 | Efficiency = 1f; |
114 | FrictionTimescale = BSMotor.InfiniteVector; | ||
115 | CurrentValue = TargetValue = Vector3.Zero; | 111 | CurrentValue = TargetValue = Vector3.Zero; |
116 | ErrorZeroThreshold = 0.001f; | 112 | ErrorZeroThreshold = 0.001f; |
117 | } | 113 | } |
118 | public BSVMotor(string useName, float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency) | 114 | public BSVMotor(string useName, float timeScale, float decayTimeScale, float efficiency) |
119 | : this(useName) | 115 | : this(useName) |
120 | { | 116 | { |
121 | TimeScale = timeScale; | 117 | TimeScale = timeScale; |
122 | TargetValueDecayTimeScale = decayTimeScale; | 118 | TargetValueDecayTimeScale = decayTimeScale; |
123 | FrictionTimescale = frictionTimeScale; | ||
124 | Efficiency = efficiency; | 119 | Efficiency = efficiency; |
125 | CurrentValue = TargetValue = Vector3.Zero; | 120 | CurrentValue = TargetValue = Vector3.Zero; |
126 | } | 121 | } |
@@ -149,7 +144,6 @@ public class BSVMotor : BSMotor | |||
149 | 144 | ||
150 | Vector3 correction = Vector3.Zero; | 145 | Vector3 correction = Vector3.Zero; |
151 | Vector3 error = TargetValue - CurrentValue; | 146 | Vector3 error = TargetValue - CurrentValue; |
152 | LastError = error; | ||
153 | if (!ErrorIsZero(error)) | 147 | if (!ErrorIsZero(error)) |
154 | { | 148 | { |
155 | correction = StepError(timeStep, error); | 149 | correction = StepError(timeStep, error); |
@@ -165,26 +159,11 @@ public class BSVMotor : BSMotor | |||
165 | TargetValue *= (1f - decayFactor); | 159 | TargetValue *= (1f - decayFactor); |
166 | } | 160 | } |
167 | 161 | ||
168 | // The amount we can correct the error is reduced by the friction | ||
169 | Vector3 frictionFactor = Vector3.Zero; | ||
170 | if (FrictionTimescale != BSMotor.InfiniteVector) | ||
171 | { | ||
172 | // frictionFactor = (Vector3.One / FrictionTimescale) * timeStep; | ||
173 | // Individual friction components can be 'infinite' so compute each separately. | ||
174 | frictionFactor.X = (FrictionTimescale.X == BSMotor.Infinite) ? 0f : (1f / FrictionTimescale.X); | ||
175 | frictionFactor.Y = (FrictionTimescale.Y == BSMotor.Infinite) ? 0f : (1f / FrictionTimescale.Y); | ||
176 | frictionFactor.Z = (FrictionTimescale.Z == BSMotor.Infinite) ? 0f : (1f / FrictionTimescale.Z); | ||
177 | frictionFactor *= timeStep; | ||
178 | CurrentValue *= (Vector3.One - frictionFactor); | ||
179 | } | ||
180 | |||
181 | MDetailLog("{0}, BSVMotor.Step,nonZero,{1},origCurr={2},origTarget={3},timeStep={4},err={5},corr={6}", | 162 | MDetailLog("{0}, BSVMotor.Step,nonZero,{1},origCurr={2},origTarget={3},timeStep={4},err={5},corr={6}", |
182 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, | 163 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, |
183 | timeStep, error, correction); | 164 | timeStep, error, correction); |
184 | MDetailLog("{0}, BSVMotor.Step,nonZero,{1},tgtDecayTS={2},decayFact={3},frictTS={4},frictFact={5},tgt={6},curr={7}", | 165 | MDetailLog("{0}, BSVMotor.Step,nonZero,{1},tgtDecayTS={2},decayFact={3},tgt={4},curr={5}", |
185 | BSScene.DetailLogZero, UseName, | 166 | BSScene.DetailLogZero, UseName, TargetValueDecayTimeScale, decayFactor, TargetValue, CurrentValue); |
186 | TargetValueDecayTimeScale, decayFactor, FrictionTimescale, frictionFactor, | ||
187 | TargetValue, CurrentValue); | ||
188 | } | 167 | } |
189 | else | 168 | else |
190 | { | 169 | { |
@@ -199,6 +178,7 @@ public class BSVMotor : BSMotor | |||
199 | MDetailLog("{0}, BSVMotor.Step,zero,{1},origTgt={2},origCurr={3},currTgt={4},currCurr={5}", | 178 | MDetailLog("{0}, BSVMotor.Step,zero,{1},origTgt={2},origCurr={3},currTgt={4},currCurr={5}", |
200 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, TargetValue, CurrentValue); | 179 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, TargetValue, CurrentValue); |
201 | } | 180 | } |
181 | LastError = error; | ||
202 | 182 | ||
203 | return correction; | 183 | return correction; |
204 | } | 184 | } |
@@ -208,6 +188,8 @@ public class BSVMotor : BSMotor | |||
208 | CurrentValue = current; | 188 | CurrentValue = current; |
209 | return Step(timeStep); | 189 | return Step(timeStep); |
210 | } | 190 | } |
191 | // Given and error, computer a correction for this step. | ||
192 | // Simple scaling of the error by the timestep. | ||
211 | public virtual Vector3 StepError(float timeStep, Vector3 error) | 193 | public virtual Vector3 StepError(float timeStep, Vector3 error) |
212 | { | 194 | { |
213 | if (!Enabled) return Vector3.Zero; | 195 | if (!Enabled) return Vector3.Zero; |
@@ -235,27 +217,27 @@ public class BSVMotor : BSMotor | |||
235 | // maximum number of outputs to generate. | 217 | // maximum number of outputs to generate. |
236 | int maxOutput = 50; | 218 | int maxOutput = 50; |
237 | MDetailLog("{0},BSVMotor.Test,{1},===================================== BEGIN Test Output", BSScene.DetailLogZero, UseName); | 219 | MDetailLog("{0},BSVMotor.Test,{1},===================================== BEGIN Test Output", BSScene.DetailLogZero, UseName); |
238 | MDetailLog("{0},BSVMotor.Test,{1},timeScale={2},targDlyTS={3},frictTS={4},eff={5},curr={6},tgt={7}", | 220 | MDetailLog("{0},BSVMotor.Test,{1},timeScale={2},targDlyTS={3},eff={4},curr={5},tgt={6}", |
239 | BSScene.DetailLogZero, UseName, | 221 | BSScene.DetailLogZero, UseName, |
240 | TimeScale, TargetValueDecayTimeScale, FrictionTimescale, Efficiency, | 222 | TimeScale, TargetValueDecayTimeScale, Efficiency, |
241 | CurrentValue, TargetValue); | 223 | CurrentValue, TargetValue); |
242 | 224 | ||
243 | LastError = BSMotor.InfiniteVector; | 225 | LastError = BSMotor.InfiniteVector; |
244 | while (maxOutput-- > 0 && !LastError.ApproxEquals(Vector3.Zero, ErrorZeroThreshold)) | 226 | while (maxOutput-- > 0 && !ErrorIsZero()) |
245 | { | 227 | { |
246 | Vector3 lastStep = Step(timeStep); | 228 | Vector3 lastStep = Step(timeStep); |
247 | MDetailLog("{0},BSVMotor.Test,{1},cur={2},tgt={3},lastError={4},lastStep={5}", | 229 | MDetailLog("{0},BSVMotor.Test,{1},cur={2},tgt={3},lastError={4},lastStep={5}", |
248 | BSScene.DetailLogZero, UseName, CurrentValue, TargetValue, LastError, lastStep); | 230 | BSScene.DetailLogZero, UseName, CurrentValue, TargetValue, LastError, lastStep); |
249 | } | 231 | } |
250 | MDetailLog("{0},BSVMotor.Test,{1},===================================== END Test Output", BSScene.DetailLogZero, UseName); | 232 | MDetailLog("{0},BSVMotor.Test,{1},===================================== END Test Output", BSScene.DetailLogZero, UseName); |
251 | 233 | ||
252 | 234 | ||
253 | } | 235 | } |
254 | 236 | ||
255 | public override string ToString() | 237 | public override string ToString() |
256 | { | 238 | { |
257 | return String.Format("<{0},curr={1},targ={2},lastErr={3},decayTS={4},frictTS={5}>", | 239 | return String.Format("<{0},curr={1},targ={2},lastErr={3},decayTS={4}>", |
258 | UseName, CurrentValue, TargetValue, LastError, TargetValueDecayTimeScale, FrictionTimescale); | 240 | UseName, CurrentValue, TargetValue, LastError, TargetValueDecayTimeScale); |
259 | } | 241 | } |
260 | } | 242 | } |
261 | 243 | ||
@@ -265,7 +247,6 @@ public class BSFMotor : BSMotor | |||
265 | { | 247 | { |
266 | public virtual float TimeScale { get; set; } | 248 | public virtual float TimeScale { get; set; } |
267 | public virtual float TargetValueDecayTimeScale { get; set; } | 249 | public virtual float TargetValueDecayTimeScale { get; set; } |
268 | public virtual float FrictionTimescale { get; set; } | ||
269 | public virtual float Efficiency { get; set; } | 250 | public virtual float Efficiency { get; set; } |
270 | 251 | ||
271 | public virtual float ErrorZeroThreshold { get; set; } | 252 | public virtual float ErrorZeroThreshold { get; set; } |
@@ -279,16 +260,15 @@ public class BSFMotor : BSMotor | |||
279 | return ErrorIsZero(LastError); | 260 | return ErrorIsZero(LastError); |
280 | } | 261 | } |
281 | public virtual bool ErrorIsZero(float err) | 262 | public virtual bool ErrorIsZero(float err) |
282 | { | 263 | { |
283 | return (err >= -ErrorZeroThreshold && err <= ErrorZeroThreshold); | 264 | return (err >= -ErrorZeroThreshold && err <= ErrorZeroThreshold); |
284 | } | 265 | } |
285 | 266 | ||
286 | public BSFMotor(string useName, float timeScale, float decayTimescale, float friction, float efficiency) | 267 | public BSFMotor(string useName, float timeScale, float decayTimescale, float efficiency) |
287 | : base(useName) | 268 | : base(useName) |
288 | { | 269 | { |
289 | TimeScale = TargetValueDecayTimeScale = BSMotor.Infinite; | 270 | TimeScale = TargetValueDecayTimeScale = BSMotor.Infinite; |
290 | Efficiency = 1f; | 271 | Efficiency = 1f; |
291 | FrictionTimescale = BSMotor.Infinite; | ||
292 | CurrentValue = TargetValue = 0f; | 272 | CurrentValue = TargetValue = 0f; |
293 | ErrorZeroThreshold = 0.01f; | 273 | ErrorZeroThreshold = 0.01f; |
294 | } | 274 | } |
@@ -315,7 +295,6 @@ public class BSFMotor : BSMotor | |||
315 | 295 | ||
316 | float correction = 0f; | 296 | float correction = 0f; |
317 | float error = TargetValue - CurrentValue; | 297 | float error = TargetValue - CurrentValue; |
318 | LastError = error; | ||
319 | if (!ErrorIsZero(error)) | 298 | if (!ErrorIsZero(error)) |
320 | { | 299 | { |
321 | correction = StepError(timeStep, error); | 300 | correction = StepError(timeStep, error); |
@@ -331,24 +310,11 @@ public class BSFMotor : BSMotor | |||
331 | TargetValue *= (1f - decayFactor); | 310 | TargetValue *= (1f - decayFactor); |
332 | } | 311 | } |
333 | 312 | ||
334 | // The amount we can correct the error is reduced by the friction | ||
335 | float frictionFactor = 0f; | ||
336 | if (FrictionTimescale != BSMotor.Infinite) | ||
337 | { | ||
338 | // frictionFactor = (Vector3.One / FrictionTimescale) * timeStep; | ||
339 | // Individual friction components can be 'infinite' so compute each separately. | ||
340 | frictionFactor = 1f / FrictionTimescale; | ||
341 | frictionFactor *= timeStep; | ||
342 | CurrentValue *= (1f - frictionFactor); | ||
343 | } | ||
344 | |||
345 | MDetailLog("{0}, BSFMotor.Step,nonZero,{1},origCurr={2},origTarget={3},timeStep={4},err={5},corr={6}", | 313 | MDetailLog("{0}, BSFMotor.Step,nonZero,{1},origCurr={2},origTarget={3},timeStep={4},err={5},corr={6}", |
346 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, | 314 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, |
347 | timeStep, error, correction); | 315 | timeStep, error, correction); |
348 | MDetailLog("{0}, BSFMotor.Step,nonZero,{1},tgtDecayTS={2},decayFact={3},frictTS={4},frictFact={5},tgt={6},curr={7}", | 316 | MDetailLog("{0}, BSFMotor.Step,nonZero,{1},tgtDecayTS={2},decayFact={3},tgt={4},curr={5}", |
349 | BSScene.DetailLogZero, UseName, | 317 | BSScene.DetailLogZero, UseName, TargetValueDecayTimeScale, decayFactor, TargetValue, CurrentValue); |
350 | TargetValueDecayTimeScale, decayFactor, FrictionTimescale, frictionFactor, | ||
351 | TargetValue, CurrentValue); | ||
352 | } | 318 | } |
353 | else | 319 | else |
354 | { | 320 | { |
@@ -363,6 +329,7 @@ public class BSFMotor : BSMotor | |||
363 | MDetailLog("{0}, BSFMotor.Step,zero,{1},origTgt={2},origCurr={3},ret={4}", | 329 | MDetailLog("{0}, BSFMotor.Step,zero,{1},origTgt={2},origCurr={3},ret={4}", |
364 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, CurrentValue); | 330 | BSScene.DetailLogZero, UseName, origCurrVal, origTarget, CurrentValue); |
365 | } | 331 | } |
332 | LastError = error; | ||
366 | 333 | ||
367 | return CurrentValue; | 334 | return CurrentValue; |
368 | } | 335 | } |
@@ -390,15 +357,15 @@ public class BSFMotor : BSMotor | |||
390 | 357 | ||
391 | public override string ToString() | 358 | public override string ToString() |
392 | { | 359 | { |
393 | return String.Format("<{0},curr={1},targ={2},lastErr={3},decayTS={4},frictTS={5}>", | 360 | return String.Format("<{0},curr={1},targ={2},lastErr={3},decayTS={4}>", |
394 | UseName, CurrentValue, TargetValue, LastError, TargetValueDecayTimeScale, FrictionTimescale); | 361 | UseName, CurrentValue, TargetValue, LastError, TargetValueDecayTimeScale); |
395 | } | 362 | } |
396 | 363 | ||
397 | } | 364 | } |
398 | 365 | ||
399 | // ============================================================================ | 366 | // ============================================================================ |
400 | // ============================================================================ | 367 | // ============================================================================ |
401 | // Proportional, Integral, Derivitive Motor | 368 | // Proportional, Integral, Derivitive ("PID") Motor |
402 | // Good description at http://www.answers.com/topic/pid-controller . Includes processes for choosing p, i and d factors. | 369 | // Good description at http://www.answers.com/topic/pid-controller . Includes processes for choosing p, i and d factors. |
403 | public class BSPIDVMotor : BSVMotor | 370 | public class BSPIDVMotor : BSVMotor |
404 | { | 371 | { |
@@ -410,7 +377,6 @@ public class BSPIDVMotor : BSVMotor | |||
410 | // The factors are vectors for the three dimensions. This is the proportional of each | 377 | // The factors are vectors for the three dimensions. This is the proportional of each |
411 | // that is applied. This could be multiplied through the actual factors but it | 378 | // that is applied. This could be multiplied through the actual factors but it |
412 | // is sometimes easier to manipulate the factors and their mix separately. | 379 | // is sometimes easier to manipulate the factors and their mix separately. |
413 | // to | ||
414 | public Vector3 FactorMix; | 380 | public Vector3 FactorMix; |
415 | 381 | ||
416 | // Arbritrary factor range. | 382 | // Arbritrary factor range. |
@@ -448,14 +414,14 @@ public class BSPIDVMotor : BSVMotor | |||
448 | // If efficiency is high (1f), use a factor value that moves the error value to zero with little overshoot. | 414 | // If efficiency is high (1f), use a factor value that moves the error value to zero with little overshoot. |
449 | // If efficiency is low (0f), use a factor value that overcorrects. | 415 | // If efficiency is low (0f), use a factor value that overcorrects. |
450 | // TODO: might want to vary contribution of different factor depending on efficiency. | 416 | // TODO: might want to vary contribution of different factor depending on efficiency. |
451 | float factor = ((1f - this.Efficiency) * EfficiencyHigh + EfficiencyLow) / 3f; | 417 | // float factor = ((1f - this.Efficiency) * EfficiencyHigh + EfficiencyLow) / 3f; |
452 | // float factor = (1f - this.Efficiency) * EfficiencyHigh + EfficiencyLow; | 418 | float factor = (1f - this.Efficiency) * EfficiencyHigh + EfficiencyLow; |
453 | 419 | ||
454 | proportionFactor = new Vector3(factor, factor, factor); | 420 | proportionFactor = new Vector3(factor, factor, factor); |
455 | integralFactor = new Vector3(factor, factor, factor); | 421 | integralFactor = new Vector3(factor, factor, factor); |
456 | derivFactor = new Vector3(factor, factor, factor); | 422 | derivFactor = new Vector3(factor, factor, factor); |
457 | 423 | ||
458 | MDetailLog("{0},BSPIDVMotor.setEfficiency,eff={1},factor={2}", BSScene.DetailLogZero, Efficiency, factor); | 424 | MDetailLog("{0}, BSPIDVMotor.setEfficiency,eff={1},factor={2}", BSScene.DetailLogZero, Efficiency, factor); |
459 | } | 425 | } |
460 | } | 426 | } |
461 | 427 | ||
@@ -469,16 +435,15 @@ public class BSPIDVMotor : BSVMotor | |||
469 | 435 | ||
470 | // A simple derivitive is the rate of change from the last error. | 436 | // A simple derivitive is the rate of change from the last error. |
471 | Vector3 derivitive = (error - LastError) * timeStep; | 437 | Vector3 derivitive = (error - LastError) * timeStep; |
472 | LastError = error; | ||
473 | 438 | ||
474 | // Correction = (proportionOfPresentError + accumulationOfPastError + rateOfChangeOfError) | 439 | // Correction = (proportionOfPresentError + accumulationOfPastError + rateOfChangeOfError) |
475 | Vector3 ret = error * timeStep * proportionFactor * FactorMix.X | 440 | Vector3 ret = error / TimeScale * timeStep * proportionFactor * FactorMix.X |
476 | + RunningIntegration * integralFactor * FactorMix.Y | 441 | + RunningIntegration / TimeScale * integralFactor * FactorMix.Y |
477 | + derivitive * derivFactor * FactorMix.Z | 442 | + derivitive / TimeScale * derivFactor * FactorMix.Z |
478 | ; | 443 | ; |
479 | 444 | ||
480 | MDetailLog("{0},BSPIDVMotor.step,ts={1},err={2},runnInt={3},deriv={4},ret={5}", | 445 | MDetailLog("{0}, BSPIDVMotor.step,ts={1},err={2},lerr={3},runnInt={4},deriv={5},ret={6}", |
481 | BSScene.DetailLogZero, timeStep, error, RunningIntegration, derivitive, ret); | 446 | BSScene.DetailLogZero, timeStep, error, LastError, RunningIntegration, derivitive, ret); |
482 | 447 | ||
483 | return ret; | 448 | return ret; |
484 | } | 449 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index 385ed9e..834228e 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | using System; | 27 | using System; |
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.Reflection; | ||
29 | using System.Text; | 30 | using System.Text; |
30 | 31 | ||
31 | using OpenSim.Region.Physics.Manager; | 32 | using OpenSim.Region.Physics.Manager; |
@@ -37,7 +38,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
37 | { | 38 | { |
38 | public static class BSParam | 39 | public static class BSParam |
39 | { | 40 | { |
40 | private static string LogHeader = "[BULLETSIM PARAMETERS]"; | 41 | private static string LogHeader = "[BULLETSIM PARAMETERS]"; |
41 | 42 | ||
42 | // Tuning notes: | 43 | // Tuning notes: |
43 | // From: http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=6575 | 44 | // From: http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=6575 |
@@ -51,7 +52,10 @@ public static class BSParam | |||
51 | // This is separate/independent from the collision margin. The collision margin increases the object a bit | 52 | // This is separate/independent from the collision margin. The collision margin increases the object a bit |
52 | // to improve collision detection performance and accuracy. | 53 | // to improve collision detection performance and accuracy. |
53 | // =================== | 54 | // =================== |
54 | // From: | 55 | // From: |
56 | |||
57 | public static bool UseSeparatePhysicsThread { get; private set; } | ||
58 | public static float PhysicsTimeStep { get; private set; } | ||
55 | 59 | ||
56 | // Level of Detail values kept as float because that's what the Meshmerizer wants | 60 | // Level of Detail values kept as float because that's what the Meshmerizer wants |
57 | public static float MeshLOD { get; private set; } | 61 | public static float MeshLOD { get; private set; } |
@@ -86,8 +90,12 @@ public static class BSParam | |||
86 | public static bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes | 90 | public static bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes |
87 | public static bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects | 91 | public static bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects |
88 | public static bool ShouldRemoveZeroWidthTriangles { get; private set; } | 92 | public static bool ShouldRemoveZeroWidthTriangles { get; private set; } |
93 | public static bool ShouldUseBulletHACD { get; set; } | ||
94 | public static bool ShouldUseSingleConvexHullForPrims { get; set; } | ||
95 | public static bool ShouldUseGImpactShapeForPrims { get; set; } | ||
96 | public static bool ShouldUseAssetHulls { get; set; } | ||
89 | 97 | ||
90 | public static float TerrainImplementation { get; private set; } | 98 | public static float TerrainImplementation { get; set; } |
91 | public static int TerrainMeshMagnification { get; private set; } | 99 | public static int TerrainMeshMagnification { get; private set; } |
92 | public static float TerrainFriction { get; private set; } | 100 | public static float TerrainFriction { get; private set; } |
93 | public static float TerrainHitFraction { get; private set; } | 101 | public static float TerrainHitFraction { get; private set; } |
@@ -112,6 +120,7 @@ public static class BSParam | |||
112 | public static float NumberOfSolverIterations { get; private set; } | 120 | public static float NumberOfSolverIterations { get; private set; } |
113 | public static bool UseSingleSidedMeshes { get; private set; } | 121 | public static bool UseSingleSidedMeshes { get; private set; } |
114 | public static float GlobalContactBreakingThreshold { get; private set; } | 122 | public static float GlobalContactBreakingThreshold { get; private set; } |
123 | public static float PhysicsUnmanLoggingFrames { get; private set; } | ||
115 | 124 | ||
116 | // Avatar parameters | 125 | // Avatar parameters |
117 | public static float AvatarFriction { get; private set; } | 126 | public static float AvatarFriction { get; private set; } |
@@ -122,11 +131,18 @@ public static class BSParam | |||
122 | public static float AvatarCapsuleWidth { get; private set; } | 131 | public static float AvatarCapsuleWidth { get; private set; } |
123 | public static float AvatarCapsuleDepth { get; private set; } | 132 | public static float AvatarCapsuleDepth { get; private set; } |
124 | public static float AvatarCapsuleHeight { get; private set; } | 133 | public static float AvatarCapsuleHeight { get; private set; } |
134 | public static float AvatarHeightLowFudge { get; private set; } | ||
135 | public static float AvatarHeightMidFudge { get; private set; } | ||
136 | public static float AvatarHeightHighFudge { get; private set; } | ||
125 | public static float AvatarContactProcessingThreshold { get; private set; } | 137 | public static float AvatarContactProcessingThreshold { get; private set; } |
138 | public static float AvatarStopZeroThreshold { get; private set; } | ||
139 | public static int AvatarJumpFrames { get; private set; } | ||
126 | public static float AvatarBelowGroundUpCorrectionMeters { get; private set; } | 140 | public static float AvatarBelowGroundUpCorrectionMeters { get; private set; } |
127 | public static float AvatarStepHeight { get; private set; } | 141 | public static float AvatarStepHeight { get; private set; } |
128 | public static float AvatarStepApproachFactor { get; private set; } | 142 | public static float AvatarStepApproachFactor { get; private set; } |
129 | public static float AvatarStepForceFactor { get; private set; } | 143 | public static float AvatarStepForceFactor { get; private set; } |
144 | public static float AvatarStepUpCorrectionFactor { get; private set; } | ||
145 | public static int AvatarStepSmoothingSteps { get; private set; } | ||
130 | 146 | ||
131 | // Vehicle parameters | 147 | // Vehicle parameters |
132 | public static float VehicleMaxLinearVelocity { get; private set; } | 148 | public static float VehicleMaxLinearVelocity { get; private set; } |
@@ -138,9 +154,15 @@ public static class BSParam | |||
138 | public static float VehicleRestitution { get; private set; } | 154 | public static float VehicleRestitution { get; private set; } |
139 | public static Vector3 VehicleLinearFactor { get; private set; } | 155 | public static Vector3 VehicleLinearFactor { get; private set; } |
140 | public static Vector3 VehicleAngularFactor { get; private set; } | 156 | public static Vector3 VehicleAngularFactor { get; private set; } |
157 | public static Vector3 VehicleInertiaFactor { get; private set; } | ||
141 | public static float VehicleGroundGravityFudge { get; private set; } | 158 | public static float VehicleGroundGravityFudge { get; private set; } |
142 | public static float VehicleAngularBankingTimescaleFudge { get; private set; } | 159 | public static float VehicleAngularBankingTimescaleFudge { get; private set; } |
143 | public static bool VehicleDebuggingEnabled { get; private set; } | 160 | public static bool VehicleEnableLinearDeflection { get; private set; } |
161 | public static bool VehicleLinearDeflectionNotCollidingNoZ { get; private set; } | ||
162 | public static bool VehicleEnableAngularVerticalAttraction { get; private set; } | ||
163 | public static int VehicleAngularVerticalAttractionAlgorithm { get; private set; } | ||
164 | public static bool VehicleEnableAngularDeflection { get; private set; } | ||
165 | public static bool VehicleEnableAngularBanking { get; private set; } | ||
144 | 166 | ||
145 | // Convex Hulls | 167 | // Convex Hulls |
146 | public static int CSHullMaxDepthSplit { get; private set; } | 168 | public static int CSHullMaxDepthSplit { get; private set; } |
@@ -149,9 +171,19 @@ public static class BSParam | |||
149 | public static float CSHullVolumeConservationThresholdPercent { get; private set; } | 171 | public static float CSHullVolumeConservationThresholdPercent { get; private set; } |
150 | public static int CSHullMaxVertices { get; private set; } | 172 | public static int CSHullMaxVertices { get; private set; } |
151 | public static float CSHullMaxSkinWidth { get; private set; } | 173 | public static float CSHullMaxSkinWidth { get; private set; } |
174 | public static float BHullMaxVerticesPerHull { get; private set; } // 100 | ||
175 | public static float BHullMinClusters { get; private set; } // 2 | ||
176 | public static float BHullCompacityWeight { get; private set; } // 0.1 | ||
177 | public static float BHullVolumeWeight { get; private set; } // 0.0 | ||
178 | public static float BHullConcavity { get; private set; } // 100 | ||
179 | public static bool BHullAddExtraDistPoints { get; private set; } // false | ||
180 | public static bool BHullAddNeighboursDistPoints { get; private set; } // false | ||
181 | public static bool BHullAddFacesPoints { get; private set; } // false | ||
182 | public static bool BHullShouldAdjustCollisionMargin { get; private set; } // false | ||
152 | 183 | ||
153 | // Linkset implementation parameters | 184 | // Linkset implementation parameters |
154 | public static float LinksetImplementation { get; private set; } | 185 | public static float LinksetImplementation { get; private set; } |
186 | public static bool LinksetOffsetCenterOfMass { get; private set; } | ||
155 | public static bool LinkConstraintUseFrameOffset { get; private set; } | 187 | public static bool LinkConstraintUseFrameOffset { get; private set; } |
156 | public static bool LinkConstraintEnableTransMotor { get; private set; } | 188 | public static bool LinkConstraintEnableTransMotor { get; private set; } |
157 | public static float LinkConstraintTransMotorMaxVel { get; private set; } | 189 | public static float LinkConstraintTransMotorMaxVel { get; private set; } |
@@ -223,16 +255,41 @@ public static class BSParam | |||
223 | getter = pGetter; | 255 | getter = pGetter; |
224 | objectSet = pObjSetter; | 256 | objectSet = pObjSetter; |
225 | } | 257 | } |
226 | /* Wish I could simplify using this definition but CLR doesn't store references so closure around delegates of references won't work | 258 | // Simple parameter variable where property name is the same as the INI file name |
227 | public ParameterDefn(string pName, string pDesc, T pDefault, ref T loc) | 259 | // and the value is only a simple get and set. |
260 | public ParameterDefn(string pName, string pDesc, T pDefault) | ||
228 | : base(pName, pDesc) | 261 | : base(pName, pDesc) |
229 | { | 262 | { |
230 | defaultValue = pDefault; | 263 | defaultValue = pDefault; |
231 | setter = (s, v) => { loc = v; }; | 264 | setter = (s, v) => { SetValueByName(s, name, v); }; |
232 | getter = (s) => { return loc; }; | 265 | getter = (s) => { return GetValueByName(s, name); }; |
233 | objectSet = null; | 266 | objectSet = null; |
234 | } | 267 | } |
235 | */ | 268 | // Use reflection to find the property named 'pName' in BSParam and assign 'val' to same. |
269 | private void SetValueByName(BSScene s, string pName, T val) | ||
270 | { | ||
271 | PropertyInfo prop = typeof(BSParam).GetProperty(pName, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); | ||
272 | if (prop == null) | ||
273 | { | ||
274 | // This should only be output when someone adds a new INI parameter and misspells the name. | ||
275 | s.Logger.ErrorFormat("{0} SetValueByName: did not find '{1}'. Verify specified property name is the same as the given INI parameters name.", LogHeader, pName); | ||
276 | } | ||
277 | else | ||
278 | { | ||
279 | prop.SetValue(null, val, null); | ||
280 | } | ||
281 | } | ||
282 | // Use reflection to find the property named 'pName' in BSParam and return the value in same. | ||
283 | private T GetValueByName(BSScene s, string pName) | ||
284 | { | ||
285 | PropertyInfo prop = typeof(BSParam).GetProperty(pName, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); | ||
286 | if (prop == null) | ||
287 | { | ||
288 | // This should only be output when someone adds a new INI parameter and misspells the name. | ||
289 | s.Logger.ErrorFormat("{0} GetValueByName: did not find '{1}'. Verify specified property name is the same as the given INI parameter name.", LogHeader, pName); | ||
290 | } | ||
291 | return (T)prop.GetValue(null, null); | ||
292 | } | ||
236 | public override void AssignDefault(BSScene s) | 293 | public override void AssignDefault(BSScene s) |
237 | { | 294 | { |
238 | setter(s, defaultValue); | 295 | setter(s, defaultValue); |
@@ -309,6 +366,11 @@ public static class BSParam | |||
309 | // v = value (appropriate type) | 366 | // v = value (appropriate type) |
310 | private static ParameterDefnBase[] ParameterDefinitions = | 367 | private static ParameterDefnBase[] ParameterDefinitions = |
311 | { | 368 | { |
369 | new ParameterDefn<bool>("UseSeparatePhysicsThread", "If 'true', the physics engine runs independent from the simulator heartbeat", | ||
370 | false ), | ||
371 | new ParameterDefn<float>("PhysicsTimeStep", "If separate thread, seconds to simulate each interval", | ||
372 | 0.089f ), | ||
373 | |||
312 | new ParameterDefn<bool>("MeshSculptedPrim", "Whether to create meshes for sculpties", | 374 | new ParameterDefn<bool>("MeshSculptedPrim", "Whether to create meshes for sculpties", |
313 | true, | 375 | true, |
314 | (s) => { return ShouldMeshSculptedPrim; }, | 376 | (s) => { return ShouldMeshSculptedPrim; }, |
@@ -322,18 +384,20 @@ public static class BSParam | |||
322 | (s) => { return ShouldUseHullsForPhysicalObjects; }, | 384 | (s) => { return ShouldUseHullsForPhysicalObjects; }, |
323 | (s,v) => { ShouldUseHullsForPhysicalObjects = v; } ), | 385 | (s,v) => { ShouldUseHullsForPhysicalObjects = v; } ), |
324 | new ParameterDefn<bool>("ShouldRemoveZeroWidthTriangles", "If true, remove degenerate triangles from meshes", | 386 | new ParameterDefn<bool>("ShouldRemoveZeroWidthTriangles", "If true, remove degenerate triangles from meshes", |
325 | true, | 387 | true ), |
326 | (s) => { return ShouldRemoveZeroWidthTriangles; }, | 388 | new ParameterDefn<bool>("ShouldUseBulletHACD", "If true, use the Bullet version of HACD", |
327 | (s,v) => { ShouldRemoveZeroWidthTriangles = v; } ), | 389 | false ), |
390 | new ParameterDefn<bool>("ShouldUseSingleConvexHullForPrims", "If true, use a single convex hull shape for physical prims", | ||
391 | true ), | ||
392 | new ParameterDefn<bool>("ShouldUseGImpactShapeForPrims", "If true, use a GImpact shape for prims with cuts and twists", | ||
393 | false ), | ||
394 | new ParameterDefn<bool>("ShouldUseAssetHulls", "If true, use hull if specified in the mesh asset info", | ||
395 | true ), | ||
328 | 396 | ||
329 | new ParameterDefn<int>("CrossingFailuresBeforeOutOfBounds", "How forgiving we are about getting into adjactent regions", | 397 | new ParameterDefn<int>("CrossingFailuresBeforeOutOfBounds", "How forgiving we are about getting into adjactent regions", |
330 | 5, | 398 | 5 ), |
331 | (s) => { return CrossingFailuresBeforeOutOfBounds; }, | ||
332 | (s,v) => { CrossingFailuresBeforeOutOfBounds = v; } ), | ||
333 | new ParameterDefn<float>("UpdateVelocityChangeThreshold", "Change in updated velocity required before reporting change to simulator", | 399 | new ParameterDefn<float>("UpdateVelocityChangeThreshold", "Change in updated velocity required before reporting change to simulator", |
334 | 0.1f, | 400 | 0.1f ), |
335 | (s) => { return UpdateVelocityChangeThreshold; }, | ||
336 | (s,v) => { UpdateVelocityChangeThreshold = v; } ), | ||
337 | 401 | ||
338 | new ParameterDefn<float>("MeshLevelOfDetail", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)", | 402 | new ParameterDefn<float>("MeshLevelOfDetail", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)", |
339 | 32f, | 403 | 32f, |
@@ -399,26 +463,22 @@ public static class BSParam | |||
399 | (s) => { return MaxAddForceMagnitude; }, | 463 | (s) => { return MaxAddForceMagnitude; }, |
400 | (s,v) => { MaxAddForceMagnitude = v; MaxAddForceMagnitudeSquared = v * v; } ), | 464 | (s,v) => { MaxAddForceMagnitude = v; MaxAddForceMagnitudeSquared = v * v; } ), |
401 | // Density is passed around as 100kg/m3. This scales that to 1kg/m3. | 465 | // Density is passed around as 100kg/m3. This scales that to 1kg/m3. |
466 | // Reduce by power of 100 because Bullet doesn't seem to handle objects with large mass very well | ||
402 | new ParameterDefn<float>("DensityScaleFactor", "Conversion for simulator/viewer density (100kg/m3) to physical density (1kg/m3)", | 467 | new ParameterDefn<float>("DensityScaleFactor", "Conversion for simulator/viewer density (100kg/m3) to physical density (1kg/m3)", |
403 | 0.01f, | 468 | 0.01f ), |
404 | (s) => { return DensityScaleFactor; }, | ||
405 | (s,v) => { DensityScaleFactor = v; } ), | ||
406 | 469 | ||
407 | new ParameterDefn<float>("PID_D", "Derivitive factor for motion smoothing", | 470 | new ParameterDefn<float>("PID_D", "Derivitive factor for motion smoothing", |
408 | 2200f, | 471 | 2200f ), |
409 | (s) => { return (float)PID_D; }, | ||
410 | (s,v) => { PID_D = v; } ), | ||
411 | new ParameterDefn<float>("PID_P", "Parameteric factor for motion smoothing", | 472 | new ParameterDefn<float>("PID_P", "Parameteric factor for motion smoothing", |
412 | 900f, | 473 | 900f ), |
413 | (s) => { return (float)PID_P; }, | ||
414 | (s,v) => { PID_P = v; } ), | ||
415 | 474 | ||
416 | new ParameterDefn<float>("DefaultFriction", "Friction factor used on new objects", | 475 | new ParameterDefn<float>("DefaultFriction", "Friction factor used on new objects", |
417 | 0.2f, | 476 | 0.2f, |
418 | (s) => { return DefaultFriction; }, | 477 | (s) => { return DefaultFriction; }, |
419 | (s,v) => { DefaultFriction = v; s.UnmanagedParams[0].defaultFriction = v; } ), | 478 | (s,v) => { DefaultFriction = v; s.UnmanagedParams[0].defaultFriction = v; } ), |
479 | // For historical reasons, the viewer and simulator multiply the density by 100 | ||
420 | new ParameterDefn<float>("DefaultDensity", "Density for new objects" , | 480 | new ParameterDefn<float>("DefaultDensity", "Density for new objects" , |
421 | 10.000006836f, // Aluminum g/cm3 | 481 | 1000.0006836f, // Aluminum g/cm3 * 100 |
422 | (s) => { return DefaultDensity; }, | 482 | (s) => { return DefaultDensity; }, |
423 | (s,v) => { DefaultDensity = v; s.UnmanagedParams[0].defaultDensity = v; } ), | 483 | (s,v) => { DefaultDensity = v; s.UnmanagedParams[0].defaultDensity = v; } ), |
424 | new ParameterDefn<float>("DefaultRestitution", "Bouncyness of an object" , | 484 | new ParameterDefn<float>("DefaultRestitution", "Bouncyness of an object" , |
@@ -478,86 +538,61 @@ public static class BSParam | |||
478 | (s,o) => { s.PE.SetContactProcessingThreshold(o.PhysBody, ContactProcessingThreshold); } ), | 538 | (s,o) => { s.PE.SetContactProcessingThreshold(o.PhysBody, ContactProcessingThreshold); } ), |
479 | 539 | ||
480 | new ParameterDefn<float>("TerrainImplementation", "Type of shape to use for terrain (0=heightmap, 1=mesh)", | 540 | new ParameterDefn<float>("TerrainImplementation", "Type of shape to use for terrain (0=heightmap, 1=mesh)", |
481 | (float)BSTerrainPhys.TerrainImplementation.Mesh, | 541 | (float)BSTerrainPhys.TerrainImplementation.Mesh ), |
482 | (s) => { return TerrainImplementation; }, | ||
483 | (s,v) => { TerrainImplementation = v; } ), | ||
484 | new ParameterDefn<int>("TerrainMeshMagnification", "Number of times the 256x256 heightmap is multiplied to create the terrain mesh" , | 542 | new ParameterDefn<int>("TerrainMeshMagnification", "Number of times the 256x256 heightmap is multiplied to create the terrain mesh" , |
485 | 2, | 543 | 2 ), |
486 | (s) => { return TerrainMeshMagnification; }, | ||
487 | (s,v) => { TerrainMeshMagnification = v; } ), | ||
488 | new ParameterDefn<float>("TerrainFriction", "Factor to reduce movement against terrain surface" , | 544 | new ParameterDefn<float>("TerrainFriction", "Factor to reduce movement against terrain surface" , |
489 | 0.3f, | 545 | 0.3f ), |
490 | (s) => { return TerrainFriction; }, | ||
491 | (s,v) => { TerrainFriction = v; /* TODO: set on real terrain */} ), | ||
492 | new ParameterDefn<float>("TerrainHitFraction", "Distance to measure hit collisions" , | 546 | new ParameterDefn<float>("TerrainHitFraction", "Distance to measure hit collisions" , |
493 | 0.8f, | 547 | 0.8f ), |
494 | (s) => { return TerrainHitFraction; }, | ||
495 | (s,v) => { TerrainHitFraction = v; /* TODO: set on real terrain */ } ), | ||
496 | new ParameterDefn<float>("TerrainRestitution", "Bouncyness" , | 548 | new ParameterDefn<float>("TerrainRestitution", "Bouncyness" , |
497 | 0f, | 549 | 0f ), |
498 | (s) => { return TerrainRestitution; }, | ||
499 | (s,v) => { TerrainRestitution = v; /* TODO: set on real terrain */ } ), | ||
500 | new ParameterDefn<float>("TerrainContactProcessingThreshold", "Distance from terrain to stop processing collisions" , | 550 | new ParameterDefn<float>("TerrainContactProcessingThreshold", "Distance from terrain to stop processing collisions" , |
501 | 0.0f, | 551 | 0.0f ), |
502 | (s) => { return TerrainContactProcessingThreshold; }, | ||
503 | (s,v) => { TerrainContactProcessingThreshold = v; /* TODO: set on real terrain */ } ), | ||
504 | new ParameterDefn<float>("TerrainCollisionMargin", "Margin where collision checking starts" , | 552 | new ParameterDefn<float>("TerrainCollisionMargin", "Margin where collision checking starts" , |
505 | 0.08f, | 553 | 0.08f ), |
506 | (s) => { return TerrainCollisionMargin; }, | ||
507 | (s,v) => { TerrainCollisionMargin = v; /* TODO: set on real terrain */ } ), | ||
508 | 554 | ||
509 | new ParameterDefn<float>("AvatarFriction", "Factor to reduce movement against an avatar. Changed on avatar recreation.", | 555 | new ParameterDefn<float>("AvatarFriction", "Factor to reduce movement against an avatar. Changed on avatar recreation.", |
510 | 0.2f, | 556 | 0.2f ), |
511 | (s) => { return AvatarFriction; }, | ||
512 | (s,v) => { AvatarFriction = v; } ), | ||
513 | new ParameterDefn<float>("AvatarStandingFriction", "Avatar friction when standing. Changed on avatar recreation.", | 557 | new ParameterDefn<float>("AvatarStandingFriction", "Avatar friction when standing. Changed on avatar recreation.", |
514 | 0.95f, | 558 | 0.95f ), |
515 | (s) => { return AvatarStandingFriction; }, | ||
516 | (s,v) => { AvatarStandingFriction = v; } ), | ||
517 | new ParameterDefn<float>("AvatarAlwaysRunFactor", "Speed multiplier if avatar is set to always run", | 559 | new ParameterDefn<float>("AvatarAlwaysRunFactor", "Speed multiplier if avatar is set to always run", |
518 | 1.3f, | 560 | 1.3f ), |
519 | (s) => { return AvatarAlwaysRunFactor; }, | 561 | // For historical reasons, density is reported * 100 |
520 | (s,v) => { AvatarAlwaysRunFactor = v; } ), | 562 | new ParameterDefn<float>("AvatarDensity", "Density of an avatar. Changed on avatar recreation. Scaled times 100.", |
521 | new ParameterDefn<float>("AvatarDensity", "Density of an avatar. Changed on avatar recreation.", | 563 | 3500f) , // 3.5 * 100 |
522 | 3.5f, | ||
523 | (s) => { return AvatarDensity; }, | ||
524 | (s,v) => { AvatarDensity = v; } ), | ||
525 | new ParameterDefn<float>("AvatarRestitution", "Bouncyness. Changed on avatar recreation.", | 564 | new ParameterDefn<float>("AvatarRestitution", "Bouncyness. Changed on avatar recreation.", |
526 | 0f, | 565 | 0f ), |
527 | (s) => { return AvatarRestitution; }, | ||
528 | (s,v) => { AvatarRestitution = v; } ), | ||
529 | new ParameterDefn<float>("AvatarCapsuleWidth", "The distance between the sides of the avatar capsule", | 566 | new ParameterDefn<float>("AvatarCapsuleWidth", "The distance between the sides of the avatar capsule", |
530 | 0.6f, | 567 | 0.6f ) , |
531 | (s) => { return AvatarCapsuleWidth; }, | ||
532 | (s,v) => { AvatarCapsuleWidth = v; } ), | ||
533 | new ParameterDefn<float>("AvatarCapsuleDepth", "The distance between the front and back of the avatar capsule", | 568 | new ParameterDefn<float>("AvatarCapsuleDepth", "The distance between the front and back of the avatar capsule", |
534 | 0.45f, | 569 | 0.45f ), |
535 | (s) => { return AvatarCapsuleDepth; }, | ||
536 | (s,v) => { AvatarCapsuleDepth = v; } ), | ||
537 | new ParameterDefn<float>("AvatarCapsuleHeight", "Default height of space around avatar", | 570 | new ParameterDefn<float>("AvatarCapsuleHeight", "Default height of space around avatar", |
538 | 1.5f, | 571 | 1.5f ), |
539 | (s) => { return AvatarCapsuleHeight; }, | 572 | new ParameterDefn<float>("AvatarHeightLowFudge", "A fudge factor to make small avatars stand on the ground", |
540 | (s,v) => { AvatarCapsuleHeight = v; } ), | 573 | -0.2f ), |
574 | new ParameterDefn<float>("AvatarHeightMidFudge", "A fudge distance to adjust average sized avatars to be standing on ground", | ||
575 | 0.1f ), | ||
576 | new ParameterDefn<float>("AvatarHeightHighFudge", "A fudge factor to make tall avatars stand on the ground", | ||
577 | 0.1f ), | ||
541 | new ParameterDefn<float>("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions", | 578 | new ParameterDefn<float>("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions", |
542 | 0.1f, | 579 | 0.1f ), |
543 | (s) => { return AvatarContactProcessingThreshold; }, | 580 | new ParameterDefn<float>("AvatarStopZeroThreshold", "Movement velocity below which avatar is assumed to be stopped", |
544 | (s,v) => { AvatarContactProcessingThreshold = v; } ), | 581 | 0.1f ), |
545 | new ParameterDefn<float>("AvatarBelowGroundUpCorrectionMeters", "Meters to move avatar up if it seems to be below ground", | 582 | new ParameterDefn<float>("AvatarBelowGroundUpCorrectionMeters", "Meters to move avatar up if it seems to be below ground", |
546 | 1.0f, | 583 | 1.0f ), |
547 | (s) => { return AvatarBelowGroundUpCorrectionMeters; }, | 584 | new ParameterDefn<int>("AvatarJumpFrames", "Number of frames to allow jump forces. Changes jump height.", |
548 | (s,v) => { AvatarBelowGroundUpCorrectionMeters = v; } ), | 585 | 4 ), |
549 | new ParameterDefn<float>("AvatarStepHeight", "Height of a step obstacle to consider step correction", | 586 | new ParameterDefn<float>("AvatarStepHeight", "Height of a step obstacle to consider step correction", |
550 | 0.3f, | 587 | 0.6f ) , |
551 | (s) => { return AvatarStepHeight; }, | ||
552 | (s,v) => { AvatarStepHeight = v; } ), | ||
553 | new ParameterDefn<float>("AvatarStepApproachFactor", "Factor to control angle of approach to step (0=straight on)", | 588 | new ParameterDefn<float>("AvatarStepApproachFactor", "Factor to control angle of approach to step (0=straight on)", |
554 | 0.6f, | 589 | 0.6f ), |
555 | (s) => { return AvatarStepApproachFactor; }, | ||
556 | (s,v) => { AvatarStepApproachFactor = v; } ), | ||
557 | new ParameterDefn<float>("AvatarStepForceFactor", "Controls the amount of force up applied to step up onto a step", | 590 | new ParameterDefn<float>("AvatarStepForceFactor", "Controls the amount of force up applied to step up onto a step", |
558 | 2.0f, | 591 | 1.0f ), |
559 | (s) => { return AvatarStepForceFactor; }, | 592 | new ParameterDefn<float>("AvatarStepUpCorrectionFactor", "Multiplied by height of step collision to create up movement at step", |
560 | (s,v) => { AvatarStepForceFactor = v; } ), | 593 | 1.0f ), |
594 | new ParameterDefn<int>("AvatarStepSmoothingSteps", "Number of frames after a step collision that we continue walking up stairs", | ||
595 | 2 ), | ||
561 | 596 | ||
562 | new ParameterDefn<float>("VehicleMaxLinearVelocity", "Maximum velocity magnitude that can be assigned to a vehicle", | 597 | new ParameterDefn<float>("VehicleMaxLinearVelocity", "Maximum velocity magnitude that can be assigned to a vehicle", |
563 | 1000.0f, | 598 | 1000.0f, |
@@ -568,37 +603,33 @@ public static class BSParam | |||
568 | (s) => { return (float)VehicleMaxAngularVelocity; }, | 603 | (s) => { return (float)VehicleMaxAngularVelocity; }, |
569 | (s,v) => { VehicleMaxAngularVelocity = v; VehicleMaxAngularVelocitySq = v * v; } ), | 604 | (s,v) => { VehicleMaxAngularVelocity = v; VehicleMaxAngularVelocitySq = v * v; } ), |
570 | new ParameterDefn<float>("VehicleAngularDamping", "Factor to damp vehicle angular movement per second (0.0 - 1.0)", | 605 | new ParameterDefn<float>("VehicleAngularDamping", "Factor to damp vehicle angular movement per second (0.0 - 1.0)", |
571 | 0.0f, | 606 | 0.0f ), |
572 | (s) => { return VehicleAngularDamping; }, | ||
573 | (s,v) => { VehicleAngularDamping = v; } ), | ||
574 | new ParameterDefn<Vector3>("VehicleLinearFactor", "Fraction of physical linear changes applied to vehicle (<0,0,0> to <1,1,1>)", | 607 | new ParameterDefn<Vector3>("VehicleLinearFactor", "Fraction of physical linear changes applied to vehicle (<0,0,0> to <1,1,1>)", |
575 | new Vector3(1f, 1f, 1f), | 608 | new Vector3(1f, 1f, 1f) ), |
576 | (s) => { return VehicleLinearFactor; }, | ||
577 | (s,v) => { VehicleLinearFactor = v; } ), | ||
578 | new ParameterDefn<Vector3>("VehicleAngularFactor", "Fraction of physical angular changes applied to vehicle (<0,0,0> to <1,1,1>)", | 609 | new ParameterDefn<Vector3>("VehicleAngularFactor", "Fraction of physical angular changes applied to vehicle (<0,0,0> to <1,1,1>)", |
579 | new Vector3(1f, 1f, 1f), | 610 | new Vector3(1f, 1f, 1f) ), |
580 | (s) => { return VehicleAngularFactor; }, | 611 | new ParameterDefn<Vector3>("VehicleInertiaFactor", "Fraction of physical inertia applied (<0,0,0> to <1,1,1>)", |
581 | (s,v) => { VehicleAngularFactor = v; } ), | 612 | new Vector3(1f, 1f, 1f) ), |
582 | new ParameterDefn<float>("VehicleFriction", "Friction of vehicle on the ground (0.0 - 1.0)", | 613 | new ParameterDefn<float>("VehicleFriction", "Friction of vehicle on the ground (0.0 - 1.0)", |
583 | 0.0f, | 614 | 0.0f ), |
584 | (s) => { return VehicleFriction; }, | ||
585 | (s,v) => { VehicleFriction = v; } ), | ||
586 | new ParameterDefn<float>("VehicleRestitution", "Bouncyness factor for vehicles (0.0 - 1.0)", | 615 | new ParameterDefn<float>("VehicleRestitution", "Bouncyness factor for vehicles (0.0 - 1.0)", |
587 | 0.0f, | 616 | 0.0f ), |
588 | (s) => { return VehicleRestitution; }, | ||
589 | (s,v) => { VehicleRestitution = v; } ), | ||
590 | new ParameterDefn<float>("VehicleGroundGravityFudge", "Factor to multiply gravity if a ground vehicle is probably on the ground (0.0 - 1.0)", | 617 | new ParameterDefn<float>("VehicleGroundGravityFudge", "Factor to multiply gravity if a ground vehicle is probably on the ground (0.0 - 1.0)", |
591 | 0.2f, | 618 | 0.2f ), |
592 | (s) => { return VehicleGroundGravityFudge; }, | ||
593 | (s,v) => { VehicleGroundGravityFudge = v; } ), | ||
594 | new ParameterDefn<float>("VehicleAngularBankingTimescaleFudge", "Factor to multiple angular banking timescale. Tune to increase realism.", | 619 | new ParameterDefn<float>("VehicleAngularBankingTimescaleFudge", "Factor to multiple angular banking timescale. Tune to increase realism.", |
595 | 60.0f, | 620 | 60.0f ), |
596 | (s) => { return VehicleAngularBankingTimescaleFudge; }, | 621 | new ParameterDefn<bool>("VehicleEnableLinearDeflection", "Turn on/off vehicle linear deflection effect", |
597 | (s,v) => { VehicleAngularBankingTimescaleFudge = v; } ), | 622 | true ), |
598 | new ParameterDefn<bool>("VehicleDebuggingEnable", "Turn on/off vehicle debugging", | 623 | new ParameterDefn<bool>("VehicleLinearDeflectionNotCollidingNoZ", "Turn on/off linear deflection Z effect on non-colliding vehicles", |
599 | false, | 624 | true ), |
600 | (s) => { return VehicleDebuggingEnabled; }, | 625 | new ParameterDefn<bool>("VehicleEnableAngularVerticalAttraction", "Turn on/off vehicle angular vertical attraction effect", |
601 | (s,v) => { VehicleDebuggingEnabled = v; } ), | 626 | true ), |
627 | new ParameterDefn<int>("VehicleAngularVerticalAttractionAlgorithm", "Select vertical attraction algo. You need to look at the source.", | ||
628 | 0 ), | ||
629 | new ParameterDefn<bool>("VehicleEnableAngularDeflection", "Turn on/off vehicle angular deflection effect", | ||
630 | true ), | ||
631 | new ParameterDefn<bool>("VehicleEnableAngularBanking", "Turn on/off vehicle angular banking effect", | ||
632 | true ), | ||
602 | 633 | ||
603 | new ParameterDefn<float>("MaxPersistantManifoldPoolSize", "Number of manifolds pooled (0 means default of 4096)", | 634 | new ParameterDefn<float>("MaxPersistantManifoldPoolSize", "Number of manifolds pooled (0 means default of 4096)", |
604 | 0f, | 635 | 0f, |
@@ -611,7 +642,7 @@ public static class BSParam | |||
611 | new ParameterDefn<bool>("ShouldDisableContactPoolDynamicAllocation", "Enable to allow large changes in object count", | 642 | new ParameterDefn<bool>("ShouldDisableContactPoolDynamicAllocation", "Enable to allow large changes in object count", |
612 | false, | 643 | false, |
613 | (s) => { return ShouldDisableContactPoolDynamicAllocation; }, | 644 | (s) => { return ShouldDisableContactPoolDynamicAllocation; }, |
614 | (s,v) => { ShouldDisableContactPoolDynamicAllocation = v; | 645 | (s,v) => { ShouldDisableContactPoolDynamicAllocation = v; |
615 | s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation = NumericBool(v); } ), | 646 | s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation = NumericBool(v); } ), |
616 | new ParameterDefn<bool>("ShouldForceUpdateAllAabbs", "Enable to recomputer AABBs every simulator step", | 647 | new ParameterDefn<bool>("ShouldForceUpdateAllAabbs", "Enable to recomputer AABBs every simulator step", |
617 | false, | 648 | false, |
@@ -641,64 +672,61 @@ public static class BSParam | |||
641 | 0f, | 672 | 0f, |
642 | (s) => { return GlobalContactBreakingThreshold; }, | 673 | (s) => { return GlobalContactBreakingThreshold; }, |
643 | (s,v) => { GlobalContactBreakingThreshold = v; s.UnmanagedParams[0].globalContactBreakingThreshold = v; } ), | 674 | (s,v) => { GlobalContactBreakingThreshold = v; s.UnmanagedParams[0].globalContactBreakingThreshold = v; } ), |
675 | new ParameterDefn<float>("PhysicsUnmanLoggingFrames", "If non-zero, frames between output of detailed unmanaged physics statistics", | ||
676 | 0f, | ||
677 | (s) => { return PhysicsUnmanLoggingFrames; }, | ||
678 | (s,v) => { PhysicsUnmanLoggingFrames = v; s.UnmanagedParams[0].physicsLoggingFrames = v; } ), | ||
644 | 679 | ||
645 | new ParameterDefn<int>("CSHullMaxDepthSplit", "CS impl: max depth to split for hull. 1-10 but > 7 is iffy", | 680 | new ParameterDefn<int>("CSHullMaxDepthSplit", "CS impl: max depth to split for hull. 1-10 but > 7 is iffy", |
646 | 7, | 681 | 7 ), |
647 | (s) => { return CSHullMaxDepthSplit; }, | ||
648 | (s,v) => { CSHullMaxDepthSplit = v; } ), | ||
649 | new ParameterDefn<int>("CSHullMaxDepthSplitForSimpleShapes", "CS impl: max depth setting for simple prim shapes", | 682 | new ParameterDefn<int>("CSHullMaxDepthSplitForSimpleShapes", "CS impl: max depth setting for simple prim shapes", |
650 | 2, | 683 | 2 ), |
651 | (s) => { return CSHullMaxDepthSplitForSimpleShapes; }, | ||
652 | (s,v) => { CSHullMaxDepthSplitForSimpleShapes = v; } ), | ||
653 | new ParameterDefn<float>("CSHullConcavityThresholdPercent", "CS impl: concavity threshold percent (0-20)", | 684 | new ParameterDefn<float>("CSHullConcavityThresholdPercent", "CS impl: concavity threshold percent (0-20)", |
654 | 5f, | 685 | 5f ), |
655 | (s) => { return CSHullConcavityThresholdPercent; }, | ||
656 | (s,v) => { CSHullConcavityThresholdPercent = v; } ), | ||
657 | new ParameterDefn<float>("CSHullVolumeConservationThresholdPercent", "percent volume conservation to collapse hulls (0-30)", | 686 | new ParameterDefn<float>("CSHullVolumeConservationThresholdPercent", "percent volume conservation to collapse hulls (0-30)", |
658 | 5f, | 687 | 5f ), |
659 | (s) => { return CSHullVolumeConservationThresholdPercent; }, | ||
660 | (s,v) => { CSHullVolumeConservationThresholdPercent = v; } ), | ||
661 | new ParameterDefn<int>("CSHullMaxVertices", "CS impl: maximum number of vertices in output hulls. Keep < 50.", | 688 | new ParameterDefn<int>("CSHullMaxVertices", "CS impl: maximum number of vertices in output hulls. Keep < 50.", |
662 | 32, | 689 | 32 ), |
663 | (s) => { return CSHullMaxVertices; }, | ||
664 | (s,v) => { CSHullMaxVertices = v; } ), | ||
665 | new ParameterDefn<float>("CSHullMaxSkinWidth", "CS impl: skin width to apply to output hulls.", | 690 | new ParameterDefn<float>("CSHullMaxSkinWidth", "CS impl: skin width to apply to output hulls.", |
666 | 0, | 691 | 0f ), |
667 | (s) => { return CSHullMaxSkinWidth; }, | 692 | |
668 | (s,v) => { CSHullMaxSkinWidth = v; } ), | 693 | new ParameterDefn<float>("BHullMaxVerticesPerHull", "Bullet impl: max number of vertices per created hull", |
694 | 200f ), | ||
695 | new ParameterDefn<float>("BHullMinClusters", "Bullet impl: minimum number of hulls to create per mesh", | ||
696 | 10f ), | ||
697 | new ParameterDefn<float>("BHullCompacityWeight", "Bullet impl: weight factor for how compact to make hulls", | ||
698 | 20f ), | ||
699 | new ParameterDefn<float>("BHullVolumeWeight", "Bullet impl: weight factor for volume in created hull", | ||
700 | 0.1f ), | ||
701 | new ParameterDefn<float>("BHullConcavity", "Bullet impl: weight factor for how convex a created hull can be", | ||
702 | 10f ), | ||
703 | new ParameterDefn<bool>("BHullAddExtraDistPoints", "Bullet impl: whether to add extra vertices for long distance vectors", | ||
704 | true ), | ||
705 | new ParameterDefn<bool>("BHullAddNeighboursDistPoints", "Bullet impl: whether to add extra vertices between neighbor hulls", | ||
706 | true ), | ||
707 | new ParameterDefn<bool>("BHullAddFacesPoints", "Bullet impl: whether to add extra vertices to break up hull faces", | ||
708 | true ), | ||
709 | new ParameterDefn<bool>("BHullShouldAdjustCollisionMargin", "Bullet impl: whether to shrink resulting hulls to account for collision margin", | ||
710 | false ), | ||
669 | 711 | ||
670 | new ParameterDefn<float>("LinksetImplementation", "Type of linkset implementation (0=Constraint, 1=Compound, 2=Manual)", | 712 | new ParameterDefn<float>("LinksetImplementation", "Type of linkset implementation (0=Constraint, 1=Compound, 2=Manual)", |
671 | (float)BSLinkset.LinksetImplementation.Compound, | 713 | (float)BSLinkset.LinksetImplementation.Compound ), |
672 | (s) => { return LinksetImplementation; }, | 714 | new ParameterDefn<bool>("LinksetOffsetCenterOfMass", "If 'true', compute linkset center-of-mass and offset linkset position to account for same", |
673 | (s,v) => { LinksetImplementation = v; } ), | 715 | true ), |
674 | new ParameterDefn<bool>("LinkConstraintUseFrameOffset", "For linksets built with constraints, enable frame offsetFor linksets built with constraints, enable frame offset.", | 716 | new ParameterDefn<bool>("LinkConstraintUseFrameOffset", "For linksets built with constraints, enable frame offsetFor linksets built with constraints, enable frame offset.", |
675 | false, | 717 | false ), |
676 | (s) => { return LinkConstraintUseFrameOffset; }, | ||
677 | (s,v) => { LinkConstraintUseFrameOffset = v; } ), | ||
678 | new ParameterDefn<bool>("LinkConstraintEnableTransMotor", "Whether to enable translational motor on linkset constraints", | 718 | new ParameterDefn<bool>("LinkConstraintEnableTransMotor", "Whether to enable translational motor on linkset constraints", |
679 | true, | 719 | true ), |
680 | (s) => { return LinkConstraintEnableTransMotor; }, | ||
681 | (s,v) => { LinkConstraintEnableTransMotor = v; } ), | ||
682 | new ParameterDefn<float>("LinkConstraintTransMotorMaxVel", "Maximum velocity to be applied by translational motor in linkset constraints", | 720 | new ParameterDefn<float>("LinkConstraintTransMotorMaxVel", "Maximum velocity to be applied by translational motor in linkset constraints", |
683 | 5.0f, | 721 | 5.0f ), |
684 | (s) => { return LinkConstraintTransMotorMaxVel; }, | ||
685 | (s,v) => { LinkConstraintTransMotorMaxVel = v; } ), | ||
686 | new ParameterDefn<float>("LinkConstraintTransMotorMaxForce", "Maximum force to be applied by translational motor in linkset constraints", | 722 | new ParameterDefn<float>("LinkConstraintTransMotorMaxForce", "Maximum force to be applied by translational motor in linkset constraints", |
687 | 0.1f, | 723 | 0.1f ), |
688 | (s) => { return LinkConstraintTransMotorMaxForce; }, | ||
689 | (s,v) => { LinkConstraintTransMotorMaxForce = v; } ), | ||
690 | new ParameterDefn<float>("LinkConstraintCFM", "Amount constraint can be violated. 0=no violation, 1=infinite. Default=0.1", | 724 | new ParameterDefn<float>("LinkConstraintCFM", "Amount constraint can be violated. 0=no violation, 1=infinite. Default=0.1", |
691 | 0.1f, | 725 | 0.1f ), |
692 | (s) => { return LinkConstraintCFM; }, | ||
693 | (s,v) => { LinkConstraintCFM = v; } ), | ||
694 | new ParameterDefn<float>("LinkConstraintERP", "Amount constraint is corrected each tick. 0=none, 1=all. Default = 0.2", | 726 | new ParameterDefn<float>("LinkConstraintERP", "Amount constraint is corrected each tick. 0=none, 1=all. Default = 0.2", |
695 | 0.1f, | 727 | 0.1f ), |
696 | (s) => { return LinkConstraintERP; }, | ||
697 | (s,v) => { LinkConstraintERP = v; } ), | ||
698 | new ParameterDefn<float>("LinkConstraintSolverIterations", "Number of solver iterations when computing constraint. (0 = Bullet default)", | 728 | new ParameterDefn<float>("LinkConstraintSolverIterations", "Number of solver iterations when computing constraint. (0 = Bullet default)", |
699 | 40, | 729 | 40 ), |
700 | (s) => { return LinkConstraintSolverIterations; }, | ||
701 | (s,v) => { LinkConstraintSolverIterations = v; } ), | ||
702 | 730 | ||
703 | new ParameterDefn<int>("PhysicsMetricFrames", "Frames between outputting detailed phys metrics. (0 is off)", | 731 | new ParameterDefn<int>("PhysicsMetricFrames", "Frames between outputting detailed phys metrics. (0 is off)", |
704 | 0, | 732 | 0, |
@@ -707,7 +735,7 @@ public static class BSParam | |||
707 | new ParameterDefn<float>("ResetBroadphasePool", "Setting this is any value resets the broadphase collision pool", | 735 | new ParameterDefn<float>("ResetBroadphasePool", "Setting this is any value resets the broadphase collision pool", |
708 | 0f, | 736 | 0f, |
709 | (s) => { return 0f; }, | 737 | (s) => { return 0f; }, |
710 | (s,v) => { BSParam.ResetBroadphasePoolTainted(s, v); } ), | 738 | (s,v) => { BSParam.ResetBroadphasePoolTainted(s, v, false /* inTaintTime */); } ), |
711 | new ParameterDefn<float>("ResetConstraintSolver", "Setting this is any value resets the constraint solver", | 739 | new ParameterDefn<float>("ResetConstraintSolver", "Setting this is any value resets the constraint solver", |
712 | 0f, | 740 | 0f, |
713 | (s) => { return 0f; }, | 741 | (s) => { return 0f; }, |
@@ -793,10 +821,10 @@ public static class BSParam | |||
793 | // ===================================================================== | 821 | // ===================================================================== |
794 | // There are parameters that, when set, cause things to happen in the physics engine. | 822 | // There are parameters that, when set, cause things to happen in the physics engine. |
795 | // This causes the broadphase collision cache to be cleared. | 823 | // This causes the broadphase collision cache to be cleared. |
796 | private static void ResetBroadphasePoolTainted(BSScene pPhysScene, float v) | 824 | private static void ResetBroadphasePoolTainted(BSScene pPhysScene, float v, bool inTaintTime) |
797 | { | 825 | { |
798 | BSScene physScene = pPhysScene; | 826 | BSScene physScene = pPhysScene; |
799 | physScene.TaintedObject("BSParam.ResetBroadphasePoolTainted", delegate() | 827 | physScene.TaintedObject(inTaintTime, "BSParam.ResetBroadphasePoolTainted", delegate() |
800 | { | 828 | { |
801 | physScene.PE.ResetBroadphasePool(physScene.World); | 829 | physScene.PE.ResetBroadphasePool(physScene.World); |
802 | }); | 830 | }); |
@@ -806,7 +834,7 @@ public static class BSParam | |||
806 | private static void ResetConstraintSolverTainted(BSScene pPhysScene, float v) | 834 | private static void ResetConstraintSolverTainted(BSScene pPhysScene, float v) |
807 | { | 835 | { |
808 | BSScene physScene = pPhysScene; | 836 | BSScene physScene = pPhysScene; |
809 | physScene.TaintedObject("BSParam.ResetConstraintSolver", delegate() | 837 | physScene.TaintedObject(BSScene.DetailLogZero, "BSParam.ResetConstraintSolver", delegate() |
810 | { | 838 | { |
811 | physScene.PE.ResetConstraintSolver(physScene.World); | 839 | physScene.PE.ResetConstraintSolver(physScene.World); |
812 | }); | 840 | }); |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 6bb88c7..f89b376 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | |||
@@ -38,12 +38,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
38 | * Class to wrap all objects. | 38 | * Class to wrap all objects. |
39 | * The rest of BulletSim doesn't need to keep checking for avatars or prims | 39 | * The rest of BulletSim doesn't need to keep checking for avatars or prims |
40 | * unless the difference is significant. | 40 | * unless the difference is significant. |
41 | * | 41 | * |
42 | * Variables in the physicsl objects are in three forms: | 42 | * Variables in the physicsl objects are in three forms: |
43 | * VariableName: used by the simulator and performs taint operations, etc | 43 | * VariableName: used by the simulator and performs taint operations, etc |
44 | * RawVariableName: direct reference to the BulletSim storage for the variable value | 44 | * RawVariableName: direct reference to the BulletSim storage for the variable value |
45 | * ForceVariableName: direct reference (store and fetch) to the value in the physics engine. | 45 | * ForceVariableName: direct reference (store and fetch) to the value in the physics engine. |
46 | * The last two (and certainly the last one) should be referenced only in taint-time. | 46 | * The last one should only be referenced in taint-time. |
47 | */ | 47 | */ |
48 | 48 | ||
49 | /* | 49 | /* |
@@ -52,7 +52,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
52 | * SOP.ApplyImpulse SOP.ApplyAngularImpulse SOP.SetAngularImpulse SOP.SetForce | 52 | * SOP.ApplyImpulse SOP.ApplyAngularImpulse SOP.SetAngularImpulse SOP.SetForce |
53 | * SOG.ApplyImpulse SOG.ApplyAngularImpulse SOG.SetAngularImpulse | 53 | * SOG.ApplyImpulse SOG.ApplyAngularImpulse SOG.SetAngularImpulse |
54 | * PA.AddForce PA.AddAngularForce PA.Torque = v PA.Force = v | 54 | * PA.AddForce PA.AddAngularForce PA.Torque = v PA.Force = v |
55 | * BS.ApplyCentralForce BS.ApplyTorque | 55 | * BS.ApplyCentralForce BS.ApplyTorque |
56 | */ | 56 | */ |
57 | 57 | ||
58 | // Flags used to denote which properties updates when making UpdateProperties calls to linksets, etc. | 58 | // Flags used to denote which properties updates when making UpdateProperties calls to linksets, etc. |
@@ -72,19 +72,27 @@ public abstract class BSPhysObject : PhysicsActor | |||
72 | } | 72 | } |
73 | protected BSPhysObject(BSScene parentScene, uint localID, string name, string typeName) | 73 | protected BSPhysObject(BSScene parentScene, uint localID, string name, string typeName) |
74 | { | 74 | { |
75 | PhysicsScene = parentScene; | 75 | IsInitialized = false; |
76 | |||
77 | PhysScene = parentScene; | ||
76 | LocalID = localID; | 78 | LocalID = localID; |
77 | PhysObjectName = name; | 79 | PhysObjectName = name; |
78 | Name = name; // PhysicsActor also has the name of the object. Someday consolidate. | 80 | Name = name; // PhysicsActor also has the name of the object. Someday consolidate. |
79 | TypeName = typeName; | 81 | TypeName = typeName; |
80 | 82 | ||
83 | // The collection of things that push me around | ||
84 | PhysicalActors = new BSActorCollection(PhysScene); | ||
85 | |||
81 | // Initialize variables kept in base. | 86 | // Initialize variables kept in base. |
82 | GravModifier = 1.0f; | 87 | GravModifier = 1.0f; |
83 | Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity); | 88 | Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity); |
89 | HoverActive = false; | ||
84 | 90 | ||
85 | // We don't have any physical representation yet. | 91 | // We don't have any physical representation yet. |
86 | PhysBody = new BulletBody(localID); | 92 | PhysBody = new BulletBody(localID); |
87 | PhysShape = new BulletShape(); | 93 | PhysShape = new BSShapeNull(); |
94 | |||
95 | UserSetCenterOfMassDisplacement = null; | ||
88 | 96 | ||
89 | PrimAssetState = PrimAssetCondition.Unknown; | 97 | PrimAssetState = PrimAssetCondition.Unknown; |
90 | 98 | ||
@@ -92,30 +100,41 @@ public abstract class BSPhysObject : PhysicsActor | |||
92 | SetMaterial((int)MaterialAttributes.Material.Wood); | 100 | SetMaterial((int)MaterialAttributes.Material.Wood); |
93 | 101 | ||
94 | CollisionCollection = new CollisionEventUpdate(); | 102 | CollisionCollection = new CollisionEventUpdate(); |
95 | CollisionsLastTick = CollisionCollection; | 103 | CollisionsLastReported = CollisionCollection; |
104 | CollisionsLastTick = new CollisionEventUpdate(); | ||
105 | CollisionsLastTickStep = -1; | ||
106 | |||
96 | SubscribedEventsMs = 0; | 107 | SubscribedEventsMs = 0; |
97 | CollidingStep = 0; | 108 | // Crazy values that will never be true |
98 | CollidingGroundStep = 0; | 109 | CollidingStep = BSScene.NotASimulationStep; |
99 | CollisionAccumulation = 0; | 110 | CollidingGroundStep = BSScene.NotASimulationStep; |
111 | CollisionAccumulation = BSScene.NotASimulationStep; | ||
100 | ColliderIsMoving = false; | 112 | ColliderIsMoving = false; |
101 | CollisionScore = 0; | 113 | CollisionScore = 0; |
102 | 114 | ||
103 | // All axis free. | 115 | // All axis free. |
104 | LockedAxis = LockedAxisFree; | 116 | LockedLinearAxis = LockedAxisFree; |
117 | LockedAngularAxis = LockedAxisFree; | ||
105 | } | 118 | } |
106 | 119 | ||
107 | // Tell the object to clean up. | 120 | // Tell the object to clean up. |
108 | public virtual void Destroy() | 121 | public virtual void Destroy() |
109 | { | 122 | { |
110 | UnRegisterAllPreStepActions(); | 123 | PhysicalActors.Enable(false); |
111 | UnRegisterAllPostStepActions(); | 124 | PhysScene.TaintedObject(LocalID, "BSPhysObject.Destroy", delegate() |
125 | { | ||
126 | PhysicalActors.Dispose(); | ||
127 | }); | ||
112 | } | 128 | } |
113 | 129 | ||
114 | public BSScene PhysicsScene { get; protected set; } | 130 | public BSScene PhysScene { get; protected set; } |
115 | // public override uint LocalID { get; set; } // Use the LocalID definition in PhysicsActor | 131 | // public override uint LocalID { get; set; } // Use the LocalID definition in PhysicsActor |
116 | public string PhysObjectName { get; protected set; } | 132 | public string PhysObjectName { get; protected set; } |
117 | public string TypeName { get; protected set; } | 133 | public string TypeName { get; protected set; } |
118 | 134 | ||
135 | // Set to 'true' when the object is completely initialized. | ||
136 | // This mostly prevents property updates and collisions until the object is completely here. | ||
137 | public bool IsInitialized { get; protected set; } | ||
119 | 138 | ||
120 | // Return the object mass without calculating it or having side effects | 139 | // Return the object mass without calculating it or having side effects |
121 | public abstract float RawMass { get; } | 140 | public abstract float RawMass { get; } |
@@ -131,26 +150,19 @@ public abstract class BSPhysObject : PhysicsActor | |||
131 | // Reference to the physical body (btCollisionObject) of this object | 150 | // Reference to the physical body (btCollisionObject) of this object |
132 | public BulletBody PhysBody; | 151 | public BulletBody PhysBody; |
133 | // Reference to the physical shape (btCollisionShape) of this object | 152 | // Reference to the physical shape (btCollisionShape) of this object |
134 | public BulletShape PhysShape; | 153 | public BSShape PhysShape; |
135 | 154 | ||
136 | // The physical representation of the prim might require an asset fetch. | 155 | // The physical representation of the prim might require an asset fetch. |
137 | // The asset state is first 'Unknown' then 'Waiting' then either 'Failed' or 'Fetched'. | 156 | // The asset state is first 'Unknown' then 'Waiting' then either 'Failed' or 'Fetched'. |
138 | public enum PrimAssetCondition | 157 | public enum PrimAssetCondition |
139 | { | 158 | { |
140 | Unknown, Waiting, Failed, Fetched | 159 | Unknown, Waiting, FailedAssetFetch, FailedMeshing, Fetched |
141 | } | 160 | } |
142 | public PrimAssetCondition PrimAssetState { get; set; } | 161 | public PrimAssetCondition PrimAssetState { get; set; } |
143 | 162 | ||
144 | // The objects base shape information. Null if not a prim type shape. | 163 | // The objects base shape information. Null if not a prim type shape. |
145 | public PrimitiveBaseShape BaseShape { get; protected set; } | 164 | public PrimitiveBaseShape BaseShape { get; protected set; } |
146 | 165 | ||
147 | // Some types of objects have preferred physical representations. | ||
148 | // Returns SHAPE_UNKNOWN if there is no preference. | ||
149 | public virtual BSPhysicsShapeType PreferredPhysicalShape | ||
150 | { | ||
151 | get { return BSPhysicsShapeType.SHAPE_UNKNOWN; } | ||
152 | } | ||
153 | |||
154 | // When the physical properties are updated, an EntityProperty holds the update values. | 166 | // When the physical properties are updated, an EntityProperty holds the update values. |
155 | // Keep the current and last EntityProperties to enable computation of differences | 167 | // Keep the current and last EntityProperties to enable computation of differences |
156 | // between the current update and the previous values. | 168 | // between the current update and the previous values. |
@@ -168,6 +180,7 @@ public abstract class BSPhysObject : PhysicsActor | |||
168 | public abstract bool IsSolid { get; } | 180 | public abstract bool IsSolid { get; } |
169 | public abstract bool IsStatic { get; } | 181 | public abstract bool IsStatic { get; } |
170 | public abstract bool IsSelected { get; } | 182 | public abstract bool IsSelected { get; } |
183 | public abstract bool IsVolumeDetect { get; } | ||
171 | 184 | ||
172 | // Materialness | 185 | // Materialness |
173 | public MaterialAttributes.Material Material { get; private set; } | 186 | public MaterialAttributes.Material Material { get; private set; } |
@@ -176,11 +189,25 @@ public abstract class BSPhysObject : PhysicsActor | |||
176 | Material = (MaterialAttributes.Material)material; | 189 | Material = (MaterialAttributes.Material)material; |
177 | 190 | ||
178 | // Setting the material sets the material attributes also. | 191 | // Setting the material sets the material attributes also. |
192 | // TODO: decide if this is necessary -- the simulator does this. | ||
179 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); | 193 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); |
180 | Friction = matAttrib.friction; | 194 | Friction = matAttrib.friction; |
181 | Restitution = matAttrib.restitution; | 195 | Restitution = matAttrib.restitution; |
182 | Density = matAttrib.density / BSParam.DensityScaleFactor; | 196 | Density = matAttrib.density; |
183 | DetailLog("{0},{1}.SetMaterial,Mat={2},frict={3},rest={4},den={5}", LocalID, TypeName, Material, Friction, Restitution, Density); | 197 | // DetailLog("{0},{1}.SetMaterial,Mat={2},frict={3},rest={4},den={5}", LocalID, TypeName, Material, Friction, Restitution, Density); |
198 | } | ||
199 | |||
200 | public override float Density | ||
201 | { | ||
202 | get | ||
203 | { | ||
204 | return base.Density; | ||
205 | } | ||
206 | set | ||
207 | { | ||
208 | DetailLog("{0},BSPhysObject.Density,set,den={1}", LocalID, value); | ||
209 | base.Density = value; | ||
210 | } | ||
184 | } | 211 | } |
185 | 212 | ||
186 | // Stop all physical motion. | 213 | // Stop all physical motion. |
@@ -190,21 +217,55 @@ public abstract class BSPhysObject : PhysicsActor | |||
190 | // Update the physical location and motion of the object. Called with data from Bullet. | 217 | // Update the physical location and motion of the object. Called with data from Bullet. |
191 | public abstract void UpdateProperties(EntityProperties entprop); | 218 | public abstract void UpdateProperties(EntityProperties entprop); |
192 | 219 | ||
193 | public abstract OMV.Vector3 RawPosition { get; set; } | 220 | public virtual OMV.Vector3 RawPosition { get; set; } |
194 | public abstract OMV.Vector3 ForcePosition { get; set; } | 221 | public abstract OMV.Vector3 ForcePosition { get; set; } |
195 | 222 | ||
196 | public abstract OMV.Quaternion RawOrientation { get; set; } | 223 | public virtual OMV.Quaternion RawOrientation { get; set; } |
197 | public abstract OMV.Quaternion ForceOrientation { get; set; } | 224 | public abstract OMV.Quaternion ForceOrientation { get; set; } |
198 | 225 | ||
199 | public abstract OMV.Vector3 RawVelocity { get; set; } | 226 | public OMV.Vector3 RawVelocity { get; set; } |
200 | public abstract OMV.Vector3 ForceVelocity { get; set; } | 227 | public abstract OMV.Vector3 ForceVelocity { get; set; } |
201 | 228 | ||
229 | public OMV.Vector3 RawForce { get; set; } | ||
230 | public OMV.Vector3 RawTorque { get; set; } | ||
231 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) | ||
232 | { | ||
233 | AddAngularForce(force, pushforce, false); | ||
234 | } | ||
235 | public abstract void AddAngularForce(OMV.Vector3 force, bool pushforce, bool inTaintTime); | ||
236 | public abstract void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime); | ||
237 | |||
202 | public abstract OMV.Vector3 ForceRotationalVelocity { get; set; } | 238 | public abstract OMV.Vector3 ForceRotationalVelocity { get; set; } |
203 | 239 | ||
204 | public abstract float ForceBuoyancy { get; set; } | 240 | public abstract float ForceBuoyancy { get; set; } |
205 | 241 | ||
206 | public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; } | 242 | public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; } |
207 | 243 | ||
244 | public override bool PIDActive { set { MoveToTargetActive = value; } } | ||
245 | public override OMV.Vector3 PIDTarget { set { MoveToTargetTarget = value; } } | ||
246 | public override float PIDTau { set { MoveToTargetTau = value; } } | ||
247 | |||
248 | public bool MoveToTargetActive { get; set; } | ||
249 | public OMV.Vector3 MoveToTargetTarget { get; set; } | ||
250 | public float MoveToTargetTau { get; set; } | ||
251 | |||
252 | // Used for llSetHoverHeight and maybe vehicle height. Hover Height will override MoveTo target's Z | ||
253 | public override bool PIDHoverActive { set { HoverActive = value; } } | ||
254 | public override float PIDHoverHeight { set { HoverHeight = value; } } | ||
255 | public override PIDHoverType PIDHoverType { set { HoverType = value; } } | ||
256 | public override float PIDHoverTau { set { HoverTau = value; } } | ||
257 | |||
258 | public bool HoverActive { get; set; } | ||
259 | public float HoverHeight { get; set; } | ||
260 | public PIDHoverType HoverType { get; set; } | ||
261 | public float HoverTau { get; set; } | ||
262 | |||
263 | // For RotLookAt | ||
264 | public override OMV.Quaternion APIDTarget { set { return; } } | ||
265 | public override bool APIDActive { set { return; } } | ||
266 | public override float APIDStrength { set { return; } } | ||
267 | public override float APIDDamping { set { return; } } | ||
268 | |||
208 | // The current velocity forward | 269 | // The current velocity forward |
209 | public virtual float ForwardSpeed | 270 | public virtual float ForwardSpeed |
210 | { | 271 | { |
@@ -226,10 +287,69 @@ public abstract class BSPhysObject : PhysicsActor | |||
226 | 287 | ||
227 | // The user can optionally set the center of mass. The user's setting will override any | 288 | // The user can optionally set the center of mass. The user's setting will override any |
228 | // computed center-of-mass (like in linksets). | 289 | // computed center-of-mass (like in linksets). |
229 | public OMV.Vector3? UserSetCenterOfMass { get; set; } | 290 | // Note this is a displacement from the root's coordinates. Zero means use the root prim as center-of-mass. |
291 | public OMV.Vector3? UserSetCenterOfMassDisplacement { get; set; } | ||
292 | |||
293 | public OMV.Vector3 LockedLinearAxis { get; set; } // zero means locked. one means free. | ||
294 | public OMV.Vector3 LockedAngularAxis { get; set; } // zero means locked. one means free. | ||
295 | public const float FreeAxis = 1f; | ||
296 | public readonly OMV.Vector3 LockedAxisFree = new OMV.Vector3(FreeAxis, FreeAxis, FreeAxis); // All axis are free | ||
297 | |||
298 | // Enable physical actions. Bullet will keep sleeping non-moving physical objects so | ||
299 | // they need waking up when parameters are changed. | ||
300 | // Called in taint-time!! | ||
301 | public void ActivateIfPhysical(bool forceIt) | ||
302 | { | ||
303 | if (PhysBody.HasPhysicalBody) | ||
304 | { | ||
305 | if (IsPhysical) | ||
306 | { | ||
307 | // Physical objects might need activating | ||
308 | PhysScene.PE.Activate(PhysBody, forceIt); | ||
309 | } | ||
310 | else | ||
311 | { | ||
312 | // Clear the collision cache since we've changed some properties. | ||
313 | PhysScene.PE.ClearCollisionProxyCache(PhysScene.World, PhysBody); | ||
314 | } | ||
315 | } | ||
316 | } | ||
230 | 317 | ||
231 | public OMV.Vector3 LockedAxis { get; set; } // zero means locked. one means free. | 318 | // 'actors' act on the physical object to change or constrain its motion. These can range from |
232 | public readonly OMV.Vector3 LockedAxisFree = new OMV.Vector3(1f, 1f, 1f); // All axis are free | 319 | // hovering to complex vehicle motion. |
320 | // May be called at non-taint time as this just adds the actor to the action list and the real | ||
321 | // work is done during the simulation step. | ||
322 | // Note that, if the actor is already in the list and we are disabling same, the actor is just left | ||
323 | // in the list disabled. | ||
324 | public delegate BSActor CreateActor(); | ||
325 | public void EnableActor(bool enableActor, string actorName, CreateActor creator) | ||
326 | { | ||
327 | lock (PhysicalActors) | ||
328 | { | ||
329 | BSActor theActor; | ||
330 | if (PhysicalActors.TryGetActor(actorName, out theActor)) | ||
331 | { | ||
332 | // The actor already exists so just turn it on or off | ||
333 | DetailLog("{0},BSPhysObject.EnableActor,enablingExistingActor,name={1},enable={2}", LocalID, actorName, enableActor); | ||
334 | theActor.Enabled = enableActor; | ||
335 | } | ||
336 | else | ||
337 | { | ||
338 | // The actor does not exist. If it should, create it. | ||
339 | if (enableActor) | ||
340 | { | ||
341 | DetailLog("{0},BSPhysObject.EnableActor,creatingActor,name={1}", LocalID, actorName); | ||
342 | theActor = creator(); | ||
343 | PhysicalActors.Add(actorName, theActor); | ||
344 | theActor.Enabled = true; | ||
345 | } | ||
346 | else | ||
347 | { | ||
348 | DetailLog("{0},BSPhysObject.EnableActor,notCreatingActorSinceNotEnabled,name={1}", LocalID, actorName); | ||
349 | } | ||
350 | } | ||
351 | } | ||
352 | } | ||
233 | 353 | ||
234 | #region Collisions | 354 | #region Collisions |
235 | 355 | ||
@@ -247,70 +367,98 @@ public abstract class BSPhysObject : PhysicsActor | |||
247 | protected CollisionFlags CurrentCollisionFlags { get; set; } | 367 | protected CollisionFlags CurrentCollisionFlags { get; set; } |
248 | // On a collision, check the collider and remember if the last collider was moving | 368 | // On a collision, check the collider and remember if the last collider was moving |
249 | // Used to modify the standing of avatars (avatars on stationary things stand still) | 369 | // Used to modify the standing of avatars (avatars on stationary things stand still) |
250 | protected bool ColliderIsMoving; | 370 | public bool ColliderIsMoving; |
371 | // 'true' if the last collider was a volume detect object | ||
372 | public bool ColliderIsVolumeDetect; | ||
373 | // Used by BSCharacter to manage standing (and not slipping) | ||
374 | public bool IsStationary; | ||
251 | 375 | ||
252 | // Count of collisions for this object | 376 | // Count of collisions for this object |
253 | protected long CollisionAccumulation { get; set; } | 377 | protected long CollisionAccumulation { get; set; } |
254 | 378 | ||
255 | public override bool IsColliding { | 379 | public override bool IsColliding { |
256 | get { return (CollidingStep == PhysicsScene.SimulationStep); } | 380 | get { return (CollidingStep == PhysScene.SimulationStep); } |
257 | set { | 381 | set { |
258 | if (value) | 382 | if (value) |
259 | CollidingStep = PhysicsScene.SimulationStep; | 383 | CollidingStep = PhysScene.SimulationStep; |
260 | else | 384 | else |
261 | CollidingStep = 0; | 385 | CollidingStep = BSScene.NotASimulationStep; |
262 | } | 386 | } |
263 | } | 387 | } |
388 | // Complex objects (like linksets) need to know if there is a collision on any part of | ||
389 | // their shape. 'IsColliding' has an existing definition of reporting a collision on | ||
390 | // only this specific prim or component of linksets. | ||
391 | // 'HasSomeCollision' is defined as reporting if there is a collision on any part of | ||
392 | // the complex body that this prim is the root of. | ||
393 | public virtual bool HasSomeCollision | ||
394 | { | ||
395 | get { return IsColliding; } | ||
396 | set { IsColliding = value; } | ||
397 | } | ||
264 | public override bool CollidingGround { | 398 | public override bool CollidingGround { |
265 | get { return (CollidingGroundStep == PhysicsScene.SimulationStep); } | 399 | get { return (CollidingGroundStep == PhysScene.SimulationStep); } |
266 | set | 400 | set |
267 | { | 401 | { |
268 | if (value) | 402 | if (value) |
269 | CollidingGroundStep = PhysicsScene.SimulationStep; | 403 | CollidingGroundStep = PhysScene.SimulationStep; |
270 | else | 404 | else |
271 | CollidingGroundStep = 0; | 405 | CollidingGroundStep = BSScene.NotASimulationStep; |
272 | } | 406 | } |
273 | } | 407 | } |
274 | public override bool CollidingObj { | 408 | public override bool CollidingObj { |
275 | get { return (CollidingObjectStep == PhysicsScene.SimulationStep); } | 409 | get { return (CollidingObjectStep == PhysScene.SimulationStep); } |
276 | set { | 410 | set { |
277 | if (value) | 411 | if (value) |
278 | CollidingObjectStep = PhysicsScene.SimulationStep; | 412 | CollidingObjectStep = PhysScene.SimulationStep; |
279 | else | 413 | else |
280 | CollidingObjectStep = 0; | 414 | CollidingObjectStep = BSScene.NotASimulationStep; |
281 | } | 415 | } |
282 | } | 416 | } |
283 | 417 | ||
284 | // The collisions that have been collected this tick | 418 | // The collisions that have been collected for the next collision reporting (throttled by subscription) |
285 | protected CollisionEventUpdate CollisionCollection; | 419 | protected CollisionEventUpdate CollisionCollection; |
286 | // Remember collisions from last tick for fancy collision based actions | 420 | // This is the collision collection last reported to the Simulator. |
421 | public CollisionEventUpdate CollisionsLastReported; | ||
422 | // Remember the collisions recorded in the last tick for fancy collision checking | ||
287 | // (like a BSCharacter walking up stairs). | 423 | // (like a BSCharacter walking up stairs). |
288 | protected CollisionEventUpdate CollisionsLastTick; | 424 | public CollisionEventUpdate CollisionsLastTick; |
425 | private long CollisionsLastTickStep = -1; | ||
289 | 426 | ||
290 | // The simulation step is telling this object about a collision. | 427 | // The simulation step is telling this object about a collision. |
291 | // Return 'true' if a collision was processed and should be sent up. | 428 | // Return 'true' if a collision was processed and should be sent up. |
292 | // Return 'false' if this object is not enabled/subscribed/appropriate for or has already seen this collision. | 429 | // Return 'false' if this object is not enabled/subscribed/appropriate for or has already seen this collision. |
293 | // Called at taint time from within the Step() function | 430 | // Called at taint time from within the Step() function |
431 | public delegate bool CollideCall(uint collidingWith, BSPhysObject collidee, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth); | ||
294 | public virtual bool Collide(uint collidingWith, BSPhysObject collidee, | 432 | public virtual bool Collide(uint collidingWith, BSPhysObject collidee, |
295 | OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) | 433 | OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) |
296 | { | 434 | { |
297 | bool ret = false; | 435 | bool ret = false; |
298 | 436 | ||
299 | // The following lines make IsColliding(), CollidingGround() and CollidingObj work | 437 | // The following lines make IsColliding(), CollidingGround() and CollidingObj work |
300 | CollidingStep = PhysicsScene.SimulationStep; | 438 | CollidingStep = PhysScene.SimulationStep; |
301 | if (collidingWith <= PhysicsScene.TerrainManager.HighestTerrainID) | 439 | if (collidingWith <= PhysScene.TerrainManager.HighestTerrainID) |
302 | { | 440 | { |
303 | CollidingGroundStep = PhysicsScene.SimulationStep; | 441 | CollidingGroundStep = PhysScene.SimulationStep; |
304 | } | 442 | } |
305 | else | 443 | else |
306 | { | 444 | { |
307 | CollidingObjectStep = PhysicsScene.SimulationStep; | 445 | CollidingObjectStep = PhysScene.SimulationStep; |
308 | } | 446 | } |
309 | 447 | ||
310 | CollisionAccumulation++; | 448 | CollisionAccumulation++; |
311 | 449 | ||
312 | // For movement tests, remember if we are colliding with an object that is moving. | 450 | // For movement tests, remember if we are colliding with an object that is moving. |
313 | ColliderIsMoving = collidee != null ? (collidee.RawVelocity != OMV.Vector3.Zero) : false; | 451 | ColliderIsMoving = collidee != null ? (collidee.RawVelocity != OMV.Vector3.Zero) : false; |
452 | ColliderIsVolumeDetect = collidee != null ? (collidee.IsVolumeDetect) : false; | ||
453 | |||
454 | // Make a collection of the collisions that happened the last simulation tick. | ||
455 | // This is different than the collection created for sending up to the simulator as it is cleared every tick. | ||
456 | if (CollisionsLastTickStep != PhysScene.SimulationStep) | ||
457 | { | ||
458 | CollisionsLastTick = new CollisionEventUpdate(); | ||
459 | CollisionsLastTickStep = PhysScene.SimulationStep; | ||
460 | } | ||
461 | CollisionsLastTick.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); | ||
314 | 462 | ||
315 | // If someone has subscribed for collision events log the collision so it will be reported up | 463 | // If someone has subscribed for collision events log the collision so it will be reported up |
316 | if (SubscribedEvents()) { | 464 | if (SubscribedEvents()) { |
@@ -332,12 +480,12 @@ public abstract class BSPhysObject : PhysicsActor | |||
332 | bool ret = true; | 480 | bool ret = true; |
333 | 481 | ||
334 | // If the 'no collision' call, force it to happen right now so quick collision_end | 482 | // If the 'no collision' call, force it to happen right now so quick collision_end |
335 | bool force = (CollisionCollection.Count == 0 && CollisionsLastTick.Count != 0); | 483 | bool force = (CollisionCollection.Count == 0 && CollisionsLastReported.Count != 0); |
336 | 484 | ||
337 | // throttle the collisions to the number of milliseconds specified in the subscription | 485 | // throttle the collisions to the number of milliseconds specified in the subscription |
338 | if (force || (PhysicsScene.SimulationNowTime >= NextCollisionOkTime)) | 486 | if (force || (PhysScene.SimulationNowTime >= NextCollisionOkTime)) |
339 | { | 487 | { |
340 | NextCollisionOkTime = PhysicsScene.SimulationNowTime + SubscribedEventsMs; | 488 | NextCollisionOkTime = PhysScene.SimulationNowTime + SubscribedEventsMs; |
341 | 489 | ||
342 | // We are called if we previously had collisions. If there are no collisions | 490 | // We are called if we previously had collisions. If there are no collisions |
343 | // this time, send up one last empty event so OpenSim can sense collision end. | 491 | // this time, send up one last empty event so OpenSim can sense collision end. |
@@ -351,11 +499,11 @@ public abstract class BSPhysObject : PhysicsActor | |||
351 | base.SendCollisionUpdate(CollisionCollection); | 499 | base.SendCollisionUpdate(CollisionCollection); |
352 | 500 | ||
353 | // Remember the collisions from this tick for some collision specific processing. | 501 | // Remember the collisions from this tick for some collision specific processing. |
354 | CollisionsLastTick = CollisionCollection; | 502 | CollisionsLastReported = CollisionCollection; |
355 | 503 | ||
356 | // The CollisionCollection instance is passed around in the simulator. | 504 | // The CollisionCollection instance is passed around in the simulator. |
357 | // Make sure we don't have a handle to that one and that a new one is used for next time. | 505 | // Make sure we don't have a handle to that one and that a new one is used for next time. |
358 | // This fixes an interesting 'gotcha'. If we call CollisionCollection.Clear() here, | 506 | // This fixes an interesting 'gotcha'. If we call CollisionCollection.Clear() here, |
359 | // a race condition is created for the other users of this instance. | 507 | // a race condition is created for the other users of this instance. |
360 | CollisionCollection = new CollisionEventUpdate(); | 508 | CollisionCollection = new CollisionEventUpdate(); |
361 | } | 509 | } |
@@ -372,10 +520,10 @@ public abstract class BSPhysObject : PhysicsActor | |||
372 | // make sure first collision happens | 520 | // make sure first collision happens |
373 | NextCollisionOkTime = Util.EnvironmentTickCountSubtract(SubscribedEventsMs); | 521 | NextCollisionOkTime = Util.EnvironmentTickCountSubtract(SubscribedEventsMs); |
374 | 522 | ||
375 | PhysicsScene.TaintedObject(TypeName+".SubscribeEvents", delegate() | 523 | PhysScene.TaintedObject(LocalID, TypeName+".SubscribeEvents", delegate() |
376 | { | 524 | { |
377 | if (PhysBody.HasPhysicalBody) | 525 | if (PhysBody.HasPhysicalBody) |
378 | CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 526 | CurrentCollisionFlags = PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); |
379 | }); | 527 | }); |
380 | } | 528 | } |
381 | else | 529 | else |
@@ -387,11 +535,11 @@ public abstract class BSPhysObject : PhysicsActor | |||
387 | public override void UnSubscribeEvents() { | 535 | public override void UnSubscribeEvents() { |
388 | // DetailLog("{0},{1}.UnSubscribeEvents,unsubscribing", LocalID, TypeName); | 536 | // DetailLog("{0},{1}.UnSubscribeEvents,unsubscribing", LocalID, TypeName); |
389 | SubscribedEventsMs = 0; | 537 | SubscribedEventsMs = 0; |
390 | PhysicsScene.TaintedObject(TypeName+".UnSubscribeEvents", delegate() | 538 | PhysScene.TaintedObject(LocalID, TypeName+".UnSubscribeEvents", delegate() |
391 | { | 539 | { |
392 | // Make sure there is a body there because sometimes destruction happens in an un-ideal order. | 540 | // Make sure there is a body there because sometimes destruction happens in an un-ideal order. |
393 | if (PhysBody.HasPhysicalBody) | 541 | if (PhysBody.HasPhysicalBody) |
394 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 542 | CurrentCollisionFlags = PhysScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); |
395 | }); | 543 | }); |
396 | } | 544 | } |
397 | // Return 'true' if the simulator wants collision events | 545 | // Return 'true' if the simulator wants collision events |
@@ -405,7 +553,7 @@ public abstract class BSPhysObject : PhysicsActor | |||
405 | { | 553 | { |
406 | // Scale the collision count by the time since the last collision. | 554 | // Scale the collision count by the time since the last collision. |
407 | // The "+1" prevents dividing by zero. | 555 | // The "+1" prevents dividing by zero. |
408 | long timeAgo = PhysicsScene.SimulationStep - CollidingStep + 1; | 556 | long timeAgo = PhysScene.SimulationStep - CollidingStep + 1; |
409 | CollisionScore = CollisionAccumulation / timeAgo; | 557 | CollisionScore = CollisionAccumulation / timeAgo; |
410 | } | 558 | } |
411 | public override float CollisionScore { get; set; } | 559 | public override float CollisionScore { get; set; } |
@@ -413,103 +561,8 @@ public abstract class BSPhysObject : PhysicsActor | |||
413 | #endregion // Collisions | 561 | #endregion // Collisions |
414 | 562 | ||
415 | #region Per Simulation Step actions | 563 | #region Per Simulation Step actions |
416 | // There are some actions that must be performed for a physical object before each simulation step. | ||
417 | // These actions are optional so, rather than scanning all the physical objects and asking them | ||
418 | // if they have anything to do, a physical object registers for an event call before the step is performed. | ||
419 | // This bookkeeping makes it easy to add, remove and clean up after all these registrations. | ||
420 | private Dictionary<string, BSScene.PreStepAction> RegisteredPrestepActions = new Dictionary<string, BSScene.PreStepAction>(); | ||
421 | private Dictionary<string, BSScene.PostStepAction> RegisteredPoststepActions = new Dictionary<string, BSScene.PostStepAction>(); | ||
422 | protected void RegisterPreStepAction(string op, uint id, BSScene.PreStepAction actn) | ||
423 | { | ||
424 | string identifier = op + "-" + id.ToString(); | ||
425 | 564 | ||
426 | lock (RegisteredPrestepActions) | 565 | public BSActorCollection PhysicalActors; |
427 | { | ||
428 | // Clean out any existing action | ||
429 | UnRegisterPreStepAction(op, id); | ||
430 | RegisteredPrestepActions[identifier] = actn; | ||
431 | PhysicsScene.BeforeStep += actn; | ||
432 | } | ||
433 | DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier); | ||
434 | } | ||
435 | |||
436 | // Unregister a pre step action. Safe to call if the action has not been registered. | ||
437 | // Returns 'true' if an action was actually removed | ||
438 | protected bool UnRegisterPreStepAction(string op, uint id) | ||
439 | { | ||
440 | string identifier = op + "-" + id.ToString(); | ||
441 | bool removed = false; | ||
442 | lock (RegisteredPrestepActions) | ||
443 | { | ||
444 | if (RegisteredPrestepActions.ContainsKey(identifier)) | ||
445 | { | ||
446 | PhysicsScene.BeforeStep -= RegisteredPrestepActions[identifier]; | ||
447 | RegisteredPrestepActions.Remove(identifier); | ||
448 | removed = true; | ||
449 | } | ||
450 | } | ||
451 | DetailLog("{0},BSPhysObject.UnRegisterPreStepAction,id={1},removed={2}", LocalID, identifier, removed); | ||
452 | return removed; | ||
453 | } | ||
454 | |||
455 | protected void UnRegisterAllPreStepActions() | ||
456 | { | ||
457 | lock (RegisteredPrestepActions) | ||
458 | { | ||
459 | foreach (KeyValuePair<string, BSScene.PreStepAction> kvp in RegisteredPrestepActions) | ||
460 | { | ||
461 | PhysicsScene.BeforeStep -= kvp.Value; | ||
462 | } | ||
463 | RegisteredPrestepActions.Clear(); | ||
464 | } | ||
465 | DetailLog("{0},BSPhysObject.UnRegisterAllPreStepActions,", LocalID); | ||
466 | } | ||
467 | |||
468 | protected void RegisterPostStepAction(string op, uint id, BSScene.PostStepAction actn) | ||
469 | { | ||
470 | string identifier = op + "-" + id.ToString(); | ||
471 | |||
472 | lock (RegisteredPoststepActions) | ||
473 | { | ||
474 | // Clean out any existing action | ||
475 | UnRegisterPostStepAction(op, id); | ||
476 | RegisteredPoststepActions[identifier] = actn; | ||
477 | PhysicsScene.AfterStep += actn; | ||
478 | } | ||
479 | DetailLog("{0},BSPhysObject.RegisterPostStepAction,id={1}", LocalID, identifier); | ||
480 | } | ||
481 | |||
482 | // Unregister a pre step action. Safe to call if the action has not been registered. | ||
483 | // Returns 'true' if an action was actually removed. | ||
484 | protected bool UnRegisterPostStepAction(string op, uint id) | ||
485 | { | ||
486 | string identifier = op + "-" + id.ToString(); | ||
487 | bool removed = false; | ||
488 | lock (RegisteredPoststepActions) | ||
489 | { | ||
490 | if (RegisteredPoststepActions.ContainsKey(identifier)) | ||
491 | { | ||
492 | PhysicsScene.AfterStep -= RegisteredPoststepActions[identifier]; | ||
493 | RegisteredPoststepActions.Remove(identifier); | ||
494 | removed = true; | ||
495 | } | ||
496 | } | ||
497 | DetailLog("{0},BSPhysObject.UnRegisterPostStepAction,id={1},removed={2}", LocalID, identifier, removed); | ||
498 | return removed; | ||
499 | } | ||
500 | |||
501 | protected void UnRegisterAllPostStepActions() | ||
502 | { | ||
503 | lock (RegisteredPoststepActions) | ||
504 | { | ||
505 | foreach (KeyValuePair<string, BSScene.PostStepAction> kvp in RegisteredPoststepActions) | ||
506 | { | ||
507 | PhysicsScene.AfterStep -= kvp.Value; | ||
508 | } | ||
509 | RegisteredPoststepActions.Clear(); | ||
510 | } | ||
511 | DetailLog("{0},BSPhysObject.UnRegisterAllPostStepActions,", LocalID); | ||
512 | } | ||
513 | 566 | ||
514 | // When an update to the physical properties happens, this event is fired to let | 567 | // When an update to the physical properties happens, this event is fired to let |
515 | // different actors to modify the update before it is passed around | 568 | // different actors to modify the update before it is passed around |
@@ -522,53 +575,13 @@ public abstract class BSPhysObject : PhysicsActor | |||
522 | actions(ref entprop); | 575 | actions(ref entprop); |
523 | } | 576 | } |
524 | 577 | ||
525 | private Dictionary<string, PreUpdatePropertyAction> RegisteredPreUpdatePropertyActions = new Dictionary<string, PreUpdatePropertyAction>(); | ||
526 | public void RegisterPreUpdatePropertyAction(string identifier, PreUpdatePropertyAction actn) | ||
527 | { | ||
528 | lock (RegisteredPreUpdatePropertyActions) | ||
529 | { | ||
530 | // Clean out any existing action | ||
531 | UnRegisterPreUpdatePropertyAction(identifier); | ||
532 | RegisteredPreUpdatePropertyActions[identifier] = actn; | ||
533 | OnPreUpdateProperty += actn; | ||
534 | } | ||
535 | DetailLog("{0},BSPhysObject.RegisterPreUpdatePropertyAction,id={1}", LocalID, identifier); | ||
536 | } | ||
537 | public bool UnRegisterPreUpdatePropertyAction(string identifier) | ||
538 | { | ||
539 | bool removed = false; | ||
540 | lock (RegisteredPreUpdatePropertyActions) | ||
541 | { | ||
542 | if (RegisteredPreUpdatePropertyActions.ContainsKey(identifier)) | ||
543 | { | ||
544 | OnPreUpdateProperty -= RegisteredPreUpdatePropertyActions[identifier]; | ||
545 | RegisteredPreUpdatePropertyActions.Remove(identifier); | ||
546 | removed = true; | ||
547 | } | ||
548 | } | ||
549 | DetailLog("{0},BSPhysObject.UnRegisterPreUpdatePropertyAction,id={1},removed={2}", LocalID, identifier, removed); | ||
550 | return removed; | ||
551 | } | ||
552 | public void UnRegisterAllPreUpdatePropertyActions() | ||
553 | { | ||
554 | lock (RegisteredPreUpdatePropertyActions) | ||
555 | { | ||
556 | foreach (KeyValuePair<string, PreUpdatePropertyAction> kvp in RegisteredPreUpdatePropertyActions) | ||
557 | { | ||
558 | OnPreUpdateProperty -= kvp.Value; | ||
559 | } | ||
560 | RegisteredPreUpdatePropertyActions.Clear(); | ||
561 | } | ||
562 | DetailLog("{0},BSPhysObject.UnRegisterAllPreUpdatePropertyAction,", LocalID); | ||
563 | } | ||
564 | |||
565 | #endregion // Per Simulation Step actions | 578 | #endregion // Per Simulation Step actions |
566 | 579 | ||
567 | // High performance detailed logging routine used by the physical objects. | 580 | // High performance detailed logging routine used by the physical objects. |
568 | protected void DetailLog(string msg, params Object[] args) | 581 | protected void DetailLog(string msg, params Object[] args) |
569 | { | 582 | { |
570 | if (PhysicsScene.PhysicsLogging.Enabled) | 583 | if (PhysScene.PhysicsLogging.Enabled) |
571 | PhysicsScene.DetailLog(msg, args); | 584 | PhysScene.DetailLog(msg, args); |
572 | } | 585 | } |
573 | 586 | ||
574 | } | 587 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 6a5461a..15b7090 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -41,7 +41,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
41 | [Serializable] | 41 | [Serializable] |
42 | public class BSPrim : BSPhysObject | 42 | public class BSPrim : BSPhysObject |
43 | { | 43 | { |
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 44 | protected static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
45 | private static readonly string LogHeader = "[BULLETS PRIM]"; | 45 | private static readonly string LogHeader = "[BULLETS PRIM]"; |
46 | 46 | ||
47 | // _size is what the user passed. Scale is what we pass to the physics engine with the mesh. | 47 | // _size is what the user passed. Scale is what we pass to the physics engine with the mesh. |
@@ -51,15 +51,8 @@ public class BSPrim : BSPhysObject | |||
51 | private bool _isSelected; | 51 | private bool _isSelected; |
52 | private bool _isVolumeDetect; | 52 | private bool _isVolumeDetect; |
53 | 53 | ||
54 | // _position is what the simulator thinks the positions of the prim is. | ||
55 | private OMV.Vector3 _position; | ||
56 | |||
57 | private float _mass; // the mass of this object | 54 | private float _mass; // the mass of this object |
58 | private OMV.Vector3 _force; | ||
59 | private OMV.Vector3 _velocity; | ||
60 | private OMV.Vector3 _torque; | ||
61 | private OMV.Vector3 _acceleration; | 55 | private OMV.Vector3 _acceleration; |
62 | private OMV.Quaternion _orientation; | ||
63 | private int _physicsActorType; | 56 | private int _physicsActorType; |
64 | private bool _isPhysical; | 57 | private bool _isPhysical; |
65 | private bool _flying; | 58 | private bool _flying; |
@@ -72,16 +65,18 @@ public class BSPrim : BSPhysObject | |||
72 | 65 | ||
73 | private int CrossingFailures { get; set; } | 66 | private int CrossingFailures { get; set; } |
74 | 67 | ||
75 | public BSDynamics VehicleController { get; private set; } | 68 | // Keep a handle to the vehicle actor so it is easy to set parameters on same. |
76 | 69 | public const string VehicleActorName = "BasicVehicle"; | |
77 | private BSVMotor _targetMotor; | ||
78 | private OMV.Vector3 _PIDTarget; | ||
79 | private float _PIDTau; | ||
80 | 70 | ||
81 | private BSFMotor _hoverMotor; | 71 | // Parameters for the hover actor |
82 | private float _PIDHoverHeight; | 72 | public const string HoverActorName = "BSPrim.HoverActor"; |
83 | private PIDHoverType _PIDHoverType; | 73 | // Parameters for the axis lock actor |
84 | private float _PIDHoverTau; | 74 | public const String LockedAxisActorName = "BSPrim.LockedAxis"; |
75 | // Parameters for the move to target actor | ||
76 | public const string MoveToTargetActorName = "BSPrim.MoveToTargetActor"; | ||
77 | // Parameters for the setForce and setTorque actors | ||
78 | public const string SetForceActorName = "BSPrim.SetForceActor"; | ||
79 | public const string SetTorqueActorName = "BSPrim.SetTorqueActor"; | ||
85 | 80 | ||
86 | public BSPrim(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, | 81 | public BSPrim(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, |
87 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) | 82 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) |
@@ -89,31 +84,34 @@ public class BSPrim : BSPhysObject | |||
89 | { | 84 | { |
90 | // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID); | 85 | // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID); |
91 | _physicsActorType = (int)ActorTypes.Prim; | 86 | _physicsActorType = (int)ActorTypes.Prim; |
92 | _position = pos; | 87 | RawPosition = pos; |
93 | _size = size; | 88 | _size = size; |
94 | Scale = size; // prims are the size the user wants them to be (different for BSCharactes). | 89 | Scale = size; // prims are the size the user wants them to be (different for BSCharactes). |
95 | _orientation = rotation; | 90 | RawOrientation = rotation; |
96 | _buoyancy = 0f; | 91 | _buoyancy = 0f; |
97 | _velocity = OMV.Vector3.Zero; | 92 | RawVelocity = OMV.Vector3.Zero; |
98 | _rotationalVelocity = OMV.Vector3.Zero; | 93 | _rotationalVelocity = OMV.Vector3.Zero; |
99 | BaseShape = pbs; | 94 | BaseShape = pbs; |
100 | _isPhysical = pisPhysical; | 95 | _isPhysical = pisPhysical; |
101 | _isVolumeDetect = false; | 96 | _isVolumeDetect = false; |
102 | 97 | ||
103 | VehicleController = new BSDynamics(PhysicsScene, this); // add vehicleness | 98 | // Add a dynamic vehicle to our set of actors that can move this prim. |
99 | // PhysicalActors.Add(VehicleActorName, new BSDynamics(PhysScene, this, VehicleActorName)); | ||
104 | 100 | ||
105 | _mass = CalculateMass(); | 101 | _mass = CalculateMass(); |
106 | 102 | ||
107 | DetailLog("{0},BSPrim.constructor,call", LocalID); | 103 | // DetailLog("{0},BSPrim.constructor,call", LocalID); |
108 | // do the actual object creation at taint time | 104 | // do the actual object creation at taint time |
109 | PhysicsScene.TaintedObject("BSPrim.create", delegate() | 105 | PhysScene.TaintedObject(LocalID, "BSPrim.create", delegate() |
110 | { | 106 | { |
111 | // Make sure the object is being created with some sanity. | 107 | // Make sure the object is being created with some sanity. |
112 | ExtremeSanityCheck(true /* inTaintTime */); | 108 | ExtremeSanityCheck(true /* inTaintTime */); |
113 | 109 | ||
114 | CreateGeomAndObject(true); | 110 | CreateGeomAndObject(true); |
115 | 111 | ||
116 | CurrentCollisionFlags = PhysicsScene.PE.GetCollisionFlags(PhysBody); | 112 | CurrentCollisionFlags = PhysScene.PE.GetCollisionFlags(PhysBody); |
113 | |||
114 | IsInitialized = true; | ||
117 | }); | 115 | }); |
118 | } | 116 | } |
119 | 117 | ||
@@ -121,19 +119,21 @@ public class BSPrim : BSPhysObject | |||
121 | public override void Destroy() | 119 | public override void Destroy() |
122 | { | 120 | { |
123 | // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID); | 121 | // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID); |
122 | IsInitialized = false; | ||
123 | |||
124 | base.Destroy(); | 124 | base.Destroy(); |
125 | 125 | ||
126 | // Undo any vehicle properties | 126 | // Undo any vehicle properties |
127 | this.VehicleType = (int)Vehicle.TYPE_NONE; | 127 | this.VehicleType = (int)Vehicle.TYPE_NONE; |
128 | 128 | ||
129 | PhysicsScene.TaintedObject("BSPrim.destroy", delegate() | 129 | PhysScene.TaintedObject(LocalID, "BSPrim.Destroy", delegate() |
130 | { | 130 | { |
131 | DetailLog("{0},BSPrim.Destroy,taint,", LocalID); | 131 | DetailLog("{0},BSPrim.Destroy,taint,", LocalID); |
132 | // If there are physical body and shape, release my use of same. | 132 | // If there are physical body and shape, release my use of same. |
133 | PhysicsScene.Shapes.DereferenceBody(PhysBody, null); | 133 | PhysScene.Shapes.DereferenceBody(PhysBody, null); |
134 | PhysBody.Clear(); | 134 | PhysBody.Clear(); |
135 | PhysicsScene.Shapes.DereferenceShape(PhysShape, null); | 135 | PhysShape.Dereference(PhysScene); |
136 | PhysShape.Clear(); | 136 | PhysShape = new BSShapeNull(); |
137 | }); | 137 | }); |
138 | } | 138 | } |
139 | 139 | ||
@@ -159,25 +159,13 @@ public class BSPrim : BSPhysObject | |||
159 | ForceBodyShapeRebuild(false); | 159 | ForceBodyShapeRebuild(false); |
160 | } | 160 | } |
161 | } | 161 | } |
162 | // 'unknown' says to choose the best type | ||
163 | public override BSPhysicsShapeType PreferredPhysicalShape | ||
164 | { get { return BSPhysicsShapeType.SHAPE_UNKNOWN; } } | ||
165 | |||
166 | public override bool ForceBodyShapeRebuild(bool inTaintTime) | 162 | public override bool ForceBodyShapeRebuild(bool inTaintTime) |
167 | { | 163 | { |
168 | if (inTaintTime) | 164 | PhysScene.TaintedObject(inTaintTime, LocalID, "BSPrim.ForceBodyShapeRebuild", delegate() |
169 | { | 165 | { |
170 | _mass = CalculateMass(); // changing the shape changes the mass | 166 | _mass = CalculateMass(); // changing the shape changes the mass |
171 | CreateGeomAndObject(true); | 167 | CreateGeomAndObject(true); |
172 | } | 168 | }); |
173 | else | ||
174 | { | ||
175 | PhysicsScene.TaintedObject("BSPrim.ForceBodyShapeRebuild", delegate() | ||
176 | { | ||
177 | _mass = CalculateMass(); // changing the shape changes the mass | ||
178 | CreateGeomAndObject(true); | ||
179 | }); | ||
180 | } | ||
181 | return true; | 169 | return true; |
182 | } | 170 | } |
183 | public override bool Grabbed { | 171 | public override bool Grabbed { |
@@ -190,7 +178,7 @@ public class BSPrim : BSPhysObject | |||
190 | if (value != _isSelected) | 178 | if (value != _isSelected) |
191 | { | 179 | { |
192 | _isSelected = value; | 180 | _isSelected = value; |
193 | PhysicsScene.TaintedObject("BSPrim.setSelected", delegate() | 181 | PhysScene.TaintedObject(LocalID, "BSPrim.setSelected", delegate() |
194 | { | 182 | { |
195 | DetailLog("{0},BSPrim.selected,taint,selected={1}", LocalID, _isSelected); | 183 | DetailLog("{0},BSPrim.selected,taint,selected={1}", LocalID, _isSelected); |
196 | SetObjectDynamic(false); | 184 | SetObjectDynamic(false); |
@@ -231,165 +219,93 @@ public class BSPrim : BSPhysObject | |||
231 | // Called at taint time! | 219 | // Called at taint time! |
232 | public override void ZeroMotion(bool inTaintTime) | 220 | public override void ZeroMotion(bool inTaintTime) |
233 | { | 221 | { |
234 | _velocity = OMV.Vector3.Zero; | 222 | RawVelocity = OMV.Vector3.Zero; |
235 | _acceleration = OMV.Vector3.Zero; | 223 | _acceleration = OMV.Vector3.Zero; |
236 | _rotationalVelocity = OMV.Vector3.Zero; | 224 | _rotationalVelocity = OMV.Vector3.Zero; |
237 | 225 | ||
238 | // Zero some other properties in the physics engine | 226 | // Zero some other properties in the physics engine |
239 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() | 227 | PhysScene.TaintedObject(inTaintTime, LocalID, "BSPrim.ZeroMotion", delegate() |
240 | { | 228 | { |
241 | if (PhysBody.HasPhysicalBody) | 229 | if (PhysBody.HasPhysicalBody) |
242 | PhysicsScene.PE.ClearAllForces(PhysBody); | 230 | PhysScene.PE.ClearAllForces(PhysBody); |
243 | }); | 231 | }); |
244 | } | 232 | } |
245 | public override void ZeroAngularMotion(bool inTaintTime) | 233 | public override void ZeroAngularMotion(bool inTaintTime) |
246 | { | 234 | { |
247 | _rotationalVelocity = OMV.Vector3.Zero; | 235 | _rotationalVelocity = OMV.Vector3.Zero; |
248 | // Zero some other properties in the physics engine | 236 | // Zero some other properties in the physics engine |
249 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() | 237 | PhysScene.TaintedObject(inTaintTime, LocalID, "BSPrim.ZeroMotion", delegate() |
250 | { | 238 | { |
251 | // DetailLog("{0},BSPrim.ZeroAngularMotion,call,rotVel={1}", LocalID, _rotationalVelocity); | 239 | // DetailLog("{0},BSPrim.ZeroAngularMotion,call,rotVel={1}", LocalID, _rotationalVelocity); |
252 | if (PhysBody.HasPhysicalBody) | 240 | if (PhysBody.HasPhysicalBody) |
253 | { | 241 | { |
254 | PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity); | 242 | PhysScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity); |
255 | PhysicsScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity); | 243 | PhysScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity); |
256 | } | 244 | } |
257 | }); | 245 | }); |
258 | } | 246 | } |
259 | 247 | ||
260 | bool TryExperimentalLockAxisCode = false; | ||
261 | BSConstraint LockAxisConstraint = null; | ||
262 | public override void LockAngularMotion(OMV.Vector3 axis) | 248 | public override void LockAngularMotion(OMV.Vector3 axis) |
263 | { | 249 | { |
264 | DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis); | 250 | DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis); |
265 | 251 | ||
266 | // "1" means free, "0" means locked | 252 | // "1" means free, "0" means locked |
267 | OMV.Vector3 locking = new OMV.Vector3(1f, 1f, 1f); | 253 | OMV.Vector3 locking = LockedAxisFree; |
268 | if (axis.X != 1) locking.X = 0f; | 254 | if (axis.X != 1) locking.X = 0f; |
269 | if (axis.Y != 1) locking.Y = 0f; | 255 | if (axis.Y != 1) locking.Y = 0f; |
270 | if (axis.Z != 1) locking.Z = 0f; | 256 | if (axis.Z != 1) locking.Z = 0f; |
271 | LockedAxis = locking; | 257 | LockedAngularAxis = locking; |
272 | 258 | ||
273 | if (TryExperimentalLockAxisCode && LockedAxis != LockedAxisFree) | 259 | EnableActor(LockedAngularAxis != LockedAxisFree, LockedAxisActorName, delegate() |
274 | { | 260 | { |
275 | // Lock that axis by creating a 6DOF constraint that has one end in the world and | 261 | return new BSActorLockAxis(PhysScene, this, LockedAxisActorName); |
276 | // the other in the object. | 262 | }); |
277 | // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817 | ||
278 | // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380 | ||
279 | |||
280 | PhysicsScene.TaintedObject("BSPrim.LockAngularMotion", delegate() | ||
281 | { | ||
282 | CleanUpLockAxisPhysicals(true /* inTaintTime */); | ||
283 | |||
284 | BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(PhysicsScene.World, PhysBody, | ||
285 | OMV.Vector3.Zero, OMV.Quaternion.Inverse(RawOrientation), | ||
286 | true /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); | ||
287 | LockAxisConstraint = axisConstrainer; | ||
288 | PhysicsScene.Constraints.AddConstraint(LockAxisConstraint); | ||
289 | |||
290 | // The constraint is tied to the world and oriented to the prim. | ||
291 | |||
292 | // Free to move linearly | ||
293 | OMV.Vector3 linearLow = OMV.Vector3.Zero; | ||
294 | OMV.Vector3 linearHigh = PhysicsScene.TerrainManager.DefaultRegionSize; | ||
295 | axisConstrainer.SetLinearLimits(linearLow, linearHigh); | ||
296 | |||
297 | // Angular with some axis locked | ||
298 | float f2PI = (float)Math.PI * 2f; | ||
299 | OMV.Vector3 angularLow = new OMV.Vector3(-f2PI, -f2PI, -f2PI); | ||
300 | OMV.Vector3 angularHigh = new OMV.Vector3(f2PI, f2PI, f2PI); | ||
301 | if (LockedAxis.X != 1f) | ||
302 | { | ||
303 | angularLow.X = 0f; | ||
304 | angularHigh.X = 0f; | ||
305 | } | ||
306 | if (LockedAxis.Y != 1f) | ||
307 | { | ||
308 | angularLow.Y = 0f; | ||
309 | angularHigh.Y = 0f; | ||
310 | } | ||
311 | if (LockedAxis.Z != 1f) | ||
312 | { | ||
313 | angularLow.Z = 0f; | ||
314 | angularHigh.Z = 0f; | ||
315 | } | ||
316 | axisConstrainer.SetAngularLimits(angularLow, angularHigh); | ||
317 | |||
318 | DetailLog("{0},BSPrim.LockAngularMotion,create,linLow={1},linHi={2},angLow={3},angHi={4}", | ||
319 | LocalID, linearLow, linearHigh, angularLow, angularHigh); | ||
320 | |||
321 | // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. | ||
322 | axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); | ||
323 | 263 | ||
324 | axisConstrainer.RecomputeConstraintVariables(RawMass); | 264 | // Update parameters so the new actor's Refresh() action is called at the right time. |
325 | }); | 265 | PhysScene.TaintedObject(LocalID, "BSPrim.LockAngularMotion", delegate() |
326 | } | ||
327 | else | ||
328 | { | 266 | { |
329 | // Everything seems unlocked | 267 | UpdatePhysicalParameters(); |
330 | CleanUpLockAxisPhysicals(false /* inTaintTime */); | 268 | }); |
331 | } | ||
332 | 269 | ||
333 | return; | 270 | return; |
334 | } | 271 | } |
335 | // Get rid of any constraint built for LockAxis | ||
336 | // Most often the constraint is removed when the constraint collection is cleaned for this prim. | ||
337 | private void CleanUpLockAxisPhysicals(bool inTaintTime) | ||
338 | { | ||
339 | if (LockAxisConstraint != null) | ||
340 | { | ||
341 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.CleanUpLockAxisPhysicals", delegate() | ||
342 | { | ||
343 | if (LockAxisConstraint != null) | ||
344 | { | ||
345 | PhysicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); | ||
346 | LockAxisConstraint = null; | ||
347 | DetailLog("{0},BSPrim.CleanUpLockAxisPhysicals,destroyingConstraint", LocalID); | ||
348 | } | ||
349 | }); | ||
350 | } | ||
351 | } | ||
352 | 272 | ||
353 | public override OMV.Vector3 RawPosition | ||
354 | { | ||
355 | get { return _position; } | ||
356 | set { _position = value; } | ||
357 | } | ||
358 | public override OMV.Vector3 Position { | 273 | public override OMV.Vector3 Position { |
359 | get { | 274 | get { |
360 | // don't do the GetObjectPosition for root elements because this function is called a zillion times. | 275 | // don't do the GetObjectPosition for root elements because this function is called a zillion times. |
361 | // _position = ForcePosition; | 276 | // RawPosition = ForcePosition; |
362 | return _position; | 277 | return RawPosition; |
363 | } | 278 | } |
364 | set { | 279 | set { |
365 | // If the position must be forced into the physics engine, use ForcePosition. | 280 | // If the position must be forced into the physics engine, use ForcePosition. |
366 | // All positions are given in world positions. | 281 | // All positions are given in world positions. |
367 | if (_position == value) | 282 | if (RawPosition == value) |
368 | { | 283 | { |
369 | DetailLog("{0},BSPrim.setPosition,call,positionNotChanging,pos={1},orient={2}", LocalID, _position, _orientation); | 284 | DetailLog("{0},BSPrim.setPosition,call,positionNotChanging,pos={1},orient={2}", LocalID, RawPosition, RawOrientation); |
370 | return; | 285 | return; |
371 | } | 286 | } |
372 | _position = value; | 287 | RawPosition = value; |
373 | PositionSanityCheck(false); | 288 | PositionSanityCheck(false); |
374 | 289 | ||
375 | PhysicsScene.TaintedObject("BSPrim.setPosition", delegate() | 290 | PhysScene.TaintedObject(LocalID, "BSPrim.setPosition", delegate() |
376 | { | 291 | { |
377 | DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 292 | DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, RawPosition, RawOrientation); |
378 | ForcePosition = _position; | 293 | ForcePosition = RawPosition; |
379 | }); | 294 | }); |
380 | } | 295 | } |
381 | } | 296 | } |
382 | 297 | ||
298 | // NOTE: overloaded by BSPrimDisplaced to handle offset for center-of-gravity. | ||
383 | public override OMV.Vector3 ForcePosition { | 299 | public override OMV.Vector3 ForcePosition { |
384 | get { | 300 | get { |
385 | _position = PhysicsScene.PE.GetPosition(PhysBody); | 301 | RawPosition = PhysScene.PE.GetPosition(PhysBody); |
386 | return _position; | 302 | return RawPosition; |
387 | } | 303 | } |
388 | set { | 304 | set { |
389 | _position = value; | 305 | RawPosition = value; |
390 | if (PhysBody.HasPhysicalBody) | 306 | if (PhysBody.HasPhysicalBody) |
391 | { | 307 | { |
392 | PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); | 308 | PhysScene.PE.SetTranslation(PhysBody, RawPosition, RawOrientation); |
393 | ActivateIfPhysical(false); | 309 | ActivateIfPhysical(false); |
394 | } | 310 | } |
395 | } | 311 | } |
@@ -406,7 +322,7 @@ public class BSPrim : BSPhysObject | |||
406 | if (!IsPhysicallyActive) | 322 | if (!IsPhysicallyActive) |
407 | return ret; | 323 | return ret; |
408 | 324 | ||
409 | if (!PhysicsScene.TerrainManager.IsWithinKnownTerrain(RawPosition)) | 325 | if (!PhysScene.TerrainManager.IsWithinKnownTerrain(RawPosition)) |
410 | { | 326 | { |
411 | // The physical object is out of the known/simulated area. | 327 | // The physical object is out of the known/simulated area. |
412 | // Upper levels of code will handle the transition to other areas so, for | 328 | // Upper levels of code will handle the transition to other areas so, for |
@@ -414,7 +330,7 @@ public class BSPrim : BSPhysObject | |||
414 | return ret; | 330 | return ret; |
415 | } | 331 | } |
416 | 332 | ||
417 | float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(RawPosition); | 333 | float terrainHeight = PhysScene.TerrainManager.GetTerrainHeightAtXYZ(RawPosition); |
418 | OMV.Vector3 upForce = OMV.Vector3.Zero; | 334 | OMV.Vector3 upForce = OMV.Vector3.Zero; |
419 | float approxSize = Math.Max(Size.X, Math.Max(Size.Y, Size.Z)); | 335 | float approxSize = Math.Max(Size.X, Math.Max(Size.Y, Size.Z)); |
420 | if ((RawPosition.Z + approxSize / 2f) < terrainHeight) | 336 | if ((RawPosition.Z + approxSize / 2f) < terrainHeight) |
@@ -423,10 +339,10 @@ public class BSPrim : BSPhysObject | |||
423 | float targetHeight = terrainHeight + (Size.Z / 2f); | 339 | float targetHeight = terrainHeight + (Size.Z / 2f); |
424 | // If the object is below ground it just has to be moved up because pushing will | 340 | // If the object is below ground it just has to be moved up because pushing will |
425 | // not get it through the terrain | 341 | // not get it through the terrain |
426 | _position.Z = targetHeight; | 342 | RawPosition = new OMV.Vector3(RawPosition.X, RawPosition.Y, targetHeight); |
427 | if (inTaintTime) | 343 | if (inTaintTime) |
428 | { | 344 | { |
429 | ForcePosition = _position; | 345 | ForcePosition = RawPosition; |
430 | } | 346 | } |
431 | // If we are throwing the object around, zero its other forces | 347 | // If we are throwing the object around, zero its other forces |
432 | ZeroMotion(inTaintTime); | 348 | ZeroMotion(inTaintTime); |
@@ -435,7 +351,7 @@ public class BSPrim : BSPhysObject | |||
435 | 351 | ||
436 | if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0) | 352 | if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0) |
437 | { | 353 | { |
438 | float waterHeight = PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(_position); | 354 | float waterHeight = PhysScene.TerrainManager.GetWaterLevelAtXYZ(RawPosition); |
439 | // TODO: a floating motor so object will bob in the water | 355 | // TODO: a floating motor so object will bob in the water |
440 | if (Math.Abs(RawPosition.Z - waterHeight) > 0.1f) | 356 | if (Math.Abs(RawPosition.Z - waterHeight) > 0.1f) |
441 | { | 357 | { |
@@ -443,8 +359,8 @@ public class BSPrim : BSPhysObject | |||
443 | upForce.Z = (waterHeight - RawPosition.Z) * 1f; | 359 | upForce.Z = (waterHeight - RawPosition.Z) * 1f; |
444 | 360 | ||
445 | // Apply upforce and overcome gravity. | 361 | // Apply upforce and overcome gravity. |
446 | OMV.Vector3 correctionForce = upForce - PhysicsScene.DefaultGravity; | 362 | OMV.Vector3 correctionForce = upForce - PhysScene.DefaultGravity; |
447 | DetailLog("{0},BSPrim.PositionSanityCheck,applyForce,pos={1},upForce={2},correctionForce={3}", LocalID, _position, upForce, correctionForce); | 363 | DetailLog("{0},BSPrim.PositionSanityCheck,applyForce,pos={1},upForce={2},correctionForce={3}", LocalID, RawPosition, upForce, correctionForce); |
448 | AddForce(correctionForce, false, inTaintTime); | 364 | AddForce(correctionForce, false, inTaintTime); |
449 | ret = true; | 365 | ret = true; |
450 | } | 366 | } |
@@ -463,17 +379,17 @@ public class BSPrim : BSPhysObject | |||
463 | uint wayOutThere = Constants.RegionSize * Constants.RegionSize; | 379 | uint wayOutThere = Constants.RegionSize * Constants.RegionSize; |
464 | // There have been instances of objects getting thrown way out of bounds and crashing | 380 | // There have been instances of objects getting thrown way out of bounds and crashing |
465 | // the border crossing code. | 381 | // the border crossing code. |
466 | if ( _position.X < -Constants.RegionSize || _position.X > wayOutThere | 382 | if ( RawPosition.X < -Constants.RegionSize || RawPosition.X > wayOutThere |
467 | || _position.Y < -Constants.RegionSize || _position.Y > wayOutThere | 383 | || RawPosition.Y < -Constants.RegionSize || RawPosition.Y > wayOutThere |
468 | || _position.Z < -Constants.RegionSize || _position.Z > wayOutThere) | 384 | || RawPosition.Z < -Constants.RegionSize || RawPosition.Z > wayOutThere) |
469 | { | 385 | { |
470 | _position = new OMV.Vector3(10, 10, 50); | 386 | RawPosition = new OMV.Vector3(10, 10, 50); |
471 | ZeroMotion(inTaintTime); | 387 | ZeroMotion(inTaintTime); |
472 | ret = true; | 388 | ret = true; |
473 | } | 389 | } |
474 | if (_velocity.LengthSquared() > BSParam.MaxLinearVelocity) | 390 | if (RawVelocity.LengthSquared() > BSParam.MaxLinearVelocity) |
475 | { | 391 | { |
476 | _velocity = Util.ClampV(_velocity, BSParam.MaxLinearVelocity); | 392 | RawVelocity = Util.ClampV(RawVelocity, BSParam.MaxLinearVelocity); |
477 | ret = true; | 393 | ret = true; |
478 | } | 394 | } |
479 | if (_rotationalVelocity.LengthSquared() > BSParam.MaxAngularVelocitySquared) | 395 | if (_rotationalVelocity.LengthSquared() > BSParam.MaxAngularVelocitySquared) |
@@ -498,7 +414,7 @@ public class BSPrim : BSPhysObject | |||
498 | get { return _mass; } | 414 | get { return _mass; } |
499 | } | 415 | } |
500 | // used when we only want this prim's mass and not the linkset thing | 416 | // used when we only want this prim's mass and not the linkset thing |
501 | public override float RawMass { | 417 | public override float RawMass { |
502 | get { return _mass; } | 418 | get { return _mass; } |
503 | } | 419 | } |
504 | // Set the physical mass to the passed mass. | 420 | // Set the physical mass to the passed mass. |
@@ -509,10 +425,10 @@ public class BSPrim : BSPhysObject | |||
509 | { | 425 | { |
510 | if (IsStatic) | 426 | if (IsStatic) |
511 | { | 427 | { |
512 | PhysicsScene.PE.SetGravity(PhysBody, PhysicsScene.DefaultGravity); | 428 | PhysScene.PE.SetGravity(PhysBody, PhysScene.DefaultGravity); |
513 | Inertia = OMV.Vector3.Zero; | 429 | Inertia = OMV.Vector3.Zero; |
514 | PhysicsScene.PE.SetMassProps(PhysBody, 0f, Inertia); | 430 | PhysScene.PE.SetMassProps(PhysBody, 0f, Inertia); |
515 | PhysicsScene.PE.UpdateInertiaTensor(PhysBody); | 431 | PhysScene.PE.UpdateInertiaTensor(PhysBody); |
516 | } | 432 | } |
517 | else | 433 | else |
518 | { | 434 | { |
@@ -521,16 +437,19 @@ public class BSPrim : BSPhysObject | |||
521 | // Changing interesting properties doesn't change proxy and collision cache | 437 | // Changing interesting properties doesn't change proxy and collision cache |
522 | // information. The Bullet solution is to re-add the object to the world | 438 | // information. The Bullet solution is to re-add the object to the world |
523 | // after parameters are changed. | 439 | // after parameters are changed. |
524 | PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, PhysBody); | 440 | PhysScene.PE.RemoveObjectFromWorld(PhysScene.World, PhysBody); |
525 | } | 441 | } |
526 | 442 | ||
527 | // The computation of mass props requires gravity to be set on the object. | 443 | // The computation of mass props requires gravity to be set on the object. |
528 | Gravity = ComputeGravity(Buoyancy); | 444 | Gravity = ComputeGravity(Buoyancy); |
529 | PhysicsScene.PE.SetGravity(PhysBody, Gravity); | 445 | PhysScene.PE.SetGravity(PhysBody, Gravity); |
530 | 446 | ||
531 | Inertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass); | 447 | // OMV.Vector3 currentScale = PhysScene.PE.GetLocalScaling(PhysShape.physShapeInfo); // DEBUG DEBUG |
532 | PhysicsScene.PE.SetMassProps(PhysBody, physMass, Inertia); | 448 | // DetailLog("{0},BSPrim.UpdateMassProperties,currentScale{1},shape={2}", LocalID, currentScale, PhysShape.physShapeInfo); // DEBUG DEBUG |
533 | PhysicsScene.PE.UpdateInertiaTensor(PhysBody); | 449 | |
450 | Inertia = PhysScene.PE.CalculateLocalInertia(PhysShape.physShapeInfo, physMass); | ||
451 | PhysScene.PE.SetMassProps(PhysBody, physMass, Inertia); | ||
452 | PhysScene.PE.UpdateInertiaTensor(PhysBody); | ||
534 | 453 | ||
535 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", | 454 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", |
536 | LocalID, physMass, Inertia, Gravity, inWorld); | 455 | LocalID, physMass, Inertia, Gravity, inWorld); |
@@ -546,7 +465,7 @@ public class BSPrim : BSPhysObject | |||
546 | // Return what gravity should be set to this very moment | 465 | // Return what gravity should be set to this very moment |
547 | public OMV.Vector3 ComputeGravity(float buoyancy) | 466 | public OMV.Vector3 ComputeGravity(float buoyancy) |
548 | { | 467 | { |
549 | OMV.Vector3 ret = PhysicsScene.DefaultGravity; | 468 | OMV.Vector3 ret = PhysScene.DefaultGravity; |
550 | 469 | ||
551 | if (!IsStatic) | 470 | if (!IsStatic) |
552 | { | 471 | { |
@@ -570,95 +489,121 @@ public class BSPrim : BSPhysObject | |||
570 | } | 489 | } |
571 | 490 | ||
572 | public override OMV.Vector3 Force { | 491 | public override OMV.Vector3 Force { |
573 | get { return _force; } | 492 | get { return RawForce; } |
574 | set { | 493 | set { |
575 | _force = value; | 494 | RawForce = value; |
576 | if (_force != OMV.Vector3.Zero) | 495 | EnableActor(RawForce != OMV.Vector3.Zero, SetForceActorName, delegate() |
577 | { | 496 | { |
578 | // If the force is non-zero, it must be reapplied each tick because | 497 | return new BSActorSetForce(PhysScene, this, SetForceActorName); |
579 | // Bullet clears the forces applied last frame. | 498 | }); |
580 | RegisterPreStepAction("BSPrim.setForce", LocalID, | 499 | } |
581 | delegate(float timeStep) | 500 | } |
582 | { | ||
583 | if (!IsPhysicallyActive || _force == OMV.Vector3.Zero) | ||
584 | { | ||
585 | UnRegisterPreStepAction("BSPrim.setForce", LocalID); | ||
586 | return; | ||
587 | } | ||
588 | 501 | ||
589 | DetailLog("{0},BSPrim.setForce,preStep,force={1}", LocalID, _force); | 502 | // Find and return a handle to the current vehicle actor. |
590 | if (PhysBody.HasPhysicalBody) | 503 | // Return 'null' if there is no vehicle actor. |
591 | { | 504 | public BSDynamics GetVehicleActor(bool createIfNone) |
592 | PhysicsScene.PE.ApplyCentralForce(PhysBody, _force); | 505 | { |
593 | ActivateIfPhysical(false); | 506 | BSDynamics ret = null; |
594 | } | 507 | BSActor actor; |
595 | } | 508 | if (PhysicalActors.TryGetActor(VehicleActorName, out actor)) |
596 | ); | 509 | { |
597 | } | 510 | ret = actor as BSDynamics; |
598 | else | 511 | } |
512 | else | ||
513 | { | ||
514 | if (createIfNone) | ||
599 | { | 515 | { |
600 | UnRegisterPreStepAction("BSPrim.setForce", LocalID); | 516 | ret = new BSDynamics(PhysScene, this, VehicleActorName); |
517 | PhysicalActors.Add(ret.ActorName, ret); | ||
601 | } | 518 | } |
602 | } | 519 | } |
520 | return ret; | ||
603 | } | 521 | } |
604 | 522 | ||
605 | public override int VehicleType { | 523 | public override int VehicleType { |
606 | get { | 524 | get { |
607 | return (int)VehicleController.Type; // if we are a vehicle, return that type | 525 | int ret = (int)Vehicle.TYPE_NONE; |
526 | BSDynamics vehicleActor = GetVehicleActor(false /* createIfNone */); | ||
527 | if (vehicleActor != null) | ||
528 | ret = (int)vehicleActor.Type; | ||
529 | return ret; | ||
608 | } | 530 | } |
609 | set { | 531 | set { |
610 | Vehicle type = (Vehicle)value; | 532 | Vehicle type = (Vehicle)value; |
611 | 533 | ||
612 | PhysicsScene.TaintedObject("setVehicleType", delegate() | 534 | PhysScene.TaintedObject(LocalID, "setVehicleType", delegate() |
613 | { | 535 | { |
614 | // Done at taint time so we're sure the physics engine is not using the variables | 536 | // Some vehicle scripts change vehicle type on the fly as an easy way to |
615 | // Vehicle code changes the parameters for this vehicle type. | 537 | // change all the parameters. Like a plane changing to CAR when on the |
616 | VehicleController.ProcessTypeChange(type); | 538 | // ground. In this case, don't want to zero motion. |
617 | ActivateIfPhysical(false); | 539 | // ZeroMotion(true /* inTaintTime */); |
618 | 540 | if (type == Vehicle.TYPE_NONE) | |
619 | // If an active vehicle, register the vehicle code to be called before each step | ||
620 | if (VehicleController.Type == Vehicle.TYPE_NONE) | ||
621 | { | 541 | { |
622 | UnRegisterPreStepAction("BSPrim.Vehicle", LocalID); | 542 | // Vehicle type is 'none' so get rid of any actor that may have been allocated. |
623 | UnRegisterPostStepAction("BSPrim.Vehicle", LocalID); | 543 | BSDynamics vehicleActor = GetVehicleActor(false /* createIfNone */); |
544 | if (vehicleActor != null) | ||
545 | { | ||
546 | PhysicalActors.RemoveAndRelease(vehicleActor.ActorName); | ||
547 | } | ||
624 | } | 548 | } |
625 | else | 549 | else |
626 | { | 550 | { |
627 | RegisterPreStepAction("BSPrim.Vehicle", LocalID, VehicleController.Step); | 551 | // Vehicle type is not 'none' so create an actor and set it running. |
628 | RegisterPostStepAction("BSPrim.Vehicle", LocalID, VehicleController.PostStep); | 552 | BSDynamics vehicleActor = GetVehicleActor(true /* createIfNone */); |
553 | if (vehicleActor != null) | ||
554 | { | ||
555 | vehicleActor.ProcessTypeChange(type); | ||
556 | ActivateIfPhysical(false); | ||
557 | } | ||
629 | } | 558 | } |
630 | }); | 559 | }); |
631 | } | 560 | } |
632 | } | 561 | } |
633 | public override void VehicleFloatParam(int param, float value) | 562 | public override void VehicleFloatParam(int param, float value) |
634 | { | 563 | { |
635 | PhysicsScene.TaintedObject("BSPrim.VehicleFloatParam", delegate() | 564 | PhysScene.TaintedObject(LocalID, "BSPrim.VehicleFloatParam", delegate() |
636 | { | 565 | { |
637 | VehicleController.ProcessFloatVehicleParam((Vehicle)param, value); | 566 | BSDynamics vehicleActor = GetVehicleActor(true /* createIfNone */); |
638 | ActivateIfPhysical(false); | 567 | if (vehicleActor != null) |
568 | { | ||
569 | vehicleActor.ProcessFloatVehicleParam((Vehicle)param, value); | ||
570 | ActivateIfPhysical(false); | ||
571 | } | ||
639 | }); | 572 | }); |
640 | } | 573 | } |
641 | public override void VehicleVectorParam(int param, OMV.Vector3 value) | 574 | public override void VehicleVectorParam(int param, OMV.Vector3 value) |
642 | { | 575 | { |
643 | PhysicsScene.TaintedObject("BSPrim.VehicleVectorParam", delegate() | 576 | PhysScene.TaintedObject(LocalID, "BSPrim.VehicleVectorParam", delegate() |
644 | { | 577 | { |
645 | VehicleController.ProcessVectorVehicleParam((Vehicle)param, value); | 578 | BSDynamics vehicleActor = GetVehicleActor(true /* createIfNone */); |
646 | ActivateIfPhysical(false); | 579 | if (vehicleActor != null) |
580 | { | ||
581 | vehicleActor.ProcessVectorVehicleParam((Vehicle)param, value); | ||
582 | ActivateIfPhysical(false); | ||
583 | } | ||
647 | }); | 584 | }); |
648 | } | 585 | } |
649 | public override void VehicleRotationParam(int param, OMV.Quaternion rotation) | 586 | public override void VehicleRotationParam(int param, OMV.Quaternion rotation) |
650 | { | 587 | { |
651 | PhysicsScene.TaintedObject("BSPrim.VehicleRotationParam", delegate() | 588 | PhysScene.TaintedObject(LocalID, "BSPrim.VehicleRotationParam", delegate() |
652 | { | 589 | { |
653 | VehicleController.ProcessRotationVehicleParam((Vehicle)param, rotation); | 590 | BSDynamics vehicleActor = GetVehicleActor(true /* createIfNone */); |
654 | ActivateIfPhysical(false); | 591 | if (vehicleActor != null) |
592 | { | ||
593 | vehicleActor.ProcessRotationVehicleParam((Vehicle)param, rotation); | ||
594 | ActivateIfPhysical(false); | ||
595 | } | ||
655 | }); | 596 | }); |
656 | } | 597 | } |
657 | public override void VehicleFlags(int param, bool remove) | 598 | public override void VehicleFlags(int param, bool remove) |
658 | { | 599 | { |
659 | PhysicsScene.TaintedObject("BSPrim.VehicleFlags", delegate() | 600 | PhysScene.TaintedObject(LocalID, "BSPrim.VehicleFlags", delegate() |
660 | { | 601 | { |
661 | VehicleController.ProcessVehicleFlags(param, remove); | 602 | BSDynamics vehicleActor = GetVehicleActor(true /* createIfNone */); |
603 | if (vehicleActor != null) | ||
604 | { | ||
605 | vehicleActor.ProcessVehicleFlags(param, remove); | ||
606 | } | ||
662 | }); | 607 | }); |
663 | } | 608 | } |
664 | 609 | ||
@@ -668,7 +613,7 @@ public class BSPrim : BSPhysObject | |||
668 | if (_isVolumeDetect != newValue) | 613 | if (_isVolumeDetect != newValue) |
669 | { | 614 | { |
670 | _isVolumeDetect = newValue; | 615 | _isVolumeDetect = newValue; |
671 | PhysicsScene.TaintedObject("BSPrim.SetVolumeDetect", delegate() | 616 | PhysScene.TaintedObject(LocalID, "BSPrim.SetVolumeDetect", delegate() |
672 | { | 617 | { |
673 | // DetailLog("{0},setVolumeDetect,taint,volDetect={1}", LocalID, _isVolumeDetect); | 618 | // DetailLog("{0},setVolumeDetect,taint,volDetect={1}", LocalID, _isVolumeDetect); |
674 | SetObjectDynamic(true); | 619 | SetObjectDynamic(true); |
@@ -676,10 +621,14 @@ public class BSPrim : BSPhysObject | |||
676 | } | 621 | } |
677 | return; | 622 | return; |
678 | } | 623 | } |
624 | public override bool IsVolumeDetect | ||
625 | { | ||
626 | get { return _isVolumeDetect; } | ||
627 | } | ||
679 | public override void SetMaterial(int material) | 628 | public override void SetMaterial(int material) |
680 | { | 629 | { |
681 | base.SetMaterial(material); | 630 | base.SetMaterial(material); |
682 | PhysicsScene.TaintedObject("BSPrim.SetMaterial", delegate() | 631 | PhysScene.TaintedObject(LocalID, "BSPrim.SetMaterial", delegate() |
683 | { | 632 | { |
684 | UpdatePhysicalParameters(); | 633 | UpdatePhysicalParameters(); |
685 | }); | 634 | }); |
@@ -692,7 +641,7 @@ public class BSPrim : BSPhysObject | |||
692 | if (base.Friction != value) | 641 | if (base.Friction != value) |
693 | { | 642 | { |
694 | base.Friction = value; | 643 | base.Friction = value; |
695 | PhysicsScene.TaintedObject("BSPrim.setFriction", delegate() | 644 | PhysScene.TaintedObject(LocalID, "BSPrim.setFriction", delegate() |
696 | { | 645 | { |
697 | UpdatePhysicalParameters(); | 646 | UpdatePhysicalParameters(); |
698 | }); | 647 | }); |
@@ -707,7 +656,7 @@ public class BSPrim : BSPhysObject | |||
707 | if (base.Restitution != value) | 656 | if (base.Restitution != value) |
708 | { | 657 | { |
709 | base.Restitution = value; | 658 | base.Restitution = value; |
710 | PhysicsScene.TaintedObject("BSPrim.setRestitution", delegate() | 659 | PhysScene.TaintedObject(LocalID, "BSPrim.setRestitution", delegate() |
711 | { | 660 | { |
712 | UpdatePhysicalParameters(); | 661 | UpdatePhysicalParameters(); |
713 | }); | 662 | }); |
@@ -724,7 +673,7 @@ public class BSPrim : BSPhysObject | |||
724 | if (base.Density != value) | 673 | if (base.Density != value) |
725 | { | 674 | { |
726 | base.Density = value; | 675 | base.Density = value; |
727 | PhysicsScene.TaintedObject("BSPrim.setDensity", delegate() | 676 | PhysScene.TaintedObject(LocalID, "BSPrim.setDensity", delegate() |
728 | { | 677 | { |
729 | UpdatePhysicalParameters(); | 678 | UpdatePhysicalParameters(); |
730 | }); | 679 | }); |
@@ -739,93 +688,66 @@ public class BSPrim : BSPhysObject | |||
739 | if (base.GravModifier != value) | 688 | if (base.GravModifier != value) |
740 | { | 689 | { |
741 | base.GravModifier = value; | 690 | base.GravModifier = value; |
742 | PhysicsScene.TaintedObject("BSPrim.setGravityModifier", delegate() | 691 | PhysScene.TaintedObject(LocalID, "BSPrim.setGravityModifier", delegate() |
743 | { | 692 | { |
744 | UpdatePhysicalParameters(); | 693 | UpdatePhysicalParameters(); |
745 | }); | 694 | }); |
746 | } | 695 | } |
747 | } | 696 | } |
748 | } | 697 | } |
749 | public override OMV.Vector3 RawVelocity | ||
750 | { | ||
751 | get { return _velocity; } | ||
752 | set { _velocity = value; } | ||
753 | } | ||
754 | public override OMV.Vector3 Velocity { | 698 | public override OMV.Vector3 Velocity { |
755 | get { return _velocity; } | 699 | get { return RawVelocity; } |
756 | set { | 700 | set { |
757 | _velocity = value; | 701 | RawVelocity = value; |
758 | PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate() | 702 | PhysScene.TaintedObject(LocalID, "BSPrim.setVelocity", delegate() |
759 | { | 703 | { |
760 | // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); | 704 | // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, RawVelocity); |
761 | ForceVelocity = _velocity; | 705 | ForceVelocity = RawVelocity; |
762 | }); | 706 | }); |
763 | } | 707 | } |
764 | } | 708 | } |
765 | public override OMV.Vector3 ForceVelocity { | 709 | public override OMV.Vector3 ForceVelocity { |
766 | get { return _velocity; } | 710 | get { return RawVelocity; } |
767 | set { | 711 | set { |
768 | PhysicsScene.AssertInTaintTime("BSPrim.ForceVelocity"); | 712 | PhysScene.AssertInTaintTime("BSPrim.ForceVelocity"); |
769 | 713 | ||
770 | _velocity = Util.ClampV(value, BSParam.MaxLinearVelocity); | 714 | RawVelocity = Util.ClampV(value, BSParam.MaxLinearVelocity); |
771 | if (PhysBody.HasPhysicalBody) | 715 | if (PhysBody.HasPhysicalBody) |
772 | { | 716 | { |
773 | DetailLog("{0},BSPrim.ForceVelocity,taint,vel={1}", LocalID, _velocity); | 717 | DetailLog("{0},BSPrim.ForceVelocity,taint,vel={1}", LocalID, RawVelocity); |
774 | PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity); | 718 | PhysScene.PE.SetLinearVelocity(PhysBody, RawVelocity); |
775 | ActivateIfPhysical(false); | 719 | ActivateIfPhysical(false); |
776 | } | 720 | } |
777 | } | 721 | } |
778 | } | 722 | } |
779 | public override OMV.Vector3 Torque { | 723 | public override OMV.Vector3 Torque { |
780 | get { return _torque; } | 724 | get { return RawTorque; } |
781 | set { | 725 | set { |
782 | _torque = value; | 726 | RawTorque = value; |
783 | if (_torque != OMV.Vector3.Zero) | 727 | EnableActor(RawTorque != OMV.Vector3.Zero, SetTorqueActorName, delegate() |
784 | { | 728 | { |
785 | // If the torque is non-zero, it must be reapplied each tick because | 729 | return new BSActorSetTorque(PhysScene, this, SetTorqueActorName); |
786 | // Bullet clears the forces applied last frame. | 730 | }); |
787 | RegisterPreStepAction("BSPrim.setTorque", LocalID, | 731 | DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, RawTorque); |
788 | delegate(float timeStep) | ||
789 | { | ||
790 | if (!IsPhysicallyActive || _torque == OMV.Vector3.Zero) | ||
791 | { | ||
792 | UnRegisterPreStepAction("BSPrim.setTorque", LocalID); | ||
793 | return; | ||
794 | } | ||
795 | |||
796 | if (PhysBody.HasPhysicalBody) | ||
797 | AddAngularForce(_torque, false, true); | ||
798 | } | ||
799 | ); | ||
800 | } | ||
801 | else | ||
802 | { | ||
803 | UnRegisterPreStepAction("BSPrim.setTorque", LocalID); | ||
804 | } | ||
805 | // DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque); | ||
806 | } | 732 | } |
807 | } | 733 | } |
808 | public override OMV.Vector3 Acceleration { | 734 | public override OMV.Vector3 Acceleration { |
809 | get { return _acceleration; } | 735 | get { return _acceleration; } |
810 | set { _acceleration = value; } | 736 | set { _acceleration = value; } |
811 | } | 737 | } |
812 | public override OMV.Quaternion RawOrientation | 738 | |
813 | { | ||
814 | get { return _orientation; } | ||
815 | set { _orientation = value; } | ||
816 | } | ||
817 | public override OMV.Quaternion Orientation { | 739 | public override OMV.Quaternion Orientation { |
818 | get { | 740 | get { |
819 | return _orientation; | 741 | return RawOrientation; |
820 | } | 742 | } |
821 | set { | 743 | set { |
822 | if (_orientation == value) | 744 | if (RawOrientation == value) |
823 | return; | 745 | return; |
824 | _orientation = value; | 746 | RawOrientation = value; |
825 | 747 | ||
826 | PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() | 748 | PhysScene.TaintedObject(LocalID, "BSPrim.setOrientation", delegate() |
827 | { | 749 | { |
828 | ForceOrientation = _orientation; | 750 | ForceOrientation = RawOrientation; |
829 | }); | 751 | }); |
830 | } | 752 | } |
831 | } | 753 | } |
@@ -834,14 +756,14 @@ public class BSPrim : BSPhysObject | |||
834 | { | 756 | { |
835 | get | 757 | get |
836 | { | 758 | { |
837 | _orientation = PhysicsScene.PE.GetOrientation(PhysBody); | 759 | RawOrientation = PhysScene.PE.GetOrientation(PhysBody); |
838 | return _orientation; | 760 | return RawOrientation; |
839 | } | 761 | } |
840 | set | 762 | set |
841 | { | 763 | { |
842 | _orientation = value; | 764 | RawOrientation = value; |
843 | if (PhysBody.HasPhysicalBody) | 765 | if (PhysBody.HasPhysicalBody) |
844 | PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); | 766 | PhysScene.PE.SetTranslation(PhysBody, RawPosition, RawOrientation); |
845 | } | 767 | } |
846 | } | 768 | } |
847 | public override int PhysicsActorType { | 769 | public override int PhysicsActorType { |
@@ -854,7 +776,7 @@ public class BSPrim : BSPhysObject | |||
854 | if (_isPhysical != value) | 776 | if (_isPhysical != value) |
855 | { | 777 | { |
856 | _isPhysical = value; | 778 | _isPhysical = value; |
857 | PhysicsScene.TaintedObject("BSPrim.setIsPhysical", delegate() | 779 | PhysScene.TaintedObject(LocalID, "BSPrim.setIsPhysical", delegate() |
858 | { | 780 | { |
859 | DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical); | 781 | DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical); |
860 | SetObjectDynamic(true); | 782 | SetObjectDynamic(true); |
@@ -898,24 +820,25 @@ public class BSPrim : BSPhysObject | |||
898 | // isSolid: other objects bounce off of this object | 820 | // isSolid: other objects bounce off of this object |
899 | // isVolumeDetect: other objects pass through but can generate collisions | 821 | // isVolumeDetect: other objects pass through but can generate collisions |
900 | // collisionEvents: whether this object returns collision events | 822 | // collisionEvents: whether this object returns collision events |
823 | // NOTE: overloaded by BSPrimLinkable to also update linkset physical parameters. | ||
901 | public virtual void UpdatePhysicalParameters() | 824 | public virtual void UpdatePhysicalParameters() |
902 | { | 825 | { |
903 | if (!PhysBody.HasPhysicalBody) | 826 | if (!PhysBody.HasPhysicalBody) |
904 | { | 827 | { |
905 | // This would only happen if updates are called for during initialization when the body is not set up yet. | 828 | // This would only happen if updates are called for during initialization when the body is not set up yet. |
906 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,taint,calledWithNoPhysBody", LocalID); | 829 | // DetailLog("{0},BSPrim.UpdatePhysicalParameters,taint,calledWithNoPhysBody", LocalID); |
907 | return; | 830 | return; |
908 | } | 831 | } |
909 | 832 | ||
910 | // Mangling all the physical properties requires the object not be in the physical world. | 833 | // Mangling all the physical properties requires the object not be in the physical world. |
911 | // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). | 834 | // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). |
912 | PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, PhysBody); | 835 | PhysScene.PE.RemoveObjectFromWorld(PhysScene.World, PhysBody); |
913 | 836 | ||
914 | // Set up the object physicalness (does gravity and collisions move this object) | 837 | // Set up the object physicalness (does gravity and collisions move this object) |
915 | MakeDynamic(IsStatic); | 838 | MakeDynamic(IsStatic); |
916 | 839 | ||
917 | // Update vehicle specific parameters (after MakeDynamic() so can change physical parameters) | 840 | // Update vehicle specific parameters (after MakeDynamic() so can change physical parameters) |
918 | VehicleController.Refresh(); | 841 | PhysicalActors.Refresh(); |
919 | 842 | ||
920 | // Arrange for collision events if the simulator wants them | 843 | // Arrange for collision events if the simulator wants them |
921 | EnableCollisions(SubscribedEvents()); | 844 | EnableCollisions(SubscribedEvents()); |
@@ -926,10 +849,11 @@ public class BSPrim : BSPhysObject | |||
926 | AddObjectToPhysicalWorld(); | 849 | AddObjectToPhysicalWorld(); |
927 | 850 | ||
928 | // Rebuild its shape | 851 | // Rebuild its shape |
929 | PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, PhysBody); | 852 | PhysScene.PE.UpdateSingleAabb(PhysScene.World, PhysBody); |
930 | 853 | ||
931 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},cType={6},body={7},shape={8}", | 854 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},cType={6},body={7},shape={8}", |
932 | LocalID, IsStatic, IsSolid, Mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody.collisionType, PhysBody, PhysShape); | 855 | LocalID, IsStatic, IsSolid, Mass, SubscribedEvents(), |
856 | CurrentCollisionFlags, PhysBody.collisionType, PhysBody, PhysShape); | ||
933 | } | 857 | } |
934 | 858 | ||
935 | // "Making dynamic" means changing to and from static. | 859 | // "Making dynamic" means changing to and from static. |
@@ -942,28 +866,28 @@ public class BSPrim : BSPhysObject | |||
942 | if (makeStatic) | 866 | if (makeStatic) |
943 | { | 867 | { |
944 | // Become a Bullet 'static' object type | 868 | // Become a Bullet 'static' object type |
945 | CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT); | 869 | CurrentCollisionFlags = PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT); |
946 | // Stop all movement | 870 | // Stop all movement |
947 | ZeroMotion(true); | 871 | ZeroMotion(true); |
948 | 872 | ||
949 | // Set various physical properties so other object interact properly | 873 | // Set various physical properties so other object interact properly |
950 | PhysicsScene.PE.SetFriction(PhysBody, Friction); | 874 | PhysScene.PE.SetFriction(PhysBody, Friction); |
951 | PhysicsScene.PE.SetRestitution(PhysBody, Restitution); | 875 | PhysScene.PE.SetRestitution(PhysBody, Restitution); |
952 | PhysicsScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold); | 876 | PhysScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold); |
953 | 877 | ||
954 | // Mass is zero which disables a bunch of physics stuff in Bullet | 878 | // Mass is zero which disables a bunch of physics stuff in Bullet |
955 | UpdatePhysicalMassProperties(0f, false); | 879 | UpdatePhysicalMassProperties(0f, false); |
956 | // Set collision detection parameters | 880 | // Set collision detection parameters |
957 | if (BSParam.CcdMotionThreshold > 0f) | 881 | if (BSParam.CcdMotionThreshold > 0f) |
958 | { | 882 | { |
959 | PhysicsScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold); | 883 | PhysScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold); |
960 | PhysicsScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius); | 884 | PhysScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius); |
961 | } | 885 | } |
962 | 886 | ||
963 | // The activation state is 'disabled' so Bullet will not try to act on it. | 887 | // The activation state is 'disabled' so Bullet will not try to act on it. |
964 | // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.DISABLE_SIMULATION); | 888 | // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.DISABLE_SIMULATION); |
965 | // Start it out sleeping and physical actions could wake it up. | 889 | // Start it out sleeping and physical actions could wake it up. |
966 | PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ISLAND_SLEEPING); | 890 | PhysScene.PE.ForceActivationState(PhysBody, ActivationState.ISLAND_SLEEPING); |
967 | 891 | ||
968 | // This collides like a static object | 892 | // This collides like a static object |
969 | PhysBody.collisionType = CollisionType.Static; | 893 | PhysBody.collisionType = CollisionType.Static; |
@@ -971,11 +895,11 @@ public class BSPrim : BSPhysObject | |||
971 | else | 895 | else |
972 | { | 896 | { |
973 | // Not a Bullet static object | 897 | // Not a Bullet static object |
974 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT); | 898 | CurrentCollisionFlags = PhysScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT); |
975 | 899 | ||
976 | // Set various physical properties so other object interact properly | 900 | // Set various physical properties so other object interact properly |
977 | PhysicsScene.PE.SetFriction(PhysBody, Friction); | 901 | PhysScene.PE.SetFriction(PhysBody, Friction); |
978 | PhysicsScene.PE.SetRestitution(PhysBody, Restitution); | 902 | PhysScene.PE.SetRestitution(PhysBody, Restitution); |
979 | // DetailLog("{0},BSPrim.MakeDynamic,frict={1},rest={2}", LocalID, Friction, Restitution); | 903 | // DetailLog("{0},BSPrim.MakeDynamic,frict={1},rest={2}", LocalID, Friction, Restitution); |
980 | 904 | ||
981 | // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 | 905 | // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 |
@@ -983,8 +907,8 @@ public class BSPrim : BSPhysObject | |||
983 | // PhysicsScene.PE.ClearAllForces(BSBody); | 907 | // PhysicsScene.PE.ClearAllForces(BSBody); |
984 | 908 | ||
985 | // For good measure, make sure the transform is set through to the motion state | 909 | // For good measure, make sure the transform is set through to the motion state |
986 | ForcePosition = _position; | 910 | ForcePosition = RawPosition; |
987 | ForceVelocity = _velocity; | 911 | ForceVelocity = RawVelocity; |
988 | ForceRotationalVelocity = _rotationalVelocity; | 912 | ForceRotationalVelocity = _rotationalVelocity; |
989 | 913 | ||
990 | // A dynamic object has mass | 914 | // A dynamic object has mass |
@@ -993,22 +917,22 @@ public class BSPrim : BSPhysObject | |||
993 | // Set collision detection parameters | 917 | // Set collision detection parameters |
994 | if (BSParam.CcdMotionThreshold > 0f) | 918 | if (BSParam.CcdMotionThreshold > 0f) |
995 | { | 919 | { |
996 | PhysicsScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold); | 920 | PhysScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold); |
997 | PhysicsScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius); | 921 | PhysScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius); |
998 | } | 922 | } |
999 | 923 | ||
1000 | // Various values for simulation limits | 924 | // Various values for simulation limits |
1001 | PhysicsScene.PE.SetDamping(PhysBody, BSParam.LinearDamping, BSParam.AngularDamping); | 925 | PhysScene.PE.SetDamping(PhysBody, BSParam.LinearDamping, BSParam.AngularDamping); |
1002 | PhysicsScene.PE.SetDeactivationTime(PhysBody, BSParam.DeactivationTime); | 926 | PhysScene.PE.SetDeactivationTime(PhysBody, BSParam.DeactivationTime); |
1003 | PhysicsScene.PE.SetSleepingThresholds(PhysBody, BSParam.LinearSleepingThreshold, BSParam.AngularSleepingThreshold); | 927 | PhysScene.PE.SetSleepingThresholds(PhysBody, BSParam.LinearSleepingThreshold, BSParam.AngularSleepingThreshold); |
1004 | PhysicsScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold); | 928 | PhysScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold); |
1005 | 929 | ||
1006 | // This collides like an object. | 930 | // This collides like an object. |
1007 | PhysBody.collisionType = CollisionType.Dynamic; | 931 | PhysBody.collisionType = CollisionType.Dynamic; |
1008 | 932 | ||
1009 | // Force activation of the object so Bullet will act on it. | 933 | // Force activation of the object so Bullet will act on it. |
1010 | // Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects. | 934 | // Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects. |
1011 | PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG); | 935 | PhysScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG); |
1012 | } | 936 | } |
1013 | } | 937 | } |
1014 | 938 | ||
@@ -1018,7 +942,7 @@ public class BSPrim : BSPhysObject | |||
1018 | // the functions after this one set up the state of a possibly newly created collision body. | 942 | // the functions after this one set up the state of a possibly newly created collision body. |
1019 | private void MakeSolid(bool makeSolid) | 943 | private void MakeSolid(bool makeSolid) |
1020 | { | 944 | { |
1021 | CollisionObjectTypes bodyType = (CollisionObjectTypes)PhysicsScene.PE.GetBodyType(PhysBody); | 945 | CollisionObjectTypes bodyType = (CollisionObjectTypes)PhysScene.PE.GetBodyType(PhysBody); |
1022 | if (makeSolid) | 946 | if (makeSolid) |
1023 | { | 947 | { |
1024 | // Verify the previous code created the correct shape for this type of thing. | 948 | // Verify the previous code created the correct shape for this type of thing. |
@@ -1026,7 +950,7 @@ public class BSPrim : BSPhysObject | |||
1026 | { | 950 | { |
1027 | m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for solidity. id={1}, type={2}", LogHeader, LocalID, bodyType); | 951 | m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for solidity. id={1}, type={2}", LogHeader, LocalID, bodyType); |
1028 | } | 952 | } |
1029 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE); | 953 | CurrentCollisionFlags = PhysScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE); |
1030 | } | 954 | } |
1031 | else | 955 | else |
1032 | { | 956 | { |
@@ -1034,32 +958,23 @@ public class BSPrim : BSPhysObject | |||
1034 | { | 958 | { |
1035 | m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for non-solidness. id={1}, type={2}", LogHeader, LocalID, bodyType); | 959 | m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for non-solidness. id={1}, type={2}", LogHeader, LocalID, bodyType); |
1036 | } | 960 | } |
1037 | CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE); | 961 | CurrentCollisionFlags = PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE); |
1038 | 962 | ||
1039 | // Change collision info from a static object to a ghosty collision object | 963 | // Change collision info from a static object to a ghosty collision object |
1040 | PhysBody.collisionType = CollisionType.VolumeDetect; | 964 | PhysBody.collisionType = CollisionType.VolumeDetect; |
1041 | } | 965 | } |
1042 | } | 966 | } |
1043 | 967 | ||
1044 | // Enable physical actions. Bullet will keep sleeping non-moving physical objects so | ||
1045 | // they need waking up when parameters are changed. | ||
1046 | // Called in taint-time!! | ||
1047 | private void ActivateIfPhysical(bool forceIt) | ||
1048 | { | ||
1049 | if (IsPhysical && PhysBody.HasPhysicalBody) | ||
1050 | PhysicsScene.PE.Activate(PhysBody, forceIt); | ||
1051 | } | ||
1052 | |||
1053 | // Turn on or off the flag controlling whether collision events are returned to the simulator. | 968 | // Turn on or off the flag controlling whether collision events are returned to the simulator. |
1054 | private void EnableCollisions(bool wantsCollisionEvents) | 969 | private void EnableCollisions(bool wantsCollisionEvents) |
1055 | { | 970 | { |
1056 | if (wantsCollisionEvents) | 971 | if (wantsCollisionEvents) |
1057 | { | 972 | { |
1058 | CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 973 | CurrentCollisionFlags = PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); |
1059 | } | 974 | } |
1060 | else | 975 | else |
1061 | { | 976 | { |
1062 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 977 | CurrentCollisionFlags = PhysScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); |
1063 | } | 978 | } |
1064 | } | 979 | } |
1065 | 980 | ||
@@ -1070,7 +985,7 @@ public class BSPrim : BSPhysObject | |||
1070 | { | 985 | { |
1071 | if (PhysBody.HasPhysicalBody) | 986 | if (PhysBody.HasPhysicalBody) |
1072 | { | 987 | { |
1073 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody); | 988 | PhysScene.PE.AddObjectToWorld(PhysScene.World, PhysBody); |
1074 | } | 989 | } |
1075 | else | 990 | else |
1076 | { | 991 | { |
@@ -1105,12 +1020,12 @@ public class BSPrim : BSPhysObject | |||
1105 | public override bool FloatOnWater { | 1020 | public override bool FloatOnWater { |
1106 | set { | 1021 | set { |
1107 | _floatOnWater = value; | 1022 | _floatOnWater = value; |
1108 | PhysicsScene.TaintedObject("BSPrim.setFloatOnWater", delegate() | 1023 | PhysScene.TaintedObject(LocalID, "BSPrim.setFloatOnWater", delegate() |
1109 | { | 1024 | { |
1110 | if (_floatOnWater) | 1025 | if (_floatOnWater) |
1111 | CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); | 1026 | CurrentCollisionFlags = PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); |
1112 | else | 1027 | else |
1113 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); | 1028 | CurrentCollisionFlags = PhysScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); |
1114 | }); | 1029 | }); |
1115 | } | 1030 | } |
1116 | } | 1031 | } |
@@ -1122,7 +1037,7 @@ public class BSPrim : BSPhysObject | |||
1122 | _rotationalVelocity = value; | 1037 | _rotationalVelocity = value; |
1123 | Util.ClampV(_rotationalVelocity, BSParam.MaxAngularVelocity); | 1038 | Util.ClampV(_rotationalVelocity, BSParam.MaxAngularVelocity); |
1124 | // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); | 1039 | // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); |
1125 | PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() | 1040 | PhysScene.TaintedObject(LocalID, "BSPrim.setRotationalVelocity", delegate() |
1126 | { | 1041 | { |
1127 | ForceRotationalVelocity = _rotationalVelocity; | 1042 | ForceRotationalVelocity = _rotationalVelocity; |
1128 | }); | 1043 | }); |
@@ -1137,7 +1052,7 @@ public class BSPrim : BSPhysObject | |||
1137 | if (PhysBody.HasPhysicalBody) | 1052 | if (PhysBody.HasPhysicalBody) |
1138 | { | 1053 | { |
1139 | DetailLog("{0},BSPrim.ForceRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); | 1054 | DetailLog("{0},BSPrim.ForceRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); |
1140 | PhysicsScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity); | 1055 | PhysScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity); |
1141 | // PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity); | 1056 | // PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity); |
1142 | ActivateIfPhysical(false); | 1057 | ActivateIfPhysical(false); |
1143 | } | 1058 | } |
@@ -1153,7 +1068,7 @@ public class BSPrim : BSPhysObject | |||
1153 | get { return _buoyancy; } | 1068 | get { return _buoyancy; } |
1154 | set { | 1069 | set { |
1155 | _buoyancy = value; | 1070 | _buoyancy = value; |
1156 | PhysicsScene.TaintedObject("BSPrim.setBuoyancy", delegate() | 1071 | PhysScene.TaintedObject(LocalID, "BSPrim.setBuoyancy", delegate() |
1157 | { | 1072 | { |
1158 | ForceBuoyancy = _buoyancy; | 1073 | ForceBuoyancy = _buoyancy; |
1159 | }); | 1074 | }); |
@@ -1171,179 +1086,54 @@ public class BSPrim : BSPhysObject | |||
1171 | } | 1086 | } |
1172 | } | 1087 | } |
1173 | 1088 | ||
1174 | // Used for MoveTo | ||
1175 | public override OMV.Vector3 PIDTarget { | ||
1176 | set | ||
1177 | { | ||
1178 | // TODO: add a sanity check -- don't move more than a region or something like that. | ||
1179 | _PIDTarget = value; | ||
1180 | } | ||
1181 | } | ||
1182 | public override float PIDTau { | ||
1183 | set { _PIDTau = value; } | ||
1184 | } | ||
1185 | public override bool PIDActive { | 1089 | public override bool PIDActive { |
1186 | set { | 1090 | set { |
1187 | if (value) | 1091 | base.MoveToTargetActive = value; |
1092 | EnableActor(MoveToTargetActive, MoveToTargetActorName, delegate() | ||
1188 | { | 1093 | { |
1189 | // We're taking over after this. | 1094 | return new BSActorMoveToTarget(PhysScene, this, MoveToTargetActorName); |
1190 | ZeroMotion(true); | 1095 | }); |
1191 | 1096 | } | |
1192 | _targetMotor = new BSVMotor("BSPrim.PIDTarget", | 1097 | } |
1193 | _PIDTau, // timeScale | ||
1194 | BSMotor.Infinite, // decay time scale | ||
1195 | BSMotor.InfiniteVector, // friction timescale | ||
1196 | 1f // efficiency | ||
1197 | ); | ||
1198 | _targetMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. | ||
1199 | _targetMotor.SetTarget(_PIDTarget); | ||
1200 | _targetMotor.SetCurrent(RawPosition); | ||
1201 | /* | ||
1202 | _targetMotor = new BSPIDVMotor("BSPrim.PIDTarget"); | ||
1203 | _targetMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. | ||
1204 | |||
1205 | _targetMotor.SetTarget(_PIDTarget); | ||
1206 | _targetMotor.SetCurrent(RawPosition); | ||
1207 | _targetMotor.TimeScale = _PIDTau; | ||
1208 | _targetMotor.Efficiency = 1f; | ||
1209 | */ | ||
1210 | |||
1211 | RegisterPreStepAction("BSPrim.PIDTarget", LocalID, delegate(float timeStep) | ||
1212 | { | ||
1213 | if (!IsPhysicallyActive) | ||
1214 | { | ||
1215 | UnRegisterPreStepAction("BSPrim.PIDTarget", LocalID); | ||
1216 | return; | ||
1217 | } | ||
1218 | |||
1219 | OMV.Vector3 origPosition = RawPosition; // DEBUG DEBUG (for printout below) | ||
1220 | |||
1221 | // 'movePosition' is where we'd like the prim to be at this moment. | ||
1222 | OMV.Vector3 movePosition = RawPosition + _targetMotor.Step(timeStep); | ||
1223 | 1098 | ||
1224 | // If we are very close to our target, turn off the movement motor. | 1099 | public override OMV.Vector3 PIDTarget |
1225 | if (_targetMotor.ErrorIsZero()) | 1100 | { |
1226 | { | 1101 | set |
1227 | DetailLog("{0},BSPrim.PIDTarget,zeroMovement,movePos={1},pos={2},mass={3}", | 1102 | { |
1228 | LocalID, movePosition, RawPosition, Mass); | 1103 | base.PIDTarget = value; |
1229 | ForcePosition = _targetMotor.TargetValue; | 1104 | BSActor actor; |
1230 | _targetMotor.Enabled = false; | 1105 | if (PhysicalActors.TryGetActor(MoveToTargetActorName, out actor)) |
1231 | } | ||
1232 | else | ||
1233 | { | ||
1234 | _position = movePosition; | ||
1235 | PositionSanityCheck(true /* intaintTime */); | ||
1236 | ForcePosition = _position; | ||
1237 | } | ||
1238 | DetailLog("{0},BSPrim.PIDTarget,move,fromPos={1},movePos={2}", LocalID, origPosition, movePosition); | ||
1239 | }); | ||
1240 | } | ||
1241 | else | ||
1242 | { | 1106 | { |
1243 | // Stop any targetting | 1107 | // if the actor exists, tell it to refresh its values. |
1244 | UnRegisterPreStepAction("BSPrim.PIDTarget", LocalID); | 1108 | actor.Refresh(); |
1245 | } | 1109 | } |
1110 | |||
1246 | } | 1111 | } |
1247 | } | 1112 | } |
1248 | |||
1249 | // Used for llSetHoverHeight and maybe vehicle height | 1113 | // Used for llSetHoverHeight and maybe vehicle height |
1250 | // Hover Height will override MoveTo target's Z | 1114 | // Hover Height will override MoveTo target's Z |
1251 | public override bool PIDHoverActive { | 1115 | public override bool PIDHoverActive { |
1252 | set { | 1116 | set { |
1253 | if (value) | 1117 | base.HoverActive = value; |
1118 | EnableActor(HoverActive, HoverActorName, delegate() | ||
1254 | { | 1119 | { |
1255 | // Turning the target on | 1120 | return new BSActorHover(PhysScene, this, HoverActorName); |
1256 | _hoverMotor = new BSFMotor("BSPrim.Hover", | 1121 | }); |
1257 | _PIDHoverTau, // timeScale | ||
1258 | BSMotor.Infinite, // decay time scale | ||
1259 | BSMotor.Infinite, // friction timescale | ||
1260 | 1f // efficiency | ||
1261 | ); | ||
1262 | _hoverMotor.SetTarget(ComputeCurrentPIDHoverHeight()); | ||
1263 | _hoverMotor.SetCurrent(RawPosition.Z); | ||
1264 | _hoverMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages. | ||
1265 | |||
1266 | RegisterPreStepAction("BSPrim.Hover", LocalID, delegate(float timeStep) | ||
1267 | { | ||
1268 | // Don't do hovering while the object is selected. | ||
1269 | if (!IsPhysicallyActive) | ||
1270 | return; | ||
1271 | |||
1272 | _hoverMotor.SetCurrent(RawPosition.Z); | ||
1273 | _hoverMotor.SetTarget(ComputeCurrentPIDHoverHeight()); | ||
1274 | float targetHeight = _hoverMotor.Step(timeStep); | ||
1275 | |||
1276 | // 'targetHeight' is where we'd like the Z of the prim to be at this moment. | ||
1277 | // Compute the amount of force to push us there. | ||
1278 | float moveForce = (targetHeight - RawPosition.Z) * Mass; | ||
1279 | // Undo anything the object thinks it's doing at the moment | ||
1280 | moveForce = -RawVelocity.Z * Mass; | ||
1281 | |||
1282 | PhysicsScene.PE.ApplyCentralImpulse(PhysBody, new OMV.Vector3(0f, 0f, moveForce)); | ||
1283 | DetailLog("{0},BSPrim.Hover,move,targHt={1},moveForce={2},mass={3}", LocalID, targetHeight, moveForce, Mass); | ||
1284 | }); | ||
1285 | } | ||
1286 | else | ||
1287 | { | ||
1288 | UnRegisterPreStepAction("BSPrim.Hover", LocalID); | ||
1289 | } | ||
1290 | } | ||
1291 | } | ||
1292 | public override float PIDHoverHeight { | ||
1293 | set { _PIDHoverHeight = value; } | ||
1294 | } | ||
1295 | public override PIDHoverType PIDHoverType { | ||
1296 | set { _PIDHoverType = value; } | ||
1297 | } | ||
1298 | public override float PIDHoverTau { | ||
1299 | set { _PIDHoverTau = value; } | ||
1300 | } | ||
1301 | // Based on current position, determine what we should be hovering at now. | ||
1302 | // Must recompute often. What if we walked offa cliff> | ||
1303 | private float ComputeCurrentPIDHoverHeight() | ||
1304 | { | ||
1305 | float ret = _PIDHoverHeight; | ||
1306 | float groundHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(RawPosition); | ||
1307 | |||
1308 | switch (_PIDHoverType) | ||
1309 | { | ||
1310 | case PIDHoverType.Ground: | ||
1311 | ret = groundHeight + _PIDHoverHeight; | ||
1312 | break; | ||
1313 | case PIDHoverType.GroundAndWater: | ||
1314 | float waterHeight = PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(RawPosition); | ||
1315 | if (groundHeight > waterHeight) | ||
1316 | { | ||
1317 | ret = groundHeight + _PIDHoverHeight; | ||
1318 | } | ||
1319 | else | ||
1320 | { | ||
1321 | ret = waterHeight + _PIDHoverHeight; | ||
1322 | } | ||
1323 | break; | ||
1324 | } | 1122 | } |
1325 | return ret; | ||
1326 | } | 1123 | } |
1327 | 1124 | ||
1328 | |||
1329 | // For RotLookAt | ||
1330 | public override OMV.Quaternion APIDTarget { set { return; } } | ||
1331 | public override bool APIDActive { set { return; } } | ||
1332 | public override float APIDStrength { set { return; } } | ||
1333 | public override float APIDDamping { set { return; } } | ||
1334 | |||
1335 | public override void AddForce(OMV.Vector3 force, bool pushforce) { | 1125 | public override void AddForce(OMV.Vector3 force, bool pushforce) { |
1336 | // Per documentation, max force is limited. | 1126 | // Per documentation, max force is limited. |
1337 | OMV.Vector3 addForce = Util.ClampV(force, BSParam.MaxAddForceMagnitude); | 1127 | OMV.Vector3 addForce = Util.ClampV(force, BSParam.MaxAddForceMagnitude); |
1338 | 1128 | ||
1339 | // Since this force is being applied in only one step, make this a force per second. | 1129 | // Since this force is being applied in only one step, make this a force per second. |
1340 | addForce /= PhysicsScene.LastTimeStep; | 1130 | addForce /= PhysScene.LastTimeStep; |
1341 | AddForce(addForce, pushforce, false /* inTaintTime */); | 1131 | AddForce(addForce, pushforce, false /* inTaintTime */); |
1342 | } | 1132 | } |
1343 | 1133 | ||
1344 | // Applying a force just adds this to the total force on the object. | 1134 | // Applying a force just adds this to the total force on the object. |
1345 | // This added force will only last the next simulation tick. | 1135 | // This added force will only last the next simulation tick. |
1346 | public void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) { | 1136 | public override void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) { |
1347 | // for an object, doesn't matter if force is a pushforce or not | 1137 | // for an object, doesn't matter if force is a pushforce or not |
1348 | if (IsPhysicallyActive) | 1138 | if (IsPhysicallyActive) |
1349 | { | 1139 | { |
@@ -1352,13 +1142,15 @@ public class BSPrim : BSPhysObject | |||
1352 | // DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce); | 1142 | // DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce); |
1353 | 1143 | ||
1354 | OMV.Vector3 addForce = force; | 1144 | OMV.Vector3 addForce = force; |
1355 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate() | 1145 | PhysScene.TaintedObject(inTaintTime, LocalID, "BSPrim.AddForce", delegate() |
1356 | { | 1146 | { |
1357 | // Bullet adds this central force to the total force for this tick | 1147 | // Bullet adds this central force to the total force for this tick. |
1148 | // Deep down in Bullet: | ||
1149 | // linearVelocity += totalForce / mass * timeStep; | ||
1358 | DetailLog("{0},BSPrim.addForce,taint,force={1}", LocalID, addForce); | 1150 | DetailLog("{0},BSPrim.addForce,taint,force={1}", LocalID, addForce); |
1359 | if (PhysBody.HasPhysicalBody) | 1151 | if (PhysBody.HasPhysicalBody) |
1360 | { | 1152 | { |
1361 | PhysicsScene.PE.ApplyCentralForce(PhysBody, addForce); | 1153 | PhysScene.PE.ApplyCentralForce(PhysBody, addForce); |
1362 | ActivateIfPhysical(false); | 1154 | ActivateIfPhysical(false); |
1363 | } | 1155 | } |
1364 | }); | 1156 | }); |
@@ -1380,13 +1172,13 @@ public class BSPrim : BSPhysObject | |||
1380 | OMV.Vector3 addImpulse = Util.ClampV(impulse, BSParam.MaxAddForceMagnitude); | 1172 | OMV.Vector3 addImpulse = Util.ClampV(impulse, BSParam.MaxAddForceMagnitude); |
1381 | // DetailLog("{0},BSPrim.addForceImpulse,call,impulse={1}", LocalID, impulse); | 1173 | // DetailLog("{0},BSPrim.addForceImpulse,call,impulse={1}", LocalID, impulse); |
1382 | 1174 | ||
1383 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddImpulse", delegate() | 1175 | PhysScene.TaintedObject(inTaintTime, LocalID, "BSPrim.AddImpulse", delegate() |
1384 | { | 1176 | { |
1385 | // Bullet adds this impulse immediately to the velocity | 1177 | // Bullet adds this impulse immediately to the velocity |
1386 | DetailLog("{0},BSPrim.addForceImpulse,taint,impulseforce={1}", LocalID, addImpulse); | 1178 | DetailLog("{0},BSPrim.addForceImpulse,taint,impulseforce={1}", LocalID, addImpulse); |
1387 | if (PhysBody.HasPhysicalBody) | 1179 | if (PhysBody.HasPhysicalBody) |
1388 | { | 1180 | { |
1389 | PhysicsScene.PE.ApplyCentralImpulse(PhysBody, addImpulse); | 1181 | PhysScene.PE.ApplyCentralImpulse(PhysBody, addImpulse); |
1390 | ActivateIfPhysical(false); | 1182 | ActivateIfPhysical(false); |
1391 | } | 1183 | } |
1392 | }); | 1184 | }); |
@@ -1399,20 +1191,18 @@ public class BSPrim : BSPhysObject | |||
1399 | } | 1191 | } |
1400 | } | 1192 | } |
1401 | 1193 | ||
1402 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { | 1194 | // BSPhysObject.AddAngularForce() |
1403 | AddAngularForce(force, pushforce, false); | 1195 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) |
1404 | } | ||
1405 | public void AddAngularForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) | ||
1406 | { | 1196 | { |
1407 | if (force.IsFinite()) | 1197 | if (force.IsFinite()) |
1408 | { | 1198 | { |
1409 | OMV.Vector3 angForce = force; | 1199 | OMV.Vector3 angForce = force; |
1410 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddAngularForce", delegate() | 1200 | PhysScene.TaintedObject(inTaintTime, LocalID, "BSPrim.AddAngularForce", delegate() |
1411 | { | 1201 | { |
1412 | if (PhysBody.HasPhysicalBody) | 1202 | if (PhysBody.HasPhysicalBody) |
1413 | { | 1203 | { |
1414 | DetailLog("{0},BSPrim.AddAngularForce,taint,angForce={1}", LocalID, angForce); | 1204 | DetailLog("{0},BSPrim.AddAngularForce,taint,angForce={1}", LocalID, angForce); |
1415 | PhysicsScene.PE.ApplyTorque(PhysBody, angForce); | 1205 | PhysScene.PE.ApplyTorque(PhysBody, angForce); |
1416 | ActivateIfPhysical(false); | 1206 | ActivateIfPhysical(false); |
1417 | } | 1207 | } |
1418 | }); | 1208 | }); |
@@ -1431,11 +1221,11 @@ public class BSPrim : BSPhysObject | |||
1431 | public void ApplyTorqueImpulse(OMV.Vector3 impulse, bool inTaintTime) | 1221 | public void ApplyTorqueImpulse(OMV.Vector3 impulse, bool inTaintTime) |
1432 | { | 1222 | { |
1433 | OMV.Vector3 applyImpulse = impulse; | 1223 | OMV.Vector3 applyImpulse = impulse; |
1434 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyTorqueImpulse", delegate() | 1224 | PhysScene.TaintedObject(inTaintTime, LocalID, "BSPrim.ApplyTorqueImpulse", delegate() |
1435 | { | 1225 | { |
1436 | if (PhysBody.HasPhysicalBody) | 1226 | if (PhysBody.HasPhysicalBody) |
1437 | { | 1227 | { |
1438 | PhysicsScene.PE.ApplyTorqueImpulse(PhysBody, applyImpulse); | 1228 | PhysScene.PE.ApplyTorqueImpulse(PhysBody, applyImpulse); |
1439 | ActivateIfPhysical(false); | 1229 | ActivateIfPhysical(false); |
1440 | } | 1230 | } |
1441 | }); | 1231 | }); |
@@ -1721,9 +1511,11 @@ public class BSPrim : BSPhysObject | |||
1721 | volume *= (profileEnd - profileBegin); | 1511 | volume *= (profileEnd - profileBegin); |
1722 | 1512 | ||
1723 | returnMass = Density * BSParam.DensityScaleFactor * volume; | 1513 | returnMass = Density * BSParam.DensityScaleFactor * volume; |
1724 | DetailLog("{0},BSPrim.CalculateMass,den={1},vol={2},mass={3}", LocalID, Density, volume, returnMass); | ||
1725 | 1514 | ||
1726 | returnMass = Util.Clamp(returnMass, BSParam.MinimumObjectMass, BSParam.MaximumObjectMass); | 1515 | returnMass = Util.Clamp(returnMass, BSParam.MinimumObjectMass, BSParam.MaximumObjectMass); |
1516 | // DetailLog("{0},BSPrim.CalculateMass,den={1},vol={2},mass={3}", LocalID, Density, volume, returnMass); | ||
1517 | DetailLog("{0},BSPrim.CalculateMass,den={1},vol={2},mass={3},pathB={4},pathE={5},profB={6},profE={7},siz={8}", | ||
1518 | LocalID, Density, volume, returnMass, pathBegin, pathEnd, profileBegin, profileEnd, _size); | ||
1727 | 1519 | ||
1728 | return returnMass; | 1520 | return returnMass; |
1729 | }// end CalculateMass | 1521 | }// end CalculateMass |
@@ -1736,13 +1528,14 @@ public class BSPrim : BSPhysObject | |||
1736 | { | 1528 | { |
1737 | // Create the correct physical representation for this type of object. | 1529 | // Create the correct physical representation for this type of object. |
1738 | // Updates base.PhysBody and base.PhysShape with the new information. | 1530 | // Updates base.PhysBody and base.PhysShape with the new information. |
1739 | // Ignore 'forceRebuild'. This routine makes the right choices and changes of necessary. | 1531 | // Ignore 'forceRebuild'. 'GetBodyAndShape' makes the right choices and changes of necessary. |
1740 | PhysicsScene.Shapes.GetBodyAndShape(false /*forceRebuild */, PhysicsScene.World, this, null, delegate(BulletBody dBody) | 1532 | PhysScene.Shapes.GetBodyAndShape(false /*forceRebuild */, PhysScene.World, this, delegate(BulletBody pBody, BulletShape pShape) |
1741 | { | 1533 | { |
1742 | // Called if the current prim body is about to be destroyed. | 1534 | // Called if the current prim body is about to be destroyed. |
1743 | // Remove all the physical dependencies on the old body. | 1535 | // Remove all the physical dependencies on the old body. |
1744 | // (Maybe someday make the changing of BSShape an event to be subscribed to by BSLinkset, ...) | 1536 | // (Maybe someday make the changing of BSShape an event to be subscribed to by BSLinkset, ...) |
1745 | RemoveBodyDependencies(); | 1537 | // Note: this virtual function is overloaded by BSPrimLinkable to remove linkset constraints. |
1538 | RemoveDependencies(); | ||
1746 | }); | 1539 | }); |
1747 | 1540 | ||
1748 | // Make sure the properties are set on the new object | 1541 | // Make sure the properties are set on the new object |
@@ -1750,33 +1543,45 @@ public class BSPrim : BSPhysObject | |||
1750 | return; | 1543 | return; |
1751 | } | 1544 | } |
1752 | 1545 | ||
1753 | protected virtual void RemoveBodyDependencies() | 1546 | // Called at taint-time |
1547 | protected virtual void RemoveDependencies() | ||
1754 | { | 1548 | { |
1755 | VehicleController.RemoveBodyDependencies(this); | 1549 | PhysicalActors.RemoveDependencies(); |
1550 | } | ||
1551 | |||
1552 | #region Extension | ||
1553 | public override object Extension(string pFunct, params object[] pParams) | ||
1554 | { | ||
1555 | DetailLog("{0} BSPrim.Extension,op={1}", LocalID, pFunct); | ||
1556 | object ret = null; | ||
1557 | switch (pFunct) | ||
1558 | { | ||
1559 | default: | ||
1560 | ret = base.Extension(pFunct, pParams); | ||
1561 | break; | ||
1562 | } | ||
1563 | return ret; | ||
1756 | } | 1564 | } |
1565 | #endregion // Extension | ||
1757 | 1566 | ||
1758 | // The physics engine says that properties have updated. Update same and inform | 1567 | // The physics engine says that properties have updated. Update same and inform |
1759 | // the world that things have changed. | 1568 | // the world that things have changed. |
1569 | // NOTE: BSPrim.UpdateProperties is overloaded by BSPrimLinkable which modifies updates from root and children prims. | ||
1570 | // NOTE: BSPrim.UpdateProperties is overloaded by BSPrimDisplaced which handles mapping physical position to simulator position. | ||
1760 | public override void UpdateProperties(EntityProperties entprop) | 1571 | public override void UpdateProperties(EntityProperties entprop) |
1761 | { | 1572 | { |
1573 | // Let anyone (like the actors) modify the updated properties before they are pushed into the object and the simulator. | ||
1762 | TriggerPreUpdatePropertyAction(ref entprop); | 1574 | TriggerPreUpdatePropertyAction(ref entprop); |
1763 | 1575 | ||
1764 | // A temporary kludge to suppress the rotational effects introduced on vehicles by Bullet | ||
1765 | // TODO: handle physics introduced by Bullet with computed vehicle physics. | ||
1766 | if (VehicleController.IsActive) | ||
1767 | { | ||
1768 | entprop.RotationalVelocity = OMV.Vector3.Zero; | ||
1769 | } | ||
1770 | |||
1771 | // DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG | 1576 | // DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG |
1772 | 1577 | ||
1773 | // Assign directly to the local variables so the normal set actions do not happen | 1578 | // Assign directly to the local variables so the normal set actions do not happen |
1774 | _position = entprop.Position; | 1579 | RawPosition = entprop.Position; |
1775 | _orientation = entprop.Rotation; | 1580 | RawOrientation = entprop.Rotation; |
1776 | // DEBUG DEBUG DEBUG -- smooth velocity changes a bit. The simulator seems to be | 1581 | // DEBUG DEBUG DEBUG -- smooth velocity changes a bit. The simulator seems to be |
1777 | // very sensitive to velocity changes. | 1582 | // very sensitive to velocity changes. |
1778 | if (entprop.Velocity == OMV.Vector3.Zero || !entprop.Velocity.ApproxEquals(_velocity, BSParam.UpdateVelocityChangeThreshold)) | 1583 | if (entprop.Velocity == OMV.Vector3.Zero || !entprop.Velocity.ApproxEquals(RawVelocity, BSParam.UpdateVelocityChangeThreshold)) |
1779 | _velocity = entprop.Velocity; | 1584 | RawVelocity = entprop.Velocity; |
1780 | _acceleration = entprop.Acceleration; | 1585 | _acceleration = entprop.Acceleration; |
1781 | _rotationalVelocity = entprop.RotationalVelocity; | 1586 | _rotationalVelocity = entprop.RotationalVelocity; |
1782 | 1587 | ||
@@ -1785,29 +1590,20 @@ public class BSPrim : BSPhysObject | |||
1785 | // The sanity check can change the velocity and/or position. | 1590 | // The sanity check can change the velocity and/or position. |
1786 | if (PositionSanityCheck(true /* inTaintTime */ )) | 1591 | if (PositionSanityCheck(true /* inTaintTime */ )) |
1787 | { | 1592 | { |
1788 | entprop.Position = _position; | 1593 | entprop.Position = RawPosition; |
1789 | entprop.Velocity = _velocity; | 1594 | entprop.Velocity = RawVelocity; |
1790 | entprop.RotationalVelocity = _rotationalVelocity; | 1595 | entprop.RotationalVelocity = _rotationalVelocity; |
1791 | entprop.Acceleration = _acceleration; | 1596 | entprop.Acceleration = _acceleration; |
1792 | } | 1597 | } |
1793 | 1598 | ||
1794 | OMV.Vector3 direction = OMV.Vector3.UnitX * _orientation; // DEBUG DEBUG DEBUG | 1599 | OMV.Vector3 direction = OMV.Vector3.UnitX * RawOrientation; // DEBUG DEBUG DEBUG |
1795 | DetailLog("{0},BSPrim.UpdateProperties,call,entProp={1},dir={2}", LocalID, entprop, direction); | 1600 | DetailLog("{0},BSPrim.UpdateProperties,call,entProp={1},dir={2}", LocalID, entprop, direction); |
1796 | 1601 | ||
1797 | // remember the current and last set values | 1602 | // remember the current and last set values |
1798 | LastEntityProperties = CurrentEntityProperties; | 1603 | LastEntityProperties = CurrentEntityProperties; |
1799 | CurrentEntityProperties = entprop; | 1604 | CurrentEntityProperties = entprop; |
1800 | 1605 | ||
1801 | base.RequestPhysicsterseUpdate(); | 1606 | PhysScene.PostUpdate(this); |
1802 | /* | ||
1803 | else | ||
1804 | { | ||
1805 | // For debugging, report the movement of children | ||
1806 | DetailLog("{0},BSPrim.UpdateProperties,child,pos={1},orient={2},vel={3},accel={4},rotVel={5}", | ||
1807 | LocalID, entprop.Position, entprop.Rotation, entprop.Velocity, | ||
1808 | entprop.Acceleration, entprop.RotationalVelocity); | ||
1809 | } | ||
1810 | */ | ||
1811 | } | 1607 | } |
1812 | } | 1608 | } |
1813 | } | 1609 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs index f1c3b5c..2eb1440 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs | |||
@@ -23,11 +23,6 @@ | |||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | ||
27 | * The quotations from http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial | ||
28 | * are Copyright (c) 2009 Linden Research, Inc and are used under their license | ||
29 | * of Creative Commons Attribution-Share Alike 3.0 | ||
30 | * (http://creativecommons.org/licenses/by-sa/3.0/). | ||
31 | */ | 26 | */ |
32 | 27 | ||
33 | using System; | 28 | using System; |
@@ -44,14 +39,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
44 | { | 39 | { |
45 | public class BSPrimDisplaced : BSPrim | 40 | public class BSPrimDisplaced : BSPrim |
46 | { | 41 | { |
47 | // The purpose of this module is to do any mapping between what the simulator thinks | 42 | // The purpose of this subclass is to do any mapping between what the simulator thinks |
48 | // the prim position and orientation is and what the physical position/orientation. | 43 | // the prim position and orientation is and what the physical position/orientation. |
49 | // This difference happens because Bullet assumes the center-of-mass is the <0,0,0> | 44 | // This difference happens because Bullet assumes the center-of-mass is the <0,0,0> |
50 | // of the prim/linkset. The simulator tracks the location of the prim/linkset by | 45 | // of the prim/linkset. The simulator, on the other hand, tracks the location of |
51 | // the location of the root prim. So, if center-of-mass is anywhere but the origin | 46 | // the prim/linkset by the location of the root prim. So, if center-of-mass is anywhere |
52 | // of the root prim, the physical origin is displaced from the simulator origin. | 47 | // but the origin of the root prim, the physical origin is displaced from the simulator origin. |
53 | // | 48 | // |
54 | // This routine works by capturing the Force* setting of position/orientation/... and | 49 | // This routine works by capturing ForcePosition and |
55 | // adjusting the simulator values (being set) into the physical values. | 50 | // adjusting the simulator values (being set) into the physical values. |
56 | // The conversion is also done in the opposite direction (physical origin -> simulator origin). | 51 | // The conversion is also done in the opposite direction (physical origin -> simulator origin). |
57 | // | 52 | // |
@@ -59,8 +54,8 @@ public class BSPrimDisplaced : BSPrim | |||
59 | // are converted into simulator origin values before being passed to the base | 54 | // are converted into simulator origin values before being passed to the base |
60 | // class. | 55 | // class. |
61 | 56 | ||
57 | // PositionDisplacement is the vehicle relative distance from the root prim position to the center-of-mass. | ||
62 | public virtual OMV.Vector3 PositionDisplacement { get; set; } | 58 | public virtual OMV.Vector3 PositionDisplacement { get; set; } |
63 | public virtual OMV.Quaternion OrientationDisplacement { get; set; } | ||
64 | 59 | ||
65 | public BSPrimDisplaced(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, | 60 | public BSPrimDisplaced(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, |
66 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) | 61 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) |
@@ -69,68 +64,96 @@ public class BSPrimDisplaced : BSPrim | |||
69 | ClearDisplacement(); | 64 | ClearDisplacement(); |
70 | } | 65 | } |
71 | 66 | ||
67 | // Clears any center-of-mass displacement introduced by linksets, etc. | ||
68 | // Does not clear the displacement set by the user. | ||
72 | public void ClearDisplacement() | 69 | public void ClearDisplacement() |
73 | { | 70 | { |
74 | PositionDisplacement = OMV.Vector3.Zero; | 71 | if (UserSetCenterOfMassDisplacement.HasValue) |
75 | OrientationDisplacement = OMV.Quaternion.Identity; | 72 | PositionDisplacement = (OMV.Vector3)UserSetCenterOfMassDisplacement; |
73 | else | ||
74 | PositionDisplacement = OMV.Vector3.Zero; | ||
76 | } | 75 | } |
77 | 76 | ||
78 | // Set this sets and computes the displacement from the passed prim to the center-of-mass. | 77 | // Set this sets and computes the displacement from the passed prim to the center-of-mass. |
79 | // A user set value for center-of-mass overrides whatever might be passed in here. | 78 | // A user set value for center-of-mass overrides whatever might be passed in here. |
80 | // The displacement is in local coordinates (relative to root prim in linkset oriented coordinates). | 79 | // The displacement is in local coordinates (relative to root prim in linkset oriented coordinates). |
81 | public virtual void SetEffectiveCenterOfMassW(Vector3 centerOfMassDisplacement) | 80 | // Returns the relative offset from the root position to the center-of-mass. |
81 | // Called at taint time. | ||
82 | public virtual Vector3 SetEffectiveCenterOfMassDisplacement(Vector3 centerOfMassDisplacement) | ||
82 | { | 83 | { |
84 | PhysScene.AssertInTaintTime("BSPrimDisplaced.SetEffectiveCenterOfMassDisplacement"); | ||
83 | Vector3 comDisp; | 85 | Vector3 comDisp; |
84 | if (UserSetCenterOfMass.HasValue) | 86 | if (UserSetCenterOfMassDisplacement.HasValue) |
85 | comDisp = (OMV.Vector3)UserSetCenterOfMass; | 87 | comDisp = (OMV.Vector3)UserSetCenterOfMassDisplacement; |
86 | else | 88 | else |
87 | comDisp = centerOfMassDisplacement; | 89 | comDisp = centerOfMassDisplacement; |
88 | 90 | ||
89 | if (comDisp == Vector3.Zero) | 91 | // Eliminate any jitter caused be very slight differences in masses and positions |
90 | { | 92 | if (comDisp.ApproxEquals(Vector3.Zero, 0.01f) ) |
91 | // If there is no diplacement. Things get reset. | 93 | comDisp = Vector3.Zero; |
92 | PositionDisplacement = OMV.Vector3.Zero; | 94 | |
93 | OrientationDisplacement = OMV.Quaternion.Identity; | 95 | DetailLog("{0},BSPrimDisplaced.SetEffectiveCenterOfMassDisplacement,userSet={1},comDisp={2}", |
94 | } | 96 | LocalID, UserSetCenterOfMassDisplacement.HasValue, comDisp); |
95 | else | 97 | if ( !comDisp.ApproxEquals(PositionDisplacement, 0.01f) ) |
96 | { | 98 | { |
97 | // Remember the displacement from root as well as the origional rotation of the | 99 | // Displacement setting is changing. |
98 | // new center-of-mass. | 100 | // The relationship between the physical object and simulated object must be aligned. |
99 | PositionDisplacement = comDisp; | 101 | PositionDisplacement = comDisp; |
100 | OrientationDisplacement = OMV.Quaternion.Identity; | 102 | this.ForcePosition = RawPosition; |
101 | } | 103 | } |
104 | |||
105 | return PositionDisplacement; | ||
102 | } | 106 | } |
103 | 107 | ||
108 | // 'ForcePosition' is the one way to set the physical position of the body in the physics engine. | ||
109 | // Displace the simulator idea of position (center of root prim) to the physical position. | ||
104 | public override Vector3 ForcePosition | 110 | public override Vector3 ForcePosition |
105 | { | 111 | { |
106 | get { return base.ForcePosition; } | 112 | get { |
113 | OMV.Vector3 physPosition = PhysScene.PE.GetPosition(PhysBody); | ||
114 | if (PositionDisplacement != OMV.Vector3.Zero) | ||
115 | { | ||
116 | // If there is some displacement, return the physical position (center-of-mass) | ||
117 | // location minus the displacement to give the center of the root prim. | ||
118 | OMV.Vector3 displacement = PositionDisplacement * ForceOrientation; | ||
119 | DetailLog("{0},BSPrimDisplaced.ForcePosition,get,physPos={1},disp={2},simPos={3}", | ||
120 | LocalID, physPosition, displacement, physPosition - displacement); | ||
121 | physPosition -= displacement; | ||
122 | } | ||
123 | RawPosition = physPosition; | ||
124 | return physPosition; | ||
125 | } | ||
107 | set | 126 | set |
108 | { | 127 | { |
109 | if (PositionDisplacement != OMV.Vector3.Zero) | 128 | if (PositionDisplacement != OMV.Vector3.Zero) |
110 | base.ForcePosition = value - (PositionDisplacement * RawOrientation); | 129 | { |
130 | // This value is the simulator's idea of where the prim is: the center of the root prim | ||
131 | RawPosition = value; | ||
132 | |||
133 | // Move the passed root prim postion to the center-of-mass position and set in the physics engine. | ||
134 | OMV.Vector3 displacement = PositionDisplacement * RawOrientation; | ||
135 | OMV.Vector3 displacedPos = RawPosition + displacement; | ||
136 | DetailLog("{0},BSPrimDisplaced.ForcePosition,set,simPos={1},disp={2},physPos={3}", | ||
137 | LocalID, RawPosition, displacement, displacedPos); | ||
138 | if (PhysBody.HasPhysicalBody) | ||
139 | { | ||
140 | PhysScene.PE.SetTranslation(PhysBody, displacedPos, RawOrientation); | ||
141 | ActivateIfPhysical(false); | ||
142 | } | ||
143 | } | ||
111 | else | 144 | else |
145 | { | ||
112 | base.ForcePosition = value; | 146 | base.ForcePosition = value; |
147 | } | ||
113 | } | 148 | } |
114 | } | 149 | } |
115 | 150 | ||
116 | public override Quaternion ForceOrientation | 151 | // These are also overridden by BSPrimLinkable if the prim can be part of a linkset |
117 | { | ||
118 | get { return base.ForceOrientation; } | ||
119 | set | ||
120 | { | ||
121 | base.ForceOrientation = value; | ||
122 | } | ||
123 | } | ||
124 | |||
125 | // TODO: decide if this is the right place for these variables. | ||
126 | // Somehow incorporate the optional settability by the user. | ||
127 | // Is this used? | ||
128 | public override OMV.Vector3 CenterOfMass | 152 | public override OMV.Vector3 CenterOfMass |
129 | { | 153 | { |
130 | get { return RawPosition; } | 154 | get { return RawPosition; } |
131 | } | 155 | } |
132 | 156 | ||
133 | // Is this used? | ||
134 | public override OMV.Vector3 GeometricCenter | 157 | public override OMV.Vector3 GeometricCenter |
135 | { | 158 | { |
136 | get { return RawPosition; } | 159 | get { return RawPosition; } |
@@ -139,12 +162,18 @@ public class BSPrimDisplaced : BSPrim | |||
139 | public override void UpdateProperties(EntityProperties entprop) | 162 | public override void UpdateProperties(EntityProperties entprop) |
140 | { | 163 | { |
141 | // Undo any center-of-mass displacement that might have been done. | 164 | // Undo any center-of-mass displacement that might have been done. |
142 | if (PositionDisplacement != OMV.Vector3.Zero || OrientationDisplacement != OMV.Quaternion.Identity) | 165 | if (PositionDisplacement != OMV.Vector3.Zero) |
143 | { | 166 | { |
144 | // Correct for any rotation around the center-of-mass | 167 | // The origional shape was offset from 'zero' by PositionDisplacement. |
145 | // TODO!!! | 168 | // These physical location must be back converted to be centered around the displaced |
146 | entprop.Position = entprop.Position + (PositionDisplacement * entprop.Rotation); | 169 | // root shape. |
147 | // entprop.Rotation = something; | 170 | |
171 | // Move the returned center-of-mass location to the root prim location. | ||
172 | OMV.Vector3 displacement = PositionDisplacement * entprop.Rotation; | ||
173 | OMV.Vector3 displacedPos = entprop.Position - displacement; | ||
174 | DetailLog("{0},BSPrimDisplaced.UpdateProperties,physPos={1},disp={2},simPos={3}", | ||
175 | LocalID, entprop.Position, displacement, displacedPos); | ||
176 | entprop.Position = displacedPos; | ||
148 | } | 177 | } |
149 | 178 | ||
150 | base.UpdateProperties(entprop); | 179 | base.UpdateProperties(entprop); |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs index d65d407..126b146 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs | |||
@@ -30,6 +30,7 @@ using System.Linq; | |||
30 | using System.Text; | 30 | using System.Text; |
31 | 31 | ||
32 | using OpenSim.Framework; | 32 | using OpenSim.Framework; |
33 | using OpenSim.Region.OptionalModules.Scripting; | ||
33 | 34 | ||
34 | using OMV = OpenMetaverse; | 35 | using OMV = OpenMetaverse; |
35 | 36 | ||
@@ -37,44 +38,49 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
37 | { | 38 | { |
38 | public class BSPrimLinkable : BSPrimDisplaced | 39 | public class BSPrimLinkable : BSPrimDisplaced |
39 | { | 40 | { |
41 | // The purpose of this subclass is to add linkset functionality to the prim. This overrides | ||
42 | // operations necessary for keeping the linkset created and, additionally, this | ||
43 | // calls the linkset implementation for its creation and management. | ||
44 | |||
45 | private static readonly string LogHeader = "[BULLETS PRIMLINKABLE]"; | ||
46 | |||
47 | // This adds the overrides for link() and delink() so the prim is linkable. | ||
48 | |||
40 | public BSLinkset Linkset { get; set; } | 49 | public BSLinkset Linkset { get; set; } |
41 | // The index of this child prim. | 50 | // The index of this child prim. |
42 | public int LinksetChildIndex { get; set; } | 51 | public int LinksetChildIndex { get; set; } |
43 | 52 | ||
44 | public BSLinksetInfo LinksetInfo { get; set; } | 53 | public BSLinkset.LinksetImplementation LinksetType { get; set; } |
45 | 54 | ||
46 | public BSPrimLinkable(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, | 55 | public BSPrimLinkable(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, |
47 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) | 56 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) |
48 | : base(localID, primName, parent_scene, pos, size, rotation, pbs, pisPhysical) | 57 | : base(localID, primName, parent_scene, pos, size, rotation, pbs, pisPhysical) |
49 | { | 58 | { |
50 | Linkset = BSLinkset.Factory(PhysicsScene, this); | 59 | // Default linkset implementation for this prim |
60 | LinksetType = (BSLinkset.LinksetImplementation)BSParam.LinksetImplementation; | ||
51 | 61 | ||
52 | PhysicsScene.TaintedObject("BSPrimLinksetCompound.Refresh", delegate() | 62 | Linkset = BSLinkset.Factory(PhysScene, this); |
53 | { | 63 | |
54 | Linkset.Refresh(this); | 64 | Linkset.Refresh(this); |
55 | }); | ||
56 | } | 65 | } |
57 | 66 | ||
58 | public override void Destroy() | 67 | public override void Destroy() |
59 | { | 68 | { |
60 | Linkset = Linkset.RemoveMeFromLinkset(this); | 69 | Linkset = Linkset.RemoveMeFromLinkset(this, false /* inTaintTime */); |
61 | base.Destroy(); | 70 | base.Destroy(); |
62 | } | 71 | } |
63 | 72 | ||
64 | public override BSPhysicsShapeType PreferredPhysicalShape | ||
65 | { get { return Linkset.PreferredPhysicalShape(this); } } | ||
66 | |||
67 | public override void link(Manager.PhysicsActor obj) | 73 | public override void link(Manager.PhysicsActor obj) |
68 | { | 74 | { |
69 | BSPrimLinkable parent = obj as BSPrimLinkable; | 75 | BSPrimLinkable parent = obj as BSPrimLinkable; |
70 | if (parent != null) | 76 | if (parent != null) |
71 | { | 77 | { |
72 | BSPhysObject parentBefore = Linkset.LinksetRoot; | 78 | BSPhysObject parentBefore = Linkset.LinksetRoot; // DEBUG |
73 | int childrenBefore = Linkset.NumberOfChildren; | 79 | int childrenBefore = Linkset.NumberOfChildren; // DEBUG |
74 | 80 | ||
75 | Linkset = parent.Linkset.AddMeToLinkset(this); | 81 | Linkset = parent.Linkset.AddMeToLinkset(this); |
76 | 82 | ||
77 | DetailLog("{0},BSPrimLinkset.link,call,parentBefore={1}, childrenBefore=={2}, parentAfter={3}, childrenAfter={4}", | 83 | DetailLog("{0},BSPrimLinkable.link,call,parentBefore={1}, childrenBefore=={2}, parentAfter={3}, childrenAfter={4}", |
78 | LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren); | 84 | LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren); |
79 | } | 85 | } |
80 | return; | 86 | return; |
@@ -85,12 +91,12 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
85 | // TODO: decide if this parent checking needs to happen at taint time | 91 | // TODO: decide if this parent checking needs to happen at taint time |
86 | // Race condition here: if link() and delink() in same simulation tick, the delink will not happen | 92 | // Race condition here: if link() and delink() in same simulation tick, the delink will not happen |
87 | 93 | ||
88 | BSPhysObject parentBefore = Linkset.LinksetRoot; | 94 | BSPhysObject parentBefore = Linkset.LinksetRoot; // DEBUG |
89 | int childrenBefore = Linkset.NumberOfChildren; | 95 | int childrenBefore = Linkset.NumberOfChildren; // DEBUG |
90 | 96 | ||
91 | Linkset = Linkset.RemoveMeFromLinkset(this); | 97 | Linkset = Linkset.RemoveMeFromLinkset(this, false /* inTaintTime*/); |
92 | 98 | ||
93 | DetailLog("{0},BSPrimLinkset.delink,parentBefore={1},childrenBefore={2},parentAfter={3},childrenAfter={4}, ", | 99 | DetailLog("{0},BSPrimLinkable.delink,parentBefore={1},childrenBefore={2},parentAfter={3},childrenAfter={4}, ", |
94 | LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren); | 100 | LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren); |
95 | return; | 101 | return; |
96 | } | 102 | } |
@@ -102,7 +108,7 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
102 | set | 108 | set |
103 | { | 109 | { |
104 | base.Position = value; | 110 | base.Position = value; |
105 | PhysicsScene.TaintedObject("BSPrimLinkset.setPosition", delegate() | 111 | PhysScene.TaintedObject(LocalID, "BSPrimLinkable.setPosition", delegate() |
106 | { | 112 | { |
107 | Linkset.UpdateProperties(UpdatedProperties.Position, this); | 113 | Linkset.UpdateProperties(UpdatedProperties.Position, this); |
108 | }); | 114 | }); |
@@ -116,7 +122,7 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
116 | set | 122 | set |
117 | { | 123 | { |
118 | base.Orientation = value; | 124 | base.Orientation = value; |
119 | PhysicsScene.TaintedObject("BSPrimLinkset.setOrientation", delegate() | 125 | PhysScene.TaintedObject(LocalID, "BSPrimLinkable.setOrientation", delegate() |
120 | { | 126 | { |
121 | Linkset.UpdateProperties(UpdatedProperties.Orientation, this); | 127 | Linkset.UpdateProperties(UpdatedProperties.Orientation, this); |
122 | }); | 128 | }); |
@@ -128,6 +134,17 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
128 | get { return Linkset.LinksetMass; } | 134 | get { return Linkset.LinksetMass; } |
129 | } | 135 | } |
130 | 136 | ||
137 | public override OMV.Vector3 CenterOfMass | ||
138 | { | ||
139 | get { return Linkset.CenterOfMass; } | ||
140 | } | ||
141 | |||
142 | public override OMV.Vector3 GeometricCenter | ||
143 | { | ||
144 | get { return Linkset.GeometricCenter; } | ||
145 | } | ||
146 | |||
147 | // Refresh the linkset structure and parameters when the prim's physical parameters are changed. | ||
131 | public override void UpdatePhysicalParameters() | 148 | public override void UpdatePhysicalParameters() |
132 | { | 149 | { |
133 | base.UpdatePhysicalParameters(); | 150 | base.UpdatePhysicalParameters(); |
@@ -139,44 +156,193 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
139 | Linkset.Refresh(this); | 156 | Linkset.Refresh(this); |
140 | } | 157 | } |
141 | 158 | ||
159 | // When the prim is made dynamic or static, the linkset needs to change. | ||
142 | protected override void MakeDynamic(bool makeStatic) | 160 | protected override void MakeDynamic(bool makeStatic) |
143 | { | 161 | { |
144 | base.MakeDynamic(makeStatic); | 162 | base.MakeDynamic(makeStatic); |
145 | if (makeStatic) | 163 | if (Linkset != null) // null can happen during initialization |
146 | Linkset.MakeStatic(this); | 164 | { |
147 | else | 165 | if (makeStatic) |
148 | Linkset.MakeDynamic(this); | 166 | Linkset.MakeStatic(this); |
167 | else | ||
168 | Linkset.MakeDynamic(this); | ||
169 | } | ||
149 | } | 170 | } |
150 | 171 | ||
151 | // Body is being taken apart. Remove physical dependencies and schedule a rebuild. | 172 | // Body is being taken apart. Remove physical dependencies and schedule a rebuild. |
152 | protected override void RemoveBodyDependencies() | 173 | protected override void RemoveDependencies() |
153 | { | 174 | { |
154 | Linkset.RemoveBodyDependencies(this); | 175 | Linkset.RemoveDependencies(this); |
155 | base.RemoveBodyDependencies(); | 176 | base.RemoveDependencies(); |
156 | } | 177 | } |
157 | 178 | ||
179 | // Called after a simulation step for the changes in physical object properties. | ||
180 | // Do any filtering/modification needed for linksets. | ||
158 | public override void UpdateProperties(EntityProperties entprop) | 181 | public override void UpdateProperties(EntityProperties entprop) |
159 | { | 182 | { |
160 | if (Linkset.IsRoot(this)) | 183 | if (Linkset.IsRoot(this) || Linkset.ShouldReportPropertyUpdates(this)) |
161 | { | 184 | { |
162 | // Properties are only updated for the roots of a linkset. | 185 | // Properties are only updated for the roots of a linkset. |
163 | // TODO: this will have to change when linksets are articulated. | 186 | // TODO: this will have to change when linksets are articulated. |
164 | base.UpdateProperties(entprop); | 187 | base.UpdateProperties(entprop); |
165 | } | 188 | } |
189 | /* | ||
190 | else | ||
191 | { | ||
192 | // For debugging, report the movement of children | ||
193 | DetailLog("{0},BSPrim.UpdateProperties,child,pos={1},orient={2},vel={3},accel={4},rotVel={5}", | ||
194 | LocalID, entprop.Position, entprop.Rotation, entprop.Velocity, | ||
195 | entprop.Acceleration, entprop.RotationalVelocity); | ||
196 | } | ||
197 | */ | ||
166 | // The linkset might like to know about changing locations | 198 | // The linkset might like to know about changing locations |
167 | Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this); | 199 | Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this); |
168 | } | 200 | } |
169 | 201 | ||
202 | // Called after a simulation step to post a collision with this object. | ||
203 | // This returns 'true' if the collision has been queued and the SendCollisions call must | ||
204 | // be made at the end of the simulation step. | ||
170 | public override bool Collide(uint collidingWith, BSPhysObject collidee, | 205 | public override bool Collide(uint collidingWith, BSPhysObject collidee, |
171 | OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) | 206 | OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) |
172 | { | 207 | { |
173 | // prims in the same linkset cannot collide with each other | 208 | bool ret = false; |
174 | BSPrimLinkable convCollidee = collidee as BSPrimLinkable; | 209 | // Ask the linkset if it wants to handle the collision |
175 | if (convCollidee != null && (this.Linkset.LinksetID == convCollidee.Linkset.LinksetID)) | 210 | if (!Linkset.HandleCollide(collidingWith, collidee, contactPoint, contactNormal, pentrationDepth)) |
211 | { | ||
212 | // The linkset didn't handle it so pass the collision through normal processing | ||
213 | ret = base.Collide(collidingWith, collidee, contactPoint, contactNormal, pentrationDepth); | ||
214 | } | ||
215 | return ret; | ||
216 | } | ||
217 | |||
218 | // A linkset reports any collision on any part of the linkset. | ||
219 | public long SomeCollisionSimulationStep = 0; | ||
220 | public override bool HasSomeCollision | ||
221 | { | ||
222 | get | ||
223 | { | ||
224 | return (SomeCollisionSimulationStep == PhysScene.SimulationStep) || base.IsColliding; | ||
225 | } | ||
226 | set | ||
176 | { | 227 | { |
177 | return false; | 228 | if (value) |
229 | SomeCollisionSimulationStep = PhysScene.SimulationStep; | ||
230 | else | ||
231 | SomeCollisionSimulationStep = 0; | ||
232 | |||
233 | base.HasSomeCollision = value; | ||
234 | } | ||
235 | } | ||
236 | |||
237 | // Convert the existing linkset of this prim into a new type. | ||
238 | public bool ConvertLinkset(BSLinkset.LinksetImplementation newType) | ||
239 | { | ||
240 | bool ret = false; | ||
241 | if (LinksetType != newType) | ||
242 | { | ||
243 | DetailLog("{0},BSPrimLinkable.ConvertLinkset,oldT={1},newT={2}", LocalID, LinksetType, newType); | ||
244 | |||
245 | // Set the implementation type first so the call to BSLinkset.Factory gets the new type. | ||
246 | this.LinksetType = newType; | ||
247 | |||
248 | BSLinkset oldLinkset = this.Linkset; | ||
249 | BSLinkset newLinkset = BSLinkset.Factory(PhysScene, this); | ||
250 | |||
251 | this.Linkset = newLinkset; | ||
252 | |||
253 | // Pick up any physical dependencies this linkset might have in the physics engine. | ||
254 | oldLinkset.RemoveDependencies(this); | ||
255 | |||
256 | // Create a list of the children (mainly because can't interate through a list that's changing) | ||
257 | List<BSPrimLinkable> children = new List<BSPrimLinkable>(); | ||
258 | oldLinkset.ForEachMember((child) => | ||
259 | { | ||
260 | if (!oldLinkset.IsRoot(child)) | ||
261 | children.Add(child); | ||
262 | return false; // 'false' says to continue to next member | ||
263 | }); | ||
264 | |||
265 | // Remove the children from the old linkset and add to the new (will be a new instance from the factory) | ||
266 | foreach (BSPrimLinkable child in children) | ||
267 | { | ||
268 | oldLinkset.RemoveMeFromLinkset(child, true /*inTaintTime*/); | ||
269 | } | ||
270 | foreach (BSPrimLinkable child in children) | ||
271 | { | ||
272 | newLinkset.AddMeToLinkset(child); | ||
273 | child.Linkset = newLinkset; | ||
274 | } | ||
275 | |||
276 | // Force the shape and linkset to get reconstructed | ||
277 | newLinkset.Refresh(this); | ||
278 | this.ForceBodyShapeRebuild(true /* inTaintTime */); | ||
279 | } | ||
280 | return ret; | ||
281 | } | ||
282 | |||
283 | #region Extension | ||
284 | public override object Extension(string pFunct, params object[] pParams) | ||
285 | { | ||
286 | DetailLog("{0} BSPrimLinkable.Extension,op={1},nParam={2}", LocalID, pFunct, pParams.Length); | ||
287 | object ret = null; | ||
288 | switch (pFunct) | ||
289 | { | ||
290 | // physGetLinksetType(); | ||
291 | // pParams = [ BSPhysObject root, null ] | ||
292 | case ExtendedPhysics.PhysFunctGetLinksetType: | ||
293 | { | ||
294 | ret = (object)LinksetType; | ||
295 | DetailLog("{0},BSPrimLinkable.Extension.physGetLinksetType,type={1}", LocalID, ret); | ||
296 | break; | ||
297 | } | ||
298 | // physSetLinksetType(type); | ||
299 | // pParams = [ BSPhysObject root, null, integer type ] | ||
300 | case ExtendedPhysics.PhysFunctSetLinksetType: | ||
301 | { | ||
302 | if (pParams.Length > 2) | ||
303 | { | ||
304 | BSLinkset.LinksetImplementation linksetType = (BSLinkset.LinksetImplementation)pParams[2]; | ||
305 | if (Linkset.IsRoot(this)) | ||
306 | { | ||
307 | PhysScene.TaintedObject(LocalID, "BSPrim.PhysFunctSetLinksetType", delegate() | ||
308 | { | ||
309 | // Cause the linkset type to change | ||
310 | DetailLog("{0},BSPrimLinkable.Extension.physSetLinksetType, oldType={1},newType={2}", | ||
311 | LocalID, Linkset.LinksetImpl, linksetType); | ||
312 | ConvertLinkset(linksetType); | ||
313 | }); | ||
314 | } | ||
315 | ret = (object)(int)linksetType; | ||
316 | } | ||
317 | break; | ||
318 | } | ||
319 | // physChangeLinkType(linknum, typeCode); | ||
320 | // pParams = [ BSPhysObject root, BSPhysObject child, integer linkType ] | ||
321 | case ExtendedPhysics.PhysFunctChangeLinkType: | ||
322 | { | ||
323 | ret = Linkset.Extension(pFunct, pParams); | ||
324 | break; | ||
325 | } | ||
326 | // physGetLinkType(linknum); | ||
327 | // pParams = [ BSPhysObject root, BSPhysObject child ] | ||
328 | case ExtendedPhysics.PhysFunctGetLinkType: | ||
329 | { | ||
330 | ret = Linkset.Extension(pFunct, pParams); | ||
331 | break; | ||
332 | } | ||
333 | // physChangeLinkParams(linknum, [code, value, code, value, ...]); | ||
334 | // pParams = [ BSPhysObject root, BSPhysObject child, object[] [ string op, object opParam, string op, object opParam, ... ] ] | ||
335 | case ExtendedPhysics.PhysFunctChangeLinkParams: | ||
336 | { | ||
337 | ret = Linkset.Extension(pFunct, pParams); | ||
338 | break; | ||
339 | } | ||
340 | default: | ||
341 | ret = base.Extension(pFunct, pParams); | ||
342 | break; | ||
178 | } | 343 | } |
179 | return base.Collide(collidingWith, collidee, contactPoint, contactNormal, pentrationDepth); | 344 | return ret; |
180 | } | 345 | } |
346 | #endregion // Extension | ||
181 | } | 347 | } |
182 | } | 348 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index e6aefd5..b3dfa41 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
@@ -56,12 +56,23 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
56 | public string BulletEngineName { get; private set; } | 56 | public string BulletEngineName { get; private set; } |
57 | public BSAPITemplate PE; | 57 | public BSAPITemplate PE; |
58 | 58 | ||
59 | // If the physics engine is running on a separate thread | ||
60 | public Thread m_physicsThread; | ||
61 | |||
59 | public Dictionary<uint, BSPhysObject> PhysObjects; | 62 | public Dictionary<uint, BSPhysObject> PhysObjects; |
60 | public BSShapeCollection Shapes; | 63 | public BSShapeCollection Shapes; |
61 | 64 | ||
62 | // Keeping track of the objects with collisions so we can report begin and end of a collision | 65 | // Keeping track of the objects with collisions so we can report begin and end of a collision |
63 | public HashSet<BSPhysObject> ObjectsWithCollisions = new HashSet<BSPhysObject>(); | 66 | public HashSet<BSPhysObject> ObjectsWithCollisions = new HashSet<BSPhysObject>(); |
64 | public HashSet<BSPhysObject> ObjectsWithNoMoreCollisions = new HashSet<BSPhysObject>(); | 67 | public HashSet<BSPhysObject> ObjectsWithNoMoreCollisions = new HashSet<BSPhysObject>(); |
68 | |||
69 | // All the collision processing is protected with this lock object | ||
70 | public Object CollisionLock = new Object(); | ||
71 | |||
72 | // Properties are updated here | ||
73 | public Object UpdateLock = new Object(); | ||
74 | public HashSet<BSPhysObject> ObjectsWithUpdates = new HashSet<BSPhysObject>(); | ||
75 | |||
65 | // Keep track of all the avatars so we can send them a collision event | 76 | // Keep track of all the avatars so we can send them a collision event |
66 | // every tick so OpenSim will update its animation. | 77 | // every tick so OpenSim will update its animation. |
67 | private HashSet<BSPhysObject> m_avatars = new HashSet<BSPhysObject>(); | 78 | private HashSet<BSPhysObject> m_avatars = new HashSet<BSPhysObject>(); |
@@ -77,12 +88,22 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
77 | public BSConstraintCollection Constraints { get; private set; } | 88 | public BSConstraintCollection Constraints { get; private set; } |
78 | 89 | ||
79 | // Simulation parameters | 90 | // Simulation parameters |
91 | internal float m_physicsStepTime; // if running independently, the interval simulated by default | ||
92 | |||
80 | internal int m_maxSubSteps; | 93 | internal int m_maxSubSteps; |
81 | internal float m_fixedTimeStep; | 94 | internal float m_fixedTimeStep; |
82 | internal long m_simulationStep = 0; | 95 | |
83 | internal float NominalFrameRate { get; set; } | 96 | internal float m_simulatedTime; // the time simulated previously. Used for physics framerate calc. |
97 | |||
98 | internal long m_simulationStep = 0; // The current simulation step. | ||
84 | public long SimulationStep { get { return m_simulationStep; } } | 99 | public long SimulationStep { get { return m_simulationStep; } } |
85 | internal float LastTimeStep { get; private set; } | 100 | // A number to use for SimulationStep that is probably not any step value |
101 | // Used by the collision code (which remembers the step when a collision happens) to remember not any simulation step. | ||
102 | public static long NotASimulationStep = -1234; | ||
103 | |||
104 | internal float LastTimeStep { get; private set; } // The simulation time from the last invocation of Simulate() | ||
105 | |||
106 | internal float NominalFrameRate { get; set; } // Parameterized ideal frame rate that simulation is scaled to | ||
86 | 107 | ||
87 | // Physical objects can register for prestep or poststep events | 108 | // Physical objects can register for prestep or poststep events |
88 | public delegate void PreStepAction(float timeStep); | 109 | public delegate void PreStepAction(float timeStep); |
@@ -90,7 +111,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
90 | public event PreStepAction BeforeStep; | 111 | public event PreStepAction BeforeStep; |
91 | public event PostStepAction AfterStep; | 112 | public event PostStepAction AfterStep; |
92 | 113 | ||
93 | // A value of the time now so all the collision and update routines do not have to get their own | 114 | // A value of the time 'now' so all the collision and update routines do not have to get their own |
94 | // Set to 'now' just before all the prims and actors are called for collisions and updates | 115 | // Set to 'now' just before all the prims and actors are called for collisions and updates |
95 | public int SimulationNowTime { get; private set; } | 116 | public int SimulationNowTime { get; private set; } |
96 | 117 | ||
@@ -136,12 +157,20 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
136 | public delegate void TaintCallback(); | 157 | public delegate void TaintCallback(); |
137 | private struct TaintCallbackEntry | 158 | private struct TaintCallbackEntry |
138 | { | 159 | { |
160 | public String originator; | ||
139 | public String ident; | 161 | public String ident; |
140 | public TaintCallback callback; | 162 | public TaintCallback callback; |
141 | public TaintCallbackEntry(string i, TaintCallback c) | 163 | public TaintCallbackEntry(string pIdent, TaintCallback pCallBack) |
164 | { | ||
165 | originator = BSScene.DetailLogZero; | ||
166 | ident = pIdent; | ||
167 | callback = pCallBack; | ||
168 | } | ||
169 | public TaintCallbackEntry(string pOrigin, string pIdent, TaintCallback pCallBack) | ||
142 | { | 170 | { |
143 | ident = i; | 171 | originator = pOrigin; |
144 | callback = c; | 172 | ident = pIdent; |
173 | callback = pCallBack; | ||
145 | } | 174 | } |
146 | } | 175 | } |
147 | private Object _taintLock = new Object(); // lock for using the next object | 176 | private Object _taintLock = new Object(); // lock for using the next object |
@@ -188,6 +217,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
188 | PhysObjects = new Dictionary<uint, BSPhysObject>(); | 217 | PhysObjects = new Dictionary<uint, BSPhysObject>(); |
189 | Shapes = new BSShapeCollection(this); | 218 | Shapes = new BSShapeCollection(this); |
190 | 219 | ||
220 | m_simulatedTime = 0f; | ||
221 | LastTimeStep = 0.1f; | ||
222 | |||
191 | // Allocate pinned memory to pass parameters. | 223 | // Allocate pinned memory to pass parameters. |
192 | UnmanagedParams = new ConfigurationParameters[1]; | 224 | UnmanagedParams = new ConfigurationParameters[1]; |
193 | 225 | ||
@@ -202,8 +234,8 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
202 | // can be left in and every call doesn't have to check for null. | 234 | // can be left in and every call doesn't have to check for null. |
203 | if (m_physicsLoggingEnabled) | 235 | if (m_physicsLoggingEnabled) |
204 | { | 236 | { |
205 | PhysicsLogging = new Logging.LogWriter(m_physicsLoggingDir, m_physicsLoggingPrefix, m_physicsLoggingFileMinutes); | 237 | PhysicsLogging = new Logging.LogWriter(m_physicsLoggingDir, m_physicsLoggingPrefix, m_physicsLoggingFileMinutes, m_physicsLoggingDoFlush); |
206 | PhysicsLogging.ErrorLogger = m_log; // for DEBUG. Let's the logger output error messages. | 238 | PhysicsLogging.ErrorLogger = m_log; // for DEBUG. Let's the logger output its own error messages. |
207 | } | 239 | } |
208 | else | 240 | else |
209 | { | 241 | { |
@@ -227,10 +259,20 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
227 | TerrainManager = new BSTerrainManager(this); | 259 | TerrainManager = new BSTerrainManager(this); |
228 | TerrainManager.CreateInitialGroundPlaneAndTerrain(); | 260 | TerrainManager.CreateInitialGroundPlaneAndTerrain(); |
229 | 261 | ||
230 | m_log.WarnFormat("{0} Linksets implemented with {1}", LogHeader, (BSLinkset.LinksetImplementation)BSParam.LinksetImplementation); | 262 | // Put some informational messages into the log file. |
263 | m_log.InfoFormat("{0} Linksets implemented with {1}", LogHeader, (BSLinkset.LinksetImplementation)BSParam.LinksetImplementation); | ||
231 | 264 | ||
232 | InTaintTime = false; | 265 | InTaintTime = false; |
233 | m_initialized = true; | 266 | m_initialized = true; |
267 | |||
268 | // If the physics engine runs on its own thread, start same. | ||
269 | if (BSParam.UseSeparatePhysicsThread) | ||
270 | { | ||
271 | // The physics simulation should happen independently of the heartbeat loop | ||
272 | m_physicsThread = new Thread(BulletSPluginPhysicsThread); | ||
273 | m_physicsThread.Name = BulletEngineName; | ||
274 | m_physicsThread.Start(); | ||
275 | } | ||
234 | } | 276 | } |
235 | 277 | ||
236 | // All default parameter values are set here. There should be no values set in the | 278 | // All default parameter values are set here. There should be no values set in the |
@@ -268,6 +310,13 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
268 | // Do any replacements in the parameters | 310 | // Do any replacements in the parameters |
269 | m_physicsLoggingPrefix = m_physicsLoggingPrefix.Replace("%REGIONNAME%", RegionName); | 311 | m_physicsLoggingPrefix = m_physicsLoggingPrefix.Replace("%REGIONNAME%", RegionName); |
270 | } | 312 | } |
313 | else | ||
314 | { | ||
315 | // Nothing in the configuration INI file so assume unmanaged and other defaults. | ||
316 | BulletEngineName = "BulletUnmanaged"; | ||
317 | m_physicsLoggingEnabled = false; | ||
318 | VehicleLoggingEnabled = false; | ||
319 | } | ||
271 | 320 | ||
272 | // The material characteristics. | 321 | // The material characteristics. |
273 | BSMaterials.InitializeFromDefaults(Params); | 322 | BSMaterials.InitializeFromDefaults(Params); |
@@ -311,11 +360,22 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
311 | 360 | ||
312 | switch (selectionName) | 361 | switch (selectionName) |
313 | { | 362 | { |
363 | case "bullet": | ||
314 | case "bulletunmanaged": | 364 | case "bulletunmanaged": |
315 | ret = new BSAPIUnman(engineName, this); | 365 | ret = new BSAPIUnman(engineName, this); |
316 | break; | 366 | break; |
317 | case "bulletxna": | 367 | case "bulletxna": |
318 | ret = new BSAPIXNA(engineName, this); | 368 | ret = new BSAPIXNA(engineName, this); |
369 | // Disable some features that are not implemented in BulletXNA | ||
370 | m_log.InfoFormat("{0} Disabling some physics features not implemented by BulletXNA", LogHeader); | ||
371 | m_log.InfoFormat("{0} Disabling ShouldUseBulletHACD", LogHeader); | ||
372 | BSParam.ShouldUseBulletHACD = false; | ||
373 | m_log.InfoFormat("{0} Disabling ShouldUseSingleConvexHullForPrims", LogHeader); | ||
374 | BSParam.ShouldUseSingleConvexHullForPrims = false; | ||
375 | m_log.InfoFormat("{0} Disabling ShouldUseGImpactShapeForPrims", LogHeader); | ||
376 | BSParam.ShouldUseGImpactShapeForPrims = false; | ||
377 | m_log.InfoFormat("{0} Setting terrain implimentation to Heightmap", LogHeader); | ||
378 | BSParam.TerrainImplementation = (float)BSTerrainPhys.TerrainImplementation.Heightmap; | ||
319 | break; | 379 | break; |
320 | } | 380 | } |
321 | 381 | ||
@@ -325,7 +385,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
325 | } | 385 | } |
326 | else | 386 | else |
327 | { | 387 | { |
328 | m_log.WarnFormat("{0} Selected bullet engine {1} -> {2}/{3}", LogHeader, engineName, ret.BulletEngineName, ret.BulletEngineVersion); | 388 | m_log.InfoFormat("{0} Selected bullet engine {1} -> {2}/{3}", LogHeader, engineName, ret.BulletEngineName, ret.BulletEngineVersion); |
329 | } | 389 | } |
330 | 390 | ||
331 | return ret; | 391 | return ret; |
@@ -463,7 +523,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
463 | 523 | ||
464 | if (!m_initialized) return null; | 524 | if (!m_initialized) return null; |
465 | 525 | ||
466 | DetailLog("{0},BSScene.AddPrimShape,call", localID); | 526 | // DetailLog("{0},BSScene.AddPrimShape,call", localID); |
467 | 527 | ||
468 | BSPhysObject prim = new BSPrimLinkable(localID, primName, this, position, size, rotation, pbs, isPhysical); | 528 | BSPhysObject prim = new BSPrimLinkable(localID, primName, this, position, size, rotation, pbs, isPhysical); |
469 | lock (PhysObjects) PhysObjects.Add(localID, prim); | 529 | lock (PhysObjects) PhysObjects.Add(localID, prim); |
@@ -478,25 +538,41 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
478 | #endregion // Prim and Avatar addition and removal | 538 | #endregion // Prim and Avatar addition and removal |
479 | 539 | ||
480 | #region Simulation | 540 | #region Simulation |
481 | // Simulate one timestep | 541 | |
542 | // Call from the simulator to send physics information to the simulator objects. | ||
543 | // This pushes all the collision and property update events into the objects in | ||
544 | // the simulator and, since it is on the heartbeat thread, there is an implicit | ||
545 | // locking of those data structures from other heartbeat events. | ||
546 | // If the physics engine is running on a separate thread, the update information | ||
547 | // will be in the ObjectsWithCollions and ObjectsWithUpdates structures. | ||
482 | public override float Simulate(float timeStep) | 548 | public override float Simulate(float timeStep) |
483 | { | 549 | { |
550 | if (!BSParam.UseSeparatePhysicsThread) | ||
551 | { | ||
552 | DoPhysicsStep(timeStep); | ||
553 | } | ||
554 | return SendUpdatesToSimulator(timeStep); | ||
555 | } | ||
556 | |||
557 | // Call the physics engine to do one 'timeStep' and collect collisions and updates | ||
558 | // into ObjectsWithCollisions and ObjectsWithUpdates data structures. | ||
559 | private void DoPhysicsStep(float timeStep) | ||
560 | { | ||
484 | // prevent simulation until we've been initialized | 561 | // prevent simulation until we've been initialized |
485 | if (!m_initialized) return 5.0f; | 562 | if (!m_initialized) return; |
486 | 563 | ||
487 | LastTimeStep = timeStep; | 564 | LastTimeStep = timeStep; |
488 | 565 | ||
489 | int updatedEntityCount = 0; | 566 | int updatedEntityCount = 0; |
490 | int collidersCount = 0; | 567 | int collidersCount = 0; |
491 | 568 | ||
492 | int beforeTime = 0; | 569 | int beforeTime = Util.EnvironmentTickCount(); |
493 | int simTime = 0; | 570 | int simTime = 0; |
494 | 571 | ||
495 | // update the prim states while we know the physics engine is not busy | ||
496 | int numTaints = _taintOperations.Count; | 572 | int numTaints = _taintOperations.Count; |
497 | |||
498 | InTaintTime = true; // Only used for debugging so locking is not necessary. | 573 | InTaintTime = true; // Only used for debugging so locking is not necessary. |
499 | 574 | ||
575 | // update the prim states while we know the physics engine is not busy | ||
500 | ProcessTaints(); | 576 | ProcessTaints(); |
501 | 577 | ||
502 | // Some of the physical objects requre individual, pre-step calls | 578 | // Some of the physical objects requre individual, pre-step calls |
@@ -519,18 +595,8 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
519 | int numSubSteps = 0; | 595 | int numSubSteps = 0; |
520 | try | 596 | try |
521 | { | 597 | { |
522 | if (PhysicsLogging.Enabled) | ||
523 | beforeTime = Util.EnvironmentTickCount(); | ||
524 | |||
525 | numSubSteps = PE.PhysicsStep(World, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out collidersCount); | 598 | numSubSteps = PE.PhysicsStep(World, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out collidersCount); |
526 | 599 | ||
527 | if (PhysicsLogging.Enabled) | ||
528 | { | ||
529 | simTime = Util.EnvironmentTickCountSubtract(beforeTime); | ||
530 | DetailLog("{0},Simulate,call, frame={1}, nTaints={2}, simTime={3}, substeps={4}, updates={5}, colliders={6}, objWColl={7}", | ||
531 | DetailLogZero, m_simulationStep, numTaints, simTime, numSubSteps, | ||
532 | updatedEntityCount, collidersCount, ObjectsWithCollisions.Count); | ||
533 | } | ||
534 | } | 600 | } |
535 | catch (Exception e) | 601 | catch (Exception e) |
536 | { | 602 | { |
@@ -542,77 +608,63 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
542 | collidersCount = 0; | 608 | collidersCount = 0; |
543 | } | 609 | } |
544 | 610 | ||
611 | // Make the physics engine dump useful statistics periodically | ||
545 | if (PhysicsMetricDumpFrames != 0 && ((m_simulationStep % PhysicsMetricDumpFrames) == 0)) | 612 | if (PhysicsMetricDumpFrames != 0 && ((m_simulationStep % PhysicsMetricDumpFrames) == 0)) |
546 | PE.DumpPhysicsStatistics(World); | 613 | PE.DumpPhysicsStatistics(World); |
547 | 614 | ||
548 | // Get a value for 'now' so all the collision and update routines don't have to get their own. | 615 | // Get a value for 'now' so all the collision and update routines don't have to get their own. |
549 | SimulationNowTime = Util.EnvironmentTickCount(); | 616 | SimulationNowTime = Util.EnvironmentTickCount(); |
550 | 617 | ||
551 | // If there were collisions, process them by sending the event to the prim. | 618 | // Send collision information to the colliding objects. The objects decide if the collision |
552 | // Collisions must be processed before updates. | 619 | // is 'real' (like linksets don't collide with themselves) and the individual objects |
553 | if (collidersCount > 0) | 620 | // know if the simulator has subscribed to collisions. |
621 | lock (CollisionLock) | ||
554 | { | 622 | { |
555 | for (int ii = 0; ii < collidersCount; ii++) | 623 | if (collidersCount > 0) |
556 | { | 624 | { |
557 | uint cA = m_collisionArray[ii].aID; | 625 | for (int ii = 0; ii < collidersCount; ii++) |
558 | uint cB = m_collisionArray[ii].bID; | ||
559 | Vector3 point = m_collisionArray[ii].point; | ||
560 | Vector3 normal = m_collisionArray[ii].normal; | ||
561 | float penetration = m_collisionArray[ii].penetration; | ||
562 | SendCollision(cA, cB, point, normal, penetration); | ||
563 | SendCollision(cB, cA, point, -normal, penetration); | ||
564 | } | ||
565 | } | ||
566 | |||
567 | // The above SendCollision's batch up the collisions on the objects. | ||
568 | // Now push the collisions into the simulator. | ||
569 | if (ObjectsWithCollisions.Count > 0) | ||
570 | { | ||
571 | foreach (BSPhysObject bsp in ObjectsWithCollisions) | ||
572 | if (!bsp.SendCollisions()) | ||
573 | { | 626 | { |
574 | // If the object is done colliding, see that it's removed from the colliding list | 627 | uint cA = m_collisionArray[ii].aID; |
575 | ObjectsWithNoMoreCollisions.Add(bsp); | 628 | uint cB = m_collisionArray[ii].bID; |
629 | Vector3 point = m_collisionArray[ii].point; | ||
630 | Vector3 normal = m_collisionArray[ii].normal; | ||
631 | float penetration = m_collisionArray[ii].penetration; | ||
632 | SendCollision(cA, cB, point, normal, penetration); | ||
633 | SendCollision(cB, cA, point, -normal, penetration); | ||
576 | } | 634 | } |
635 | } | ||
577 | } | 636 | } |
578 | 637 | ||
579 | // This is a kludge to get avatar movement updates. | 638 | // If any of the objects had updated properties, tell the managed objects about the update |
580 | // The simulator expects collisions for avatars even if there are have been no collisions. | 639 | // and remember that there was a change so it will be passed to the simulator. |
581 | // The event updates avatar animations and stuff. | 640 | lock (UpdateLock) |
582 | // If you fix avatar animation updates, remove this overhead and let normal collision processing happen. | ||
583 | foreach (BSPhysObject bsp in m_avatars) | ||
584 | if (!ObjectsWithCollisions.Contains(bsp)) // don't call avatars twice | ||
585 | bsp.SendCollisions(); | ||
586 | |||
587 | // Objects that are done colliding are removed from the ObjectsWithCollisions list. | ||
588 | // Not done above because it is inside an iteration of ObjectWithCollisions. | ||
589 | // This complex collision processing is required to create an empty collision | ||
590 | // event call after all real collisions have happened on an object. This enables | ||
591 | // the simulator to generate the 'collision end' event. | ||
592 | if (ObjectsWithNoMoreCollisions.Count > 0) | ||
593 | { | ||
594 | foreach (BSPhysObject po in ObjectsWithNoMoreCollisions) | ||
595 | ObjectsWithCollisions.Remove(po); | ||
596 | ObjectsWithNoMoreCollisions.Clear(); | ||
597 | } | ||
598 | // Done with collisions. | ||
599 | |||
600 | // If any of the objects had updated properties, tell the object it has been changed by the physics engine | ||
601 | if (updatedEntityCount > 0) | ||
602 | { | 641 | { |
603 | for (int ii = 0; ii < updatedEntityCount; ii++) | 642 | if (updatedEntityCount > 0) |
604 | { | 643 | { |
605 | EntityProperties entprop = m_updateArray[ii]; | 644 | for (int ii = 0; ii < updatedEntityCount; ii++) |
606 | BSPhysObject pobj; | ||
607 | if (PhysObjects.TryGetValue(entprop.ID, out pobj)) | ||
608 | { | 645 | { |
609 | pobj.UpdateProperties(entprop); | 646 | EntityProperties entprop = m_updateArray[ii]; |
647 | BSPhysObject pobj; | ||
648 | if (PhysObjects.TryGetValue(entprop.ID, out pobj)) | ||
649 | { | ||
650 | if (pobj.IsInitialized) | ||
651 | pobj.UpdateProperties(entprop); | ||
652 | } | ||
610 | } | 653 | } |
611 | } | 654 | } |
612 | } | 655 | } |
613 | 656 | ||
657 | // Some actors want to know when the simulation step is complete. | ||
614 | TriggerPostStepEvent(timeStep); | 658 | TriggerPostStepEvent(timeStep); |
615 | 659 | ||
660 | simTime = Util.EnvironmentTickCountSubtract(beforeTime); | ||
661 | if (PhysicsLogging.Enabled) | ||
662 | { | ||
663 | DetailLog("{0},DoPhysicsStep,complete,frame={1}, nTaints={2}, simTime={3}, substeps={4}, updates={5}, colliders={6}, objWColl={7}", | ||
664 | DetailLogZero, m_simulationStep, numTaints, simTime, numSubSteps, | ||
665 | updatedEntityCount, collidersCount, ObjectsWithCollisions.Count); | ||
666 | } | ||
667 | |||
616 | // The following causes the unmanaged code to output ALL the values found in ALL the objects in the world. | 668 | // The following causes the unmanaged code to output ALL the values found in ALL the objects in the world. |
617 | // Only enable this in a limited test world with few objects. | 669 | // Only enable this in a limited test world with few objects. |
618 | if (m_physicsPhysicalDumpEnabled) | 670 | if (m_physicsPhysicalDumpEnabled) |
@@ -621,7 +673,84 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
621 | // The physics engine returns the number of milliseconds it simulated this call. | 673 | // The physics engine returns the number of milliseconds it simulated this call. |
622 | // These are summed and normalized to one second and divided by 1000 to give the reported physics FPS. | 674 | // These are summed and normalized to one second and divided by 1000 to give the reported physics FPS. |
623 | // Multiply by a fixed nominal frame rate to give a rate similar to the simulator (usually 55). | 675 | // Multiply by a fixed nominal frame rate to give a rate similar to the simulator (usually 55). |
624 | return (float)numSubSteps * m_fixedTimeStep * 1000f * NominalFrameRate; | 676 | m_simulatedTime += (float)numSubSteps * m_fixedTimeStep * 1000f * NominalFrameRate; |
677 | } | ||
678 | |||
679 | // Called by a BSPhysObject to note that it has changed properties and this information | ||
680 | // should be passed up to the simulator at the proper time. | ||
681 | // Note: this is called by the BSPhysObject from invocation via DoPhysicsStep() above so | ||
682 | // this is is under UpdateLock. | ||
683 | public void PostUpdate(BSPhysObject updatee) | ||
684 | { | ||
685 | ObjectsWithUpdates.Add(updatee); | ||
686 | } | ||
687 | |||
688 | // The simulator thinks it is physics time so return all the collisions and position | ||
689 | // updates that were collected in actual physics simulation. | ||
690 | private float SendUpdatesToSimulator(float timeStep) | ||
691 | { | ||
692 | if (!m_initialized) return 5.0f; | ||
693 | |||
694 | DetailLog("{0},SendUpdatesToSimulator,collisions={1},updates={2},simedTime={3}", | ||
695 | BSScene.DetailLogZero, ObjectsWithCollisions.Count, ObjectsWithUpdates.Count, m_simulatedTime); | ||
696 | // Push the collisions into the simulator. | ||
697 | lock (CollisionLock) | ||
698 | { | ||
699 | if (ObjectsWithCollisions.Count > 0) | ||
700 | { | ||
701 | foreach (BSPhysObject bsp in ObjectsWithCollisions) | ||
702 | if (!bsp.SendCollisions()) | ||
703 | { | ||
704 | // If the object is done colliding, see that it's removed from the colliding list | ||
705 | ObjectsWithNoMoreCollisions.Add(bsp); | ||
706 | } | ||
707 | } | ||
708 | |||
709 | // This is a kludge to get avatar movement updates. | ||
710 | // The simulator expects collisions for avatars even if there are have been no collisions. | ||
711 | // The event updates avatar animations and stuff. | ||
712 | // If you fix avatar animation updates, remove this overhead and let normal collision processing happen. | ||
713 | foreach (BSPhysObject bsp in m_avatars) | ||
714 | if (!ObjectsWithCollisions.Contains(bsp)) // don't call avatars twice | ||
715 | bsp.SendCollisions(); | ||
716 | |||
717 | // Objects that are done colliding are removed from the ObjectsWithCollisions list. | ||
718 | // Not done above because it is inside an iteration of ObjectWithCollisions. | ||
719 | // This complex collision processing is required to create an empty collision | ||
720 | // event call after all real collisions have happened on an object. This allows | ||
721 | // the simulator to generate the 'collision end' event. | ||
722 | if (ObjectsWithNoMoreCollisions.Count > 0) | ||
723 | { | ||
724 | foreach (BSPhysObject po in ObjectsWithNoMoreCollisions) | ||
725 | ObjectsWithCollisions.Remove(po); | ||
726 | ObjectsWithNoMoreCollisions.Clear(); | ||
727 | } | ||
728 | } | ||
729 | |||
730 | // Call the simulator for each object that has physics property updates. | ||
731 | HashSet<BSPhysObject> updatedObjects = null; | ||
732 | lock (UpdateLock) | ||
733 | { | ||
734 | if (ObjectsWithUpdates.Count > 0) | ||
735 | { | ||
736 | updatedObjects = ObjectsWithUpdates; | ||
737 | ObjectsWithUpdates = new HashSet<BSPhysObject>(); | ||
738 | } | ||
739 | } | ||
740 | if (updatedObjects != null) | ||
741 | { | ||
742 | foreach (BSPhysObject obj in updatedObjects) | ||
743 | { | ||
744 | obj.RequestPhysicsterseUpdate(); | ||
745 | } | ||
746 | updatedObjects.Clear(); | ||
747 | } | ||
748 | |||
749 | // Return the framerate simulated to give the above returned results. | ||
750 | // (Race condition here but this is just bookkeeping so rare mistakes do not merit a lock). | ||
751 | float simTime = m_simulatedTime; | ||
752 | m_simulatedTime = 0f; | ||
753 | return simTime; | ||
625 | } | 754 | } |
626 | 755 | ||
627 | // Something has collided | 756 | // Something has collided |
@@ -640,21 +769,49 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
640 | return; | 769 | return; |
641 | } | 770 | } |
642 | 771 | ||
643 | // The terrain is not in the physical object list so 'collidee' can be null when Collide() is called. | 772 | // Note: the terrain is not in the physical object list so 'collidee' can be null when Collide() is called. |
644 | BSPhysObject collidee = null; | 773 | BSPhysObject collidee = null; |
645 | PhysObjects.TryGetValue(collidingWith, out collidee); | 774 | PhysObjects.TryGetValue(collidingWith, out collidee); |
646 | 775 | ||
647 | // DetailLog("{0},BSScene.SendCollision,collide,id={1},with={2}", DetailLogZero, localID, collidingWith); | 776 | // DetailLog("{0},BSScene.SendCollision,collide,id={1},with={2}", DetailLogZero, localID, collidingWith); |
648 | 777 | ||
649 | if (collider.Collide(collidingWith, collidee, collidePoint, collideNormal, penetration)) | 778 | if (collider.IsInitialized) |
650 | { | 779 | { |
651 | // If a collision was posted, remember to send it to the simulator | 780 | if (collider.Collide(collidingWith, collidee, collidePoint, collideNormal, penetration)) |
652 | ObjectsWithCollisions.Add(collider); | 781 | { |
782 | // If a collision was 'good', remember to send it to the simulator | ||
783 | ObjectsWithCollisions.Add(collider); | ||
784 | } | ||
653 | } | 785 | } |
654 | 786 | ||
655 | return; | 787 | return; |
656 | } | 788 | } |
657 | 789 | ||
790 | public void BulletSPluginPhysicsThread() | ||
791 | { | ||
792 | while (m_initialized) | ||
793 | { | ||
794 | int beginSimulationRealtimeMS = Util.EnvironmentTickCount(); | ||
795 | DoPhysicsStep(BSParam.PhysicsTimeStep); | ||
796 | int simulationRealtimeMS = Util.EnvironmentTickCountSubtract(beginSimulationRealtimeMS); | ||
797 | int simulationTimeVsRealtimeDifferenceMS = ((int)(BSParam.PhysicsTimeStep*1000f)) - simulationRealtimeMS; | ||
798 | |||
799 | if (simulationTimeVsRealtimeDifferenceMS > 0) | ||
800 | { | ||
801 | // The simulation of the time interval took less than realtime. | ||
802 | // Do a sleep for the rest of realtime. | ||
803 | Thread.Sleep(simulationTimeVsRealtimeDifferenceMS); | ||
804 | } | ||
805 | else | ||
806 | { | ||
807 | // The simulation took longer than realtime. | ||
808 | // Do some scaling of simulation time. | ||
809 | // TODO. | ||
810 | DetailLog("{0},BulletSPluginPhysicsThread,longerThanRealtime={1}", BSScene.DetailLogZero, simulationTimeVsRealtimeDifferenceMS); | ||
811 | } | ||
812 | } | ||
813 | } | ||
814 | |||
658 | #endregion // Simulation | 815 | #endregion // Simulation |
659 | 816 | ||
660 | public override void GetResults() { } | 817 | public override void GetResults() { } |
@@ -717,6 +874,14 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
717 | 874 | ||
718 | public override bool IsThreaded { get { return false; } } | 875 | public override bool IsThreaded { get { return false; } } |
719 | 876 | ||
877 | #region Extensions | ||
878 | public override object Extension(string pFunct, params object[] pParams) | ||
879 | { | ||
880 | DetailLog("{0} BSScene.Extension,op={1}", DetailLogZero, pFunct); | ||
881 | return base.Extension(pFunct, pParams); | ||
882 | } | ||
883 | #endregion // Extensions | ||
884 | |||
720 | #region Taints | 885 | #region Taints |
721 | // The simulation execution order is: | 886 | // The simulation execution order is: |
722 | // Simulate() | 887 | // Simulate() |
@@ -731,26 +896,37 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
731 | // Calls to the PhysicsActors can't directly call into the physics engine | 896 | // Calls to the PhysicsActors can't directly call into the physics engine |
732 | // because it might be busy. We delay changes to a known time. | 897 | // because it might be busy. We delay changes to a known time. |
733 | // We rely on C#'s closure to save and restore the context for the delegate. | 898 | // We rely on C#'s closure to save and restore the context for the delegate. |
734 | public void TaintedObject(String ident, TaintCallback callback) | 899 | public void TaintedObject(string pOriginator, string pIdent, TaintCallback pCallback) |
735 | { | 900 | { |
736 | if (!m_initialized) return; | 901 | TaintedObject(false /*inTaintTime*/, pOriginator, pIdent, pCallback); |
737 | 902 | } | |
738 | lock (_taintLock) | 903 | public void TaintedObject(uint pOriginator, String pIdent, TaintCallback pCallback) |
739 | { | 904 | { |
740 | _taintOperations.Add(new TaintCallbackEntry(ident, callback)); | 905 | TaintedObject(false /*inTaintTime*/, m_physicsLoggingEnabled ? pOriginator.ToString() : BSScene.DetailLogZero, pIdent, pCallback); |
741 | } | 906 | } |
742 | 907 | public void TaintedObject(bool inTaintTime, String pIdent, TaintCallback pCallback) | |
743 | return; | 908 | { |
909 | TaintedObject(inTaintTime, BSScene.DetailLogZero, pIdent, pCallback); | ||
910 | } | ||
911 | public void TaintedObject(bool inTaintTime, uint pOriginator, String pIdent, TaintCallback pCallback) | ||
912 | { | ||
913 | TaintedObject(inTaintTime, m_physicsLoggingEnabled ? pOriginator.ToString() : BSScene.DetailLogZero, pIdent, pCallback); | ||
744 | } | 914 | } |
745 | |||
746 | // Sometimes a potentially tainted operation can be used in and out of taint time. | 915 | // Sometimes a potentially tainted operation can be used in and out of taint time. |
747 | // This routine executes the command immediately if in taint-time otherwise it is queued. | 916 | // This routine executes the command immediately if in taint-time otherwise it is queued. |
748 | public void TaintedObject(bool inTaintTime, string ident, TaintCallback callback) | 917 | public void TaintedObject(bool inTaintTime, string pOriginator, string pIdent, TaintCallback pCallback) |
749 | { | 918 | { |
919 | if (!m_initialized) return; | ||
920 | |||
750 | if (inTaintTime) | 921 | if (inTaintTime) |
751 | callback(); | 922 | pCallback(); |
752 | else | 923 | else |
753 | TaintedObject(ident, callback); | 924 | { |
925 | lock (_taintLock) | ||
926 | { | ||
927 | _taintOperations.Add(new TaintCallbackEntry(pOriginator, pIdent, pCallback)); | ||
928 | } | ||
929 | } | ||
754 | } | 930 | } |
755 | 931 | ||
756 | private void TriggerPreStepEvent(float timeStep) | 932 | private void TriggerPreStepEvent(float timeStep) |
@@ -780,7 +956,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
780 | 956 | ||
781 | private void ProcessRegularTaints() | 957 | private void ProcessRegularTaints() |
782 | { | 958 | { |
783 | if (_taintOperations.Count > 0) // save allocating new list if there is nothing to process | 959 | if (m_initialized && _taintOperations.Count > 0) // save allocating new list if there is nothing to process |
784 | { | 960 | { |
785 | // swizzle a new list into the list location so we can process what's there | 961 | // swizzle a new list into the list location so we can process what's there |
786 | List<TaintCallbackEntry> oldList; | 962 | List<TaintCallbackEntry> oldList; |
@@ -794,7 +970,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
794 | { | 970 | { |
795 | try | 971 | try |
796 | { | 972 | { |
797 | DetailLog("{0},BSScene.ProcessTaints,doTaint,id={1}", DetailLogZero, tcbe.ident); // DEBUG DEBUG DEBUG | 973 | DetailLog("{0},BSScene.ProcessTaints,doTaint,id={1}", tcbe.originator, tcbe.ident); // DEBUG DEBUG DEBUG |
798 | tcbe.callback(); | 974 | tcbe.callback(); |
799 | } | 975 | } |
800 | catch (Exception e) | 976 | catch (Exception e) |
@@ -811,10 +987,11 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
811 | // will replace any previous operation by the same object. | 987 | // will replace any previous operation by the same object. |
812 | public void PostTaintObject(String ident, uint ID, TaintCallback callback) | 988 | public void PostTaintObject(String ident, uint ID, TaintCallback callback) |
813 | { | 989 | { |
814 | string uniqueIdent = ident + "-" + ID.ToString(); | 990 | string IDAsString = ID.ToString(); |
991 | string uniqueIdent = ident + "-" + IDAsString; | ||
815 | lock (_taintLock) | 992 | lock (_taintLock) |
816 | { | 993 | { |
817 | _postTaintOperations[uniqueIdent] = new TaintCallbackEntry(uniqueIdent, callback); | 994 | _postTaintOperations[uniqueIdent] = new TaintCallbackEntry(IDAsString, uniqueIdent, callback); |
818 | } | 995 | } |
819 | 996 | ||
820 | return; | 997 | return; |
@@ -823,7 +1000,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
823 | // Taints that happen after the normal taint processing but before the simulation step. | 1000 | // Taints that happen after the normal taint processing but before the simulation step. |
824 | private void ProcessPostTaintTaints() | 1001 | private void ProcessPostTaintTaints() |
825 | { | 1002 | { |
826 | if (_postTaintOperations.Count > 0) | 1003 | if (m_initialized && _postTaintOperations.Count > 0) |
827 | { | 1004 | { |
828 | Dictionary<string, TaintCallbackEntry> oldList; | 1005 | Dictionary<string, TaintCallbackEntry> oldList; |
829 | lock (_taintLock) | 1006 | lock (_taintLock) |
@@ -924,7 +1101,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
924 | string xval = val; | 1101 | string xval = val; |
925 | List<uint> xlIDs = lIDs; | 1102 | List<uint> xlIDs = lIDs; |
926 | string xparm = parm; | 1103 | string xparm = parm; |
927 | TaintedObject("BSScene.UpdateParameterSet", delegate() { | 1104 | TaintedObject(DetailLogZero, "BSScene.UpdateParameterSet", delegate() { |
928 | BSParam.ParameterDefnBase thisParam; | 1105 | BSParam.ParameterDefnBase thisParam; |
929 | if (BSParam.TryGetParameter(xparm, out thisParam)) | 1106 | if (BSParam.TryGetParameter(xparm, out thisParam)) |
930 | { | 1107 | { |
@@ -963,8 +1140,6 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
963 | public void DetailLog(string msg, params Object[] args) | 1140 | public void DetailLog(string msg, params Object[] args) |
964 | { | 1141 | { |
965 | PhysicsLogging.Write(msg, args); | 1142 | PhysicsLogging.Write(msg, args); |
966 | // Add the Flush() if debugging crashes. Gets all the messages written out. | ||
967 | if (m_physicsLoggingDoFlush) PhysicsLogging.Flush(); | ||
968 | } | 1143 | } |
969 | // Used to fill in the LocalID when there isn't one. It's the correct number of characters. | 1144 | // Used to fill in the LocalID when there isn't one. It's the correct number of characters. |
970 | public const string DetailLogZero = "0000000000"; | 1145 | public const string DetailLogZero = "0000000000"; |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 220fbbc..32bbc8f 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | |||
@@ -38,38 +38,15 @@ public sealed class BSShapeCollection : IDisposable | |||
38 | { | 38 | { |
39 | private static string LogHeader = "[BULLETSIM SHAPE COLLECTION]"; | 39 | private static string LogHeader = "[BULLETSIM SHAPE COLLECTION]"; |
40 | 40 | ||
41 | private BSScene PhysicsScene { get; set; } | 41 | private BSScene m_physicsScene { get; set; } |
42 | 42 | ||
43 | private Object m_collectionActivityLock = new Object(); | 43 | private Object m_collectionActivityLock = new Object(); |
44 | 44 | ||
45 | // Description of a Mesh | ||
46 | private struct MeshDesc | ||
47 | { | ||
48 | public BulletShape shape; | ||
49 | public int referenceCount; | ||
50 | public DateTime lastReferenced; | ||
51 | public UInt64 shapeKey; | ||
52 | } | ||
53 | |||
54 | // Description of a hull. | ||
55 | // Meshes and hulls have the same shape hash key but we only need hulls for efficient collision calculations. | ||
56 | private struct HullDesc | ||
57 | { | ||
58 | public BulletShape shape; | ||
59 | public int referenceCount; | ||
60 | public DateTime lastReferenced; | ||
61 | public UInt64 shapeKey; | ||
62 | } | ||
63 | |||
64 | // The sharable set of meshes and hulls. Indexed by their shape hash. | ||
65 | private Dictionary<System.UInt64, MeshDesc> Meshes = new Dictionary<System.UInt64, MeshDesc>(); | ||
66 | private Dictionary<System.UInt64, HullDesc> Hulls = new Dictionary<System.UInt64, HullDesc>(); | ||
67 | |||
68 | private bool DDetail = false; | 45 | private bool DDetail = false; |
69 | 46 | ||
70 | public BSShapeCollection(BSScene physScene) | 47 | public BSShapeCollection(BSScene physScene) |
71 | { | 48 | { |
72 | PhysicsScene = physScene; | 49 | m_physicsScene = physScene; |
73 | // Set the next to 'true' for very detailed shape update detailed logging (detailed details?) | 50 | // Set the next to 'true' for very detailed shape update detailed logging (detailed details?) |
74 | // While detailed debugging is still active, this is better than commenting out all the | 51 | // While detailed debugging is still active, this is better than commenting out all the |
75 | // DetailLog statements. When debugging slows down, this and the protected logging | 52 | // DetailLog statements. When debugging slows down, this and the protected logging |
@@ -86,22 +63,18 @@ public sealed class BSShapeCollection : IDisposable | |||
86 | // Mostly used for changing bodies out from under Linksets. | 63 | // Mostly used for changing bodies out from under Linksets. |
87 | // Useful for other cases where parameters need saving. | 64 | // Useful for other cases where parameters need saving. |
88 | // Passing 'null' says no callback. | 65 | // Passing 'null' says no callback. |
89 | public delegate void ShapeDestructionCallback(BulletShape shape); | 66 | public delegate void PhysicalDestructionCallback(BulletBody pBody, BulletShape pShape); |
90 | public delegate void BodyDestructionCallback(BulletBody body); | ||
91 | 67 | ||
92 | // Called to update/change the body and shape for an object. | 68 | // Called to update/change the body and shape for an object. |
93 | // First checks the shape and updates that if necessary then makes | 69 | // The object has some shape and body on it. Here we decide if that is the correct shape |
94 | // sure the body is of the right type. | 70 | // for the current state of the object (static/dynamic/...). |
71 | // If bodyCallback is not null, it is called if either the body or the shape are changed | ||
72 | // so dependencies (like constraints) can be removed before the physical object is dereferenced. | ||
95 | // Return 'true' if either the body or the shape changed. | 73 | // Return 'true' if either the body or the shape changed. |
96 | // 'shapeCallback' and 'bodyCallback' are, if non-null, functions called just before | 74 | // Called at taint-time. |
97 | // the current shape or body is destroyed. This allows the caller to remove any | 75 | public bool GetBodyAndShape(bool forceRebuild, BulletWorld sim, BSPhysObject prim, PhysicalDestructionCallback bodyCallback) |
98 | // higher level dependencies on the shape or body. Mostly used for LinkSets to | ||
99 | // remove the physical constraints before the body is destroyed. | ||
100 | // Called at taint-time!! | ||
101 | public bool GetBodyAndShape(bool forceRebuild, BulletWorld sim, BSPhysObject prim, | ||
102 | ShapeDestructionCallback shapeCallback, BodyDestructionCallback bodyCallback) | ||
103 | { | 76 | { |
104 | PhysicsScene.AssertInTaintTime("BSShapeCollection.GetBodyAndShape"); | 77 | m_physicsScene.AssertInTaintTime("BSShapeCollection.GetBodyAndShape"); |
105 | 78 | ||
106 | bool ret = false; | 79 | bool ret = false; |
107 | 80 | ||
@@ -111,12 +84,12 @@ public sealed class BSShapeCollection : IDisposable | |||
111 | // Do we have the correct geometry for this type of object? | 84 | // Do we have the correct geometry for this type of object? |
112 | // Updates prim.BSShape with information/pointers to shape. | 85 | // Updates prim.BSShape with information/pointers to shape. |
113 | // Returns 'true' of BSShape is changed to a new shape. | 86 | // Returns 'true' of BSShape is changed to a new shape. |
114 | bool newGeom = CreateGeom(forceRebuild, prim, shapeCallback); | 87 | bool newGeom = CreateGeom(forceRebuild, prim, bodyCallback); |
115 | // If we had to select a new shape geometry for the object, | 88 | // If we had to select a new shape geometry for the object, |
116 | // rebuild the body around it. | 89 | // rebuild the body around it. |
117 | // Updates prim.BSBody with information/pointers to requested body | 90 | // Updates prim.BSBody with information/pointers to requested body |
118 | // Returns 'true' if BSBody was changed. | 91 | // Returns 'true' if BSBody was changed. |
119 | bool newBody = CreateBody((newGeom || forceRebuild), prim, PhysicsScene.World, bodyCallback); | 92 | bool newBody = CreateBody((newGeom || forceRebuild), prim, m_physicsScene.World, bodyCallback); |
120 | ret = newGeom || newBody; | 93 | ret = newGeom || newBody; |
121 | } | 94 | } |
122 | DetailLog("{0},BSShapeCollection.GetBodyAndShape,taintExit,force={1},ret={2},body={3},shape={4}", | 95 | DetailLog("{0},BSShapeCollection.GetBodyAndShape,taintExit,force={1},ret={2},body={3},shape={4}", |
@@ -127,274 +100,20 @@ public sealed class BSShapeCollection : IDisposable | |||
127 | 100 | ||
128 | public bool GetBodyAndShape(bool forceRebuild, BulletWorld sim, BSPhysObject prim) | 101 | public bool GetBodyAndShape(bool forceRebuild, BulletWorld sim, BSPhysObject prim) |
129 | { | 102 | { |
130 | return GetBodyAndShape(forceRebuild, sim, prim, null, null); | 103 | return GetBodyAndShape(forceRebuild, sim, prim, null); |
131 | } | ||
132 | |||
133 | // Track another user of a body. | ||
134 | // We presume the caller has allocated the body. | ||
135 | // Bodies only have one user so the body is just put into the world if not already there. | ||
136 | private void ReferenceBody(BulletBody body) | ||
137 | { | ||
138 | lock (m_collectionActivityLock) | ||
139 | { | ||
140 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body); | ||
141 | if (!PhysicsScene.PE.IsInWorld(PhysicsScene.World, body)) | ||
142 | { | ||
143 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, body); | ||
144 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body); | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | |||
149 | // Release the usage of a body. | ||
150 | // Called when releasing use of a BSBody. BSShape is handled separately. | ||
151 | // Called in taint time. | ||
152 | public void DereferenceBody(BulletBody body, BodyDestructionCallback bodyCallback ) | ||
153 | { | ||
154 | if (!body.HasPhysicalBody) | ||
155 | return; | ||
156 | |||
157 | PhysicsScene.AssertInTaintTime("BSShapeCollection.DereferenceBody"); | ||
158 | |||
159 | lock (m_collectionActivityLock) | ||
160 | { | ||
161 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody,body={1}", body.ID, body); | ||
162 | // If the caller needs to know the old body is going away, pass the event up. | ||
163 | if (bodyCallback != null) bodyCallback(body); | ||
164 | |||
165 | if (PhysicsScene.PE.IsInWorld(PhysicsScene.World, body)) | ||
166 | { | ||
167 | PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, body); | ||
168 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body); | ||
169 | } | ||
170 | |||
171 | // Zero any reference to the shape so it is not freed when the body is deleted. | ||
172 | PhysicsScene.PE.SetCollisionShape(PhysicsScene.World, body, null); | ||
173 | PhysicsScene.PE.DestroyObject(PhysicsScene.World, body); | ||
174 | } | ||
175 | } | ||
176 | |||
177 | // Track the datastructures and use count for a shape. | ||
178 | // When creating a hull, this is called first to reference the mesh | ||
179 | // and then again to reference the hull. | ||
180 | // Meshes and hulls for the same shape have the same hash key. | ||
181 | // NOTE that native shapes are not added to the mesh list or removed. | ||
182 | // Returns 'true' if this is the initial reference to the shape. Otherwise reused. | ||
183 | public bool ReferenceShape(BulletShape shape) | ||
184 | { | ||
185 | bool ret = false; | ||
186 | switch (shape.type) | ||
187 | { | ||
188 | case BSPhysicsShapeType.SHAPE_MESH: | ||
189 | MeshDesc meshDesc; | ||
190 | if (Meshes.TryGetValue(shape.shapeKey, out meshDesc)) | ||
191 | { | ||
192 | // There is an existing instance of this mesh. | ||
193 | meshDesc.referenceCount++; | ||
194 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,existingMesh,key={1},cnt={2}", | ||
195 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); | ||
196 | } | ||
197 | else | ||
198 | { | ||
199 | // This is a new reference to a mesh | ||
200 | meshDesc.shape = shape.Clone(); | ||
201 | meshDesc.shapeKey = shape.shapeKey; | ||
202 | // We keep a reference to the underlying IMesh data so a hull can be built | ||
203 | meshDesc.referenceCount = 1; | ||
204 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,newMesh,key={1},cnt={2}", | ||
205 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); | ||
206 | ret = true; | ||
207 | } | ||
208 | meshDesc.lastReferenced = System.DateTime.Now; | ||
209 | Meshes[shape.shapeKey] = meshDesc; | ||
210 | break; | ||
211 | case BSPhysicsShapeType.SHAPE_HULL: | ||
212 | HullDesc hullDesc; | ||
213 | if (Hulls.TryGetValue(shape.shapeKey, out hullDesc)) | ||
214 | { | ||
215 | // There is an existing instance of this hull. | ||
216 | hullDesc.referenceCount++; | ||
217 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,existingHull,key={1},cnt={2}", | ||
218 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); | ||
219 | } | ||
220 | else | ||
221 | { | ||
222 | // This is a new reference to a hull | ||
223 | hullDesc.shape = shape.Clone(); | ||
224 | hullDesc.shapeKey = shape.shapeKey; | ||
225 | hullDesc.referenceCount = 1; | ||
226 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}", | ||
227 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); | ||
228 | ret = true; | ||
229 | |||
230 | } | ||
231 | hullDesc.lastReferenced = System.DateTime.Now; | ||
232 | Hulls[shape.shapeKey] = hullDesc; | ||
233 | break; | ||
234 | case BSPhysicsShapeType.SHAPE_UNKNOWN: | ||
235 | break; | ||
236 | default: | ||
237 | // Native shapes are not tracked and they don't go into any list | ||
238 | break; | ||
239 | } | ||
240 | return ret; | ||
241 | } | 104 | } |
242 | 105 | ||
243 | // Release the usage of a shape. | 106 | // If the existing prim's shape is to be replaced, remove the tie to the existing shape |
244 | public void DereferenceShape(BulletShape shape, ShapeDestructionCallback shapeCallback) | 107 | // before replacing it. |
108 | private void DereferenceExistingShape(BSPhysObject prim, PhysicalDestructionCallback shapeCallback) | ||
245 | { | 109 | { |
246 | if (!shape.HasPhysicalShape) | 110 | if (prim.PhysShape.HasPhysicalShape) |
247 | return; | ||
248 | |||
249 | PhysicsScene.AssertInTaintTime("BSShapeCollection.DereferenceShape"); | ||
250 | |||
251 | if (shape.HasPhysicalShape) | ||
252 | { | ||
253 | if (shape.isNativeShape) | ||
254 | { | ||
255 | // Native shapes are not tracked and are released immediately | ||
256 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1}", | ||
257 | BSScene.DetailLogZero, shape.AddrString); | ||
258 | if (shapeCallback != null) shapeCallback(shape); | ||
259 | PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape); | ||
260 | } | ||
261 | else | ||
262 | { | ||
263 | switch (shape.type) | ||
264 | { | ||
265 | case BSPhysicsShapeType.SHAPE_HULL: | ||
266 | DereferenceHull(shape, shapeCallback); | ||
267 | break; | ||
268 | case BSPhysicsShapeType.SHAPE_MESH: | ||
269 | DereferenceMesh(shape, shapeCallback); | ||
270 | break; | ||
271 | case BSPhysicsShapeType.SHAPE_COMPOUND: | ||
272 | DereferenceCompound(shape, shapeCallback); | ||
273 | break; | ||
274 | case BSPhysicsShapeType.SHAPE_UNKNOWN: | ||
275 | break; | ||
276 | default: | ||
277 | break; | ||
278 | } | ||
279 | } | ||
280 | } | ||
281 | } | ||
282 | |||
283 | // Count down the reference count for a mesh shape | ||
284 | // Called at taint-time. | ||
285 | private void DereferenceMesh(BulletShape shape, ShapeDestructionCallback shapeCallback) | ||
286 | { | ||
287 | MeshDesc meshDesc; | ||
288 | if (Meshes.TryGetValue(shape.shapeKey, out meshDesc)) | ||
289 | { | 111 | { |
290 | meshDesc.referenceCount--; | 112 | if (shapeCallback != null) |
291 | // TODO: release the Bullet storage | 113 | shapeCallback(prim.PhysBody, prim.PhysShape.physShapeInfo); |
292 | if (shapeCallback != null) shapeCallback(shape); | 114 | prim.PhysShape.Dereference(m_physicsScene); |
293 | meshDesc.lastReferenced = System.DateTime.Now; | ||
294 | Meshes[shape.shapeKey] = meshDesc; | ||
295 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceMesh,shape={1},refCnt={2}", | ||
296 | BSScene.DetailLogZero, shape, meshDesc.referenceCount); | ||
297 | |||
298 | } | ||
299 | } | ||
300 | |||
301 | // Count down the reference count for a hull shape | ||
302 | // Called at taint-time. | ||
303 | private void DereferenceHull(BulletShape shape, ShapeDestructionCallback shapeCallback) | ||
304 | { | ||
305 | HullDesc hullDesc; | ||
306 | if (Hulls.TryGetValue(shape.shapeKey, out hullDesc)) | ||
307 | { | ||
308 | hullDesc.referenceCount--; | ||
309 | // TODO: release the Bullet storage (aging old entries?) | ||
310 | |||
311 | // Tell upper layers that, if they have dependencies on this shape, this link is going away | ||
312 | if (shapeCallback != null) shapeCallback(shape); | ||
313 | |||
314 | hullDesc.lastReferenced = System.DateTime.Now; | ||
315 | Hulls[shape.shapeKey] = hullDesc; | ||
316 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceHull,shape={1},refCnt={2}", | ||
317 | BSScene.DetailLogZero, shape, hullDesc.referenceCount); | ||
318 | } | ||
319 | } | ||
320 | |||
321 | // Remove a reference to a compound shape. | ||
322 | // Taking a compound shape apart is a little tricky because if you just delete the | ||
323 | // physical shape, it will free all the underlying children. We can't do that because | ||
324 | // they could be shared. So, this removes each of the children from the compound and | ||
325 | // dereferences them separately before destroying the compound collision object itself. | ||
326 | // Called at taint-time. | ||
327 | private void DereferenceCompound(BulletShape shape, ShapeDestructionCallback shapeCallback) | ||
328 | { | ||
329 | if (!PhysicsScene.PE.IsCompound(shape)) | ||
330 | { | ||
331 | // Failed the sanity check!! | ||
332 | PhysicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}", | ||
333 | LogHeader, shape.type, shape.AddrString); | ||
334 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}", | ||
335 | BSScene.DetailLogZero, shape.type, shape.AddrString); | ||
336 | return; | ||
337 | } | ||
338 | |||
339 | int numChildren = PhysicsScene.PE.GetNumberOfCompoundChildren(shape); | ||
340 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", BSScene.DetailLogZero, shape, numChildren); | ||
341 | |||
342 | for (int ii = numChildren - 1; ii >= 0; ii--) | ||
343 | { | ||
344 | BulletShape childShape = PhysicsScene.PE.RemoveChildShapeFromCompoundShapeIndex(shape, ii); | ||
345 | DereferenceAnonCollisionShape(childShape); | ||
346 | } | ||
347 | PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape); | ||
348 | } | ||
349 | |||
350 | // Sometimes we have a pointer to a collision shape but don't know what type it is. | ||
351 | // Figure out type and call the correct dereference routine. | ||
352 | // Called at taint-time. | ||
353 | private void DereferenceAnonCollisionShape(BulletShape shapeInfo) | ||
354 | { | ||
355 | MeshDesc meshDesc; | ||
356 | HullDesc hullDesc; | ||
357 | |||
358 | if (TryGetMeshByPtr(shapeInfo, out meshDesc)) | ||
359 | { | ||
360 | shapeInfo.type = BSPhysicsShapeType.SHAPE_MESH; | ||
361 | shapeInfo.shapeKey = meshDesc.shapeKey; | ||
362 | } | ||
363 | else | ||
364 | { | ||
365 | if (TryGetHullByPtr(shapeInfo, out hullDesc)) | ||
366 | { | ||
367 | shapeInfo.type = BSPhysicsShapeType.SHAPE_HULL; | ||
368 | shapeInfo.shapeKey = hullDesc.shapeKey; | ||
369 | } | ||
370 | else | ||
371 | { | ||
372 | if (PhysicsScene.PE.IsCompound(shapeInfo)) | ||
373 | { | ||
374 | shapeInfo.type = BSPhysicsShapeType.SHAPE_COMPOUND; | ||
375 | } | ||
376 | else | ||
377 | { | ||
378 | if (PhysicsScene.PE.IsNativeShape(shapeInfo)) | ||
379 | { | ||
380 | shapeInfo.isNativeShape = true; | ||
381 | shapeInfo.type = BSPhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter) | ||
382 | } | ||
383 | } | ||
384 | } | ||
385 | } | ||
386 | |||
387 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceAnonCollisionShape,shape={1}", BSScene.DetailLogZero, shapeInfo); | ||
388 | |||
389 | if (shapeInfo.type != BSPhysicsShapeType.SHAPE_UNKNOWN) | ||
390 | { | ||
391 | DereferenceShape(shapeInfo, null); | ||
392 | } | ||
393 | else | ||
394 | { | ||
395 | PhysicsScene.Logger.ErrorFormat("{0} Could not decypher shape type. Region={1}, addr={2}", | ||
396 | LogHeader, PhysicsScene.RegionName, shapeInfo.AddrString); | ||
397 | } | 115 | } |
116 | prim.PhysShape = new BSShapeNull(); | ||
398 | } | 117 | } |
399 | 118 | ||
400 | // Create the geometry information in Bullet for later use. | 119 | // Create the geometry information in Bullet for later use. |
@@ -405,60 +124,41 @@ public sealed class BSShapeCollection : IDisposable | |||
405 | // Info in prim.BSShape is updated to the new shape. | 124 | // Info in prim.BSShape is updated to the new shape. |
406 | // Returns 'true' if the geometry was rebuilt. | 125 | // Returns 'true' if the geometry was rebuilt. |
407 | // Called at taint-time! | 126 | // Called at taint-time! |
408 | private bool CreateGeom(bool forceRebuild, BSPhysObject prim, ShapeDestructionCallback shapeCallback) | 127 | private bool CreateGeom(bool forceRebuild, BSPhysObject prim, PhysicalDestructionCallback shapeCallback) |
409 | { | 128 | { |
410 | bool ret = false; | 129 | bool ret = false; |
411 | bool haveShape = false; | 130 | bool haveShape = false; |
131 | bool nativeShapePossible = true; | ||
132 | PrimitiveBaseShape pbs = prim.BaseShape; | ||
412 | 133 | ||
413 | if (!haveShape && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_CAPSULE) | 134 | // Kludge to create the capsule for the avatar. |
135 | // TDOD: Remove/redo this when BSShapeAvatar is working!! | ||
136 | BSCharacter theChar = prim as BSCharacter; | ||
137 | if (theChar != null) | ||
414 | { | 138 | { |
415 | // an avatar capsule is close to a native shape (it is not shared) | 139 | DereferenceExistingShape(prim, shapeCallback); |
416 | GetReferenceToNativeShape(prim, BSPhysicsShapeType.SHAPE_CAPSULE, FixedShapeKey.KEY_CAPSULE, shapeCallback); | 140 | prim.PhysShape = BSShapeNative.GetReference(m_physicsScene, prim, |
417 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,avatarCapsule,shape={1}", prim.LocalID, prim.PhysShape); | 141 | BSPhysicsShapeType.SHAPE_CAPSULE, FixedShapeKey.KEY_CAPSULE); |
418 | ret = true; | 142 | ret = true; |
419 | haveShape = true; | 143 | haveShape = true; |
420 | } | 144 | } |
421 | 145 | ||
422 | // Compound shapes are handled special as they are rebuilt from scratch. | ||
423 | // This isn't too great a hardship since most of the child shapes will have already been created. | ||
424 | if (!haveShape && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_COMPOUND) | ||
425 | { | ||
426 | ret = GetReferenceToCompoundShape(prim, shapeCallback); | ||
427 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,compoundShape,shape={1}", prim.LocalID, prim.PhysShape); | ||
428 | haveShape = true; | ||
429 | } | ||
430 | |||
431 | if (!haveShape) | ||
432 | { | ||
433 | ret = CreateGeomNonSpecial(forceRebuild, prim, shapeCallback); | ||
434 | } | ||
435 | |||
436 | return ret; | ||
437 | } | ||
438 | |||
439 | // Create a mesh, hull or native shape. | ||
440 | // Return 'true' if the prim's shape was changed. | ||
441 | public bool CreateGeomNonSpecial(bool forceRebuild, BSPhysObject prim, ShapeDestructionCallback shapeCallback) | ||
442 | { | ||
443 | bool ret = false; | ||
444 | bool haveShape = false; | ||
445 | bool nativeShapePossible = true; | ||
446 | PrimitiveBaseShape pbs = prim.BaseShape; | ||
447 | |||
448 | // If the prim attributes are simple, this could be a simple Bullet native shape | 146 | // If the prim attributes are simple, this could be a simple Bullet native shape |
147 | // Native shapes work whether to object is static or physical. | ||
449 | if (!haveShape | 148 | if (!haveShape |
450 | && nativeShapePossible | 149 | && nativeShapePossible |
451 | && pbs != null | 150 | && pbs != null |
452 | && !pbs.SculptEntry | 151 | && PrimHasNoCuts(pbs) |
453 | && ((pbs.SculptEntry && !BSParam.ShouldMeshSculptedPrim) || PrimHasNoCuts(pbs)) ) | 152 | && ( !pbs.SculptEntry || (pbs.SculptEntry && !BSParam.ShouldMeshSculptedPrim) ) |
153 | ) | ||
454 | { | 154 | { |
455 | // Get the scale of any existing shape so we can see if the new shape is same native type and same size. | 155 | // Get the scale of any existing shape so we can see if the new shape is same native type and same size. |
456 | OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero; | 156 | OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero; |
457 | if (prim.PhysShape.HasPhysicalShape) | 157 | if (prim.PhysShape.HasPhysicalShape) |
458 | scaleOfExistingShape = PhysicsScene.PE.GetLocalScaling(prim.PhysShape); | 158 | scaleOfExistingShape = m_physicsScene.PE.GetLocalScaling(prim.PhysShape.physShapeInfo); |
459 | 159 | ||
460 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}", | 160 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}", |
461 | prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.type); | 161 | prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.physShapeInfo.shapeType); |
462 | 162 | ||
463 | // It doesn't look like Bullet scales native spheres so make sure the scales are all equal | 163 | // It doesn't look like Bullet scales native spheres so make sure the scales are all equal |
464 | if ((pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1) | 164 | if ((pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1) |
@@ -466,26 +166,30 @@ public sealed class BSShapeCollection : IDisposable | |||
466 | { | 166 | { |
467 | haveShape = true; | 167 | haveShape = true; |
468 | if (forceRebuild | 168 | if (forceRebuild |
469 | || prim.Scale != scaleOfExistingShape | 169 | || prim.PhysShape.ShapeType != BSPhysicsShapeType.SHAPE_SPHERE |
470 | || prim.PhysShape.type != BSPhysicsShapeType.SHAPE_SPHERE | 170 | ) |
471 | ) | ||
472 | { | 171 | { |
473 | ret = GetReferenceToNativeShape(prim, BSPhysicsShapeType.SHAPE_SPHERE, | 172 | DereferenceExistingShape(prim, shapeCallback); |
474 | FixedShapeKey.KEY_SPHERE, shapeCallback); | 173 | prim.PhysShape = BSShapeNative.GetReference(m_physicsScene, prim, |
174 | BSPhysicsShapeType.SHAPE_SPHERE, FixedShapeKey.KEY_SPHERE); | ||
175 | ret = true; | ||
475 | } | 176 | } |
476 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,sphere,force={1},rebuilt={2},shape={3}", | 177 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,sphere,force={1},rebuilt={2},shape={3}", |
477 | prim.LocalID, forceRebuild, ret, prim.PhysShape); | 178 | prim.LocalID, forceRebuild, ret, prim.PhysShape); |
478 | } | 179 | } |
180 | // If we didn't make a sphere, maybe a box will work. | ||
479 | if (!haveShape && pbs.ProfileShape == ProfileShape.Square && pbs.PathCurve == (byte)Extrusion.Straight) | 181 | if (!haveShape && pbs.ProfileShape == ProfileShape.Square && pbs.PathCurve == (byte)Extrusion.Straight) |
480 | { | 182 | { |
481 | haveShape = true; | 183 | haveShape = true; |
482 | if (forceRebuild | 184 | if (forceRebuild |
483 | || prim.Scale != scaleOfExistingShape | 185 | || prim.Scale != scaleOfExistingShape |
484 | || prim.PhysShape.type != BSPhysicsShapeType.SHAPE_BOX | 186 | || prim.PhysShape.ShapeType != BSPhysicsShapeType.SHAPE_BOX |
485 | ) | 187 | ) |
486 | { | 188 | { |
487 | ret = GetReferenceToNativeShape( prim, BSPhysicsShapeType.SHAPE_BOX, | 189 | DereferenceExistingShape(prim, shapeCallback); |
488 | FixedShapeKey.KEY_BOX, shapeCallback); | 190 | prim.PhysShape = BSShapeNative.GetReference(m_physicsScene, prim, |
191 | BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX); | ||
192 | ret = true; | ||
489 | } | 193 | } |
490 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,box,force={1},rebuilt={2},shape={3}", | 194 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,box,force={1},rebuilt={2},shape={3}", |
491 | prim.LocalID, forceRebuild, ret, prim.PhysShape); | 195 | prim.LocalID, forceRebuild, ret, prim.PhysShape); |
@@ -502,7 +206,7 @@ public sealed class BSShapeCollection : IDisposable | |||
502 | } | 206 | } |
503 | 207 | ||
504 | // return 'true' if this shape description does not include any cutting or twisting. | 208 | // return 'true' if this shape description does not include any cutting or twisting. |
505 | private bool PrimHasNoCuts(PrimitiveBaseShape pbs) | 209 | public static bool PrimHasNoCuts(PrimitiveBaseShape pbs) |
506 | { | 210 | { |
507 | return pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0 | 211 | return pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0 |
508 | && pbs.ProfileHollow == 0 | 212 | && pbs.ProfileHollow == 0 |
@@ -514,7 +218,7 @@ public sealed class BSShapeCollection : IDisposable | |||
514 | } | 218 | } |
515 | 219 | ||
516 | // return 'true' if the prim's shape was changed. | 220 | // return 'true' if the prim's shape was changed. |
517 | public bool CreateGeomMeshOrHull(BSPhysObject prim, ShapeDestructionCallback shapeCallback) | 221 | private bool CreateGeomMeshOrHull(BSPhysObject prim, PhysicalDestructionCallback shapeCallback) |
518 | { | 222 | { |
519 | 223 | ||
520 | bool ret = false; | 224 | bool ret = false; |
@@ -522,503 +226,121 @@ public sealed class BSShapeCollection : IDisposable | |||
522 | // made. Native shapes work in either case. | 226 | // made. Native shapes work in either case. |
523 | if (prim.IsPhysical && BSParam.ShouldUseHullsForPhysicalObjects) | 227 | if (prim.IsPhysical && BSParam.ShouldUseHullsForPhysicalObjects) |
524 | { | 228 | { |
525 | // Update prim.BSShape to reference a hull of this shape. | 229 | // Use a simple, single mesh convex hull shape if the object is simple enough |
526 | ret = GetReferenceToHull(prim, shapeCallback); | 230 | BSShape potentialHull = null; |
527 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,hull,shape={1},key={2}", | ||
528 | prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X")); | ||
529 | } | ||
530 | else | ||
531 | { | ||
532 | ret = GetReferenceToMesh(prim, shapeCallback); | ||
533 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,mesh,shape={1},key={2}", | ||
534 | prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X")); | ||
535 | } | ||
536 | return ret; | ||
537 | } | ||
538 | |||
539 | // Creates a native shape and assignes it to prim.BSShape. | ||
540 | // "Native" shapes are never shared. they are created here and destroyed in DereferenceShape(). | ||
541 | private bool GetReferenceToNativeShape(BSPhysObject prim, | ||
542 | BSPhysicsShapeType shapeType, FixedShapeKey shapeKey, | ||
543 | ShapeDestructionCallback shapeCallback) | ||
544 | { | ||
545 | // release any previous shape | ||
546 | DereferenceShape(prim.PhysShape, shapeCallback); | ||
547 | |||
548 | BulletShape newShape = BuildPhysicalNativeShape(prim, shapeType, shapeKey); | ||
549 | |||
550 | // Don't need to do a 'ReferenceShape()' here because native shapes are not shared. | ||
551 | if (DDetail) DetailLog("{0},BSShapeCollection.AddNativeShapeToPrim,create,newshape={1},scale={2}", | ||
552 | prim.LocalID, newShape, prim.Scale); | ||
553 | |||
554 | // native shapes are scaled by Bullet | ||
555 | prim.PhysShape = newShape; | ||
556 | return true; | ||
557 | } | ||
558 | |||
559 | private BulletShape BuildPhysicalNativeShape(BSPhysObject prim, BSPhysicsShapeType shapeType, | ||
560 | FixedShapeKey shapeKey) | ||
561 | { | ||
562 | BulletShape newShape; | ||
563 | // Need to make sure the passed shape information is for the native type. | ||
564 | ShapeData nativeShapeData = new ShapeData(); | ||
565 | nativeShapeData.Type = shapeType; | ||
566 | nativeShapeData.ID = prim.LocalID; | ||
567 | nativeShapeData.Scale = prim.Scale; | ||
568 | nativeShapeData.Size = prim.Scale; // unneeded, I think. | ||
569 | nativeShapeData.MeshKey = (ulong)shapeKey; | ||
570 | nativeShapeData.HullKey = (ulong)shapeKey; | ||
571 | |||
572 | if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE) | ||
573 | { | ||
574 | 231 | ||
575 | newShape = PhysicsScene.PE.BuildCapsuleShape(PhysicsScene.World, 1f, 1f, prim.Scale); | 232 | PrimitiveBaseShape pbs = prim.BaseShape; |
576 | if (DDetail) DetailLog("{0},BSShapeCollection.BuildPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale); | 233 | // Use a simple, one section convex shape for prims that are probably convex (no cuts or twists) |
577 | } | 234 | if (BSParam.ShouldUseSingleConvexHullForPrims |
578 | else | 235 | && pbs != null |
579 | { | 236 | && !pbs.SculptEntry |
580 | // Native shapes are scaled in Bullet so set the scaling to the size | 237 | && PrimHasNoCuts(pbs) |
581 | newShape = PhysicsScene.PE.BuildNativeShape(PhysicsScene.World, nativeShapeData); | 238 | ) |
582 | 239 | { | |
583 | } | 240 | potentialHull = BSShapeConvexHull.GetReference(m_physicsScene, false /* forceRebuild */, prim); |
584 | if (!newShape.HasPhysicalShape) | 241 | } |
585 | { | 242 | // Use the GImpact shape if it is a prim that has some concaveness |
586 | PhysicsScene.Logger.ErrorFormat("{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}", | 243 | if (potentialHull == null |
587 | LogHeader, prim.LocalID, shapeType); | 244 | && BSParam.ShouldUseGImpactShapeForPrims |
588 | } | 245 | && pbs != null |
589 | newShape.shapeKey = (System.UInt64)shapeKey; | 246 | && !pbs.SculptEntry |
590 | newShape.isNativeShape = true; | 247 | ) |
591 | 248 | { | |
592 | return newShape; | 249 | potentialHull = BSShapeGImpact.GetReference(m_physicsScene, false /* forceRebuild */, prim); |
593 | } | 250 | } |
594 | 251 | // If not any of the simple cases, just make a hull | |
595 | // Builds a mesh shape in the physical world and updates prim.BSShape. | 252 | if (potentialHull == null) |
596 | // Dereferences previous shape in BSShape and adds a reference for this new shape. | 253 | { |
597 | // Returns 'true' of a mesh was actually built. Otherwise . | 254 | potentialHull = BSShapeHull.GetReference(m_physicsScene, false /*forceRebuild*/, prim); |
598 | // Called at taint-time! | 255 | } |
599 | private bool GetReferenceToMesh(BSPhysObject prim, ShapeDestructionCallback shapeCallback) | ||
600 | { | ||
601 | BulletShape newShape = new BulletShape(); | ||
602 | |||
603 | float lod; | ||
604 | System.UInt64 newMeshKey = ComputeShapeKey(prim.Size, prim.BaseShape, out lod); | ||
605 | |||
606 | // if this new shape is the same as last time, don't recreate the mesh | ||
607 | if (newMeshKey == prim.PhysShape.shapeKey && prim.PhysShape.type == BSPhysicsShapeType.SHAPE_MESH) | ||
608 | return false; | ||
609 | |||
610 | if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToMesh,create,oldKey={1},newKey={2},size={3},lod={4}", | ||
611 | prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newMeshKey.ToString("X"), prim.Size, lod); | ||
612 | |||
613 | // Since we're recreating new, get rid of the reference to the previous shape | ||
614 | DereferenceShape(prim.PhysShape, shapeCallback); | ||
615 | |||
616 | newShape = CreatePhysicalMesh(prim, newMeshKey, prim.BaseShape, prim.Size, lod); | ||
617 | // Take evasive action if the mesh was not constructed. | ||
618 | newShape = VerifyMeshCreated(newShape, prim); | ||
619 | |||
620 | ReferenceShape(newShape); | ||
621 | |||
622 | prim.PhysShape = newShape; | ||
623 | |||
624 | return true; // 'true' means a new shape has been added to this prim | ||
625 | } | ||
626 | |||
627 | private BulletShape CreatePhysicalMesh(BSPhysObject prim, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) | ||
628 | { | ||
629 | BulletShape newShape = new BulletShape(); | ||
630 | 256 | ||
631 | MeshDesc meshDesc; | 257 | // If the current shape is not what is on the prim at the moment, time to change. |
632 | if (Meshes.TryGetValue(newMeshKey, out meshDesc)) | 258 | if (!prim.PhysShape.HasPhysicalShape |
633 | { | 259 | || potentialHull.ShapeType != prim.PhysShape.ShapeType |
634 | // If the mesh has already been built just use it. | 260 | || potentialHull.physShapeInfo.shapeKey != prim.PhysShape.physShapeInfo.shapeKey) |
635 | newShape = meshDesc.shape.Clone(); | 261 | { |
262 | DereferenceExistingShape(prim, shapeCallback); | ||
263 | prim.PhysShape = potentialHull; | ||
264 | ret = true; | ||
265 | } | ||
266 | else | ||
267 | { | ||
268 | // The current shape on the prim is the correct one. We don't need the potential reference. | ||
269 | potentialHull.Dereference(m_physicsScene); | ||
270 | } | ||
271 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,hull,shape={1}", prim.LocalID, prim.PhysShape); | ||
636 | } | 272 | } |
637 | else | 273 | else |
638 | { | 274 | { |
639 | IMesh meshData = PhysicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod, | 275 | // Non-physical objects should be just meshes. |
640 | true, | 276 | BSShape potentialMesh = BSShapeMesh.GetReference(m_physicsScene, false /*forceRebuild*/, prim); |
641 | false, // say it is not physical so a bounding box is not built | 277 | // If the current shape is not what is on the prim at the moment, time to change. |
642 | false, // do not cache the mesh and do not use previously built versions | 278 | if (!prim.PhysShape.HasPhysicalShape |
643 | false // It's NOT for ODE | 279 | || potentialMesh.ShapeType != prim.PhysShape.ShapeType |
644 | ); | 280 | || potentialMesh.physShapeInfo.shapeKey != prim.PhysShape.physShapeInfo.shapeKey) |
645 | |||
646 | if (meshData != null) | ||
647 | { | 281 | { |
648 | 282 | DereferenceExistingShape(prim, shapeCallback); | |
649 | int[] indices = meshData.getIndexListAsInt(); | 283 | prim.PhysShape = potentialMesh; |
650 | int realIndicesIndex = indices.Length; | 284 | ret = true; |
651 | float[] verticesAsFloats = meshData.getVertexListAsFloat(); | ||
652 | |||
653 | if (BSParam.ShouldRemoveZeroWidthTriangles) | ||
654 | { | ||
655 | // Remove degenerate triangles. These are triangles with two of the vertices | ||
656 | // are the same. This is complicated by the problem that vertices are not | ||
657 | // made unique in sculpties so we have to compare the values in the vertex. | ||
658 | realIndicesIndex = 0; | ||
659 | for (int tri = 0; tri < indices.Length; tri += 3) | ||
660 | { | ||
661 | // Compute displacements into vertex array for each vertex of the triangle | ||
662 | int v1 = indices[tri + 0] * 3; | ||
663 | int v2 = indices[tri + 1] * 3; | ||
664 | int v3 = indices[tri + 2] * 3; | ||
665 | // Check to see if any two of the vertices are the same | ||
666 | if (!( ( verticesAsFloats[v1 + 0] == verticesAsFloats[v2 + 0] | ||
667 | && verticesAsFloats[v1 + 1] == verticesAsFloats[v2 + 1] | ||
668 | && verticesAsFloats[v1 + 2] == verticesAsFloats[v2 + 2]) | ||
669 | || ( verticesAsFloats[v2 + 0] == verticesAsFloats[v3 + 0] | ||
670 | && verticesAsFloats[v2 + 1] == verticesAsFloats[v3 + 1] | ||
671 | && verticesAsFloats[v2 + 2] == verticesAsFloats[v3 + 2]) | ||
672 | || ( verticesAsFloats[v1 + 0] == verticesAsFloats[v3 + 0] | ||
673 | && verticesAsFloats[v1 + 1] == verticesAsFloats[v3 + 1] | ||
674 | && verticesAsFloats[v1 + 2] == verticesAsFloats[v3 + 2]) ) | ||
675 | ) | ||
676 | { | ||
677 | // None of the vertices of the triangles are the same. This is a good triangle; | ||
678 | indices[realIndicesIndex + 0] = indices[tri + 0]; | ||
679 | indices[realIndicesIndex + 1] = indices[tri + 1]; | ||
680 | indices[realIndicesIndex + 2] = indices[tri + 2]; | ||
681 | realIndicesIndex += 3; | ||
682 | } | ||
683 | } | ||
684 | } | ||
685 | DetailLog("{0},BSShapeCollection.CreatePhysicalMesh,origTri={1},realTri={2},numVerts={3}", | ||
686 | BSScene.DetailLogZero, indices.Length / 3, realIndicesIndex / 3, verticesAsFloats.Length / 3); | ||
687 | |||
688 | if (realIndicesIndex != 0) | ||
689 | { | ||
690 | newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, | ||
691 | realIndicesIndex, indices, verticesAsFloats.Length / 3, verticesAsFloats); | ||
692 | } | ||
693 | else | ||
694 | { | ||
695 | PhysicsScene.Logger.DebugFormat("{0} All mesh triangles degenerate. Prim {1} at {2} in {3}", | ||
696 | LogHeader, prim.PhysObjectName, prim.RawPosition, PhysicsScene.Name); | ||
697 | } | ||
698 | } | 285 | } |
286 | else | ||
287 | { | ||
288 | // We don't need this reference to the mesh that is already being using. | ||
289 | potentialMesh.Dereference(m_physicsScene); | ||
290 | } | ||
291 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,mesh,shape={1}", prim.LocalID, prim.PhysShape); | ||
699 | } | 292 | } |
700 | newShape.shapeKey = newMeshKey; | 293 | return ret; |
701 | |||
702 | return newShape; | ||
703 | } | ||
704 | |||
705 | // See that hull shape exists in the physical world and update prim.BSShape. | ||
706 | // We could be creating the hull because scale changed or whatever. | ||
707 | // Return 'true' if a new hull was built. Otherwise, returning a shared hull instance. | ||
708 | private bool GetReferenceToHull(BSPhysObject prim, ShapeDestructionCallback shapeCallback) | ||
709 | { | ||
710 | BulletShape newShape; | ||
711 | |||
712 | float lod; | ||
713 | System.UInt64 newHullKey = ComputeShapeKey(prim.Size, prim.BaseShape, out lod); | ||
714 | |||
715 | // if the hull hasn't changed, don't rebuild it | ||
716 | if (newHullKey == prim.PhysShape.shapeKey && prim.PhysShape.type == BSPhysicsShapeType.SHAPE_HULL) | ||
717 | return false; | ||
718 | |||
719 | if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToHull,create,oldKey={1},newKey={2}", | ||
720 | prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newHullKey.ToString("X")); | ||
721 | |||
722 | // Remove usage of the previous shape. | ||
723 | DereferenceShape(prim.PhysShape, shapeCallback); | ||
724 | |||
725 | newShape = CreatePhysicalHull(prim.PhysObjectName, newHullKey, prim.BaseShape, prim.Size, lod); | ||
726 | // It might not have been created if we're waiting for an asset. | ||
727 | newShape = VerifyMeshCreated(newShape, prim); | ||
728 | |||
729 | ReferenceShape(newShape); | ||
730 | |||
731 | prim.PhysShape = newShape; | ||
732 | return true; // 'true' means a new shape has been added to this prim | ||
733 | } | 294 | } |
734 | 295 | ||
735 | List<ConvexResult> m_hulls; | 296 | // Track another user of a body. |
736 | private BulletShape CreatePhysicalHull(string objName, System.UInt64 newHullKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) | 297 | // We presume the caller has allocated the body. |
298 | // Bodies only have one user so the body is just put into the world if not already there. | ||
299 | private void ReferenceBody(BulletBody body) | ||
737 | { | 300 | { |
738 | 301 | lock (m_collectionActivityLock) | |
739 | BulletShape newShape = new BulletShape(); | ||
740 | IntPtr hullPtr = IntPtr.Zero; | ||
741 | |||
742 | HullDesc hullDesc; | ||
743 | if (Hulls.TryGetValue(newHullKey, out hullDesc)) | ||
744 | { | ||
745 | // If the hull shape already has been created, just use the one shared instance. | ||
746 | newShape = hullDesc.shape.Clone(); | ||
747 | } | ||
748 | else | ||
749 | { | 302 | { |
750 | // Build a new hull in the physical world. | 303 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body); |
751 | // Pass true for physicalness as this prevents the creation of bounding box which is not needed | 304 | if (!m_physicsScene.PE.IsInWorld(m_physicsScene.World, body)) |
752 | IMesh meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, true, false, false, false); | ||
753 | if (meshData != null) | ||
754 | { | 305 | { |
755 | 306 | m_physicsScene.PE.AddObjectToWorld(m_physicsScene.World, body); | |
756 | int[] indices = meshData.getIndexListAsInt(); | 307 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body); |
757 | List<OMV.Vector3> vertices = meshData.getVertexList(); | ||
758 | |||
759 | //format conversion from IMesh format to DecompDesc format | ||
760 | List<int> convIndices = new List<int>(); | ||
761 | List<float3> convVertices = new List<float3>(); | ||
762 | for (int ii = 0; ii < indices.GetLength(0); ii++) | ||
763 | { | ||
764 | convIndices.Add(indices[ii]); | ||
765 | } | ||
766 | foreach (OMV.Vector3 vv in vertices) | ||
767 | { | ||
768 | convVertices.Add(new float3(vv.X, vv.Y, vv.Z)); | ||
769 | } | ||
770 | |||
771 | uint maxDepthSplit = (uint)BSParam.CSHullMaxDepthSplit; | ||
772 | if (BSParam.CSHullMaxDepthSplit != BSParam.CSHullMaxDepthSplitForSimpleShapes) | ||
773 | { | ||
774 | // Simple primitive shapes we know are convex so they are better implemented with | ||
775 | // fewer hulls. | ||
776 | // Check for simple shape (prim without cuts) and reduce split parameter if so. | ||
777 | if (PrimHasNoCuts(pbs)) | ||
778 | { | ||
779 | maxDepthSplit = (uint)BSParam.CSHullMaxDepthSplitForSimpleShapes; | ||
780 | } | ||
781 | } | ||
782 | |||
783 | // setup and do convex hull conversion | ||
784 | m_hulls = new List<ConvexResult>(); | ||
785 | DecompDesc dcomp = new DecompDesc(); | ||
786 | dcomp.mIndices = convIndices; | ||
787 | dcomp.mVertices = convVertices; | ||
788 | dcomp.mDepth = maxDepthSplit; | ||
789 | dcomp.mCpercent = BSParam.CSHullConcavityThresholdPercent; | ||
790 | dcomp.mPpercent = BSParam.CSHullVolumeConservationThresholdPercent; | ||
791 | dcomp.mMaxVertices = (uint)BSParam.CSHullMaxVertices; | ||
792 | dcomp.mSkinWidth = BSParam.CSHullMaxSkinWidth; | ||
793 | ConvexBuilder convexBuilder = new ConvexBuilder(HullReturn); | ||
794 | // create the hull into the _hulls variable | ||
795 | convexBuilder.process(dcomp); | ||
796 | |||
797 | DetailLog("{0},BSShapeCollection.CreatePhysicalHull,key={1},inVert={2},inInd={3},split={4},hulls={5}", | ||
798 | BSScene.DetailLogZero, newHullKey, indices.GetLength(0), vertices.Count, maxDepthSplit, m_hulls.Count); | ||
799 | |||
800 | // Convert the vertices and indices for passing to unmanaged. | ||
801 | // The hull information is passed as a large floating point array. | ||
802 | // The format is: | ||
803 | // convHulls[0] = number of hulls | ||
804 | // convHulls[1] = number of vertices in first hull | ||
805 | // convHulls[2] = hull centroid X coordinate | ||
806 | // convHulls[3] = hull centroid Y coordinate | ||
807 | // convHulls[4] = hull centroid Z coordinate | ||
808 | // convHulls[5] = first hull vertex X | ||
809 | // convHulls[6] = first hull vertex Y | ||
810 | // convHulls[7] = first hull vertex Z | ||
811 | // convHulls[8] = second hull vertex X | ||
812 | // ... | ||
813 | // convHulls[n] = number of vertices in second hull | ||
814 | // convHulls[n+1] = second hull centroid X coordinate | ||
815 | // ... | ||
816 | // | ||
817 | // TODO: is is very inefficient. Someday change the convex hull generator to return | ||
818 | // data structures that do not need to be converted in order to pass to Bullet. | ||
819 | // And maybe put the values directly into pinned memory rather than marshaling. | ||
820 | int hullCount = m_hulls.Count; | ||
821 | int totalVertices = 1; // include one for the count of the hulls | ||
822 | foreach (ConvexResult cr in m_hulls) | ||
823 | { | ||
824 | totalVertices += 4; // add four for the vertex count and centroid | ||
825 | totalVertices += cr.HullIndices.Count * 3; // we pass just triangles | ||
826 | } | ||
827 | float[] convHulls = new float[totalVertices]; | ||
828 | |||
829 | convHulls[0] = (float)hullCount; | ||
830 | int jj = 1; | ||
831 | foreach (ConvexResult cr in m_hulls) | ||
832 | { | ||
833 | // copy vertices for index access | ||
834 | float3[] verts = new float3[cr.HullVertices.Count]; | ||
835 | int kk = 0; | ||
836 | foreach (float3 ff in cr.HullVertices) | ||
837 | { | ||
838 | verts[kk++] = ff; | ||
839 | } | ||
840 | |||
841 | // add to the array one hull's worth of data | ||
842 | convHulls[jj++] = cr.HullIndices.Count; | ||
843 | convHulls[jj++] = 0f; // centroid x,y,z | ||
844 | convHulls[jj++] = 0f; | ||
845 | convHulls[jj++] = 0f; | ||
846 | foreach (int ind in cr.HullIndices) | ||
847 | { | ||
848 | convHulls[jj++] = verts[ind].x; | ||
849 | convHulls[jj++] = verts[ind].y; | ||
850 | convHulls[jj++] = verts[ind].z; | ||
851 | } | ||
852 | } | ||
853 | // create the hull data structure in Bullet | ||
854 | newShape = PhysicsScene.PE.CreateHullShape(PhysicsScene.World, hullCount, convHulls); | ||
855 | } | 308 | } |
856 | } | 309 | } |
857 | |||
858 | newShape.shapeKey = newHullKey; | ||
859 | |||
860 | return newShape; | ||
861 | } | ||
862 | |||
863 | // Callback from convex hull creater with a newly created hull. | ||
864 | // Just add it to our collection of hulls for this shape. | ||
865 | private void HullReturn(ConvexResult result) | ||
866 | { | ||
867 | m_hulls.Add(result); | ||
868 | return; | ||
869 | } | 310 | } |
870 | 311 | ||
871 | // Compound shapes are always built from scratch. | 312 | // Release the usage of a body. |
872 | // This shouldn't be to bad since most of the parts will be meshes that had been built previously. | 313 | // Called when releasing use of a BSBody. BSShape is handled separately. |
873 | private bool GetReferenceToCompoundShape(BSPhysObject prim, ShapeDestructionCallback shapeCallback) | 314 | // Called in taint time. |
874 | { | 315 | public void DereferenceBody(BulletBody body, PhysicalDestructionCallback bodyCallback ) |
875 | // Remove reference to the old shape | ||
876 | // Don't need to do this as the shape is freed when the new root shape is created below. | ||
877 | // DereferenceShape(prim.PhysShape, true, shapeCallback); | ||
878 | |||
879 | BulletShape cShape = PhysicsScene.PE.CreateCompoundShape(PhysicsScene.World, false); | ||
880 | |||
881 | // Create the shape for the root prim and add it to the compound shape. Cannot be a native shape. | ||
882 | CreateGeomMeshOrHull(prim, shapeCallback); | ||
883 | PhysicsScene.PE.AddChildShapeToCompoundShape(cShape, prim.PhysShape, OMV.Vector3.Zero, OMV.Quaternion.Identity); | ||
884 | if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addRootPrim,compShape={1},rootShape={2}", | ||
885 | prim.LocalID, cShape, prim.PhysShape); | ||
886 | |||
887 | prim.PhysShape = cShape; | ||
888 | |||
889 | return true; | ||
890 | } | ||
891 | |||
892 | // Create a hash of all the shape parameters to be used as a key | ||
893 | // for this particular shape. | ||
894 | private System.UInt64 ComputeShapeKey(OMV.Vector3 size, PrimitiveBaseShape pbs, out float retLod) | ||
895 | { | ||
896 | // level of detail based on size and type of the object | ||
897 | float lod = BSParam.MeshLOD; | ||
898 | |||
899 | // prims with curvy internal cuts need higher lod | ||
900 | if (pbs.HollowShape == HollowShape.Circle) | ||
901 | lod = BSParam.MeshCircularLOD; | ||
902 | |||
903 | if (pbs.SculptEntry) | ||
904 | lod = BSParam.SculptLOD; | ||
905 | |||
906 | // Mega prims usually get more detail because one can interact with shape approximations at this size. | ||
907 | float maxAxis = Math.Max(size.X, Math.Max(size.Y, size.Z)); | ||
908 | if (maxAxis > BSParam.MeshMegaPrimThreshold) | ||
909 | lod = BSParam.MeshMegaPrimLOD; | ||
910 | |||
911 | retLod = lod; | ||
912 | return pbs.GetMeshKey(size, lod); | ||
913 | } | ||
914 | // For those who don't want the LOD | ||
915 | private System.UInt64 ComputeShapeKey(OMV.Vector3 size, PrimitiveBaseShape pbs) | ||
916 | { | 316 | { |
917 | float lod; | 317 | if (!body.HasPhysicalBody) |
918 | return ComputeShapeKey(size, pbs, out lod); | 318 | return; |
919 | } | ||
920 | 319 | ||
921 | // The creation of a mesh or hull can fail if an underlying asset is not available. | 320 | m_physicsScene.AssertInTaintTime("BSShapeCollection.DereferenceBody"); |
922 | // There are two cases: 1) the asset is not in the cache and it needs to be fetched; | ||
923 | // and 2) the asset cannot be converted (like failed decompression of JPEG2000s). | ||
924 | // The first case causes the asset to be fetched. The second case requires | ||
925 | // us to not loop forever. | ||
926 | // Called after creating a physical mesh or hull. If the physical shape was created, | ||
927 | // just return. | ||
928 | private BulletShape VerifyMeshCreated(BulletShape newShape, BSPhysObject prim) | ||
929 | { | ||
930 | // If the shape was successfully created, nothing more to do | ||
931 | if (newShape.HasPhysicalShape) | ||
932 | return newShape; | ||
933 | 321 | ||
934 | // VerifyMeshCreated is called after trying to create the mesh. If we think the asset had been | 322 | lock (m_collectionActivityLock) |
935 | // fetched but we end up here again, the meshing of the asset must have failed. | ||
936 | // Prevent trying to keep fetching the mesh by declaring failure. | ||
937 | if (prim.PrimAssetState == BSPhysObject.PrimAssetCondition.Fetched) | ||
938 | { | ||
939 | prim.PrimAssetState = BSPhysObject.PrimAssetCondition.Failed; | ||
940 | PhysicsScene.Logger.WarnFormat("{0} Fetched asset would not mesh. {1}, texture={2}", | ||
941 | LogHeader, prim.PhysObjectName, prim.BaseShape.SculptTexture); | ||
942 | } | ||
943 | else | ||
944 | { | 323 | { |
945 | // If this mesh has an underlying asset and we have not failed getting it before, fetch the asset | 324 | if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody,body={1}", body.ID, body); |
946 | if (prim.BaseShape.SculptEntry | 325 | // If the caller needs to know the old body is going away, pass the event up. |
947 | && prim.PrimAssetState != BSPhysObject.PrimAssetCondition.Failed | 326 | if (bodyCallback != null) |
948 | && prim.PrimAssetState != BSPhysObject.PrimAssetCondition.Waiting | 327 | bodyCallback(body, null); |
949 | && prim.BaseShape.SculptTexture != OMV.UUID.Zero | ||
950 | ) | ||
951 | { | ||
952 | DetailLog("{0},BSShapeCollection.VerifyMeshCreated,fetchAsset", prim.LocalID); | ||
953 | // Multiple requestors will know we're waiting for this asset | ||
954 | prim.PrimAssetState = BSPhysObject.PrimAssetCondition.Waiting; | ||
955 | |||
956 | BSPhysObject xprim = prim; | ||
957 | Util.FireAndForget(delegate | ||
958 | { | ||
959 | RequestAssetDelegate assetProvider = PhysicsScene.RequestAssetMethod; | ||
960 | if (assetProvider != null) | ||
961 | { | ||
962 | BSPhysObject yprim = xprim; // probably not necessary, but, just in case. | ||
963 | assetProvider(yprim.BaseShape.SculptTexture, delegate(AssetBase asset) | ||
964 | { | ||
965 | bool assetFound = false; | ||
966 | string mismatchIDs = String.Empty; // DEBUG DEBUG | ||
967 | if (asset != null && yprim.BaseShape.SculptEntry) | ||
968 | { | ||
969 | if (yprim.BaseShape.SculptTexture.ToString() == asset.ID) | ||
970 | { | ||
971 | yprim.BaseShape.SculptData = asset.Data; | ||
972 | // This will cause the prim to see that the filler shape is not the right | ||
973 | // one and try again to build the object. | ||
974 | // No race condition with the normal shape setting since the rebuild is at taint time. | ||
975 | yprim.ForceBodyShapeRebuild(false /* inTaintTime */); | ||
976 | assetFound = true; | ||
977 | } | ||
978 | else | ||
979 | { | ||
980 | mismatchIDs = yprim.BaseShape.SculptTexture.ToString() + "/" + asset.ID; | ||
981 | } | ||
982 | } | ||
983 | if (assetFound) | ||
984 | yprim.PrimAssetState = BSPhysObject.PrimAssetCondition.Fetched; | ||
985 | else | ||
986 | yprim.PrimAssetState = BSPhysObject.PrimAssetCondition.Failed; | ||
987 | DetailLog("{0},BSShapeCollection,fetchAssetCallback,found={1},isSculpt={2},ids={3}", | ||
988 | yprim.LocalID, assetFound, yprim.BaseShape.SculptEntry, mismatchIDs ); | ||
989 | 328 | ||
990 | }); | 329 | // Removing an object not in the world is a NOOP |
991 | } | 330 | m_physicsScene.PE.RemoveObjectFromWorld(m_physicsScene.World, body); |
992 | else | ||
993 | { | ||
994 | xprim.PrimAssetState = BSPhysObject.PrimAssetCondition.Failed; | ||
995 | PhysicsScene.Logger.ErrorFormat("{0} Physical object requires asset but no asset provider. Name={1}", | ||
996 | LogHeader, PhysicsScene.Name); | ||
997 | } | ||
998 | }); | ||
999 | } | ||
1000 | else | ||
1001 | { | ||
1002 | if (prim.PrimAssetState == BSPhysObject.PrimAssetCondition.Failed) | ||
1003 | { | ||
1004 | PhysicsScene.Logger.WarnFormat("{0} Mesh failed to fetch asset. obj={1}, texture={2}", | ||
1005 | LogHeader, prim.PhysObjectName, prim.BaseShape.SculptTexture); | ||
1006 | } | ||
1007 | } | ||
1008 | } | ||
1009 | 331 | ||
1010 | // While we wait for the mesh defining asset to be loaded, stick in a simple box for the object. | 332 | // Zero any reference to the shape so it is not freed when the body is deleted. |
1011 | BulletShape fillinShape = BuildPhysicalNativeShape(prim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX); | 333 | m_physicsScene.PE.SetCollisionShape(m_physicsScene.World, body, null); |
1012 | DetailLog("{0},BSShapeCollection.VerifyMeshCreated,boxTempShape", prim.LocalID); | ||
1013 | 334 | ||
1014 | return fillinShape; | 335 | m_physicsScene.PE.DestroyObject(m_physicsScene.World, body); |
336 | } | ||
1015 | } | 337 | } |
1016 | 338 | ||
1017 | // Create a body object in Bullet. | 339 | // Create a body object in Bullet. |
1018 | // Updates prim.BSBody with the information about the new body if one is created. | 340 | // Updates prim.BSBody with the information about the new body if one is created. |
1019 | // Returns 'true' if an object was actually created. | 341 | // Returns 'true' if an object was actually created. |
1020 | // Called at taint-time. | 342 | // Called at taint-time. |
1021 | private bool CreateBody(bool forceRebuild, BSPhysObject prim, BulletWorld sim, BodyDestructionCallback bodyCallback) | 343 | private bool CreateBody(bool forceRebuild, BSPhysObject prim, BulletWorld sim, PhysicalDestructionCallback bodyCallback) |
1022 | { | 344 | { |
1023 | bool ret = false; | 345 | bool ret = false; |
1024 | 346 | ||
@@ -1029,7 +351,7 @@ public sealed class BSShapeCollection : IDisposable | |||
1029 | // If not a solid object, body is a GhostObject. Otherwise a RigidBody. | 351 | // If not a solid object, body is a GhostObject. Otherwise a RigidBody. |
1030 | if (!mustRebuild) | 352 | if (!mustRebuild) |
1031 | { | 353 | { |
1032 | CollisionObjectTypes bodyType = (CollisionObjectTypes)PhysicsScene.PE.GetBodyType(prim.PhysBody); | 354 | CollisionObjectTypes bodyType = (CollisionObjectTypes)m_physicsScene.PE.GetBodyType(prim.PhysBody); |
1033 | if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY | 355 | if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY |
1034 | || !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT) | 356 | || !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT) |
1035 | { | 357 | { |
@@ -1047,12 +369,12 @@ public sealed class BSShapeCollection : IDisposable | |||
1047 | BulletBody aBody; | 369 | BulletBody aBody; |
1048 | if (prim.IsSolid) | 370 | if (prim.IsSolid) |
1049 | { | 371 | { |
1050 | aBody = PhysicsScene.PE.CreateBodyFromShape(sim, prim.PhysShape, prim.LocalID, prim.RawPosition, prim.RawOrientation); | 372 | aBody = m_physicsScene.PE.CreateBodyFromShape(sim, prim.PhysShape.physShapeInfo, prim.LocalID, prim.RawPosition, prim.RawOrientation); |
1051 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,mesh,body={1}", prim.LocalID, aBody); | 373 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,rigid,body={1}", prim.LocalID, aBody); |
1052 | } | 374 | } |
1053 | else | 375 | else |
1054 | { | 376 | { |
1055 | aBody = PhysicsScene.PE.CreateGhostFromShape(sim, prim.PhysShape, prim.LocalID, prim.RawPosition, prim.RawOrientation); | 377 | aBody = m_physicsScene.PE.CreateGhostFromShape(sim, prim.PhysShape.physShapeInfo, prim.LocalID, prim.RawPosition, prim.RawOrientation); |
1056 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,ghost,body={1}", prim.LocalID, aBody); | 378 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,ghost,body={1}", prim.LocalID, aBody); |
1057 | } | 379 | } |
1058 | 380 | ||
@@ -1066,46 +388,10 @@ public sealed class BSShapeCollection : IDisposable | |||
1066 | return ret; | 388 | return ret; |
1067 | } | 389 | } |
1068 | 390 | ||
1069 | private bool TryGetMeshByPtr(BulletShape shape, out MeshDesc outDesc) | ||
1070 | { | ||
1071 | bool ret = false; | ||
1072 | MeshDesc foundDesc = new MeshDesc(); | ||
1073 | foreach (MeshDesc md in Meshes.Values) | ||
1074 | { | ||
1075 | if (md.shape.ReferenceSame(shape)) | ||
1076 | { | ||
1077 | foundDesc = md; | ||
1078 | ret = true; | ||
1079 | break; | ||
1080 | } | ||
1081 | |||
1082 | } | ||
1083 | outDesc = foundDesc; | ||
1084 | return ret; | ||
1085 | } | ||
1086 | |||
1087 | private bool TryGetHullByPtr(BulletShape shape, out HullDesc outDesc) | ||
1088 | { | ||
1089 | bool ret = false; | ||
1090 | HullDesc foundDesc = new HullDesc(); | ||
1091 | foreach (HullDesc hd in Hulls.Values) | ||
1092 | { | ||
1093 | if (hd.shape.ReferenceSame(shape)) | ||
1094 | { | ||
1095 | foundDesc = hd; | ||
1096 | ret = true; | ||
1097 | break; | ||
1098 | } | ||
1099 | |||
1100 | } | ||
1101 | outDesc = foundDesc; | ||
1102 | return ret; | ||
1103 | } | ||
1104 | |||
1105 | private void DetailLog(string msg, params Object[] args) | 391 | private void DetailLog(string msg, params Object[] args) |
1106 | { | 392 | { |
1107 | if (PhysicsScene.PhysicsLogging.Enabled) | 393 | if (m_physicsScene.PhysicsLogging.Enabled) |
1108 | PhysicsScene.DetailLog(msg, args); | 394 | m_physicsScene.DetailLog(msg, args); |
1109 | } | 395 | } |
1110 | } | 396 | } |
1111 | } | 397 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs index ee18379..fe5ff6c 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | |||
@@ -29,115 +29,312 @@ using System; | |||
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Text; | 30 | using System.Text; |
31 | 31 | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Physics.Manager; | ||
34 | using OpenSim.Region.Physics.Meshing; | ||
35 | using OpenSim.Region.Physics.ConvexDecompositionDotNet; | ||
36 | |||
32 | using OMV = OpenMetaverse; | 37 | using OMV = OpenMetaverse; |
33 | 38 | ||
34 | namespace OpenSim.Region.Physics.BulletSPlugin | 39 | namespace OpenSim.Region.Physics.BulletSPlugin |
35 | { | 40 | { |
36 | public abstract class BSShape | 41 | public abstract class BSShape |
37 | { | 42 | { |
43 | private static string LogHeader = "[BULLETSIM SHAPE]"; | ||
44 | |||
38 | public int referenceCount { get; set; } | 45 | public int referenceCount { get; set; } |
39 | public DateTime lastReferenced { get; set; } | 46 | public DateTime lastReferenced { get; set; } |
47 | public BulletShape physShapeInfo { get; set; } | ||
40 | 48 | ||
41 | public BSShape() | 49 | public BSShape() |
42 | { | 50 | { |
43 | referenceCount = 0; | 51 | referenceCount = 1; |
44 | lastReferenced = DateTime.Now; | 52 | lastReferenced = DateTime.Now; |
53 | physShapeInfo = new BulletShape(); | ||
45 | } | 54 | } |
46 | 55 | public BSShape(BulletShape pShape) | |
47 | // Get a reference to a physical shape. Create if it doesn't exist | ||
48 | public static BSShape GetShapeReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim) | ||
49 | { | 56 | { |
50 | BSShape ret = null; | 57 | referenceCount = 1; |
51 | 58 | lastReferenced = DateTime.Now; | |
52 | if (prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_CAPSULE) | 59 | physShapeInfo = pShape; |
53 | { | 60 | } |
54 | // an avatar capsule is close to a native shape (it is not shared) | ||
55 | ret = BSShapeNative.GetReference(physicsScene, prim, BSPhysicsShapeType.SHAPE_CAPSULE, | ||
56 | FixedShapeKey.KEY_CAPSULE); | ||
57 | physicsScene.DetailLog("{0},BSShape.GetShapeReference,avatarCapsule,shape={1}", prim.LocalID, ret); | ||
58 | } | ||
59 | |||
60 | // Compound shapes are handled special as they are rebuilt from scratch. | ||
61 | // This isn't too great a hardship since most of the child shapes will have already been created. | ||
62 | if (ret == null && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_COMPOUND) | ||
63 | { | ||
64 | // Getting a reference to a compound shape gets you the compound shape with the root prim shape added | ||
65 | ret = BSShapeCompound.GetReference(prim); | ||
66 | physicsScene.DetailLog("{0},BSShapeCollection.CreateGeom,compoundShape,shape={1}", prim.LocalID, ret); | ||
67 | } | ||
68 | |||
69 | // Avatars have their own unique shape | ||
70 | if (ret == null && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_AVATAR) | ||
71 | { | ||
72 | // Getting a reference to a compound shape gets you the compound shape with the root prim shape added | ||
73 | ret = BSShapeAvatar.GetReference(prim); | ||
74 | physicsScene.DetailLog("{0},BSShapeCollection.CreateGeom,avatarShape,shape={1}", prim.LocalID, ret); | ||
75 | } | ||
76 | 61 | ||
77 | if (ret == null) | 62 | // Get another reference to this shape. |
78 | ret = GetShapeReferenceNonSpecial(physicsScene, forceRebuild, prim); | 63 | public abstract BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim); |
79 | 64 | ||
80 | return ret; | 65 | // Called when this shape is being used again. |
81 | } | 66 | // Used internally. External callers should call instance.GetReference() to properly copy/reference |
82 | public static BSShape GetShapeReferenceNonSpecial(BSScene physicsScene, bool forceRebuild, BSPhysObject prim) | 67 | // the shape. |
68 | protected virtual void IncrementReference() | ||
83 | { | 69 | { |
84 | return null; | 70 | referenceCount++; |
71 | lastReferenced = DateTime.Now; | ||
85 | } | 72 | } |
86 | public static BSShape GetShapeReferenceNonNative(BSScene physicsScene, bool forceRebuild, BSPhysObject prim) | 73 | |
74 | // Called when this shape is done being used. | ||
75 | protected virtual void DecrementReference() | ||
87 | { | 76 | { |
88 | return null; | 77 | referenceCount--; |
78 | lastReferenced = DateTime.Now; | ||
89 | } | 79 | } |
90 | 80 | ||
91 | // Release the use of a physical shape. | 81 | // Release the use of a physical shape. |
92 | public abstract void Dereference(BSScene physicsScene); | 82 | public abstract void Dereference(BSScene physicsScene); |
93 | 83 | ||
94 | // All shapes have a static call to get a reference to the physical shape | 84 | // Return 'true' if there is an allocated physics physical shape under this class instance. |
95 | // protected abstract static BSShape GetReference(); | 85 | public virtual bool HasPhysicalShape |
86 | { | ||
87 | get | ||
88 | { | ||
89 | if (physShapeInfo != null) | ||
90 | return physShapeInfo.HasPhysicalShape; | ||
91 | return false; | ||
92 | } | ||
93 | } | ||
94 | public virtual BSPhysicsShapeType ShapeType | ||
95 | { | ||
96 | get | ||
97 | { | ||
98 | BSPhysicsShapeType ret = BSPhysicsShapeType.SHAPE_UNKNOWN; | ||
99 | if (physShapeInfo != null && physShapeInfo.HasPhysicalShape) | ||
100 | ret = physShapeInfo.shapeType; | ||
101 | return ret; | ||
102 | } | ||
103 | } | ||
96 | 104 | ||
97 | // Returns a string for debugging that uniquily identifies the memory used by this instance | 105 | // Returns a string for debugging that uniquily identifies the memory used by this instance |
98 | public virtual string AddrString | 106 | public virtual string AddrString |
99 | { | 107 | { |
100 | get { return "unknown"; } | 108 | get |
109 | { | ||
110 | if (physShapeInfo != null) | ||
111 | return physShapeInfo.AddrString; | ||
112 | return "unknown"; | ||
113 | } | ||
101 | } | 114 | } |
102 | 115 | ||
103 | public override string ToString() | 116 | public override string ToString() |
104 | { | 117 | { |
105 | StringBuilder buff = new StringBuilder(); | 118 | StringBuilder buff = new StringBuilder(); |
106 | buff.Append("<p="); | 119 | if (physShapeInfo == null) |
107 | buff.Append(AddrString); | 120 | { |
121 | buff.Append("<noPhys"); | ||
122 | } | ||
123 | else | ||
124 | { | ||
125 | buff.Append("<phy="); | ||
126 | buff.Append(physShapeInfo.ToString()); | ||
127 | } | ||
108 | buff.Append(",c="); | 128 | buff.Append(",c="); |
109 | buff.Append(referenceCount.ToString()); | 129 | buff.Append(referenceCount.ToString()); |
110 | buff.Append(">"); | 130 | buff.Append(">"); |
111 | return buff.ToString(); | 131 | return buff.ToString(); |
112 | } | 132 | } |
133 | |||
134 | #region Common shape routines | ||
135 | // Create a hash of all the shape parameters to be used as a key for this particular shape. | ||
136 | public static System.UInt64 ComputeShapeKey(OMV.Vector3 size, PrimitiveBaseShape pbs, out float retLod) | ||
137 | { | ||
138 | // level of detail based on size and type of the object | ||
139 | float lod = BSParam.MeshLOD; | ||
140 | if (pbs.SculptEntry) | ||
141 | lod = BSParam.SculptLOD; | ||
142 | |||
143 | // Mega prims usually get more detail because one can interact with shape approximations at this size. | ||
144 | float maxAxis = Math.Max(size.X, Math.Max(size.Y, size.Z)); | ||
145 | if (maxAxis > BSParam.MeshMegaPrimThreshold) | ||
146 | lod = BSParam.MeshMegaPrimLOD; | ||
147 | |||
148 | retLod = lod; | ||
149 | return pbs.GetMeshKey(size, lod); | ||
150 | } | ||
151 | |||
152 | // The creation of a mesh or hull can fail if an underlying asset is not available. | ||
153 | // There are two cases: 1) the asset is not in the cache and it needs to be fetched; | ||
154 | // and 2) the asset cannot be converted (like failed decompression of JPEG2000s). | ||
155 | // The first case causes the asset to be fetched. The second case requires | ||
156 | // us to not loop forever. | ||
157 | // Called after creating a physical mesh or hull. If the physical shape was created, | ||
158 | // just return. | ||
159 | public static BulletShape VerifyMeshCreated(BSScene physicsScene, BulletShape newShape, BSPhysObject prim) | ||
160 | { | ||
161 | // If the shape was successfully created, nothing more to do | ||
162 | if (newShape.HasPhysicalShape) | ||
163 | return newShape; | ||
164 | |||
165 | // VerifyMeshCreated is called after trying to create the mesh. If we think the asset had been | ||
166 | // fetched but we end up here again, the meshing of the asset must have failed. | ||
167 | // Prevent trying to keep fetching the mesh by declaring failure. | ||
168 | if (prim.PrimAssetState == BSPhysObject.PrimAssetCondition.Fetched) | ||
169 | { | ||
170 | prim.PrimAssetState = BSPhysObject.PrimAssetCondition.FailedMeshing; | ||
171 | physicsScene.Logger.WarnFormat("{0} Fetched asset would not mesh. prim={1}, texture={2}", | ||
172 | LogHeader, UsefulPrimInfo(physicsScene, prim), prim.BaseShape.SculptTexture); | ||
173 | physicsScene.DetailLog("{0},BSShape.VerifyMeshCreated,setFailed,prim={1},tex={2}", | ||
174 | prim.LocalID, UsefulPrimInfo(physicsScene, prim), prim.BaseShape.SculptTexture); | ||
175 | } | ||
176 | else | ||
177 | { | ||
178 | // If this mesh has an underlying asset and we have not failed getting it before, fetch the asset | ||
179 | if (prim.BaseShape.SculptEntry | ||
180 | && prim.PrimAssetState != BSPhysObject.PrimAssetCondition.FailedAssetFetch | ||
181 | && prim.PrimAssetState != BSPhysObject.PrimAssetCondition.FailedMeshing | ||
182 | && prim.PrimAssetState != BSPhysObject.PrimAssetCondition.Waiting | ||
183 | && prim.BaseShape.SculptTexture != OMV.UUID.Zero | ||
184 | ) | ||
185 | { | ||
186 | physicsScene.DetailLog("{0},BSShape.VerifyMeshCreated,fetchAsset,objNam={1},tex={2}", | ||
187 | prim.LocalID, prim.PhysObjectName, prim.BaseShape.SculptTexture); | ||
188 | // Multiple requestors will know we're waiting for this asset | ||
189 | prim.PrimAssetState = BSPhysObject.PrimAssetCondition.Waiting; | ||
190 | |||
191 | BSPhysObject xprim = prim; | ||
192 | Util.FireAndForget(delegate | ||
193 | { | ||
194 | // physicsScene.DetailLog("{0},BSShape.VerifyMeshCreated,inFireAndForget", xprim.LocalID); | ||
195 | RequestAssetDelegate assetProvider = physicsScene.RequestAssetMethod; | ||
196 | if (assetProvider != null) | ||
197 | { | ||
198 | BSPhysObject yprim = xprim; // probably not necessary, but, just in case. | ||
199 | assetProvider(yprim.BaseShape.SculptTexture, delegate(AssetBase asset) | ||
200 | { | ||
201 | // physicsScene.DetailLog("{0},BSShape.VerifyMeshCreated,assetProviderCallback", xprim.LocalID); | ||
202 | bool assetFound = false; | ||
203 | string mismatchIDs = String.Empty; // DEBUG DEBUG | ||
204 | if (asset != null && yprim.BaseShape.SculptEntry) | ||
205 | { | ||
206 | if (yprim.BaseShape.SculptTexture.ToString() == asset.ID) | ||
207 | { | ||
208 | yprim.BaseShape.SculptData = asset.Data; | ||
209 | // This will cause the prim to see that the filler shape is not the right | ||
210 | // one and try again to build the object. | ||
211 | // No race condition with the normal shape setting since the rebuild is at taint time. | ||
212 | yprim.PrimAssetState = BSPhysObject.PrimAssetCondition.Fetched; | ||
213 | yprim.ForceBodyShapeRebuild(false /* inTaintTime */); | ||
214 | assetFound = true; | ||
215 | } | ||
216 | else | ||
217 | { | ||
218 | mismatchIDs = yprim.BaseShape.SculptTexture.ToString() + "/" + asset.ID; | ||
219 | } | ||
220 | } | ||
221 | if (!assetFound) | ||
222 | { | ||
223 | yprim.PrimAssetState = BSPhysObject.PrimAssetCondition.FailedAssetFetch; | ||
224 | } | ||
225 | physicsScene.DetailLog("{0},BSShape.VerifyMeshCreated,fetchAssetCallback,found={1},isSculpt={2},ids={3}", | ||
226 | yprim.LocalID, assetFound, yprim.BaseShape.SculptEntry, mismatchIDs ); | ||
227 | }); | ||
228 | } | ||
229 | else | ||
230 | { | ||
231 | xprim.PrimAssetState = BSPhysObject.PrimAssetCondition.FailedAssetFetch; | ||
232 | physicsScene.Logger.ErrorFormat("{0} Physical object requires asset but no asset provider. Name={1}", | ||
233 | LogHeader, physicsScene.Name); | ||
234 | } | ||
235 | }); | ||
236 | } | ||
237 | else | ||
238 | { | ||
239 | if (prim.PrimAssetState == BSPhysObject.PrimAssetCondition.FailedAssetFetch) | ||
240 | { | ||
241 | physicsScene.Logger.WarnFormat("{0} Mesh failed to fetch asset. prim={1}, texture={2}", | ||
242 | LogHeader, UsefulPrimInfo(physicsScene, prim), prim.BaseShape.SculptTexture); | ||
243 | physicsScene.DetailLog("{0},BSShape.VerifyMeshCreated,wasFailed,prim={1},tex={2}", | ||
244 | prim.LocalID, UsefulPrimInfo(physicsScene, prim), prim.BaseShape.SculptTexture); | ||
245 | } | ||
246 | if (prim.PrimAssetState == BSPhysObject.PrimAssetCondition.FailedMeshing) | ||
247 | { | ||
248 | physicsScene.Logger.WarnFormat("{0} Mesh asset would not mesh. prim={1}, texture={2}", | ||
249 | LogHeader, UsefulPrimInfo(physicsScene, prim), prim.BaseShape.SculptTexture); | ||
250 | physicsScene.DetailLog("{0},BSShape.VerifyMeshCreated,wasFailedMeshing,prim={1},tex={2}", | ||
251 | prim.LocalID, UsefulPrimInfo(physicsScene, prim), prim.BaseShape.SculptTexture); | ||
252 | } | ||
253 | } | ||
254 | } | ||
255 | |||
256 | // While we wait for the mesh defining asset to be loaded, stick in a simple box for the object. | ||
257 | BSShape fillShape = BSShapeNative.GetReference(physicsScene, prim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX); | ||
258 | physicsScene.DetailLog("{0},BSShape.VerifyMeshCreated,boxTempShape", prim.LocalID); | ||
259 | |||
260 | return fillShape.physShapeInfo; | ||
261 | } | ||
262 | |||
263 | public static String UsefulPrimInfo(BSScene pScene, BSPhysObject prim) | ||
264 | { | ||
265 | StringBuilder buff = new StringBuilder(prim.PhysObjectName); | ||
266 | buff.Append("/pos="); | ||
267 | buff.Append(prim.RawPosition.ToString()); | ||
268 | if (pScene != null) | ||
269 | { | ||
270 | buff.Append("/rgn="); | ||
271 | buff.Append(pScene.Name); | ||
272 | } | ||
273 | return buff.ToString(); | ||
274 | } | ||
275 | |||
276 | #endregion // Common shape routines | ||
113 | } | 277 | } |
114 | 278 | ||
279 | // ============================================================================================================ | ||
115 | public class BSShapeNull : BSShape | 280 | public class BSShapeNull : BSShape |
116 | { | 281 | { |
117 | public BSShapeNull() : base() | 282 | public BSShapeNull() : base() |
118 | { | 283 | { |
119 | } | 284 | } |
120 | public static BSShape GetReference() { return new BSShapeNull(); } | 285 | public static BSShape GetReference() { return new BSShapeNull(); } |
286 | public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim) { return new BSShapeNull(); } | ||
121 | public override void Dereference(BSScene physicsScene) { /* The magic of garbage collection will make this go away */ } | 287 | public override void Dereference(BSScene physicsScene) { /* The magic of garbage collection will make this go away */ } |
122 | } | 288 | } |
123 | 289 | ||
290 | // ============================================================================================================ | ||
124 | public class BSShapeNative : BSShape | 291 | public class BSShapeNative : BSShape |
125 | { | 292 | { |
126 | private static string LogHeader = "[BULLETSIM SHAPE NATIVE]"; | 293 | private static string LogHeader = "[BULLETSIM SHAPE NATIVE]"; |
127 | public BSShapeNative() : base() | 294 | public BSShapeNative(BulletShape pShape) : base(pShape) |
128 | { | 295 | { |
129 | } | 296 | } |
130 | public static BSShape GetReference(BSScene physicsScene, BSPhysObject prim, | 297 | |
131 | BSPhysicsShapeType shapeType, FixedShapeKey shapeKey) | 298 | public static BSShape GetReference(BSScene physicsScene, BSPhysObject prim, |
299 | BSPhysicsShapeType shapeType, FixedShapeKey shapeKey) | ||
132 | { | 300 | { |
133 | // Native shapes are not shared and are always built anew. | 301 | // Native shapes are not shared and are always built anew. |
134 | //return new BSShapeNative(physicsScene, prim, shapeType, shapeKey); | 302 | return new BSShapeNative(CreatePhysicalNativeShape(physicsScene, prim, shapeType, shapeKey)); |
135 | return null; | ||
136 | } | 303 | } |
137 | 304 | ||
138 | private BSShapeNative(BSScene physicsScene, BSPhysObject prim, | 305 | public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim) |
139 | BSPhysicsShapeType shapeType, FixedShapeKey shapeKey) | ||
140 | { | 306 | { |
307 | // Native shapes are not shared so we return a new shape. | ||
308 | BSShape ret = null; | ||
309 | lock (physShapeInfo) | ||
310 | { | ||
311 | ret = new BSShapeNative(CreatePhysicalNativeShape(pPhysicsScene, pPrim, | ||
312 | physShapeInfo.shapeType, (FixedShapeKey)physShapeInfo.shapeKey)); | ||
313 | } | ||
314 | return ret; | ||
315 | } | ||
316 | |||
317 | // Make this reference to the physical shape go away since native shapes are not shared. | ||
318 | public override void Dereference(BSScene physicsScene) | ||
319 | { | ||
320 | // Native shapes are not tracked and are released immediately | ||
321 | lock (physShapeInfo) | ||
322 | { | ||
323 | if (physShapeInfo.HasPhysicalShape) | ||
324 | { | ||
325 | physicsScene.DetailLog("{0},BSShapeNative.Dereference,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this); | ||
326 | physicsScene.PE.DeleteCollisionShape(physicsScene.World, physShapeInfo); | ||
327 | } | ||
328 | physShapeInfo.Clear(); | ||
329 | // Garbage collection will free up this instance. | ||
330 | } | ||
331 | } | ||
332 | |||
333 | private static BulletShape CreatePhysicalNativeShape(BSScene physicsScene, BSPhysObject prim, | ||
334 | BSPhysicsShapeType shapeType, FixedShapeKey shapeKey) | ||
335 | { | ||
336 | BulletShape newShape; | ||
337 | |||
141 | ShapeData nativeShapeData = new ShapeData(); | 338 | ShapeData nativeShapeData = new ShapeData(); |
142 | nativeShapeData.Type = shapeType; | 339 | nativeShapeData.Type = shapeType; |
143 | nativeShapeData.ID = prim.LocalID; | 340 | nativeShapeData.ID = prim.LocalID; |
@@ -146,84 +343,880 @@ public class BSShapeNative : BSShape | |||
146 | nativeShapeData.MeshKey = (ulong)shapeKey; | 343 | nativeShapeData.MeshKey = (ulong)shapeKey; |
147 | nativeShapeData.HullKey = (ulong)shapeKey; | 344 | nativeShapeData.HullKey = (ulong)shapeKey; |
148 | 345 | ||
149 | |||
150 | /* | ||
151 | if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE) | 346 | if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE) |
152 | { | 347 | { |
153 | ptr = PhysicsScene.PE.BuildCapsuleShape(physicsScene.World, 1f, 1f, prim.Scale); | 348 | newShape = physicsScene.PE.BuildCapsuleShape(physicsScene.World, 1f, 1f, prim.Scale); |
154 | physicsScene.DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale); | 349 | physicsScene.DetailLog("{0},BSShapeNative,capsule,scale={1}", prim.LocalID, prim.Scale); |
155 | } | 350 | } |
156 | else | 351 | else |
157 | { | 352 | { |
158 | ptr = PhysicsScene.PE.BuildNativeShape(physicsScene.World, nativeShapeData); | 353 | newShape = physicsScene.PE.BuildNativeShape(physicsScene.World, nativeShapeData); |
159 | } | 354 | } |
160 | if (ptr == IntPtr.Zero) | 355 | if (!newShape.HasPhysicalShape) |
161 | { | 356 | { |
162 | physicsScene.Logger.ErrorFormat("{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}", | 357 | physicsScene.Logger.ErrorFormat("{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}", |
163 | LogHeader, prim.LocalID, shapeType); | 358 | LogHeader, prim.LocalID, shapeType); |
164 | } | 359 | } |
165 | type = shapeType; | 360 | newShape.shapeType = shapeType; |
166 | key = (UInt64)shapeKey; | 361 | newShape.isNativeShape = true; |
167 | */ | 362 | newShape.shapeKey = (UInt64)shapeKey; |
168 | } | 363 | return newShape; |
169 | // Make this reference to the physical shape go away since native shapes are not shared. | ||
170 | public override void Dereference(BSScene physicsScene) | ||
171 | { | ||
172 | /* | ||
173 | // Native shapes are not tracked and are released immediately | ||
174 | physicsScene.DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this); | ||
175 | PhysicsScene.PE.DeleteCollisionShape(physicsScene.World, this); | ||
176 | ptr = IntPtr.Zero; | ||
177 | // Garbage collection will free up this instance. | ||
178 | */ | ||
179 | } | 364 | } |
365 | |||
180 | } | 366 | } |
181 | 367 | ||
368 | // ============================================================================================================ | ||
182 | public class BSShapeMesh : BSShape | 369 | public class BSShapeMesh : BSShape |
183 | { | 370 | { |
184 | private static string LogHeader = "[BULLETSIM SHAPE MESH]"; | 371 | private static string LogHeader = "[BULLETSIM SHAPE MESH]"; |
185 | private static Dictionary<System.UInt64, BSShapeMesh> Meshes = new Dictionary<System.UInt64, BSShapeMesh>(); | 372 | public static Dictionary<System.UInt64, BSShapeMesh> Meshes = new Dictionary<System.UInt64, BSShapeMesh>(); |
186 | 373 | ||
187 | public BSShapeMesh() : base() | 374 | public BSShapeMesh(BulletShape pShape) : base(pShape) |
188 | { | 375 | { |
189 | } | 376 | } |
190 | public static BSShape GetReference() { return new BSShapeNull(); } | 377 | public static BSShape GetReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim) |
191 | public override void Dereference(BSScene physicsScene) { } | 378 | { |
379 | float lod; | ||
380 | System.UInt64 newMeshKey = BSShape.ComputeShapeKey(prim.Size, prim.BaseShape, out lod); | ||
381 | |||
382 | BSShapeMesh retMesh = null; | ||
383 | lock (Meshes) | ||
384 | { | ||
385 | if (Meshes.TryGetValue(newMeshKey, out retMesh)) | ||
386 | { | ||
387 | // The mesh has already been created. Return a new reference to same. | ||
388 | retMesh.IncrementReference(); | ||
389 | } | ||
390 | else | ||
391 | { | ||
392 | retMesh = new BSShapeMesh(new BulletShape()); | ||
393 | // An instance of this mesh has not been created. Build and remember same. | ||
394 | BulletShape newShape = retMesh.CreatePhysicalMesh(physicsScene, prim, newMeshKey, prim.BaseShape, prim.Size, lod); | ||
395 | |||
396 | // Check to see if mesh was created (might require an asset). | ||
397 | newShape = VerifyMeshCreated(physicsScene, newShape, prim); | ||
398 | if (!newShape.isNativeShape | ||
399 | || prim.PrimAssetState == BSPhysObject.PrimAssetCondition.FailedMeshing | ||
400 | || prim.PrimAssetState == BSPhysObject.PrimAssetCondition.FailedAssetFetch) | ||
401 | { | ||
402 | // If a mesh was what was created, remember the built shape for later sharing. | ||
403 | // Also note that if meshing failed we put it in the mesh list as there is nothing else to do about the mesh. | ||
404 | Meshes.Add(newMeshKey, retMesh); | ||
405 | } | ||
406 | |||
407 | retMesh.physShapeInfo = newShape; | ||
408 | } | ||
409 | } | ||
410 | physicsScene.DetailLog("{0},BSShapeMesh,getReference,mesh={1},size={2},lod={3}", prim.LocalID, retMesh, prim.Size, lod); | ||
411 | return retMesh; | ||
412 | } | ||
413 | public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim) | ||
414 | { | ||
415 | BSShape ret = null; | ||
416 | // If the underlying shape is native, the actual shape has not been build (waiting for asset) | ||
417 | // and we must create a copy of the native shape since they are never shared. | ||
418 | if (physShapeInfo.HasPhysicalShape && physShapeInfo.isNativeShape) | ||
419 | { | ||
420 | // TODO: decide when the native shapes should be freed. Check in Dereference? | ||
421 | ret = BSShapeNative.GetReference(pPhysicsScene, pPrim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX); | ||
422 | } | ||
423 | else | ||
424 | { | ||
425 | // Another reference to this shape is just counted. | ||
426 | IncrementReference(); | ||
427 | ret = this; | ||
428 | } | ||
429 | return ret; | ||
430 | } | ||
431 | public override void Dereference(BSScene physicsScene) | ||
432 | { | ||
433 | lock (Meshes) | ||
434 | { | ||
435 | this.DecrementReference(); | ||
436 | physicsScene.DetailLog("{0},BSShapeMesh.Dereference,shape={1}", BSScene.DetailLogZero, this); | ||
437 | // TODO: schedule aging and destruction of unused meshes. | ||
438 | } | ||
439 | } | ||
440 | // Loop through all the known meshes and return the description based on the physical address. | ||
441 | public static bool TryGetMeshByPtr(BulletShape pShape, out BSShapeMesh outMesh) | ||
442 | { | ||
443 | bool ret = false; | ||
444 | BSShapeMesh foundDesc = null; | ||
445 | lock (Meshes) | ||
446 | { | ||
447 | foreach (BSShapeMesh sm in Meshes.Values) | ||
448 | { | ||
449 | if (sm.physShapeInfo.ReferenceSame(pShape)) | ||
450 | { | ||
451 | foundDesc = sm; | ||
452 | ret = true; | ||
453 | break; | ||
454 | } | ||
455 | |||
456 | } | ||
457 | } | ||
458 | outMesh = foundDesc; | ||
459 | return ret; | ||
460 | } | ||
461 | |||
462 | public delegate BulletShape CreateShapeCall(BulletWorld world, int indicesCount, int[] indices, int verticesCount, float[] vertices ); | ||
463 | private BulletShape CreatePhysicalMesh(BSScene physicsScene, BSPhysObject prim, System.UInt64 newMeshKey, | ||
464 | PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) | ||
465 | { | ||
466 | return BSShapeMesh.CreatePhysicalMeshShape(physicsScene, prim, newMeshKey, pbs, size, lod, | ||
467 | (w, iC, i, vC, v) => physicsScene.PE.CreateMeshShape(w, iC, i, vC, v) ); | ||
468 | } | ||
469 | |||
470 | // Code that uses the mesher to create the index/vertices info for a trimesh shape. | ||
471 | // This is used by the passed 'makeShape' call to create the Bullet mesh shape. | ||
472 | // The actual build call is passed so this logic can be used by several of the shapes that use a | ||
473 | // simple mesh as their base shape. | ||
474 | public static BulletShape CreatePhysicalMeshShape(BSScene physicsScene, BSPhysObject prim, System.UInt64 newMeshKey, | ||
475 | PrimitiveBaseShape pbs, OMV.Vector3 size, float lod, CreateShapeCall makeShape) | ||
476 | { | ||
477 | BulletShape newShape = new BulletShape(); | ||
478 | |||
479 | IMesh meshData = null; | ||
480 | lock (physicsScene.mesher) | ||
481 | { | ||
482 | meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod, | ||
483 | false, // say it is not physical so a bounding box is not built | ||
484 | false, // do not cache the mesh and do not use previously built versions | ||
485 | false, | ||
486 | false | ||
487 | ); | ||
488 | } | ||
489 | |||
490 | if (meshData != null) | ||
491 | { | ||
492 | if (prim.PrimAssetState == BSPhysObject.PrimAssetCondition.Fetched) | ||
493 | { | ||
494 | // Release the fetched asset data once it has been used. | ||
495 | pbs.SculptData = new byte[0]; | ||
496 | prim.PrimAssetState = BSPhysObject.PrimAssetCondition.Unknown; | ||
497 | } | ||
498 | |||
499 | int[] indices = meshData.getIndexListAsInt(); | ||
500 | int realIndicesIndex = indices.Length; | ||
501 | float[] verticesAsFloats = meshData.getVertexListAsFloat(); | ||
502 | |||
503 | if (BSParam.ShouldRemoveZeroWidthTriangles) | ||
504 | { | ||
505 | // Remove degenerate triangles. These are triangles with two of the vertices | ||
506 | // are the same. This is complicated by the problem that vertices are not | ||
507 | // made unique in sculpties so we have to compare the values in the vertex. | ||
508 | realIndicesIndex = 0; | ||
509 | for (int tri = 0; tri < indices.Length; tri += 3) | ||
510 | { | ||
511 | // Compute displacements into vertex array for each vertex of the triangle | ||
512 | int v1 = indices[tri + 0] * 3; | ||
513 | int v2 = indices[tri + 1] * 3; | ||
514 | int v3 = indices[tri + 2] * 3; | ||
515 | // Check to see if any two of the vertices are the same | ||
516 | if (!( ( verticesAsFloats[v1 + 0] == verticesAsFloats[v2 + 0] | ||
517 | && verticesAsFloats[v1 + 1] == verticesAsFloats[v2 + 1] | ||
518 | && verticesAsFloats[v1 + 2] == verticesAsFloats[v2 + 2]) | ||
519 | || ( verticesAsFloats[v2 + 0] == verticesAsFloats[v3 + 0] | ||
520 | && verticesAsFloats[v2 + 1] == verticesAsFloats[v3 + 1] | ||
521 | && verticesAsFloats[v2 + 2] == verticesAsFloats[v3 + 2]) | ||
522 | || ( verticesAsFloats[v1 + 0] == verticesAsFloats[v3 + 0] | ||
523 | && verticesAsFloats[v1 + 1] == verticesAsFloats[v3 + 1] | ||
524 | && verticesAsFloats[v1 + 2] == verticesAsFloats[v3 + 2]) ) | ||
525 | ) | ||
526 | { | ||
527 | // None of the vertices of the triangles are the same. This is a good triangle; | ||
528 | indices[realIndicesIndex + 0] = indices[tri + 0]; | ||
529 | indices[realIndicesIndex + 1] = indices[tri + 1]; | ||
530 | indices[realIndicesIndex + 2] = indices[tri + 2]; | ||
531 | realIndicesIndex += 3; | ||
532 | } | ||
533 | } | ||
534 | } | ||
535 | physicsScene.DetailLog("{0},BSShapeMesh.CreatePhysicalMesh,key={1},origTri={2},realTri={3},numVerts={4}", | ||
536 | BSScene.DetailLogZero, newMeshKey.ToString("X"), indices.Length / 3, realIndicesIndex / 3, verticesAsFloats.Length / 3); | ||
537 | |||
538 | if (realIndicesIndex != 0) | ||
539 | { | ||
540 | newShape = makeShape(physicsScene.World, realIndicesIndex, indices, verticesAsFloats.Length / 3, verticesAsFloats); | ||
541 | } | ||
542 | else | ||
543 | { | ||
544 | // Force the asset condition to 'failed' so we won't try to keep fetching and processing this mesh. | ||
545 | prim.PrimAssetState = BSPhysObject.PrimAssetCondition.FailedMeshing; | ||
546 | physicsScene.Logger.DebugFormat("{0} All mesh triangles degenerate. Prim={1}", LogHeader, UsefulPrimInfo(physicsScene, prim) ); | ||
547 | physicsScene.DetailLog("{0},BSShapeMesh.CreatePhysicalMesh,allDegenerate,key={1}", prim.LocalID, newMeshKey); | ||
548 | } | ||
549 | } | ||
550 | newShape.shapeKey = newMeshKey; | ||
551 | |||
552 | return newShape; | ||
553 | } | ||
192 | } | 554 | } |
193 | 555 | ||
556 | // ============================================================================================================ | ||
194 | public class BSShapeHull : BSShape | 557 | public class BSShapeHull : BSShape |
195 | { | 558 | { |
196 | private static string LogHeader = "[BULLETSIM SHAPE HULL]"; | 559 | private static string LogHeader = "[BULLETSIM SHAPE HULL]"; |
197 | private static Dictionary<System.UInt64, BSShapeHull> Hulls = new Dictionary<System.UInt64, BSShapeHull>(); | 560 | public static Dictionary<System.UInt64, BSShapeHull> Hulls = new Dictionary<System.UInt64, BSShapeHull>(); |
198 | 561 | ||
199 | public BSShapeHull() : base() | 562 | public BSShapeHull(BulletShape pShape) : base(pShape) |
200 | { | 563 | { |
201 | } | 564 | } |
202 | public static BSShape GetReference() { return new BSShapeNull(); } | 565 | public static BSShape GetReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim) |
203 | public override void Dereference(BSScene physicsScene) { } | 566 | { |
567 | float lod; | ||
568 | System.UInt64 newHullKey = BSShape.ComputeShapeKey(prim.Size, prim.BaseShape, out lod); | ||
569 | |||
570 | BSShapeHull retHull = null; | ||
571 | lock (Hulls) | ||
572 | { | ||
573 | if (Hulls.TryGetValue(newHullKey, out retHull)) | ||
574 | { | ||
575 | // The mesh has already been created. Return a new reference to same. | ||
576 | retHull.IncrementReference(); | ||
577 | } | ||
578 | else | ||
579 | { | ||
580 | retHull = new BSShapeHull(new BulletShape()); | ||
581 | // An instance of this mesh has not been created. Build and remember same. | ||
582 | BulletShape newShape = retHull.CreatePhysicalHull(physicsScene, prim, newHullKey, prim.BaseShape, prim.Size, lod); | ||
583 | |||
584 | // Check to see if hull was created (might require an asset). | ||
585 | newShape = VerifyMeshCreated(physicsScene, newShape, prim); | ||
586 | if (!newShape.isNativeShape | ||
587 | || prim.PrimAssetState == BSPhysObject.PrimAssetCondition.FailedMeshing | ||
588 | || prim.PrimAssetState == BSPhysObject.PrimAssetCondition.FailedAssetFetch) | ||
589 | { | ||
590 | // If a mesh was what was created, remember the built shape for later sharing. | ||
591 | Hulls.Add(newHullKey, retHull); | ||
592 | } | ||
593 | retHull.physShapeInfo = newShape; | ||
594 | } | ||
595 | } | ||
596 | physicsScene.DetailLog("{0},BSShapeHull,getReference,hull={1},size={2},lod={3}", prim.LocalID, retHull, prim.Size, lod); | ||
597 | return retHull; | ||
598 | } | ||
599 | public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim) | ||
600 | { | ||
601 | BSShape ret = null; | ||
602 | // If the underlying shape is native, the actual shape has not been build (waiting for asset) | ||
603 | // and we must create a copy of the native shape since they are never shared. | ||
604 | if (physShapeInfo.HasPhysicalShape && physShapeInfo.isNativeShape) | ||
605 | { | ||
606 | // TODO: decide when the native shapes should be freed. Check in Dereference? | ||
607 | ret = BSShapeNative.GetReference(pPhysicsScene, pPrim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX); | ||
608 | } | ||
609 | else | ||
610 | { | ||
611 | // Another reference to this shape is just counted. | ||
612 | IncrementReference(); | ||
613 | ret = this; | ||
614 | } | ||
615 | return ret; | ||
616 | } | ||
617 | public override void Dereference(BSScene physicsScene) | ||
618 | { | ||
619 | lock (Hulls) | ||
620 | { | ||
621 | this.DecrementReference(); | ||
622 | physicsScene.DetailLog("{0},BSShapeHull.Dereference,shape={1}", BSScene.DetailLogZero, this); | ||
623 | // TODO: schedule aging and destruction of unused meshes. | ||
624 | } | ||
625 | } | ||
626 | List<ConvexResult> m_hulls; | ||
627 | private BulletShape CreatePhysicalHull(BSScene physicsScene, BSPhysObject prim, System.UInt64 newHullKey, | ||
628 | PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) | ||
629 | { | ||
630 | BulletShape newShape = new BulletShape(); | ||
631 | |||
632 | IMesh meshData = null; | ||
633 | List<List<OMV.Vector3>> allHulls = null; | ||
634 | lock (physicsScene.mesher) | ||
635 | { | ||
636 | // Pass true for physicalness as this prevents the creation of bounding box which is not needed | ||
637 | meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod, true /* isPhysical */, false /* shouldCache */, false, false); | ||
638 | |||
639 | // If we should use the asset's hull info, fetch it out of the locked mesher | ||
640 | if (meshData != null && BSParam.ShouldUseAssetHulls) | ||
641 | { | ||
642 | Meshmerizer realMesher = physicsScene.mesher as Meshmerizer; | ||
643 | if (realMesher != null) | ||
644 | { | ||
645 | allHulls = realMesher.GetConvexHulls(size); | ||
646 | } | ||
647 | if (allHulls == null) | ||
648 | { | ||
649 | physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,assetHulls,noAssetHull", prim.LocalID); | ||
650 | } | ||
651 | } | ||
652 | } | ||
653 | |||
654 | // If there is hull data in the mesh asset, build the hull from that | ||
655 | if (allHulls != null && BSParam.ShouldUseAssetHulls) | ||
656 | { | ||
657 | int hullCount = allHulls.Count; | ||
658 | int totalVertices = 1; // include one for the count of the hulls | ||
659 | // Using the structure described for HACD hulls, create the memory sturcture | ||
660 | // to pass the hull data to the creater. | ||
661 | foreach (List<OMV.Vector3> hullVerts in allHulls) | ||
662 | { | ||
663 | totalVertices += 4; // add four for the vertex count and centroid | ||
664 | totalVertices += hullVerts.Count * 3; // one vertex is three dimensions | ||
665 | } | ||
666 | float[] convHulls = new float[totalVertices]; | ||
667 | |||
668 | convHulls[0] = (float)hullCount; | ||
669 | int jj = 1; | ||
670 | foreach (List<OMV.Vector3> hullVerts in allHulls) | ||
671 | { | ||
672 | convHulls[jj + 0] = hullVerts.Count; | ||
673 | convHulls[jj + 1] = 0f; // centroid x,y,z | ||
674 | convHulls[jj + 2] = 0f; | ||
675 | convHulls[jj + 3] = 0f; | ||
676 | jj += 4; | ||
677 | foreach (OMV.Vector3 oneVert in hullVerts) | ||
678 | { | ||
679 | convHulls[jj + 0] = oneVert.X; | ||
680 | convHulls[jj + 1] = oneVert.Y; | ||
681 | convHulls[jj + 2] = oneVert.Z; | ||
682 | jj += 3; | ||
683 | } | ||
684 | } | ||
685 | |||
686 | // create the hull data structure in Bullet | ||
687 | newShape = physicsScene.PE.CreateHullShape(physicsScene.World, hullCount, convHulls); | ||
688 | |||
689 | physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,assetHulls,hulls={1},totVert={2},shape={3}", | ||
690 | prim.LocalID, hullCount, totalVertices, newShape); | ||
691 | } | ||
692 | |||
693 | // If no hull specified in the asset and we should use Bullet's HACD approximation... | ||
694 | if (!newShape.HasPhysicalShape && BSParam.ShouldUseBulletHACD) | ||
695 | { | ||
696 | // Build the hull shape from an existing mesh shape. | ||
697 | // The mesh should have already been created in Bullet. | ||
698 | physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,bulletHACD,entry", prim.LocalID); | ||
699 | BSShape meshShape = BSShapeMesh.GetReference(physicsScene, true, prim); | ||
700 | |||
701 | if (meshShape.physShapeInfo.HasPhysicalShape) | ||
702 | { | ||
703 | HACDParams parms; | ||
704 | parms.maxVerticesPerHull = BSParam.BHullMaxVerticesPerHull; | ||
705 | parms.minClusters = BSParam.BHullMinClusters; | ||
706 | parms.compacityWeight = BSParam.BHullCompacityWeight; | ||
707 | parms.volumeWeight = BSParam.BHullVolumeWeight; | ||
708 | parms.concavity = BSParam.BHullConcavity; | ||
709 | parms.addExtraDistPoints = BSParam.NumericBool(BSParam.BHullAddExtraDistPoints); | ||
710 | parms.addNeighboursDistPoints = BSParam.NumericBool(BSParam.BHullAddNeighboursDistPoints); | ||
711 | parms.addFacesPoints = BSParam.NumericBool(BSParam.BHullAddFacesPoints); | ||
712 | parms.shouldAdjustCollisionMargin = BSParam.NumericBool(BSParam.BHullShouldAdjustCollisionMargin); | ||
713 | |||
714 | physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,hullFromMesh,beforeCall", prim.LocalID, newShape.HasPhysicalShape); | ||
715 | newShape = physicsScene.PE.BuildHullShapeFromMesh(physicsScene.World, meshShape.physShapeInfo, parms); | ||
716 | physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,hullFromMesh,shape={1}", prim.LocalID, newShape); | ||
717 | |||
718 | // Now done with the mesh shape. | ||
719 | meshShape.Dereference(physicsScene); | ||
720 | } | ||
721 | physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,bulletHACD,exit,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape); | ||
722 | } | ||
723 | |||
724 | // If no other hull specifications, use our HACD hull approximation. | ||
725 | if (!newShape.HasPhysicalShape && meshData != null) | ||
726 | { | ||
727 | if (prim.PrimAssetState == BSPhysObject.PrimAssetCondition.Fetched) | ||
728 | { | ||
729 | // Release the fetched asset data once it has been used. | ||
730 | pbs.SculptData = new byte[0]; | ||
731 | prim.PrimAssetState = BSPhysObject.PrimAssetCondition.Unknown; | ||
732 | } | ||
733 | |||
734 | int[] indices = meshData.getIndexListAsInt(); | ||
735 | List<OMV.Vector3> vertices = meshData.getVertexList(); | ||
736 | |||
737 | //format conversion from IMesh format to DecompDesc format | ||
738 | List<int> convIndices = new List<int>(); | ||
739 | List<float3> convVertices = new List<float3>(); | ||
740 | for (int ii = 0; ii < indices.GetLength(0); ii++) | ||
741 | { | ||
742 | convIndices.Add(indices[ii]); | ||
743 | } | ||
744 | foreach (OMV.Vector3 vv in vertices) | ||
745 | { | ||
746 | convVertices.Add(new float3(vv.X, vv.Y, vv.Z)); | ||
747 | } | ||
748 | |||
749 | uint maxDepthSplit = (uint)BSParam.CSHullMaxDepthSplit; | ||
750 | if (BSParam.CSHullMaxDepthSplit != BSParam.CSHullMaxDepthSplitForSimpleShapes) | ||
751 | { | ||
752 | // Simple primitive shapes we know are convex so they are better implemented with | ||
753 | // fewer hulls. | ||
754 | // Check for simple shape (prim without cuts) and reduce split parameter if so. | ||
755 | if (BSShapeCollection.PrimHasNoCuts(pbs)) | ||
756 | { | ||
757 | maxDepthSplit = (uint)BSParam.CSHullMaxDepthSplitForSimpleShapes; | ||
758 | } | ||
759 | } | ||
760 | |||
761 | // setup and do convex hull conversion | ||
762 | m_hulls = new List<ConvexResult>(); | ||
763 | DecompDesc dcomp = new DecompDesc(); | ||
764 | dcomp.mIndices = convIndices; | ||
765 | dcomp.mVertices = convVertices; | ||
766 | dcomp.mDepth = maxDepthSplit; | ||
767 | dcomp.mCpercent = BSParam.CSHullConcavityThresholdPercent; | ||
768 | dcomp.mPpercent = BSParam.CSHullVolumeConservationThresholdPercent; | ||
769 | dcomp.mMaxVertices = (uint)BSParam.CSHullMaxVertices; | ||
770 | dcomp.mSkinWidth = BSParam.CSHullMaxSkinWidth; | ||
771 | ConvexBuilder convexBuilder = new ConvexBuilder(HullReturn); | ||
772 | // create the hull into the _hulls variable | ||
773 | convexBuilder.process(dcomp); | ||
774 | |||
775 | physicsScene.DetailLog("{0},BSShapeCollection.CreatePhysicalHull,key={1},inVert={2},inInd={3},split={4},hulls={5}", | ||
776 | BSScene.DetailLogZero, newHullKey, indices.GetLength(0), vertices.Count, maxDepthSplit, m_hulls.Count); | ||
777 | |||
778 | // Convert the vertices and indices for passing to unmanaged. | ||
779 | // The hull information is passed as a large floating point array. | ||
780 | // The format is: | ||
781 | // convHulls[0] = number of hulls | ||
782 | // convHulls[1] = number of vertices in first hull | ||
783 | // convHulls[2] = hull centroid X coordinate | ||
784 | // convHulls[3] = hull centroid Y coordinate | ||
785 | // convHulls[4] = hull centroid Z coordinate | ||
786 | // convHulls[5] = first hull vertex X | ||
787 | // convHulls[6] = first hull vertex Y | ||
788 | // convHulls[7] = first hull vertex Z | ||
789 | // convHulls[8] = second hull vertex X | ||
790 | // ... | ||
791 | // convHulls[n] = number of vertices in second hull | ||
792 | // convHulls[n+1] = second hull centroid X coordinate | ||
793 | // ... | ||
794 | // | ||
795 | // TODO: is is very inefficient. Someday change the convex hull generator to return | ||
796 | // data structures that do not need to be converted in order to pass to Bullet. | ||
797 | // And maybe put the values directly into pinned memory rather than marshaling. | ||
798 | int hullCount = m_hulls.Count; | ||
799 | int totalVertices = 1; // include one for the count of the hulls | ||
800 | foreach (ConvexResult cr in m_hulls) | ||
801 | { | ||
802 | totalVertices += 4; // add four for the vertex count and centroid | ||
803 | totalVertices += cr.HullIndices.Count * 3; // we pass just triangles | ||
804 | } | ||
805 | float[] convHulls = new float[totalVertices]; | ||
806 | |||
807 | convHulls[0] = (float)hullCount; | ||
808 | int jj = 1; | ||
809 | foreach (ConvexResult cr in m_hulls) | ||
810 | { | ||
811 | // copy vertices for index access | ||
812 | float3[] verts = new float3[cr.HullVertices.Count]; | ||
813 | int kk = 0; | ||
814 | foreach (float3 ff in cr.HullVertices) | ||
815 | { | ||
816 | verts[kk++] = ff; | ||
817 | } | ||
818 | |||
819 | // add to the array one hull's worth of data | ||
820 | convHulls[jj++] = cr.HullIndices.Count; | ||
821 | convHulls[jj++] = 0f; // centroid x,y,z | ||
822 | convHulls[jj++] = 0f; | ||
823 | convHulls[jj++] = 0f; | ||
824 | foreach (int ind in cr.HullIndices) | ||
825 | { | ||
826 | convHulls[jj++] = verts[ind].x; | ||
827 | convHulls[jj++] = verts[ind].y; | ||
828 | convHulls[jj++] = verts[ind].z; | ||
829 | } | ||
830 | } | ||
831 | // create the hull data structure in Bullet | ||
832 | newShape = physicsScene.PE.CreateHullShape(physicsScene.World, hullCount, convHulls); | ||
833 | } | ||
834 | newShape.shapeKey = newHullKey; | ||
835 | return newShape; | ||
836 | } | ||
837 | // Callback from convex hull creater with a newly created hull. | ||
838 | // Just add it to our collection of hulls for this shape. | ||
839 | private void HullReturn(ConvexResult result) | ||
840 | { | ||
841 | m_hulls.Add(result); | ||
842 | return; | ||
843 | } | ||
844 | // Loop through all the known hulls and return the description based on the physical address. | ||
845 | public static bool TryGetHullByPtr(BulletShape pShape, out BSShapeHull outHull) | ||
846 | { | ||
847 | bool ret = false; | ||
848 | BSShapeHull foundDesc = null; | ||
849 | lock (Hulls) | ||
850 | { | ||
851 | foreach (BSShapeHull sh in Hulls.Values) | ||
852 | { | ||
853 | if (sh.physShapeInfo.ReferenceSame(pShape)) | ||
854 | { | ||
855 | foundDesc = sh; | ||
856 | ret = true; | ||
857 | break; | ||
858 | } | ||
859 | |||
860 | } | ||
861 | } | ||
862 | outHull = foundDesc; | ||
863 | return ret; | ||
864 | } | ||
204 | } | 865 | } |
205 | 866 | ||
867 | // ============================================================================================================ | ||
206 | public class BSShapeCompound : BSShape | 868 | public class BSShapeCompound : BSShape |
207 | { | 869 | { |
208 | private static string LogHeader = "[BULLETSIM SHAPE COMPOUND]"; | 870 | private static string LogHeader = "[BULLETSIM SHAPE COMPOUND]"; |
209 | public BSShapeCompound() : base() | 871 | public static Dictionary<string, BSShapeCompound> CompoundShapes = new Dictionary<string, BSShapeCompound>(); |
872 | |||
873 | public BSShapeCompound(BulletShape pShape) : base(pShape) | ||
210 | { | 874 | { |
211 | } | 875 | } |
212 | public static BSShape GetReference(BSPhysObject prim) | 876 | public static BSShape GetReference(BSScene physicsScene) |
213 | { | 877 | { |
214 | return new BSShapeNull(); | 878 | // Base compound shapes are not shared so this returns a raw shape. |
879 | // A built compound shape can be reused in linksets. | ||
880 | BSShapeCompound ret = new BSShapeCompound(CreatePhysicalCompoundShape(physicsScene)); | ||
881 | CompoundShapes.Add(ret.AddrString, ret); | ||
882 | return ret; | ||
883 | } | ||
884 | public override BSShape GetReference(BSScene physicsScene, BSPhysObject prim) | ||
885 | { | ||
886 | // Calling this reference means we want another handle to an existing compound shape | ||
887 | // (usually linksets) so return this copy. | ||
888 | IncrementReference(); | ||
889 | return this; | ||
890 | } | ||
891 | // Dereferencing a compound shape releases the hold on all the child shapes. | ||
892 | public override void Dereference(BSScene physicsScene) | ||
893 | { | ||
894 | lock (physShapeInfo) | ||
895 | { | ||
896 | this.DecrementReference(); | ||
897 | physicsScene.DetailLog("{0},BSShapeCompound.Dereference,shape={1}", BSScene.DetailLogZero, this); | ||
898 | if (referenceCount <= 0) | ||
899 | { | ||
900 | if (!physicsScene.PE.IsCompound(physShapeInfo)) | ||
901 | { | ||
902 | // Failed the sanity check!! | ||
903 | physicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}", | ||
904 | LogHeader, physShapeInfo.shapeType, physShapeInfo.AddrString); | ||
905 | physicsScene.DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}", | ||
906 | BSScene.DetailLogZero, physShapeInfo.shapeType, physShapeInfo.AddrString); | ||
907 | return; | ||
908 | } | ||
909 | |||
910 | int numChildren = physicsScene.PE.GetNumberOfCompoundChildren(physShapeInfo); | ||
911 | physicsScene.DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", | ||
912 | BSScene.DetailLogZero, physShapeInfo, numChildren); | ||
913 | |||
914 | // Loop through all the children dereferencing each. | ||
915 | for (int ii = numChildren - 1; ii >= 0; ii--) | ||
916 | { | ||
917 | BulletShape childShape = physicsScene.PE.RemoveChildShapeFromCompoundShapeIndex(physShapeInfo, ii); | ||
918 | DereferenceAnonCollisionShape(physicsScene, childShape); | ||
919 | } | ||
920 | |||
921 | lock (CompoundShapes) | ||
922 | CompoundShapes.Remove(physShapeInfo.AddrString); | ||
923 | physicsScene.PE.DeleteCollisionShape(physicsScene.World, physShapeInfo); | ||
924 | } | ||
925 | } | ||
926 | } | ||
927 | public static bool TryGetCompoundByPtr(BulletShape pShape, out BSShapeCompound outCompound) | ||
928 | { | ||
929 | lock (CompoundShapes) | ||
930 | { | ||
931 | string addr = pShape.AddrString; | ||
932 | return CompoundShapes.TryGetValue(addr, out outCompound); | ||
933 | } | ||
934 | } | ||
935 | private static BulletShape CreatePhysicalCompoundShape(BSScene physicsScene) | ||
936 | { | ||
937 | BulletShape cShape = physicsScene.PE.CreateCompoundShape(physicsScene.World, false); | ||
938 | return cShape; | ||
939 | } | ||
940 | // Sometimes we have a pointer to a collision shape but don't know what type it is. | ||
941 | // Figure out type and call the correct dereference routine. | ||
942 | // Called at taint-time. | ||
943 | private void DereferenceAnonCollisionShape(BSScene physicsScene, BulletShape pShape) | ||
944 | { | ||
945 | // TODO: figure a better way to go through all the shape types and find a possible instance. | ||
946 | physicsScene.DetailLog("{0},BSShapeCompound.DereferenceAnonCollisionShape,shape={1}", | ||
947 | BSScene.DetailLogZero, pShape); | ||
948 | BSShapeMesh meshDesc; | ||
949 | if (BSShapeMesh.TryGetMeshByPtr(pShape, out meshDesc)) | ||
950 | { | ||
951 | meshDesc.Dereference(physicsScene); | ||
952 | // physicsScene.DetailLog("{0},BSShapeCompound.DereferenceAnonCollisionShape,foundMesh,shape={1}", BSScene.DetailLogZero, pShape); | ||
953 | } | ||
954 | else | ||
955 | { | ||
956 | BSShapeHull hullDesc; | ||
957 | if (BSShapeHull.TryGetHullByPtr(pShape, out hullDesc)) | ||
958 | { | ||
959 | hullDesc.Dereference(physicsScene); | ||
960 | // physicsScene.DetailLog("{0},BSShapeCompound.DereferenceAnonCollisionShape,foundHull,shape={1}", BSScene.DetailLogZero, pShape); | ||
961 | } | ||
962 | else | ||
963 | { | ||
964 | BSShapeConvexHull chullDesc; | ||
965 | if (BSShapeConvexHull.TryGetConvexHullByPtr(pShape, out chullDesc)) | ||
966 | { | ||
967 | chullDesc.Dereference(physicsScene); | ||
968 | // physicsScene.DetailLog("{0},BSShapeCompound.DereferenceAnonCollisionShape,foundConvexHull,shape={1}", BSScene.DetailLogZero, pShape); | ||
969 | } | ||
970 | else | ||
971 | { | ||
972 | BSShapeGImpact gImpactDesc; | ||
973 | if (BSShapeGImpact.TryGetGImpactByPtr(pShape, out gImpactDesc)) | ||
974 | { | ||
975 | gImpactDesc.Dereference(physicsScene); | ||
976 | // physicsScene.DetailLog("{0},BSShapeCompound.DereferenceAnonCollisionShape,foundgImpact,shape={1}", BSScene.DetailLogZero, pShape); | ||
977 | } | ||
978 | else | ||
979 | { | ||
980 | // Didn't find it in the lists of specific types. It could be compound. | ||
981 | BSShapeCompound compoundDesc; | ||
982 | if (BSShapeCompound.TryGetCompoundByPtr(pShape, out compoundDesc)) | ||
983 | { | ||
984 | compoundDesc.Dereference(physicsScene); | ||
985 | // physicsScene.DetailLog("{0},BSShapeCompound.DereferenceAnonCollisionShape,recursiveCompoundShape,shape={1}", BSScene.DetailLogZero, pShape); | ||
986 | } | ||
987 | else | ||
988 | { | ||
989 | // If none of the above, maybe it is a simple native shape. | ||
990 | if (physicsScene.PE.IsNativeShape(pShape)) | ||
991 | { | ||
992 | // physicsScene.DetailLog("{0},BSShapeCompound.DereferenceAnonCollisionShape,assumingNative,shape={1}", BSScene.DetailLogZero, pShape); | ||
993 | BSShapeNative nativeShape = new BSShapeNative(pShape); | ||
994 | nativeShape.Dereference(physicsScene); | ||
995 | } | ||
996 | } | ||
997 | } | ||
998 | } | ||
999 | } | ||
1000 | } | ||
1001 | } | ||
1002 | } | ||
1003 | |||
1004 | // ============================================================================================================ | ||
1005 | public class BSShapeConvexHull : BSShape | ||
1006 | { | ||
1007 | private static string LogHeader = "[BULLETSIM SHAPE CONVEX HULL]"; | ||
1008 | public static Dictionary<System.UInt64, BSShapeConvexHull> ConvexHulls = new Dictionary<System.UInt64, BSShapeConvexHull>(); | ||
1009 | |||
1010 | public BSShapeConvexHull(BulletShape pShape) : base(pShape) | ||
1011 | { | ||
1012 | } | ||
1013 | public static BSShape GetReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim) | ||
1014 | { | ||
1015 | float lod; | ||
1016 | System.UInt64 newMeshKey = BSShape.ComputeShapeKey(prim.Size, prim.BaseShape, out lod); | ||
1017 | |||
1018 | physicsScene.DetailLog("{0},BSShapeConvexHull,getReference,newKey={1},size={2},lod={3}", | ||
1019 | prim.LocalID, newMeshKey.ToString("X"), prim.Size, lod); | ||
1020 | |||
1021 | BSShapeConvexHull retConvexHull = null; | ||
1022 | lock (ConvexHulls) | ||
1023 | { | ||
1024 | if (ConvexHulls.TryGetValue(newMeshKey, out retConvexHull)) | ||
1025 | { | ||
1026 | // The mesh has already been created. Return a new reference to same. | ||
1027 | retConvexHull.IncrementReference(); | ||
1028 | } | ||
1029 | else | ||
1030 | { | ||
1031 | retConvexHull = new BSShapeConvexHull(new BulletShape()); | ||
1032 | BulletShape convexShape = null; | ||
1033 | |||
1034 | // Get a handle to a mesh to build the hull from | ||
1035 | BSShape baseMesh = BSShapeMesh.GetReference(physicsScene, false /* forceRebuild */, prim); | ||
1036 | if (baseMesh.physShapeInfo.isNativeShape) | ||
1037 | { | ||
1038 | // We get here if the mesh was not creatable. Could be waiting for an asset from the disk. | ||
1039 | // In the short term, we return the native shape and a later ForceBodyShapeRebuild should | ||
1040 | // get back to this code with a buildable mesh. | ||
1041 | // TODO: not sure the temp native shape is freed when the mesh is rebuilt. When does this get freed? | ||
1042 | convexShape = baseMesh.physShapeInfo; | ||
1043 | } | ||
1044 | else | ||
1045 | { | ||
1046 | convexShape = physicsScene.PE.BuildConvexHullShapeFromMesh(physicsScene.World, baseMesh.physShapeInfo); | ||
1047 | convexShape.shapeKey = newMeshKey; | ||
1048 | ConvexHulls.Add(convexShape.shapeKey, retConvexHull); | ||
1049 | physicsScene.DetailLog("{0},BSShapeConvexHull.GetReference,addingNewlyCreatedShape,shape={1}", | ||
1050 | BSScene.DetailLogZero, convexShape); | ||
1051 | } | ||
1052 | |||
1053 | // Done with the base mesh | ||
1054 | baseMesh.Dereference(physicsScene); | ||
1055 | |||
1056 | retConvexHull.physShapeInfo = convexShape; | ||
1057 | } | ||
1058 | } | ||
1059 | return retConvexHull; | ||
1060 | } | ||
1061 | public override BSShape GetReference(BSScene physicsScene, BSPhysObject prim) | ||
1062 | { | ||
1063 | // Calling this reference means we want another handle to an existing shape | ||
1064 | // (usually linksets) so return this copy. | ||
1065 | IncrementReference(); | ||
1066 | return this; | ||
1067 | } | ||
1068 | // Dereferencing a compound shape releases the hold on all the child shapes. | ||
1069 | public override void Dereference(BSScene physicsScene) | ||
1070 | { | ||
1071 | lock (ConvexHulls) | ||
1072 | { | ||
1073 | this.DecrementReference(); | ||
1074 | physicsScene.DetailLog("{0},BSShapeConvexHull.Dereference,shape={1}", BSScene.DetailLogZero, this); | ||
1075 | // TODO: schedule aging and destruction of unused meshes. | ||
1076 | } | ||
1077 | } | ||
1078 | // Loop through all the known hulls and return the description based on the physical address. | ||
1079 | public static bool TryGetConvexHullByPtr(BulletShape pShape, out BSShapeConvexHull outHull) | ||
1080 | { | ||
1081 | bool ret = false; | ||
1082 | BSShapeConvexHull foundDesc = null; | ||
1083 | lock (ConvexHulls) | ||
1084 | { | ||
1085 | foreach (BSShapeConvexHull sh in ConvexHulls.Values) | ||
1086 | { | ||
1087 | if (sh.physShapeInfo.ReferenceSame(pShape)) | ||
1088 | { | ||
1089 | foundDesc = sh; | ||
1090 | ret = true; | ||
1091 | break; | ||
1092 | } | ||
1093 | |||
1094 | } | ||
1095 | } | ||
1096 | outHull = foundDesc; | ||
1097 | return ret; | ||
1098 | } | ||
1099 | } | ||
1100 | // ============================================================================================================ | ||
1101 | public class BSShapeGImpact : BSShape | ||
1102 | { | ||
1103 | private static string LogHeader = "[BULLETSIM SHAPE GIMPACT]"; | ||
1104 | public static Dictionary<System.UInt64, BSShapeGImpact> GImpacts = new Dictionary<System.UInt64, BSShapeGImpact>(); | ||
1105 | |||
1106 | public BSShapeGImpact(BulletShape pShape) : base(pShape) | ||
1107 | { | ||
1108 | } | ||
1109 | public static BSShape GetReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim) | ||
1110 | { | ||
1111 | float lod; | ||
1112 | System.UInt64 newMeshKey = BSShape.ComputeShapeKey(prim.Size, prim.BaseShape, out lod); | ||
1113 | |||
1114 | physicsScene.DetailLog("{0},BSShapeGImpact,getReference,newKey={1},size={2},lod={3}", | ||
1115 | prim.LocalID, newMeshKey.ToString("X"), prim.Size, lod); | ||
1116 | |||
1117 | BSShapeGImpact retGImpact = null; | ||
1118 | lock (GImpacts) | ||
1119 | { | ||
1120 | if (GImpacts.TryGetValue(newMeshKey, out retGImpact)) | ||
1121 | { | ||
1122 | // The mesh has already been created. Return a new reference to same. | ||
1123 | retGImpact.IncrementReference(); | ||
1124 | } | ||
1125 | else | ||
1126 | { | ||
1127 | retGImpact = new BSShapeGImpact(new BulletShape()); | ||
1128 | BulletShape newShape = retGImpact.CreatePhysicalGImpact(physicsScene, prim, newMeshKey, prim.BaseShape, prim.Size, lod); | ||
1129 | |||
1130 | // Check to see if mesh was created (might require an asset). | ||
1131 | newShape = VerifyMeshCreated(physicsScene, newShape, prim); | ||
1132 | newShape.shapeKey = newMeshKey; | ||
1133 | if (!newShape.isNativeShape | ||
1134 | || prim.PrimAssetState == BSPhysObject.PrimAssetCondition.FailedMeshing | ||
1135 | || prim.PrimAssetState == BSPhysObject.PrimAssetCondition.FailedAssetFetch) | ||
1136 | { | ||
1137 | // If a mesh was what was created, remember the built shape for later sharing. | ||
1138 | // Also note that if meshing failed we put it in the mesh list as there is nothing | ||
1139 | // else to do about the mesh. | ||
1140 | GImpacts.Add(newMeshKey, retGImpact); | ||
1141 | } | ||
1142 | |||
1143 | retGImpact.physShapeInfo = newShape; | ||
1144 | } | ||
1145 | } | ||
1146 | return retGImpact; | ||
1147 | } | ||
1148 | |||
1149 | private BulletShape CreatePhysicalGImpact(BSScene physicsScene, BSPhysObject prim, System.UInt64 newMeshKey, | ||
1150 | PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) | ||
1151 | { | ||
1152 | return BSShapeMesh.CreatePhysicalMeshShape(physicsScene, prim, newMeshKey, pbs, size, lod, | ||
1153 | (w, iC, i, vC, v) => physicsScene.PE.CreateGImpactShape(w, iC, i, vC, v) ); | ||
1154 | } | ||
1155 | |||
1156 | public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim) | ||
1157 | { | ||
1158 | BSShape ret = null; | ||
1159 | // If the underlying shape is native, the actual shape has not been build (waiting for asset) | ||
1160 | // and we must create a copy of the native shape since they are never shared. | ||
1161 | if (physShapeInfo.HasPhysicalShape && physShapeInfo.isNativeShape) | ||
1162 | { | ||
1163 | // TODO: decide when the native shapes should be freed. Check in Dereference? | ||
1164 | ret = BSShapeNative.GetReference(pPhysicsScene, pPrim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX); | ||
1165 | } | ||
1166 | else | ||
1167 | { | ||
1168 | // Another reference to this shape is just counted. | ||
1169 | IncrementReference(); | ||
1170 | ret = this; | ||
1171 | } | ||
1172 | return ret; | ||
1173 | } | ||
1174 | // Dereferencing a compound shape releases the hold on all the child shapes. | ||
1175 | public override void Dereference(BSScene physicsScene) | ||
1176 | { | ||
1177 | lock (GImpacts) | ||
1178 | { | ||
1179 | this.DecrementReference(); | ||
1180 | physicsScene.DetailLog("{0},BSShapeGImpact.Dereference,shape={1}", BSScene.DetailLogZero, this); | ||
1181 | // TODO: schedule aging and destruction of unused meshes. | ||
1182 | } | ||
1183 | } | ||
1184 | // Loop through all the known hulls and return the description based on the physical address. | ||
1185 | public static bool TryGetGImpactByPtr(BulletShape pShape, out BSShapeGImpact outHull) | ||
1186 | { | ||
1187 | bool ret = false; | ||
1188 | BSShapeGImpact foundDesc = null; | ||
1189 | lock (GImpacts) | ||
1190 | { | ||
1191 | foreach (BSShapeGImpact sh in GImpacts.Values) | ||
1192 | { | ||
1193 | if (sh.physShapeInfo.ReferenceSame(pShape)) | ||
1194 | { | ||
1195 | foundDesc = sh; | ||
1196 | ret = true; | ||
1197 | break; | ||
1198 | } | ||
1199 | |||
1200 | } | ||
1201 | } | ||
1202 | outHull = foundDesc; | ||
1203 | return ret; | ||
215 | } | 1204 | } |
216 | public override void Dereference(BSScene physicsScene) { } | ||
217 | } | 1205 | } |
218 | 1206 | ||
1207 | // ============================================================================================================ | ||
219 | public class BSShapeAvatar : BSShape | 1208 | public class BSShapeAvatar : BSShape |
220 | { | 1209 | { |
221 | private static string LogHeader = "[BULLETSIM SHAPE AVATAR]"; | 1210 | private static string LogHeader = "[BULLETSIM SHAPE AVATAR]"; |
222 | public BSShapeAvatar() : base() | 1211 | public BSShapeAvatar() : base() |
223 | { | 1212 | { |
224 | } | 1213 | } |
225 | public static BSShape GetReference(BSPhysObject prim) | 1214 | public static BSShape GetReference(BSPhysObject prim) |
226 | { | 1215 | { |
1216 | return new BSShapeNull(); | ||
1217 | } | ||
1218 | public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim) | ||
1219 | { | ||
227 | return new BSShapeNull(); | 1220 | return new BSShapeNull(); |
228 | } | 1221 | } |
229 | public override void Dereference(BSScene physicsScene) { } | 1222 | public override void Dereference(BSScene physicsScene) { } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs index e4fecc3..8888d6d 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs | |||
@@ -68,7 +68,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
68 | 68 | ||
69 | // This minCoords and maxCoords passed in give the size of the terrain (min and max Z | 69 | // This minCoords and maxCoords passed in give the size of the terrain (min and max Z |
70 | // are the high and low points of the heightmap). | 70 | // are the high and low points of the heightmap). |
71 | public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, float[] initialMap, | 71 | public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, float[] initialMap, |
72 | Vector3 minCoords, Vector3 maxCoords) | 72 | Vector3 minCoords, Vector3 maxCoords) |
73 | : base(physicsScene, regionBase, id) | 73 | : base(physicsScene, regionBase, id) |
74 | { | 74 | { |
@@ -92,7 +92,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
92 | private void BuildHeightmapTerrain() | 92 | private void BuildHeightmapTerrain() |
93 | { | 93 | { |
94 | // Create the terrain shape from the mapInfo | 94 | // Create the terrain shape from the mapInfo |
95 | m_mapInfo.terrainShape = PhysicsScene.PE.CreateTerrainShape( m_mapInfo.ID, | 95 | m_mapInfo.terrainShape = m_physicsScene.PE.CreateTerrainShape( m_mapInfo.ID, |
96 | new Vector3(m_mapInfo.sizeX, m_mapInfo.sizeY, 0), m_mapInfo.minZ, m_mapInfo.maxZ, | 96 | new Vector3(m_mapInfo.sizeX, m_mapInfo.sizeY, 0), m_mapInfo.minZ, m_mapInfo.maxZ, |
97 | m_mapInfo.heightMap, 1f, BSParam.TerrainCollisionMargin); | 97 | m_mapInfo.heightMap, 1f, BSParam.TerrainCollisionMargin); |
98 | 98 | ||
@@ -103,26 +103,25 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
103 | centerPos.Y = m_mapInfo.minCoords.Y + (m_mapInfo.sizeY / 2f); | 103 | centerPos.Y = m_mapInfo.minCoords.Y + (m_mapInfo.sizeY / 2f); |
104 | centerPos.Z = m_mapInfo.minZ + ((m_mapInfo.maxZ - m_mapInfo.minZ) / 2f); | 104 | centerPos.Z = m_mapInfo.minZ + ((m_mapInfo.maxZ - m_mapInfo.minZ) / 2f); |
105 | 105 | ||
106 | m_mapInfo.terrainBody = PhysicsScene.PE.CreateBodyWithDefaultMotionState(m_mapInfo.terrainShape, | 106 | m_mapInfo.terrainBody = m_physicsScene.PE.CreateBodyWithDefaultMotionState(m_mapInfo.terrainShape, |
107 | m_mapInfo.ID, centerPos, Quaternion.Identity); | 107 | m_mapInfo.ID, centerPos, Quaternion.Identity); |
108 | 108 | ||
109 | // Set current terrain attributes | 109 | // Set current terrain attributes |
110 | PhysicsScene.PE.SetFriction(m_mapInfo.terrainBody, BSParam.TerrainFriction); | 110 | m_physicsScene.PE.SetFriction(m_mapInfo.terrainBody, BSParam.TerrainFriction); |
111 | PhysicsScene.PE.SetHitFraction(m_mapInfo.terrainBody, BSParam.TerrainHitFraction); | 111 | m_physicsScene.PE.SetHitFraction(m_mapInfo.terrainBody, BSParam.TerrainHitFraction); |
112 | PhysicsScene.PE.SetRestitution(m_mapInfo.terrainBody, BSParam.TerrainRestitution); | 112 | m_physicsScene.PE.SetRestitution(m_mapInfo.terrainBody, BSParam.TerrainRestitution); |
113 | PhysicsScene.PE.SetCollisionFlags(m_mapInfo.terrainBody, CollisionFlags.CF_STATIC_OBJECT); | 113 | m_physicsScene.PE.SetCollisionFlags(m_mapInfo.terrainBody, CollisionFlags.CF_STATIC_OBJECT); |
114 | |||
115 | m_mapInfo.terrainBody.collisionType = CollisionType.Terrain; | ||
114 | 116 | ||
115 | // Return the new terrain to the world of physical objects | 117 | // Return the new terrain to the world of physical objects |
116 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_mapInfo.terrainBody); | 118 | m_physicsScene.PE.AddObjectToWorld(m_physicsScene.World, m_mapInfo.terrainBody); |
117 | 119 | ||
118 | // redo its bounding box now that it is in the world | 120 | // redo its bounding box now that it is in the world |
119 | PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_mapInfo.terrainBody); | 121 | m_physicsScene.PE.UpdateSingleAabb(m_physicsScene.World, m_mapInfo.terrainBody); |
120 | |||
121 | m_mapInfo.terrainBody.collisionType = CollisionType.Terrain; | ||
122 | m_mapInfo.terrainBody.ApplyCollisionMask(PhysicsScene); | ||
123 | 122 | ||
124 | // Make it so the terrain will not move or be considered for movement. | 123 | // Make it so the terrain will not move or be considered for movement. |
125 | PhysicsScene.PE.ForceActivationState(m_mapInfo.terrainBody, ActivationState.DISABLE_SIMULATION); | 124 | m_physicsScene.PE.ForceActivationState(m_mapInfo.terrainBody, ActivationState.DISABLE_SIMULATION); |
126 | 125 | ||
127 | return; | 126 | return; |
128 | } | 127 | } |
@@ -134,9 +133,9 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
134 | { | 133 | { |
135 | if (m_mapInfo.terrainBody.HasPhysicalBody) | 134 | if (m_mapInfo.terrainBody.HasPhysicalBody) |
136 | { | 135 | { |
137 | PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_mapInfo.terrainBody); | 136 | m_physicsScene.PE.RemoveObjectFromWorld(m_physicsScene.World, m_mapInfo.terrainBody); |
138 | // Frees both the body and the shape. | 137 | // Frees both the body and the shape. |
139 | PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_mapInfo.terrainBody); | 138 | m_physicsScene.PE.DestroyObject(m_physicsScene.World, m_mapInfo.terrainBody); |
140 | } | 139 | } |
141 | } | 140 | } |
142 | m_mapInfo = null; | 141 | m_mapInfo = null; |
@@ -155,7 +154,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
155 | catch | 154 | catch |
156 | { | 155 | { |
157 | // Sometimes they give us wonky values of X and Y. Give a warning and return something. | 156 | // Sometimes they give us wonky values of X and Y. Give a warning and return something. |
158 | PhysicsScene.Logger.WarnFormat("{0} Bad request for terrain height. terrainBase={1}, pos={2}", | 157 | m_physicsScene.Logger.WarnFormat("{0} Bad request for terrain height. terrainBase={1}, pos={2}", |
159 | LogHeader, m_mapInfo.terrainRegionBase, pos); | 158 | LogHeader, m_mapInfo.terrainRegionBase, pos); |
160 | ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET; | 159 | ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET; |
161 | } | 160 | } |
@@ -165,7 +164,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
165 | // The passed position is relative to the base of the region. | 164 | // The passed position is relative to the base of the region. |
166 | public override float GetWaterLevelAtXYZ(Vector3 pos) | 165 | public override float GetWaterLevelAtXYZ(Vector3 pos) |
167 | { | 166 | { |
168 | return PhysicsScene.SimpleWaterLevel; | 167 | return m_physicsScene.SimpleWaterLevel; |
169 | } | 168 | } |
170 | } | 169 | } |
171 | } | 170 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs index b2fb835..441d2d3 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs | |||
@@ -50,14 +50,14 @@ public abstract class BSTerrainPhys : IDisposable | |||
50 | Mesh = 1 | 50 | Mesh = 1 |
51 | } | 51 | } |
52 | 52 | ||
53 | public BSScene PhysicsScene { get; private set; } | 53 | protected BSScene m_physicsScene { get; private set; } |
54 | // Base of the region in world coordinates. Coordinates inside the region are relative to this. | 54 | // Base of the region in world coordinates. Coordinates inside the region are relative to this. |
55 | public Vector3 TerrainBase { get; private set; } | 55 | public Vector3 TerrainBase { get; private set; } |
56 | public uint ID { get; private set; } | 56 | public uint ID { get; private set; } |
57 | 57 | ||
58 | public BSTerrainPhys(BSScene physicsScene, Vector3 regionBase, uint id) | 58 | public BSTerrainPhys(BSScene physicsScene, Vector3 regionBase, uint id) |
59 | { | 59 | { |
60 | PhysicsScene = physicsScene; | 60 | m_physicsScene = physicsScene; |
61 | TerrainBase = regionBase; | 61 | TerrainBase = regionBase; |
62 | ID = id; | 62 | ID = id; |
63 | } | 63 | } |
@@ -86,7 +86,7 @@ public sealed class BSTerrainManager : IDisposable | |||
86 | public Vector3 DefaultRegionSize = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); | 86 | public Vector3 DefaultRegionSize = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); |
87 | 87 | ||
88 | // The scene that I am part of | 88 | // The scene that I am part of |
89 | private BSScene PhysicsScene { get; set; } | 89 | private BSScene m_physicsScene { get; set; } |
90 | 90 | ||
91 | // The ground plane created to keep thing from falling to infinity. | 91 | // The ground plane created to keep thing from falling to infinity. |
92 | private BulletBody m_groundPlane; | 92 | private BulletBody m_groundPlane; |
@@ -113,7 +113,7 @@ public sealed class BSTerrainManager : IDisposable | |||
113 | 113 | ||
114 | public BSTerrainManager(BSScene physicsScene) | 114 | public BSTerrainManager(BSScene physicsScene) |
115 | { | 115 | { |
116 | PhysicsScene = physicsScene; | 116 | m_physicsScene = physicsScene; |
117 | m_terrains = new Dictionary<Vector3,BSTerrainPhys>(); | 117 | m_terrains = new Dictionary<Vector3,BSTerrainPhys>(); |
118 | 118 | ||
119 | // Assume one region of default size | 119 | // Assume one region of default size |
@@ -132,21 +132,22 @@ public sealed class BSTerrainManager : IDisposable | |||
132 | // safe to call Bullet in real time. We hope no one is moving prims around yet. | 132 | // safe to call Bullet in real time. We hope no one is moving prims around yet. |
133 | public void CreateInitialGroundPlaneAndTerrain() | 133 | public void CreateInitialGroundPlaneAndTerrain() |
134 | { | 134 | { |
135 | DetailLog("{0},BSTerrainManager.CreateInitialGroundPlaneAndTerrain,region={1}", BSScene.DetailLogZero, PhysicsScene.RegionName); | 135 | DetailLog("{0},BSTerrainManager.CreateInitialGroundPlaneAndTerrain,region={1}", BSScene.DetailLogZero, m_physicsScene.RegionName); |
136 | // The ground plane is here to catch things that are trying to drop to negative infinity | 136 | // The ground plane is here to catch things that are trying to drop to negative infinity |
137 | BulletShape groundPlaneShape = PhysicsScene.PE.CreateGroundPlaneShape(BSScene.GROUNDPLANE_ID, 1f, BSParam.TerrainCollisionMargin); | 137 | BulletShape groundPlaneShape = m_physicsScene.PE.CreateGroundPlaneShape(BSScene.GROUNDPLANE_ID, 1f, BSParam.TerrainCollisionMargin); |
138 | m_groundPlane = PhysicsScene.PE.CreateBodyWithDefaultMotionState(groundPlaneShape, | 138 | m_groundPlane = m_physicsScene.PE.CreateBodyWithDefaultMotionState(groundPlaneShape, |
139 | BSScene.GROUNDPLANE_ID, Vector3.Zero, Quaternion.Identity); | 139 | BSScene.GROUNDPLANE_ID, Vector3.Zero, Quaternion.Identity); |
140 | 140 | ||
141 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_groundPlane); | ||
142 | PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_groundPlane); | ||
143 | // Ground plane does not move | ||
144 | PhysicsScene.PE.ForceActivationState(m_groundPlane, ActivationState.DISABLE_SIMULATION); | ||
145 | // Everything collides with the ground plane. | 141 | // Everything collides with the ground plane. |
146 | m_groundPlane.collisionType = CollisionType.Groundplane; | 142 | m_groundPlane.collisionType = CollisionType.Groundplane; |
147 | m_groundPlane.ApplyCollisionMask(PhysicsScene); | ||
148 | 143 | ||
149 | BSTerrainPhys initialTerrain = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize); | 144 | m_physicsScene.PE.AddObjectToWorld(m_physicsScene.World, m_groundPlane); |
145 | m_physicsScene.PE.UpdateSingleAabb(m_physicsScene.World, m_groundPlane); | ||
146 | |||
147 | // Ground plane does not move | ||
148 | m_physicsScene.PE.ForceActivationState(m_groundPlane, ActivationState.DISABLE_SIMULATION); | ||
149 | |||
150 | BSTerrainPhys initialTerrain = new BSTerrainHeightmap(m_physicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize); | ||
150 | lock (m_terrains) | 151 | lock (m_terrains) |
151 | { | 152 | { |
152 | // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain. | 153 | // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain. |
@@ -157,12 +158,12 @@ public sealed class BSTerrainManager : IDisposable | |||
157 | // Release all the terrain structures we might have allocated | 158 | // Release all the terrain structures we might have allocated |
158 | public void ReleaseGroundPlaneAndTerrain() | 159 | public void ReleaseGroundPlaneAndTerrain() |
159 | { | 160 | { |
160 | DetailLog("{0},BSTerrainManager.ReleaseGroundPlaneAndTerrain,region={1}", BSScene.DetailLogZero, PhysicsScene.RegionName); | 161 | DetailLog("{0},BSTerrainManager.ReleaseGroundPlaneAndTerrain,region={1}", BSScene.DetailLogZero, m_physicsScene.RegionName); |
161 | if (m_groundPlane.HasPhysicalBody) | 162 | if (m_groundPlane.HasPhysicalBody) |
162 | { | 163 | { |
163 | if (PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_groundPlane)) | 164 | if (m_physicsScene.PE.RemoveObjectFromWorld(m_physicsScene.World, m_groundPlane)) |
164 | { | 165 | { |
165 | PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_groundPlane); | 166 | m_physicsScene.PE.DestroyObject(m_physicsScene.World, m_groundPlane); |
166 | } | 167 | } |
167 | m_groundPlane.Clear(); | 168 | m_groundPlane.Clear(); |
168 | } | 169 | } |
@@ -188,7 +189,7 @@ public sealed class BSTerrainManager : IDisposable | |||
188 | float[] localHeightMap = heightMap; | 189 | float[] localHeightMap = heightMap; |
189 | // If there are multiple requests for changes to the same terrain between ticks, | 190 | // If there are multiple requests for changes to the same terrain between ticks, |
190 | // only do that last one. | 191 | // only do that last one. |
191 | PhysicsScene.PostTaintObject("TerrainManager.SetTerrain-"+ m_worldOffset.ToString(), 0, delegate() | 192 | m_physicsScene.PostTaintObject("TerrainManager.SetTerrain-"+ m_worldOffset.ToString(), 0, delegate() |
192 | { | 193 | { |
193 | if (m_worldOffset != Vector3.Zero && MegaRegionParentPhysicsScene != null) | 194 | if (m_worldOffset != Vector3.Zero && MegaRegionParentPhysicsScene != null) |
194 | { | 195 | { |
@@ -199,15 +200,8 @@ public sealed class BSTerrainManager : IDisposable | |||
199 | if (MegaRegionParentPhysicsScene is BSScene) | 200 | if (MegaRegionParentPhysicsScene is BSScene) |
200 | { | 201 | { |
201 | DetailLog("{0},SetTerrain.ToParent,offset={1},worldMax={2}", BSScene.DetailLogZero, m_worldOffset, m_worldMax); | 202 | DetailLog("{0},SetTerrain.ToParent,offset={1},worldMax={2}", BSScene.DetailLogZero, m_worldOffset, m_worldMax); |
202 | // This looks really odd but this region is passing its terrain to its mega-region root region | 203 | ((BSScene)MegaRegionParentPhysicsScene).TerrainManager.AddMegaRegionChildTerrain( |
203 | // and the creation of the terrain must happen on the root region's taint thread and not | 204 | BSScene.CHILDTERRAIN_ID, localHeightMap, m_worldOffset, m_worldOffset + DefaultRegionSize); |
204 | // my taint thread. | ||
205 | ((BSScene)MegaRegionParentPhysicsScene).PostTaintObject("TerrainManager.SetTerrain.Mega-" + m_worldOffset.ToString(), 0, delegate() | ||
206 | { | ||
207 | ((BSScene)MegaRegionParentPhysicsScene).TerrainManager.UpdateTerrain( | ||
208 | BSScene.CHILDTERRAIN_ID, localHeightMap, | ||
209 | m_worldOffset, m_worldOffset + DefaultRegionSize, true /* inTaintTime */); | ||
210 | }); | ||
211 | } | 205 | } |
212 | } | 206 | } |
213 | else | 207 | else |
@@ -215,12 +209,23 @@ public sealed class BSTerrainManager : IDisposable | |||
215 | // If not doing the mega-prim thing, just change the terrain | 209 | // If not doing the mega-prim thing, just change the terrain |
216 | DetailLog("{0},SetTerrain.Existing", BSScene.DetailLogZero); | 210 | DetailLog("{0},SetTerrain.Existing", BSScene.DetailLogZero); |
217 | 211 | ||
218 | UpdateTerrain(BSScene.TERRAIN_ID, localHeightMap, | 212 | UpdateTerrain(BSScene.TERRAIN_ID, localHeightMap, m_worldOffset, m_worldOffset + DefaultRegionSize); |
219 | m_worldOffset, m_worldOffset + DefaultRegionSize, true /* inTaintTime */); | ||
220 | } | 213 | } |
221 | }); | 214 | }); |
222 | } | 215 | } |
223 | 216 | ||
217 | // Another region is calling this region and passing a terrain. | ||
218 | // A region that is not the mega-region root will pass its terrain to the root region so the root region | ||
219 | // physics engine will have all the terrains. | ||
220 | private void AddMegaRegionChildTerrain(uint id, float[] heightMap, Vector3 minCoords, Vector3 maxCoords) | ||
221 | { | ||
222 | // Since we are called by another region's thread, the action must be rescheduled onto our processing thread. | ||
223 | m_physicsScene.PostTaintObject("TerrainManager.AddMegaRegionChild" + minCoords.ToString(), id, delegate() | ||
224 | { | ||
225 | UpdateTerrain(id, heightMap, minCoords, maxCoords); | ||
226 | }); | ||
227 | } | ||
228 | |||
224 | // If called for terrain has has not been previously allocated, a new terrain will be built | 229 | // If called for terrain has has not been previously allocated, a new terrain will be built |
225 | // based on the passed information. The 'id' should be either the terrain id or | 230 | // based on the passed information. The 'id' should be either the terrain id or |
226 | // BSScene.CHILDTERRAIN_ID. If the latter, a new child terrain ID will be allocated and used. | 231 | // BSScene.CHILDTERRAIN_ID. If the latter, a new child terrain ID will be allocated and used. |
@@ -230,11 +235,10 @@ public sealed class BSTerrainManager : IDisposable | |||
230 | // This call is most often used to update the heightMap and parameters of the terrain. | 235 | // This call is most often used to update the heightMap and parameters of the terrain. |
231 | // (The above does suggest that some simplification/refactoring is in order.) | 236 | // (The above does suggest that some simplification/refactoring is in order.) |
232 | // Called during taint-time. | 237 | // Called during taint-time. |
233 | private void UpdateTerrain(uint id, float[] heightMap, | 238 | private void UpdateTerrain(uint id, float[] heightMap, Vector3 minCoords, Vector3 maxCoords) |
234 | Vector3 minCoords, Vector3 maxCoords, bool inTaintTime) | ||
235 | { | 239 | { |
236 | DetailLog("{0},BSTerrainManager.UpdateTerrain,call,id={1},minC={2},maxC={3},inTaintTime={4}", | 240 | DetailLog("{0},BSTerrainManager.UpdateTerrain,call,id={1},minC={2},maxC={3}", |
237 | BSScene.DetailLogZero, id, minCoords, maxCoords, inTaintTime); | 241 | BSScene.DetailLogZero, id, minCoords, maxCoords); |
238 | 242 | ||
239 | // Find high and low points of passed heightmap. | 243 | // Find high and low points of passed heightmap. |
240 | // The min and max passed in is usually the area objects can be in (maximum | 244 | // The min and max passed in is usually the area objects can be in (maximum |
@@ -303,7 +307,7 @@ public sealed class BSTerrainManager : IDisposable | |||
303 | newTerrainID = ++m_terrainCount; | 307 | newTerrainID = ++m_terrainCount; |
304 | 308 | ||
305 | DetailLog("{0},BSTerrainManager.UpdateTerrain:NewTerrain,taint,newID={1},minCoord={2},maxCoord={3}", | 309 | DetailLog("{0},BSTerrainManager.UpdateTerrain:NewTerrain,taint,newID={1},minCoord={2},maxCoord={3}", |
306 | BSScene.DetailLogZero, newTerrainID, minCoords, minCoords); | 310 | BSScene.DetailLogZero, newTerrainID, minCoords, maxCoords); |
307 | BSTerrainPhys newTerrainPhys = BuildPhysicalTerrain(terrainRegionBase, id, heightMap, minCoords, maxCoords); | 311 | BSTerrainPhys newTerrainPhys = BuildPhysicalTerrain(terrainRegionBase, id, heightMap, minCoords, maxCoords); |
308 | m_terrains.Add(terrainRegionBase, newTerrainPhys); | 312 | m_terrains.Add(terrainRegionBase, newTerrainPhys); |
309 | 313 | ||
@@ -315,26 +319,26 @@ public sealed class BSTerrainManager : IDisposable | |||
315 | // TODO: redo terrain implementation selection to allow other base types than heightMap. | 319 | // TODO: redo terrain implementation selection to allow other base types than heightMap. |
316 | private BSTerrainPhys BuildPhysicalTerrain(Vector3 terrainRegionBase, uint id, float[] heightMap, Vector3 minCoords, Vector3 maxCoords) | 320 | private BSTerrainPhys BuildPhysicalTerrain(Vector3 terrainRegionBase, uint id, float[] heightMap, Vector3 minCoords, Vector3 maxCoords) |
317 | { | 321 | { |
318 | PhysicsScene.Logger.DebugFormat("{0} Terrain for {1}/{2} created with {3}", | 322 | m_physicsScene.Logger.DebugFormat("{0} Terrain for {1}/{2} created with {3}", |
319 | LogHeader, PhysicsScene.RegionName, terrainRegionBase, | 323 | LogHeader, m_physicsScene.RegionName, terrainRegionBase, |
320 | (BSTerrainPhys.TerrainImplementation)BSParam.TerrainImplementation); | 324 | (BSTerrainPhys.TerrainImplementation)BSParam.TerrainImplementation); |
321 | BSTerrainPhys newTerrainPhys = null; | 325 | BSTerrainPhys newTerrainPhys = null; |
322 | switch ((int)BSParam.TerrainImplementation) | 326 | switch ((int)BSParam.TerrainImplementation) |
323 | { | 327 | { |
324 | case (int)BSTerrainPhys.TerrainImplementation.Heightmap: | 328 | case (int)BSTerrainPhys.TerrainImplementation.Heightmap: |
325 | newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, terrainRegionBase, id, | 329 | newTerrainPhys = new BSTerrainHeightmap(m_physicsScene, terrainRegionBase, id, |
326 | heightMap, minCoords, maxCoords); | 330 | heightMap, minCoords, maxCoords); |
327 | break; | 331 | break; |
328 | case (int)BSTerrainPhys.TerrainImplementation.Mesh: | 332 | case (int)BSTerrainPhys.TerrainImplementation.Mesh: |
329 | newTerrainPhys = new BSTerrainMesh(PhysicsScene, terrainRegionBase, id, | 333 | newTerrainPhys = new BSTerrainMesh(m_physicsScene, terrainRegionBase, id, |
330 | heightMap, minCoords, maxCoords); | 334 | heightMap, minCoords, maxCoords); |
331 | break; | 335 | break; |
332 | default: | 336 | default: |
333 | PhysicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. Type={1}/{2},Region={3}/{4}", | 337 | m_physicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. Type={1}/{2},Region={3}/{4}", |
334 | LogHeader, | 338 | LogHeader, |
335 | (int)BSParam.TerrainImplementation, | 339 | (int)BSParam.TerrainImplementation, |
336 | BSParam.TerrainImplementation, | 340 | BSParam.TerrainImplementation, |
337 | PhysicsScene.RegionName, terrainRegionBase); | 341 | m_physicsScene.RegionName, terrainRegionBase); |
338 | break; | 342 | break; |
339 | } | 343 | } |
340 | return newTerrainPhys; | 344 | return newTerrainPhys; |
@@ -351,6 +355,8 @@ public sealed class BSTerrainManager : IDisposable | |||
351 | // Return a new position that is over known terrain if the position is outside our terrain. | 355 | // Return a new position that is over known terrain if the position is outside our terrain. |
352 | public Vector3 ClampPositionIntoKnownTerrain(Vector3 pPos) | 356 | public Vector3 ClampPositionIntoKnownTerrain(Vector3 pPos) |
353 | { | 357 | { |
358 | float edgeEpsilon = 0.1f; | ||
359 | |||
354 | Vector3 ret = pPos; | 360 | Vector3 ret = pPos; |
355 | 361 | ||
356 | // First, base addresses are never negative so correct for that possible problem. | 362 | // First, base addresses are never negative so correct for that possible problem. |
@@ -375,10 +381,19 @@ public sealed class BSTerrainManager : IDisposable | |||
375 | // NOTE that GetTerrainPhysicalAtXYZ will set 'terrainBaseXYZ' to the base of the unfound region. | 381 | // NOTE that GetTerrainPhysicalAtXYZ will set 'terrainBaseXYZ' to the base of the unfound region. |
376 | 382 | ||
377 | // Must be off the top of a region. Find an adjacent region to move into. | 383 | // Must be off the top of a region. Find an adjacent region to move into. |
384 | // The returned terrain is always 'lower'. That is, closer to <0,0>. | ||
378 | Vector3 adjacentTerrainBase = FindAdjacentTerrainBase(terrainBaseXYZ); | 385 | Vector3 adjacentTerrainBase = FindAdjacentTerrainBase(terrainBaseXYZ); |
379 | 386 | ||
380 | ret.X = Math.Min(ret.X, adjacentTerrainBase.X + (ret.X % DefaultRegionSize.X)); | 387 | if (adjacentTerrainBase.X < terrainBaseXYZ.X) |
381 | ret.Y = Math.Min(ret.Y, adjacentTerrainBase.Y + (ret.X % DefaultRegionSize.Y)); | 388 | { |
389 | // moving down into a new region in the X dimension. New position will be the max in the new base. | ||
390 | ret.X = adjacentTerrainBase.X + DefaultRegionSize.X - edgeEpsilon; | ||
391 | } | ||
392 | if (adjacentTerrainBase.Y < terrainBaseXYZ.Y) | ||
393 | { | ||
394 | // moving down into a new region in the X dimension. New position will be the max in the new base. | ||
395 | ret.Y = adjacentTerrainBase.Y + DefaultRegionSize.Y - edgeEpsilon; | ||
396 | } | ||
382 | DetailLog("{0},BSTerrainManager.ClampPositionToKnownTerrain,findingAdjacentRegion,adjacentRegBase={1},oldPos={2},newPos={3}", | 397 | DetailLog("{0},BSTerrainManager.ClampPositionToKnownTerrain,findingAdjacentRegion,adjacentRegBase={1},oldPos={2},newPos={3}", |
383 | BSScene.DetailLogZero, adjacentTerrainBase, pPos, ret); | 398 | BSScene.DetailLogZero, adjacentTerrainBase, pPos, ret); |
384 | 399 | ||
@@ -426,8 +441,8 @@ public sealed class BSTerrainManager : IDisposable | |||
426 | } | 441 | } |
427 | else | 442 | else |
428 | { | 443 | { |
429 | PhysicsScene.Logger.ErrorFormat("{0} GetTerrainHeightAtXY: terrain not found: region={1}, x={2}, y={3}", | 444 | m_physicsScene.Logger.ErrorFormat("{0} GetTerrainHeightAtXY: terrain not found: region={1}, x={2}, y={3}", |
430 | LogHeader, PhysicsScene.RegionName, tX, tY); | 445 | LogHeader, m_physicsScene.RegionName, tX, tY); |
431 | DetailLog("{0},BSTerrainManager.GetTerrainHeightAtXYZ,terrainNotFound,pos={1},base={2}", | 446 | DetailLog("{0},BSTerrainManager.GetTerrainHeightAtXYZ,terrainNotFound,pos={1},base={2}", |
432 | BSScene.DetailLogZero, pos, terrainBaseXYZ); | 447 | BSScene.DetailLogZero, pos, terrainBaseXYZ); |
433 | } | 448 | } |
@@ -448,8 +463,8 @@ public sealed class BSTerrainManager : IDisposable | |||
448 | } | 463 | } |
449 | else | 464 | else |
450 | { | 465 | { |
451 | PhysicsScene.Logger.ErrorFormat("{0} GetWaterHeightAtXY: terrain not found: pos={1}, terrainBase={2}, height={3}", | 466 | m_physicsScene.Logger.ErrorFormat("{0} GetWaterHeightAtXY: terrain not found: pos={1}, terrainBase={2}, height={3}", |
452 | LogHeader, PhysicsScene.RegionName, pos, terrainBaseXYZ, ret); | 467 | LogHeader, m_physicsScene.RegionName, pos, terrainBaseXYZ, ret); |
453 | } | 468 | } |
454 | return ret; | 469 | return ret; |
455 | } | 470 | } |
@@ -561,7 +576,7 @@ public sealed class BSTerrainManager : IDisposable | |||
561 | 576 | ||
562 | private void DetailLog(string msg, params Object[] args) | 577 | private void DetailLog(string msg, params Object[] args) |
563 | { | 578 | { |
564 | PhysicsScene.PhysicsLogging.Write(msg, args); | 579 | m_physicsScene.PhysicsLogging.Write(msg, args); |
565 | } | 580 | } |
566 | } | 581 | } |
567 | } | 582 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs index 2ce1513..e4ca098 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs | |||
@@ -51,7 +51,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
51 | BulletShape m_terrainShape; | 51 | BulletShape m_terrainShape; |
52 | BulletBody m_terrainBody; | 52 | BulletBody m_terrainBody; |
53 | 53 | ||
54 | public BSTerrainMesh(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize) | 54 | public BSTerrainMesh(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize) |
55 | : base(physicsScene, regionBase, id) | 55 | : base(physicsScene, regionBase, id) |
56 | { | 56 | { |
57 | } | 57 | } |
@@ -62,7 +62,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
62 | } | 62 | } |
63 | 63 | ||
64 | // Create terrain mesh from a heightmap. | 64 | // Create terrain mesh from a heightmap. |
65 | public BSTerrainMesh(BSScene physicsScene, Vector3 regionBase, uint id, float[] initialMap, | 65 | public BSTerrainMesh(BSScene physicsScene, Vector3 regionBase, uint id, float[] initialMap, |
66 | Vector3 minCoords, Vector3 maxCoords) | 66 | Vector3 minCoords, Vector3 maxCoords) |
67 | : base(physicsScene, regionBase, id) | 67 | : base(physicsScene, regionBase, id) |
68 | { | 68 | { |
@@ -80,7 +80,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
80 | if (BSParam.TerrainMeshMagnification == 1) | 80 | if (BSParam.TerrainMeshMagnification == 1) |
81 | { | 81 | { |
82 | // If a magnification of one, use the old routine that is tried and true. | 82 | // If a magnification of one, use the old routine that is tried and true. |
83 | meshCreationSuccess = BSTerrainMesh.ConvertHeightmapToMesh(PhysicsScene, | 83 | meshCreationSuccess = BSTerrainMesh.ConvertHeightmapToMesh(m_physicsScene, |
84 | initialMap, m_sizeX, m_sizeY, // input size | 84 | initialMap, m_sizeX, m_sizeY, // input size |
85 | Vector3.Zero, // base for mesh | 85 | Vector3.Zero, // base for mesh |
86 | out indicesCount, out indices, out verticesCount, out vertices); | 86 | out indicesCount, out indices, out verticesCount, out vertices); |
@@ -88,7 +88,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
88 | else | 88 | else |
89 | { | 89 | { |
90 | // Other magnifications use the newer routine | 90 | // Other magnifications use the newer routine |
91 | meshCreationSuccess = BSTerrainMesh.ConvertHeightmapToMesh2(PhysicsScene, | 91 | meshCreationSuccess = BSTerrainMesh.ConvertHeightmapToMesh2(m_physicsScene, |
92 | initialMap, m_sizeX, m_sizeY, // input size | 92 | initialMap, m_sizeX, m_sizeY, // input size |
93 | BSParam.TerrainMeshMagnification, | 93 | BSParam.TerrainMeshMagnification, |
94 | physicsScene.TerrainManager.DefaultRegionSize, | 94 | physicsScene.TerrainManager.DefaultRegionSize, |
@@ -98,21 +98,21 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
98 | if (!meshCreationSuccess) | 98 | if (!meshCreationSuccess) |
99 | { | 99 | { |
100 | // DISASTER!! | 100 | // DISASTER!! |
101 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,failedConversionOfHeightmap,id={1}", BSScene.DetailLogZero, ID); | 101 | m_physicsScene.DetailLog("{0},BSTerrainMesh.create,failedConversionOfHeightmap,id={1}", BSScene.DetailLogZero, ID); |
102 | PhysicsScene.Logger.ErrorFormat("{0} Failed conversion of heightmap to mesh! base={1}", LogHeader, TerrainBase); | 102 | m_physicsScene.Logger.ErrorFormat("{0} Failed conversion of heightmap to mesh! base={1}", LogHeader, TerrainBase); |
103 | // Something is very messed up and a crash is in our future. | 103 | // Something is very messed up and a crash is in our future. |
104 | return; | 104 | return; |
105 | } | 105 | } |
106 | 106 | ||
107 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,meshed,id={1},indices={2},indSz={3},vertices={4},vertSz={5}", | 107 | m_physicsScene.DetailLog("{0},BSTerrainMesh.create,meshed,id={1},indices={2},indSz={3},vertices={4},vertSz={5}", |
108 | BSScene.DetailLogZero, ID, indicesCount, indices.Length, verticesCount, vertices.Length); | 108 | BSScene.DetailLogZero, ID, indicesCount, indices.Length, verticesCount, vertices.Length); |
109 | 109 | ||
110 | m_terrainShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, indicesCount, indices, verticesCount, vertices); | 110 | m_terrainShape = m_physicsScene.PE.CreateMeshShape(m_physicsScene.World, indicesCount, indices, verticesCount, vertices); |
111 | if (!m_terrainShape.HasPhysicalShape) | 111 | if (!m_terrainShape.HasPhysicalShape) |
112 | { | 112 | { |
113 | // DISASTER!! | 113 | // DISASTER!! |
114 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,failedCreationOfShape,id={1}", BSScene.DetailLogZero, ID); | 114 | m_physicsScene.DetailLog("{0},BSTerrainMesh.create,failedCreationOfShape,id={1}", BSScene.DetailLogZero, ID); |
115 | PhysicsScene.Logger.ErrorFormat("{0} Failed creation of terrain mesh! base={1}", LogHeader, TerrainBase); | 115 | m_physicsScene.Logger.ErrorFormat("{0} Failed creation of terrain mesh! base={1}", LogHeader, TerrainBase); |
116 | // Something is very messed up and a crash is in our future. | 116 | // Something is very messed up and a crash is in our future. |
117 | return; | 117 | return; |
118 | } | 118 | } |
@@ -120,52 +120,52 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
120 | Vector3 pos = regionBase; | 120 | Vector3 pos = regionBase; |
121 | Quaternion rot = Quaternion.Identity; | 121 | Quaternion rot = Quaternion.Identity; |
122 | 122 | ||
123 | m_terrainBody = PhysicsScene.PE.CreateBodyWithDefaultMotionState(m_terrainShape, ID, pos, rot); | 123 | m_terrainBody = m_physicsScene.PE.CreateBodyWithDefaultMotionState(m_terrainShape, ID, pos, rot); |
124 | if (!m_terrainBody.HasPhysicalBody) | 124 | if (!m_terrainBody.HasPhysicalBody) |
125 | { | 125 | { |
126 | // DISASTER!! | 126 | // DISASTER!! |
127 | PhysicsScene.Logger.ErrorFormat("{0} Failed creation of terrain body! base={1}", LogHeader, TerrainBase); | 127 | m_physicsScene.Logger.ErrorFormat("{0} Failed creation of terrain body! base={1}", LogHeader, TerrainBase); |
128 | // Something is very messed up and a crash is in our future. | 128 | // Something is very messed up and a crash is in our future. |
129 | return; | 129 | return; |
130 | } | 130 | } |
131 | physicsScene.PE.SetShapeCollisionMargin(m_terrainShape, BSParam.TerrainCollisionMargin); | 131 | physicsScene.PE.SetShapeCollisionMargin(m_terrainShape, BSParam.TerrainCollisionMargin); |
132 | 132 | ||
133 | // Set current terrain attributes | 133 | // Set current terrain attributes |
134 | PhysicsScene.PE.SetFriction(m_terrainBody, BSParam.TerrainFriction); | 134 | m_physicsScene.PE.SetFriction(m_terrainBody, BSParam.TerrainFriction); |
135 | PhysicsScene.PE.SetHitFraction(m_terrainBody, BSParam.TerrainHitFraction); | 135 | m_physicsScene.PE.SetHitFraction(m_terrainBody, BSParam.TerrainHitFraction); |
136 | PhysicsScene.PE.SetRestitution(m_terrainBody, BSParam.TerrainRestitution); | 136 | m_physicsScene.PE.SetRestitution(m_terrainBody, BSParam.TerrainRestitution); |
137 | PhysicsScene.PE.SetContactProcessingThreshold(m_terrainBody, BSParam.TerrainContactProcessingThreshold); | 137 | m_physicsScene.PE.SetContactProcessingThreshold(m_terrainBody, BSParam.TerrainContactProcessingThreshold); |
138 | PhysicsScene.PE.SetCollisionFlags(m_terrainBody, CollisionFlags.CF_STATIC_OBJECT); | 138 | m_physicsScene.PE.SetCollisionFlags(m_terrainBody, CollisionFlags.CF_STATIC_OBJECT); |
139 | 139 | ||
140 | // Static objects are not very massive. | 140 | // Static objects are not very massive. |
141 | PhysicsScene.PE.SetMassProps(m_terrainBody, 0f, Vector3.Zero); | 141 | m_physicsScene.PE.SetMassProps(m_terrainBody, 0f, Vector3.Zero); |
142 | 142 | ||
143 | // Put the new terrain to the world of physical objects | 143 | // Put the new terrain to the world of physical objects |
144 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_terrainBody); | 144 | m_physicsScene.PE.AddObjectToWorld(m_physicsScene.World, m_terrainBody); |
145 | 145 | ||
146 | // Redo its bounding box now that it is in the world | 146 | // Redo its bounding box now that it is in the world |
147 | PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_terrainBody); | 147 | m_physicsScene.PE.UpdateSingleAabb(m_physicsScene.World, m_terrainBody); |
148 | 148 | ||
149 | m_terrainBody.collisionType = CollisionType.Terrain; | 149 | m_terrainBody.collisionType = CollisionType.Terrain; |
150 | m_terrainBody.ApplyCollisionMask(PhysicsScene); | 150 | m_terrainBody.ApplyCollisionMask(m_physicsScene); |
151 | 151 | ||
152 | if (BSParam.UseSingleSidedMeshes) | 152 | if (BSParam.UseSingleSidedMeshes) |
153 | { | 153 | { |
154 | PhysicsScene.DetailLog("{0},BSTerrainMesh.settingCustomMaterial,id={1}", BSScene.DetailLogZero, id); | 154 | m_physicsScene.DetailLog("{0},BSTerrainMesh.settingCustomMaterial,id={1}", BSScene.DetailLogZero, id); |
155 | PhysicsScene.PE.AddToCollisionFlags(m_terrainBody, CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK); | 155 | m_physicsScene.PE.AddToCollisionFlags(m_terrainBody, CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK); |
156 | } | 156 | } |
157 | 157 | ||
158 | // Make it so the terrain will not move or be considered for movement. | 158 | // Make it so the terrain will not move or be considered for movement. |
159 | PhysicsScene.PE.ForceActivationState(m_terrainBody, ActivationState.DISABLE_SIMULATION); | 159 | m_physicsScene.PE.ForceActivationState(m_terrainBody, ActivationState.DISABLE_SIMULATION); |
160 | } | 160 | } |
161 | 161 | ||
162 | public override void Dispose() | 162 | public override void Dispose() |
163 | { | 163 | { |
164 | if (m_terrainBody.HasPhysicalBody) | 164 | if (m_terrainBody.HasPhysicalBody) |
165 | { | 165 | { |
166 | PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_terrainBody); | 166 | m_physicsScene.PE.RemoveObjectFromWorld(m_physicsScene.World, m_terrainBody); |
167 | // Frees both the body and the shape. | 167 | // Frees both the body and the shape. |
168 | PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_terrainBody); | 168 | m_physicsScene.PE.DestroyObject(m_physicsScene.World, m_terrainBody); |
169 | m_terrainBody.Clear(); | 169 | m_terrainBody.Clear(); |
170 | m_terrainShape.Clear(); | 170 | m_terrainShape.Clear(); |
171 | } | 171 | } |
@@ -185,7 +185,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
185 | catch | 185 | catch |
186 | { | 186 | { |
187 | // Sometimes they give us wonky values of X and Y. Give a warning and return something. | 187 | // Sometimes they give us wonky values of X and Y. Give a warning and return something. |
188 | PhysicsScene.Logger.WarnFormat("{0} Bad request for terrain height. terrainBase={1}, pos={2}", | 188 | m_physicsScene.Logger.WarnFormat("{0} Bad request for terrain height. terrainBase={1}, pos={2}", |
189 | LogHeader, TerrainBase, pos); | 189 | LogHeader, TerrainBase, pos); |
190 | ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET; | 190 | ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET; |
191 | } | 191 | } |
@@ -195,7 +195,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
195 | // The passed position is relative to the base of the region. | 195 | // The passed position is relative to the base of the region. |
196 | public override float GetWaterLevelAtXYZ(Vector3 pos) | 196 | public override float GetWaterLevelAtXYZ(Vector3 pos) |
197 | { | 197 | { |
198 | return PhysicsScene.SimpleWaterLevel; | 198 | return m_physicsScene.SimpleWaterLevel; |
199 | } | 199 | } |
200 | 200 | ||
201 | // Convert the passed heightmap to mesh information suitable for CreateMeshShape2(). | 201 | // Convert the passed heightmap to mesh information suitable for CreateMeshShape2(). |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs index 8012d91..971ff9f 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs | |||
@@ -104,11 +104,11 @@ public class BulletShape | |||
104 | { | 104 | { |
105 | public BulletShape() | 105 | public BulletShape() |
106 | { | 106 | { |
107 | type = BSPhysicsShapeType.SHAPE_UNKNOWN; | 107 | shapeType = BSPhysicsShapeType.SHAPE_UNKNOWN; |
108 | shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; | 108 | shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; |
109 | isNativeShape = false; | 109 | isNativeShape = false; |
110 | } | 110 | } |
111 | public BSPhysicsShapeType type; | 111 | public BSPhysicsShapeType shapeType; |
112 | public System.UInt64 shapeKey; | 112 | public System.UInt64 shapeKey; |
113 | public bool isNativeShape; | 113 | public bool isNativeShape; |
114 | 114 | ||
@@ -133,7 +133,7 @@ public class BulletShape | |||
133 | buff.Append("<p="); | 133 | buff.Append("<p="); |
134 | buff.Append(AddrString); | 134 | buff.Append(AddrString); |
135 | buff.Append(",s="); | 135 | buff.Append(",s="); |
136 | buff.Append(type.ToString()); | 136 | buff.Append(shapeType.ToString()); |
137 | buff.Append(",k="); | 137 | buff.Append(",k="); |
138 | buff.Append(shapeKey.ToString("X")); | 138 | buff.Append(shapeKey.ToString("X")); |
139 | buff.Append(",n="); | 139 | buff.Append(",n="); |
@@ -224,42 +224,43 @@ public static class BulletSimData | |||
224 | // As mentioned above, don't use the CollisionFilterGroups definitions directly in the code | 224 | // As mentioned above, don't use the CollisionFilterGroups definitions directly in the code |
225 | // but, instead, use references to this dictionary. Finding and debugging | 225 | // but, instead, use references to this dictionary. Finding and debugging |
226 | // collision flag problems will be made easier. | 226 | // collision flag problems will be made easier. |
227 | public static Dictionary<CollisionType, CollisionTypeFilterGroup> CollisionTypeMasks | 227 | public static Dictionary<CollisionType, CollisionTypeFilterGroup> CollisionTypeMasks |
228 | = new Dictionary<CollisionType, CollisionTypeFilterGroup>() | 228 | = new Dictionary<CollisionType, CollisionTypeFilterGroup>() |
229 | { | 229 | { |
230 | { CollisionType.Avatar, | 230 | { CollisionType.Avatar, |
231 | new CollisionTypeFilterGroup(CollisionType.Avatar, | 231 | new CollisionTypeFilterGroup(CollisionType.Avatar, |
232 | (uint)CollisionFilterGroups.BCharacterGroup, | 232 | (uint)CollisionFilterGroups.BCharacterGroup, |
233 | (uint)CollisionFilterGroups.BAllGroup) | 233 | (uint)CollisionFilterGroups.BAllGroup) |
234 | }, | 234 | }, |
235 | { CollisionType.Groundplane, | 235 | { CollisionType.Groundplane, |
236 | new CollisionTypeFilterGroup(CollisionType.Groundplane, | 236 | new CollisionTypeFilterGroup(CollisionType.Groundplane, |
237 | (uint)CollisionFilterGroups.BGroundPlaneGroup, | 237 | (uint)CollisionFilterGroups.BGroundPlaneGroup, |
238 | (uint)CollisionFilterGroups.BAllGroup) | 238 | // (uint)CollisionFilterGroups.BAllGroup) |
239 | (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup)) | ||
239 | }, | 240 | }, |
240 | { CollisionType.Terrain, | 241 | { CollisionType.Terrain, |
241 | new CollisionTypeFilterGroup(CollisionType.Terrain, | 242 | new CollisionTypeFilterGroup(CollisionType.Terrain, |
242 | (uint)CollisionFilterGroups.BTerrainGroup, | 243 | (uint)CollisionFilterGroups.BTerrainGroup, |
243 | (uint)(CollisionFilterGroups.BAllGroup & ~CollisionFilterGroups.BStaticGroup)) | 244 | (uint)(CollisionFilterGroups.BAllGroup & ~CollisionFilterGroups.BStaticGroup)) |
244 | }, | 245 | }, |
245 | { CollisionType.Static, | 246 | { CollisionType.Static, |
246 | new CollisionTypeFilterGroup(CollisionType.Static, | 247 | new CollisionTypeFilterGroup(CollisionType.Static, |
247 | (uint)CollisionFilterGroups.BStaticGroup, | 248 | (uint)CollisionFilterGroups.BStaticGroup, |
248 | (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup)) | 249 | (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup)) |
249 | }, | 250 | }, |
250 | { CollisionType.Dynamic, | 251 | { CollisionType.Dynamic, |
251 | new CollisionTypeFilterGroup(CollisionType.Dynamic, | 252 | new CollisionTypeFilterGroup(CollisionType.Dynamic, |
252 | (uint)CollisionFilterGroups.BSolidGroup, | 253 | (uint)CollisionFilterGroups.BSolidGroup, |
253 | (uint)(CollisionFilterGroups.BAllGroup)) | 254 | (uint)(CollisionFilterGroups.BAllGroup)) |
254 | }, | 255 | }, |
255 | { CollisionType.VolumeDetect, | 256 | { CollisionType.VolumeDetect, |
256 | new CollisionTypeFilterGroup(CollisionType.VolumeDetect, | 257 | new CollisionTypeFilterGroup(CollisionType.VolumeDetect, |
257 | (uint)CollisionFilterGroups.BSensorTrigger, | 258 | (uint)CollisionFilterGroups.BSensorTrigger, |
258 | (uint)(~CollisionFilterGroups.BSensorTrigger)) | 259 | (uint)(~CollisionFilterGroups.BSensorTrigger)) |
259 | }, | 260 | }, |
260 | { CollisionType.LinksetChild, | 261 | { CollisionType.LinksetChild, |
261 | new CollisionTypeFilterGroup(CollisionType.LinksetChild, | 262 | new CollisionTypeFilterGroup(CollisionType.LinksetChild, |
262 | (uint)CollisionFilterGroups.BLinksetChildGroup, | 263 | (uint)CollisionFilterGroups.BLinksetChildGroup, |
263 | (uint)(CollisionFilterGroups.BNoneGroup)) | 264 | (uint)(CollisionFilterGroups.BNoneGroup)) |
264 | // (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup)) | 265 | // (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup)) |
265 | }, | 266 | }, |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index 8a15abe..0453376 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt | |||
@@ -1,65 +1,61 @@ | |||
1 | CURRENT PRIORITIES | 1 | CURRENT PROBLEMS TO FIX AND/OR LOOK AT |
2 | ================================================= | 2 | ================================================= |
3 | Use the HACD convex hull routine in Bullet rather than the C# version. | 3 | Vehicle buoyancy. Computed correctly? Possibly creating very large effective mass. |
4 | Speed up hullifying large meshes. | 4 | Interaction of llSetBuoyancy and vehicle buoyancy. Should be additive? |
5 | Negative buoyancy computed correctly | ||
6 | Center-of-gravity | ||
7 | Computation of mesh mass. How done? How should it be done? | ||
5 | Enable vehicle border crossings (at least as poorly as ODE) | 8 | Enable vehicle border crossings (at least as poorly as ODE) |
6 | Terrain skirts | 9 | Terrain skirts |
7 | Avatar created in previous region and not new region when crossing border | 10 | Avatar created in previous region and not new region when crossing border |
8 | Vehicle recreated in new sim at small Z value (offset from root value?) (DONE) | 11 | Vehicle recreated in new sim at small Z value (offset from root value?) (DONE) |
9 | Lock axis | 12 | User settable terrain mesh |
13 | Allow specifying as convex or concave and use different getHeight functions depending | ||
14 | Boats, when turning nose down into the water | ||
15 | Acts like rotation around Z is also effecting rotation around X and Y | ||
10 | Deleting a linkset while standing on the root will leave the physical shape of the root behind. | 16 | Deleting a linkset while standing on the root will leave the physical shape of the root behind. |
11 | Not sure if it is because standing on it. Done with large prim linksets. | 17 | Not sure if it is because standing on it. Done with large prim linksets. |
12 | Linkset child rotations. | 18 | Linkset child rotations. |
13 | Nebadon spiral tube has middle sections which are rotated wrong. | 19 | Nebadon spiral tube has middle sections which are rotated wrong. |
14 | Select linked spiral tube. Delink and note where the middle section ends up. | 20 | Select linked spiral tube. Delink and note where the middle section ends up. |
15 | Vehicle angular vertical attraction | ||
16 | vehicle angular banking | ||
17 | Center-of-gravity | ||
18 | Vehicle angular deflection | ||
19 | Preferred orientation angular correction fix | ||
20 | when should angular and linear motor targets be zeroed? when selected? | ||
21 | Need a vehicle.clear()? Or an 'else' in prestep if not physical. | ||
22 | Teravus llMoveToTarget script debug | 21 | Teravus llMoveToTarget script debug |
23 | Mixing of hover, buoyancy/gravity, moveToTarget, into one force | 22 | Mixing of hover, buoyancy/gravity, moveToTarget, into one force |
24 | Setting hover height to zero disables hover even if hover flags are on (from SL wiki) | 23 | Setting hover height to zero disables hover even if hover flags are on (from SL wiki) |
25 | limitMotorUp calibration (more down?) | 24 | limitMotorUp calibration (more down?) |
26 | llRotLookAt | 25 | llRotLookAt |
27 | llLookAt | 26 | llLookAt |
28 | Avatars walking up stairs (HALF DONE) | 27 | Convert to avatar mesh capsule. Include rotation of capsule. |
29 | Avatar movement | ||
30 | flying into a wall doesn't stop avatar who keeps appearing to move through the obstacle (DONE) | ||
31 | walking up stairs is not calibrated correctly (stairs out of Kepler cabin) | ||
32 | avatar capsule rotation completed (NOT DONE - Bullet's capsule shape is not the solution) | ||
33 | Vehicle script tuning/debugging | 28 | Vehicle script tuning/debugging |
34 | Avanti speed script | 29 | Avanti speed script |
35 | Weapon shooter script | 30 | Weapon shooter script |
36 | Move material definitions (friction, ...) into simulator. | 31 | Move material definitions (friction, ...) into simulator. |
37 | Add material densities to the material types. | 32 | osGetPhysicsEngineVerion() and create a version code for the C++ DLL |
38 | Terrain detail: double terrain mesh detail | ||
39 | One sided meshes? Should terrain be built into a closed shape? | 33 | One sided meshes? Should terrain be built into a closed shape? |
40 | When meshes get partially wedged into the terrain, they cannot push themselves out. | 34 | When meshes get partially wedged into the terrain, they cannot push themselves out. |
41 | It is possible that Bullet processes collisions whether entering or leaving a mesh. | 35 | It is possible that Bullet processes collisions whether entering or leaving a mesh. |
42 | Ref: http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4869 | 36 | Ref: http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4869 |
37 | Small physical objects do not interact correctly | ||
38 | Create chain of .5x.5x.1 torui and make all but top physical so to hang. | ||
39 | The chain will fall apart and pairs will dance around on ground | ||
40 | Chains of 1x1x.2 will stay connected but will dance. | ||
41 | Chains above 2x2x.4 are more stable and get stablier as torui get larger. | ||
43 | 42 | ||
44 | VEHICLES TODO LIST: | 43 | VEHICLES TODO LIST: |
45 | ================================================= | 44 | ================================================= |
46 | Border crossing with linked vehicle causes crash | 45 | LINEAR_MOTOR_DIRECTION values should be clamped to reasonable numbers. |
47 | 20121129.1411: editting/moving phys object across region boundries causes crash | 46 | What are the limits in SL? |
48 | getPos-> btRigidBody::upcast -> getBodyType -> BOOM | 47 | Same for other velocity settings. |
49 | Vehicles (Move smoothly) | 48 | UBit improvements to remove rubber-banding of avatars sitting on vehicle child prims: |
49 | https://github.com/UbitUmarov/Ubit-opensim | ||
50 | Some vehicles should not be able to turn if no speed or off ground. | 50 | Some vehicles should not be able to turn if no speed or off ground. |
51 | What to do if vehicle and prim buoyancy differ? | ||
52 | Cannot edit/move a vehicle being ridden: it jumps back to the origional position. | 51 | Cannot edit/move a vehicle being ridden: it jumps back to the origional position. |
53 | Neb car jiggling left and right | 52 | Neb car jiggling left and right |
54 | Happens on terrain and any other mesh object. Flat cubes are much smoother. | 53 | Happens on terrain and any other mesh object. Flat cubes are much smoother. |
55 | This has been reduced but not eliminated. | 54 | This has been reduced but not eliminated. |
56 | Implement referenceFrame for all the motion routines. | 55 | Implement referenceFrame for all the motion routines. |
57 | For limitMotorUp, use raycast down to find if vehicle is in the air. | ||
58 | Verify llGetVel() is returning a smooth and good value for vehicle movement. | 56 | Verify llGetVel() is returning a smooth and good value for vehicle movement. |
59 | llGetVel() should return the root's velocity if requested in a child prim. | 57 | llGetVel() should return the root's velocity if requested in a child prim. |
60 | Implement function efficiency for lineaar and angular motion. | 58 | Implement function efficiency for lineaar and angular motion. |
61 | After getting off a vehicle, the root prim is phantom (can be walked through) | ||
62 | Need to force a position update for the root prim after compound shape destruction | ||
63 | Linkset explosion after three "rides" on Nebadon lite vehicle (LinksetConstraint) | 59 | Linkset explosion after three "rides" on Nebadon lite vehicle (LinksetConstraint) |
64 | Remove vehicle angular velocity zeroing in BSPrim.UpdateProperties(). | 60 | Remove vehicle angular velocity zeroing in BSPrim.UpdateProperties(). |
65 | A kludge that isn't fixing the real problem of Bullet adding extra motion. | 61 | A kludge that isn't fixing the real problem of Bullet adding extra motion. |
@@ -68,11 +64,10 @@ Incorporate inter-relationship of angular corrections. For instance, angularDefl | |||
68 | creates over-correction and over-shoot and wabbling. | 64 | creates over-correction and over-shoot and wabbling. |
69 | Vehicle attributes are not restored when a vehicle is rezzed on region creation | 65 | Vehicle attributes are not restored when a vehicle is rezzed on region creation |
70 | Create vehicle, setup vehicle properties, restart region, vehicle is not reinitialized. | 66 | Create vehicle, setup vehicle properties, restart region, vehicle is not reinitialized. |
67 | What to do if vehicle and prim buoyancy differ? | ||
71 | 68 | ||
72 | GENERAL TODO LIST: | 69 | GENERAL TODO LIST: |
73 | ================================================= | 70 | ================================================= |
74 | Explore btGImpactMeshShape as alternative to convex hulls for simplified physical objects. | ||
75 | Regular triangle meshes don't do physical collisions. | ||
76 | Resitution of a prim works on another prim but not on terrain. | 71 | Resitution of a prim works on another prim but not on terrain. |
77 | The dropped prim doesn't bounce properly on the terrain. | 72 | The dropped prim doesn't bounce properly on the terrain. |
78 | Add a sanity check for PIDTarget location. | 73 | Add a sanity check for PIDTarget location. |
@@ -98,29 +93,15 @@ Revisit CollisionMargin. Builders notice the 0.04 spacing between prims. | |||
98 | Duplicating a physical prim causes old prim to jump away | 93 | Duplicating a physical prim causes old prim to jump away |
99 | Dup a phys prim and the original become unselected and thus interacts w/ selected prim. | 94 | Dup a phys prim and the original become unselected and thus interacts w/ selected prim. |
100 | Scenes with hundred of thousands of static objects take a lot of physics CPU time. | 95 | Scenes with hundred of thousands of static objects take a lot of physics CPU time. |
101 | BSPrim.Force should set a continious force on the prim. The force should be | ||
102 | applied each tick. Some limits? | ||
103 | Gun sending shooter flying. | 96 | Gun sending shooter flying. |
104 | Collision margin (gap between physical objects lying on each other) | 97 | Collision margin (gap between physical objects lying on each other) |
105 | Boundry checking (crashes related to crossing boundry) | 98 | Boundry checking (crashes related to crossing boundry) |
106 | Add check for border edge position for avatars and objects. | 99 | Add check for border edge position for avatars and objects. |
107 | Verify the events are created for border crossings. | 100 | Verify the events are created for border crossings. |
108 | Avatar rotation (check out changes to ScenePresence for physical rotation) | ||
109 | Avatar running (what does phys engine need to do?) | ||
110 | Small physical objects do not interact correctly | ||
111 | Create chain of .5x.5x.1 torui and make all but top physical so to hang. | ||
112 | The chain will fall apart and pairs will dance around on ground | ||
113 | Chains of 1x1x.2 will stay connected but will dance. | ||
114 | Chains above 2x2x.4 are more stable and get stablier as torui get larger. | ||
115 | Add PID motor for avatar movement (slow to stop, ...) | ||
116 | setForce should set a constant force. Different than AddImpulse. | ||
117 | Implement raycast. | ||
118 | Implement ShapeCollection.Dispose() | 101 | Implement ShapeCollection.Dispose() |
119 | Implement water as a plain so raycasting and collisions can happen with same. | 102 | Implement water as a plain or mesh so raycasting and collisions can happen with same. |
120 | Add collision penetration return | 103 | Add collision penetration return |
121 | Add field passed back by BulletSim.dll and fill with info in ManifoldConstact.GetDistance() | 104 | Add field passed back by BulletSim.dll and fill with info in ManifoldConstact.GetDistance() |
122 | Add osGetPhysicsEngineName() so scripters can tell whether BulletSim or ODE | ||
123 | Also osGetPhysicsEngineVerion() maybe. | ||
124 | Linkset.Position and Linkset.Orientation requre rewrite to properly return | 105 | Linkset.Position and Linkset.Orientation requre rewrite to properly return |
125 | child position. LinksetConstraint acts like it's at taint time!! | 106 | child position. LinksetConstraint acts like it's at taint time!! |
126 | Implement LockAngularMotion -- implements llSetStatus(ROTATE_AXIS_*, T/F) | 107 | Implement LockAngularMotion -- implements llSetStatus(ROTATE_AXIS_*, T/F) |
@@ -132,9 +113,6 @@ Selecting and deselecting physical objects causes CPU processing time to jump | |||
132 | Re-implement buoyancy as a separate force on the object rather than diddling gravity. | 113 | Re-implement buoyancy as a separate force on the object rather than diddling gravity. |
133 | Register a pre-step event to add the force. | 114 | Register a pre-step event to add the force. |
134 | More efficient memory usage when passing hull information from BSPrim to BulletSim | 115 | More efficient memory usage when passing hull information from BSPrim to BulletSim |
135 | Avatar movement motor check for zero or small movement. Somehow suppress small movements | ||
136 | when avatar has stopped and is just standing. Simple test for near zero has | ||
137 | the problem of preventing starting up (increase from zero) especially when falling. | ||
138 | Physical and phantom will drop through the terrain | 116 | Physical and phantom will drop through the terrain |
139 | 117 | ||
140 | 118 | ||
@@ -168,6 +146,7 @@ Eliminate collisions between objects in a linkset. (LinksetConstraint) | |||
168 | 146 | ||
169 | MORE | 147 | MORE |
170 | ====================================================== | 148 | ====================================================== |
149 | Compute avatar size and scale correctly. Now it is a bit off from the capsule size. | ||
171 | Create tests for different interface components | 150 | Create tests for different interface components |
172 | Have test objects/scripts measure themselves and turn color if correct/bad | 151 | Have test objects/scripts measure themselves and turn color if correct/bad |
173 | Test functions in SL and calibrate correctness there | 152 | Test functions in SL and calibrate correctness there |
@@ -176,7 +155,6 @@ Do we need to do convex hulls all the time? Can complex meshes be left meshes? | |||
176 | There is some problem with meshes and collisions | 155 | There is some problem with meshes and collisions |
177 | Hulls are not as detailed as meshes. Hulled vehicles insides are different shape. | 156 | Hulls are not as detailed as meshes. Hulled vehicles insides are different shape. |
178 | Debounce avatar contact so legs don't keep folding up when standing. | 157 | Debounce avatar contact so legs don't keep folding up when standing. |
179 | Implement LSL physics controls. Like STATUS_ROTATE_X. | ||
180 | Add border extensions to terrain to help region crossings and objects leaving region. | 158 | Add border extensions to terrain to help region crossings and objects leaving region. |
181 | Use a different capsule shape for avatar when sitting | 159 | Use a different capsule shape for avatar when sitting |
182 | LL uses a pyrimidal shape scaled by the avatar's bounding box | 160 | LL uses a pyrimidal shape scaled by the avatar's bounding box |
@@ -209,8 +187,6 @@ Keep avatar scaling correct. http://pennycow.blogspot.fr/2011/07/matter-of-scale | |||
209 | 187 | ||
210 | INTERNAL IMPROVEMENT/CLEANUP | 188 | INTERNAL IMPROVEMENT/CLEANUP |
211 | ================================================= | 189 | ================================================= |
212 | Can the 'inTaintTime' flag be cleaned up and used? For instance, a call to | ||
213 | BSScene.TaintedObject() could immediately execute the callback if already in taint time. | ||
214 | Create the physical wrapper classes (BulletBody, BulletShape) by methods on | 190 | Create the physical wrapper classes (BulletBody, BulletShape) by methods on |
215 | BSAPITemplate and make their actual implementation Bullet engine specific. | 191 | BSAPITemplate and make their actual implementation Bullet engine specific. |
216 | For the short term, just call the existing functions in ShapeCollection. | 192 | For the short term, just call the existing functions in ShapeCollection. |
@@ -344,3 +320,60 @@ Angular motion around Z moves the vehicle in world Z and not vehicle Z in ODE. | |||
344 | Verify that angular motion specified around Z moves in the vehicle coordinates. | 320 | Verify that angular motion specified around Z moves in the vehicle coordinates. |
345 | DONE 20130120: BulletSim properly applies force in vehicle relative coordinates. | 321 | DONE 20130120: BulletSim properly applies force in vehicle relative coordinates. |
346 | Nebadon vehicles turning funny in arena (DONE) | 322 | Nebadon vehicles turning funny in arena (DONE) |
323 | Lock axis (DONE 20130401) | ||
324 | Terrain detail: double terrain mesh detail (DONE) | ||
325 | Use the HACD convex hull routine in Bullet rather than the C# version. | ||
326 | Speed up hullifying large meshes. (DONE) | ||
327 | Vehicle ride, get up, ride again. Second time vehicle does not act correctly. | ||
328 | Have to rez new vehicle and delete the old to fix situation. | ||
329 | (DONE 20130520: normalize rotations) | ||
330 | Hitting RESET on Nebadon's vehicle while riding causes vehicle to get into odd | ||
331 | position state where it will not settle onto ground properly, etc | ||
332 | (DONE 20130520: normalize rotations) | ||
333 | Two of Nebadon vehicles in a sim max the CPU. This is new. | ||
334 | (DONE 20130520: two problems: if asset failed to mesh, constantly refetched | ||
335 | asset; vehicle was sending too many messages to all linkset members) | ||
336 | Add material densities to the material types. (WILL NOT BE DONE: not how it is done) | ||
337 | Avatars walking up stairs (DONE) | ||
338 | Avatar movement | ||
339 | flying into a wall doesn't stop avatar who keeps appearing to move through the obstacle (DONE) | ||
340 | walking up stairs is not calibrated correctly (stairs out of Kepler cabin) (DONE) | ||
341 | avatar capsule rotation completed (NOT DONE - Bullet's capsule shape is not the solution) | ||
342 | After getting off a vehicle, the root prim is phantom (can be walked through) | ||
343 | Need to force a position update for the root prim after compound shape destruction | ||
344 | (DONE) | ||
345 | Explore btGImpactMeshShape as alternative to convex hulls for simplified physical objects. | ||
346 | Regular triangle meshes don't do physical collisions. | ||
347 | (DONE: discovered GImpact is VERY CPU intensive) | ||
348 | Script changing rotation of child prim while vehicle moving (eg turning wheel) causes | ||
349 | the wheel to appear to jump back. Looks like sending position from previous update. | ||
350 | (DONE: redo of compound linksets fixed problem) | ||
351 | Refarb compound linkset creation to create a pseudo-root for center-of-mass | ||
352 | Let children change their shape to physical indendently and just add shapes to compound | ||
353 | (DONE: redo of compound linkset fixed problem) | ||
354 | Vehicle angular vertical attraction (DONE: vegaslon code) | ||
355 | vehicle angular banking (DONE: vegaslon code) | ||
356 | Vehicle angular deflection (DONE: vegaslon code) | ||
357 | Preferred orientation angular correction fix | ||
358 | Vehicles (Move smoothly) | ||
359 | For limitMotorUp, use raycast down to find if vehicle is in the air. | ||
360 | (WILL NOT BE DONE: gravity does the job well enough) | ||
361 | BSPrim.Force should set a continious force on the prim. The force should be | ||
362 | applied each tick. Some limits? | ||
363 | (DONE: added physical actors. Implemented SetForce, SetTorque, ...) | ||
364 | Implement LSL physics controls. Like STATUS_ROTATE_X. (DONE) | ||
365 | Add osGetPhysicsEngineName() so scripters can tell whether BulletSim or ODE | ||
366 | Avatar rotation (check out changes to ScenePresence for physical rotation) (DONE) | ||
367 | Avatar running (what does phys engine need to do?) (DONE: multiplies run factor by walking force) | ||
368 | setForce should set a constant force. Different than AddImpulse. (DONE) | ||
369 | Add PID motor for avatar movement (slow to stop, ...) (WNBD: current works ok) | ||
370 | Avatar movement motor check for zero or small movement. Somehow suppress small movements | ||
371 | when avatar has stopped and is just standing. Simple test for near zero has | ||
372 | the problem of preventing starting up (increase from zero) especially when falling. | ||
373 | (DONE: avatar movement actor knows if standing on stationary object and zeros motion) | ||
374 | Can the 'inTaintTime' flag be cleaned up and used? For instance, a call to | ||
375 | BSScene.TaintedObject() could immediately execute the callback if already in taint time. | ||
376 | (DONE) | ||
377 | |||
378 | |||
379 | |||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/Properties/AssemblyInfo.cs b/OpenSim/Region/Physics/BulletSPlugin/Properties/AssemblyInfo.cs index 02b03a8..d069178 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/Properties/AssemblyInfo.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/Properties/AssemblyInfo.cs | |||
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices; | |||
29 | // Build Number | 29 | // Build Number |
30 | // Revision | 30 | // Revision |
31 | // | 31 | // |
32 | [assembly: AssemblyVersion("0.7.6.*")] | 32 | [assembly: AssemblyVersion("0.8.0.*")] |
33 | 33 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs b/OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs index 33232bd..48e74eb 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs | |||
@@ -57,6 +57,8 @@ public class BasicVehicles : OpenSimTestCase | |||
57 | public void Init() | 57 | public void Init() |
58 | { | 58 | { |
59 | Dictionary<string, string> engineParams = new Dictionary<string, string>(); | 59 | Dictionary<string, string> engineParams = new Dictionary<string, string>(); |
60 | engineParams.Add("VehicleEnableAngularVerticalAttraction", "true"); | ||
61 | engineParams.Add("VehicleAngularVerticalAttractionAlgorithm", "1"); | ||
60 | PhysicsScene = BulletSimTestsUtil.CreateBasicPhysicsEngine(engineParams); | 62 | PhysicsScene = BulletSimTestsUtil.CreateBasicPhysicsEngine(engineParams); |
61 | 63 | ||
62 | PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateSphere(); | 64 | PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateSphere(); |
@@ -114,21 +116,25 @@ public class BasicVehicles : OpenSimTestCase | |||
114 | // Instead the appropriate values are set and calls are made just the parts of the | 116 | // Instead the appropriate values are set and calls are made just the parts of the |
115 | // controller we want to exercise. Stepping the physics engine then applies | 117 | // controller we want to exercise. Stepping the physics engine then applies |
116 | // the actions of that one feature. | 118 | // the actions of that one feature. |
117 | TestVehicle.VehicleController.ProcessFloatVehicleParam(Vehicle.VERTICAL_ATTRACTION_EFFICIENCY, efficiency); | 119 | BSDynamics vehicleActor = TestVehicle.GetVehicleActor(true /* createIfNone */); |
118 | TestVehicle.VehicleController.ProcessFloatVehicleParam(Vehicle.VERTICAL_ATTRACTION_TIMESCALE, timeScale); | 120 | if (vehicleActor != null) |
119 | TestVehicle.VehicleController.enableAngularVerticalAttraction = true; | ||
120 | |||
121 | TestVehicle.IsPhysical = true; | ||
122 | PhysicsScene.ProcessTaints(); | ||
123 | |||
124 | // Step the simulator a bunch of times and vertical attraction should orient the vehicle up | ||
125 | for (int ii = 0; ii < simSteps; ii++) | ||
126 | { | 121 | { |
127 | TestVehicle.VehicleController.ForgetKnownVehicleProperties(); | 122 | vehicleActor.ProcessFloatVehicleParam(Vehicle.VERTICAL_ATTRACTION_EFFICIENCY, efficiency); |
128 | TestVehicle.VehicleController.ComputeAngularVerticalAttraction(); | 123 | vehicleActor.ProcessFloatVehicleParam(Vehicle.VERTICAL_ATTRACTION_TIMESCALE, timeScale); |
129 | TestVehicle.VehicleController.PushKnownChanged(); | 124 | // vehicleActor.enableAngularVerticalAttraction = true; |
130 | 125 | ||
131 | PhysicsScene.Simulate(simulationTimeStep); | 126 | TestVehicle.IsPhysical = true; |
127 | PhysicsScene.ProcessTaints(); | ||
128 | |||
129 | // Step the simulator a bunch of times and vertical attraction should orient the vehicle up | ||
130 | for (int ii = 0; ii < simSteps; ii++) | ||
131 | { | ||
132 | vehicleActor.ForgetKnownVehicleProperties(); | ||
133 | vehicleActor.ComputeAngularVerticalAttraction(); | ||
134 | vehicleActor.PushKnownChanged(); | ||
135 | |||
136 | PhysicsScene.Simulate(simulationTimeStep); | ||
137 | } | ||
132 | } | 138 | } |
133 | 139 | ||
134 | TestVehicle.IsPhysical = false; | 140 | TestVehicle.IsPhysical = false; |