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 };
        }
    }  

  • 相关阅读:
    windows编程:第一个windows程序
    百度地图API多个点聚合时,标注添加的标签label地图刷新就丢失的问题解决
    在WPF的WebBrowser控件中屏蔽脚本错误的提示
    使用SQL语句逐条更新每条记录
    通过 HDU 2048 来初步理解动态规划
    一个乱码问题
    2、设置配置文件
    1、搭建 maven 环境
    MyBatis 缓存机制
    关于 Mybatis 设置懒加载无效的问题
  • 原文地址:https://www.cnblogs.com/xpvincent/p/3211043.html
Copyright © 2011-2022 走看看