|
|
@@ -1,10 +1,13 @@
|
|
|
using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
|
+using UnityEngine.UIElements;
|
|
|
|
|
|
public class PlaneGenerator : MonoBehaviour
|
|
|
{
|
|
|
public Material material;
|
|
|
|
|
|
+ public float noiseLevel = 0.1f;
|
|
|
+
|
|
|
private const int pqsResolution = 16;
|
|
|
private const int sphereRadius = 10;
|
|
|
|
|
|
@@ -134,74 +137,86 @@ public class PlaneGenerator : MonoBehaviour
|
|
|
mesh.GetComponent<MeshRenderer>().material = material;
|
|
|
}
|
|
|
|
|
|
- private void RotatePlaneZ(Vector3[] vertices)
|
|
|
+ private void RotatePlaneX(Vector3[] vertices)
|
|
|
{
|
|
|
for (int x = 0, vertex = 0; x < pqsResolution + 1; x++)
|
|
|
{
|
|
|
for (int z = 0; z < pqsResolution + 1; z++, vertex++)
|
|
|
{
|
|
|
- vertices[vertex] = new Vector3(-vertices[vertex].x, vertices[vertex].z, vertices[vertex].y);
|
|
|
- vertices[vertex] = Vector3.Normalize(vertices[vertex]) * sphereRadius;
|
|
|
+ vertices[vertex] = new Vector3(vertices[vertex].y, vertices[vertex].x, -vertices[vertex].z);
|
|
|
+ var noise = GetNoise(vertices[vertex].y, vertices[vertex].z);
|
|
|
+ vertices[vertex] = noise * sphereRadius * Vector3.Normalize(vertices[vertex]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void RotatePlaneY(Vector3[] vertices)
|
|
|
+ private void RotatePlaneX1(Vector3[] vertices)
|
|
|
{
|
|
|
for (int x = 0, vertex = 0; x < pqsResolution + 1; x++)
|
|
|
{
|
|
|
for (int z = 0; z < pqsResolution + 1; z++, vertex++)
|
|
|
{
|
|
|
- vertices[vertex] = Vector3.Normalize(vertices[vertex]) * sphereRadius;
|
|
|
+ vertices[vertex] = new Vector3(-vertices[vertex].y, -vertices[vertex].x, -vertices[vertex].z);
|
|
|
+ var noise = GetNoise(-vertices[vertex].y, -vertices[vertex].z);
|
|
|
+ vertices[vertex] = noise * sphereRadius * Vector3.Normalize(vertices[vertex]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void RotatePlaneZ1(Vector3[] vertices)
|
|
|
+ private void RotatePlaneY(Vector3[] vertices)
|
|
|
{
|
|
|
for (int x = 0, vertex = 0; x < pqsResolution + 1; x++)
|
|
|
{
|
|
|
for (int z = 0; z < pqsResolution + 1; z++, vertex++)
|
|
|
{
|
|
|
- vertices[vertex] = new Vector3(-vertices[vertex].x, -vertices[vertex].z, -vertices[vertex].y);
|
|
|
- vertices[vertex] = Vector3.Normalize(vertices[vertex]) * sphereRadius;
|
|
|
+ var noise = GetNoise(vertices[vertex].x, vertices[vertex].z);
|
|
|
+ vertices[vertex] = noise * sphereRadius * Vector3.Normalize(vertices[vertex]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void RotatePlaneX(Vector3[] vertices)
|
|
|
+ private void RotatePlaneY1(Vector3[] vertices)
|
|
|
{
|
|
|
for (int x = 0, vertex = 0; x < pqsResolution + 1; x++)
|
|
|
{
|
|
|
for (int z = 0; z < pqsResolution + 1; z++, vertex++)
|
|
|
{
|
|
|
- vertices[vertex] = new Vector3(vertices[vertex].y, vertices[vertex].x, -vertices[vertex].z);
|
|
|
- vertices[vertex] = Vector3.Normalize(vertices[vertex]) * sphereRadius;
|
|
|
+ vertices[vertex] = new Vector3(-vertices[vertex].x, -vertices[vertex].y, vertices[vertex].z);
|
|
|
+ var noise = GetNoise(-vertices[vertex].x, -vertices[vertex].z);
|
|
|
+ vertices[vertex] = noise * sphereRadius * Vector3.Normalize(vertices[vertex]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void RotatePlaneY1(Vector3[] vertices)
|
|
|
+
|
|
|
+ private void RotatePlaneZ(Vector3[] vertices)
|
|
|
{
|
|
|
for (int x = 0, vertex = 0; x < pqsResolution + 1; x++)
|
|
|
{
|
|
|
for (int z = 0; z < pqsResolution + 1; z++, vertex++)
|
|
|
{
|
|
|
- vertices[vertex] = new Vector3(-vertices[vertex].x, -vertices[vertex].y, vertices[vertex].z);
|
|
|
- vertices[vertex] = Vector3.Normalize(vertices[vertex]) * sphereRadius;
|
|
|
+ vertices[vertex] = new Vector3(-vertices[vertex].x, vertices[vertex].z, vertices[vertex].y);
|
|
|
+ var noise = GetNoise(-vertices[vertex].x, vertices[vertex].y);
|
|
|
+ vertices[vertex] = noise * sphereRadius * Vector3.Normalize(vertices[vertex]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void RotatePlaneX1(Vector3[] vertices)
|
|
|
+ private void RotatePlaneZ1(Vector3[] vertices)
|
|
|
{
|
|
|
for (int x = 0, vertex = 0; x < pqsResolution + 1; x++)
|
|
|
{
|
|
|
for (int z = 0; z < pqsResolution + 1; z++, vertex++)
|
|
|
{
|
|
|
- vertices[vertex] = new Vector3(-vertices[vertex].y, -vertices[vertex].x, -vertices[vertex].z);
|
|
|
- vertices[vertex] = Vector3.Normalize(vertices[vertex]) * sphereRadius;
|
|
|
+ vertices[vertex] = new Vector3(-vertices[vertex].x, -vertices[vertex].z, -vertices[vertex].y);
|
|
|
+ var noise = GetNoise(-vertices[vertex].x, -vertices[vertex].y);
|
|
|
+ vertices[vertex] = noise * sphereRadius * Vector3.Normalize(vertices[vertex]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private float GetNoise(float x, float y)
|
|
|
+ {
|
|
|
+ return 1 + Mathf.PerlinNoise(x, y) * noiseLevel;
|
|
|
+ }
|
|
|
}
|