问题描述
如何为我的Perlin噪声添加八度?我尝试了一些方法,但前一次却行不通。在for循环中添加多个噪声或更改噪声变量,例如for(int o = 0; o
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MeshGenerator : MonoBehaviour
{
Mesh mesh;
Vector3[] vertices;
int[] triangles;
Vector2[] uvs;
public int xSize;
public int zSize;
public int seed;
[Header("Noise")]
float height;
public float multiplier = .3f;
public float scale = 1;
public int octaves = 8;
// Start is called before the first frame update
void Start()
{
mesh = new Mesh();
GetComponent<MeshFilter>().mesh = mesh;
CreateMesh();
UpdateMesh();
}
void CreateMesh()
{
vertices = new Vector3[(xSize + 1) * (zSize + 1)];
for (int i = 0,z = 0; z <= zSize; z++)
{
for (int x = 0; x <= xSize; x++)
{
height = Mathf.PerlinNoise(x * multiplier,z * multiplier) * 2;
vertices[i] = new Vector3(x,height,z);
i++;
}
}
triangles = new int[xSize * zSize * 6];
int vert = 0;
int tris = 0;
for (int z = 0; z < zSize; z++)
{
for (int x = 0; x < xSize; x++)
{
triangles[tris + 0] = vert + 0;
triangles[tris + 1] = vert + xSize + 1;
triangles[tris + 2] = vert + 1;
triangles[tris + 3] = vert + 1;
triangles[tris + 4] = vert + xSize + 1;
triangles[tris + 5] = vert + xSize + 2;
vert++;
tris += 6;
}
vert++;
}
uvs = new Vector2[vertices.Length];
for (int i = 0,z = 0; z <= zSize; z++)
{
for (int x = 0; x <= xSize; x++,i++)
{
uvs[i] = new Vector2((float)x / xSize,(float)z / zSize);
}
}
}
void UpdateMesh()
{
mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.uv = uvs;
mesh.RecalculateNormals();
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)