Vegetation Mask Line
Vegetation Mask Line
The VegetationMaskLine component will handle run-time masking of vegetation. It is designed to be added to GameObjects in the scene and will make the vegetation adapt to them based on the settings. A mask will follow, scale and rotate with the GameObject. It can also be saved with prefabs and instanced at run-time.
In addition to the area defined by the nodes in the component, each vegetation type, Grass, Plants, Trees, Objects and Large Objects can be filtered and can have an additional range outside of the polygon mask area.
Masks are used at spawn time when new areas are loaded and will not affect rendering speed. Masking out vegetation may result in better performance.
You can add or delete nodes direct in the editor. Nodes will follow terrain. Ctrl-Click in terrain to add new nodes. They will be positioned between the 2 closest nodes. Ctrl-Shift-Click to delete nodes.
Show area will draw a line around the polygon area in scene view in the editor.
Show handles will add movement handles to the scene view to move nodes. With high node count polygons (100+) handles at a distance will not show.
Mask name will show up as a label in the center polygon in sceneview when option is turned on in VegetationStudioManager component.
Global vegetation removal
In order to remove vegetation within the polygon area enable Remove Grass, Plants, Trees, Objects or Large objects.
Additional perimeter distances is in meters and can be set separately for each category. This will expand the polygon in all directions.
The additional perimeter range has a min/max value. The distance between these is using a perlin noise for the falloff to give a more organic edge to the mask. You can adjust the Noice scale to get a result you like
Localized vegetation placement
Localized vegetation placement is used to include a vegetation type in a mask line. This could be used to introduce a new plant as a hedge, plant trees in a row by a road etc. that does not spawn in the rest of the environment. In order to use enable the Include vegetation checkbox and add one or more Vegetation Types. The Vegetation item you want to spawn will have to be set with the same Vegetation Type ID in the Vegetation System component.
The vegetation item will be spawned inside the polygon with all normal rules set in the Vegetation System inspector.
The Density and size of these rules can be overridden on a mask to mask basis. This can give the effect of plants growing over time etc. These settings can be set run-time. This could allow you to switch plants in a field, make them bigger etc.
Width setting controls the with of the line mask.
The VegetationMaskLine component can be added to any GameObject run-time. The mask settings and points can be changed at any time. The UpdateVegetationMask() function must be called after changes from script.
Available mask settings and default values are:
public bool RemoveGrass = true;
public bool RemovePlants = true;
public bool RemoveTrees = true;
public bool RemoveObjects = true;
public bool RemoveLargeObjects = true;
public float AdditionalGrassPerimiter = 0;
public float AdditionalPlantPerimiter = 0;
public float AdditionalTreePerimiter = 0;
public float AdditionalObjectPerimiter = 0;
public float AdditionalLargeObjectPerimiter = 0;
Adding a new mask to a gameobject:
VegetationMaskLine vegetationMaskLine = this.gameObject.AddComponent<VegetationMaskLine>();
vegetationMaskLine.RemoveGrass = true;
vegetationMaskLine.AdditionalGrassPerimiter = 5f;
//Points in the array list needs to be in worldspace positions.
The VegetationMaskLine will internally create a object of the type PolygonMaskLine. If you have your own system to manage polygon areas you want to mask you can also do this direct. You need to create a new PolygonMaskLine object, configure it and add it to the static VegetationStudioManager.AddVegetationMask(maskLine); function.
You will be responsible for keeping a reference to the PolygonMaskLine object and remove it and add a new if you want to change it. VegetationStudioManager.RemoveVegetationMask(maskLine);
Internally the VegetationMaskLine component will make one PolygonMaskLine object per segment in the line.
List<Vector3> worldSpaceNodeList = GetWorldSpaceNodePositions();
//Replace GetWorldSpaceNodePositions with your own code to make a list if Vector3 positions in worldspace.
PolygonMaskLine maskLine = new PolygonMaskLine
removeGrass = RemoveGrass,
removePlants = RemovePlants,
removeTrees = RemoveTrees,
removeObjects = RemoveObjects,
removeLargeObjects = RemoveLargeObjects,
additionalGrassWidth = AdditionalGrassPerimiter,
additionalPlantWidth = AdditionalPlantPerimiter,
additionalTreeWidth = AdditionalTreePerimiter,
additionalObjectWidth = AdditionalObjectPerimiter,
additionalLargeObjectWidth = AdditionalLargeObjectPerimiter
Look in VegetationMaskLine.cs for example on how to add localized vegetation placement from code also.