static public Color GetTextureColor(Texture2D tex, int scanPixelCount) { TC.SetTextureReadWrite(tex); Color32[] colors = tex.GetPixels32(); double r, b, g; r = b = g = 0; scanPixelCount *= scanPixelCount; int length = colors.Length / scanPixelCount; int total = 0; for (int i = 0; i < colors.Length; i += length) { r += colors[i].r / 255.0f; g += colors[i].g / 255.0f; b += colors[i].b / 255.0f; ++total; } return(new Color((float)(r / total), (float)(g / total), (float)(b / total), 1)); }
public void SetReadWriteTextureItems() { for (int i = 0; i < itemList.Count; i++) { TC.SetTextureReadWrite(itemList[i].preview.tex); } }
public void ApplyGrass(TCUnityTerrain sTerrain = null) { if (!CheckValidUnityTerrain()) { return; } if (sTerrain == null) { sTerrain = this; } CleanGrassPrototypes(sTerrain); List <DetailPrototype> detailPrototypesCleaned = new List <DetailPrototype>(); float multi = sTerrain.grassScaleMulti; bool tooManyGrassMessage = false; for (int i = 0; i < sTerrain.detailPrototypes.Count; i++) { if (detailPrototypesCleaned.Count >= TC.grassLimit) { tooManyGrassMessage = true; break; } TC_DetailPrototype s = sTerrain.detailPrototypes[i]; DetailPrototype d = new DetailPrototype(); d.bendFactor = s.bendFactor; d.dryColor = s.dryColor; d.healthyColor = s.healthyColor; d.minHeight = s.minHeight * multi; d.maxHeight = s.maxHeight * multi; d.minWidth = s.minWidth * multi; d.maxWidth = s.maxWidth * multi; d.noiseSpread = s.noiseSpread; d.usePrototypeMesh = s.usePrototypeMesh; d.prototype = s.prototype; d.prototypeTexture = s.prototypeTexture; d.renderMode = s.renderMode; TC.SetTextureReadWrite(d.prototypeTexture); detailPrototypesCleaned.Add(d); } if (tooManyGrassMessage) { TC.AddMessage("TC2 supports generating maximum " + TC.grassLimit + " grass textures."); Debug.Log("TC2 supports generating maximum " + TC.grassLimit + " grass textures."); } terrain.terrainData.detailPrototypes = detailPrototypesCleaned.ToArray(); }
public void ApplySplatTextures(TCUnityTerrain sTerrain = null) { if (!CheckValidUnityTerrain()) { return; } if (sTerrain == null) { sTerrain = this; } // CleanSplatTextures(sTerrain); List <SplatPrototype> splatPrototypesCleaned = new List <SplatPrototype>(); bool tooManySplatsMessage = false; for (int i = 0; i < sTerrain.splatPrototypes.Count; i++) { if (splatPrototypesCleaned.Count >= TC.splatLimit) { tooManySplatsMessage = true; break; } TC_SplatPrototype s = sTerrain.splatPrototypes[i]; if (s.texture != null) { SplatPrototype d = new SplatPrototype(); d.texture = s.texture; d.normalMap = s.normalMap; d.metallic = s.metallic; d.smoothness = s.smoothness; d.tileOffset = s.tileOffset; float tileSize = sTerrain.terrain.terrainData.size.x / Mathf.Round(sTerrain.terrain.terrainData.size.x / s.tileSize.x); d.tileSize = new Vector2(tileSize, tileSize); splatPrototypesCleaned.Add(d); TC.SetTextureReadWrite(s.texture); } } if (tooManySplatsMessage) { TC.AddMessage("TC2 supports generating maximum " + TC.splatLimit + " splat textures."); Debug.Log("TC2 supports generating maximum " + TC.splatLimit + " splat textures."); } terrain.terrainData.splatPrototypes = splatPrototypesCleaned.ToArray(); }
public void ApplyGrass(TCUnityTerrain sTerrain = null) { if (!CheckValidUnityTerrain()) { return; } if (sTerrain == null) { sTerrain = this; } CleanGrassPrototypes(sTerrain); List <DetailPrototype> DetailPrototypesCleaned = new List <DetailPrototype>(); float multi = sTerrain.grassScaleMulti; for (int i = 0; i < sTerrain.detailPrototypes.Count; i++) { TC_DetailPrototype s = sTerrain.detailPrototypes[i]; DetailPrototype d = new DetailPrototype(); d.bendFactor = s.bendFactor; d.dryColor = s.dryColor; d.healthyColor = s.healthyColor; d.minHeight = s.minHeight * multi; d.maxHeight = s.maxHeight * multi; d.minWidth = s.minWidth * multi; d.maxWidth = s.maxWidth * multi; d.noiseSpread = s.noiseSpread; d.usePrototypeMesh = s.usePrototypeMesh; d.prototype = s.prototype; d.prototypeTexture = s.prototypeTexture; d.renderMode = s.renderMode; TC.SetTextureReadWrite(d.prototypeTexture); DetailPrototypesCleaned.Add(d); } terrain.terrainData.detailPrototypes = DetailPrototypesCleaned.ToArray(); }
public void CalcPreview(bool calcValues = true) { if (!TC_Settings.instance.hasMasterTerrain) { return; } if (itemList.Count > 1) { int length = TC_Settings.instance.masterTerrain.terrainData.splatPrototypes.Length; if (outputId == TC.splatOutput) { Texture2D[] texArray = new Texture2D[length]; for (int i = 0; i < length; i++) { texArray[i] = TC_Settings.instance.masterTerrain.terrainData.splatPrototypes[i].texture; TC.SetTextureReadWrite(texArray[i]); } CalcPreview(texArray); } else { if (outputId == TC.grassOutput) { for (int i = 0; i < itemList.Count; i++) { TC.SetTextureReadWrite(itemList[i].preview.tex); } } CalcPreview(null); } } CreateMixBuffer(); // Debug.Log("CalcPreview"); TC.AutoGenerate(); }
public void ApplySplatTextures(TCUnityTerrain sTerrain = null) { if (!CheckValidUnityTerrain()) { return; } if (sTerrain == null) { sTerrain = this; } // CleanSplatTextures(sTerrain); List <SplatPrototype> splatPrototypesCleaned = new List <SplatPrototype>(); for (int i = 0; i < sTerrain.splatPrototypes.Count; i++) { TC_SplatPrototype s = sTerrain.splatPrototypes[i]; if (s.texture != null) { SplatPrototype d = new SplatPrototype(); d.texture = s.texture; d.normalMap = s.normalMap; d.metallic = s.metallic; d.smoothness = s.smoothness; d.tileOffset = s.tileOffset; float tileSize = sTerrain.terrain.terrainData.size.x / Mathf.Round(sTerrain.terrain.terrainData.size.x / s.tileSize.x); d.tileSize = new Vector2(tileSize, tileSize); splatPrototypesCleaned.Add(d); TC.SetTextureReadWrite(s.texture); } } terrain.terrainData.splatPrototypes = splatPrototypesCleaned.ToArray(); }
public void ApplySplatTextures(TC_TerrainArea terrainArea, TCUnityTerrain sTerrain = null) { if (!CheckValidUnityTerrain()) { return; } if (sTerrain == null) { sTerrain = this; } // CleanSplatTextures(sTerrain); #if UNITY_5 || UNITY_2017 || UNITY_2018_1 || UNITY_2018_2 List <SplatPrototype> splatPrototypesCleaned = new List <SplatPrototype>(); bool tooManySplatsMessage = false; for (int i = 0; i < sTerrain.splatPrototypes.Count; i++) { if (splatPrototypesCleaned.Count >= TC.splatLimit) { tooManySplatsMessage = true; break; } TC_SplatPrototype s = sTerrain.splatPrototypes[i]; if (s.texture != null) { SplatPrototype d = new SplatPrototype(); d.texture = s.texture; d.normalMap = s.normalMap; d.metallic = s.metallic; d.smoothness = s.smoothness; d.tileOffset = s.tileOffset; float tileSize = sTerrain.terrain.terrainData.size.x / Mathf.Round(sTerrain.terrain.terrainData.size.x / s.tileSize.x); d.tileSize = new Vector2(tileSize, tileSize); splatPrototypesCleaned.Add(d); TC.SetTextureReadWrite(s.texture); } } if (tooManySplatsMessage) { TC.AddMessage("TC2 supports generating maximum " + TC.splatLimit + " splat textures."); Debug.Log("TC2 supports generating maximum " + TC.splatLimit + " splat textures."); } terrain.terrainData.splatPrototypes = splatPrototypesCleaned.ToArray(); #else List <TerrainLayer> splatPrototypesCleaned = new List <TerrainLayer>(); bool tooManySplatsMessage = false; for (int i = 0; i < sTerrain.splatPrototypes.Count; i++) { if (splatPrototypesCleaned.Count >= TC.splatLimit) { tooManySplatsMessage = true; break; } TC_SplatPrototype s = sTerrain.splatPrototypes[i]; if (s.texture != null) { TerrainLayer d = new TerrainLayer(); d.diffuseTexture = s.texture; d.normalMapTexture = s.normalMap; d.normalScale = s.normalScale; d.metallic = s.metallic; d.smoothness = s.smoothness; d.tileOffset = s.tileOffset; float tileSize = sTerrain.terrain.terrainData.size.x / Mathf.Round(sTerrain.terrain.terrainData.size.x / s.tileSize.x); d.tileSize = new Vector2(tileSize, tileSize); splatPrototypesCleaned.Add(d); TC.SetTextureReadWrite(s.texture); } } if (tooManySplatsMessage) { TC.AddMessage("TC2 supports generating maximum " + TC.splatLimit + " splat textures."); Debug.Log("TC2 supports generating maximum " + TC.splatLimit + " splat textures."); } TerrainLayer[] newTerrainLayers = splatPrototypesCleaned.ToArray(); #if UNITY_EDITOR string terrainPath = "Assets" + terrainArea.terrainDataPath.Replace(Application.dataPath, String.Empty); for (int i = 0; i < newTerrainLayers.Length; i++) { string path; if (terrainArea.useSameTerrainLayersForAllTerrains) { path = terrainPath + "/" + terrainArea.terrainName + "_TerrainLayer_" + i + ".asset"; } else { path = terrainPath + "/" + terrain.name + "_TerrainLayer_" + i + ".asset"; } TerrainLayer terrainLayer = UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(TerrainLayer)) as TerrainLayer; if (terrainLayer == null) { UnityEditor.AssetDatabase.DeleteAsset(path); UnityEditor.AssetDatabase.CreateAsset(newTerrainLayers[i], path); } else { CopyTerrainLayer(newTerrainLayers[i], terrainLayer); newTerrainLayers[i] = terrainLayer; } } #endif terrain.terrainData.terrainLayers = newTerrainLayers; #endif }