This repository contains some basic C# and Shaderlab scripts for reading and displaying NetCDF data in Unity.
CreateMesh.cs
- contains code for generating a variety of simple empty meshes in Unity (ranging from a single triangle to a 3D cube)VertexColorShader.shader
- can be used to create a custom shader in Unity such that an RGBA colour is assigned to a vertex based on its position within a meshrainbow_cube.cs
- contains functions to read a NetCDF file in Unity and print statistics to the console, then construct a 3D mesh based on the file dimensions and assign a semi-random RGBA colour to each vertex based on the custom shader 'VertexColorShader.shader'Wind_Mesh.cs
- contains code to read in a remote NetCDF file and plot the horizontal wind field onto a 3D mesh (by assigning the data values to the mesh vertex) using the custom vertex shader 'VertexColorShader.shader'netcdf_mesh_update.cs
- contains code to read in a local NetCDF file (user must provide their own), construct a 3D mesh and plot data onto it. This script contains functionality to move forward and backward in time using the keyboard arrow keys. This script was developed using cloud fraction data from a WRF file but can be modified for other types of data.MultipleFields/wrf_multi_fields.cs
- contains code similar tonetcdf_mesh_updates.cs
but includes additional 'toggle' functionality to switch between different meteorological fields on-the-fly
Most of these scripts use third-party libraries to read NetCDF files using C#. These are:
- UCAR's NetCDF-C
- nuget's SDSLite (dependent on NetCDF-C)
Download these packages to your Assets/Plugins folder within your Unity project.
- Save the scripts under Assets/Scripts and the shader under Assets/Shaders in your Unity project
- Double-click on the script in the Project panel to edit as appropriate
- If making use of the custom vertex shader, create a new material under Assets/Materials and assign the custom shader to the material
- Create a new object in the Hierarchy panel
- Add components to the new object: a mesh filter, a mesh renderer, and a C# script (link the appropriate script)
- If making use of the custom vertex shader, change the mesh renderer from its default material to the custom material you made earlier
- During these steps, you will see Unity attempt to compile the code. Check the Project/Console section to see if there are any errors in compilation.
- If compilation is successful, hit the 'play' button in the Scene to execute the code.
Here is a screenshot to show what the output of rainbow_cube.cs
should look like if successful:
Here is a screenshot to show what the output of Wind_Mesh.cs
should look like if successful (blue = negative velocity, red = positive, white = neutral):
Here is a screenshot to show what the output of netcdf_mesh_update.cs
might look like (it will depend on your file!), showing the cloud fraction (where 0 is transparent and 1 is solid white) from a WRF model output file at a particular time frame: