private void EnsurePhysicsSector(int x, int y, int face) { MyEnvironmentSector sector; long key = Entities.Planet.MyPlanetSectorId.MakeSectorId(x, y, face); if (!PhysicsSectors.TryGetValue(key, out sector)) { MyPlanetEnvironmentClipmapProxy proxy; if (Proxies.TryGetValue(key, out proxy)) { sector = proxy.EnvironmentSector; sector.EnablePhysics(true); } else if (HeldSectors.TryGetValue(key, out sector)) { ; } else { sector = EnvironmentDefinition.CreateSector(); MyEnvironmentSectorParameters parms = new MyEnvironmentSectorParameters(); var leafSize = m_clipmaps[face].LeafSize; var leafSizeHalf = m_clipmaps[face].LeafSize / 2; int leafCountHalf = 1 << m_clipmaps[face].Depth - 1; Matrix wmf = m_clipmaps[face].WorldMatrix; parms.SurfaceBasisX = new Vector3(leafSizeHalf, 0, 0); Vector3.RotateAndScale(ref parms.SurfaceBasisX, ref wmf, out parms.SurfaceBasisX); parms.SurfaceBasisY = new Vector3(0, leafSizeHalf, 0); Vector3.RotateAndScale(ref parms.SurfaceBasisY, ref wmf, out parms.SurfaceBasisY); parms.Environment = EnvironmentDefinition; parms.Center = Vector3D.Transform(new Vector3D((x - leafCountHalf + .5) * leafSize, (y - leafCountHalf + .5) * leafSize, 0), m_clipmaps[face].WorldMatrix); parms.DataRange = new BoundingBox2I(new Vector2I(x, y), new Vector2I(x, y)); parms.Provider = Providers[face]; parms.EntityId = Entities.Planet.MyPlanetSectorId.MakeSectorEntityId(x, y, 0, face, Planet.EntityId); parms.SectorId = Entities.Planet.MyPlanetSectorId.MakeSectorId(x, y, face); parms.Bounds = GetBoundingShape(ref parms.Center, ref parms.SurfaceBasisX, ref parms.SurfaceBasisY); sector.Init(this, ref parms); sector.EnablePhysics(true); Planet.AddChildEntity((MyEntity)sector); } PhysicsSectors.Add(key, sector); } m_sectorsWithPhysics.AddOrEnsureOnComplement(sector); }