本文整理汇总了C#中MeshData.CreateMesh方法的典型用法代码示例。如果您正苦于以下问题:C# MeshData.CreateMesh方法的具体用法?C# MeshData.CreateMesh怎么用?C# MeshData.CreateMesh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshData
的用法示例。
在下文中一共展示了MeshData.CreateMesh方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawMesh
public void DrawMesh(MeshData meshData, Texture2D texture) {
currentTexture = texture;
//print (currentTexture.width + " " + currentTexture.height);
meshFilter.sharedMesh = meshData.CreateMesh ();
meshRenderer.sharedMaterial.mainTexture = texture;
GetComponent<MeshCollider>().sharedMesh = meshFilter.sharedMesh;
}
示例2: Generate
public void Generate(TerrainConfig config) {
config.MapHeight += 1;
config.MapWidth += 1;
Config = config;
float[,] noiseMap = Noise.GenerateNoiseMap(
config.MapWidth,
config.MapHeight,
config.Seed,
config.NoiseScale,
config.Octaves,
config.Persistance,
config.Lacunarity,
config.Offset
);
Color[] colorMap = new Color[config.MapWidth * config.MapHeight];
for (int y = 0; y < config.MapHeight; y++) {
for (int x = 0; x < config.MapWidth; x++) {
float currentHeight = noiseMap[x, y];
for (int i = 0; i < TerrainTypes.Length; i++) {
if (currentHeight <= TerrainTypes[i].Height) {
colorMap[y * config.MapWidth + x] = TerrainTypes[i].Color;
//print (y * config.MapWidth + x);
break;
}
}
}
}
int width = noiseMap.GetLength(0);
int height = noiseMap.GetLength(1);
float topLeftX = (width - 1) / -2f;
float topLeftZ = (height - 1) / 2f;
MeshData meshData = new MeshData(width, height);
int vertexIndex = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
meshData.Vertices[vertexIndex] = new Vector3((topLeftX + x) / 4, 0, (topLeftZ - y) / 4);
meshData.Uvs[vertexIndex] = new Vector2((x / (float) width), (y / (float) height));
if (x < width - 1 && y < height - 1) {
meshData.AddTriangle(vertexIndex, vertexIndex + width + 1, vertexIndex + width);
meshData.AddTriangle(vertexIndex + width + 1, vertexIndex, vertexIndex + 1);
}
vertexIndex++;
}
}
Texture = new Texture2D(width, height);
Texture.filterMode = FilterMode.Point;
Texture.wrapMode = TextureWrapMode.Clamp;
Texture.SetPixels(colorMap);
Texture.Apply();
Mesh finalMesh = meshData.CreateMesh();
GetComponent<MeshFilter>().sharedMesh = finalMesh;
GetComponent<MeshRenderer>().material.mainTexture = Texture;
GetComponent<MeshCollider>().sharedMesh = finalMesh;
}
示例3: OnMeshDataReceived
void OnMeshDataReceived(MeshData meshData) {
mesh = meshData.CreateMesh ();
hasMesh = true;
updateCallback ();
}
示例4: DrawMesh
public void DrawMesh(MeshData meshData, Texture2D texture)
{
meshFilter.sharedMesh = meshData.CreateMesh();
//meshRenderer.sharedMaterial.mainTexture = texture;
}
示例5: OnMeshDataReceived
void OnMeshDataReceived(MeshData meshData) {
meshFilter.mesh = meshData.CreateMesh ();
}
示例6: DrawMesh
public void DrawMesh(MeshData meshData)
{
meshFilter.sharedMesh = meshData.CreateMesh();
meshFilter.transform.localScale = Vector3.one * FindObjectOfType<MapGenerator>().terrainData.uniformScale;
}
示例7: OnMeshDataReceived
void OnMeshDataReceived(MeshData meshData)
{
mesh = meshData.CreateMesh();
hasMesh = true;
}