本文整理汇总了C#中Mesh.RecalculateTangents方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.RecalculateTangents方法的具体用法?C# Mesh.RecalculateTangents怎么用?C# Mesh.RecalculateTangents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mesh
的用法示例。
在下文中一共展示了Mesh.RecalculateTangents方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Make
public static Mesh Make(Vector3[] vertices, Vector2[] uv, int[] triangles) {
Mesh mesh = new Mesh();
mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = triangles;
mesh.RecalculateNormals();
mesh.RecalculateTangents();
mesh.RecalculateBounds();
return mesh;
}
示例2: CopyToMesh
public void CopyToMesh(Mesh target) {
target.vertices = vertices;
target.normals = normals;
target.tangents = tangents;
target.uv = uv;
target.uv2 = uv2;
target.colors = colors;
target.triangles = triangles;
target.RecalculateBounds();
target.RecalculateTangents();
}
示例3: GenerateMesh
public void GenerateMesh(bool[,] cloudArray)
{
if (cloudArray == null)
return;
width = cloudArray.GetLength(0);
height = cloudArray.GetLength(1);
if (width * height > 65535)
{
width = Mathf.Clamp(width, 0, 255);
height = Mathf.Clamp(height, 0, 255);
}
Vector3[] vertexPositions = new Vector3[width * height];
vertexColors = new Color[width * height];
Vector2[] vertexUV = new Vector2[width * height];
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++)
{
int index = CoordToIndex(x, y);
vertexPositions[index] = (new Vector3(
x * 16 * 48 * GameMap.tileWidth,
0,
-y * 16 * 48 * GameMap.tileWidth) + offset) * scale;
vertexColors[index] = Color.white;
if (cloudArray[x, y])
vertexColors[index].a = 1;
else
vertexColors[index].a = 0;
vertexUV[index] = new Vector2(x, y);
}
List<int> triangles = new List<int>();
for (int x = 0; x < width - 1; x++)
for (int y = 0; y < height - 1; y++)
{
triangles.Add(CoordToIndex(x, y));
triangles.Add(CoordToIndex(x + 1, y));
triangles.Add(CoordToIndex(x + 1, y + 1));
triangles.Add(CoordToIndex(x, y));
triangles.Add(CoordToIndex(x + 1, y + 1));
triangles.Add(CoordToIndex(x, y + 1));
}
Mesh terrainMesh = new Mesh();
terrainMesh.vertices = vertexPositions;
terrainMesh.colors = vertexColors;
terrainMesh.uv = vertexUV;
terrainMesh.triangles = triangles.ToArray();
terrainMesh.RecalculateNormals();
terrainMesh.RecalculateTangents();
meshFilter.mesh = terrainMesh;
}
示例4: FillMesh
public static void FillMesh(Mesh mesh, Vector3[] vs, Vector3[] ns, Vector2[] uv1s, Vector2[] uv2s, Vector2[] uv3s, Vector2[] uv4s, Color32[] colors32, int[] ts, BoneWeight[] bws, Matrix4x4[] bindposes, int[] subMeshOffsets, bool recalcNormals)
{
mesh.vertices = vs;
if(ns != null && ns.Length > 0) mesh.normals = ns;
if(uv1s != null && uv1s.Length > 0) mesh.uv = uv1s;
if(uv2s != null && uv2s.Length > 0) mesh.uv2 = uv2s;
#if UNITY_4_3
#elif UNITY_4_4
#elif UNITY_4_5
#elif UNITY_4_6
#else
if(uv3s != null && uv2s.Length > 0) mesh.uv3 = uv3s;
if(uv4s != null && uv2s.Length > 0) mesh.uv4 = uv4s;
#endif
if(colors32 != null && colors32.Length > 0) mesh.colors32 = colors32;
if(bws != null && bws.Length > 0) mesh.boneWeights = bws;
if(bindposes != null && bindposes.Length > 0) mesh.bindposes = bindposes;
if(subMeshOffsets.Length == 1) {
mesh.triangles = ts;
} else {
mesh.subMeshCount = subMeshOffsets.Length;
for(int s=0;s<subMeshOffsets.Length;s++) {
subMeshOffsets[s] = Mathf.Max(0,subMeshOffsets[s]);
int end = s+1 < subMeshOffsets.Length ? subMeshOffsets[s+1] : ts.Length;
if(end - subMeshOffsets[s] > 0) {
int[] subTs = new int[end - subMeshOffsets[s]];
Array.Copy(ts, subMeshOffsets[s], subTs, 0, end - subMeshOffsets[s]);
mesh.SetTriangles(subTs, s);
} else {
mesh.SetTriangles((int[])null, s);
}
}
}
if(recalcNormals || mesh.normals == null || mesh.normals.Length <= 0) mesh.RecalculateNormals();
mesh.RecalculateTangents();
}
示例5: GenerateMesh
void GenerateMesh()
{
vertexPositions = new Vector3[width * height];
vertexColors = new Color[width * height];
vertexUV = new Vector2[width * height];
vertexUV2 = new Vector2[width * height];
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++)
{
int index = CoordToIndex(x, y);
vertexPositions[index] = (new Vector3(
x * 16 * 48 * GameMap.tileWidth,
elevation[x, y] * GameMap.tileHeight,
-y * 16 * 48 * GameMap.tileWidth) + offset) * scale;
//vertexColors[index] = cloudStriped[x, y] ? Color.white : Color.black;// * cloudFog[x, y] / 3.0f;
vertexColors[index] = Color.white;
vertexUV2[index] = new Vector2(rainfall[x, y], 100 - drainage[x, y]) / 100;
vertexUV[index] = new Vector2(x, y);
}
if (triangles == null)
triangles = new List<int>();
triangles.Clear();
for (int x = 0; x < width - 1; x++)
for (int y = 0; y < height - 1; y++)
{
if (DetailRegions.ContainsKey(new DFCoord2d(x, y)))
continue;
triangles.Add(CoordToIndex(x, y));
triangles.Add(CoordToIndex(x + 1, y));
triangles.Add(CoordToIndex(x + 1, y + 1));
triangles.Add(CoordToIndex(x, y));
triangles.Add(CoordToIndex(x + 1, y + 1));
triangles.Add(CoordToIndex(x, y + 1));
}
terrainMesh = new Mesh();
terrainMesh.vertices = vertexPositions;
terrainMesh.colors = vertexColors;
terrainMesh.uv = vertexUV;
terrainMesh.uv2 = vertexUV2;
terrainMesh.triangles = triangles.ToArray();
terrainMesh.RecalculateNormals();
terrainMesh.RecalculateTangents();
meshFilter.mesh = terrainMesh;
}
示例6: GenerateMesh
void GenerateMesh()
{
int h = height - 1;
int w = width - 1;
vertices.Clear();
colors.Clear();
uvCoords.Clear();
uvCoords2.Clear();
triangles.Clear();
waterVerts.Clear();
waterUvs.Clear();
waterTris.Clear();
DFCoord fortMin = DFConnection.Instance.EmbarkMapPosition - regionOrigin;
DFCoord fortMax = fortMin + (DFConnection.Instance.EmbarkMapSize / 3);
for (int x = 0; x < w; x++)
{
for (int y = 0; y < h; y++)
{
if (IsInCoords(fortMin, fortMax, x, y))
continue;
RegionTile tile = tiles[x, y];
if (tile == null)
continue;
Vector2 biome = new Vector2(tile.rainfall, 100 - tile.drainage) / 100;
Vector3 vert1 = new Vector3(x * 48 * GameMap.tileWidth, tile.elevation * GameMap.tileHeight, -y * 48 * GameMap.tileWidth);
Sides riverSides = 0;
if (tile.rivers != null)
{
if (tile.rivers.north.min_pos >= 0)
riverSides |= Sides.North;
if (tile.rivers.east.min_pos >= 0)
riverSides |= Sides.East;
if (tile.rivers.south.min_pos >= 0)
riverSides |= Sides.South;
if (tile.rivers.west.min_pos >= 0)
riverSides |= Sides.West;
}
int north = 0;
if (y > 0 && !IsInCoords(fortMin, fortMax, x, y - 1))
north = tiles[x, y - 1].elevation;
int south = 0;
if (y < h - 1 && !IsInCoords(fortMin, fortMax, x, y + 1))
south = tiles[x, y + 1].elevation;
int east = 0;
if (x < w - 1 && !IsInCoords(fortMin, fortMax, x + 1, y))
east = tiles[x + 1, y].elevation;
int west = 0;
if (x > 0 && !IsInCoords(fortMin, fortMax, x - 1, y))
west = tiles[x - 1, y].elevation;
if (riverSides == 0)
AddFlatTile(vert1, biome, north * GameMap.tileHeight, east * GameMap.tileHeight, south * GameMap.tileHeight, west * GameMap.tileHeight, tile.water_elevation);
else
{
AddRiverTile(riverSides, tile.rivers, vert1, biome, north * GameMap.tileHeight, east * GameMap.tileHeight, south * GameMap.tileHeight, west * GameMap.tileHeight);
}
if (vertices.Count >= (65535 - 20))
break;
}
if (vertices.Count >= (65535 - 20))
break;
}
terrainMesh = new Mesh();
terrainMesh.vertices = vertices.ToArray();
terrainMesh.colors = colors.ToArray();
terrainMesh.uv = uvCoords.ToArray();
terrainMesh.uv2 = uvCoords2.ToArray();
terrainMesh.triangles = triangles.ToArray();
terrainMesh.RecalculateNormals();
terrainMesh.RecalculateTangents();
meshFilter.mesh = terrainMesh;
if(waterVerts.Count > 0)
{
if (waterChunk == null)
{
waterChunk = Instantiate<MeshFilter>(parentMap.waterPrefab);
waterChunk.transform.parent = transform;
waterChunk.gameObject.name = "Water ";
waterChunk.transform.localPosition = Vector3.zero;
}
if (waterChunk.mesh == null)
waterChunk.mesh = new Mesh();
Mesh waterMesh = waterChunk.mesh;
//.........这里部分代码省略.........
示例7: Start
//.........这里部分代码省略.........
}
else
{
if (atanA - atanB > Mathf.PI)
{
edge = new VoronoiEdge { VVertexA = vB - CellData.Site, VVertexB = vA - CellData.Site };
}
else
{
edge = new VoronoiEdge { VVertexA = vA - CellData.Site, VVertexB = vB - CellData.Site };
}
}
}
else
{
if (atanA > atanB)
{
edge = new VoronoiEdge { VVertexA = vA - CellData.Site, VVertexB = vB - CellData.Site };
}
else
{
if (atanB - atanA > Mathf.PI)
{
edge = new VoronoiEdge { VVertexA = vA - CellData.Site, VVertexB = vB - CellData.Site };
}
else
{
edge = new VoronoiEdge { VVertexA = vB - CellData.Site, VVertexB = vA - CellData.Site };
}
}
}
return edge;
}).ToArray();
var maxDistFromCenter = edges.Max(e => Mathf.Max((float)e.VVertexA.Length, (float)e.VVertexB.Length));
if (edges[0].VVertexA.Length > maxDistFromCenter)
{
maxDistFromCenter = (float)edges[0].VVertexA.Length;
}
maxDistFromCenter *= 2; // To make sure that UV coords will be in [-0.5; 0.5] range
Mesh mesh = new Mesh();
mesh.name = "cellMesh";
var cellCorners = new Vector3[edges.Length * 2 + 1];
var triangles = new int[edges.Length * 3];
var uvs = new Vector2[edges.Length * 2 + 1];
cellCorners[0] = Vector3.zero; // Placing Cell Center at Origin of new GameObjects
//verts [1] = new Vector3 (edges [0].Start.x, edges [0].Start.y, 0f);
var shift = new Vector2(0.5f, 0.5f); // Shifting texture coords origin
uvs[0] = shift;
uvs[1] = new Vector2(((float)edges[0].VVertexA.X + shift.x) / maxDistFromCenter, ((float)edges[0].VVertexA.Y + shift.y) / maxDistFromCenter);
for (int i = 0; i < edges.Length; i++)
{
var edge = edges[i];
cellCorners[2 * i + 1] = new Vector3((float)edges[i].VVertexA.X, (float)edges[i].VVertexA.Y, 0f);
cellCorners[2 * i + 2] = new Vector3((float)edges[i].VVertexB.X, (float)edges[i].VVertexB.Y, 0f);
var uvStart = shift + new Vector2((float)edge.VVertexA.X / maxDistFromCenter, (float)edge.VVertexA.Y / maxDistFromCenter);
var uvEnd = shift + new Vector2((float)edge.VVertexB.X / maxDistFromCenter, (float)edge.VVertexB.Y / maxDistFromCenter);
uvs[2 * i + 1] = new Vector3(uvStart.x, uvStart.y, 0f);
uvs[2 * i + 2] = new Vector3(uvEnd.x, uvEnd.y, 0f);
triangles[3 * i] = 0;
triangles[3 * i + 1] = 2 * i + 1;
triangles[3 * i + 2] = 2 * i + 2;
}
mesh.vertices = cellCorners;
mesh.uv = uvs;
mesh.triangles = triangles;
mesh.RecalculateNormals();
mesh.RecalculateBounds();
mesh.Optimize();
mesh.RecalculateTangents();
meshFilter.sharedMesh = mesh;
var meshRenderer = gameObject.AddComponent<MeshRenderer>();
if (MeshMaterial == null)
{
meshRenderer.material.color = Color.green;
}
else
{
meshRenderer.material = MeshMaterial;
}
var polyCollider = gameObject.AddComponent<EdgeCollider2D>();
polyCollider.points = cellCorners.Skip(1).Select(c => new Vector2(c.x, c.y)).ToArray();
}
示例8: GenerateMesh
//.........这里部分代码省略.........
}
default:
{
min = new Vector3(building.min_x * GameMap.tileWidth, 0, -building.min_y * GameMap.tileWidth);
max = new Vector3((building.max_x + 1) * GameMap.tileWidth, 13 * GameMap.tileHeight / 6.0f, -(building.max_y + 1) * GameMap.tileWidth);
AddBlock(vert1 + min, vert1 + max, biome, Color.magenta, snow);
break;
}
}
}
Random.InitState(new DFCoord2d(x+regionOrigin.x, y+regionOrigin.y).GetHashCode());
if (tile.buildings.Count == 0 && tile.treeMaterials.Count > 0)
{
float treeRadius = 4f * GameMap.tileWidth;
var treeCoords = UniformPoissonDiskSampler.SampleRectangle(new Vector2(vert1.x + treeRadius, vert1.z - 48 * GameMap.tileWidth + treeRadius), new Vector2(vert1.x + 48 * GameMap.tileWidth - treeRadius, vert1.z - treeRadius), (Mathf.Lerp(48.0f, 8.0f, Mathf.Pow(tile.vegetation / 100.0f, 0.5f))) * GameMap.tileWidth);
foreach (var coord in treeCoords)
{
var tree = tile.treeMaterials[Random.Range(0, tile.treeMaterials.Count - 1)];
int plantIndex = tree.mat_index;
if (tree.mat_type != 419
|| DFConnection.Instance.NetPlantRawList == null
|| DFConnection.Instance.NetPlantRawList.plant_raws.Count <= plantIndex)
continue;
foreach (var growth in DFConnection.Instance.NetPlantRawList.plant_raws[plantIndex].growths)
{
int currentTicks = TimeHolder.DisplayedTime.CurrentYearTicks;
if ((growth.timing_start != -1 && growth.timing_start > currentTicks) || (growth.timing_end != -1 && growth.timing_end < currentTicks))
continue;
tree = growth.mat;
break;
}
Color treeColor = Color.green;
fakeTile.material = tree;
if (ContentLoader.Instance.ColorConfiguration.GetValue(fakeTile, MeshLayer.StaticMaterial, out colorDef))
treeColor = colorDef.color;
if (tree.mat_type == 419) // bare tree
AddTree(new Vector3(coord.x, tile.elevation * GameMap.tileHeight, coord.y), GameMap.tileWidth / 2, Random.Range(7.0f, 9.0f) * GameMap.tileHeight, treeColor, biome, snow, Random.Range(0.0f, 360.0f));
else
AddTree(new Vector3(coord.x, tile.elevation * GameMap.tileHeight, coord.y), treeRadius, Random.Range(7.0f, 9.0f) * GameMap.tileHeight, treeColor, biome, snow, Random.Range(0.0f, 360.0f));
}
}
}
if (vertices.Count >= (65535 - 20))
break;
}
if (vertices.Count >= (65535 - 20))
break;
}
terrainMesh = new Mesh();
terrainMesh.vertices = vertices.ToArray();
terrainMesh.colors = colors.ToArray();
terrainMesh.uv = uvCoords.ToArray();
terrainMesh.uv2 = uvCoords2.ToArray();
terrainMesh.uv3 = uvCoords3.ToArray();
terrainMesh.triangles = triangles.ToArray();
terrainMesh.RecalculateNormals();
terrainMesh.RecalculateTangents();
meshFilter.mesh = terrainMesh;
if(waterVerts.Count > 0)
{
if (waterChunk == null)
{
waterChunk = Instantiate(parentMap.regionWaterPrefab);
waterChunk.transform.parent = transform;
waterChunk.gameObject.name = "Water ";
waterChunk.transform.localPosition = Vector3.zero;
}
if (waterChunk.mesh == null)
waterChunk.mesh = new Mesh();
Mesh waterMesh = waterChunk.mesh;
waterMesh.Clear();
waterMesh.vertices = waterVerts.ToArray();
waterMesh.uv = waterUvs.ToArray();
waterMesh.triangles = waterTris.ToArray();
waterMesh.RecalculateNormals();
waterMesh.RecalculateTangents();
waterChunk.mesh = waterMesh;
waterVerts.Clear();
waterUvs.Clear();
waterTris.Clear();
}
}
示例9: FillMesh
public static void FillMesh(Mesh mesh, Vector3[] vs, Vector3[] ns, Vector2[] uv1s, Vector2[] uv2s, Vector2[] uv3s, Vector2[] uv4s, Color32[] colors32, int[] ts, BoneWeight[] bws, Matrix4x4[] bindposes, int[] subMeshOffsets, bool recalcNormals)
{
mesh.vertices = vs;
if (ns != null && ns.Length > 0)
{
mesh.normals = ns;
}
if (uv1s != null && uv1s.Length > 0)
{
mesh.uv = uv1s;
}
if (uv2s != null && uv2s.Length > 0)
{
mesh.uv2 = uv2s;
}
if (uv3s != null && uv2s.Length > 0)
{
mesh.uv3 = uv3s;
}
if (uv4s != null && uv2s.Length > 0)
{
mesh.uv4 = uv4s;
}
if (colors32 != null && colors32.Length > 0)
{
mesh.colors32 = colors32;
}
if (bws != null && bws.Length > 0)
{
mesh.boneWeights = bws;
}
if (bindposes != null && bindposes.Length > 0)
{
mesh.bindposes = bindposes;
}
if (subMeshOffsets.Length == 1)
{
mesh.triangles = ts;
}
else
{
mesh.subMeshCount = subMeshOffsets.Length;
for (int i = 0; i < subMeshOffsets.Length; i++)
{
subMeshOffsets[i] = Mathf.Max(0, subMeshOffsets[i]);
int num = (i + 1 >= subMeshOffsets.Length) ? ts.Length : subMeshOffsets[i + 1];
if (num - subMeshOffsets[i] > 0)
{
int[] array = new int[num - subMeshOffsets[i]];
Array.Copy(ts, subMeshOffsets[i], array, 0, num - subMeshOffsets[i]);
mesh.SetTriangles(array, i);
}
else
{
mesh.SetTriangles(null, i);
}
}
}
if (recalcNormals || mesh.normals == null || mesh.normals.Length <= 0)
{
mesh.RecalculateNormals();
}
mesh.RecalculateTangents();
}