From 735d89e3692bb7c620b9e3c248a1dbd5924b8b3f Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 25 Sep 2012 15:01:18 -0700 Subject: BulletSim: btGhostObjects working to make 'volume detect' work. Rearrangement and cleanup of shape collection code. Much more readable. Enabling and use of collision filters and masks. Addition of ID to body creation BulletSimAPI calls so always set in shape for collision reporting. Change default of ShouldSplitSimulationIslands and ShouldRandomizeSolverOrder from 'false' to 'true'. When 'false', this suppresses NO_CONTACT_RESPONSE which makes volume detect fail. --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 10 +- .../Region/Physics/BulletSPlugin/BSPhysObject.cs | 8 +- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 28 +- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 24 +- .../Physics/BulletSPlugin/BSShapeCollection.cs | 296 +++++++++++---------- .../Physics/BulletSPlugin/BSTerrainManager.cs | 12 +- .../Region/Physics/BulletSPlugin/BulletSimAPI.cs | 78 ++++-- 7 files changed, 265 insertions(+), 191 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index e4b1dd4..961bcde 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -90,7 +90,8 @@ public class BSCharacter : BSPhysObject // Physics creates a unit capsule which is scaled by the physics engine. ComputeAvatarScale(_size); _avatarDensity = PhysicsScene.Params.avatarDensity; - ComputeAvatarVolumeAndMass(); // set _avatarVolume and _mass based on capsule size, _density and _scale + // set _avatarVolume and _mass based on capsule size, _density and _scale + ComputeAvatarVolumeAndMass(); ShapeData shapeData = new ShapeData(); shapeData.ID = LocalID; @@ -111,10 +112,15 @@ public class BSCharacter : BSPhysObject DetailLog("{0},BSCharacter.create,taint", LocalID); BulletSimAPI.CreateObject(PhysicsScene.WorldID, shapeData); - // Set the buoyancy for flying. This will be refactored when all the settings happen in C# + // Set the buoyancy for flying. This will be refactored when all the settings happen in C#. + // If not set at creation, the avatar will stop flying when created after crossing a region boundry. BulletSimAPI.SetObjectBuoyancy(PhysicsScene.WorldID, LocalID, _buoyancy); BSBody = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(PhysicsScene.World.ptr, LocalID)); + + // This works here because CreateObject has already put the character into the physical world. + BulletSimAPI.SetCollisionFilterMask2(BSBody.ptr, + (uint)CollisionFilterGroups.AvatarFilter, (uint)CollisionFilterGroups.AvatarMask); }); return; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 6a9fe50..3458477 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -123,6 +123,7 @@ public abstract class BSPhysObject : PhysicsActor CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); DetailLog("{0},{1}.Collison.AddCollider,call,with={2},point={3},normal={4},depth={5}", LocalID, TypeName, collidingWith, contactPoint, contactNormal, pentrationDepth); + ret = true; } return ret; @@ -145,7 +146,10 @@ public abstract class BSPhysObject : PhysicsActor // We are called if we previously had collisions. If there are no collisions // this time, send up one last empty event so OpenSim can sense collision end. if (CollisionCollection.Count == 0) + { + // If I have no collisions this time, remove me from the list of objects with collisions. PhysicsScene.ObjectsWithNoMoreCollisions.Add(this); + } DetailLog("{0},{1}.SendCollisionUpdate,call,numCollisions={2}", LocalID, TypeName, CollisionCollection.Count); base.SendCollisionUpdate(CollisionCollection); @@ -159,7 +163,7 @@ public abstract class BSPhysObject : PhysicsActor // Subscribe for collision events. // Parameter is the millisecond rate the caller wishes collision events to occur. public override void SubscribeEvents(int ms) { - DetailLog("{0},BSScene.SubscribeEvents,subscribing,ms={1}", BSScene.DetailLogZero, ms); + DetailLog("{0},{1}.SubscribeEvents,subscribing,ms={2}", LocalID, TypeName, ms); SubscribedEventsMs = ms; if (ms > 0) { @@ -178,7 +182,7 @@ public abstract class BSPhysObject : PhysicsActor } } public override void UnSubscribeEvents() { - DetailLog("{0},BSScene.UnSubscribeEvents,unsubscribing", BSScene.DetailLogZero); + DetailLog("{0},{1}.UnSubscribeEvents,unsubscribing", LocalID, TypeName); SubscribedEventsMs = 0; PhysicsScene.TaintedObject(TypeName+".UnSubscribeEvents", delegate() { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 5be2b1b..1c6d476 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -271,7 +271,7 @@ public sealed class BSPrim : BSPhysObject _position = BulletSimAPI.GetPosition2(BSBody.ptr); // don't do the GetObjectPosition for root elements because this function is called a zillion times - // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, LocalID); + // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); return _position; } set { @@ -432,7 +432,7 @@ 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.GetObjectPosition(Scene.WorldID, LocalID); + // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); }); @@ -492,7 +492,8 @@ public sealed class BSPrim : BSPhysObject { DetailLog("{0},BSPrim.UpdatePhysicalParameters,entry,body={1},shape={2}", LocalID, BSBody, BSShape); - // Mangling all the physical properties requires the object to be out of the physical world + // Mangling all the physical properties requires the object to be out of the physical world. + // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, BSBody.ptr); #if !CSHARP_BODY_MANAGEMENT @@ -517,6 +518,14 @@ public sealed class BSPrim : BSPhysObject // Rebuild its shape BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, BSBody.ptr); + // Collision filter can be set only when the object is in the world + if (BSBody.collisionFilter != 0 || BSBody.collisionMask != 0) + { + BulletSimAPI.SetCollisionFilterMask2(BSBody.ptr, (uint)BSBody.collisionFilter, (uint)BSBody.collisionMask); + DetailLog("{0},BSPrim.UpdatePhysicalParameters,setCollisionFilterMask,filter={1},mask={2}", + LocalID, BSBody.collisionFilter.ToString("X"), BSBody.collisionMask.ToString("X")); + } + // Recompute any linkset parameters. // When going from non-physical to physical, this re-enables the constraints that // had been automatically disabled when the mass was set to zero. @@ -548,8 +557,11 @@ public sealed class BSPrim : BSPhysObject // There can be special things needed for implementing linksets Linkset.MakeStatic(this); // The activation state is 'sleeping' so Bullet will not try to act on it - BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ISLAND_SLEEPING); - // BulletSimAPI.ForceActivationState2(BSBody.Ptr, ActivationState.DISABLE_SIMULATION); + // BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ISLAND_SLEEPING); + BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.DISABLE_SIMULATION); + + BSBody.collisionFilter = CollisionFilterGroups.StaticObjectFilter; + BSBody.collisionMask = CollisionFilterGroups.StaticObjectMask; } else { @@ -582,6 +594,9 @@ public sealed class BSPrim : BSPhysObject // Force activation of the object so Bullet will act on it. BulletSimAPI.Activate2(BSBody.ptr, true); + + BSBody.collisionFilter = CollisionFilterGroups.ObjectFilter; + BSBody.collisionMask = CollisionFilterGroups.ObjectMask; } } @@ -609,6 +624,8 @@ 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(BSBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); + BSBody.collisionFilter = CollisionFilterGroups.VolumeDetectFilter; + BSBody.collisionMask = CollisionFilterGroups.VolumeDetectMask; } #else // If doing the body management in C#, all this logic is in CSShapeCollection.CreateObject(). @@ -745,7 +762,6 @@ public sealed class BSPrim : BSPhysObject // Buoyancy is faked by changing the gravity applied to the object float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); BulletSimAPI.SetGravity2(BSBody.ptr, new OMV.Vector3(0f, 0f, grav)); - // BulletSimAPI.SetObjectBuoyancy(Scene.WorldID, LocalID, _buoyancy); }); } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 87c7b1b..e8c628c 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -39,20 +39,20 @@ using log4net; using OpenMetaverse; // TODOs for BulletSim (for BSScene, BSPrim, BSCharacter and BulletSim) -// Adjust character capsule size when height is adjusted (ScenePresence.SetHeight) -// Test sculpties +// Move all logic out of the C++ code and into the C# code for easier future modifications. +// Test sculpties (verified that they don't work) // Compute physics FPS reasonably // Based on material, set density and friction -// More efficient memory usage when passing hull information from BSPrim to BulletSim -// Move all logic out of the C++ code and into the C# code for easier future modifications. +// Don't use constraints in linksets of non-physical objects. Means having to move children manually. // Four states of prim: Physical, regular, phantom and selected. Are we modeling these correctly? // In SL one can set both physical and phantom (gravity, does not effect others, makes collisions with ground) // At the moment, physical and phantom causes object to drop through the terrain // Physical phantom objects and related typing (collision options ) -// Use collision masks for collision with terrain and phantom objects // Check out llVolumeDetect. Must do something for that. +// Use collision masks for collision with terrain and phantom objects +// More efficient memory usage when passing hull information from BSPrim to BulletSim // Should prim.link() and prim.delink() membership checking happen at taint time? -// Mesh sharing. Use meshHash to tell if we already have a hull of that shape and only create once +// Mesh sharing. Use meshHash to tell if we already have a hull of that shape and only create once. // Do attachments need to be handled separately? Need collision events. Do not collide with VolumeDetect // Implement LockAngularMotion // Decide if clearing forces is the right thing to do when setting position (BulletSim::SetObjectTranslation) @@ -356,6 +356,12 @@ public class BSScene : PhysicsScene, IPhysicsParameters Constraints = null; } + if (Shapes != null) + { + Shapes.Dispose(); + Shapes = null; + } + // Anything left in the unmanaged code should be cleaned out BulletSimAPI.Shutdown(WorldID); @@ -589,7 +595,6 @@ public class BSScene : PhysicsScene, IPhysicsParameters { if (localID <= TerrainManager.HighestTerrainID) { - DetailLog("{0},BSScene.SendCollision,collideWithTerrain,id={1},with={2}", DetailLogZero, localID, collidingWith); return; // don't send collisions to the terrain } @@ -601,8 +606,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters return; } - // The terrain is not in the physical object list so 'collidee' - // can be null when Collide() is called. + // The terrain is not in the physical object list so 'collidee' can be null when Collide() is called. BSPhysObject collidee = null; PhysObjects.TryGetValue(collidingWith, out collidee); @@ -1026,7 +1030,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters (s) => { return s.m_params[0].shouldRandomizeSolverOrder; }, (s,p,l,v) => { s.m_params[0].shouldRandomizeSolverOrder = v; } ), new ParameterDefn("ShouldSplitSimulationIslands", "Enable splitting active object scanning islands", - ConfigurationParameters.numericFalse, + ConfigurationParameters.numericTrue, (s,cf,p,v) => { s.m_params[0].shouldSplitSimulationIslands = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); }, (s) => { return s.m_params[0].shouldSplitSimulationIslands; }, (s,p,l,v) => { s.m_params[0].shouldSplitSimulationIslands = v; } ), diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 6b90661..7fce8c9 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs @@ -36,6 +36,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin { public class BSShapeCollection : IDisposable { + private static string LogHeader = "[BULLETSIM SHAPE COLLECTION]"; + protected BSScene PhysicsScene { get; set; } private Object m_collectionActivityLock = new Object(); @@ -43,24 +45,23 @@ public class BSShapeCollection : IDisposable // Description of a Mesh private struct MeshDesc { - public IntPtr Ptr; + public IntPtr ptr; public int referenceCount; public DateTime lastReferenced; - public IMesh meshData; } // Description of a hull. // Meshes and hulls have the same shape hash key but we only need hulls for efficient physical objects private struct HullDesc { - public IntPtr Ptr; + public IntPtr ptr; public int referenceCount; public DateTime lastReferenced; } private struct BodyDesc { - public IntPtr Ptr; + public IntPtr ptr; // Bodies are only used once so reference count is always either one or zero public int referenceCount; public DateTime lastReferenced; @@ -93,14 +94,16 @@ public class BSShapeCollection : IDisposable lock (m_collectionActivityLock) { // Do we have the correct geometry for this type of object? + // Updates prim.BSShape with information/pointers to requested shape bool newGeom = CreateGeom(forceRebuild, prim, shapeData, pbs); // If we had to select a new shape geometry for the object, // rebuild the body around it. + // Updates prim.BSBody with information/pointers to requested body bool newBody = CreateBody((newGeom || forceRebuild), prim, PhysicsScene.World, prim.BSShape, shapeData); ret = newGeom || newBody; } - DetailLog("{0},BSShapeCollection.GetBodyAndShape,force-{1},ret={2},body={3},shape={4}", - prim.LocalID, forceRebuild, ret, prim.BSBody, prim.BSShape); + DetailLog("{0},BSShapeCollection.GetBodyAndShape,force={1},ret={2},body={3},shape={4}", + prim.LocalID, forceRebuild, ret, prim.BSBody, prim.BSShape); return ret; } @@ -120,7 +123,8 @@ public class BSShapeCollection : IDisposable } else { - bodyDesc.Ptr = shape.ptr; + // New entry + bodyDesc.ptr = shape.ptr; bodyDesc.referenceCount = 1; DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,ref={1}", shape.ID, bodyDesc.referenceCount); } @@ -130,7 +134,7 @@ public class BSShapeCollection : IDisposable } // Release the usage of a body. - // Not that this will also delete the body in BUllet if the body is now unused (reference count = 0). + // Called when releasing use of a BSBody. BSShape is handled separately. public void DereferenceBody(BulletBody shape, bool inTaintTime) { if (shape.ptr == IntPtr.Zero) @@ -146,15 +150,17 @@ public class BSShapeCollection : IDisposable Bodies[shape.ID] = bodyDesc; DetailLog("{0},BSShapeCollection.DereferenceBody,ref={1}", shape.ID, bodyDesc.referenceCount); + // If body is no longer being used, free it -- bodies are never shared. if (bodyDesc.referenceCount == 0) { Bodies.Remove(shape.ID); BSScene.TaintCallback removeOperation = delegate() { - DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody. Ptr={1:X}", shape.ID, shape.ptr); - // zero any reference to the shape so it is not freed when the body is deleted + DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody. ptr={1}", + shape.ID, shape.ptr.ToString("X")); + // Zero any reference to the shape so it is not freed when the body is deleted. BulletSimAPI.SetCollisionShape2(PhysicsScene.World.ptr, shape.ptr, IntPtr.Zero); - // It may have already been removed from the world in which case the next is a NOOP + // It may have already been removed from the world in which case the next is a NOOP. BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, shape.ptr); BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, shape.ptr); }; @@ -172,19 +178,13 @@ public class BSShapeCollection : IDisposable } } - // Track another user of the shape - private bool ReferenceShape(BulletShape shape) - { - return ReferenceShape(shape, null); - } - // Track the datastructures and use count for a shape. // When creating a hull, this is called first to reference the mesh // and then again to reference the hull. // Meshes and hulls for the same shape have the same hash key. // NOTE that native shapes are not added to the mesh list or removed. // Returns 'true' if this is the initial reference to the shape. Otherwise reused. - private bool ReferenceShape(BulletShape shape, IMesh meshData) + private bool ReferenceShape(BulletShape shape) { bool ret = false; switch (shape.type) @@ -196,16 +196,16 @@ public class BSShapeCollection : IDisposable // There is an existing instance of this mesh. meshDesc.referenceCount++; DetailLog("{0},BSShapeColliction.ReferenceShape,existingMesh,key={1},cnt={2}", - BSScene.DetailLogZero, shape.shapeKey, meshDesc.referenceCount); + BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); } else { // This is a new reference to a mesh - meshDesc.Ptr = shape.ptr; - meshDesc.meshData = meshData; + meshDesc.ptr = shape.ptr; + // We keep a reference to the underlying IMesh data so a hull can be built meshDesc.referenceCount = 1; DetailLog("{0},BSShapeColliction.ReferenceShape,newMesh,key={1},cnt={2}", - BSScene.DetailLogZero, shape.shapeKey, meshDesc.referenceCount); + BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); ret = true; } meshDesc.lastReferenced = System.DateTime.Now; @@ -215,18 +215,18 @@ public class BSShapeCollection : IDisposable HullDesc hullDesc; if (Hulls.TryGetValue(shape.shapeKey, out hullDesc)) { - // There is an existing instance of this mesh. + // There is an existing instance of this hull. hullDesc.referenceCount++; DetailLog("{0},BSShapeColliction.ReferenceShape,existingHull,key={1},cnt={2}", - BSScene.DetailLogZero, shape.shapeKey, hullDesc.referenceCount); + BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); } else { // This is a new reference to a hull - hullDesc.Ptr = shape.ptr; + hullDesc.ptr = shape.ptr; hullDesc.referenceCount = 1; DetailLog("{0},BSShapeColliction.ReferenceShape,newHull,key={1},cnt={2}", - BSScene.DetailLogZero, shape.shapeKey, hullDesc.referenceCount); + BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); ret = true; } @@ -242,7 +242,8 @@ public class BSShapeCollection : IDisposable return ret; } - // Release the usage of a shape + // Release the usage of a shape. + // The collisionObject is released since it is a copy of the real collision shape. private void DereferenceShape(BulletShape shape, bool atTaintTime) { if (shape.ptr == IntPtr.Zero) @@ -254,8 +255,6 @@ public class BSShapeCollection : IDisposable { case ShapeData.PhysicsShapeType.SHAPE_HULL: DereferenceHull(shape); - // Hulls also include a mesh - DereferenceMesh(shape); break; case ShapeData.PhysicsShapeType.SHAPE_MESH: DereferenceMesh(shape); @@ -266,15 +265,24 @@ public class BSShapeCollection : IDisposable // Native shapes are not tracked and are released immediately if (shape.ptr != IntPtr.Zero & shape.isNativeShape) { + DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1},taintTime={2}", + BSScene.DetailLogZero, shape.ptr.ToString("X"), atTaintTime); BulletSimAPI.DeleteCollisionShape2(PhysicsScene.World.ptr, shape.ptr); } break; } }; if (atTaintTime) - dereferenceOperation(); + { + lock (m_collectionActivityLock) + { + dereferenceOperation(); + } + } else + { PhysicsScene.TaintedObject("BSShapeCollection.DereferenceShape", dereferenceOperation); + } } // Count down the reference count for a mesh shape @@ -288,8 +296,8 @@ public class BSShapeCollection : IDisposable // TODO: release the Bullet storage meshDesc.lastReferenced = System.DateTime.Now; Meshes[shape.shapeKey] = meshDesc; - DetailLog("{0},BSShapeColliction.DereferenceMesh,key={1},cnt={2}", - BSScene.DetailLogZero, shape.shapeKey, meshDesc.referenceCount); + DetailLog("{0},BSShapeCollection.DereferenceMesh,key={1},refCnt={2}", + BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); } } @@ -305,8 +313,8 @@ public class BSShapeCollection : IDisposable // TODO: release the Bullet storage (aging old entries?) hullDesc.lastReferenced = System.DateTime.Now; Hulls[shape.shapeKey] = hullDesc; - DetailLog("{0},BSShapeColliction.DereferenceHull,key={1},cnt={2}", - BSScene.DetailLogZero, shape.shapeKey, hullDesc.referenceCount); + DetailLog("{0},BSShapeCollection.DereferenceHull,key={1},refCnt={2}", + BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); } } @@ -322,8 +330,6 @@ public class BSShapeCollection : IDisposable bool haveShape = false; bool nativeShapePossible = true; - BulletShape newShape = new BulletShape(IntPtr.Zero); - // If the prim attributes are simple, this could be a simple Bullet native shape if (nativeShapePossible && ((pbs.SculptEntry && !PhysicsScene.ShouldMeshSculptedPrim) @@ -340,137 +346,117 @@ public class BSShapeCollection : IDisposable haveShape = true; if (forceRebuild || (prim.BSShape.type != ShapeData.PhysicsShapeType.SHAPE_SPHERE)) { - newShape = AddNativeShapeToPrim( - prim, shapeData, ShapeData.PhysicsShapeType.SHAPE_SPHERE, ShapeData.FixedShapeKey.KEY_SPHERE); + ret = GetReferenceToNativeShape(prim, shapeData, + ShapeData.PhysicsShapeType.SHAPE_SPHERE, ShapeData.FixedShapeKey.KEY_SPHERE); DetailLog("{0},BSShapeCollection.CreateGeom,sphere,force={1},shape={2}", - prim.LocalID, forceRebuild,prim.BSShape); - - ret = true; + prim.LocalID, forceRebuild, prim.BSShape); } } else { - // m_log.DebugFormat("{0}: CreateGeom: Defaulting to box. lid={1}, type={2}, size={3}", LogHeader, LocalID, _shapeType, _size); haveShape = true; if (forceRebuild || (prim.BSShape.type != ShapeData.PhysicsShapeType.SHAPE_BOX)) { - newShape = AddNativeShapeToPrim( + ret = GetReferenceToNativeShape( prim, shapeData, ShapeData.PhysicsShapeType.SHAPE_BOX, ShapeData.FixedShapeKey.KEY_BOX); DetailLog("{0},BSShapeCollection.CreateGeom,box,force={1},shape={2}", - prim.LocalID, forceRebuild,prim.BSShape); - - ret = true; + prim.LocalID, forceRebuild, prim.BSShape); } } } - // If a simple shape is not happening, create a mesh and possibly a hull + // If a simple shape is not happening, create a mesh and possibly a hull. // Note that if it's a native shape, the check for physical/non-physical is not // made. Native shapes are best used in either case. if (!haveShape) { if (prim.IsPhysical) { - if (forceRebuild || !Hulls.ContainsKey(shapeData.HullKey)) - { - // physical objects require a hull for interaction. - // This also creates the mesh if it doesn't already exist. - ret = CreateGeomHull(prim, shapeData, pbs); - } - else - { - prim.BSShape = new BulletShape(Hulls[shapeData.HullKey].Ptr, - ShapeData.PhysicsShapeType.SHAPE_HULL); - prim.BSShape.shapeKey = shapeData.HullKey; - // Another user of this shape. - ReferenceShape(prim.BSShape); - ret = true; - } + // Update prim.BSShape to reference a hull of this shape. + ret = GetReferenceToHull(prim, shapeData, pbs); + DetailLog("{0},BSShapeCollection.CreateGeom,hull,shape={1},key={2}", + shapeData.ID, prim.BSShape, prim.BSShape.shapeKey.ToString("X")); } else { - if (forceRebuild || !Meshes.ContainsKey(prim.BSShape.shapeKey)) - { - // Static (non-physical) objects only need a mesh for bumping into - // Returning 'true' means prim.BShape was changed. - ret = CreateGeomMesh(prim, shapeData, pbs); - } - else - { - prim.BSShape = new BulletShape(Hulls[shapeData.MeshKey].Ptr, - ShapeData.PhysicsShapeType.SHAPE_MESH); - prim.BSShape.shapeKey = shapeData.MeshKey; - ReferenceShape(prim.BSShape); - ret = true; - } + ret = GetReferenceToMesh(prim, shapeData, pbs); + DetailLog("{0},BSShapeCollection.CreateGeom,mesh,shape={1},key={2}", + shapeData.ID, prim.BSShape, prim.BSShape.shapeKey.ToString("X")); } } return ret; } // Creates a native shape and assignes it to prim.BSShape - private BulletShape AddNativeShapeToPrim( - BSPrim prim, ShapeData shapeData, ShapeData.PhysicsShapeType shapeType, - ShapeData.FixedShapeKey shapeKey) + private bool GetReferenceToNativeShape( BSPrim prim, ShapeData shapeData, + ShapeData.PhysicsShapeType shapeType, ShapeData.FixedShapeKey shapeKey) { BulletShape newShape; + shapeData.Type = shapeType; // Bullet native objects are scaled by the Bullet engine so pass the size in prim.Scale = shapeData.Size; - shapeData.Type = shapeType; - shapeData.Scale = prim.Scale; + shapeData.Scale = shapeData.Size; // release any previous shape DereferenceShape(prim.BSShape, true); - // Shape of this discriptioin is not allocated. Create new. - newShape = new BulletShape( - BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, shapeData), shapeType); + // Native shapes are always built independently. + newShape = new BulletShape(BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, shapeData), shapeType); newShape.shapeKey = (ulong)shapeKey; newShape.isNativeShape = true; - // Don't to a 'ReferenceShape()' here because native shapes are not tracked. + // Don't need to do a 'ReferenceShape()' here because native shapes are not tracked. + DetailLog("{0},BSShapeCollection.AddNativeShapeToPrim,create,newshape={1}", shapeData.ID, newShape); prim.BSShape = newShape; - return newShape; + return true; } - // Returns 'true' of a mesh was actually rebuild. + // Builds a mesh shape in the physical world and updates prim.BSShape. + // Dereferences previous shape in BSShape and adds a reference for this new shape. + // Returns 'true' of a mesh was actually built. Otherwise . // Called at taint-time! - private bool CreateGeomMesh(BSPrim prim, ShapeData shapeData, PrimitiveBaseShape pbs) + private bool GetReferenceToMesh(BSPrim prim, ShapeData shapeData, PrimitiveBaseShape pbs) { BulletShape newShape = new BulletShape(IntPtr.Zero); - // level of detail based on size and type of the object - float lod = PhysicsScene.MeshLOD; - if (pbs.SculptEntry) - lod = PhysicsScene.SculptLOD; - - float maxAxis = Math.Max(shapeData.Size.X, Math.Max(shapeData.Size.Y, shapeData.Size.Z)); - if (maxAxis > PhysicsScene.MeshMegaPrimThreshold) - lod = PhysicsScene.MeshMegaPrimLOD; - - ulong newMeshKey = (ulong)pbs.GetMeshKey(shapeData.Size, lod); + float lod; + ulong newMeshKey = ComputeShapeKey(shapeData, pbs, out lod); // if this new shape is the same as last time, don't recreate the mesh if (prim.BSShape.shapeKey == newMeshKey) return false; - DetailLog("{0},BSShapeCollection.CreateGeomMesh,create,key={1}", prim.LocalID, newMeshKey); + DetailLog("{0},BSShapeCollection.CreateGeomMesh,create,oldKey={1},newKey={2}", + prim.LocalID, prim.BSShape.shapeKey.ToString("X"), newMeshKey.ToString("X")); // Since we're recreating new, get rid of the reference to the previous shape DereferenceShape(prim.BSShape, true); + newShape = CreatePhysicalMesh(prim.PhysObjectName, newMeshKey, pbs, shapeData.Size, lod); + + ReferenceShape(newShape); + + // meshes are already scaled by the meshmerizer + prim.Scale = new OMV.Vector3(1f, 1f, 1f); + prim.BSShape = newShape; + + return true; // 'true' means a new shape has been added to this prim + } + + private BulletShape CreatePhysicalMesh(string objName, ulong newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) + { IMesh meshData = null; IntPtr meshPtr; MeshDesc meshDesc; if (Meshes.TryGetValue(newMeshKey, out meshDesc)) { // If the mesh has already been built just use it. - meshPtr = meshDesc.Ptr; + meshPtr = meshDesc.ptr; } else { - // always pass false for physicalness as this creates some sort of bounding box which we don't need - meshData = PhysicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, shapeData.Size, lod, false); + // Pass false for physicalness as this creates some sort of bounding box which we don't need + meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, false); int[] indices = meshData.getIndexListAsInt(); List vertices = meshData.getVertexList(); @@ -490,56 +476,62 @@ public class BSShapeCollection : IDisposable meshPtr = BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr, indices.GetLength(0), indices, vertices.Count, verticesAsFloats); } - newShape = new BulletShape(meshPtr, ShapeData.PhysicsShapeType.SHAPE_MESH); + BulletShape newShape = new BulletShape(meshPtr, ShapeData.PhysicsShapeType.SHAPE_MESH); newShape.shapeKey = newMeshKey; - ReferenceShape(newShape, meshData); - - // meshes are already scaled by the meshmerizer - prim.Scale = new OMV.Vector3(1f, 1f, 1f); - prim.BSShape = newShape; - return true; // 'true' means a new shape has been added to this prim + return newShape; } - // Returns 'true' of a mesh was actually rebuild (we could also have one of these specs). - List m_hulls; - private bool CreateGeomHull(BSPrim prim, ShapeData shapeData, PrimitiveBaseShape pbs) + // See that hull shape exists in the physical world and update prim.BSShape. + // We could be creating the hull because scale changed or whatever. + private bool GetReferenceToHull(BSPrim prim, ShapeData shapeData, PrimitiveBaseShape pbs) { BulletShape newShape; - // Level of detail for the mesh can be different for sculpties and regular meshes. - float lod = pbs.SculptEntry ? PhysicsScene.SculptLOD : PhysicsScene.MeshLOD; - - ulong newHullKey = (ulong)pbs.GetMeshKey(shapeData.Size, lod); + float lod; + ulong newHullKey = ComputeShapeKey(shapeData, pbs, out lod); // if the hull hasn't changed, don't rebuild it if (newHullKey == prim.BSShape.shapeKey) return false; - DetailLog("{0},BSShapeCollection.CreateGeomHull,create,oldKey={1},newKey={2}", prim.LocalID, newHullKey, newHullKey); + DetailLog("{0},BSShapeCollection.CreateGeomHull,create,oldKey={1},newKey={2}", + prim.LocalID, prim.BSShape.shapeKey.ToString("X"), newHullKey.ToString("X")); - // Remove references to the previous shape. Also removes reference to underlying mesh. + // Remove usage of the previous shape. Also removes reference to underlying mesh if it is a hull. DereferenceShape(prim.BSShape, true); - // Do not let the mesh dereference itself again. Was done in the above DerefereceShape(). - prim.BSShape.type = ShapeData.PhysicsShapeType.SHAPE_UNKNOWN; - - // Make sure the underlying mesh exists and is correct. - // Since we're in the hull code, we know CreateGeomMesh() will not create a native shape. - CreateGeomMesh(prim, shapeData, pbs); - MeshDesc meshDesc = Meshes[newHullKey]; + newShape = CreatePhysicalHull(prim.PhysObjectName, newHullKey, pbs, shapeData.Size, lod); + + if (!ReferenceShape(newShape)) + { + PhysicsScene.Logger.ErrorFormat("{0} Created new hull shape but one already exists: id={1}, key={2}, refCnt={3}", + LogHeader, shapeData.ID, newHullKey.ToString("X"), Hulls[newHullKey].referenceCount); + } + // hulls are already scaled by the meshmerizer + prim.Scale = new OMV.Vector3(1f, 1f, 1f); + prim.BSShape = newShape; + return true; // 'true' means a new shape has been added to this prim + } + + List m_hulls; + private BulletShape CreatePhysicalHull(string objName, ulong newHullKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) + { IntPtr hullPtr; HullDesc hullDesc; if (Hulls.TryGetValue(newHullKey, out hullDesc)) { // If the hull shape already is created, just use it. - hullPtr = hullDesc.Ptr; + hullPtr = hullDesc.ptr; } else { // Build a new hull in the physical world - int[] indices = meshDesc.meshData.getIndexListAsInt(); - List vertices = meshDesc.meshData.getVertexList(); + // Pass false for physicalness as this creates some sort of bounding box which we don't need + IMesh meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, false); + + int[] indices = meshData.getIndexListAsInt(); + List vertices = meshData.getVertexList(); //format conversion from IMesh format to DecompDesc format List convIndices = new List(); @@ -616,20 +608,13 @@ public class BSShapeCollection : IDisposable } } // create the hull data structure in Bullet - // m_log.DebugFormat("{0}: CreateGeom: calling CreateHull. lid={1}, key={2}, hulls={3}", LogHeader, LocalID, _hullKey, hullCount); hullPtr = BulletSimAPI.CreateHullShape2(PhysicsScene.World.ptr, hullCount, convHulls); } - newShape = new BulletShape(hullPtr, ShapeData.PhysicsShapeType.SHAPE_HULL); + BulletShape newShape = new BulletShape(hullPtr, ShapeData.PhysicsShapeType.SHAPE_HULL); newShape.shapeKey = newHullKey; - newShape.meshPtr = meshDesc.Ptr; - - ReferenceShape(newShape); - // meshes and hulls are already scaled by the meshmerizer - prim.Scale = new OMV.Vector3(1f, 1f, 1f); - prim.BSShape = newShape; - return true; // 'true' means a new shape has been added to this prim + return newShape; // 'true' means a new shape has been added to this prim } // Callback from convex hull creater with a newly created hull. @@ -640,7 +625,30 @@ public class BSShapeCollection : IDisposable return; } - // Create an object in Bullet if it has not already been created. + // Create a hash of all the shape parameters to be used as a key + // for this particular shape. + private ulong ComputeShapeKey(ShapeData shapeData, PrimitiveBaseShape pbs, out float retLod) + { + // level of detail based on size and type of the object + float lod = PhysicsScene.MeshLOD; + if (pbs.SculptEntry) + lod = PhysicsScene.SculptLOD; + + float maxAxis = Math.Max(shapeData.Size.X, Math.Max(shapeData.Size.Y, shapeData.Size.Z)); + if (maxAxis > PhysicsScene.MeshMegaPrimThreshold) + lod = PhysicsScene.MeshMegaPrimLOD; + + retLod = lod; + return (ulong)pbs.GetMeshKey(shapeData.Size, lod); + } + // For those who don't want the LOD + private ulong ComputeShapeKey(ShapeData shapeData, PrimitiveBaseShape pbs) + { + float lod; + return ComputeShapeKey(shapeData, pbs, out lod); + } + + // Create a body object in Bullet. // Updates prim.BSBody with the information about the new body if one is created. // Returns 'true' if an object was actually created. // Called at taint-time. @@ -665,7 +673,7 @@ public class BSShapeCollection : IDisposable } - if (mustRebuild) + if (mustRebuild || forceRebuild) { DereferenceBody(prim.BSBody, true); @@ -673,13 +681,15 @@ public class BSShapeCollection : IDisposable IntPtr bodyPtr = IntPtr.Zero; if (prim.IsSolid) { - bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, shapeData.Position, shapeData.Rotation); - DetailLog("{0},BSShapeCollection.CreateObject,mesh,ptr={1:X}", prim.LocalID, bodyPtr); + bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, + shapeData.ID, shapeData.Position, shapeData.Rotation); + DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); } else { - bodyPtr = BulletSimAPI.CreateGhostFromShape2(sim.ptr, shape.ptr, shapeData.Position, shapeData.Rotation); - DetailLog("{0},BSShapeCollection.CreateObject,ghost,ptr={1:X}", prim.LocalID, bodyPtr); + bodyPtr = BulletSimAPI.CreateGhostFromShape2(sim.ptr, shape.ptr, + shapeData.ID, shapeData.Position, shapeData.Rotation); + DetailLog("{0},BSShapeCollection.CreateBody,ghost,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); } aBody = new BulletBody(shapeData.ID, bodyPtr); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs index 093d2a4..5d5d9cb 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs @@ -111,8 +111,12 @@ public class BSTerrainManager BulletSimAPI.CreateGroundPlaneShape2(BSScene.GROUNDPLANE_ID, 1f, TERRAIN_COLLISION_MARGIN), ShapeData.PhysicsShapeType.SHAPE_GROUNDPLANE); m_groundPlane = new BulletBody(BSScene.GROUNDPLANE_ID, - BulletSimAPI.CreateBodyWithDefaultMotionState2(groundPlaneShape.ptr, Vector3.Zero, Quaternion.Identity)); + BulletSimAPI.CreateBodyWithDefaultMotionState2(groundPlaneShape.ptr, BSScene.GROUNDPLANE_ID, + Vector3.Zero, Quaternion.Identity)); BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr); + // Everything collides with the ground plane. + BulletSimAPI.SetCollisionFilterMask2(m_groundPlane.ptr, + (uint)CollisionFilterGroups.GroundPlaneFilter, (uint)CollisionFilterGroups.GroundPlaneMask); Vector3 minTerrainCoords = new Vector3(0f, 0f, HEIGHT_INITIALIZATION - HEIGHT_EQUAL_FUDGE); Vector3 maxTerrainCoords = new Vector3(DefaultRegionSize.X, DefaultRegionSize.Y, HEIGHT_INITIALIZATION); @@ -304,7 +308,11 @@ public class BSTerrainManager mapInfo.terrainBody = new BulletBody(mapInfo.ID, BulletSimAPI.CreateBodyWithDefaultMotionState2(mapInfo.terrainShape.ptr, - centerPos, Quaternion.Identity)); + id, centerPos, Quaternion.Identity)); + + BulletSimAPI.SetCollisionFilterMask2(mapInfo.terrainBody.ptr, + (uint)CollisionFilterGroups.TerrainFilter, + (uint)CollisionFilterGroups.TerrainMask); } // Make sure the entry is in the heightmap table diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs index 8480dd1..6910050 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs @@ -57,9 +57,13 @@ public struct BulletBody { ID = id; ptr = xx; + collisionFilter = 0; + collisionMask = 0; } public IntPtr ptr; public uint ID; + public CollisionFilterGroups collisionFilter; + public CollisionFilterGroups collisionMask; public override string ToString() { StringBuilder buff = new StringBuilder(); @@ -67,6 +71,13 @@ public struct BulletBody buff.Append(ID.ToString()); buff.Append(",p="); buff.Append(ptr.ToString("X")); + if (collisionFilter != 0 && collisionMask != 0) + { + buff.Append(",f="); + buff.Append(collisionFilter.ToString("X")); + buff.Append(",m="); + buff.Append(collisionMask.ToString("X")); + } buff.Append(">"); return buff.ToString(); } @@ -80,7 +91,6 @@ public struct BulletShape type=ShapeData.PhysicsShapeType.SHAPE_UNKNOWN; shapeKey = 0; isNativeShape = false; - meshPtr = IntPtr.Zero; } public BulletShape(IntPtr xx, ShapeData.PhysicsShapeType typ) { @@ -88,14 +98,12 @@ public struct BulletShape type = typ; shapeKey = 0; isNativeShape = false; - meshPtr = IntPtr.Zero; } public IntPtr ptr; public ShapeData.PhysicsShapeType type; public ulong shapeKey; public bool isNativeShape; // Hulls have an underlying mesh. A pointer to it is hidden here. - public IntPtr meshPtr; public override string ToString() { StringBuilder buff = new StringBuilder(); @@ -107,8 +115,6 @@ public struct BulletShape buff.Append(shapeKey.ToString("X")); buff.Append(",n="); buff.Append(isNativeShape.ToString()); - buff.Append(",m="); - buff.Append(meshPtr.ToString("X")); buff.Append(">"); return buff.ToString(); } @@ -124,7 +130,7 @@ public struct BulletConstraint public IntPtr Ptr; } -// An allocated HeightMapThing which hold various heightmap info +// 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. @@ -345,21 +351,41 @@ public enum CollisionFlags : uint // Values for collisions groups and masks public enum CollisionFilterGroups : uint { - NoneFilter = 0, - DefaultFilter = 1 << 0, - StaticFilter = 1 << 1, - KinematicFilter = 1 << 2, - DebrisFilter = 1 << 3, - SensorTrigger = 1 << 4, - CharacterFilter = 1 << 5, - AllFilter = 0xFFFFFFFF, + // Don't use the bit definitions!! Define the use in a + // filter/mask definition below. This way collision interactions + // are more easily debugged. + BNoneFilter = 0, + BDefaultFilter = 1 << 0, + BStaticFilter = 1 << 1, + BKinematicFilter = 1 << 2, + BDebrisFilter = 1 << 3, + BSensorTrigger = 1 << 4, + BCharacterFilter = 1 << 5, + BAllFilter = 0xFFFFFFFF, // Filter groups defined by BulletSim - GroundPlaneFilter = 1 << 10, - TerrainFilter = 1 << 11, - RaycastFilter = 1 << 12, - SolidFilter = 1 << 13, + BGroundPlaneFilter = 1 << 10, + BTerrainFilter = 1 << 11, + BRaycastFilter = 1 << 12, + BSolidFilter = 1 << 13, + + // The collsion filters and masked are defined in one place -- don't want them scattered + AvatarFilter = BDefaultFilter | BCharacterFilter | BSolidFilter, + AvatarMask = BAllFilter, + ObjectFilter = BDefaultFilter | BSolidFilter, + ObjectMask = BAllFilter, + StaticObjectFilter = BDefaultFilter | BStaticFilter | BSolidFilter, + StaticObjectMask = BAllFilter, + VolumeDetectFilter = BSensorTrigger, + VolumeDetectMask = ~BSensorTrigger, + TerrainFilter = BTerrainFilter, + TerrainMask = BAllFilter, + GroundPlaneFilter = BAllFilter, + GroundPlaneMask = BAllFilter + }; + + // CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0 // ERP controls amount of correction per tick. Usable range=0.1..0.8. Default=0.2. public enum ConstraintParams : int @@ -560,7 +586,7 @@ public static extern IntPtr CreateHullShape2(IntPtr world, int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr BuildHullShape2(IntPtr world, IntPtr meshShape); +public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData); @@ -581,7 +607,7 @@ public static extern void RemoveChildFromCompoundShape2(IntPtr cShape, IntPtr re public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateBodyFromShapeAndInfo2(IntPtr sim, IntPtr shape, IntPtr constructionInfo); +public static extern IntPtr CreateBodyFromShapeAndInfo2(IntPtr sim, IntPtr shape, uint id, IntPtr constructionInfo); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape); @@ -590,13 +616,13 @@ public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape); public static extern int GetBodyType2(IntPtr obj); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, Vector3 pos, Quaternion rot); +public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, Vector3 pos, Quaternion rot); +public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint id, Vector3 pos, Quaternion rot); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, Vector3 pos, Quaternion rot); +public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern IntPtr AllocateBodyInfo2(IntPtr obj); @@ -1015,6 +1041,9 @@ public static extern Vector3 GetPushVelocity2(IntPtr obj); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern Vector3 GetTurnVelocity2(IntPtr obj); +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetCollisionFilterMask2(IntPtr body, uint filter, uint mask); + // ===================================================================================== // btCollisionShape entries @@ -1066,9 +1095,6 @@ public static extern void SetMargin2(IntPtr shape, float val); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern float GetMargin2(IntPtr shape); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetCollisionFilterMask(IntPtr shape, uint filter, uint mask); - // ===================================================================================== // Debugging [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -- cgit v1.1