From ce5083a504a82712149f5e3dab622d42e260bba3 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 9 Dec 2012 22:10:32 -0800 Subject: BulletSim: adjust friction and restitution based on material type. --- OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 10 ++++++++++ OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 12 +++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index f6a890e..b05d4ee 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -60,6 +60,9 @@ public abstract class BSPhysObject : PhysicsActor Linkset = BSLinkset.Factory(PhysicsScene, this); LastAssetBuildFailed = false; + // Default material type + Material = MaterialAttributes.Material.Wood; + CollisionCollection = new CollisionEventUpdate(); SubscribedEventsMs = 0; CollidingStep = 0; @@ -109,6 +112,13 @@ public abstract class BSPhysObject : PhysicsActor public abstract bool IsSolid { get; } public abstract bool IsStatic { get; } + // Materialness + public MaterialAttributes.Material Material { get; private set; } + public override void SetMaterial(int material) + { + Material = (MaterialAttributes.Material)material; + } + // Stop all physical motion. public abstract void ZeroMotion(bool inTaintTime); public abstract void ZeroAngularMotion(bool inTaintTime); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 4d203ff..627393a 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -683,8 +683,9 @@ public sealed class BSPrim : BSPhysObject ZeroMotion(true); // Set various physical properties so other object interact properly - BulletSimAPI.SetFriction2(PhysBody.ptr, PhysicsScene.Params.defaultFriction); - BulletSimAPI.SetRestitution2(PhysBody.ptr, PhysicsScene.Params.defaultRestitution); + MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); + BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction); + BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution); // Mass is zero which disables a bunch of physics stuff in Bullet UpdatePhysicalMassProperties(0f); @@ -711,9 +712,10 @@ public sealed class BSPrim : BSPhysObject // Not a Bullet static object CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT); - // Set various physical properties so internal dynamic properties will get computed correctly as they are set - BulletSimAPI.SetFriction2(PhysBody.ptr, PhysicsScene.Params.defaultFriction); - BulletSimAPI.SetRestitution2(PhysBody.ptr, PhysicsScene.Params.defaultRestitution); + // Set various physical properties so other object interact properly + MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true); + BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction); + BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution); // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 // Since this can be called multiple times, only zero forces when becoming physical -- cgit v1.1 From a19896cc569c037436ad8e65f044224f169d63d4 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 9 Dec 2012 22:32:13 -0800 Subject: BulletSim: some comments about rebuilding linksets (having to recompute and restore a child's position in the world based on its position in the moved linkset). --- OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index 1f7c398..bc9f9be 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs @@ -192,6 +192,8 @@ public sealed class BSLinksetCompound : BSLinkset child.LocalID, child.PhysBody.ptr.ToString("X")); // Cause the child's body to be rebuilt and thus restored to normal operation + // TODO: position and rotation must be restored because the child could have moved + // based on the linkset. child.ForceBodyShapeRebuild(false); if (!HasAnyChildren) @@ -236,9 +238,10 @@ public sealed class BSLinksetCompound : BSLinkset if (cPrim.PhysShape.isNativeShape) { - // Native shapes are not shared so we need to create a new one. - // A mesh or hull is created because scale is not available on a native shape. - // (TODO: Bullet does have a btScaledCollisionShape. Can that be used?) + // A native shape is turning into a null collision shape because native + // shapes are not shared so we have to hullify it so it will be tracked + // and freed at the correct time. This also solves the scaling problem + // (native shapes scaled but hull/meshes are assumed to not be). BulletShape saveShape = cPrim.PhysShape; cPrim.PhysShape.ptr = IntPtr.Zero; // Don't let the create free the child's shape PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null); -- cgit v1.1 From 9df85eadf4b3719a898fda8769313ae023962c25 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 10 Dec 2012 15:35:53 -0800 Subject: BulletSim: Fix crash on the destruction of physical linksets. While fixing the above, add methods to physical body and shape pointer wrapper so routines won't have to know that IntPtr.Zero means no physical instance. Fix problem with physical linksets failing after a few sits and unsits by properly restoring child prom positions for compound linksets after multiple selection and deselections. --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 2 + .../Region/Physics/BulletSPlugin/BSConstraint.cs | 4 +- .../Physics/BulletSPlugin/BSConstraint6Dof.cs | 4 +- OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs | 8 ++ .../Physics/BulletSPlugin/BSLinksetCompound.cs | 113 +++++++++++++++++---- .../Region/Physics/BulletSPlugin/BSPhysObject.cs | 5 +- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 6 +- .../Physics/BulletSPlugin/BSShapeCollection.cs | 16 +-- .../Physics/BulletSPlugin/BSTerrainHeightmap.cs | 2 +- .../Physics/BulletSPlugin/BSTerrainManager.cs | 4 +- .../Region/Physics/BulletSPlugin/BSTerrainMesh.cs | 6 +- .../Region/Physics/BulletSPlugin/BulletSimAPI.cs | 23 +++++ 12 files changed, 155 insertions(+), 38 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 21aa9be..88460cc 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -124,7 +124,9 @@ public sealed class BSCharacter : BSPhysObject PhysicsScene.TaintedObject("BSCharacter.destroy", delegate() { PhysicsScene.Shapes.DereferenceBody(PhysBody, true, null); + PhysBody.Clear(); PhysicsScene.Shapes.DereferenceShape(PhysShape, true, null); + PhysShape.Clear(); }); } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs index 65fac00..6b1e304 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs @@ -57,7 +57,7 @@ public abstract class BSConstraint : IDisposable if (m_enabled) { m_enabled = false; - if (m_constraint.ptr != IntPtr.Zero) + if (m_constraint.HasPhysicalConstraint) { bool success = BulletSimAPI.DestroyConstraint2(m_world.ptr, m_constraint.ptr); m_world.physicsScene.DetailLog("{0},BSConstraint.Dispose,taint,id1={1},body1={2},id2={3},body2={4},success={5}", @@ -65,7 +65,7 @@ public abstract class BSConstraint : IDisposable m_body1.ID, m_body1.ptr.ToString("X"), m_body2.ID, m_body2.ptr.ToString("X"), success); - m_constraint.ptr = System.IntPtr.Zero; + m_constraint.Clear(); } } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs index 23ef052..b073555 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs @@ -65,7 +65,7 @@ public sealed class BSConstraint6Dof : BSConstraint m_world = world; m_body1 = obj1; m_body2 = obj2; - if (obj1.ptr == IntPtr.Zero || obj2.ptr == IntPtr.Zero) + if (!obj1.HasPhysicalBody || !obj2.HasPhysicalBody) { world.physicsScene.DetailLog("{0},BS6DOFConstraint,badBodyPtr,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", BSScene.DetailLogZero, world.worldID, @@ -83,7 +83,7 @@ public sealed class BSConstraint6Dof : BSConstraint world.physicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}", BSScene.DetailLogZero, world.worldID, m_constraint.ptr.ToString("X"), obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X")); - if (m_constraint.ptr == IntPtr.Zero) + if (!m_constraint.HasPhysicalConstraint) { world.physicsScene.Logger.ErrorFormat("{0} Failed creation of 6Dof constraint. rootID={1}, childID={2}", LogHeader, obj1.ID, obj2.ID); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs index 0df4310..777c5cb 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs @@ -32,6 +32,14 @@ using OMV = OpenMetaverse; namespace OpenSim.Region.Physics.BulletSPlugin { + +// A BSPrim can get individual information about its linkedness attached +// to it through an instance of a subclass of LinksetInfo. +// Each type of linkset will define the information needed for its type. +public abstract class BSLinksetInfo +{ +} + public abstract class BSLinkset { // private static string LogHeader = "[BULLETSIM LINKSET]"; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index bc9f9be..fe5b5e3 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs @@ -32,6 +32,31 @@ using OMV = OpenMetaverse; namespace OpenSim.Region.Physics.BulletSPlugin { + +// When a child is linked, the relationship position of the child to the parent +// is remembered so the child's world position can be recomputed when it is +// removed from the linkset. +sealed class BSLinksetCompoundInfo : BSLinksetInfo +{ + public OMV.Vector3 OffsetPos; + public OMV.Quaternion OffsetRot; + public BSLinksetCompoundInfo(OMV.Vector3 p, OMV.Quaternion r) + { + OffsetPos = p; + OffsetRot = r; + } + public override string ToString() + { + StringBuilder buff = new StringBuilder(); + buff.Append(""); + return buff.ToString(); + } +}; + public sealed class BSLinksetCompound : BSLinkset { private static string LogHeader = "[BULLETSIM LINKSET COMPOUND]"; @@ -44,6 +69,7 @@ public sealed class BSLinksetCompound : BSLinkset // For compound implimented linksets, if there are children, use compound shape for the root. public override BSPhysicsShapeType PreferredPhysicalShape(BSPhysObject requestor) { + // Returning 'unknown' means we don't have a preference. BSPhysicsShapeType ret = BSPhysicsShapeType.SHAPE_UNKNOWN; if (IsRoot(requestor) && HasAnyChildren) { @@ -63,10 +89,10 @@ public sealed class BSLinksetCompound : BSLinkset // InternalRefresh(requestor); } + // Schedule a refresh to happen after all the other taint processing. private void InternalRefresh(BSPhysObject requestor) { DetailLog("{0},BSLinksetCompound.Refresh,schedulingRefresh,requestor={1}", LinksetRoot.LocalID, requestor.LocalID); - // Queue to happen after all the other taint processing PhysicsScene.PostTaintObject("BSLinksetCompound.Refresh", requestor.LocalID, delegate() { if (IsRoot(requestor) && HasAnyChildren) @@ -108,7 +134,7 @@ public sealed class BSLinksetCompound : BSLinkset { // The non-physical children can come back to life. BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); - // Don't force activation so setting of DISABLE_SIMULATION can stay. + // Don't force activation so setting of DISABLE_SIMULATION can stay if used. BulletSimAPI.Activate2(child.PhysBody.ptr, false); ret = true; } @@ -146,6 +172,10 @@ public sealed class BSLinksetCompound : BSLinkset if (!IsRoot(child)) { + // Because it is a convenient time, recompute child world position and rotation based on + // its position in the linkset. + RecomputeChildWorldPosition(child, true); + // Cause the current shape to be freed and the new one to be built. InternalRefresh(LinksetRoot); ret = true; @@ -154,6 +184,42 @@ public sealed class BSLinksetCompound : BSLinkset return ret; } + // When the linkset is built, the child shape is added + // to the compound shape relative to the root shape. The linkset then moves around but + // this does not move the actual child prim. The child prim's location must be recomputed + // based on the location of the root shape. + private void RecomputeChildWorldPosition(BSPhysObject child, bool inTaintTime) + { + BSLinksetCompoundInfo lci = child.LinksetInfo as BSLinksetCompoundInfo; + if (lci != null) + { + if (inTaintTime) + { + OMV.Vector3 oldPos = child.RawPosition; + child.ForcePosition = LinksetRoot.RawPosition + lci.OffsetPos; + child.ForceOrientation = LinksetRoot.RawOrientation * lci.OffsetRot; + DetailLog("{0},BSLinksetCompound.RecomputeChildWorldPosition,oldPos={1},lci={2},newPos={3}", + child.LocalID, oldPos, lci, child.RawPosition); + } + else + { + // TaintedObject is not used here so the raw position is set now and not at taint-time. + child.Position = LinksetRoot.RawPosition + lci.OffsetPos; + child.Orientation = LinksetRoot.RawOrientation * lci.OffsetRot; + } + } + else + { + // This happens when children have been added to the linkset but the linkset + // has not been constructed yet. So like, at taint time, adding children to a linkset + // and then changing properties of the children (makePhysical, for instance) + // but the post-print action of actually rebuilding the linkset has not yet happened. + // PhysicsScene.Logger.WarnFormat("{0} Restoring linkset child position failed because of no relative position computed. ID={1}", + // LogHeader, child.LocalID); + DetailLog("{0},BSLinksetCompound.recomputeChildWorldPosition,noRelativePositonInfo", child.LocalID); + } + } + // Companion to RemoveBodyDependencies(). If RemoveBodyDependencies() returns 'true', // this routine will restore the removed constraints. // Called at taint-time!! @@ -192,8 +258,7 @@ public sealed class BSLinksetCompound : BSLinkset child.LocalID, child.PhysBody.ptr.ToString("X")); // Cause the child's body to be rebuilt and thus restored to normal operation - // TODO: position and rotation must be restored because the child could have moved - // based on the linkset. + RecomputeChildWorldPosition(child, false); child.ForceBodyShapeRebuild(false); if (!HasAnyChildren) @@ -228,43 +293,57 @@ public sealed class BSLinksetCompound : BSLinkset { if (!IsRoot(cPrim)) { - // Each child position and rotation is given relative to the root. - OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(LinksetRoot.RawOrientation); - OMV.Vector3 displacementPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation; - OMV.Quaternion displacementRot = cPrim.RawOrientation * invRootOrientation; + // Compute the displacement of the child from the root of the linkset. + // This info is saved in the child prim so the relationship does not + // change over time and the new child position can be computed + // when the linkset is being disassembled (the linkset may have moved). + BSLinksetCompoundInfo lci = cPrim.LinksetInfo as BSLinksetCompoundInfo; + if (lci == null) + { + // Each child position and rotation is given relative to the root. + OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(LinksetRoot.RawOrientation); + OMV.Vector3 displacementPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation; + OMV.Quaternion displacementRot = cPrim.RawOrientation * invRootOrientation; + + // Save relative position for recomputing child's world position after moving linkset. + lci = new BSLinksetCompoundInfo(displacementPos, displacementRot); + cPrim.LinksetInfo = lci; + DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,creatingRelPos,lci={1}", cPrim.LocalID, lci); + } DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addMemberToShape,mID={1},mShape={2},dispPos={3},dispRot={4}", - LinksetRoot.LocalID, cPrim.LocalID, cPrim.PhysShape, displacementPos, displacementRot); + LinksetRoot.LocalID, cPrim.LocalID, cPrim.PhysShape, lci.OffsetPos, lci.OffsetRot); if (cPrim.PhysShape.isNativeShape) { - // A native shape is turning into a null collision shape because native + // A native shape is turning into a hull collision shape because native // shapes are not shared so we have to hullify it so it will be tracked // and freed at the correct time. This also solves the scaling problem // (native shapes scaled but hull/meshes are assumed to not be). + // TODO: decide of the native shape can just be used in the compound shape. + // Use call to CreateGeomNonSpecial(). BulletShape saveShape = cPrim.PhysShape; - cPrim.PhysShape.ptr = IntPtr.Zero; // Don't let the create free the child's shape + cPrim.PhysShape.Clear(); // Don't let the create free the child's shape + // PhysicsScene.Shapes.CreateGeomNonSpecial(true, cPrim, null); PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null); BulletShape newShape = cPrim.PhysShape; cPrim.PhysShape = saveShape; - BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, newShape.ptr, displacementPos, displacementRot); + BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, newShape.ptr, lci.OffsetPos , lci.OffsetRot); } else { // For the shared shapes (meshes and hulls), just use the shape in the child. + // The reference count added here will be decremented when the compound shape + // is destroyed in BSShapeCollection (the child shapes are looped over and dereferenced). if (PhysicsScene.Shapes.ReferenceShape(cPrim.PhysShape)) { PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}", LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape); } - BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, displacementPos, displacementRot); + BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, lci.OffsetPos , lci.OffsetRot); } } - // TODO: need to phantomize the child prims left behind. - // Maybe just destroy the children bodies and shapes and have them rebuild on unlink. - // Selection/deselection might cause way too many build/destructions esp. for LARGE linksets. - return false; // 'false' says to move onto the next child in the list }); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index b05d4ee..d2fc15c 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -75,6 +75,7 @@ public abstract class BSPhysObject : PhysicsActor public string TypeName { get; protected set; } public BSLinkset Linkset { get; set; } + public BSLinksetInfo LinksetInfo { get; set; } // Return the object mass without calculating it or having side effects public abstract float RawMass { get; } @@ -253,7 +254,9 @@ public abstract class BSPhysObject : PhysicsActor SubscribedEventsMs = 0; PhysicsScene.TaintedObject(TypeName+".UnSubscribeEvents", delegate() { - CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); + // Make sure there is a body there because sometimes destruction happens in an un-ideal order. + if (PhysBody.HasPhysicalBody) + CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); }); } // Return 'true' if the simulator wants collision events diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 627393a..d1d100d 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -108,8 +108,8 @@ public sealed class BSPrim : BSPhysObject _mass = CalculateMass(); // No body or shape yet - PhysBody = new BulletBody(LocalID, IntPtr.Zero); - PhysShape = new BulletShape(IntPtr.Zero); + PhysBody = new BulletBody(LocalID); + PhysShape = new BulletShape(); DetailLog("{0},BSPrim.constructor,call", LocalID); // do the actual object creation at taint time @@ -143,7 +143,9 @@ public sealed class BSPrim : BSPhysObject DetailLog("{0},BSPrim.Destroy,taint,", LocalID); // If there are physical body and shape, release my use of same. PhysicsScene.Shapes.DereferenceBody(PhysBody, true, null); + PhysBody.Clear(); PhysicsScene.Shapes.DereferenceShape(PhysShape, true, null); + PhysShape.Clear(); }); } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 933f573..74b4371 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs @@ -149,7 +149,7 @@ public sealed class BSShapeCollection : IDisposable // Called when releasing use of a BSBody. BSShape is handled separately. public void DereferenceBody(BulletBody body, bool inTaintTime, BodyDestructionCallback bodyCallback ) { - if (body.ptr == IntPtr.Zero) + if (!body.HasPhysicalBody) return; lock (m_collectionActivityLock) @@ -243,12 +243,12 @@ public sealed class BSShapeCollection : IDisposable // Release the usage of a shape. public void DereferenceShape(BulletShape shape, bool inTaintTime, ShapeDestructionCallback shapeCallback) { - if (shape.ptr == IntPtr.Zero) + if (!shape.HasPhysicalShape) return; PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceShape", delegate() { - if (shape.ptr != IntPtr.Zero) + if (shape.HasPhysicalShape) { if (shape.isNativeShape) { @@ -440,7 +440,7 @@ public sealed class BSShapeCollection : IDisposable } // Create a mesh/hull shape or a native shape if 'nativeShapePossible' is 'true'. - private bool CreateGeomNonSpecial(bool forceRebuild, BSPhysObject prim, ShapeDestructionCallback shapeCallback) + public bool CreateGeomNonSpecial(bool forceRebuild, BSPhysObject prim, ShapeDestructionCallback shapeCallback) { bool ret = false; bool haveShape = false; @@ -573,7 +573,7 @@ public sealed class BSShapeCollection : IDisposable // Native shapes are scaled in Bullet so set the scaling to the size newShape = new BulletShape(BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, nativeShapeData), shapeType); } - if (newShape.ptr == IntPtr.Zero) + if (!newShape.HasPhysicalShape) { PhysicsScene.Logger.ErrorFormat("{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}", LogHeader, prim.LocalID, shapeType); @@ -590,7 +590,7 @@ public sealed class BSShapeCollection : IDisposable // Called at taint-time! private bool GetReferenceToMesh(BSPhysObject prim, ShapeDestructionCallback shapeCallback) { - BulletShape newShape = new BulletShape(IntPtr.Zero); + BulletShape newShape = new BulletShape(); float lod; System.UInt64 newMeshKey = ComputeShapeKey(prim.Size, prim.BaseShape, out lod); @@ -860,7 +860,7 @@ public sealed class BSShapeCollection : IDisposable private BulletShape VerifyMeshCreated(BulletShape newShape, BSPhysObject prim) { // If the shape was successfully created, nothing more to do - if (newShape.ptr != IntPtr.Zero) + if (newShape.HasPhysicalShape) return newShape; // If this mesh has an underlying asset and we have not failed getting it before, fetch the asset @@ -919,7 +919,7 @@ public sealed class BSShapeCollection : IDisposable bool ret = false; // the mesh, hull or native shape must have already been created in Bullet - bool mustRebuild = (prim.PhysBody.ptr == IntPtr.Zero); + bool mustRebuild = !prim.PhysBody.HasPhysicalBody; // If there is an existing body, verify it's of an acceptable type. // If not a solid object, body is a GhostObject. Otherwise a RigidBody. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs index 83b9c37..2d379bb 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs @@ -136,7 +136,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys { if (m_mapInfo != null) { - if (m_mapInfo.terrainBody.ptr != IntPtr.Zero) + if (m_mapInfo.terrainBody.HasPhysicalBody) { BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); // Frees both the body and the shape. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs index 83df360..c28d69d 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs @@ -151,13 +151,13 @@ public sealed class BSTerrainManager // Release all the terrain structures we might have allocated public void ReleaseGroundPlaneAndTerrain() { - if (m_groundPlane.ptr != IntPtr.Zero) + if (m_groundPlane.HasPhysicalBody) { if (BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr)) { BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_groundPlane.ptr); } - m_groundPlane.ptr = IntPtr.Zero; + m_groundPlane.Clear(); } ReleaseTerrain(); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs index 6ce767d..3473006 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs @@ -94,7 +94,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys m_terrainShape = new BulletShape(BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr, indicesCount, indices, verticesCount, vertices), BSPhysicsShapeType.SHAPE_MESH); - if (m_terrainShape.ptr == IntPtr.Zero) + if (!m_terrainShape.HasPhysicalShape) { // DISASTER!! PhysicsScene.DetailLog("{0},BSTerrainMesh.create,failedCreationOfShape", ID); @@ -107,7 +107,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys Quaternion rot = Quaternion.Identity; m_terrainBody = new BulletBody(id, BulletSimAPI.CreateBodyWithDefaultMotionState2( m_terrainShape.ptr, ID, pos, rot)); - if (m_terrainBody.ptr == IntPtr.Zero) + if (!m_terrainBody.HasPhysicalBody) { // DISASTER!! physicsScene.Logger.ErrorFormat("{0} Failed creation of terrain body! base={1}", LogHeader, TerrainBase); @@ -140,7 +140,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys public override void Dispose() { - if (m_terrainBody.ptr != IntPtr.Zero) + if (m_terrainBody.HasPhysicalBody) { BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr); // Frees both the body and the shape. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs index 2671995..1559025 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs @@ -53,6 +53,9 @@ public struct BulletSim // An allocated Bullet btRigidBody public struct BulletBody { + public BulletBody(uint id) : this(id, IntPtr.Zero) + { + } public BulletBody(uint id, IntPtr xx) { ID = id; @@ -64,6 +67,13 @@ public struct BulletBody public uint ID; public CollisionFilterGroups collisionGroup; public CollisionFilterGroups collisionMask; + + public void Clear() + { + ptr = IntPtr.Zero; + } + public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } } + public override string ToString() { StringBuilder buff = new StringBuilder(); @@ -103,6 +113,13 @@ public struct BulletShape public BSPhysicsShapeType type; public System.UInt64 shapeKey; public bool isNativeShape; + + public void Clear() + { + ptr = IntPtr.Zero; + } + public bool HasPhysicalShape { get { return ptr != IntPtr.Zero; } } + public override string ToString() { StringBuilder buff = new StringBuilder(); @@ -140,6 +157,12 @@ public struct BulletConstraint ptr = xx; } public IntPtr ptr; + + public void Clear() + { + ptr = IntPtr.Zero; + } + public bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } } } // An allocated HeightMapThing which holds various heightmap info. -- cgit v1.1 From 93393fb975f3886c448b6f945705304552fe8875 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 10 Dec 2012 16:46:12 -0800 Subject: BulletSim: comment out some chatty debug logging. Rearrange some code in BSDynamics to make velocity vs force calculation clearer. --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 8 +++++--- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index fa3110c..cb84456 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -818,6 +818,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin + hoverContribution + limitMotorUpContribution; + Vector3 newForce = buoyancyContribution; + // If not changing some axis, reduce out velocity if ((m_flags & (VehicleFlag.NO_X)) != 0) newVelocity.X = 0; @@ -845,7 +847,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin VehicleVelocity = newVelocity; // Other linear forces are applied as forces. - Vector3 totalDownForce = buoyancyContribution * m_vehicleMass; + Vector3 totalDownForce = newForce * m_vehicleMass; if (!totalDownForce.ApproxEquals(Vector3.Zero, 0.01f)) { VehicleAddForce(totalDownForce); @@ -1005,8 +1007,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin // has a decay factor. This says this force should // be computed with a motor. // TODO: add interaction with banking. - VDetailLog("{0}, MoveLinear,limitMotorUp,distAbove={1},downForce={2}", - Prim.LocalID, distanceAboveGround, ret); + VDetailLog("{0}, MoveLinear,limitMotorUp,distAbove={1},colliding={2},ret={3}", + Prim.LocalID, distanceAboveGround, Prim.IsColliding, ret); } return ret; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index f72bd74..17cc7b4 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -501,7 +501,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters try { - if (VehicleLoggingEnabled) DumpVehicles(); // DEBUG + // if (VehicleLoggingEnabled) DumpVehicles(); // DEBUG if (PhysicsLogging.Enabled) beforeTime = Util.EnvironmentTickCount(); numSubSteps = BulletSimAPI.PhysicsStep2(World.ptr, timeStep, m_maxSubSteps, m_fixedTimeStep, @@ -510,7 +510,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters if (PhysicsLogging.Enabled) simTime = Util.EnvironmentTickCountSubtract(beforeTime); DetailLog("{0},Simulate,call, frame={1}, nTaints={2}, simTime={3}, substeps={4}, updates={5}, colliders={6}", DetailLogZero, m_simulationStep, numTaints, simTime, numSubSteps, updatedEntityCount, collidersCount); - if (VehicleLoggingEnabled) DumpVehicles(); // DEBUG + // if (VehicleLoggingEnabled) DumpVehicles(); // DEBUG } catch (Exception e) { -- cgit v1.1 From ebf30e7ba66446d7018346c12111d65a030d2786 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 11 Dec 2012 00:02:20 -0800 Subject: BulletSim: set mass for single prim linksets when going physical. This fixes single prim vehicles not working (the surf board now zooms). --- OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index fe5b5e3..d2abdb4 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs @@ -110,12 +110,19 @@ public sealed class BSLinksetCompound : BSLinkset { bool ret = false; DetailLog("{0},BSLinksetCompound.MakeDynamic,call,IsRoot={1}", child.LocalID, IsRoot(child)); - if (!IsRoot(child)) + if (IsRoot(child)) + { + // The root is going dynamic. Make sure mass is properly set. + m_mass = ComputeLinksetMass(); + } + else { // The origional prims are removed from the world as the shape of the root compound // shape takes over. BulletSimAPI.AddToCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); BulletSimAPI.ForceActivationState2(child.PhysBody.ptr, ActivationState.DISABLE_SIMULATION); + // We don't want collisions from the old linkset children. + BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); ret = true; } return ret; -- cgit v1.1 From 8b861e880ad128edc0267b8e2d5931cfc8a142bc Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 11 Dec 2012 00:13:13 -0800 Subject: BulletSim: add ini file and command line parameters to control dumping of physical vehicle parameters (out of Bullet) on each simulation step and to optionally scale vehicle angular velocity by the time step. The latter looks to be part of a difference between angular parameters for ODE and BulletSim. SL docs say angular velocity is measured in radians/timeScale. Not sure if this is different than what ODE does. --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 9 ++++++--- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 12 ++++++++++-- OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | 2 +- OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt | 7 +++++-- 4 files changed, 22 insertions(+), 8 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index cb84456..acddc09 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -570,8 +570,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, localInertia); BulletSimAPI.UpdateInertiaTensor2(Prim.PhysBody.ptr); - VDetailLog("{0},BSDynamics.Refresh,frict={1},inert={2},aDamp={3}", - Prim.LocalID, friction, localInertia, angularDamping); + VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4}", + Prim.LocalID, m_vehicleMass, friction, localInertia, angularDamping); } else { @@ -1057,7 +1057,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin // TODO: Should this be applied as an angular force (torque)? if (!m_lastAngularCorrection.ApproxEquals(Vector3.Zero, 0.01f)) { - Vector3 scaledCorrection = m_lastAngularCorrection * pTimestep; + // DEBUG DEBUG DEBUG: optionally scale the angular velocity. Debugging SL vs ODE turning functions. + Vector3 scaledCorrection = m_lastAngularCorrection; + if (PhysicsScene.VehicleScaleAngularVelocityByTimestep) + scaledCorrection *= pTimestep; VehicleRotationalVelocity = scaledCorrection; VDetailLog("{0}, MoveAngular,done,nonZero,angMotorContrib={1},vertAttrContrib={2},bankContrib={3},deflectContrib={4},totalContrib={5},scaledCorr={6}", diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 17cc7b4..f4f2801 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -188,6 +188,8 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters private bool m_physicsLoggingDoFlush; // 'true' of the vehicle code is to log lots of details public bool VehicleLoggingEnabled { get; private set; } + public bool VehiclePhysicalLoggingEnabled { get; private set; } + public bool VehicleScaleAngularVelocityByTimestep { get; private set; } #region Construction and Initialization public BSScene(string identifier) @@ -297,6 +299,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters m_physicsLoggingDoFlush = pConfig.GetBoolean("PhysicsLoggingDoFlush", false); // Very detailed logging for vehicle debugging VehicleLoggingEnabled = pConfig.GetBoolean("VehicleLoggingEnabled", false); + VehiclePhysicalLoggingEnabled = pConfig.GetBoolean("VehiclePhysicalLoggingEnabled", false); // Do any replacements in the parameters m_physicsLoggingPrefix = m_physicsLoggingPrefix.Replace("%REGIONNAME%", RegionName); @@ -501,7 +504,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters try { - // if (VehicleLoggingEnabled) DumpVehicles(); // DEBUG + if (VehiclePhysicalLoggingEnabled) DumpVehicles(); // DEBUG if (PhysicsLogging.Enabled) beforeTime = Util.EnvironmentTickCount(); numSubSteps = BulletSimAPI.PhysicsStep2(World.ptr, timeStep, m_maxSubSteps, m_fixedTimeStep, @@ -510,7 +513,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters if (PhysicsLogging.Enabled) simTime = Util.EnvironmentTickCountSubtract(beforeTime); DetailLog("{0},Simulate,call, frame={1}, nTaints={2}, simTime={3}, substeps={4}, updates={5}, colliders={6}", DetailLogZero, m_simulationStep, numTaints, simTime, numSubSteps, updatedEntityCount, collidersCount); - // if (VehicleLoggingEnabled) DumpVehicles(); // DEBUG + if (VehiclePhysicalLoggingEnabled) DumpVehicles(); // DEBUG } catch (Exception e) { @@ -1226,6 +1229,11 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters (s,cf,p,v) => { s.m_params[0].vehicleAngularDamping = cf.GetFloat(p, v); }, (s) => { return s.m_params[0].vehicleAngularDamping; }, (s,p,l,v) => { s.m_params[0].vehicleAngularDamping = v; } ), + new ParameterDefn("VehicleScaleAngularVelocityByTimestep", "If true, scale angular turning by timestep", + ConfigurationParameters.numericFalse, + (s,cf,p,v) => { s.VehicleScaleAngularVelocityByTimestep = cf.GetBoolean(p, s.BoolNumeric(v)); }, + (s) => { return s.NumericBool(s.VehicleScaleAngularVelocityByTimestep); }, + (s,p,l,v) => { s.VehicleScaleAngularVelocityByTimestep = s.BoolNumeric(v); } ), new ParameterDefn("MaxPersistantManifoldPoolSize", "Number of manifolds pooled (0 means default of 4096)", 0f, diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 74b4371..4ab9a99 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs @@ -793,7 +793,7 @@ public sealed class BSShapeCollection : IDisposable BulletShape newShape = new BulletShape(hullPtr, BSPhysicsShapeType.SHAPE_HULL); newShape.shapeKey = newHullKey; - return newShape; // 'true' means a new shape has been added to this prim + return newShape; } // Callback from convex hull creater with a newly created hull. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index a2161c3..4b6e9a4 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt @@ -38,7 +38,8 @@ Disable activity of passive linkset children. Scenes with hundred of thousands of static objects take a lot of physics CPU time. BSPrim.Force should set a continious force on the prim. The force should be applied each tick. Some limits? -Single prim vehicles don't seem to properly vehiclize. +Linksets should allow collisions to individual children + Add LocalID to children shapes in LinksetCompound and create events for individuals Gun sending shooter flying. Collision margin (gap between physical objects lying on each other) Boundry checking (crashes related to crossing boundry) @@ -145,4 +146,6 @@ Linkset implementation using compound shapes. (Resolution: implemented LinksetCo Light cycle falling over when driving (Resolution: implemented VerticalAttractor) Light cycle not banking (Resolution: It doesn't. Banking is roll adding yaw.) Package Bullet source mods for Bullet internal stats output - (Resolution: move code into WorldData.h rather than relying on patches) \ No newline at end of file + (Resolution: move code into WorldData.h rather than relying on patches) +Single prim vehicles don't seem to properly vehiclize. + (Resolution: mass was not getting set properly for single prim linksets) -- cgit v1.1 From 905d7c43ad34869df03b21fcd24eb8ea8c6beeae Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 11 Dec 2012 00:35:16 -0800 Subject: BulletSim: modify LIMIT_MOTOR_UP to limit BOAT types to be at water rather than ground level. This makes boats float at water level better but not perfectly. There probably needs to be some interaction between HOVER and LIMIT_MOTOR_UP. --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index acddc09..82e829e 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -993,8 +993,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin if ((m_flags & (VehicleFlag.LIMIT_MOTOR_UP)) != 0) { - // If the vehicle is motoring into the sky, get it going back down. - float distanceAboveGround = VehiclePosition.Z - GetTerrainHeight(VehiclePosition); + float targetHeight = Type == Vehicle.TYPE_BOAT ? GetWaterLevel(VehiclePosition) : GetTerrainHeight(VehiclePosition); + float distanceAboveGround = VehiclePosition.Z - targetHeight; // Not colliding if the vehicle is off the ground if (!Prim.IsColliding) { -- cgit v1.1 From 63099184dbd2c1c5bcee2c3c87802f78444e7008 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 11 Dec 2012 13:42:23 -0800 Subject: BulletSim: protect prim property setting to remove crash from taints setting properties after the destroy object taint has happened. --- OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | 2 +- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 54 +++++++++++++++------- .../Region/Physics/BulletSPlugin/BulletSimTODO.txt | 9 +++- 3 files changed, 45 insertions(+), 20 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs index 851d508..cf0a9dc 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs @@ -65,7 +65,7 @@ public abstract class BSMotor // Can all the incremental stepping be replaced with motor classes? // Motor which moves CurrentValue to TargetValue over TimeScale seconds. -// The TargetValue is decays in TargetValueDecayTimeScale and +// The TargetValue decays in TargetValueDecayTimeScale and // the CurrentValue will be held back by FrictionTimeScale. // TimeScale and TargetDelayTimeScale may be 'infinite' which means go decay. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index d1d100d..1280c25 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -249,7 +249,8 @@ public sealed class BSPrim : BSPhysObject // Zero some other properties in the physics engine PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() { - BulletSimAPI.ClearAllForces2(PhysBody.ptr); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.ClearAllForces2(PhysBody.ptr); }); } public override void ZeroAngularMotion(bool inTaintTime) @@ -259,8 +260,11 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() { // DetailLog("{0},BSPrim.ZeroAngularMotion,call,rotVel={1}", LocalID, _rotationalVelocity); - BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, _rotationalVelocity); - BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); + if (PhysBody.HasPhysicalBody) + { + BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, _rotationalVelocity); + BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); + } }); } @@ -297,8 +301,11 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject("BSPrim.setPosition", delegate() { // DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); - BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); - ActivateIfPhysical(false); + if (PhysBody.HasPhysicalBody) + { + BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + ActivateIfPhysical(false); + } }); } } @@ -415,7 +422,8 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject("BSPrim.setForce", delegate() { // DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); - BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); }); } } @@ -509,7 +517,8 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate() { // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); - BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); }); } } @@ -558,9 +567,12 @@ public sealed class BSPrim : BSPhysObject // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint? PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() { - // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); - // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); - BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + if (PhysBody.HasPhysicalBody) + { + // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); + // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); + BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + } }); } } @@ -865,7 +877,8 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() { DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); - BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); }); } } @@ -900,8 +913,11 @@ public sealed class BSPrim : BSPhysObject _buoyancy = value; // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); // Buoyancy is faked by changing the gravity applied to the object - float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); - BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); + if (PhysBody.HasPhysicalBody) + { + float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); + BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); + } } } @@ -969,7 +985,8 @@ public sealed class BSPrim : BSPhysObject } DetailLog("{0},BSPrim.AddForce,taint,force={1}", LocalID, fSum); if (fSum != OMV.Vector3.Zero) - BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, fSum); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, fSum); }); } @@ -980,7 +997,8 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyForceImpulse", delegate() { DetailLog("{0},BSPrim.ApplyForceImpulse,taint,tImpulse={1}", LocalID, applyImpulse); - BulletSimAPI.ApplyCentralImpulse2(PhysBody.ptr, applyImpulse); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.ApplyCentralImpulse2(PhysBody.ptr, applyImpulse); }); } @@ -1016,7 +1034,8 @@ public sealed class BSPrim : BSPhysObject DetailLog("{0},BSPrim.AddAngularForce,taint,aForce={1}", LocalID, fSum); if (fSum != OMV.Vector3.Zero) { - BulletSimAPI.ApplyTorque2(PhysBody.ptr, fSum); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.ApplyTorque2(PhysBody.ptr, fSum); _torque = fSum; } }); @@ -1030,7 +1049,8 @@ public sealed class BSPrim : BSPhysObject OMV.Vector3 applyImpulse = impulse; PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyTorqueImpulse", delegate() { - BulletSimAPI.ApplyTorqueImpulse2(PhysBody.ptr, applyImpulse); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.ApplyTorqueImpulse2(PhysBody.ptr, applyImpulse); }); } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index 4b6e9a4..1c7b577 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt @@ -11,12 +11,14 @@ CRASHES VEHICLES TODO LIST: ================================================= -Neb car jiggling left and right - Happens on terrain and any other mesh object. Flat cubes are much smoother. +Neb vehicle taking > 25ms of physics time!! Vehicles (Move smoothly) Add vehicle collisions so IsColliding is properly reported. Needed for banking, limitMotorUp, movementLimiting, ... Some vehicles should not be able to turn if no speed or off ground. +Neb car jiggling left and right + Happens on terrain and any other mesh object. Flat cubes are much smoother. + This has been reduced but not eliminated. For limitMotorUp, use raycast down to find if vehicle is in the air. Implement function efficiency for lineaar and angular motion. Should vehicle angular/linear movement friction happen after all the components @@ -30,6 +32,9 @@ Border crossing with linked vehicle causes crash BULLETSIM TODO LIST: ================================================= +Avatar height off after unsitting (float off ground) + Editting appearance then moving restores. + Must not be initializing height when recreating capsule after unsit. Duplicating a physical prim causes old prim to jump away Dup a phys prim and the original become unselected and thus interacts w/ selected prim. Disable activity of passive linkset children. -- cgit v1.1 From d4e0e98c001c3501ac17849ab78e7ac5a59a5c26 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 11 Dec 2012 13:54:26 -0800 Subject: BulletSim: protect character property setting to remove crash from taints setting properties after the destroy character taint. --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 60 ++++++++++++++-------- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 3 +- 2 files changed, 42 insertions(+), 21 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 88460cc..83c78f6 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -196,8 +196,11 @@ public sealed class BSCharacter : BSPhysObject PhysicsScene.TaintedObject("BSCharacter.setSize", delegate() { - BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale); - UpdatePhysicalMassProperties(RawMass); + if (PhysShape.HasPhysicalShape) + { + BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale); + UpdatePhysicalMassProperties(RawMass); + } }); } @@ -238,7 +241,8 @@ public sealed class BSCharacter : BSPhysObject // Zero some other properties directly into the physics engine PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate() { - BulletSimAPI.ClearAllForces2(PhysBody.ptr); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.ClearAllForces2(PhysBody.ptr); }); } public override void ZeroAngularMotion(bool inTaintTime) @@ -247,10 +251,13 @@ public sealed class BSCharacter : BSPhysObject PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate() { - BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); - BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); - // The next also get rid of applied linear force but the linear velocity is untouched. - BulletSimAPI.ClearForces2(PhysBody.ptr); + if (PhysBody.HasPhysicalBody) + { + BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); + BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); + // The next also get rid of applied linear force but the linear velocity is untouched. + BulletSimAPI.ClearForces2(PhysBody.ptr); + } }); } @@ -275,7 +282,8 @@ public sealed class BSCharacter : BSPhysObject PhysicsScene.TaintedObject("BSCharacter.setPosition", delegate() { DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); - BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); }); } } @@ -334,7 +342,8 @@ public sealed class BSCharacter : BSPhysObject PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.PositionSanityCheck", delegate() { DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); - BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); }); ret = true; } @@ -361,7 +370,8 @@ public sealed class BSCharacter : BSPhysObject PhysicsScene.TaintedObject("BSCharacter.SetForce", delegate() { DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force); - BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); }); } } @@ -400,7 +410,8 @@ public sealed class BSCharacter : BSPhysObject if (_currentFriction != PhysicsScene.Params.avatarStandingFriction) { _currentFriction = PhysicsScene.Params.avatarStandingFriction; - BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); } } else @@ -408,7 +419,8 @@ public sealed class BSCharacter : BSPhysObject if (_currentFriction != PhysicsScene.Params.avatarFriction) { _currentFriction = PhysicsScene.Params.avatarFriction; - BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); } } _velocity = value; @@ -445,8 +457,11 @@ public sealed class BSCharacter : BSPhysObject // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation); PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate() { - // _position = BulletSimAPI.GetPosition2(BSBody.ptr); - BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + if (PhysBody.HasPhysicalBody) + { + // _position = BulletSimAPI.GetPosition2(BSBody.ptr); + BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + } }); } } @@ -519,10 +534,13 @@ public sealed class BSCharacter : BSPhysObject _floatOnWater = value; PhysicsScene.TaintedObject("BSCharacter.setFloatOnWater", delegate() { - if (_floatOnWater) - CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); - else - CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); + if (PhysBody.HasPhysicalBody) + { + if (_floatOnWater) + CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); + else + CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); + } }); } } @@ -555,7 +573,8 @@ public sealed class BSCharacter : BSPhysObject DetailLog("{0},BSCharacter.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); // Buoyancy is faked by changing the gravity applied to the object float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); - BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); } } @@ -601,7 +620,8 @@ public sealed class BSCharacter : BSPhysObject PhysicsScene.TaintedObject("BSCharacter.AddForce", delegate() { DetailLog("{0},BSCharacter.setAddForce,taint,addedForce={1}", LocalID, _force); - BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); }); } else diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 1280c25..446e44c 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -191,7 +191,8 @@ public sealed class BSPrim : BSPhysObject } } public override bool Selected { - set { + set + { if (value != _isSelected) { _isSelected = value; -- cgit v1.1 From a082ce9da78ffb50454834fde4e3dd19e3b5bc74 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 11 Dec 2012 14:27:09 -0800 Subject: BulletSim: fix crash caused by the creation of a linkset child that is under the terrain. Users can sure find some interesting corner conditions. --- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 446e44c..35d22c0 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -332,12 +332,12 @@ public sealed class BSPrim : BSPhysObject float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position); OMV.Vector3 upForce = OMV.Vector3.Zero; - if (Position.Z < terrainHeight) + if (RawPosition.Z < terrainHeight) { DetailLog("{0},BSPrim.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight); float targetHeight = terrainHeight + (Size.Z / 2f); // Upforce proportional to the distance away from the terrain. Correct the error in 1 sec. - upForce.Z = (terrainHeight - Position.Z) * 1f; + upForce.Z = (terrainHeight - RawPosition.Z) * 1f; ret = true; } @@ -345,10 +345,10 @@ public sealed class BSPrim : BSPhysObject { float waterHeight = PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(_position); // TODO: a floating motor so object will bob in the water - if (Math.Abs(Position.Z - waterHeight) > 0.1f) + if (Math.Abs(RawPosition.Z - waterHeight) > 0.1f) { // Upforce proportional to the distance away from the water. Correct the error in 1 sec. - upForce.Z = (waterHeight - Position.Z) * 1f; + upForce.Z = (waterHeight - RawPosition.Z) * 1f; ret = true; } } -- cgit v1.1 From bb6eeb54296246e26594bc06edc3a42c0e5824e9 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 12 Dec 2012 11:01:36 -0800 Subject: BulletSim: do not return the current velocity for targetVelocity. --- OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index d2fc15c..f3b6993 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -139,6 +139,17 @@ public abstract class BSPhysObject : PhysicsActor public abstract OMV.Quaternion RawOrientation { get; set; } public abstract OMV.Quaternion ForceOrientation { get; set; } + // The system is telling us the velocity it wants to move at. + protected OMV.Vector3 m_targetVelocity; + public override OMV.Vector3 TargetVelocity + { + get { return m_targetVelocity; } + set + { + m_targetVelocity = value; + Velocity = value; + } + } public abstract OMV.Vector3 ForceVelocity { get; set; } public abstract OMV.Vector3 ForceRotationalVelocity { get; set; } -- cgit v1.1 From 7bb5613dc665a788e1b151278c20d415f708242a Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 11 Dec 2012 16:46:43 -0800 Subject: BulletSim: updates and rearrangement of the TODO list. --- .../Region/Physics/BulletSPlugin/BulletSimTODO.txt | 47 +++++++++++++++------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index 1c7b577..11c1387 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt @@ -20,6 +20,10 @@ Neb car jiggling left and right Happens on terrain and any other mesh object. Flat cubes are much smoother. This has been reduced but not eliminated. For limitMotorUp, use raycast down to find if vehicle is in the air. +Angular motion around Z moves the vehicle in world Z and not vehicle Z in ODE. + Verify that angular motion specified around Z moves in the vehicle coordinates. +Verify llGetVel() is returning a smooth and good value for vehicle movement. +llGetVel() should return the root's velocity if requested in a child prim. Implement function efficiency for lineaar and angular motion. Should vehicle angular/linear movement friction happen after all the components or does it only apply to the basic movement? @@ -32,19 +36,14 @@ Border crossing with linked vehicle causes crash BULLETSIM TODO LIST: ================================================= -Avatar height off after unsitting (float off ground) +Avatar height off after unsitting (floats off ground) Editting appearance then moving restores. Must not be initializing height when recreating capsule after unsit. Duplicating a physical prim causes old prim to jump away Dup a phys prim and the original become unselected and thus interacts w/ selected prim. -Disable activity of passive linkset children. - Since the linkset is a compound object, the old prims are left lying - around and need to be phantomized so they don't collide, ... Scenes with hundred of thousands of static objects take a lot of physics CPU time. BSPrim.Force should set a continious force on the prim. The force should be applied each tick. Some limits? -Linksets should allow collisions to individual children - Add LocalID to children shapes in LinksetCompound and create events for individuals Gun sending shooter flying. Collision margin (gap between physical objects lying on each other) Boundry checking (crashes related to crossing boundry) @@ -57,14 +56,34 @@ Small physical objects do not interact correctly The chain will fall apart and pairs will dance around on ground Chains of 1x1x.2 will stay connected but will dance. Chains above 2x2x.4 are move stable and get stablier as torui get larger. -Add material type linkage and input all the material property definitions. - Skeleton classes and table are in the sources but are not filled or used. Add PID motor for avatar movement (slow to stop, ...) setForce should set a constant force. Different than AddImpulse. Implement raycast. Implement ShapeCollection.Dispose() Implement water as a plain so raycasting and collisions can happen with same. +Add osGetPhysicsEngineName() so scripters can tell whether BulletSim or ODE + Also osGetPhysicsEngineVerion() maybe. + +LINKSETS +====================================================== +Linksets should allow collisions to individual children + Add LocalID to children shapes in LinksetCompound and create events for individuals +Verify/think through scripts in children of linksets. What do they reference + and return when getting position, velocity, ... +Confirm constraint linksets still work after making all the changes for compound linksets. +Add 'changed' flag or similar to reduce the number of times a linkset is rebuilt. + For compound linksets, add ability to remove or reposition individual child shapes. +Disable activity of passive linkset children. + Since the linkset is a compound object, the old prims are left lying + around and need to be phantomized so they don't collide, ... +Speed up creation of large physical linksets + For instance, sitting in Neb's car (130 prims) takes several seconds to become physical +Eliminate collisions between objects in a linkset. (LinksetConstraint) + Have UserPointer point to struct with localID and linksetID? + Objects in original linkset still collide with each other? +MORE +====================================================== Find/remove avatar collision with ID=0. Test avatar walking up stairs. How does compare with SL. Radius of the capsule affects ability to climb edges. @@ -73,8 +92,6 @@ Debounce avatar contact so legs don't keep folding up when standing. Implement LSL physics controls. Like STATUS_ROTATE_X. Add border extensions to terrain to help region crossings and objects leaving region. -Speed up creation of large physical linksets - For instance, sitting in Neb's car (130 prims) takes several seconds to become physical Performance test with lots of avatars. Can BulletSim support a thousand? Optimize collisions in C++: only send up to the object subscribed to collisions. Use collision subscription and remove the collsion(A,B) and collision(B,A) @@ -85,10 +102,6 @@ Avatar jump Performance measurement and changes to make quicker. Implement detailed physics stats (GetStats()). -Eliminate collisions between objects in a linkset. (LinksetConstraint) - Have UserPointer point to struct with localID and linksetID? - Objects in original linkset still collide with each other? - Measure performance improvement from hulls Test not using ghost objects for volume detect implementation. Performance of closures and delegates for taint processing @@ -101,6 +114,9 @@ Physics Arena central pyramid: why is one side permiable? INTERNAL IMPROVEMENT/CLEANUP ================================================= +Consider moving prim/character body and shape destruction in destroy() + to postTimeTime rather than protecting all the potential sets that + might have been queued up. Remove unused fields from ShapeData (not used in API2) Breakout code for mesh/hull/compound/native into separate BSShape* classes Standardize access to building and reference code. @@ -154,3 +170,6 @@ Package Bullet source mods for Bullet internal stats output (Resolution: move code into WorldData.h rather than relying on patches) Single prim vehicles don't seem to properly vehiclize. (Resolution: mass was not getting set properly for single prim linksets) +Add material type linkage and input all the material property definitions. + Skeleton classes and table are in the sources but are not filled or used. + (Resolution: -- cgit v1.1 From 6f1f7f02065520d061745afff9b1ed1bd672d87b Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 12 Dec 2012 15:07:17 -0800 Subject: BulletSim: non-functional commenting and reorganization of material attribute specifications. --- .../Region/Physics/BulletSPlugin/BSMaterials.cs | 81 +++++++++++++--------- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 1 + 2 files changed, 49 insertions(+), 33 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs index 390c2f9..c113a43 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs @@ -50,10 +50,11 @@ public struct MaterialAttributes Avatar, NumberOfTypes // the count of types in the enum. } + // Names must be in the order of the above enum. - public static string[] MaterialNames = { "Stone", "Metal", "Glass", "Wood", - "Flesh", "Plastic", "Rubber", "Light", "Avatar" }; - public static string[] MaterialAttribs = { "Density", "Friction", "Restitution"}; + // These names must coorespond to the lower case field names in the MaterialAttributes + // structure as reflection is used to select the field to put the value in. + public static readonly string[] MaterialAttribs = { "Density", "Friction", "Restitution"}; public MaterialAttributes(string t, float d, float f, float r) { @@ -70,60 +71,74 @@ public struct MaterialAttributes public static class BSMaterials { - public static MaterialAttributes[] Attributes; + // Attributes for each material type + private static readonly MaterialAttributes[] Attributes; + + // Map of material name to material type code + public static readonly Dictionary MaterialMap; static BSMaterials() { // Attribute sets for both the non-physical and physical instances of materials. Attributes = new MaterialAttributes[(int)MaterialAttributes.Material.NumberOfTypes * 2]; + + // Map of name to type code. + MaterialMap = new Dictionary(); + MaterialMap.Add("Stone", MaterialAttributes.Material.Stone); + MaterialMap.Add("Metal", MaterialAttributes.Material.Metal); + MaterialMap.Add("Glass", MaterialAttributes.Material.Glass); + MaterialMap.Add("Wood", MaterialAttributes.Material.Wood); + MaterialMap.Add("Flesh", MaterialAttributes.Material.Flesh); + MaterialMap.Add("Plastic", MaterialAttributes.Material.Plastic); + MaterialMap.Add("Rubber", MaterialAttributes.Material.Rubber); + MaterialMap.Add("Light", MaterialAttributes.Material.Light); + MaterialMap.Add("Avatar", MaterialAttributes.Material.Avatar); } // This is where all the default material attributes are defined. public static void InitializeFromDefaults(ConfigurationParameters parms) { // Values from http://wiki.secondlife.com/wiki/PRIM_MATERIAL - // public static string[] MaterialNames = { "Stone", "Metal", "Glass", "Wood", - // "Flesh", "Plastic", "Rubber", "Light", "Avatar" }; + float dDensity = parms.defaultDensity; float dFriction = parms.defaultFriction; float dRestitution = parms.defaultRestitution; - float dDensity = parms.defaultDensity; Attributes[(int)MaterialAttributes.Material.Stone] = - new MaterialAttributes("stone",dDensity, 0.8f, 0.4f); + new MaterialAttributes("stone",dDensity, 0.8f, 0.4f); Attributes[(int)MaterialAttributes.Material.Metal] = - new MaterialAttributes("metal",dDensity, 0.3f, 0.4f); + new MaterialAttributes("metal",dDensity, 0.3f, 0.4f); Attributes[(int)MaterialAttributes.Material.Glass] = - new MaterialAttributes("glass",dDensity, 0.2f, 0.7f); + new MaterialAttributes("glass",dDensity, 0.2f, 0.7f); Attributes[(int)MaterialAttributes.Material.Wood] = - new MaterialAttributes("wood",dDensity, 0.6f, 0.5f); + new MaterialAttributes("wood",dDensity, 0.6f, 0.5f); Attributes[(int)MaterialAttributes.Material.Flesh] = - new MaterialAttributes("flesh",dDensity, 0.9f, 0.3f); + new MaterialAttributes("flesh",dDensity, 0.9f, 0.3f); Attributes[(int)MaterialAttributes.Material.Plastic] = - new MaterialAttributes("plastic",dDensity, 0.4f, 0.7f); + new MaterialAttributes("plastic",dDensity, 0.4f, 0.7f); Attributes[(int)MaterialAttributes.Material.Rubber] = - new MaterialAttributes("rubber",dDensity, 0.9f, 0.9f); + new MaterialAttributes("rubber",dDensity, 0.9f, 0.9f); Attributes[(int)MaterialAttributes.Material.Light] = - new MaterialAttributes("light",dDensity, dFriction, dRestitution); + new MaterialAttributes("light",dDensity, dFriction, dRestitution); Attributes[(int)MaterialAttributes.Material.Avatar] = - new MaterialAttributes("avatar",60f, 0.2f, 0f); + new MaterialAttributes("avatar",60f, 0.2f, 0f); Attributes[(int)MaterialAttributes.Material.Stone + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("stonePhysical",dDensity, 0.8f, 0.4f); + new MaterialAttributes("stonePhysical",dDensity, 0.8f, 0.4f); Attributes[(int)MaterialAttributes.Material.Metal + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("metalPhysical",dDensity, 0.8f, 0.4f); + new MaterialAttributes("metalPhysical",dDensity, 0.8f, 0.4f); Attributes[(int)MaterialAttributes.Material.Glass + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("glassPhysical",dDensity, 0.8f, 0.7f); + new MaterialAttributes("glassPhysical",dDensity, 0.8f, 0.7f); Attributes[(int)MaterialAttributes.Material.Wood + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("woodPhysical",dDensity, 0.8f, 0.5f); + new MaterialAttributes("woodPhysical",dDensity, 0.8f, 0.5f); Attributes[(int)MaterialAttributes.Material.Flesh + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("fleshPhysical",dDensity, 0.8f, 0.3f); + new MaterialAttributes("fleshPhysical",dDensity, 0.8f, 0.3f); Attributes[(int)MaterialAttributes.Material.Plastic + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("plasticPhysical",dDensity, 0.8f, 0.7f); + new MaterialAttributes("plasticPhysical",dDensity, 0.8f, 0.7f); Attributes[(int)MaterialAttributes.Material.Rubber + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("rubberPhysical",dDensity, 0.8f, 0.9f); + new MaterialAttributes("rubberPhysical",dDensity, 0.8f, 0.9f); Attributes[(int)MaterialAttributes.Material.Light + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("lightPhysical",dDensity, dFriction, dRestitution); + new MaterialAttributes("lightPhysical",dDensity, dFriction, dRestitution); Attributes[(int)MaterialAttributes.Material.Avatar + (int)MaterialAttributes.Material.NumberOfTypes] = - new MaterialAttributes("avatarPhysical",60f, 0.2f, 0f); + new MaterialAttributes("avatarPhysical",60f, 0.2f, 0f); } // Under the [BulletSim] section, one can change the individual material @@ -139,34 +154,34 @@ public static class BSMaterials // the physical value. public static void InitializefromParameters(IConfig pConfig) { - int matType = 0; - foreach (string matName in MaterialAttributes.MaterialNames) + foreach (KeyValuePair kvp in MaterialMap) { + string matName = kvp.Key; foreach (string attribName in MaterialAttributes.MaterialAttribs) { string paramName = matName + attribName; if (pConfig.Contains(paramName)) { float paramValue = pConfig.GetFloat(paramName); - SetAttributeValue(matType, attribName, paramValue); + SetAttributeValue((int)kvp.Value, attribName, paramValue); // set the physical value also - SetAttributeValue(matType + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); + SetAttributeValue((int)kvp.Value + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); } paramName += "Physical"; if (pConfig.Contains(paramName)) { float paramValue = pConfig.GetFloat(paramName); - SetAttributeValue(matType + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); + SetAttributeValue((int)kvp.Value + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); } } - matType++; } } + // Use reflection to set the value in the attribute structure. private static void SetAttributeValue(int matType, string attribName, float val) { MaterialAttributes thisAttrib = Attributes[matType]; - FieldInfo fieldInfo = thisAttrib.GetType().GetField(attribName); + FieldInfo fieldInfo = thisAttrib.GetType().GetField(attribName.ToLower()); if (fieldInfo != null) { fieldInfo.SetValue(thisAttrib, val); @@ -174,12 +189,12 @@ public static class BSMaterials } } + // Given a material type, return a structure of attributes. public static MaterialAttributes GetAttributes(MaterialAttributes.Material type, bool isPhysical) { int ind = (int)type; if (isPhysical) ind += (int)MaterialAttributes.Material.NumberOfTypes; return Attributes[ind]; } - } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index f4f2801..cf5bb57 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -309,6 +309,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters BSMaterials.InitializeFromDefaults(Params); if (pConfig != null) { + // Let the user add new and interesting material property values. BSMaterials.InitializefromParameters(pConfig); } } -- cgit v1.1 From e1814aa827c2d0af21d087bd34e3c7f4f7cf25bd Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 12 Dec 2012 16:29:03 -0800 Subject: BulletSim: fix problem of avatar's floating off the ground after unsitting. Reworked size/scale logic so physical scale is kept in Bullet and physObject scale is the preferred size -- usually same as size but avatars are computed differently. --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 18 +++++++++-------- .../Region/Physics/BulletSPlugin/BSPhysObject.cs | 2 +- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 8 ++------ .../Physics/BulletSPlugin/BSShapeCollection.cs | 23 +++++++++++++--------- 4 files changed, 27 insertions(+), 24 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 83c78f6..c8aad8d 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -105,12 +105,12 @@ public sealed class BSCharacter : BSPhysObject DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5}", LocalID, _size, Scale, _avatarDensity, _avatarVolume, RawMass); - // do actual create at taint time + // do actual creation in taint time PhysicsScene.TaintedObject("BSCharacter.create", delegate() { DetailLog("{0},BSCharacter.create,taint", LocalID); // New body and shape into PhysBody and PhysShape - PhysicsScene.Shapes.GetBodyAndShape(true, PhysicsScene.World, this, null, null); + PhysicsScene.Shapes.GetBodyAndShape(true, PhysicsScene.World, this); SetPhysicalProperties(); }); @@ -189,6 +189,11 @@ public sealed class BSCharacter : BSPhysObject set { // When an avatar's size is set, only the height is changed. _size = value; + // Old versions of ScenePresence passed only the height. If width and/or depth are zero, + // replace with the default values. + if (_size.X == 0f) _size.X = PhysicsScene.Params.avatarCapsuleDepth; + if (_size.Y == 0f) _size.Y = PhysicsScene.Params.avatarCapsuleWidth; + ComputeAvatarScale(_size); ComputeAvatarVolumeAndMass(); DetailLog("{0},BSCharacter.setSize,call,size={1},scale={2},density={3},volume={4},mass={5}", @@ -196,18 +201,18 @@ public sealed class BSCharacter : BSPhysObject PhysicsScene.TaintedObject("BSCharacter.setSize", delegate() { - if (PhysShape.HasPhysicalShape) + if (PhysBody.HasPhysicalBody && PhysShape.HasPhysicalShape) { BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale); UpdatePhysicalMassProperties(RawMass); + // Make sure this change appears as a property update event + BulletSimAPI.PushUpdate2(PhysBody.ptr); } }); } } - public override OMV.Vector3 Scale { get; set; } - public override PrimitiveBaseShape Shape { set { BaseShape = value; } @@ -638,9 +643,6 @@ public sealed class BSCharacter : BSPhysObject private void ComputeAvatarScale(OMV.Vector3 size) { - // The 'size' given by the simulator is the mid-point of the avatar - // and X and Y are unspecified. - OMV.Vector3 newScale = size; // newScale.X = PhysicsScene.Params.avatarCapsuleWidth; // newScale.Y = PhysicsScene.Params.avatarCapsuleDepth; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index f3b6993..6539b43 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -109,7 +109,7 @@ public abstract class BSPhysObject : PhysicsActor public EntityProperties CurrentEntityProperties { get; set; } public EntityProperties LastEntityProperties { get; set; } - public abstract OMV.Vector3 Scale { get; set; } + public virtual OMV.Vector3 Scale { get; set; } public abstract bool IsSolid { get; } public abstract bool IsStatic { get; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 35d22c0..19c29cc 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -45,7 +45,6 @@ public sealed class BSPrim : BSPhysObject private static readonly string LogHeader = "[BULLETS PRIM]"; // _size is what the user passed. Scale is what we pass to the physics engine with the mesh. - // Often Scale is unity because the meshmerizer will apply _size when creating the mesh. private OMV.Vector3 _size; // the multiplier for each mesh dimension as passed by the user private bool _grabbed; @@ -93,7 +92,7 @@ public sealed class BSPrim : BSPhysObject _physicsActorType = (int)ActorTypes.Prim; _position = pos; _size = size; - Scale = size; // the scale will be set by CreateGeom depending on object type + Scale = size; // prims are the size the user wants them to be (different for BSCharactes). _orientation = rotation; _buoyancy = 1f; _velocity = OMV.Vector3.Zero; @@ -159,12 +158,10 @@ public sealed class BSPrim : BSPhysObject // We presume the scale and size are the same. If scale must be changed for // the physical shape, that is done when the geometry is built. _size = value; + Scale = _size; ForceBodyShapeRebuild(false); } } - // Scale is what we set in the physics engine. It is different than 'size' in that - // 'size' can be encorporated into the mesh. In that case, the scale is <1,1,1>. - public override OMV.Vector3 Scale { get; set; } public override PrimitiveBaseShape Shape { set { @@ -1369,7 +1366,6 @@ public sealed class BSPrim : BSPhysObject // Create the correct physical representation for this type of object. // Updates PhysBody and PhysShape with the new information. // Ignore 'forceRebuild'. This routine makes the right choices and changes of necessary. - // Returns 'true' if either the body or the shape was changed. PhysicsScene.Shapes.GetBodyAndShape(false, PhysicsScene.World, this, null, delegate(BulletBody dBody) { // Called if the current prim body is about to be destroyed. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 4ab9a99..ea996ae 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs @@ -126,6 +126,11 @@ public sealed class BSShapeCollection : IDisposable return ret; } + public bool GetBodyAndShape(bool forceRebuild, BulletSim sim, BSPhysObject prim) + { + return GetBodyAndShape(forceRebuild, sim, prim, null, null); + } + // Track another user of a body. // We presume the caller has allocated the body. // Bodies only have one user so the body is just put into the world if not already there. @@ -460,6 +465,11 @@ public sealed class BSShapeCollection : IDisposable && pbs.PathScaleX == 100 && pbs.PathScaleY == 100 && pbs.PathShearX == 0 && pbs.PathShearY == 0) ) ) { + // Get the scale of any existing shape so we can see if the new shape is same native type and same size. + OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero; + if (prim.PhysShape.HasPhysicalShape) + scaleOfExistingShape = BulletSimAPI.GetLocalScaling2(prim.PhysShape.ptr); + if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}", prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.type); @@ -469,7 +479,7 @@ public sealed class BSShapeCollection : IDisposable { haveShape = true; if (forceRebuild - || prim.Scale != prim.Size + || prim.Scale != scaleOfExistingShape || prim.PhysShape.type != BSPhysicsShapeType.SHAPE_SPHERE ) { @@ -483,7 +493,7 @@ public sealed class BSShapeCollection : IDisposable { haveShape = true; if (forceRebuild - || prim.Scale != prim.Size + || prim.Scale != scaleOfExistingShape || prim.PhysShape.type != BSPhysicsShapeType.SHAPE_BOX ) { @@ -542,7 +552,6 @@ public sealed class BSShapeCollection : IDisposable prim.LocalID, newShape, prim.Scale); // native shapes are scaled by Bullet - prim.Scale = prim.Size; prim.PhysShape = newShape; return true; } @@ -555,8 +564,8 @@ public sealed class BSShapeCollection : IDisposable ShapeData nativeShapeData = new ShapeData(); nativeShapeData.Type = shapeType; nativeShapeData.ID = prim.LocalID; - nativeShapeData.Scale = prim.Size; - nativeShapeData.Size = prim.Size; // unneeded, I think. + nativeShapeData.Scale = prim.Scale; + nativeShapeData.Size = prim.Scale; // unneeded, I think. nativeShapeData.MeshKey = (ulong)shapeKey; nativeShapeData.HullKey = (ulong)shapeKey; @@ -611,8 +620,6 @@ public sealed class BSShapeCollection : IDisposable ReferenceShape(newShape); - // meshes are already scaled by the meshmerizer - prim.Scale = new OMV.Vector3(1f, 1f, 1f); prim.PhysShape = newShape; return true; // 'true' means a new shape has been added to this prim @@ -683,8 +690,6 @@ public sealed class BSShapeCollection : IDisposable ReferenceShape(newShape); - // hulls are already scaled by the meshmerizer - prim.Scale = new OMV.Vector3(1f, 1f, 1f); prim.PhysShape = newShape; return true; // 'true' means a new shape has been added to this prim } -- cgit v1.1 From 9e0dd9952b76fdda337e518932a1ef57f8215986 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Thu, 13 Dec 2012 12:42:09 -0800 Subject: BulletSim: remove extra linkset rebuilds. --- .../Physics/BulletSPlugin/BSLinksetCompound.cs | 54 ++++++++++++++-------- 1 file changed, 36 insertions(+), 18 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index d2abdb4..6cabe3a 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs @@ -114,6 +114,12 @@ public sealed class BSLinksetCompound : BSLinkset { // The root is going dynamic. Make sure mass is properly set. m_mass = ComputeLinksetMass(); + if (HasAnyChildren) + { + // Schedule a rebuilding as this will construct the complete compound shape + // and set all the properties correctly. + InternalRefresh(LinksetRoot); + } } else { @@ -123,6 +129,9 @@ public sealed class BSLinksetCompound : BSLinkset BulletSimAPI.ForceActivationState2(child.PhysBody.ptr, ActivationState.DISABLE_SIMULATION); // We don't want collisions from the old linkset children. BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); + + child.PhysBody.collisionType = CollisionType.LinksetChild; + ret = true; } return ret; @@ -137,10 +146,21 @@ public sealed class BSLinksetCompound : BSLinkset { bool ret = false; DetailLog("{0},BSLinksetCompound.MakeStatic,call,IsRoot={1}", child.LocalID, IsRoot(child)); - if (!IsRoot(child)) + if (IsRoot(child)) + { + if (HasAnyChildren) + { + // Schedule a rebuilding as this will construct the complete compound shape + // and set all the properties correctly. + InternalRefresh(LinksetRoot); + } + } + else { // The non-physical children can come back to life. BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); + child.PhysBody.collisionType = CollisionType.LinksetChild; + // Don't force activation so setting of DISABLE_SIMULATION can stay if used. BulletSimAPI.Activate2(child.PhysBody.ptr, false); ret = true; @@ -182,19 +202,25 @@ public sealed class BSLinksetCompound : BSLinkset // Because it is a convenient time, recompute child world position and rotation based on // its position in the linkset. RecomputeChildWorldPosition(child, true); - - // Cause the current shape to be freed and the new one to be built. - InternalRefresh(LinksetRoot); - ret = true; } + // Cannot schedule a refresh/rebuild here because this routine is called when + // the linkset is being rebuilt. + // InternalRefresh(LinksetRoot); + return ret; } - // When the linkset is built, the child shape is added - // to the compound shape relative to the root shape. The linkset then moves around but - // this does not move the actual child prim. The child prim's location must be recomputed - // based on the location of the root shape. + // Companion to RemoveBodyDependencies(). If RemoveBodyDependencies() returns 'true', + // this routine will restore the removed constraints. + // Called at taint-time!! + public override void RestoreBodyDependencies(BSPrim child) + { + } + + // When the linkset is built, the child shape is added to the compound shape relative to the + // root shape. The linkset then moves around but this does not move the actual child + // prim. The child prim's location must be recomputed based on the location of the root shape. private void RecomputeChildWorldPosition(BSPhysObject child, bool inTaintTime) { BSLinksetCompoundInfo lci = child.LinksetInfo as BSLinksetCompoundInfo; @@ -227,14 +253,6 @@ public sealed class BSLinksetCompound : BSLinkset } } - // Companion to RemoveBodyDependencies(). If RemoveBodyDependencies() returns 'true', - // this routine will restore the removed constraints. - // Called at taint-time!! - public override void RestoreBodyDependencies(BSPrim child) - { - // The Refresh operation queued by RemoveBodyDependencies() will build any missing constraints. - } - // ================================================================ // Add a new child to the linkset. @@ -254,7 +272,7 @@ public sealed class BSLinksetCompound : BSLinkset } // Remove the specified child from the linkset. - // Safe to call even if the child is not really in my linkset. + // Safe to call even if the child is not really in the linkset. protected override void RemoveChildFromLinkset(BSPhysObject child) { if (m_children.Remove(child)) -- cgit v1.1 From 3b2b785a461eba34c26a45be246c2baef2820e39 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Thu, 13 Dec 2012 12:42:25 -0800 Subject: BulletSim: Add 'BulletSimData' which separates structures created for the operation of BulletSim and those defintiions/structures defined so they can be used in the unmanaged world. Consolidate setting of collision flags so implementation is not scattered. --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 5 +- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 29 +-- .../Physics/BulletSPlugin/BSTerrainHeightmap.cs | 5 +- .../Physics/BulletSPlugin/BSTerrainManager.cs | 4 +- .../Region/Physics/BulletSPlugin/BSTerrainMesh.cs | 5 +- .../Region/Physics/BulletSPlugin/BulletSimAPI.cs | 183 +------------ .../Region/Physics/BulletSPlugin/BulletSimData.cs | 282 +++++++++++++++++++++ 7 files changed, 308 insertions(+), 205 deletions(-) create mode 100755 OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index c8aad8d..0defb24 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -167,9 +167,8 @@ public sealed class BSCharacter : BSPhysObject BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); // Do this after the object has been added to the world - BulletSimAPI.SetCollisionGroupMask2(PhysBody.ptr, - (uint)CollisionFilterGroups.AvatarGroup, - (uint)CollisionFilterGroups.AvatarMask); + PhysBody.collisionType = CollisionType.Avatar; + PhysBody.ApplyCollisionMask(); } public override void RequestPhysicsterseUpdate() diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 19c29cc..c9c9c2c 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -661,14 +661,7 @@ public sealed class BSPrim : BSPhysObject BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); // Collision filter can be set only when the object is in the world - if (PhysBody.collisionGroup != 0 || PhysBody.collisionMask != 0) - { - if (!BulletSimAPI.SetCollisionGroupMask2(PhysBody.ptr, (uint)PhysBody.collisionGroup, (uint)PhysBody.collisionMask)) - { - PhysicsScene.Logger.ErrorFormat("{0} Failure setting prim collision mask. localID={1}, grp={2:X}, mask={3:X}", - LogHeader, LocalID, PhysBody.collisionGroup, PhysBody.collisionMask); - } - } + PhysBody.ApplyCollisionMask(); // Recompute any linkset parameters. // When going from non-physical to physical, this re-enables the constraints that @@ -713,11 +706,11 @@ public sealed class BSPrim : BSPhysObject // Start it out sleeping and physical actions could wake it up. BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ISLAND_SLEEPING); + // This collides like a static object + PhysBody.collisionType = CollisionType.Static; + // There can be special things needed for implementing linksets Linkset.MakeStatic(this); - - PhysBody.collisionGroup = CollisionFilterGroups.StaticObjectGroup; - PhysBody.collisionMask = CollisionFilterGroups.StaticObjectMask; } else { @@ -755,16 +748,15 @@ public sealed class BSPrim : BSPhysObject BulletSimAPI.SetSleepingThresholds2(PhysBody.ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold); BulletSimAPI.SetContactProcessingThreshold2(PhysBody.ptr, PhysicsScene.Params.contactProcessingThreshold); - // There might be special things needed for implementing linksets. - Linkset.MakeDynamic(this); + // This collides like an object. + PhysBody.collisionType = CollisionType.Dynamic; // Force activation of the object so Bullet will act on it. // Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects. BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ACTIVE_TAG); - // BulletSimAPI.Activate2(BSBody.ptr, true); - PhysBody.collisionGroup = CollisionFilterGroups.ObjectGroup; - PhysBody.collisionMask = CollisionFilterGroups.ObjectMask; + // There might be special things needed for implementing linksets. + Linkset.MakeDynamic(this); } } @@ -791,8 +783,9 @@ public sealed class BSPrim : BSPhysObject m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for non-solidness. id={1}, type={2}", LogHeader, LocalID, bodyType); } CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); - PhysBody.collisionGroup = CollisionFilterGroups.VolumeDetectGroup; - PhysBody.collisionMask = CollisionFilterGroups.VolumeDetectMask; + + // Change collision info from a static object to a ghosty collision object + PhysBody.collisionType = CollisionType.VolumeDetect; } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs index 2d379bb..2b120d6 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs @@ -121,9 +121,8 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys // redo its bounding box now that it is in the world BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); - BulletSimAPI.SetCollisionGroupMask2(m_mapInfo.terrainBody.ptr, - (uint)CollisionFilterGroups.TerrainGroup, - (uint)CollisionFilterGroups.TerrainMask); + m_mapInfo.terrainBody.collisionType = CollisionType.Terrain; + m_mapInfo.terrainBody.ApplyCollisionMask(); // Make it so the terrain will not move or be considered for movement. BulletSimAPI.ForceActivationState2(m_mapInfo.terrainBody.ptr, ActivationState.DISABLE_SIMULATION); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs index c28d69d..5dbd8ce 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs @@ -140,8 +140,8 @@ public sealed class BSTerrainManager // Ground plane does not move BulletSimAPI.ForceActivationState2(m_groundPlane.ptr, ActivationState.DISABLE_SIMULATION); // Everything collides with the ground plane. - BulletSimAPI.SetCollisionGroupMask2(m_groundPlane.ptr, - (uint)CollisionFilterGroups.GroundPlaneGroup, (uint)CollisionFilterGroups.GroundPlaneMask); + m_groundPlane.collisionType = CollisionType.Groundplane; + m_groundPlane.ApplyCollisionMask(); // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain. BSTerrainPhys initialTerrain = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs index 3473006..6dc0d92 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs @@ -130,9 +130,8 @@ public sealed class BSTerrainMesh : BSTerrainPhys // Redo its bounding box now that it is in the world BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_terrainBody.ptr); - BulletSimAPI.SetCollisionGroupMask2(m_terrainBody.ptr, - (uint)CollisionFilterGroups.TerrainGroup, - (uint)CollisionFilterGroups.TerrainMask); + m_terrainBody.collisionType = CollisionType.Terrain; + m_terrainBody.ApplyCollisionMask(); // Make it so the terrain will not move or be considered for movement. BulletSimAPI.ForceActivationState2(m_terrainBody.ptr, ActivationState.DISABLE_SIMULATION); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs index 1559025..962b540 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ using System; +using System.Collections.Generic; using System.Runtime.InteropServices; using System.Security; using System.Text; @@ -32,110 +33,6 @@ using OpenMetaverse; namespace OpenSim.Region.Physics.BulletSPlugin { -// Classes to allow some type checking for the API -// These hold pointers to allocated objects in the unmanaged space. - -// The physics engine controller class created at initialization -public struct BulletSim -{ - public BulletSim(uint worldId, BSScene bss, IntPtr xx) - { - ptr = xx; - worldID = worldId; - physicsScene = bss; - } - public IntPtr ptr; - public uint worldID; - // The scene is only in here so very low level routines have a handle to print debug/error messages - public BSScene physicsScene; -} - -// An allocated Bullet btRigidBody -public struct BulletBody -{ - public BulletBody(uint id) : this(id, IntPtr.Zero) - { - } - public BulletBody(uint id, IntPtr xx) - { - ID = id; - ptr = xx; - collisionGroup = 0; - collisionMask = 0; - } - public IntPtr ptr; - public uint ID; - public CollisionFilterGroups collisionGroup; - public CollisionFilterGroups collisionMask; - - public void Clear() - { - ptr = IntPtr.Zero; - } - public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } } - - public override string ToString() - { - StringBuilder buff = new StringBuilder(); - buff.Append(""); - return buff.ToString(); - } -} - -public struct BulletShape -{ - public BulletShape(IntPtr xx) - { - ptr = xx; - type=BSPhysicsShapeType.SHAPE_UNKNOWN; - shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; - isNativeShape = false; - } - public BulletShape(IntPtr xx, BSPhysicsShapeType typ) - { - ptr = xx; - type = typ; - shapeKey = 0; - isNativeShape = false; - } - public IntPtr ptr; - public BSPhysicsShapeType type; - public System.UInt64 shapeKey; - public bool isNativeShape; - - public void Clear() - { - ptr = IntPtr.Zero; - } - public bool HasPhysicalShape { get { return ptr != IntPtr.Zero; } } - - public override string ToString() - { - StringBuilder buff = new StringBuilder(); - buff.Append(""); - return buff.ToString(); - } -} - // Constraint type values as defined by Bullet public enum ConstraintType : int { @@ -149,50 +46,6 @@ public enum ConstraintType : int MAX_CONSTRAINT_TYPE } -// An allocated Bullet btConstraint -public struct BulletConstraint -{ - public BulletConstraint(IntPtr xx) - { - ptr = xx; - } - public IntPtr ptr; - - public void Clear() - { - ptr = IntPtr.Zero; - } - public bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } } -} - -// An allocated HeightMapThing which holds various heightmap info. -// Made a class rather than a struct so there would be only one -// instance of this and C# will pass around pointers rather -// than making copies. -public class BulletHeightMapInfo -{ - public BulletHeightMapInfo(uint id, float[] hm, IntPtr xx) { - ID = id; - Ptr = xx; - heightMap = hm; - terrainRegionBase = Vector3.Zero; - minCoords = new Vector3(100f, 100f, 25f); - maxCoords = new Vector3(101f, 101f, 26f); - minZ = maxZ = 0f; - sizeX = sizeY = 256f; - } - public uint ID; - public IntPtr Ptr; - public float[] heightMap; - public Vector3 terrainRegionBase; - public Vector3 minCoords; - public Vector3 maxCoords; - public float sizeX, sizeY; - public float minZ, maxZ; - public BulletShape terrainShape; - public BulletBody terrainBody; -} - // =============================================================================== [StructLayout(LayoutKind.Sequential)] public struct ConvexHull @@ -385,21 +238,15 @@ public enum CollisionFlags : uint BS_FLOATS_ON_WATER = 1 << 11, BS_VEHICLE_COLLISIONS = 1 << 12, BS_NONE = 0, - BS_ALL = 0xFFFFFFFF, - - // These are the collision flags switched depending on physical state. - // The other flags are used for other things and should not be fooled with. - BS_ACTIVE = CF_STATIC_OBJECT - | CF_KINEMATIC_OBJECT - | CF_NO_CONTACT_RESPONSE + BS_ALL = 0xFFFFFFFF }; -// Values for collisions groups and masks +// Values f collisions groups and masks public enum CollisionFilterGroups : uint { // Don't use the bit definitions!! Define the use in a // filter/mask definition below. This way collision interactions - // are more easily debugged. + // are more easily found and debugged. BNoneGroup = 0, BDefaultGroup = 1 << 0, BStaticGroup = 1 << 1, @@ -413,24 +260,8 @@ public enum CollisionFilterGroups : uint BTerrainGroup = 1 << 11, BRaycastGroup = 1 << 12, BSolidGroup = 1 << 13, - BLinksetGroup = 1 << 14, - - // The collsion filters and masked are defined in one place -- don't want them scattered - AvatarGroup = BCharacterGroup, - AvatarMask = BAllGroup, - ObjectGroup = BSolidGroup, - ObjectMask = BAllGroup, - StaticObjectGroup = BStaticGroup, - StaticObjectMask = AvatarGroup | ObjectGroup, // static things don't interact with much - LinksetGroup = BLinksetGroup, - LinksetMask = BAllGroup & ~BLinksetGroup, // linkset objects don't collide with each other - VolumeDetectGroup = BSensorTrigger, - VolumeDetectMask = ~BSensorTrigger, - TerrainGroup = BTerrainGroup, - TerrainMask = BAllGroup & ~BStaticGroup, // static objects on the ground don't collide - GroundPlaneGroup = BGroundPlaneGroup, - GroundPlaneMask = BAllGroup - + // BLinksetGroup = xx // a linkset proper is either static or dynamic + BLinksetChildGroup = 1 << 14, }; // CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0 @@ -457,7 +288,7 @@ public enum ConstraintParamAxis : int // =============================================================================== static class BulletSimAPI { - +// =============================================================================== // Link back to the managed code for outputting log messages [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs new file mode 100755 index 0000000..e5c4777 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs @@ -0,0 +1,282 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyrightD + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +using System; +using System.Collections.Generic; +using System.Text; +using OMV = OpenMetaverse; + +namespace OpenSim.Region.Physics.BulletSPlugin +{ +// Classes to allow some type checking for the API +// These hold pointers to allocated objects in the unmanaged space. + +// The physics engine controller class created at initialization +public struct BulletSim +{ + public BulletSim(uint worldId, BSScene bss, IntPtr xx) + { + ptr = xx; + worldID = worldId; + physicsScene = bss; + } + public IntPtr ptr; + public uint worldID; + // The scene is only in here so very low level routines have a handle to print debug/error messages + public BSScene physicsScene; +} + +// An allocated Bullet btRigidBody +public struct BulletBody +{ + public BulletBody(uint id) : this(id, IntPtr.Zero) + { + } + public BulletBody(uint id, IntPtr xx) + { + ID = id; + ptr = xx; + collisionType = CollisionType.Static; + } + public IntPtr ptr; + public uint ID; + public CollisionType collisionType; + + public void Clear() + { + ptr = IntPtr.Zero; + } + public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } } + + // Apply the specificed collision mask into the physical world + public void ApplyCollisionMask() + { + // Should assert the body has been added to the physical world. + // (The collision masks are stored in the collision proxy cache which only exists for + // a collision body that is in the world.) + BulletSimAPI.SetCollisionGroupMask2(ptr, + BulletSimData.CollisionTypeMasks[collisionType].group, + BulletSimData.CollisionTypeMasks[collisionType].mask); + } + + public override string ToString() + { + StringBuilder buff = new StringBuilder(); + buff.Append(""); + return buff.ToString(); + } +} + +public struct BulletShape +{ + public BulletShape(IntPtr xx) + { + ptr = xx; + type=BSPhysicsShapeType.SHAPE_UNKNOWN; + shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; + isNativeShape = false; + } + public BulletShape(IntPtr xx, BSPhysicsShapeType typ) + { + ptr = xx; + type = typ; + shapeKey = 0; + isNativeShape = false; + } + public IntPtr ptr; + public BSPhysicsShapeType type; + public System.UInt64 shapeKey; + public bool isNativeShape; + + public void Clear() + { + ptr = IntPtr.Zero; + } + public bool HasPhysicalShape { get { return ptr != IntPtr.Zero; } } + + public override string ToString() + { + StringBuilder buff = new StringBuilder(); + buff.Append(""); + return buff.ToString(); + } +} + +// An allocated Bullet btConstraint +public struct BulletConstraint +{ + public BulletConstraint(IntPtr xx) + { + ptr = xx; + } + public IntPtr ptr; + + public void Clear() + { + ptr = IntPtr.Zero; + } + public bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } } +} + +// An allocated HeightMapThing which holds various heightmap info. +// Made a class rather than a struct so there would be only one +// instance of this and C# will pass around pointers rather +// than making copies. +public class BulletHeightMapInfo +{ + public BulletHeightMapInfo(uint id, float[] hm, IntPtr xx) { + ID = id; + Ptr = xx; + heightMap = hm; + terrainRegionBase = OMV.Vector3.Zero; + minCoords = new OMV.Vector3(100f, 100f, 25f); + maxCoords = new OMV.Vector3(101f, 101f, 26f); + minZ = maxZ = 0f; + sizeX = sizeY = 256f; + } + public uint ID; + public IntPtr Ptr; + public float[] heightMap; + public OMV.Vector3 terrainRegionBase; + public OMV.Vector3 minCoords; + public OMV.Vector3 maxCoords; + public float sizeX, sizeY; + public float minZ, maxZ; + public BulletShape terrainShape; + public BulletBody terrainBody; +} + +// The general class of collsion object. +public enum CollisionType +{ + Avatar, + Groundplane, + Terrain, + Static, + Dynamic, + VolumeDetect, + // Linkset, // A linkset proper should be either Static or Dynamic + LinksetChild, + Unknown +}; + +// Hold specification of group and mask collision flags for a CollisionType +public struct CollisionTypeFilterGroup +{ + public CollisionTypeFilterGroup(CollisionType t, uint g, uint m) + { + type = t; + group = g; + mask = m; + } + public CollisionType type; + public uint group; + public uint mask; +}; + + /* + // The collsion filters and masked are defined in one place -- don't want them scattered + AvatarGroup = BCharacterGroup, + AvatarMask = BAllGroup, + ObjectGroup = BSolidGroup, + ObjectMask = BAllGroup, + StaticObjectGroup = BStaticGroup, + StaticObjectMask = AvatarGroup | ObjectGroup, // static things don't interact with much + LinksetGroup = BLinksetGroup, + LinksetMask = BAllGroup, + LinksetChildGroup = BLinksetChildGroup, + LinksetChildMask = BNoneGroup, // Linkset children disappear from the world + VolumeDetectGroup = BSensorTrigger, + VolumeDetectMask = ~BSensorTrigger, + TerrainGroup = BTerrainGroup, + TerrainMask = BAllGroup & ~BStaticGroup, // static objects on the ground don't collide + GroundPlaneGroup = BGroundPlaneGroup, + GroundPlaneMask = BAllGroup + */ + +public static class BulletSimData +{ + +// Map of collisionTypes to flags for collision groups and masks. +// As mentioned above, don't use the CollisionFilterGroups definitions directly in the code +// but, instead, user references to this dictionary. This makes finding and debugging +// collision flag usage easier. +public static Dictionary CollisionTypeMasks + = new Dictionary() +{ + { CollisionType.Avatar, + new CollisionTypeFilterGroup(CollisionType.Avatar, + (uint)CollisionFilterGroups.BCharacterGroup, + (uint)CollisionFilterGroups.BAllGroup) + }, + { CollisionType.Groundplane, + new CollisionTypeFilterGroup(CollisionType.Groundplane, + (uint)CollisionFilterGroups.BGroundPlaneGroup, + (uint)CollisionFilterGroups.BAllGroup) + }, + { CollisionType.Terrain, + new CollisionTypeFilterGroup(CollisionType.Terrain, + (uint)CollisionFilterGroups.BTerrainGroup, + (uint)(CollisionFilterGroups.BAllGroup & ~CollisionFilterGroups.BStaticGroup)) + }, + { CollisionType.Static, + new CollisionTypeFilterGroup(CollisionType.Static, + (uint)CollisionFilterGroups.BStaticGroup, + (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup)) + }, + { CollisionType.Dynamic, + new CollisionTypeFilterGroup(CollisionType.Dynamic, + (uint)CollisionFilterGroups.BSolidGroup, + (uint)(CollisionFilterGroups.BAllGroup)) + }, + { CollisionType.VolumeDetect, + new CollisionTypeFilterGroup(CollisionType.VolumeDetect, + (uint)CollisionFilterGroups.BSensorTrigger, + (uint)(~CollisionFilterGroups.BSensorTrigger)) + }, + { CollisionType.LinksetChild, + new CollisionTypeFilterGroup(CollisionType.LinksetChild, + (uint)CollisionFilterGroups.BTerrainGroup, + (uint)(CollisionFilterGroups.BNoneGroup)) + }, +}; + +} +} -- cgit v1.1 From 60950bfab5657b09c314ffd03aceeac5973be84c Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Thu, 13 Dec 2012 16:15:21 -0800 Subject: BulletSim: correct line endings in new BulletSimData.cs file. --- .../Region/Physics/BulletSPlugin/BulletSimData.cs | 564 ++++++++++----------- 1 file changed, 282 insertions(+), 282 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs index e5c4777..524a1d0 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs @@ -1,282 +1,282 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyrightD - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -using System; -using System.Collections.Generic; -using System.Text; -using OMV = OpenMetaverse; - -namespace OpenSim.Region.Physics.BulletSPlugin -{ -// Classes to allow some type checking for the API -// These hold pointers to allocated objects in the unmanaged space. - -// The physics engine controller class created at initialization -public struct BulletSim -{ - public BulletSim(uint worldId, BSScene bss, IntPtr xx) - { - ptr = xx; - worldID = worldId; - physicsScene = bss; - } - public IntPtr ptr; - public uint worldID; - // The scene is only in here so very low level routines have a handle to print debug/error messages - public BSScene physicsScene; -} - -// An allocated Bullet btRigidBody -public struct BulletBody -{ - public BulletBody(uint id) : this(id, IntPtr.Zero) - { - } - public BulletBody(uint id, IntPtr xx) - { - ID = id; - ptr = xx; - collisionType = CollisionType.Static; - } - public IntPtr ptr; - public uint ID; - public CollisionType collisionType; - - public void Clear() - { - ptr = IntPtr.Zero; - } - public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } } - - // Apply the specificed collision mask into the physical world - public void ApplyCollisionMask() - { - // Should assert the body has been added to the physical world. - // (The collision masks are stored in the collision proxy cache which only exists for - // a collision body that is in the world.) - BulletSimAPI.SetCollisionGroupMask2(ptr, - BulletSimData.CollisionTypeMasks[collisionType].group, - BulletSimData.CollisionTypeMasks[collisionType].mask); - } - - public override string ToString() - { - StringBuilder buff = new StringBuilder(); - buff.Append(""); - return buff.ToString(); - } -} - -public struct BulletShape -{ - public BulletShape(IntPtr xx) - { - ptr = xx; - type=BSPhysicsShapeType.SHAPE_UNKNOWN; - shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; - isNativeShape = false; - } - public BulletShape(IntPtr xx, BSPhysicsShapeType typ) - { - ptr = xx; - type = typ; - shapeKey = 0; - isNativeShape = false; - } - public IntPtr ptr; - public BSPhysicsShapeType type; - public System.UInt64 shapeKey; - public bool isNativeShape; - - public void Clear() - { - ptr = IntPtr.Zero; - } - public bool HasPhysicalShape { get { return ptr != IntPtr.Zero; } } - - public override string ToString() - { - StringBuilder buff = new StringBuilder(); - buff.Append(""); - return buff.ToString(); - } -} - -// An allocated Bullet btConstraint -public struct BulletConstraint -{ - public BulletConstraint(IntPtr xx) - { - ptr = xx; - } - public IntPtr ptr; - - public void Clear() - { - ptr = IntPtr.Zero; - } - public bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } } -} - -// An allocated HeightMapThing which holds various heightmap info. -// Made a class rather than a struct so there would be only one -// instance of this and C# will pass around pointers rather -// than making copies. -public class BulletHeightMapInfo -{ - public BulletHeightMapInfo(uint id, float[] hm, IntPtr xx) { - ID = id; - Ptr = xx; - heightMap = hm; - terrainRegionBase = OMV.Vector3.Zero; - minCoords = new OMV.Vector3(100f, 100f, 25f); - maxCoords = new OMV.Vector3(101f, 101f, 26f); - minZ = maxZ = 0f; - sizeX = sizeY = 256f; - } - public uint ID; - public IntPtr Ptr; - public float[] heightMap; - public OMV.Vector3 terrainRegionBase; - public OMV.Vector3 minCoords; - public OMV.Vector3 maxCoords; - public float sizeX, sizeY; - public float minZ, maxZ; - public BulletShape terrainShape; - public BulletBody terrainBody; -} - -// The general class of collsion object. -public enum CollisionType -{ - Avatar, - Groundplane, - Terrain, - Static, - Dynamic, - VolumeDetect, - // Linkset, // A linkset proper should be either Static or Dynamic - LinksetChild, - Unknown -}; - -// Hold specification of group and mask collision flags for a CollisionType -public struct CollisionTypeFilterGroup -{ - public CollisionTypeFilterGroup(CollisionType t, uint g, uint m) - { - type = t; - group = g; - mask = m; - } - public CollisionType type; - public uint group; - public uint mask; -}; - - /* - // The collsion filters and masked are defined in one place -- don't want them scattered - AvatarGroup = BCharacterGroup, - AvatarMask = BAllGroup, - ObjectGroup = BSolidGroup, - ObjectMask = BAllGroup, - StaticObjectGroup = BStaticGroup, - StaticObjectMask = AvatarGroup | ObjectGroup, // static things don't interact with much - LinksetGroup = BLinksetGroup, - LinksetMask = BAllGroup, - LinksetChildGroup = BLinksetChildGroup, - LinksetChildMask = BNoneGroup, // Linkset children disappear from the world - VolumeDetectGroup = BSensorTrigger, - VolumeDetectMask = ~BSensorTrigger, - TerrainGroup = BTerrainGroup, - TerrainMask = BAllGroup & ~BStaticGroup, // static objects on the ground don't collide - GroundPlaneGroup = BGroundPlaneGroup, - GroundPlaneMask = BAllGroup - */ - -public static class BulletSimData -{ - -// Map of collisionTypes to flags for collision groups and masks. -// As mentioned above, don't use the CollisionFilterGroups definitions directly in the code -// but, instead, user references to this dictionary. This makes finding and debugging -// collision flag usage easier. -public static Dictionary CollisionTypeMasks - = new Dictionary() -{ - { CollisionType.Avatar, - new CollisionTypeFilterGroup(CollisionType.Avatar, - (uint)CollisionFilterGroups.BCharacterGroup, - (uint)CollisionFilterGroups.BAllGroup) - }, - { CollisionType.Groundplane, - new CollisionTypeFilterGroup(CollisionType.Groundplane, - (uint)CollisionFilterGroups.BGroundPlaneGroup, - (uint)CollisionFilterGroups.BAllGroup) - }, - { CollisionType.Terrain, - new CollisionTypeFilterGroup(CollisionType.Terrain, - (uint)CollisionFilterGroups.BTerrainGroup, - (uint)(CollisionFilterGroups.BAllGroup & ~CollisionFilterGroups.BStaticGroup)) - }, - { CollisionType.Static, - new CollisionTypeFilterGroup(CollisionType.Static, - (uint)CollisionFilterGroups.BStaticGroup, - (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup)) - }, - { CollisionType.Dynamic, - new CollisionTypeFilterGroup(CollisionType.Dynamic, - (uint)CollisionFilterGroups.BSolidGroup, - (uint)(CollisionFilterGroups.BAllGroup)) - }, - { CollisionType.VolumeDetect, - new CollisionTypeFilterGroup(CollisionType.VolumeDetect, - (uint)CollisionFilterGroups.BSensorTrigger, - (uint)(~CollisionFilterGroups.BSensorTrigger)) - }, - { CollisionType.LinksetChild, - new CollisionTypeFilterGroup(CollisionType.LinksetChild, - (uint)CollisionFilterGroups.BTerrainGroup, - (uint)(CollisionFilterGroups.BNoneGroup)) - }, -}; - -} -} +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyrightD + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +using System; +using System.Collections.Generic; +using System.Text; +using OMV = OpenMetaverse; + +namespace OpenSim.Region.Physics.BulletSPlugin +{ +// Classes to allow some type checking for the API +// These hold pointers to allocated objects in the unmanaged space. + +// The physics engine controller class created at initialization +public struct BulletSim +{ + public BulletSim(uint worldId, BSScene bss, IntPtr xx) + { + ptr = xx; + worldID = worldId; + physicsScene = bss; + } + public IntPtr ptr; + public uint worldID; + // The scene is only in here so very low level routines have a handle to print debug/error messages + public BSScene physicsScene; +} + +// An allocated Bullet btRigidBody +public struct BulletBody +{ + public BulletBody(uint id) : this(id, IntPtr.Zero) + { + } + public BulletBody(uint id, IntPtr xx) + { + ID = id; + ptr = xx; + collisionType = CollisionType.Static; + } + public IntPtr ptr; + public uint ID; + public CollisionType collisionType; + + public void Clear() + { + ptr = IntPtr.Zero; + } + public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } } + + // Apply the specificed collision mask into the physical world + public void ApplyCollisionMask() + { + // Should assert the body has been added to the physical world. + // (The collision masks are stored in the collision proxy cache which only exists for + // a collision body that is in the world.) + BulletSimAPI.SetCollisionGroupMask2(ptr, + BulletSimData.CollisionTypeMasks[collisionType].group, + BulletSimData.CollisionTypeMasks[collisionType].mask); + } + + public override string ToString() + { + StringBuilder buff = new StringBuilder(); + buff.Append(""); + return buff.ToString(); + } +} + +public struct BulletShape +{ + public BulletShape(IntPtr xx) + { + ptr = xx; + type=BSPhysicsShapeType.SHAPE_UNKNOWN; + shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; + isNativeShape = false; + } + public BulletShape(IntPtr xx, BSPhysicsShapeType typ) + { + ptr = xx; + type = typ; + shapeKey = 0; + isNativeShape = false; + } + public IntPtr ptr; + public BSPhysicsShapeType type; + public System.UInt64 shapeKey; + public bool isNativeShape; + + public void Clear() + { + ptr = IntPtr.Zero; + } + public bool HasPhysicalShape { get { return ptr != IntPtr.Zero; } } + + public override string ToString() + { + StringBuilder buff = new StringBuilder(); + buff.Append(""); + return buff.ToString(); + } +} + +// An allocated Bullet btConstraint +public struct BulletConstraint +{ + public BulletConstraint(IntPtr xx) + { + ptr = xx; + } + public IntPtr ptr; + + public void Clear() + { + ptr = IntPtr.Zero; + } + public bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } } +} + +// An allocated HeightMapThing which holds various heightmap info. +// Made a class rather than a struct so there would be only one +// instance of this and C# will pass around pointers rather +// than making copies. +public class BulletHeightMapInfo +{ + public BulletHeightMapInfo(uint id, float[] hm, IntPtr xx) { + ID = id; + Ptr = xx; + heightMap = hm; + terrainRegionBase = OMV.Vector3.Zero; + minCoords = new OMV.Vector3(100f, 100f, 25f); + maxCoords = new OMV.Vector3(101f, 101f, 26f); + minZ = maxZ = 0f; + sizeX = sizeY = 256f; + } + public uint ID; + public IntPtr Ptr; + public float[] heightMap; + public OMV.Vector3 terrainRegionBase; + public OMV.Vector3 minCoords; + public OMV.Vector3 maxCoords; + public float sizeX, sizeY; + public float minZ, maxZ; + public BulletShape terrainShape; + public BulletBody terrainBody; +} + +// The general class of collsion object. +public enum CollisionType +{ + Avatar, + Groundplane, + Terrain, + Static, + Dynamic, + VolumeDetect, + // Linkset, // A linkset proper should be either Static or Dynamic + LinksetChild, + Unknown +}; + +// Hold specification of group and mask collision flags for a CollisionType +public struct CollisionTypeFilterGroup +{ + public CollisionTypeFilterGroup(CollisionType t, uint g, uint m) + { + type = t; + group = g; + mask = m; + } + public CollisionType type; + public uint group; + public uint mask; +}; + + /* + // The collsion filters and masked are defined in one place -- don't want them scattered + AvatarGroup = BCharacterGroup, + AvatarMask = BAllGroup, + ObjectGroup = BSolidGroup, + ObjectMask = BAllGroup, + StaticObjectGroup = BStaticGroup, + StaticObjectMask = AvatarGroup | ObjectGroup, // static things don't interact with much + LinksetGroup = BLinksetGroup, + LinksetMask = BAllGroup, + LinksetChildGroup = BLinksetChildGroup, + LinksetChildMask = BNoneGroup, // Linkset children disappear from the world + VolumeDetectGroup = BSensorTrigger, + VolumeDetectMask = ~BSensorTrigger, + TerrainGroup = BTerrainGroup, + TerrainMask = BAllGroup & ~BStaticGroup, // static objects on the ground don't collide + GroundPlaneGroup = BGroundPlaneGroup, + GroundPlaneMask = BAllGroup + */ + +public static class BulletSimData +{ + +// Map of collisionTypes to flags for collision groups and masks. +// As mentioned above, don't use the CollisionFilterGroups definitions directly in the code +// but, instead, use references to this dictionary. Finding and debugging +// collision flag problems will be made easier. +public static Dictionary CollisionTypeMasks + = new Dictionary() +{ + { CollisionType.Avatar, + new CollisionTypeFilterGroup(CollisionType.Avatar, + (uint)CollisionFilterGroups.BCharacterGroup, + (uint)CollisionFilterGroups.BAllGroup) + }, + { CollisionType.Groundplane, + new CollisionTypeFilterGroup(CollisionType.Groundplane, + (uint)CollisionFilterGroups.BGroundPlaneGroup, + (uint)CollisionFilterGroups.BAllGroup) + }, + { CollisionType.Terrain, + new CollisionTypeFilterGroup(CollisionType.Terrain, + (uint)CollisionFilterGroups.BTerrainGroup, + (uint)(CollisionFilterGroups.BAllGroup & ~CollisionFilterGroups.BStaticGroup)) + }, + { CollisionType.Static, + new CollisionTypeFilterGroup(CollisionType.Static, + (uint)CollisionFilterGroups.BStaticGroup, + (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup)) + }, + { CollisionType.Dynamic, + new CollisionTypeFilterGroup(CollisionType.Dynamic, + (uint)CollisionFilterGroups.BSolidGroup, + (uint)(CollisionFilterGroups.BAllGroup)) + }, + { CollisionType.VolumeDetect, + new CollisionTypeFilterGroup(CollisionType.VolumeDetect, + (uint)CollisionFilterGroups.BSensorTrigger, + (uint)(~CollisionFilterGroups.BSensorTrigger)) + }, + { CollisionType.LinksetChild, + new CollisionTypeFilterGroup(CollisionType.LinksetChild, + (uint)CollisionFilterGroups.BTerrainGroup, + (uint)(CollisionFilterGroups.BNoneGroup)) + }, +}; + +} +} -- cgit v1.1 From 31d3952477b96b669d8a46d0941ea6d1bc1133b5 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Thu, 13 Dec 2012 16:23:51 -0800 Subject: BulletSim: fix problem with continuious rebuilding of physical linksets. This caused movement problems and large prim vehicles to take up a LOT of simulation time. --- OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs | 9 +- .../Physics/BulletSPlugin/BSLinksetCompound.cs | 155 +++++++++++---------- .../Physics/BulletSPlugin/BSLinksetConstraints.cs | 3 +- 3 files changed, 88 insertions(+), 79 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs index 777c5cb..ce0fbe6 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs @@ -124,7 +124,7 @@ public abstract class BSLinkset get { return ComputeLinksetGeometricCenter(); } } - protected void Initialize(BSScene scene, BSPhysObject parent) + protected BSLinkset(BSScene scene, BSPhysObject parent) { // A simple linkset of one (no children) LinksetID = m_nextLinksetID++; @@ -135,6 +135,7 @@ public abstract class BSLinkset LinksetRoot = parent; m_children = new HashSet(); m_mass = parent.RawMass; + Rebuilding = false; } // Link to a linkset where the child knows the parent. @@ -227,7 +228,7 @@ public abstract class BSLinkset // I am the root of a linkset and a new child is being added // Called while LinkActivity is locked. protected abstract void AddChildToLinkset(BSPhysObject child); - + // I am the root of a linkset and one of my children is being removed. // Safe to call even if the child is not really in my linkset. protected abstract void RemoveChildFromLinkset(BSPhysObject child); @@ -237,6 +238,10 @@ public abstract class BSLinkset // May be called at runtime or taint-time. public abstract void Refresh(BSPhysObject requestor); + // Flag denoting the linkset is in the process of being rebuilt. + // Used to know not the schedule a rebuild in the middle of a rebuild. + protected bool Rebuilding { get; set; } + // The object is going dynamic (physical). Do any setup necessary // for a dynamic linkset. // Only the state of the passed object can be modified. The rest of the linkset diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index 6cabe3a..2189468 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs @@ -61,9 +61,8 @@ public sealed class BSLinksetCompound : BSLinkset { private static string LogHeader = "[BULLETSIM LINKSET COMPOUND]"; - public BSLinksetCompound(BSScene scene, BSPhysObject parent) + public BSLinksetCompound(BSScene scene, BSPhysObject parent) : base(scene, parent) { - base.Initialize(scene, parent); } // For compound implimented linksets, if there are children, use compound shape for the root. @@ -81,8 +80,6 @@ public sealed class BSLinksetCompound : BSLinkset // When physical properties are changed the linkset needs to recalculate // its internal properties. - // This is queued in the 'post taint' queue so the - // refresh will happen once after all the other taints are applied. public override void Refresh(BSPhysObject requestor) { // External request for Refresh (from BSPrim) doesn't need to do anything @@ -92,12 +89,18 @@ public sealed class BSLinksetCompound : BSLinkset // Schedule a refresh to happen after all the other taint processing. private void InternalRefresh(BSPhysObject requestor) { - DetailLog("{0},BSLinksetCompound.Refresh,schedulingRefresh,requestor={1}", LinksetRoot.LocalID, requestor.LocalID); - PhysicsScene.PostTaintObject("BSLinksetCompound.Refresh", requestor.LocalID, delegate() + DetailLog("{0},BSLinksetCompound.Refresh,schedulingRefresh,requestor={1},rebuilding={2}", + LinksetRoot.LocalID, requestor.LocalID, Rebuilding); + // When rebuilding, it is possible to set properties that would normally require a rebuild. + // If already rebuilding, don't request another rebuild. + if (!Rebuilding) { - if (IsRoot(requestor) && HasAnyChildren) - RecomputeLinksetCompound(); - }); + PhysicsScene.PostTaintObject("BSLinksetCompound.Refresh", requestor.LocalID, delegate() + { + if (IsRoot(requestor) && HasAnyChildren) + RecomputeLinksetCompound(); + }); + } } // The object is going dynamic (physical). Do any setup necessary @@ -115,11 +118,7 @@ public sealed class BSLinksetCompound : BSLinkset // The root is going dynamic. Make sure mass is properly set. m_mass = ComputeLinksetMass(); if (HasAnyChildren) - { - // Schedule a rebuilding as this will construct the complete compound shape - // and set all the properties correctly. InternalRefresh(LinksetRoot); - } } else { @@ -149,16 +148,13 @@ public sealed class BSLinksetCompound : BSLinkset if (IsRoot(child)) { if (HasAnyChildren) - { - // Schedule a rebuilding as this will construct the complete compound shape - // and set all the properties correctly. InternalRefresh(LinksetRoot); - } } else { // The non-physical children can come back to life. BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); + child.PhysBody.collisionType = CollisionType.LinksetChild; // Don't force activation so setting of DISABLE_SIMULATION can stay if used. @@ -307,74 +303,83 @@ public sealed class BSLinksetCompound : BSLinkset // Called at taint time!! private void RecomputeLinksetCompound() { - // Cause the root shape to be rebuilt as a compound object with just the root in it - LinksetRoot.ForceBodyShapeRebuild(true); + try + { + // Suppress rebuilding while rebuilding + Rebuilding = true; - DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,start,rBody={1},rShape={2},numChildren={3}", - LinksetRoot.LocalID, LinksetRoot.PhysBody, LinksetRoot.PhysShape, NumberOfChildren); + // Cause the root shape to be rebuilt as a compound object with just the root in it + LinksetRoot.ForceBodyShapeRebuild(true); - // Add a shape for each of the other children in the linkset - ForEachMember(delegate(BSPhysObject cPrim) - { - if (!IsRoot(cPrim)) + DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,start,rBody={1},rShape={2},numChildren={3}", + LinksetRoot.LocalID, LinksetRoot.PhysBody, LinksetRoot.PhysShape, NumberOfChildren); + + // Add a shape for each of the other children in the linkset + ForEachMember(delegate(BSPhysObject cPrim) { - // Compute the displacement of the child from the root of the linkset. - // This info is saved in the child prim so the relationship does not - // change over time and the new child position can be computed - // when the linkset is being disassembled (the linkset may have moved). - BSLinksetCompoundInfo lci = cPrim.LinksetInfo as BSLinksetCompoundInfo; - if (lci == null) + if (!IsRoot(cPrim)) { - // Each child position and rotation is given relative to the root. - OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(LinksetRoot.RawOrientation); - OMV.Vector3 displacementPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation; - OMV.Quaternion displacementRot = cPrim.RawOrientation * invRootOrientation; - - // Save relative position for recomputing child's world position after moving linkset. - lci = new BSLinksetCompoundInfo(displacementPos, displacementRot); - cPrim.LinksetInfo = lci; - DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,creatingRelPos,lci={1}", cPrim.LocalID, lci); - } + // Compute the displacement of the child from the root of the linkset. + // This info is saved in the child prim so the relationship does not + // change over time and the new child position can be computed + // when the linkset is being disassembled (the linkset may have moved). + BSLinksetCompoundInfo lci = cPrim.LinksetInfo as BSLinksetCompoundInfo; + if (lci == null) + { + // Each child position and rotation is given relative to the root. + OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(LinksetRoot.RawOrientation); + OMV.Vector3 displacementPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation; + OMV.Quaternion displacementRot = cPrim.RawOrientation * invRootOrientation; + + // Save relative position for recomputing child's world position after moving linkset. + lci = new BSLinksetCompoundInfo(displacementPos, displacementRot); + cPrim.LinksetInfo = lci; + DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,creatingRelPos,lci={1}", cPrim.LocalID, lci); + } - DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addMemberToShape,mID={1},mShape={2},dispPos={3},dispRot={4}", - LinksetRoot.LocalID, cPrim.LocalID, cPrim.PhysShape, lci.OffsetPos, lci.OffsetRot); + DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addMemberToShape,mID={1},mShape={2},dispPos={3},dispRot={4}", + LinksetRoot.LocalID, cPrim.LocalID, cPrim.PhysShape, lci.OffsetPos, lci.OffsetRot); - if (cPrim.PhysShape.isNativeShape) - { - // A native shape is turning into a hull collision shape because native - // shapes are not shared so we have to hullify it so it will be tracked - // and freed at the correct time. This also solves the scaling problem - // (native shapes scaled but hull/meshes are assumed to not be). - // TODO: decide of the native shape can just be used in the compound shape. - // Use call to CreateGeomNonSpecial(). - BulletShape saveShape = cPrim.PhysShape; - cPrim.PhysShape.Clear(); // Don't let the create free the child's shape - // PhysicsScene.Shapes.CreateGeomNonSpecial(true, cPrim, null); - PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null); - BulletShape newShape = cPrim.PhysShape; - cPrim.PhysShape = saveShape; - BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, newShape.ptr, lci.OffsetPos , lci.OffsetRot); - } - else - { - // For the shared shapes (meshes and hulls), just use the shape in the child. - // The reference count added here will be decremented when the compound shape - // is destroyed in BSShapeCollection (the child shapes are looped over and dereferenced). - if (PhysicsScene.Shapes.ReferenceShape(cPrim.PhysShape)) + if (cPrim.PhysShape.isNativeShape) + { + // A native shape is turning into a hull collision shape because native + // shapes are not shared so we have to hullify it so it will be tracked + // and freed at the correct time. This also solves the scaling problem + // (native shapes scaled but hull/meshes are assumed to not be). + // TODO: decide of the native shape can just be used in the compound shape. + // Use call to CreateGeomNonSpecial(). + BulletShape saveShape = cPrim.PhysShape; + cPrim.PhysShape.Clear(); // Don't let the create free the child's shape + // PhysicsScene.Shapes.CreateGeomNonSpecial(true, cPrim, null); + PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null); + BulletShape newShape = cPrim.PhysShape; + cPrim.PhysShape = saveShape; + BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, newShape.ptr, lci.OffsetPos, lci.OffsetRot); + } + else { - PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}", - LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape); + // For the shared shapes (meshes and hulls), just use the shape in the child. + // The reference count added here will be decremented when the compound shape + // is destroyed in BSShapeCollection (the child shapes are looped over and dereferenced). + if (PhysicsScene.Shapes.ReferenceShape(cPrim.PhysShape)) + { + PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}", + LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape); + } + BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, lci.OffsetPos, lci.OffsetRot); } - BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, lci.OffsetPos , lci.OffsetRot); } - } - - return false; // 'false' says to move onto the next child in the list - }); + return false; // 'false' says to move onto the next child in the list + }); - // With all of the linkset packed into the root prim, it has the mass of everyone. - float linksetMass = LinksetMass; - LinksetRoot.UpdatePhysicalMassProperties(linksetMass); + // With all of the linkset packed into the root prim, it has the mass of everyone. + float linksetMass = LinksetMass; + LinksetRoot.UpdatePhysicalMassProperties(linksetMass); + } + finally + { + Rebuilding = false; + } BulletSimAPI.RecalculateCompoundShapeLocalAabb2(LinksetRoot.PhysShape.ptr); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs index c855fda..732c084 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs @@ -36,9 +36,8 @@ public sealed class BSLinksetConstraints : BSLinkset { // private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]"; - public BSLinksetConstraints(BSScene scene, BSPhysObject parent) + public BSLinksetConstraints(BSScene scene, BSPhysObject parent) : base(scene, parent) { - base.Initialize(scene, parent); } // When physical properties are changed the linkset needs to recalculate -- cgit v1.1 From 664dad53dded9537e75893ca9fc6a42c93a95ded Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Thu, 13 Dec 2012 23:08:01 -0800 Subject: BulletSim: Add more to the TODO list. Clean up and improve some comments. --- OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs | 12 ++++-------- OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt | 7 +++++-- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs index 524a1d0..662177f 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs @@ -98,18 +98,14 @@ public struct BulletBody public struct BulletShape { - public BulletShape(IntPtr xx) + public BulletShape(IntPtr xx) : this(xx, BSPhysicsShapeType.SHAPE_UNKNOWN) { - ptr = xx; - type=BSPhysicsShapeType.SHAPE_UNKNOWN; - shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; - isNativeShape = false; } public BulletShape(IntPtr xx, BSPhysicsShapeType typ) { ptr = xx; type = typ; - shapeKey = 0; + shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; isNativeShape = false; } public IntPtr ptr; @@ -192,7 +188,7 @@ public enum CollisionType Static, Dynamic, VolumeDetect, - // Linkset, // A linkset proper should be either Static or Dynamic + // Linkset, // A linkset should be either Static or Dynamic LinksetChild, Unknown }; @@ -211,7 +207,7 @@ public struct CollisionTypeFilterGroup public uint mask; }; - /* + /* NOTE: old definitions kept for reference. Delete when things are working. // The collsion filters and masked are defined in one place -- don't want them scattered AvatarGroup = BCharacterGroup, AvatarMask = BAllGroup, diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index 11c1387..7d6ace8 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt @@ -19,6 +19,7 @@ Some vehicles should not be able to turn if no speed or off ground. Neb car jiggling left and right Happens on terrain and any other mesh object. Flat cubes are much smoother. This has been reduced but not eliminated. +Light cycle falling over when driving For limitMotorUp, use raycast down to find if vehicle is in the air. Angular motion around Z moves the vehicle in world Z and not vehicle Z in ODE. Verify that angular motion specified around Z moves in the vehicle coordinates. @@ -121,6 +122,9 @@ Remove unused fields from ShapeData (not used in API2) Breakout code for mesh/hull/compound/native into separate BSShape* classes Standardize access to building and reference code. The skeleton classes are in the sources but are not complete or linked in. +Make BSBody and BSShape real classes to centralize creation/changin/destruction + Convert state and parameter calls from BulletSimAPI direct calls to + calls on BSBody and BSShape Generalize Dynamics and PID with standardized motors. Generalize Linkset and vehicles into PropertyManagers Methods for Refresh, RemoveBodyDependencies, RestoreBodyDependencies @@ -132,7 +136,7 @@ Implement linkset by setting position of children when root updated. (LinksetMan Linkset implementation using manual prim movement. LinkablePrim class? Would that simplify/centralize the linkset logic? BSScene.UpdateParameterSet() is broken. How to set params on objects? -Remove HeightmapInfo from terrain specification. +Remove HeightmapInfo from terrain specification Since C++ code does not need terrain height, this structure et al are not needed. Add floating motor for BS_FLOATS_ON_WATER so prim and avatar will bob at the water level. BSPrim.PositionSanityCheck(). @@ -164,7 +168,6 @@ Do prim hash codes work for sculpties and meshes? (Resolution: yes) Linkset implementation using compound shapes. (Resolution: implemented LinksetCompound) Compound shapes will need the LocalID in the shapes and collision processing to get it from there. -Light cycle falling over when driving (Resolution: implemented VerticalAttractor) Light cycle not banking (Resolution: It doesn't. Banking is roll adding yaw.) Package Bullet source mods for Bullet internal stats output (Resolution: move code into WorldData.h rather than relying on patches) -- cgit v1.1