Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void BuildDMesh()
- {
- dmesh = new DMesh3(false,true);
- for (var i = 0; i < points.Length; i++)
- {
- dmesh.AppendVertex(points[i]);
- dmesh.SetVertexColor(i, heightGradient.Evaluate(InverseLerp(-3,7,heights[i])));
- }
- for (int y = 0; y < gridSize.y - 1; y++)
- {
- var rowStartIndex = y * gridSize.x;
- //Left Vertx Heights (ints)
- var topLeft = heights[rowStartIndex + gridSize.x];
- var bottomLeft = heights[rowStartIndex];
- for (int x = 0; x < gridSize.x - 1; x++)
- {
- var quadBottomLeftIndex = rowStartIndex + x;
- //Right Vertex Heights (ints)
- var topRight = heights[quadBottomLeftIndex + gridSize.x + 1];
- var bottomRight = heights[quadBottomLeftIndex + 1];
- //deltaHeights
- var dhtl = DeltaHeight(topLeft, bottomLeft, topRight);
- var dhtr = DeltaHeight(topRight, bottomRight, topLeft);
- var dhbl = DeltaHeight(bottomLeft, topLeft, bottomRight);
- var dhbr = DeltaHeight(bottomRight, bottomLeft, topRight);
- //if (bl == tr && (bl != tl || bl != br))
- if (Abs(dhtr - dhbl ) < Abs(dhtl - dhbr))
- {
- //bl, tl, tr
- //tr, br, bl
- dmesh.AppendTriangle(
- quadBottomLeftIndex,
- quadBottomLeftIndex + gridSize.x,
- quadBottomLeftIndex + gridSize.x + 1);
- dmesh.AppendTriangle(
- quadBottomLeftIndex + gridSize.x + 1,
- quadBottomLeftIndex + 1,
- quadBottomLeftIndex);
- }
- else
- {
- //br, bl, tl
- //tl, lt, br
- dmesh.AppendTriangle(
- quadBottomLeftIndex + 1,
- quadBottomLeftIndex,
- quadBottomLeftIndex + gridSize.x);
- dmesh.AppendTriangle(
- quadBottomLeftIndex + gridSize.x,
- quadBottomLeftIndex + gridSize.x + 1,
- quadBottomLeftIndex + 1);
- }
- bottomLeft = bottomRight; topLeft = topRight;
- }
- }
- }
- //returns the total height of 3 verticles
- public int DeltaHeight(int a, int b, int c)
- {
- int max = -100000;
- if (a > max)
- max = a;
- if (b > max)
- max = b;
- if (c > max)
- max = c;
- int min = 100000;
- if (a < min)
- min = a;
- if (b < min)
- min = b;
- if (c < min)
- min = c;
- return Abs(max - min);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement