Unity - 绘制正五边形网格
本文简述了Unity中绘制正五边形网格的基本方法:计算顶点信息、设置三角形覆盖信息、创建配置mesh
绘制方法
- 基本思路:计算出五边形顶点坐标信息作为数组,设置三角形包围方式,再创建新的mesh配置vertices、triangle参数,最终赋值到当前mesh上
- 项目实现:
- 创建DrawPentagon.cs,挂在于带有mesh的物体上(本例为Quad
- 编写代码如下:
- 查看所创建的mesh信息
public class DrawPentagon : MonoBehaviour
{
private Vector3[] newVertices; //五边形顶点数组
private int[] newTriangles; //五边形网格内的三角形网格信息
void Start()
{
//1. 创建五边形顶点坐标数组:顶点编号0~4
newVertices = new Vector3[5] {
Vector3.zero,
new Vector3(Mathf.Cos(Mathf.Deg2Rad * 36), 0, Mathf.Sin(Mathf.Deg2Rad * 36)),
new Vector3(2 * Mathf.Cos(Mathf.Deg2Rad * 36), 0, 0),
new Vector3(Mathf.Cos(Mathf.Deg2Rad * 72) + 1, 0, -Mathf.Sin(Mathf.Deg2Rad * 72)),
new Vector3(Mathf.Cos(Mathf.Deg2Rad * 72), 0, -Mathf.Sin(Mathf.Deg2Rad * 72))
/*
newVertices[0] = (0.0, 0.0, 0.0)
newVertices[1] = (0.8, 0.0, 0.6)
newVertices[2] = (1.6, 0.0, 0.0)
newVertices[3] = (1.3, 0.0, -1.0)
newVertices[4] = (0.3, 0.0, -1.0)
*/
};
//2. 设根据已有的顶点编号设置三角形包围顺序,例如0,1,2顶点围成一个三角形;0,2,3顶点围成另一三角形
newTriangles = new int[9] { 0, 1, 2, 0, 2, 3, 0, 3, 4 };
//错误情况:三角形数量不足
//newTriangles = new int[6] { 0, 1, 2, 0, 2, 3 };
//错误情况:三角形覆盖面不全
//newTriangles = new int[9] { 0, 1, 2, 1, 2, 3, 0, 3, 4 };
//3. 创建mesh信息:顶点数据、三角形
Mesh mesh = new Mesh
{
name = "Pentagon",
vertices = newVertices,
triangles = newTriangles
};
GetComponent<MeshFilter>().mesh = mesh;
}
}
示意图及错误示例:
参考
Unity - 绘制正五边形网格的更多相关文章
- unity 3d 之合并网格和贴图(combine mesh and texture)
https://www.cnblogs.com/eangulee/p/3877824.html unity 3d 之合并网格和贴图(combine mesh and texture) 本人是个小白 ...
- #使用Python的turtle绘制正六边形、叠边形
1.#Python的turtle绘制正六边形 代码: len=100 #表示边长像素 import turtle as t #正六边形内角都是120度,外角60度 for i in range(6): ...
- Unity 绘制多边形
最近工程需要用到一个多边形用来查看角色属性,于是就研究了下Mesh用网格做了一个.遗憾的的 UGUI 渲染不了 3D 物体,然后又用了一段时间研究了下UGUI的网格绘制. 不过终于还是完成了,虽然有些 ...
- unity 绘制三角形
哎 该学的还是要学 参考:http://www.narkii.com/club/thread-369573-1.html unity 顶点绘制三角形 脚本绘制; 其实filter和render就是进行 ...
- CSS绘制正五角星原理(数学模型)
尽管网上有很多CSS绘制五角星的代码案例,但是对于初学者来说可以拿来移植使用,但是在不明白其原理的情况下,进行修改移植就比较困难了.譬如想要将五角星尺寸进行缩小或者放大等设计,就需要对原代码相关数据进 ...
- unity绘制线和绘制面
绘制线条代码,其实就是指定至少两个点,然后赋予贴图即可,不废话,上代码: using UnityEngine; using System.Collections; public class LineT ...
- unity中动态生成网格
以下是绘制正方形面片的一个例子,方便之后查阅: 效果如图所示: 红轴为x方向,蓝轴为z方向. 代码如下: using System.Collections; using System.Collecti ...
- 使用ICEM绘制非结构网格时,如何提高网格质量?【转载】
作者:杨淑娟 链接:https://www.zhihu.com/question/20851390/answer/26152732 来源:知乎 著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...
- Unity绘制GUI连连看(尚未完善效果和重置)
OneImage.cs public class OneImage : MonoBehaviour { public int row, col; public Rect rect; public Te ...
随机推荐
- [linux][c/c++]代码片段02
gcc `pkg-config --cflags gtk+-3.0` -o example-1 example-1.c `pkg-config --libs gtk+-3.0` #include &l ...
- JS简单获取当前日期时间的方法(yyyy-MM-dd hh:mm:ss)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...
- 微信小程序:用 Promise 解决方案代替回调地狱。 修复 this._invokeMethod is not a function 的问题
/** * 将回调地狱转换为 Promise 形式 * https://blog.csdn.net/SEAYEHIN/article/details/88663740 * raw: wx.downlo ...
- jquery ajax Uncaught TypeError :Illegal invocation 报错
使用jquery ajax异步提交的时候报Uncaught TypeError :Illegal invocation错误,报错如图: 基本上,导致这个错误的原因一般有以下两点: 1.请求类型有误,如 ...
- Consider defining a bean of type 'com.*.*.mapper.*.*Mapper' in your configuration.
@Mapper 不能加载的问题 Consider defining a bean of type 'com.*.*.mapper.*.*Mapper' in your configuration. 添 ...
- mysql新增用户
新开了个项目,数据库也想新搞个用户,先登陆mysql,看看原来都有哪些: root@wlf:/# mysql -uroot -p Enter password: Welcome to the MySQ ...
- json 格式化处理工具
json 格式化处理工具 用于JSON的快速命令行处理工具,简单无依赖. 我这边列举一些最常用的: 调试 http 请求时打印格式化后的数据 格式化本地或或流中的数据 获取 json 的键值或进行执行 ...
- 两分钟观看 nodejs、 iojs、 npmjs 之间的狗血剧情
开门大吉,欢迎光临.这是 乐玩nodejs npm工具库 微信公众号的第一篇文章,那就先来说说 nodejs/npm 的小秘密,话不多说,赶快开始: 通过一个时间线简要描述下 2008 年 V8 引擎 ...
- 拼接Sql语句小心得
在往数据库插入数据时,需要根据数据和数据库中的列信息进行拼接,在本篇文章中,输出小心得.使用语言为 python. 拼接原始列信息 比如待插入数据库列信息为 deptNo,dName, Locate, ...
- djang-celery使用带密码的redis
前言: 网上很多django-celery使用redis(使用不带密码的redis)的用法都是千篇一律,那带密码的redis该怎么使用了呢,没有看到一篇有帮助的,在官网搜了下,发现以下用法,请看下面 ...