mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Move stretch
This commit is contained in:
parent
c3e056f9b2
commit
b4739ce67f
@ -11,7 +11,7 @@ namespace NewHorizons.Builder.Body.Geometry
|
|||||||
{
|
{
|
||||||
static class CubeSphere
|
static class CubeSphere
|
||||||
{
|
{
|
||||||
public static Mesh Build(int resolution, Texture2D heightMap, float minHeight, float maxHeight, Vector3 stretch)
|
public static Mesh Build(int resolution, Texture2D heightMap, float minHeight, float maxHeight)
|
||||||
{
|
{
|
||||||
// It breaks if resolution is greater than 100 I don't know why
|
// It breaks if resolution is greater than 100 I don't know why
|
||||||
if(resolution > 100)
|
if(resolution > 100)
|
||||||
@ -23,24 +23,7 @@ namespace NewHorizons.Builder.Body.Geometry
|
|||||||
Mesh mesh = new Mesh();
|
Mesh mesh = new Mesh();
|
||||||
mesh.name = "CubeSphere";
|
mesh.name = "CubeSphere";
|
||||||
|
|
||||||
float max = 1;
|
|
||||||
if (stretch.x > stretch.y && stretch.x > stretch.z)
|
|
||||||
max = stretch.x;
|
|
||||||
else if (stretch.y > stretch.x && stretch.y > stretch.z)
|
|
||||||
max = stretch.y;
|
|
||||||
else if (stretch.z > stretch.x && stretch.z > stretch.y)
|
|
||||||
max = stretch.z;
|
|
||||||
else if (stretch.y == stretch.z && stretch.x > stretch.y)
|
|
||||||
max = stretch.x;
|
|
||||||
else if (stretch.x == stretch.z && stretch.y > stretch.x)
|
|
||||||
max = stretch.y;
|
|
||||||
else if (stretch.x == stretch.y && stretch.z > stretch.x)
|
|
||||||
max = stretch.z;
|
|
||||||
minHeight /= max;
|
|
||||||
maxHeight /= max;
|
|
||||||
|
|
||||||
CreateVertices(mesh, resolution, heightMap, minHeight, maxHeight);
|
CreateVertices(mesh, resolution, heightMap, minHeight, maxHeight);
|
||||||
StretchVertices(mesh, stretch);
|
|
||||||
CreateTriangles(mesh, resolution);
|
CreateTriangles(mesh, resolution);
|
||||||
|
|
||||||
mesh.RecalculateNormals();
|
mesh.RecalculateNormals();
|
||||||
@ -50,24 +33,6 @@ namespace NewHorizons.Builder.Body.Geometry
|
|||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void StretchVertices(Mesh mesh, Vector3 scale)
|
|
||||||
{
|
|
||||||
var baseVertices = mesh.vertices;
|
|
||||||
|
|
||||||
var vertices = new Vector3[baseVertices.Length];
|
|
||||||
|
|
||||||
for (var i = 0; i < vertices.Length; i++)
|
|
||||||
{
|
|
||||||
var vertex = baseVertices[i];
|
|
||||||
vertex.x = vertex.x * scale.x;
|
|
||||||
vertex.y = vertex.y * scale.y;
|
|
||||||
vertex.z = vertex.z * scale.z;
|
|
||||||
vertices[i] = vertex;
|
|
||||||
}
|
|
||||||
|
|
||||||
mesh.vertices = vertices;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Thank you Catlikecoding
|
// Thank you Catlikecoding
|
||||||
private static void CreateVertices(Mesh mesh, int resolution, Texture2D heightMap, float minHeight, float maxHeight)
|
private static void CreateVertices(Mesh mesh, int resolution, Texture2D heightMap, float minHeight, float maxHeight)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -37,8 +37,9 @@ namespace NewHorizons.Builder.Body
|
|||||||
cubeSphere.SetActive(false);
|
cubeSphere.SetActive(false);
|
||||||
cubeSphere.transform.parent = sector?.transform ?? planetGO.transform;
|
cubeSphere.transform.parent = sector?.transform ?? planetGO.transform;
|
||||||
cubeSphere.transform.rotation = Quaternion.Euler(90, 0, 0);
|
cubeSphere.transform.rotation = Quaternion.Euler(90, 0, 0);
|
||||||
|
cubeSphere.transform.localScale = module.Stretch;
|
||||||
|
|
||||||
Mesh mesh = CubeSphere.Build(51, heightMap, module.MinHeight, module.MaxHeight, module.Stretch);
|
Mesh mesh = CubeSphere.Build(51, heightMap, module.MinHeight, module.MaxHeight);
|
||||||
|
|
||||||
cubeSphere.AddComponent<MeshFilter>();
|
cubeSphere.AddComponent<MeshFilter>();
|
||||||
cubeSphere.GetComponent<MeshFilter>().mesh = mesh;
|
cubeSphere.GetComponent<MeshFilter>().mesh = mesh;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user