本文整理汇总了C#中Geometry.CreateChunkyTriMesh方法的典型用法代码示例。如果您正苦于以下问题:C# Geometry.CreateChunkyTriMesh方法的具体用法?C# Geometry.CreateChunkyTriMesh怎么用?C# Geometry.CreateChunkyTriMesh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Geometry
的用法示例。
在下文中一共展示了Geometry.CreateChunkyTriMesh方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildGeometry
/// <summary>
/// This takes the current geometry and builds the data to go into Recast
/// It needs to be updated to take into account scale, position, and rotation
/// It needs to be updated to look for specific tags
/// </summary>
/// <param name="geom"></param>
private static void BuildGeometry(NavMeshSettings settings, Config config, Geometry geom)
{
for (int i = 0; i < UnityEditorInternal.InternalEditorUtility.tags.Length; i++)
{
if ((settings.Tags & (1 << i)) != 0)
{
foreach (var gameObject in GameObject.FindGameObjectsWithTag(UnityEditorInternal.InternalEditorUtility.tags[i]))
{
foreach (var terrainObj in gameObject.GetComponentsInChildren<Terrain>())
{
var terrain = terrainObj.terrainData;
var w = terrain.heightmapWidth;
var h = terrain.heightmapHeight;
var meshScale = terrain.size;
var tRes = 1;
meshScale = new Vector3(meshScale.x / (w - 1) * tRes, meshScale.y, meshScale.z / (h - 1) * tRes);
var tData = terrain.GetHeights(0, 0, w, h);
w = (w - 1) / tRes + 1;
h = (h - 1) / tRes + 1;
var tVertices = new Vector3[w * h];
var tPolys = new int[(w - 1) * (h - 1) * 6];
// Build vertices and UVs
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
tVertices[y * w + x] = Vector3.Scale(meshScale, new Vector3(x, tData[y * tRes, x * tRes], y)) + terrainObj.transform.position;
}
}
var index = 0;
// Build triangle indices: 3 indices into vertex array for each triangle
for (int y = 0; y < h - 1; y++)
{
for (int x = 0; x < w - 1; x++)
{
// For each grid cell output two triangles
tPolys[index++] = (y * w) + x;
tPolys[index++] = ((y + 1) * w) + x;
tPolys[index++] = (y * w) + x + 1;
tPolys[index++] = ((y + 1) * w) + x;
tPolys[index++] = ((y + 1) * w) + x + 1;
tPolys[index++] = (y * w) + x + 1;
}
}
int subTotalVerts = geom.NumVertexes;
foreach (var tVertex in tVertices)
{
geom.Vertexes.Add(new RecastVertex(tVertex.x, tVertex.y, tVertex.z));
geom.NumVertexes++;
}
for (int j = 0; j < tPolys.Length; j += 3)
{
geom.Triangles.Add(tPolys[j] + subTotalVerts);
geom.Triangles.Add(tPolys[j + 1] + subTotalVerts);
geom.Triangles.Add(tPolys[j + 2] + subTotalVerts);
geom.NumTriangles++;
}
}
foreach (var componentsInChild in gameObject.GetComponentsInChildren<MeshFilter>())
{
int subTotalVerts = geom.NumVertexes;
foreach (Vector3 vector3 in componentsInChild.sharedMesh.vertices)
{
Vector3 vec = gameObject.transform.TransformPoint(vector3);
geom.Vertexes.Add(new RecastVertex(vec.x, vec.y, vec.z));
geom.NumVertexes++;
}
for (int j = 0; j < componentsInChild.sharedMesh.triangles.Length; j += 3)
{
geom.Triangles.Add(componentsInChild.sharedMesh.triangles[j] + subTotalVerts);
geom.Triangles.Add(componentsInChild.sharedMesh.triangles[j + 1] + subTotalVerts);
geom.Triangles.Add(componentsInChild.sharedMesh.triangles[j + 2] + subTotalVerts);
geom.NumTriangles++;
}
}
foreach (var offMeshConnector in gameObject.GetComponentsInChildren<OffMeshConnector>())
{
RecastVertex start = new RecastVertex(offMeshConnector.StartPosition.x, offMeshConnector.StartPosition.y, offMeshConnector.StartPosition.z);
RecastVertex end = new RecastVertex(offMeshConnector.EndPosition.x, offMeshConnector.EndPosition.y, offMeshConnector.EndPosition.z);
geom.AddOffMeshConnection(start, end, offMeshConnector.Radius, offMeshConnector.Bidirectional, 5, 8);
}
}
}
}
if (geom.NumVertexes != 0)
{
geom.CalculateBounds();
config.CalculateGridSize(geom);
geom.CreateChunkyTriMesh();
//.........这里部分代码省略.........