コード例 #1
0
 // Loop through all the known hulls and return the description based on the physical address.
 public static bool TryGetConvexHullByPtr(BulletShape pShape, out BSShapeConvexHull outHull)
 {
     bool ret = false;
     BSShapeConvexHull foundDesc = null;
     lock (ConvexHulls)
     {
         foreach (BSShapeConvexHull sh in ConvexHulls.Values)
         {
             if (sh.physShapeInfo.ReferenceSame(pShape))
             {
                 foundDesc = sh;
                 ret = true;
                 break;
             }
         }
     }
     outHull = foundDesc;
     return ret;
 }
コード例 #2
0
        public static BSShape GetReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
        {
            float lod;
            UInt64 newMeshKey = ComputeShapeKey(prim.Size, prim.BaseShape, out lod);

            physicsScene.DetailLog("{0},BSShapeConvexHull,getReference,newKey={1},size={2},lod={3}",
                prim.LocalID, newMeshKey.ToString("X"), prim.Size, lod);
            BSShapeConvexHull retConvexHull;

            bool foundMesh = false;
            lock (ConvexHulls) {
                foundMesh = ConvexHulls.TryGetValue (newMeshKey, out retConvexHull);
            }
             
            if (foundMesh)
            {
                // The mesh has already been created. Return a new reference to same.
                retConvexHull.IncrementReference();
            }
            else
            {
                retConvexHull = new BSShapeConvexHull(new BulletShape());
                BulletShape convexShape;

                // Get a handle to a mesh to buld the hull from
                BSShape baseMesh = BSShapeMesh.GetReference(physicsScene, false /* forceRebuild */, prim);
                if (baseMesh.physShapeInfo.isNativeShape)
                {
                    // We get here if the mesh was not creatable. Could be waiting for an asset from the disk.
                    // In the short term, we return the native shape and a later ForceBodyShapeRebuild should
                    //      get back to this code with a buildable mesh.
                    // TODO: not sure the temp native shape is freed when the mesh is rebuilt. When does this get freed?
                    convexShape = baseMesh.physShapeInfo;
                }
                else
                {
                    convexShape = physicsScene.PE.BuildConvexHullShapeFromMesh(physicsScene.World, baseMesh.physShapeInfo);
                    convexShape.shapeKey = newMeshKey;
                    lock (ConvexHulls)
                        ConvexHulls.Add(convexShape.shapeKey, retConvexHull);
                    physicsScene.DetailLog("{0},BSShapeConvexHull.GetReference,addingNewlyCreatedShape,shape={1}",
                                           BSScene.DetailLogZero, convexShape);
                }

                // Done with the base mesh
                baseMesh.Dereference(physicsScene);
                retConvexHull.physShapeInfo = convexShape;
            }

            return retConvexHull;
        }