How to Display Earthwork Zones in Unity
Earthwork Zones, dynamically simulated in Vortex Studio, can be rendered in Unity during simulation. When a Earthwork Zone is loaded, a height field prefab is loaded from an asset bundle file located in the same directory as the Vortex file that contains the Earthwork Zone.
Manually creating prefabs and Asset Bundles
To manually create assets for the Earthwork Zone, a Unity project with the Vortex Integration Package is needed (such as VortexUnityTools or your own project), some height field and terrain prefabs must be added and the assets must be packaged in asset bundles.
For an overview of the assets workflow, refer to Workflow for Preparing and Using Assets for a Vortex Simulation with Unity Graphics.
Height Field Prefabs
At simulation time, when a Earthwork Zone instance is added, the Vortex Integration will look for a height field prefab with a specific name. The prefab name must contain the Graphics Soil hierarchy with the Graphics Soil name from the Vortex Editor explorer without the parent element that is contained in a Vortex file. The hierarchy levels are separated with period characters. Folders are omitted from the hierarchy. The name and hierarchy are case sensitive.
For example, for the following hierarchy, the prefab name would be Construction_Site.Earthwork Zone.Graphics.
Creating a Height Field Prefab
The height field prefab must have a Vortex Height Field component and a Vortex Height Field Renderer component.
Create an empty GameObject
Rename it with the proper name (see the Height Field Prefabs section introduction)
Select the created GameObject and add the VortexHeightField and VortexHeightFieldRenderer components in the inspector
Create a new material based on the DefaultHeightFieldShader shader and assign it to the VortexHeightFieldRenderer material field
Drag and drop the GameObject somewhere in the Assets folder in the project pane to create the prefab
You can create folders in in the assets folder to store the prefabs (ex: Assets/Resources/Scene)
In the following section, we present in great detail the required components and materials that compose a height field prefab.
The VortexHeightField Component
The VortexHeightField component is in charge of managing the height field data and to updating the renderer.
These public fields can be configured through the inspector:
Field | Description |
|---|---|
Height Field Offset | An height offset that can be applied to the height field. |
Hole Offset Factor | An offset factor to shrink down the hole created in the terrain where the Earthwork Zone is located. |
Blur Enabled | Enables height field geometry smoothing |
Blur Radius | Sets the smoothing factor on the height field geometry |
The VortexHeightFieldRenderer Component
This component is used to render the height field as a dynamic mesh. The mesh is generated once and updated based on the incoming height field data.
These public fields can be configured through the inspector:
Field | Description |
|---|---|
Material | The Unity material assigned to the generated height field mesh. The material must be based on the DefaultHeightFieldShader. |
Terrain Upscaling | Used to create a higher level of visual detail without having to increase the number of Dynamics cells, which can otherwise be computationally costly. |
The Height Field Material
The material must be based on the DefaultHeightFieldShader. To get a seamless transition between the overlapped terrain and the Earthwork Zone un-disturbed soil, the material must use the same parameters as the terrain node it intersects. The disturbed soil look can be controlled independently.
These public fields can be configured through the inspector:
Field | Description |
|---|---|
BaseMap | The color texture used on the un-disturbed soil. It must use the same texture from the intersected terrain material. |
NormalMap | The normal texture for the un-disturbed soil. It must use the same texture from the intersected terrain material. |
Metallic | Determines how “metal-like” the surface is (between 0 and 1). It must match the value from the intersected terrain material. |
Smoothness | Determines how smooth the surface is (between 0 and 1). It must match the value from the intersected terrain material. |
Disturbed Soil Albedo | The color texture for the disturbed soil |
Disturbed Soil Normal Map | The normal texture for the disturbed soil |
Disturbed Soil Normal Strength | The strength of the normal from the normal texture |
Disturbed Soil Texture Tiling | The disturb soil texture texture tiling |
Disturbed Blend Range And Offset | Controls the blending between the disturbed and un-disturbed soil textures. |