public static void RiverTools(LandLayers landLayer, int texture, ref bool aboveTerrain, int erase = 0, int topology = 0) { Elements.MiniBoldLabel(ToolTips.riverToolsLabel); if ((int)landLayer > 1) { Elements.BeginToolbarHorizontal(); aboveTerrain = Elements.ToolbarToggle(ToolTips.aboveTerrain, aboveTerrain); if (Elements.ToolbarButton(ToolTips.paintRivers)) { MapManager.PaintRiver(landLayer, aboveTerrain, texture, topology); } if (Elements.ToolbarButton(ToolTips.eraseRivers)) { MapManager.PaintRiver(landLayer, aboveTerrain, erase, topology); } Elements.EndToolbarHorizontal(); } else { Elements.BeginToolbarHorizontal(); aboveTerrain = Elements.ToolbarToggle(ToolTips.aboveTerrain, aboveTerrain); if (Elements.ToolbarButton(ToolTips.paintRivers)) { MapManager.PaintRiver(landLayer, aboveTerrain, texture); } Elements.EndToolbarHorizontal(); } }
public static IEnumerator SetLayer(LandLayers layer, int topology = 0) { if (GroundTextures == null || BiomeTextures == null || MiscTextures == null) { GetTextures(); } switch (layer) { case LandLayers.Ground: Land.terrainData.terrainLayers = GroundTextures; Land.terrainData.SetAlphamaps(0, 0, GroundArray); LandLayer = layer; break; case LandLayers.Biome: Land.terrainData.terrainLayers = BiomeTextures; Land.terrainData.SetAlphamaps(0, 0, BiomeArray); LandLayer = layer; break; case LandLayers.Topology: LastTopologyLayer = topology; Land.terrainData.terrainLayers = MiscTextures; Land.terrainData.SetAlphamaps(0, 0, TopologyArray[topology]); LandLayer = layer; break; } TopologyLayerEnum = (TerrainTopology.Enum)TerrainTopology.IndexToType(topology); LayerSet = true; yield return(null); }
public static IEnumerator ChangeLayer(LandLayers layer, int topology = 0) { yield return(EditorCoroutineUtility.StartCoroutineOwnerless(SaveLayer())); yield return(EditorCoroutineUtility.StartCoroutineOwnerless(SetLayer(layer, topology))); LayerSet = true; }
public IEnumerator SetLayer(LandLayers layer, int topology = 0) { yield return(EditorCoroutineUtility.StartCoroutineOwnerless(SetLayerCoroutine(layer, topology))); LayerSet = true; foreach (var item in Land.terrainData.alphamapTextures) { Undo.ClearUndo(item); } }
/// <summary>Paints the layer wherever the height conditions are met with a weighting determined by the range the height falls in.</summary> /// <param name="landLayerToPaint">The LandLayer to paint. (Ground, Biome, Alpha, Topology)</param> /// <param name="heightLow">The minimum height to paint at 100% weight.</param> /// <param name="heightHigh">The maximum height to paint at 100% weight.</param> /// <param name="minBlendLow">The minimum height to start to paint. The texture weight will increase as it gets closer to the heightlow.</param> /// <param name="maxBlendHigh">The maximum height to start to paint. The texture weight will increase as it gets closer to the heighthigh.</param> /// <param name="t">The texture to paint.</param> public static void PaintHeightBlend(LandLayers landLayerToPaint, float heightLow, float heightHigh, float minBlendLow, float maxBlendHigh, int t) { switch (landLayerToPaint) { case LandLayers.Ground: case LandLayers.Biome: SetData(SetRangeBlend(GetSplatMap(landLayerToPaint), GetHeights(), t, heightLow, heightHigh, minBlendLow, maxBlendHigh), landLayerToPaint); SetLayer(LandLayer); break; } }
/// <summary> Paints the layer wherever the slope conditions are met. Includes option to blend.</summary> /// <param name="landLayerToPaint">The LandLayer to paint. (Ground, Biome, Alpha, Topology)</param> /// <param name="slopeLow">The minimum slope to paint at 100% weight.</param> /// <param name="slopeHigh">The maximum slope to paint at 100% weight.</param> /// <param name="minBlendLow">The minimum slope to start to paint. The texture weight will increase as it gets closer to the slopeLow.</param> /// <param name="maxBlendHigh">The maximum slope to start to paint. The texture weight will increase as it gets closer to the slopeHigh.</param> /// <param name="t">The texture to paint.</param> /// <param name="topology">The Topology layer, if selected.</param> public static void PaintSlopeBlend(LandLayers landLayerToPaint, float slopeLow, float slopeHigh, float minBlendLow, float maxBlendHigh, int t) // Paints slope based on the current slope input, the slope range is between 0 - 90 { switch (landLayerToPaint) { case LandLayers.Ground: case LandLayers.Biome: SetData(SetRangeBlend(GetSplatMap(landLayerToPaint), GetSlopes(), t, slopeLow, slopeHigh, minBlendLow, maxBlendHigh), landLayerToPaint); SetLayer(LandLayer); break; } }
public static void RotateTools(LandLayers landLayer, int topology = 0) { Elements.BeginToolbarHorizontal(); if (Elements.ToolbarButton(ToolTips.rotate90)) { MapManager.RotateLayer(landLayer, true, topology); } if (Elements.ToolbarButton(ToolTips.rotate270)) { MapManager.RotateLayer(landLayer, false, topology); } Elements.EndToolbarHorizontal(); }
/// <summary>Sets whole layer to the inactive texture. Alpha and Topology only.</summary> /// <param name="landLayerToPaint">The LandLayer to clear. (Alpha, Topology)</param> /// <param name="topology">The Topology layer, if selected.</param> public static void ClearLayer(LandLayers landLayerToPaint, int topology = 0) { switch (landLayerToPaint) { case LandLayers.Topology: SetData(SetValues(GetSplatMap(landLayerToPaint, topology), 1), landLayerToPaint, topology); SetLayer(LandLayer, TerrainTopology.TypeToIndex((int)TopologyLayer)); break; case LandLayers.Alpha: SetData(SetValues(AlphaArray, false), landLayerToPaint); break; } }
/// <summary>Inverts the active and inactive textures. Alpha and Topology only.</summary> /// <param name="landLayerToPaint">The LandLayer to invert. (Alpha, Topology)</param> /// <param name="topology">The Topology layer, if selected.</param> public static void InvertLayer(LandLayers landLayerToPaint, int topology = 0) { switch (landLayerToPaint) { case LandLayers.Topology: SetData(Invert(GetSplatMap(landLayerToPaint, topology)), landLayerToPaint, topology); SetLayer(LandLayer, TerrainTopology.TypeToIndex((int)TopologyLayer)); break; case LandLayers.Alpha: SetData(Invert(AlphaArray), landLayerToPaint); break; } }
/// <summary>Texture count in layer chosen, used for determining the size of the splatmap array.</summary> /// <param name="landLayer">The LandLayer to return the texture count from. (Ground, Biome, Alpha, Topology)</param> public static int TextureCount(LandLayers landLayer) { switch (landLayer) { case LandLayers.Ground: return(8); case LandLayers.Biome: return(4); default: return(2); } }
/// <summary>Rotates the selected layer.</summary> /// <param name="landLayerToPaint">The LandLayer to rotate. (Ground, Biome, Alpha, Topology)</param> /// <param name="CW">True = 90°, False = 270°</param> /// <param name="topology">The Topology layer, if selected.</param> public static void RotateLayer(LandLayers landLayerToPaint, bool CW, int topology = 0) { switch (landLayerToPaint) { case LandLayers.Ground: case LandLayers.Biome: case LandLayers.Topology: SetData(Rotate(GetSplatMap(landLayerToPaint, topology), CW), landLayerToPaint, topology); SetLayer(LandLayer, TerrainTopology.TypeToIndex((int)TopologyLayer)); break; case LandLayers.Alpha: SetData(Rotate(AlphaArray, CW), landLayerToPaint); break; } }
/// <summary>Sets whole layer to the active texture.</summary> /// <param name="landLayerToPaint">The LandLayer to paint. (Ground, Biome, Alpha, Topology)</param> /// <param name="t">The texture to paint.</param> /// <param name="topology">The Topology layer, if selected.</param> public static void PaintLayer(LandLayers landLayerToPaint, int t, int topology = 0) { switch (landLayerToPaint) { case LandLayers.Ground: case LandLayers.Biome: case LandLayers.Topology: SetData(SetValues(GetSplatMap(landLayerToPaint), t), landLayerToPaint, topology); SetLayer(LandLayer, TerrainTopology.TypeToIndex((int)TopologyLayer)); break; case LandLayers.Alpha: SetData(SetValues(AlphaArray, true), landLayerToPaint); break; } }
public static void HeightTools(LandLayers landLayer, int texture, ref HeightsInfo heightInfo, int erase = 0, int topology = 0) { Elements.MiniBoldLabel(ToolTips.heightToolsLabel); heightInfo = ClampValues(heightInfo); float tempSlopeLow = heightInfo.HeightLow; float tempSlopeHigh = heightInfo.HeightHigh; if ((int)landLayer < 2) { float tempHeightBlendLow = heightInfo.HeightBlendLow; float tempHeightBlendHigh = heightInfo.HeightBlendHigh; heightInfo.BlendHeights = Elements.ToolbarToggleMinMax(ToolTips.toggleBlend, ToolTips.rangeLow, ToolTips.rangeHigh, heightInfo.BlendHeights, ref tempSlopeLow, ref tempSlopeHigh, 0f, 1000f); heightInfo.HeightLow = tempSlopeLow; heightInfo.HeightHigh = tempSlopeHigh; if (heightInfo.BlendHeights) { Elements.ToolbarMinMax(ToolTips.blendLow, ToolTips.blendHigh, ref tempHeightBlendLow, ref tempHeightBlendHigh, 0f, 1000f); heightInfo.HeightBlendLow = tempHeightBlendLow; heightInfo.HeightBlendHigh = tempHeightBlendHigh; } Elements.BeginToolbarHorizontal(); if (Elements.ToolbarButton(ToolTips.paintHeights)) { MapManager.PaintHeight(landLayer, heightInfo.HeightLow, heightInfo.HeightHigh, texture); } if (Elements.ToolbarButton(ToolTips.paintHeightsBlend)) { MapManager.PaintHeightBlend(landLayer, heightInfo.HeightLow, heightInfo.HeightHigh, heightInfo.HeightBlendLow, heightInfo.HeightBlendHigh, texture); } Elements.EndToolbarHorizontal(); } else { Elements.ToolbarMinMax(ToolTips.rangeLow, ToolTips.rangeHigh, ref tempSlopeLow, ref tempSlopeHigh, 0f, 1000f); heightInfo.HeightLow = tempSlopeLow; heightInfo.HeightHigh = tempSlopeHigh; Elements.BeginToolbarHorizontal(); if (Elements.ToolbarButton(ToolTips.paintHeights)) { MapManager.PaintHeight(landLayer, heightInfo.HeightLow, heightInfo.HeightHigh, texture, topology); } if (Elements.ToolbarButton(ToolTips.eraseHeights)) { MapManager.PaintHeight(landLayer, heightInfo.HeightLow, heightInfo.HeightHigh, erase, topology); } Elements.EndToolbarHorizontal(); } }
public static void SlopeTools(LandLayers landLayer, int texture, ref SlopesInfo slopeInfo, int erase = 0, int topology = 0) { Elements.MiniBoldLabel(ToolTips.slopeToolsLabel); slopeInfo = ClampValues(slopeInfo); float tempSlopeLow = slopeInfo.SlopeLow; float tempSlopeHigh = slopeInfo.SlopeHigh; if ((int)landLayer < 2) { float tempSlopeBlendLow = slopeInfo.SlopeBlendLow; float tempSlopeBlendHigh = slopeInfo.SlopeBlendHigh; slopeInfo.BlendSlopes = Elements.ToolbarToggleMinMax(ToolTips.toggleBlend, ToolTips.rangeLow, ToolTips.rangeHigh, slopeInfo.BlendSlopes, ref tempSlopeLow, ref tempSlopeHigh, 0f, 90f); slopeInfo.SlopeLow = tempSlopeLow; slopeInfo.SlopeHigh = tempSlopeHigh; if (slopeInfo.BlendSlopes) { Elements.ToolbarMinMax(ToolTips.blendLow, ToolTips.blendHigh, ref tempSlopeBlendLow, ref tempSlopeBlendHigh, 0f, 90f); slopeInfo.SlopeBlendLow = tempSlopeBlendLow; slopeInfo.SlopeBlendHigh = tempSlopeBlendHigh; } Elements.BeginToolbarHorizontal(); if (Elements.ToolbarButton(ToolTips.paintSlopes)) { MapManager.PaintSlope(landLayer, slopeInfo.SlopeLow, slopeInfo.SlopeHigh, texture); } if (Elements.ToolbarButton(ToolTips.paintSlopesBlend)) { MapManager.PaintSlopeBlend(landLayer, slopeInfo.SlopeLow, slopeInfo.SlopeHigh, slopeInfo.SlopeBlendLow, slopeInfo.SlopeBlendHigh, texture); } Elements.EndToolbarHorizontal(); } else { Elements.ToolbarMinMax(ToolTips.rangeLow, ToolTips.rangeHigh, ref tempSlopeLow, ref tempSlopeHigh, 0f, 90f); slopeInfo.SlopeLow = tempSlopeLow; slopeInfo.SlopeHigh = tempSlopeHigh; Elements.BeginToolbarHorizontal(); if (Elements.ToolbarButton(ToolTips.paintSlopes)) { MapManager.PaintSlope(landLayer, slopeInfo.SlopeLow, slopeInfo.SlopeHigh, texture, topology); } if (Elements.ToolbarButton(ToolTips.eraseSlopes)) { MapManager.PaintSlope(landLayer, slopeInfo.SlopeLow, slopeInfo.SlopeHigh, erase, topology); } Elements.EndToolbarHorizontal(); } }
/// <summary>Paints the layer wherever the height conditions are met.</summary> /// <param name="landLayerToPaint">The LandLayer to paint. (Ground, Biome, Alpha, Topology)</param> /// <param name="heightLow">The minimum height to paint at 100% weight.</param> /// <param name="heightHigh">The maximum height to paint at 100% weight.</param> /// <param name="t">The texture to paint.</param> /// <param name="topology">The Topology layer, if selected.</param> public static void PaintHeight(LandLayers landLayerToPaint, float heightLow, float heightHigh, int t, int topology = 0) { switch (landLayerToPaint) { case LandLayers.Ground: case LandLayers.Biome: case LandLayers.Topology: SetData(SetRange(GetSplatMap(landLayerToPaint, topology), GetHeights(), t, heightLow, heightHigh), landLayerToPaint, topology); SetLayer(LandLayer, TerrainTopology.TypeToIndex((int)TopologyLayer)); break; case LandLayers.Alpha: bool value = (t == 0) ? true : false; SetData(SetRange(AlphaArray, GetHeights(), value, heightLow, heightHigh), landLayerToPaint); break; } }
/// <summary>Paints the splats wherever the water is above 500 and is above the terrain.</summary> /// <param name="landLayerToPaint">The LandLayer to paint. (Ground, Biome, Alpha, Topology)</param> /// <param name="aboveTerrain">Check if the watermap is above the terrain before painting.</param> /// <param name="t">The texture to paint.</param> /// <param name="topology">The Topology layer, if selected.</param> public static void PaintRiver(LandLayers landLayerToPaint, bool aboveTerrain, int t, int topology = 0) { switch (landLayerToPaint) { case LandLayers.Ground: case LandLayers.Biome: case LandLayers.Topology: SetData(SetRiver(GetSplatMap(landLayerToPaint, topology), GetHeights(), GetWaterHeights(), aboveTerrain, t), landLayerToPaint, topology); SetLayer(LandLayers.Topology, topology); break; case LandLayers.Alpha: bool value = (t == 0) ? true : false; SetData(SetRiver(AlphaArray, GetHeights(), GetWaterHeights(), aboveTerrain, value), landLayerToPaint); break; } }
/// <summary>Paints the layer wherever the slope conditions are met. Includes option to blend.</summary> /// <param name="landLayerToPaint">The LandLayer to paint. (Ground, Biome, Alpha, Topology)</param> /// <param name="slopeLow">The minimum slope to paint at 100% weight.</param> /// <param name="slopeHigh">The maximum slope to paint at 100% weight.</param> /// <param name="t">The texture to paint.</param> /// <param name="topology">The Topology layer, if selected.</param> public static void PaintSlope(LandLayers landLayerToPaint, float slopeLow, float slopeHigh, int t, int topology = 0) // Paints slope based on the current slope input, the slope range is between 0 - 90 { switch (landLayerToPaint) { case LandLayers.Ground: case LandLayers.Biome: case LandLayers.Topology: SetData(SetRange(GetSplatMap(landLayerToPaint, topology), GetSlopes(), t, slopeLow, slopeHigh), landLayerToPaint, topology); SetLayer(LandLayers.Topology, topology); break; case LandLayers.Alpha: bool value = (t == 0) ? true : false; SetData(SetRange(AlphaArray, GetSlopes(), value, slopeLow, slopeHigh), landLayerToPaint); break; } }
public static void TextureSelect(LandLayers landLayer, ref Layers layers) { Elements.MiniBoldLabel(ToolTips.textureSelectLabel); switch (landLayer) { case LandLayers.Ground: Elements.BeginToolbarHorizontal(); Elements.ToolbarLabel(ToolTips.textureSelect); layers.Ground = (TerrainSplat.Enum)Elements.ToolbarEnumPopup(layers.Ground); Elements.EndToolbarHorizontal(); break; case LandLayers.Biome: Elements.BeginToolbarHorizontal(); Elements.ToolbarLabel(ToolTips.textureSelect); layers.Biome = (TerrainBiome.Enum)Elements.ToolbarEnumPopup(layers.Biome); Elements.EndToolbarHorizontal(); break; } }
public static void LayerTools(LandLayers landLayer, int texture, int erase = 0, int topology = 0) { Elements.MiniBoldLabel(ToolTips.layerToolsLabel); Elements.BeginToolbarHorizontal(); if (Elements.ToolbarButton(ToolTips.paintLayer)) { MapManager.PaintLayer(landLayer, texture, topology); } if ((int)landLayer > 1) { if (Elements.ToolbarButton(ToolTips.clearLayer)) { MapManager.ClearLayer(landLayer, topology); } if (Elements.ToolbarButton(ToolTips.invertLayer)) { MapManager.InvertLayer(landLayer, topology); } } Elements.EndToolbarHorizontal(); }
public static void OnLayerSaved(LandLayers layer, int?topology = null) => LayerSaved?.Invoke(layer, topology);
/// <summary>Sets the active landLayer to the index.</summary> /// <param name="landIndex">The landLayer to change to.</param> /// <param name="topology">The Topology layer to set.</param> public static void SetLandLayer(LandLayers landIndex, int topology = 0) { ChangeLandLayer(landIndex, topology); }
/// <summary>Returns the value of a texture at the selected coords.</summary> /// <param name="landLayer">The LandLayer of the texture. (Ground, Biome, Alpha, Topology)</param> /// <param name="texture">The texture to get.</param> /// <param name="x">The X coordinate.</param> /// <param name="z">The Z coordinate.</param> /// <param name="topology">The Topology layer, if selected.</param> public static float GetTexture(LandLayers landLayer, int texture, int x, int z, int topology = 0) { return(GetSplatMap(landLayer, topology)[x, z, texture]); }
/// <summary>Paints if all the conditions passed in are true.</summary> /// <param name="landLayerToPaint">The LandLayer to paint. (Ground, Biome, Alpha, Topology)</param> /// <param name="texture">The texture to paint.</param> /// <param name="conditions">The conditions to check.</param> /// <param name="topology">The Topology layer, if selected.</param> public static void PaintConditional(LandLayers landLayerToPaint, int texture, Conditions conditions, int topology = 0) { int splatRes = SplatMapRes; bool[,] conditionsMet = new bool[splatRes, splatRes]; // Paints wherever the conditionsmet is false. int progressId = Progress.Start("Conditional Paint"); for (int i = 0; i < TerrainSplat.COUNT; i++) { if (conditions.GroundConditions.CheckLayer[i]) { conditionsMet = CheckConditions(GetSplatMap(LandLayers.Ground), conditionsMet, i, conditions.GroundConditions.Weight[i]); } } Progress.Report(progressId, 0.2f, "Checking Biome"); for (int i = 0; i < TerrainBiome.COUNT; i++) { if (conditions.BiomeConditions.CheckLayer[i]) { conditionsMet = CheckConditions(GetSplatMap(LandLayers.Biome), conditionsMet, i, conditions.BiomeConditions.Weight[i]); } } Progress.Report(progressId, 0.3f, "Checking Alpha"); if (conditions.AlphaConditions.CheckAlpha) { conditionsMet = CheckConditions(AlphaArray, conditionsMet, (conditions.AlphaConditions.Texture == 0) ? true : false); } Progress.Report(progressId, 0.5f, "Checking Topology"); for (int i = 0; i < TerrainTopology.COUNT; i++) { if (conditions.TopologyConditions.CheckLayer[i]) { conditionsMet = CheckConditions(GetSplatMap(LandLayers.Topology, i), conditionsMet, (int)conditions.TopologyConditions.Texture[i], 0.5f); } } Progress.Report(progressId, 0.7f, "Checking Heights"); if (conditions.TerrainConditions.CheckHeights) { conditionsMet = CheckConditions(GetHeights(), conditionsMet, conditions.TerrainConditions.Heights.HeightLow, conditions.TerrainConditions.Heights.HeightHigh); } Progress.Report(progressId, 0.8f, "Checking Slopes"); if (conditions.TerrainConditions.CheckSlopes) { conditionsMet = CheckConditions(GetSlopes(), conditionsMet, conditions.TerrainConditions.Slopes.SlopeLow, conditions.TerrainConditions.Slopes.SlopeHigh); } Progress.Report(progressId, 0.8f, "Painting"); switch (landLayerToPaint) { case LandLayers.Ground: case LandLayers.Biome: case LandLayers.Topology: float[,,] splatMapToPaint = GetSplatMap(landLayerToPaint, topology); int textureCount = TextureCount(landLayerToPaint); Parallel.For(0, splatRes, i => { for (int j = 0; j < splatRes; j++) { if (conditionsMet[i, j] == false) { for (int k = 0; k < textureCount; k++) { splatMapToPaint[i, j, k] = 0f; } splatMapToPaint[i, j, texture] = 1f; } } }); SetData(splatMapToPaint, landLayerToPaint, topology); SetLayer(landLayerToPaint, topology); break; case LandLayers.Alpha: bool[,] alphaMapToPaint = AlphaArray; Parallel.For(0, splatRes, i => { for (int j = 0; j < splatRes; j++) { alphaMapToPaint[i, j] = (conditionsMet[i, j] == false) ? conditionsMet[i, j] : alphaMapToPaint[i, j]; } }); SetData(alphaMapToPaint, landLayerToPaint); break; } Progress.Finish(progressId); }