zoukankan      html  css  js  c++  java
  • Mesh系列文章

    就是在做项目的过程中,有用到三角形的,今天就写一下如何自定义三角形?

            先截个图,让大家有个感性认识!    

            //引用

            using UnityEngine;
            using System.Collections;
            public class Draw : MonoBehaviour
           {

                  //三个物体的变换
                  public Transform a1;
                  public Transform a2;
                  public Transform a3;
                  void Awake()
                 {

                      //添加Mesh Filter(模型网格)和Mesh Renderer(模型渲染)组件
                      gameObject.AddComponent<MeshFilter>();
                      gameObject.AddComponent<MeshRenderer>();

                      //对模型的材质赋值个颜色
                      gameObject.renderer.material.color=Color.green;

                      //获取模型网格
                      Mesh mesh = GetComponent<MeshFilter>().mesh;

                      //清楚模型的顶点和三角形索引
                      mesh.Clear();

                      //变换三个物体的坐标到代码所挂物体上的局部坐标!
                      Vector3 v1 = gameObject.transform.InverseTransformPoint(a1.position);
                      Vector3 v2 = gameObject.transform.InverseTransformPoint(a2.position);
                      Vector3 v3 = gameObject.transform.InverseTransformPoint(a3.position);

                      //然后赋值顶点
                      mesh.vertices = new Vector3[] { v1, v2, v3 };

                     //赋值三角形的索引

                      mesh.triangles = new int[] { 0, 1, 2 };
        }
    }  

  • 相关阅读:
    【基础算法】- 全排列
    【基础算法】- 2分查找
    区块链培训
    Static Binding (Early Binding) vs Dynamic Binding (Late Binding)
    test
    No data is deployed on the contract address!
    "throw" is deprecated in favour of "revert()", "require()" and "assert()".
    Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning.
    京都行
    Failed to write genesis block: database already contains an incompatible
  • 原文地址:https://www.cnblogs.com/xpvincent/p/3211043.html
Copyright © 2011-2022 走看看