diff options
author | Robert Adams | 2013-05-02 12:27:30 -0700 |
---|---|---|
committer | Robert Adams | 2013-05-02 12:27:30 -0700 |
commit | 4042c82a7293c40955a14d04d9e5ae05d35ef7cf (patch) | |
tree | c07959bf5d928e4c92f93d1a4c241742b7642dc2 /OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | |
parent | BulletSim: Rebuild physical body if physical shape changes for mesh and hull. (diff) | |
download | opensim-SC_OLD-4042c82a7293c40955a14d04d9e5ae05d35ef7cf.zip opensim-SC_OLD-4042c82a7293c40955a14d04d9e5ae05d35ef7cf.tar.gz opensim-SC_OLD-4042c82a7293c40955a14d04d9e5ae05d35ef7cf.tar.bz2 opensim-SC_OLD-4042c82a7293c40955a14d04d9e5ae05d35ef7cf.tar.xz |
BulletSim: prims with no cuts created with single convex hull shape.
Parameter added to enable/disable this feature.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs index 3346626..9ef2923 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | |||
@@ -832,6 +832,80 @@ public class BSShapeCompound : BSShape | |||
832 | } | 832 | } |
833 | 833 | ||
834 | // ============================================================================================================ | 834 | // ============================================================================================================ |
835 | public class BSShapeConvexHull : BSShape | ||
836 | { | ||
837 | private static string LogHeader = "[BULLETSIM SHAPE CONVEX HULL]"; | ||
838 | public static Dictionary<System.UInt64, BSShapeConvexHull> ConvexHulls = new Dictionary<System.UInt64, BSShapeConvexHull>(); | ||
839 | |||
840 | public BSShapeConvexHull(BulletShape pShape) : base(pShape) | ||
841 | { | ||
842 | } | ||
843 | public static BSShape GetReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim) | ||
844 | { | ||
845 | float lod; | ||
846 | System.UInt64 newMeshKey = BSShape.ComputeShapeKey(prim.Size, prim.BaseShape, out lod); | ||
847 | |||
848 | physicsScene.DetailLog("{0},BSShapeMesh,getReference,newKey={1},size={2},lod={3}", | ||
849 | prim.LocalID, newMeshKey.ToString("X"), prim.Size, lod); | ||
850 | |||
851 | BSShapeConvexHull retConvexHull = null; | ||
852 | lock (ConvexHulls) | ||
853 | { | ||
854 | if (ConvexHulls.TryGetValue(newMeshKey, out retConvexHull)) | ||
855 | { | ||
856 | // The mesh has already been created. Return a new reference to same. | ||
857 | retConvexHull.IncrementReference(); | ||
858 | } | ||
859 | else | ||
860 | { | ||
861 | retConvexHull = new BSShapeConvexHull(new BulletShape()); | ||
862 | BulletShape convexShape = null; | ||
863 | |||
864 | // Get a handle to a mesh to build the hull from | ||
865 | BSShape baseMesh = BSShapeMesh.GetReference(physicsScene, false /* forceRebuild */, prim); | ||
866 | if (baseMesh.physShapeInfo.isNativeShape) | ||
867 | { | ||
868 | // We get here if the mesh was not creatable. Could be waiting for an asset from the disk. | ||
869 | // In the short term, we return the native shape and a later ForceBodyShapeRebuild should | ||
870 | // get back to this code with a buildable mesh. | ||
871 | // TODO: not sure the temp native shape is freed when the mesh is rebuilt. When does this get freed? | ||
872 | convexShape = baseMesh.physShapeInfo; | ||
873 | } | ||
874 | else | ||
875 | { | ||
876 | convexShape = physicsScene.PE.BuildConvexHullShapeFromMesh(physicsScene.World, baseMesh.physShapeInfo); | ||
877 | convexShape.shapeKey = newMeshKey; | ||
878 | ConvexHulls.Add(convexShape.shapeKey, retConvexHull); | ||
879 | } | ||
880 | |||
881 | // Done with the base mesh | ||
882 | baseMesh.Dereference(physicsScene); | ||
883 | |||
884 | retConvexHull.physShapeInfo = convexShape; | ||
885 | } | ||
886 | } | ||
887 | return retConvexHull; | ||
888 | } | ||
889 | public override BSShape GetReference(BSScene physicsScene, BSPhysObject prim) | ||
890 | { | ||
891 | // Calling this reference means we want another handle to an existing shape | ||
892 | // (usually linksets) so return this copy. | ||
893 | IncrementReference(); | ||
894 | return this; | ||
895 | } | ||
896 | // Dereferencing a compound shape releases the hold on all the child shapes. | ||
897 | public override void Dereference(BSScene physicsScene) | ||
898 | { | ||
899 | lock (ConvexHulls) | ||
900 | { | ||
901 | this.DecrementReference(); | ||
902 | physicsScene.DetailLog("{0},BSShapeConvexHull.Dereference,shape={1}", BSScene.DetailLogZero, this); | ||
903 | // TODO: schedule aging and destruction of unused meshes. | ||
904 | } | ||
905 | } | ||
906 | } | ||
907 | |||
908 | // ============================================================================================================ | ||
835 | public class BSShapeAvatar : BSShape | 909 | public class BSShapeAvatar : BSShape |
836 | { | 910 | { |
837 | private static string LogHeader = "[BULLETSIM SHAPE AVATAR]"; | 911 | private static string LogHeader = "[BULLETSIM SHAPE AVATAR]"; |