public override void ResetEntity(LevelGeometryEntity levelGeometryEntity, Material overrideMaterial = null)
        {
            base.ResetEntity(levelGeometryEntity, overrideMaterial);
            Entity             rep          = GetEntityRepresentation(levelGeometryEntity);
            PhysicsShapeHandle physicsShape = activePhysicsShapes[levelGeometryEntity];

            if (physicsShape == PhysicsShapeHandle.NULL)
            {
                return;                                                      // Some geometry is non-collidable (i.e. planes)
            }
            rep.SetPhysicsShape(physicsShape, Vector3.ZERO, LevelGeometry.GEOMETRY_MASS, forceIntransigence: true);

            if (rep is PresetMovementEntity)
            {
                foreach (LevelGameObject levelGameObject in GameObjects.Where(go => go.GroundingGeometryEntity == levelGeometryEntity))
                {
                    GroundableEntity goRep = GetGameObjectRepresentation(levelGameObject);
                    goRep.Ground((PresetMovementEntity)rep);
                }
            }
        }
 public static bool CacheContainsHandle(PhysicsShapeHandle handle)
 {
     lock (staticMutationLock) {
         return(cache.ContainsValue(handle));
     }
 }
        public override void ResetEntityPhysics(bool fullReset)
        {
            LosgapSystem.InvokeOnMasterAsync(() => {             // Because creating geometryEntity shapes invoke on master and it can create locking deadlocks
                Vector3 physicsShapeOffset;
                lock (instanceMutationLock) {
                    if (fullReset)
                    {
                        foreach (PhysicsShapeHandle shapeHandle in activePhysicsShapes.Values.Distinct())
                        {
                            if (!WorldModelCache.CacheContainsHandle(shapeHandle))
                            {
                                shapeHandle.Dispose();
                            }
                        }
                        activePhysicsShapes.Clear();
                    }
                    List <PhysicsShapeHandle> unusedHandles = activePhysicsShapes.Values.Distinct().ToList();
                    foreach (KeyValuePair <LevelGeometryEntity, GeometryEntity> kvp in currentGeometryEntities)
                    {
                        PhysicsShapeHandle physicsShape = PhysicsShapeHandle.NULL;
                        if (kvp.Key.Geometry is LevelGeometry_Model)
                        {
                            LevelGeometry_Model geomAsModel = (LevelGeometry_Model)kvp.Key.Geometry;
                            var matchingEntity = activePhysicsShapes.Keys.FirstOrDefault(e => e.Geometry is LevelGeometry_Model && ((LevelGeometry_Model)e.Geometry).HasIdenticalPhysicsShape(geomAsModel));
                            if (matchingEntity != null)
                            {
                                physicsShape = activePhysicsShapes[matchingEntity];
                            }
                        }
                        else
                        {
                            if (activePhysicsShapes.ContainsKey(kvp.Key))
                            {
                                physicsShape = activePhysicsShapes[kvp.Key];
                            }
                        }
                        if (physicsShape == PhysicsShapeHandle.NULL)
                        {
                            physicsShape = kvp.Key.Geometry.CreatePhysicsShape(out physicsShapeOffset);
                        }
                        if (physicsShape == PhysicsShapeHandle.NULL)
                        {
                            continue;                                                                  // Some geometry is non-collidable (i.e. planes)
                        }
                        kvp.Value.SetPhysicsShape(physicsShape, Vector3.ZERO, LevelGeometry.GEOMETRY_MASS, forceIntransigence: true);
                        activePhysicsShapes[kvp.Key] = physicsShape;
                        if (!fullReset && unusedHandles.Contains(physicsShape))
                        {
                            unusedHandles.Remove(physicsShape);
                        }
                    }

                    if (!fullReset)
                    {
                        foreach (var unusedHandle in unusedHandles)
                        {
                            activePhysicsShapes.RemoveWhere(kvp => kvp.Value == unusedHandle);
                            if (!WorldModelCache.CacheContainsHandle(unusedHandle))
                            {
                                unusedHandle.Dispose();
                            }
                        }
                    }
                }
            });
        }
 public static void SetCachedModel(string filename, PhysicsShapeHandle handle)
 {
     lock (staticMutationLock) {
         cache[filename] = handle;
     }
 }