Unity没有建模工具,大多是在其他3D软件中建模后导入Unity资源中使用。但通过脚本可以修改网格的顶点属性,所以理论上可以实现在Unity中从无到有地建模。 文章出自
【狗刨学习网】
建模,就是建网格;建网格,就是画些三角形;画个三角形呢,也就是定位三个点。
不过首先了解下Unity中网格的特性。Unity中的对象就是GameObject了,每个GameObject都可以有一个MeshFilter组件(也可以没有),该组件又有mesh属性(这个一定有),而该属性又有个vertives,也就是一个Vector3数组,储存着顶点信息。
下面就是写个脚本来看看mesh里的东东都是些什么了。
代码功能即:点击Tab键轮询场景中所有GameObject,以获取其MeshFilter.mesh,并在GUI中显示mesh的主要属性内容顶点坐标,法线,三角形的绘制序列等等。(代码写的很仓促,只为了显示内容。)
代码直接拖到mainCamera中即可。可在场景中建几个Cube、Plane什么的看看。
下图即是一个立方体的mesh内容:
从中可以看出Vertices是所有点的坐标,坐标是以模型的中心点为原点的
triangles: 包含顶点数组索引的三角形列表。三角形数组的大小是3的倍数。
normals:是这个点的法线,可以理解为从这个方向看过来才能看到这个点,其它方向看过来看不到这个点,三个点的法线相同才能构成一个三角面。
uv: 基础纹理坐标, 左下角为(0,0) 左上角为(0,1) 右上角为(1,1) 右下角为(1,0)设置相应的四个点就可以贴出图片里的内容
建模,就是建网格;建网格,就是画些三角形;画个三角形呢,也就是定位三个点。
不过首先了解下Unity中网格的特性。Unity中的对象就是GameObject了,每个GameObject都可以有一个MeshFilter组件(也可以没有),该组件又有mesh属性(这个一定有),而该属性又有个vertives,也就是一个Vector3数组,储存着顶点信息。
下面就是写个脚本来看看mesh里的东东都是些什么了。
代码功能即:点击Tab键轮询场景中所有GameObject,以获取其MeshFilter.mesh,并在GUI中显示mesh的主要属性内容顶点坐标,法线,三角形的绘制序列等等。(代码写的很仓促,只为了显示内容。)
代码直接拖到mainCamera中即可。可在场景中建几个Cube、Plane什么的看看。
下图即是一个立方体的mesh内容:
从中可以看出Vertices是所有点的坐标,坐标是以模型的中心点为原点的
triangles: 包含顶点数组索引的三角形列表。三角形数组的大小是3的倍数。
normals:是这个点的法线,可以理解为从这个方向看过来才能看到这个点,其它方向看过来看不到这个点,三个点的法线相同才能构成一个三角面。
uv: 基础纹理坐标, 左下角为(0,0) 左上角为(0,1) 右上角为(1,1) 右下角为(1,0)设置相应的四个点就可以贴出图片里的内容