绘制三角形
Posted DaLiangChen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了绘制三角形相关的知识,希望对你有一定的参考价值。
网格绘制重要属性
- vertices(Vector3[]):存储绘制网格的顶点位置信息。
- triangles(int[]):通过设置对vertices的索引来定义三角形数组。
- uv(Vector2[]):贴图坐标系,记录了贴图在模型上的对应坐标点。
绘制三角形
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Mx.MeshDraw
public class BaseMeshDraw : MonoBehaviour
protected MeshFilter meshFilter;
protected MeshRenderer meshRenderer;
protected Mesh mesh;
protected int[] tris;
protected Vector2[] uvs;
protected Vector3[] normals;
private void Awake()
meshFilter = GetComponent<MeshFilter>();
if (meshFilter == null) meshFilter = gameObject.AddComponent<MeshFilter>();
meshRenderer = GetComponent<MeshRenderer>();
if (meshRenderer == null) meshRenderer = gameObject.AddComponent<MeshRenderer>();
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mx.MeshDraw;
namespace Mx.Example
/// <summary>绘制三角形</summary>
public class Example01 : BaseMeshDraw
private void Start()
drawTriangle();
/// <summary>绘制三角形</summary>
private void drawTriangle()
mesh = new Mesh();
Vector3[] verticesArr = new Vector3[3];
verticesArr[0] = new Vector3(0, 0, 0);
verticesArr[1] = new Vector3(0, 1, 0);
verticesArr[2] = new Vector3(1, 0, 0);
mesh.vertices = verticesArr;
tris = new int[3];
tris[0] = 0;
tris[1] = 1;
tris[2] = 2;
mesh.triangles = tris;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
mesh.RecalculateTangents();
meshFilter.mesh = mesh;
以上是关于绘制三角形的主要内容,如果未能解决你的问题,请参考以下文章