Я собираюсь разработать очень специфичное жидкое бульканье / кипячение для моей игры в Unity.Мой план состоял в том, чтобы сделать круглую плоскость в блендере и каким-то образом выровнять индексы с процедурным изображением и использовать смещение для анимации вершин, чтобы вызвать пузырь.Проблема в том, что, хотя в Blender есть несколько опций для изменения индексов, ни один из них не находится близко к «снизу вверх, слева направо».Поэтому моя идея заключалась в том, чтобы написать сценарий в Unity, который реорганизовал бы индексы, но до сих пор мои теории только приводили меня к сходству с исходной сеткой.Поэтому я просто проводил обмен стеками, чтобы узнать, знает ли какой-нибудь выпускник CS какую-то формулу, о которой я не узнаю, найти следующую вершину в логической серии точек, чтобы сделать единообразным индекс сетки.Вот работы, которые у меня есть, и их результаты.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class gurgleScript : MonoBehaviour {
public List<Vector3> vertices; Vector3 vertex;
void OnEnable () {
vertices = new List<Vector3>();
Vector3[] tempVerts = GetComponent<MeshFilter>().sharedMesh.vertices;
int square = Mathf.RoundToInt(Mathf.Sqrt(tempVerts.Length));
for (int VN = 0; VN < tempVerts.Length; VN++)
{
for (int VC = 0; VC < tempVerts.Length; VC++)
{
if (VC == 0) vertex = tempVerts[VC];
if(VN>0)
{
if (VN % square != 0 & !vertices.Contains(tempVerts[VC]))
if (DistanceCheck(vertex, tempVerts[VC], vertices[VN - 1], "x"))
vertex = tempVerts[VC];
if (VN % square == 0 & !vertices.Contains(tempVerts[VC]))
if (DistanceCheck(vertex, tempVerts[VC], vertices[VN - square], "y"))
vertex = tethmpVerts[VC];
}
if (VN == 0)
{
float[] vectSum = new float[tempVerts.Length];
for (int s = 0; s < tempVerts.Length; s++) vectSum[s] = tempVerts[s].x + tempVerts[s].y;
if (vectSum[VN] < tempVerts[VC].x + tempVerts[VC].y) vertex = tempVerts[VC];
}
}
vertices.Add(vertex);
}
GetComponent<MeshFilter>().sharedMesh.RecalculateBounds();
GetComponent<MeshFilter>().sharedMesh.RecalculateNormals();
}
void Update(){ GetComponent<MeshFilter>().sharedMesh.vertices = vertices.ToArray(); }
bool DistanceCheck(Vector3 final, Vector3 check, Vector3 last, string orient)
{
bool closer = new bool(); closer = false; bool close = new bool(); close = false;
if (orient == "y")
{
if(check.y > 0 & check.x < 0 && last.y < check.y) closer = true;
if(check.y > 0 & check.x > 0 && last.y > check.y) closer = true;
if (check.y < 0 & check.x < 0 && last.y < check.y) closer = true;
if (check.y < 0 & check.x > 0 && last.y < check.y) closer = true;
}
if (orient == "x")
{
if (check.x > 0 & check.y < 0 && last.y > check.y) closer = true;
if (check.x > 0 & check.y > 0 && last.y < check.y) closer = true;
if (check.x < 0 & check.y < 0 && last.y > check.y) closer = true;
if (check.x < 0 & check.y > 0 && last.y > check.y) closer = true;
}
if (closer)
if (Vector3.Distance(last, check) < Vector3.Distance(final, check))
close = true;
return close;
}
}
