unity 在Mesh中的顶点或者mesh 三角形的中点生成物体
来源:互联网 发布:linux系统工程师面试题 编辑:程序博客网 时间:2024/04/27 09:45
using UnityEngine;using System.Collections;using System.Collections.Generic;public class MeshPoint : MonoBehaviour { public GameObject cubePrefab; private Vector3[] verticals; private List<Vector3> points; public Transform cubeperent; private float randomOffect; private Vector3 pos; private Vector3 rotation; private float randomRotation; private int[] triangleArr; string triangle; Mesh mesh;// Use this for initializationvoid Start () { mesh = GetComponent<MeshFilter>().mesh; cubeperent = GameObject.Find("Cubes").transform; //*****************************************************************三角形两个顶点的中点 triangleArr = mesh.triangles; points = new List<Vector3>(mesh.vertices); //三角形的个数 int size = mesh.triangles.Length; for(int i=0;i<200;i++ ) { //一个三角形、三个点(第几个三角形) int tt = Random.Range(0,size/3); int index1= triangleArr[3 * tt]; int index2= triangleArr[3 * tt+1]; Debug.Log(index1+" "+index2); //那个顶点 Vector3 point1 = points[index1]; Vector3 point2 = points[index2]; Debug.Log(point1 + " " + point2); //中点 Vector3 point3 = (point1 +point2) / 2.0f; Instantiate(cubePrefab, point3, Quaternion.Euler(rotation), cubeperent); } cubeperent.transform.position = new Vector3(0, 119.4179f, 0); cubeperent.transform.rotation = Quaternion.Euler(new Vector3(-90.26f, 0, 0)); //---------------------------------------------------------------------------------------------------- //Debug.Log(GetComponent<MeshFilter>().mesh.vertices.Length); //******************************************************************************************根据顶点 //verticals = GetComponent<MeshFilter>().mesh.vertices; //points = new List<Vector3>(verticals); //for (int j = 0; j < 400; j++) //{ // int a = Random.Range(0, points.Count); // randomOffect = Random.Range(-0.4f,0.4f); // randomRotation = Random.Range(0,360); // pos = new Vector3(points[a].x + randomOffect, points[a].y+randomOffect, points[a].z + randomOffect); // rotation = new Vector3(transform.rotation.x + randomRotation, transform.rotation.y + randomRotation, transform.rotation.z + randomRotation); // Instantiate(cubePrefab, pos, Quaternion.Euler(rotation), cubeperent); // points.RemoveAt(a); //} //******************************************************************************************************* cubeperent.transform.position = new Vector3(0, 119.4179f, 0); cubeperent.transform.rotation = Quaternion.Euler(new Vector3(-90.26f, 0, 0));}// Update is called once per framevoid Update () {}}
0 0
- unity 在Mesh中的顶点或者mesh 三角形的中点生成物体
- Mesh 顶点的Normal
- Unity Mesh生成图形
- unity 增加顶点数,熟悉mesh的构成
- Unity Mesh Collider 顶点太多报错
- Unity Mesh
- Unity Mesh
- 用unity的mesh画圆
- Unity里的Mesh属性
- Unity里的Mesh属性
- unity mesh的自定义创建
- Unity Mesh(三) Mesh画球
- 使用Unity Mesh生成正N边形
- Unity中创建自己的mesh以及动态修改mesh
- Unity Mesh(四) Mesh 平面图形的贴图
- Unity中创建自己的mesh以及动态修改mesh
- mesh生成时候的注意事项
- Unity 中的 Mesh 及绘制圆环
- lintcode,最大子数组
- Selenium JSON通信协议
- Android ButterKnife依赖注入框架的引入和使用
- Elasticsearch 5.0-基本操作
- windows与linux下的路径区别
- unity 在Mesh中的顶点或者mesh 三角形的中点生成物体
- shell循环sleep while例子 条件判断
- 开启Instant Run后,打包适配问题
- 联合体
- Python金融大数据分析-蒙特卡洛仿真
- 欢迎使用CSDN-markdown编辑器
- 符号连接和硬连接
- 数据结构 链栈的基本操作
- 第十六周项目1-(7)验证算法归并排序