mesh网格导出obj文件
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
public class GreatMesh : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
//创建环形网格
VertexHelper vh = new VertexHelper();
float ang = 2 * Mathf.PI / 30;
for (int i = 0; i < 30; i++)
{
float x = Mathf.Sin(ang * i) * 0.3f;
float z = Mathf.Cos(ang * i) * 0.3f - 0.1f;
vh.AddVert(new Vector3(x, 0, z), Color.white, Vector2.zero);
float x0 = Mathf.Sin(ang * i) * 0.5f;
float z0 = Mathf.Cos(ang * i) * 0.5f - 0.1f;
vh.AddVert(new Vector3(x0, 0, z0), Color.white, Vector2.zero);
if (i < 29)
{
vh.AddTriangle(i * 2, i * 2 + 1, (i + 1) * 2 + 1);
vh.AddTriangle(i * 2, (i + 1) * 2 + 1, (i + 1) * 2);
}
else
{
vh.AddTriangle(i * 2, i * 2 + 1, 1);
vh.AddTriangle(i * 2, 1, 0);
}
}
Mesh mesh = new Mesh();
vh.FillMesh(mesh);
gameObject.AddComponent<MeshFilter>().mesh = mesh;
Material material = new Material(Shader.Find("Standard"));
gameObject.AddComponent<MeshRenderer