Noun Conventions:
Cloud/contour A map/fringe--cfd/fem noun that represents the physical amount of a node or grid (cell) in color. As in the following diagram:
A grid--cfd/fem noun used to make discrete meshes of objects/fields;
Cell--cfd/fem nouns, the smallest unit of grid, a single grid, a common three-dimensional cell has six-sided, tetrahedron, two-dimensional cell has four-sided, triangular;
Node--cfd/fem noun, the vertex of a cell, called a node;
mesh--computer graphics nouns, unity3d/3dmax, etc. used for three-dimensional modeling triangular mesh;
triangle--Computer graphics noun, the smallest unit of mesh, a single triangular patch;
vertice--Computer graphics noun, the vertex of triangle;
Body:
A recent requirement is to use unity to show the physical quantities in the space, and to draw a cloud of scalar fields.
Looking for someone else on the net the plan is to write shader, netizens snow dance to provide me with the solution is to dynamically generate texture pictures, the two scenarios are applied to the premise that the physical field can be described by a simple function (shader altogether cannot pass a few parameters, the dynamic generation of textures is also given in advance distribution function).
But the scalar field in the actual project is much more complex, and it is impossible to describe it with simple functions. For example, a CFD calculation results in a number of physical quantities at a discrete point location. Turn over Lele classmate Unity Shader, I found the simpler, CPU pressure is low (because the live basically dropped to the GPU) scheme, summed up is:
Specify a color texture, the cloud plane to be drawn is discretized into a grid, according to nodes coordinate replication vertices build mesh, according to the physical amount of node to calculate the corresponding vertice in the texture image of the UV value, the UV value to each triangle for rendering.
It sounds like a heavenly book, and it's easy to actually do it.
1: Specify Color texture
Take Photoshop to make a picture, import Unity3d.
2: The cloud plane that will be drawn is discretized into a grid, and the mesh is built according to nodes coordinates vertices
I want to draw a cloud of direct sound pressure levels generated by two sound sources, and then model them according to the image below. The yellow small square is the sound source, a distance from the ground 2.6m, a ground 2.2m, the cloud picture plane is located from the ground 1.5m place, directly uses unity to provide the plane.
3: Calculates the UV value of the corresponding vertice in the texture image according to the physical amount of node, and passes the UV value to each triangle for rendering.
To plane the script, pass three parameters in: Colormapupperlimit (upper value of the Chromatogram), Colormaplowerlimit (lower value of the chromatogram), ColorMap (chromatogram texture).
The core function code is as follows, using a for loop to traverse each vertice in the mesh, the front is calculated based on the global coordinates of the Vertice local A-weighted sound pressure, the results are stored in the float variable _sp, starting from the 5th line from the bottom of the _sp to calculate the UV value of the texture
Public void displaydirectsoundpressure () { Mesh _mesh
= GetComponent<MeshFilter> (). Mesh;
matrix4x4 l_w_m = transform.localtoworldmatrix;
vector3[] _vertices = _mesh.vertices;
int _count = _mesh.vertexcount;
vector2[] _uvs = new vector2[_count]; for (int i = 0; i < _count; i++) { vector3 worldc =
L_W_M.MultiplyVector (_vertices [i]); acousticsound _s = new
acousticsound (); foreach (acousticsource item in _sources) { _s += item.
directsound (WORLDC); }
float _sp = (float) _s.aweightsoundpressure; float u = (_sp -
Colormaplowerlimit) / (colormapupperlimit - colormaplowerlimit); _uvs [i] = new vector2
(u, 0); } _mesh.uv = _uvs
; }
Texture picture is left to right, only need to use linear interpolation to calculate the U value, v value is irrelevant to a
float u = (_sp-colormaplowerlimit)/(Colormapupperlimit-colormaplowerlimit);
And put the UV value in.
_uvs [i] = new Vector2 (u, 0);
Finally, the UV array is assigned to the mesh
_MESH.UV = _uvs;
Final effect: