private void SplitChunck(PlanetManager.Chunck chunckToSplit, CelestialBodyData.TerrainData.DetailLevel[] detailLevels) { chunckToSplit.chunckTransform.gameObject.SetActive(false); this.activeChuncks.Remove(chunckToSplit); double chunckSize = detailLevels[chunckToSplit.LODId + 1].chunckSize; bool flag = chunckToSplit.LODId + 1 == detailLevels.Length - 1; PlanetManager.Chunck chunck = new PlanetManager.Chunck(chunckToSplit.from, chunckSize, chunckToSplit.LODId + 1, Ref.controller.loadedPlanet, detailLevels, this.chuncksHolder, false, flag); PlanetManager.Chunck chunck2 = new PlanetManager.Chunck(chunckToSplit.from + chunckSize, chunckSize, chunckToSplit.LODId + 1, Ref.controller.loadedPlanet, detailLevels, this.chuncksHolder, false, flag); this.activeChuncks.Add(chunck); this.activeChuncks.Add(chunck2); chunck.chunckTransform.localPosition = ((!flag) ? Vector3.zero : (-chunck.chunckPosOffset)); chunck2.chunckTransform.localPosition = ((!flag) ? Vector3.zero : (-chunck2.chunckPosOffset)); chunck.secondHalf = chunck2; chunck.parentChunck = chunckToSplit; chunck2.updateMerge = double.PositiveInfinity; chunck.chunckTransform.name = "Chunck - Lod: " + (chunckToSplit.LODId + 1).ToString(); chunck2.chunckTransform.name = "Chunck - Lod: " + (chunckToSplit.LODId + 1).ToString(); if (chunckToSplit.LODId + 1 == detailLevels.Length - 1) { chunck.GenerateCollider(); chunck2.GenerateCollider(); this.colliderChuncks.Add(chunck); this.colliderChuncks.Add(chunck2); chunck.updateSplit = double.PositiveInfinity; chunck2.updateSplit = double.PositiveInfinity; } else { this.TrySplitChunck(chunck, detailLevels); this.TrySplitChunck(chunck2, detailLevels); } }
private void LoadBaseChuncks(CelestialBodyData planet) { if (planet.type != CelestialBodyData.Type.Star) { for (int i = 0; i < planet.terrainData.heightMaps[0].heightMap.HeightDataArray.Length / planet.terrainData.baseChunckSize; i++) { PlanetManager.Chunck chunck = new PlanetManager.Chunck((double)(i * planet.terrainData.baseChunckSize), (double)planet.terrainData.baseChunckSize, 0, planet, planet.terrainData.detailLevels, this.chuncksHolder, false, false); chunck.updateMerge = double.PositiveInfinity; this.activeChuncks.Add(chunck); } } }
private void TryMergeChunck(PlanetManager.Chunck chunck, CelestialBodyData.TerrainData.DetailLevel[] detailLevels) { double loadDistance = detailLevels[chunck.LODId].loadDistance; double minDistanceToVessels = this.GetMinDistanceToVessels(chunck.parentChunck); if (minDistanceToVessels > loadDistance + 10.0) { this.MergeChunck(chunck); } if (minDistanceToVessels != double.PositiveInfinity) { chunck.updateMerge = this.totalDistanceMoved + Math.Min(loadDistance - minDistanceToVessels, 100000.0) + 30.0; } }
public LowRezPlanet(CelestialBodyData planet) { PlanetManager.Chunck chunck = new PlanetManager.Chunck(0.0, (double)planet.terrainData.heightMaps[0].heightMap.HeightDataArray.Length, 0, planet, planet.terrainData.detailLevels, null, false, false); this.planet = planet; this.meshHolder = chunck.chunckTransform; this.meshHolder.localScale = Vector3.one / 10000f; this.meshHolder.gameObject.layer = LayerMask.NameToLayer("Scaled Space"); this.meshHolder.name = planet.bodyName + " Scaled"; this.meshHolder.parent = Ref.planetManager.scaledHolder; if (!planet.atmosphereData.hasAtmosphere) { return; } PlanetManager.LowRezPlanets.LowRezPlanet.CreateAtmosphere(this.meshHolder, planet, planet.atmosphereData.gradientHightMultiplier, "Scaled Space", (planet.type != CelestialBodyData.Type.Star) ? "Back" : "Default", (planet.type != CelestialBodyData.Type.Star) ? 0 : 500, planet.GenerateAtmosphereTexture()); }
private Transform CreateScaledTerrain(CelestialBodyData planet, Transform parent) { Transform chunckTransform = new PlanetManager.Chunck(16.0, (double)planet.terrainData.heightMaps[0].heightMap.HeightDataArray.Length, planet.terrainData.mapDetailLevelId, planet, planet.terrainData.detailLevels, base.transform, true, false).chunckTransform; chunckTransform.gameObject.layer = base.gameObject.layer; chunckTransform.localScale = Vector3.one * 1.0001f / 10000f; chunckTransform.parent = parent; chunckTransform.localPosition = Vector3.zero; MeshRenderer component = chunckTransform.GetComponent <MeshRenderer>(); component.sortingOrder = 10; component.sortingLayerName = "Map"; chunckTransform.name = "Mesh ( " + planet.bodyName + ")"; return(chunckTransform); }
private void MergeChunck(PlanetManager.Chunck firstHalf) { PlanetManager.Chunck secondHalf = firstHalf.secondHalf; if (!secondHalf.chunckTransform.gameObject.activeSelf) { return; } firstHalf.parentChunck.chunckTransform.gameObject.SetActive(true); this.activeChuncks.Add(firstHalf.parentChunck); this.activeChuncks.Remove(firstHalf); this.activeChuncks.Remove(secondHalf); this.colliderChuncks.Remove(firstHalf); this.colliderChuncks.Remove(secondHalf); UnityEngine.Object.Destroy(firstHalf.chunckTransform.gameObject); UnityEngine.Object.Destroy(firstHalf.secondHalf.chunckTransform.gameObject); }
private bool TrySplitChunck(PlanetManager.Chunck chunck, CelestialBodyData.TerrainData.DetailLevel[] detailLevels) { double loadDistance = detailLevels[chunck.LODId + 1].loadDistance; double minDistanceToVessels = this.GetMinDistanceToVessels(chunck); if (minDistanceToVessels < loadDistance + 10.0) { this.SplitChunck(chunck, detailLevels); return(true); } if (minDistanceToVessels != double.PositiveInfinity) { chunck.updateSplit = this.totalDistanceMoved + Math.Min(minDistanceToVessels - loadDistance, 100000.0); } return(false); }
private double GetMinDistanceToVessels(PlanetManager.Chunck chunck) { double num = double.PositiveInfinity; for (int i = 0; i < Ref.controller.vessels.Count; i++) { if (Ref.controller.vessels[i].state == Vessel.State.RealTime || Ref.controller.vessels[i].state == Vessel.State.Stationary) { Double3 @double = (Ref.controller.vessels[i].state != Vessel.State.RealTime) ? Ref.controller.vessels[i].GetGlobalPosition : (Ref.positionOffset + Ref.controller.vessels[i].partsManager.rb2d.transform.position); double closestPointOnLine = Double3.GetClosestPointOnLine(chunck.topPosition, @double); Double3 a = chunck.topPosition * closestPointOnLine; double num2 = (a - @double).magnitude2d - chunck.topSizeHalf * closestPointOnLine; if (num2 < num) { num = num2; } } } return(num); }
private void UpdateChuncksLoading(CelestialBodyData.TerrainData.DetailLevel[] detailLevels) { this.totalDistanceMoved += this.GetMaxVesselsVelocity() * (double)Time.deltaTime + 0.1; for (int i = 0; i < this.activeChuncks.Count; i++) { PlanetManager.Chunck chunck = this.activeChuncks[i]; if (this.totalDistanceMoved > chunck.updateSplit) { bool flag = this.TrySplitChunck(chunck, detailLevels); if (flag) { i--; } } if (this.totalDistanceMoved > chunck.updateMerge) { this.TryMergeChunck(chunck, detailLevels); } } }