Hi
For a Mesh that is created manually using this method:
public static Mesh CreateMesh(List<Vector3> vectors, List<int> indexes)
{
return new()
{
vertices = vectors.ToArray(),
triangles = indexes.ToArray()
};
}
public static bool ReadOFF(string offFilePath, out List<Vector3> vertices, out List<int> triangles)
{
// 1. Чтение файла OFF
vertices = new();
triangles = new();
if (!File.Exists(offFilePath))
{
return false;
}
var strs = File.ReadAllLines(offFilePath);
// Чтение количества вершин и треугольников
string[] counts = strs[1].Split();
int vertexCount = int.Parse(counts[0]);
int faceCount = int.Parse(counts[1]);
// Чтение координат вершин
for (int i = 3; i < 3 + vertexCount; i++)
{
string[] vertexData = strs[i].Split(' ');
float x = float.Parse(vertexData[0]);
float y = float.Parse(vertexData[1]);
float z = float.Parse(vertexData[2]);
vertices.Add(new Vector3(x, y, z));
}
// Чтение треугольников (граней)
for (int i = 3 + vertexCount; i < 3 + vertexCount + faceCount; i++)
{
string[] faceData = strs[i].Split(" ")[1].Split(' ');
if (faceData.Length == 3) // Треугольная грань
{
triangles.Add(int.Parse(faceData[0]));
triangles.Add(int.Parse(faceData[1]));
triangles.Add(int.Parse(faceData[2]));
}
}
return vertices.Count >= 3;
}
It is cropped, as if lighting is displayed on one side.
How can I fix this? Thanks!
Other code:
private UIDocument doc;
void OnEnable()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
obj = GameObject.Instantiate(prefab);
meshFilter = obj.GetComponent<MeshFilter>();
// Получаем корень UI
doc = GetComponent<UIDocument>();
var root = doc.rootVisualElement;
// Находим кнопку по имени
btnLoad = root.Q<Button>(nameof(btnLoad));
btnLoad.clicked += OnButtonClicked;
}
private GameObject obj;
private MeshFilter meshFilter;
[SerializeField] private GameObject prefab;
private Button btnLoad;
void OnButtonClicked()
{
ReadOFF(@"C:\Users\Public\ankofl\Data\Volumes\69-Room.off", out var vectors, out var indexes);
meshFilter.mesh = CreateMesh(vectors, indexes);
}