void generateTextures() { List <TTexture> Textures = new List <TTexture>(); for (int i = 0; i < textures.Length; i++) { Texture2D t = textures[i]; TTexture TTex = new TTexture(); TTex.texture = t; TTex.tilesize = new Vector2(16, 16); TTex.index = i; TTex.heightCurve = heightCurve; TTex.angleCurve = angleCurve; Textures.Add(TTex); } TerrainTexturing.GenerateTexture(Textures); }
public void Init(Terrain terrainOverride = null, TerrainConfig configOverride = null) { if (Object.op_Inequality((Object)terrainOverride, (Object)null)) { this.terrain = terrainOverride; } if (Object.op_Inequality((Object)configOverride, (Object)null)) { this.config = configOverride; } TerrainMeta.Terrain = this.terrain; TerrainMeta.Config = this.config; TerrainMeta.Transform = ((Component)this.terrain).get_transform(); TerrainMeta.Data = this.terrain.get_terrainData(); TerrainMeta.Size = this.terrain.get_terrainData().get_size(); TerrainMeta.OneOverSize = Vector3Ex.Inverse(TerrainMeta.Size); TerrainMeta.Position = this.terrain.GetPosition(); TerrainMeta.Collider = (TerrainCollider)((Component)this.terrain).GetComponent <TerrainCollider>(); TerrainMeta.Collision = (TerrainCollision)((Component)this.terrain).GetComponent <TerrainCollision>(); TerrainMeta.Physics = (TerrainPhysics)((Component)this.terrain).GetComponent <TerrainPhysics>(); TerrainMeta.Colors = (TerrainColors)((Component)this.terrain).GetComponent <TerrainColors>(); TerrainMeta.Quality = (TerrainQuality)((Component)this.terrain).GetComponent <TerrainQuality>(); TerrainMeta.Path = (TerrainPath)((Component)this.terrain).GetComponent <TerrainPath>(); TerrainMeta.BiomeMap = (TerrainBiomeMap)((Component)this.terrain).GetComponent <TerrainBiomeMap>(); TerrainMeta.AlphaMap = (TerrainAlphaMap)((Component)this.terrain).GetComponent <TerrainAlphaMap>(); TerrainMeta.BlendMap = (TerrainBlendMap)((Component)this.terrain).GetComponent <TerrainBlendMap>(); TerrainMeta.HeightMap = (TerrainHeightMap)((Component)this.terrain).GetComponent <TerrainHeightMap>(); TerrainMeta.SplatMap = (TerrainSplatMap)((Component)this.terrain).GetComponent <TerrainSplatMap>(); TerrainMeta.TopologyMap = (TerrainTopologyMap)((Component)this.terrain).GetComponent <TerrainTopologyMap>(); TerrainMeta.WaterMap = (TerrainWaterMap)((Component)this.terrain).GetComponent <TerrainWaterMap>(); TerrainMeta.DistanceMap = (TerrainDistanceMap)((Component)this.terrain).GetComponent <TerrainDistanceMap>(); TerrainMeta.Texturing = (TerrainTexturing)((Component)this.terrain).GetComponent <TerrainTexturing>(); TerrainMeta.HighestPoint = new Vector3((float)TerrainMeta.Position.x, (float)(TerrainMeta.Position.y + TerrainMeta.Size.y), (float)TerrainMeta.Position.z); TerrainMeta.LowestPoint = new Vector3((float)TerrainMeta.Position.x, (float)TerrainMeta.Position.y, (float)TerrainMeta.Position.z); foreach (TerrainExtension component in (TerrainExtension[])((Component)this).GetComponents <TerrainExtension>()) { component.Init(this.terrain, this.config); } uint seed = World.Seed; int num1 = SeedRandom.Range(ref seed, 0, 4) * 90; int num2 = SeedRandom.Range(ref seed, -45, 46); int num3 = SeedRandom.Sign(ref seed); TerrainMeta.LootAxisAngle = (float)num1; TerrainMeta.BiomeAxisAngle = (float)(num1 + num2 + num3 * 90); }
public static byte[] Render(out int imageWidth, out int imageHeight, out Color background, float scale = 0.5f, bool lossy = true) { _003C_003Ec__DisplayClass17_0 CS_0024_003C_003E8__locals0 = new _003C_003Ec__DisplayClass17_0(); imageWidth = 0; imageHeight = 0; background = OffShoreColor; TerrainTexturing instance = TerrainTexturing.Instance; if (instance == null) { return(null); } Terrain component = instance.GetComponent <Terrain>(); TerrainMeta component2 = instance.GetComponent <TerrainMeta>(); CS_0024_003C_003E8__locals0.terrainHeightMap = instance.GetComponent <TerrainHeightMap>(); CS_0024_003C_003E8__locals0.terrainSplatMap = instance.GetComponent <TerrainSplatMap>(); if (component == null || component2 == null || CS_0024_003C_003E8__locals0.terrainHeightMap == null || CS_0024_003C_003E8__locals0.terrainSplatMap == null) { return(null); } CS_0024_003C_003E8__locals0.mapRes = (int)((float)World.Size * Mathf.Clamp(scale, 0.1f, 4f)); CS_0024_003C_003E8__locals0.invMapRes = 1f / (float)CS_0024_003C_003E8__locals0.mapRes; if (CS_0024_003C_003E8__locals0.mapRes <= 0) { return(null); } imageWidth = CS_0024_003C_003E8__locals0.mapRes + 1000; imageHeight = CS_0024_003C_003E8__locals0.mapRes + 1000; Color[] array = new Color[imageWidth * imageHeight]; CS_0024_003C_003E8__locals0.output = new Array2D <Color>(array, imageWidth, imageHeight); Parallel.For(0, imageHeight, delegate(int y) { y -= 500; float y2 = (float)y * CS_0024_003C_003E8__locals0.invMapRes; int num = CS_0024_003C_003E8__locals0.mapRes + 500; for (int i = -500; i < num; i++) { float x = (float)i * CS_0024_003C_003E8__locals0.invMapRes; Vector3 startColor = StartColor; float num2 = CS_0024_003C_003E8__locals0._003CRender_003Eg__GetHeight_007C0(x, y2); float num3 = Math.Max(Vector3.Dot(CS_0024_003C_003E8__locals0._003CRender_003Eg__GetNormal_007C1(x, y2), SunDirection), 0f); startColor = Vector3.Lerp(startColor, GravelColor, CS_0024_003C_003E8__locals0._003CRender_003Eg__GetSplat_007C2(x, y2, 128) * GravelColor.w); startColor = Vector3.Lerp(startColor, PebbleColor, CS_0024_003C_003E8__locals0._003CRender_003Eg__GetSplat_007C2(x, y2, 64) * PebbleColor.w); startColor = Vector3.Lerp(startColor, RockColor, CS_0024_003C_003E8__locals0._003CRender_003Eg__GetSplat_007C2(x, y2, 8) * RockColor.w); startColor = Vector3.Lerp(startColor, DirtColor, CS_0024_003C_003E8__locals0._003CRender_003Eg__GetSplat_007C2(x, y2, 1) * DirtColor.w); startColor = Vector3.Lerp(startColor, GrassColor, CS_0024_003C_003E8__locals0._003CRender_003Eg__GetSplat_007C2(x, y2, 16) * GrassColor.w); startColor = Vector3.Lerp(startColor, ForestColor, CS_0024_003C_003E8__locals0._003CRender_003Eg__GetSplat_007C2(x, y2, 32) * ForestColor.w); startColor = Vector3.Lerp(startColor, SandColor, CS_0024_003C_003E8__locals0._003CRender_003Eg__GetSplat_007C2(x, y2, 4) * SandColor.w); startColor = Vector3.Lerp(startColor, SnowColor, CS_0024_003C_003E8__locals0._003CRender_003Eg__GetSplat_007C2(x, y2, 2) * SnowColor.w); float num4 = 0f - num2; if (num4 > 0f) { startColor = Vector3.Lerp(startColor, WaterColor, Mathf.Clamp(0.5f + num4 / 5f, 0f, 1f)); startColor = Vector3.Lerp(startColor, OffShoreColor, Mathf.Clamp(num4 / 50f, 0f, 1f)); num3 = 0.5f; } startColor += (num3 - 0.5f) * 0.65f * startColor; startColor = (startColor - Half) * 0.94f + Half; startColor *= 1.05f; CS_0024_003C_003E8__locals0.output[i + 500, y + 500] = new Color(startColor.x, startColor.y, startColor.z); } }); background = CS_0024_003C_003E8__locals0.output[0, 0]; return(EncodeToFile(imageWidth, imageHeight, array, lossy)); }
private void CheckInstance() { TerrainTexturing.instance = (TerrainTexturing.instance != null ? TerrainTexturing.instance : this); }
public void OnGUI() { genClass.OnGUI(); useTexturing = EditorGUILayout.BeginToggleGroup("Setup textures", useTexturing); if (useTexturing) { if (GUILayout.Button("Clear all textures")) { List <TTexture> textures = new List <TTexture>(); TerrainTexturing.GenerateTexture(textures); } foreach (var texture in texClass) { texture.OnGUI(); } if (texClass.Count > 0) { if (GUILayout.Button("Delete last")) { texClass.RemoveAt(texClass.Count - 1); } } if (GUILayout.Button("Add texture")) { texClass.Add(new wbTexturing()); } if (texClass.Count > 0 && texClass[texClass.Count - 1].texture != null) { if (GUILayout.Button("Assign new textures")) { List <TTexture> textures = new List <TTexture>(); for (int i = 0; i < texClass.Count; i++) { TTexture TTex = new TTexture(); TTex.texture = texClass[i].texture; //TTex.color = texClass[i].color; TTex.useBump = texClass[i].useBump; if (texClass[i].useBump) { TTex.bumpmap = texClass[i].bumpmap; } else { TTex.bumpmap = texClass[i].emptyBump; } TTex.tilesize = texClass[i].tilesize; TTex.index = texClass[i].index; TTex.heightCurve = texClass[i].heightCurve; TTex.angleCurve = texClass[i].angleCurve; textures.Add(TTex); } TerrainTexturing.GenerateTexture(textures); } } } EditorGUILayout.EndToggleGroup(); useFoliage = EditorGUILayout.BeginToggleGroup("Setup foliage", useFoliage); if (useFoliage) { waterCoast = EditorGUILayout.FloatField("Tree distance from coast", waterCoast); maxSteepness = EditorGUILayout.FloatField("Max hill angle for trees", maxSteepness); if (GUILayout.Button("Generate trees")) { TerrainFoliage.maxSteepness = maxSteepness; if (GameObject.Find("Water")) { TerrainFoliage.waterLevel = GameObject.Find("Water").transform.position.y + waterCoast; } else { TerrainFoliage.waterLevel = 0.0f; } TerrainFoliage.GenerateFoliage(); } if (GUILayout.Button("Remove trees")) { TerrainFoliage.ClearTrees(); } grassDensity = EditorGUILayout.IntField("Grass density", grassDensity); if (GUILayout.Button("Generate grass")) { TerrainFoliage.GenerateGrass(); } if (GUILayout.Button("Remove grass")) { TerrainFoliage.ClearGrass(); } } EditorGUILayout.EndToggleGroup(); }