版本 |
作者 |
参与者 |
完成日期 |
备注 |
UnityAPI_Mesh_V01_1.0 |
严立钻 |
|
2020.07.17 |
|
|
|
|
|
|
立钻哥哥:Unity是一个入门快、提高难的游戏引擎,想要提升能力,至少需要越过3道坎:API+Shader+综合能力;++1、API的积累:对API的合理利用不仅可以减轻自己的编码负担,而且往往可以提高程序的运行效率;这也是钻哥开始“Unity API”独立打造分类的初衷; ++2、Shader编程:想要做出一款精品游戏往往需要有高效的Shader的支持;Unity提供了一套改良的“Shader Lab”系统,优化了繁杂的“Open GL”编程; ++3、综合能力(技术+业务+管理):一款产品的制作除了功能编程外,往往会涉及很多其他领域,例如产品架构、UI交互设计、模型制作等,作为主要的编程人员,对其他相关领域的了解程序往往会影响到产品制作直至最后的产品体验; ++++立钻哥哥一直在推动【VR云游戏=Unity+SteamVR+云技术+5G+AI】,这个只是一个引子,抛砖引玉让大家对整个知识体系有一个明确的落地方向,宝宝们可以根据自己的兴趣方向进行拓展:比如Unity这里是指一种“3D游戏引擎”,也可拓展至“UE4、Cocos2dx”等游戏引擎;SteamVR是一种跨硬件解决方案,也可拓展至“VRTK”等第三方插件;“云技术+5G”是一种跨平台解决方案的核心技术,同样可拓展至其他平台解决方案;AI也是一种先进技术的举例,也可以拓展至任何一种前沿技术; |
++++【Unity API】分类:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html
++++【Unity开发基础】分类:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html
++++【Linux系统编程】分类:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html
++++【C++C铸就生存利器】分类:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html
++++【人工智能AI2026】分类:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html
++++【立钻哥哥CSDN空间】:https://blog.csdn.net/VRunSoftYanlz/
#Mesh网格 |
#Mesh网格++A1、Description描述++B2、Variables变量++C3、Public Function共有函数++D4、Message消息 |
#A1、Description描述 |
++MeshFilter网格过滤器(Inherits from: Component) ++++立钻哥哥:进入网格过滤器的类;使用程序上网格接口; ++++Variable(变量):mesh、sharedMesh; ++++[mesh]:网格; ++++[sharedMesh]:共享网格; |
++++网格(meshes)包括顶点和多个三角形数组;参考Procedural example project中的例子来使用网格的界面;
++++三角形数组仅仅是顶点的索引数组,每个三角形包含三个索引;
++++每个顶点可以有一条法线,两个纹理坐标,及颜色和切线;虽然这些是可选的,但是也可以去掉;所有的顶点信息是被储存在单独的同等规范的数组中,所以如果网格(mesh)有10个顶点,同样应该有大小为10的数组来存储法线和其它属性;
++++大概有3件事情是想要使用可修改的网格接口:1)新建一个网格,应该按照这个顺序来做:1.1>为顶点数组赋值;1.2>为三角形数组赋值;2)每帧修改顶点属性:2.1>获取顶点数组;2.2>修改它们;2.3>赋回网格;3)连续的改变网格的三角形数组值和顶点值:3.1>使用Clear刷新;3.2>指定顶点值和其他属性;3.3>指定索引值;
++++调用Clear函数在赋予新的顶点值和三角形索引值之前是非常重要的,Unity总是检查三角形的索引值,判断它们是否超出边界;调用Clear函数后,给顶点赋值,再给三角形数组赋值,以确保没有超出数组的边界;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{ public Vector3[] newVertices; public Vector2[] newUV; public int[] newTriangles;
void Start(){ Mesh mesh = new Mesh(); GetComponent<MeshFilter>().mesh = mesh; mesh.vertices = newVertices; mesh.uv = newUV; mesh.triangles = newTriangles; } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Update(){ Mesh mesh = GetComponent<MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; Vector3[] normals = mesh.normals;
int i = 0; while(i < vertices.Length){ vertices[i] += normals[i] * Mathf.Sin(Time.time); i++; } //立钻哥哥:while(){}
mesh.vertices = vertices; } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlMesh{} |
#B2、Variables变量 |
++B2、 Variables变量++++B2.1、bindposes++++B2.2、blendShapeCount++++B2.3、boneWeights++++B2.4、bounds++++B2.5、colors++++B2.6、colors32++++B2.7、isReadable++++B2.8、normals++++B2.9、subMeshCount++++B2.10、tangents++++B2.11、triangles++++B2.12、uv++++B2.13、uv2++++B2.14、uv3++++B2.15、uv4++++B2.16、vertexCount++++B2.17、vertices++++B2.18、YanlzXREngine.Mesh.Variables |
++B2.1、bindposes |
public Matrix4x4[] bindposes; |
++++绑定姿势;每个索引绑定姿势引用的是具有相同索引的骨骼;
++++当骨骼在绑定的姿势时,绑定的姿势是骨骼逆变换矩阵的反向;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ gameObject.AddComponent<Animation>(); gameObject.AddComponent<SkinnedMeshRenderer>(); SkinnedMeshRenderer rend = GetComponent<SkinnedMeshRenderer>(); Animation anim = GetComponent<Animation>();
Mesh mesh = new Mesh(); mesh.vertices = new Vector3[]{ new Vector3(-1,0,0), new Vector3(1,0,0), new Vector3(-1,5,0), new Vector3(1,5,0)}; mesh.uv = new Vector2[]{ new Vector2(0,0), new Vector2(1,0), new Vector2(0,1), new Vector2(1,1) }; mesh.triangles = new int[]{0,1,2,1,3,2}; mesh.RecalculateNormals();
rend.material = new Material(Shader.Find(“Diffuse”));
BoneWeight[] weights = new BoneWeight[4]; weights[0].boneIndex0 = 0; weights[0.]weight0 = 1; weights[1].boneIndex0 = 0; weights[1].weight0 = 1; weights[2].boneIndex0 = 1; weights[2].weight0 = 1; weights[3].boneIndex0 = 1; weights[3].weight0 = 1; mesh.boneWeights = weights;
Transform[] bones = new Transform[2]; Matrix4x4[] bindPoses = new Matrix4x4[2]; bones[0] = new GameObject(”MyLower”).transform; bones[0].parent = transform; bones[0].localRotation = Quaternion.identity; bones[0].localPosition = Vector3.zero; bindPoses[0] = bones[0].worldToLocalMaxtrix * transform.localToWorldMatrix;
bones[1] = new GameObject(“MyUpper”).transform; bones[1].parent = transform; bones[1].localRotation = Quaternion.identity; bones[1].localPosition = new Vector3(0, 5, 0); bindPoses[1] = bones[1].worldToLocalMatrix * transform.localToWorldMatrix;
mesh.bindposes = bindPoses; rend.bones = bones; rend.sharedMesh = mesh;
AnimationCurve curve = new AnimationCurve(); curve.keys = new Keyframe[]{ new Keyframe(0,0,0,0), new Keyframe(1,3,0,0), new Keyframe(2, 0.0F,0,0)}; AnimationClip clip = new AnimationClip(); clip.SetCurve(“MyLower”, typeof(Transform), “m_LocalPosition.z”, curve); anim.AddClip(clip, “MyTest”); anim.Play(“MyTest”); } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++B2.2、blendShapeCount |
public int blendShapeCount; |
++++返回该网格上的BlendShape数;
++B2.3、boneWeights |
public BoneWeight[] boneWeight; |
++++每个顶点的骨骼权重;
++++该数组的大小与vertexcount相同或为空;
++++每个顶点都可以最多收到4个不同骨骼的影响;这4个骨骼的权值之和应该为1;
Each vertex can be affected by up to 4 different bones. All 4 bone weights should sum up to 1. |
++B2.4、bounds |
public Bounds bounds; |
++++网格的边界体;
++++在网格局部坐标空间,轴对齐的边界盒(不会受到变换的影响);注意:与Renderer.bounds属性相识,但返回的是世界坐标空间的边界盒;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ Mesh mesh = GetComponent<MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; Vector2[] uvs = new Vector2[vertices.Length]; Bounds bounds = mesh.bounds;
int i = 0; while(i < uvs.Length){ uvs[i] = new Vector2(vertices[i].x / bounds.size.x, vertices[i].z / bounds.size.x); i++; } //立钻哥哥:while(){}
mesh.uv = uvs; } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++B2.5、colors |
public Color[] colors; |
++++网格的顶点颜色;
++++如果无顶点颜色可用,返回空数组;
++++出于性能因素,考虑使用colors32(Mesh.colors32)替代,这将避免字节到浮点数转换颜色,以及使用更少的临时内存;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ Mesh mesh = GetComponent<MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; Color[] colors = new Color[vertices.Length];
int i = 0; while(i < vertices.Length){ colors[i] = Color.Lerp(Color.red, Color.green, vertices[i].y); i++; } //立钻哥哥:while(){}
mesh.colors = colors; } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++B2.6、colors32 |
public Color32[] colors32; |
++++网格的顶点颜色;
++++同colors,使用Color32有更好的性能;
++B2.7、isReadable |
public bool isReadable; |
++++返回模型导入设置的“Read/Write Enabled”复选框状态;
++++对于从脚本生成的动态网格,总是返回true;
++++如果网格没有标记为可读写,当运行时从脚本访问任何数据将抛出错误;在Unity编辑器中游戏和渲染循环之外,访问被允许;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ Mesh mesh = GetComponent<MeshFilter>().sharedMesh; Debug.Log(mesh.isReadable); } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++B2.8、normals |
public int subMeshCount; |
++++子网格数,每个材质有单独的三角形列表;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ Mesh mesh = GetComponent<MeshFilter>().sharedMesh; Debug.Log(“立钻哥哥:Submeshes: ” + mesh.subMeshCount); } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++B2.9、subMeshCount |
public int subMeshCount; |
++++子网格数,每个材质有单独的三角形列表;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ Mesh mesh = GetComponent<MeshFilter>().sharedMesh; Debug.Log(“立钻哥哥:Submeshes: ” + mesh.subMeshCount); } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++B2.10、tangents |
public Vector4[] tangents; |
++++网格的切线;
++++切线主要用于带法线着色器;切线是一个有方向的单位长度向量,沿着网格表面指向水平(U)纹理方向;在Unity中切线被描述为Vector4,x,y,z组件定义的向量,如果需要,及w用来翻转副法线;
++++Unity通过计算向量和法线的叉乘来计算其他表面的向量(副法线),并乘以tangent.w;因此w应该总是1或者-1;
++++如果计划在网格上用凹凸贴图着色器,应该自己计算切线;在赋值法线或者用RecalculateNormals之后再赋值切线;
++B2.11、triangles |
public int[] triangles; |
++++网格包含的所有三角形的数组;
++++这个数组是包含顶点数组索引的三角形列表;三角形数组的大小是3的倍数;顶点可以通过简单的索引来共享同一顶点;如果网格包含多个子网格(材质),三角形列表将包含所有子网格的所有三角形;当赋值三角形数组,subMeshCount是设置为1;如果想要有多个子网格,使用subMeshCount和SetTriangles;
++++建议:先赋值顶点数组之后再赋值三角形数组,为了避免越界的错误;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ gameObject.AddComponent<MeshFilter>(); gameObject.AddComponent<MeshRenderer>();
Mesh mesh = GetComponent<MeshFilter>().mesh; mesh.Clear(); mesh.vertices = new Vector3[]{ new Vector3(0,0,0), new Vector3(0,1,0), new Vector3(1,1,0) }; mesh.uv = new Vector2[]{ new Vector2(0,0), new Vector2(0,1), new Vector2(1,1) }; mesh.triangles = new int[]{ 0, 1, 2 }; } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++B2.12、uv |
public Vector2[] uv; |
++++网格的基本纹理坐标;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ Mesh mesh = GetComponent<MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; Vector2[] uvs = new Vector2[vertices.Length];
for(int i = 0; i < uvs.Length; i++){ uvs[i] = new Vector2(vertices[i].x, vertices[i].z); } //立钻哥哥:for(){}
mesh.uv = uvs; } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++B2.13、uv2 |
public Vector2[] uv2; |
++++网格的第二套纹理坐标,如果存在的话;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ Mesh mesh = GetComponent<MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; Vector2[] uvs = new Vector2[vertices.Length];
int i = 0; while(i < uvs.Length){ uvs[i] = new Vector2(vertices[i].x, vertices[i].z); i++; } //立钻哥哥:while(){}
mesh.uv2 = uvs; } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++B2.14、uv3 |
public Vector2[] uv3; |
++++网格的第三套纹理坐标,如果存在的话;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ Mesh mesh = GetComponent<MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; Vector2[] uvs = new Vector2[vertices.Length];
int i = 0; while(i < uvs.Length){ uvs[i] = new Vector2(vertices[i].x, vertices[i].z); i++; } //立钻哥哥:while(){}
mesh.uv2 = uvs; mesh.uv3 = uvs; mesh.uv4 = uvs; } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++B2.15、uv4 |
public Vector2[] uv4; |
++++网格的第四套纹理坐标,如果存在的话;
++B2.16、vertexCount |
public int vertexCount; |
++++返回网格的顶点数量(只读);
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ Mesh mesh = GetComponent<MeshFilter>().sharedMesh; Debug.Log(mesh.vertexCount); } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++B2.17、vertices |
public Vector3[] vertices; |
++++返回顶点位置的拷贝或指定新顶点位置的数组;
++++网格中顶点数量是通过赋予一个不同数量的顶点数组来改变;注意:如果调整了顶点数组的大小,那么所有其他顶点的属性(法线,颜色,切线,纹理坐标)将自动地调节大小;在为顶点赋值时,如果这个网格的顶点有没有被赋值的那么RecalculateBounds将自动被调用;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ Mesh mesh = GetComponent<MeshFilter>().mesh; Vector3[] vertices = mesh.vertices;
int i = 0; while(i < uvs.Length){ vertices[i] += Vector3.up * Time.deltaTime; i++; } //立钻哥哥:while(){}
mesh.vertices = vertices; mesh.RecalculateBounds(); } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
#C3、Constructors构造器 |
++C3、Constructors构造器++++C3.1、Mesh++++C3.2、YanlzXREngine.Mesh.Constructors |
++C3.1、Mesh |
public Mesh(); |
++++创建一个空网格;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ Mesh mesh = new Mesh(); GetComponent<MeshFilter>().mesh = mesh; } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
#D4、Public Functions公有函数 |
++D4、Public Functions公有函数++++D4.1、AddBlendShapeFrame++++D4.2、Clear++++D4.3、ClearBlendShapes++++D4.4、CombineMeshes++++D4.5、GetBlendShapeFrameCount++++D4.6、GetBlendShapeFrameVertices++++D4.7、GetBlendShapeFrameWeight++++D4.8、GetBlendShapeIndex++++D4.9、GetBlendShapeName++++D4.10、GetIndices++++D4.11、GetTopology++++D4.12、GetTriangles++++D4.13、GetUVs++++D4.14、MarkDynamic++++D4.15、Optimize++++D4.16、RecalculateBounds++++D4.17、RecalculateNormals++++D4.18、SetColors++++D4.19、SetIndices++++D4.20、SetNormals++++D4.21、SetTangents++++D4.22、SetTriangles++++D4.23、SetUVs++++D4.24、SetVertices++++D4.25、UploadMeshData++++D4.26、YanlzXREngine.Mesh.PublicFunctions |
++D4.1、AddBlendShapeFrame |
public void AddBlendShapeFrame(string shapeName, float frameWeight, Vector3[] deltaVertices, Vector3[] deltaNormals, Vector3[] deltaTangents); |
++++[shapeName]:添加到帧的混合图形的名字;
++++[frameWeight]:帧的权重;
++++[deltaVertices]:帧的增量顶点;
++++[deltaNormals]:帧的增量法线;
++++[deltaTangents]:帧的增量切线;
++++添加新的混合图形帧;
++++如果混合图形不存在,那么创建新的混合图形;混合图形帧仅能添加新的或最后的混合图形;通常将单张用于混合图形,但混合范围[0~100%]可能被拆分成多个帧;当图形仅有一帧时,权重认定为100%;混合图形有多帧时,添加帧必须增加权重顺序;deltaVertices、deltaNormals和deltaTangents数组的大小=Mesh.vertexCount;减少网格顶点、法线和切线,从帧所有向量到获取增量来转换;如果该帧没有法线和切线,deltaNormals或deltaTangents可设置为null;
++D4.2、Clear |
public void Clear(bool keepVertexLayout=true); |
++++清空所有顶点数据和三角形索引,应该在重建三角形数组前使用这个函数;
++++该函数的默认行为保留了现有的顶点布局:如果网格有切线和顶点颜色,例如,一旦填充新的顶点数据,切线和颜色将是网格数据的一部分;如果想完全清除网格,并开始使用一个空的顶点布局,设置为true,设置为false,保留顶点布局;另外,指定空数组到任意网格组件也将删除定点布局;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ gameObject.AddComponent<MeshFilter>(); gameObject.AddComponent<MeshRenderer>();
Mesh mesh = GetComponent<MeshFilter>().mesh; mesh.Clear(); mesh.vertices = new Vector3[]{ new Vector3(0,0,0), new Vector3(0,1,0), new Vector3(1,1,0) }; mesh.uv = new Vector2[]{ new Vector2(0,0), new Vector2(0,1), new Vector2(1,1) }; mesh.triangles = new int[]{ 0, 1, 2 }; } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++D4.3、ClearBlendShapes |
public void ClearBlendShapes(); |
++++从网格清除所有混合图形;
++D4.4、CombineMeshes |
public void CombineMeshes(CombineInstance[] combine, bool mergeSubMeshes=true, bool useMatrices=true); |
++++[combine]:要合并的网格;
++++[mergeSubMeshes]:所有网格合并为单个子网格;
++++[useMatrices]:CombineInstance数组提供的变换是使用或忽略;
++++合并几个网格到该网格;
++++合并网格对于优化性能很有用;如果mergeSubMeshes为true,所有的网格合并到单个的子网格,否则每网格将合并到不同的子网格,如果所有网格共享同一材质,设置这个为true;如果useMatrices为false,在CombineInstance结构变换矩阵将被忽略;
using UnityEngine; using System.Collections; using YanlzXREngine;
[RequireComponent(typeof(MeshFilter))] [RequireComponent(typeof(MeshRenderer))] public class YanlzMesh : MonoBehaviour{
void Start(){ MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>(); CombineInstance[] combine = new CombineInstance[meshFilters.Length];
int i = 0; while(i < meshFilters.Length){ combine[i].mesh = meshFilters[i].sharedMesh; combine[i].transform = meshFilters[i].transform.localToWorldMatrix; meshFilters[i].gameObject.active = false; i++; } //立钻哥哥:while(){}
transform.GetComponent<MeshFilter>().mesh = new Mesh(); transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine); transform.gameObject.active = false; } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++D4.5、GetBlendShapeFrameCount |
public int GetBlendShapeFrameCount(int shapeIndex); |
++++[shapeIndex]:从该索引获取帧数;
++++返回混合图形的帧数;
++D4.6、GetBlendShapeFrameVertices |
public void GetBlendShapeFrameVertices(int shapeIndex, int frameIndex, Vector3[] deltaVertices, Vector3[] deltaNormals, Vector3[] deltaTangents); |
++++[shapeIndex]:该帧的图形索引;
++++[frameIndex]:从该帧索引获取权重;
++++[deltaVertices]:用于该帧开始获取的增量顶点输出数组;
++++[deltaNormals]:用于该帧开始获取的增量顶点输出法线;
++++[deltaTangents]:用于该帧开始获取的增量顶点输出切线;
++++获取混合图形帧的deltaVertices、deltaNormals和deltaTangents;
++++deltaVertices、deltaNormals和deltaTangents数组大小=Mesh.vertexCount;添加网格顶点、法线和切线从帧增量到所有向量来转换;如果用于该帧没有法线或切线,deltaNormals或deltaTangents可设置为null;
++D4.7、GetBlendShapeFrameWeight |
public float GetBlendShapeFrameWeight(int shapeIndex, int frameIndex); |
++++[shapeIndex]:该帧的图形索引;
++++[frameIndex]:从帧索引获取权重;
++++返回混合图形帧的权重;
++D4.8、GetBlendShapeIndex |
public int GetBlendShapeIndex(string blendShapeName); |
++++通过给定名称返回混合图形的索引;
++D4.9、GetBlendShapeName |
public string GetBlendShapeName(int shapeIndex); |
++++通过给定索引返回混合图形的名称;
++D4.10、GetIndices |
public int[] GetIndices(int submesh); |
++++返回子网格的索引;
++++索引的布局取决于子网格的拓扑,例如,三角形网格,每个三角形将返回三个索引;
++D4.11、GetTopology |
public MeshTopology GetTopology(int submesh); |
++++获取子网格的拓扑;
++D4.12、GetTriangles |
public int[] GetTriangles(int submesh); |
++++返回子网格的三角形列表;
++++一个子网格是一个单独的三角形列表;当网格渲染器使用多个材质时,应该保证有子网格同样数量的材质;
++D4.13、GetUVs |
public void GetUVs(int channel, List<Vector2> uvs);public void GetUVs(int channel, List<Vector3> uvs);public void GetUVs(int channel, List<Vector4> uvs); |
++++[channel]:UV通道(从0索引开始);
++++[uvs]:获取给定索引的UV列表;
++++获取给定channel索引的UV;
++++从channel获取UV,可以是Vector2、Vector3或Vector4列表;
++D4.14、MarkDynamic |
public void MarkDynamic(); |
++++优化频繁更新的网格;
++++分配顶点之前调用这个,当连续更新网格时,以获得更好的性能;内部将使网格在底层图形接口使用“动态缓存器”,当网格数据经常改变时,更高效;
++D4.15、Optimize |
public void Optimize(); |
++++优化用于显示的网格;
++++这个操作也许会需要一些时间,但是会使几何体显示地更快;例如:它从三角形中形成三角形带;如果从头生成网格并想在运行的时候取得更好的运行时性能面而不是较高的加载时间,应该使用它;三角带化的模型为每个顶点缓存位置优化三角形;对于导入的模型不应该调用这个函数,因为导入已经做过了;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ Mesh mesh = GetComponent<MeshFilter>().mesh; mesh.Optimize(); } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++D4.16、RecalculateBounds |
public void RecalculateBounds(); |
++++从顶点重新计算从网格包围体;
++++在修改顶点后应该调用这个函数,以确保边界体是正确的;分配的三角形将自动重新计算这个边界体;
++++注意:SkinnedMeshRenderer的边界,仅能通过SkinnedMeshRenderer.localBounds设置更改;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ Mesh mesh = GetComponent<MeshFilter>().mesh; mesh.RecalculateBounds(); } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++D4.17、RecalculateNormals |
public void RecalculateNormals(); |
++++重新计算网格的法线;
++++在修改完顶点后,通常会更新法线来反映新的变化;法线是根据共享的顶点计算出来的;导入到网格有时不共享所有的顶点;例如:一个顶点在一个纹理坐标的接缝处将会被分成两个顶点;因此这个RecalculateNormals函数将会在纹理坐标接缝处创建一个不光滑的法线;RecalculateNormals不会自动产生切线,因此bumpmap着色器在调用RecalculateNormals之后不会工作;然而可以提供自己的切线;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzMesh : MonoBehaviour{
void Start(){ Mesh mesh = GetComponent<MeshFilter>().mesh; mesh.RecalculateNormals(); } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlMesh{} |
++D4.18、SetColors |
public void SetColors(List<Color> inColors);public void SetColors(List<Color32> inColors); |
++++[inColors]:每个顶点颜色;
++++网格的顶点颜色;
++D4.19、SetIndices |
public void SetIndices(int[] indices, MeshTopology topology, int submesh); |
++++设置网格的索引;
++++一个子网格是简单的单独索引数组;当网格渲染器使用多个材质,应确保对应的多少子网格用作材质;
++++SetTriangles和triangles总是使网格组成三角面;使用SetIndices可以通过线或点来创建网格;
++D4.20、SetNormals |
public void SetNormals(List<Vector3> inNormals); |
++++[inNormals]:每顶点法线;
++++设置网格的法线;
++D4.21、SetTangents |
public void SetTangents(List<Vector4> inTangents); |
++++[inTangents]:每个顶点的切线;
++++设置网格的切线;
++D4.22、SetTriangles |
public void SetTriangles(List<int> inTriangles, int submes);public void SetTriangles(int[] triangles, int submesh); |
++++设置子网格的三角形列表;
++++一个子网格是一个单独的三角形列表;当网格渲染器使用多个材质时,应该确保子网格有同样数量的材质;
++++建议:在指定顶点数组后再给三角形数组赋值,以避免越界错误;
++D4.23、SetUVs |
public void SetUVs(int channel, List<Vector2> uvs);public void SetUVs(int channel, List<Vector3> uvs);public void SetUVs(int channel, List<Vector4> uvs); |
++++[channel]:UV通道索引(从0开始);
++++[uvs]:设置给定索引的UV列表;
++++用给定通道设置UV;
++++设置一个通道UV;可以是Vector2、Vector3或Vector4列表;
++D4.24、SetVertices |
public void SetVertices(List<Vector3> inVertices); |
++++[inVertices]:每个顶点的位置;
++++指定新的顶点位置数组;
++D4.25、UploadMeshData |
public void UploadMeshData(bool markNoLogerReadable); |
++++[markNoLogerReadable]:设置为真时,可释放网格数据的系统内存副本;
++++上传之前完成的网格修改到显卡API;
++++当从代码创建或修改网格(使用vertices, normals, triangles等),内部网格数据被标记为“modified”并且发送到下次网格被渲染的显卡API;
++++能立即调用UploadMeshData发送修改的数据到显卡API,以避免可能的卡顿;参数markNoLogerReadable设置为true,使网格数据从脚本不可读,并释放数据的系统内存拷贝;
#E5、立钻哥哥对Mesh类的拓展 |
++++【Unity API】分类:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html
++++【Unity开发基础】分类:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html
++++【Linux系统编程】分类:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html
++++【C++C铸就生存利器】分类:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html
++++【人工智能AI2026】分类:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html
++++【立钻哥哥CSDN空间】:https://blog.csdn.net/VRunSoftYanlz/
立钻哥哥推荐的拓展学习链接(Link_Url) |
++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz/
++++虚拟现实VR资讯: https://blog.csdn.net/VRunSoftYanlz/article/details/89165846
++++HTC_VIVE开发基础:https://blog.csdn.net/VRunSoftYanlz/article/details/81989970
++++Oculus杂谈:https://blog.csdn.net/VRunSoftYanlz/article/details/82469850
++++Oculus安装使用:https://blog.csdn.net/VRunSoftYanlz/article/details/82718982
++++Unity+SteamVR=>VR:https://blog.csdn.net/VRunSoftYanlz/article/details/88809370
++++Unity减少VR晕眩症:https://blog.csdn.net/VRunSoftYanlz/article/details/89115518
++++SteamVR简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86484254
++++SteamVR脚本功能分析:https://blog.csdn.net/VRunSoftYanlz/article/details/86531480
++++SteamVR2.0开发指南:https://blog.csdn.net/VRunSoftYanlz/article/details/86618187
++++SteamVR2.2.0开发指南:https://blog.csdn.net/VRunSoftYanlz/article/details/88784527
++++SteamVR2.2.0快速入门:https://blog.csdn.net/VRunSoftYanlz/article/details/88833579
++++SteamVR2.2.0交互系统:https://blog.csdn.net/VRunSoftYanlz/article/details/89199778
++++SteamVR2.2.0传送机制:https://blog.csdn.net/VRunSoftYanlz/article/details/89390866
++++SteamVR2.2.0教程(一):https://blog.csdn.net/VRunSoftYanlz/article/details/89324067
++++SteamVR2.2.0教程(二):https://blog.csdn.net/VRunSoftYanlz/article/details/89894097
++++SteamVR_Skeleton_Poser:https://blog.csdn.net/VRunSoftYanlz/article/details/89931725
++++SteamVR实战之PMCore:https://blog.csdn.net/VRunSoftYanlz/article/details/89463658
++++SteamVR/Extras:https://blog.csdn.net/VRunSoftYanlz/article/details/86584108
++++SteamVR/Input:https://blog.csdn.net/VRunSoftYanlz/article/details/86601950
++++OpenXR简介:https://blog.csdn.net/VRunSoftYanlz/article/details/85726365
++++VRTK杂谈:https://blog.csdn.net/VRunSoftYanlz/article/details/82562993
++++VRTK快速入门(杂谈):https://blog.csdn.net/VRunSoftYanlz/article/details/82955267
++++VRTK官方示例(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82955410
++++VRTK代码结构(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82780085
++++VRTK(SceneResources):https://blog.csdn.net/VRunSoftYanlz/article/details/82795400
++++VRTK_ControllerEvents:https://blog.csdn.net/VRunSoftYanlz/article/details/83099512
++++VRTK_InteractTouch:https://blog.csdn.net/VRunSoftYanlz/article/details/83120220
++++虚拟现实行业应用:https://blog.csdn.net/VRunSoftYanlz/article/details/88360157
++++Steam平台上的VR:https://blog.csdn.net/VRunSoftYanlz/article/details/88960085
++++Steam平台热销VR:https://blog.csdn.net/VRunSoftYanlz/article/details/89007741
++++VR实验:以太网帧的构成:https://blog.csdn.net/VRunSoftYanlz/article/details/82598140
++++实验四:存储器扩展实验:https://blog.csdn.net/VRunSoftYanlz/article/details/87834434
++++FrameVR示例V0913:https://blog.csdn.net/VRunSoftYanlz/article/details/82808498
++++FrameVR示例V1003:https://blog.csdn.net/VRunSoftYanlz/article/details/83066516
++++SwitchMachineV1022:https://blog.csdn.net/VRunSoftYanlz/article/details/83280886
++++PlaySceneManagerV1022:https://blog.csdn.net/VRunSoftYanlz/article/details/83280886
++++Unity5.x用户手册:https://blog.csdn.net/VRunSoftYanlz/article/details/81712741
++++Unity面试题ABC:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++Unity面试题D:https://blog.csdn.net/VRunSoftYanlz/article/details/78630838
++++Unity面试题E:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity面试题F:https://blog.csdn.net/VRunSoftYanlz/article/details/78630945
++++Cocos2dx面试题:https://blog.csdn.net/VRunSoftYanlz/article/details/78630967
++++禅道[zentao]:https://blog.csdn.net/VRunSoftYanlz/article/details/83964057
++++Lua快速入门篇(Xlua拓展):https://blog.csdn.net/VRunSoftYanlz/article/details/81173818
++++Lua快速入门篇(XLua教程):https://blog.csdn.net/VRunSoftYanlz/article/details/81141502
++++Lua快速入门篇(基础概述):https://blog.csdn.net/VRunSoftYanlz/article/details/81041359
++++框架知识点:https://blog.csdn.net/VRunSoftYanlz/article/details/80862879
++++游戏框架(UI框架夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80781140
++++游戏框架(初探篇):https://blog.csdn.net/VRunSoftYanlz/article/details/80630325
++++.Net框架设计:https://blog.csdn.net/VRunSoftYanlz/article/details/87401225
++++从零开始学架构:https://blog.csdn.net/VRunSoftYanlz/article/details/88095895
++++设计模式简单整理:https://blog.csdn.net/vrunsoftyanlz/article/details/79839641
++++专题:设计模式(精华篇):https://blog.csdn.net/VRunSoftYanlz/article/details/81322678
++++U3D小项目参考:https://blog.csdn.net/vrunsoftyanlz/article/details/80141811
++++Unity小游戏算法分析:https://blog.csdn.net/VRunSoftYanlz/article/details/87908365
++++Unity案例(Vehicle):https://blog.csdn.net/VRunSoftYanlz/article/details/82355876
++++UML类图:https://blog.csdn.net/vrunsoftyanlz/article/details/80289461
++++PowerDesigner简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86500084
++++Unity知识点0001:https://blog.csdn.net/vrunsoftyanlz/article/details/80302012
++++Unity知识点0008:https://blog.csdn.net/VRunSoftYanlz/article/details/81153606
++++U3D_Shader编程(第一篇:快速入门篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372071
++++U3D_Shader编程(第二篇:基础夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372628
++++Unity引擎基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78881685
++++Unity面向组件开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78881752
++++Unity物理系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78881879
++++Unity2D平台开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78882034
++++UGUI基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78884693
++++UGUI进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78884882
++++UGUI综合:https://blog.csdn.net/vrunsoftyanlz/article/details/78885013
++++Unity动画系统基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78886068
++++Unity动画系统进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78886198
++++Navigation导航系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78886281
++++Unity特效渲染:https://blog.csdn.net/vrunsoftyanlz/article/details/78886403
++++Unity数据存储:https://blog.csdn.net/vrunsoftyanlz/article/details/79251273
++++Unity中Sqlite数据库:https://blog.csdn.net/vrunsoftyanlz/article/details/79254162
++++WWW类和协程:https://blog.csdn.net/vrunsoftyanlz/article/details/79254559
++++Unity网络:https://blog.csdn.net/vrunsoftyanlz/article/details/79254902
++++Unity资源加密:https://blog.csdn.net/VRunSoftYanlz/article/details/87644514
++++PhotonServer简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86652770
++++编写Photon游戏服务器:https://blog.csdn.net/VRunSoftYanlz/article/details/86682935
++++C#事件:https://blog.csdn.net/vrunsoftyanlz/article/details/78631267
++++C#委托:https://blog.csdn.net/vrunsoftyanlz/article/details/78631183
++++C#集合:https://blog.csdn.net/vrunsoftyanlz/article/details/78631175
++++C#泛型:https://blog.csdn.net/vrunsoftyanlz/article/details/78631141
++++C#接口:https://blog.csdn.net/vrunsoftyanlz/article/details/78631122
++++C#静态类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630979
++++C#中System.String类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630945
++++C#数据类型:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity3D默认的快捷键:https://blog.csdn.net/vrunsoftyanlz/article/details/78630838
++++游戏相关缩写:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++UnityAPI.Rigidbody刚体:https://blog.csdn.net/VRunSoftYanlz/article/details/81784053
++++UnityAPI.Material材质:https://blog.csdn.net/VRunSoftYanlz/article/details/81814303
++++UnityAPI.Android安卓:https://blog.csdn.net/VRunSoftYanlz/article/details/81843193
++++UnityAPI.AndroidJNI安卓JNI:https://blog.csdn.net/VRunSoftYanlz/article/details/81879345
++++UnityAPI.Transform变换:https://blog.csdn.net/VRunSoftYanlz/article/details/81916293
++++UnityAPI.WheelCollider轮碰撞器:https://blog.csdn.net/VRunSoftYanlz/article/details/82356217
++++UnityAPI.Resources资源:https://blog.csdn.net/VRunSoftYanlz/article/details/83155518
++++JSON数据结构:https://blog.csdn.net/VRunSoftYanlz/article/details/82026644
++++CocosStudio快速入门:https://blog.csdn.net/VRunSoftYanlz/article/details/82356839
++++Unity企业内训(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82634668
++++Unity企业内训(第1讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82634733
++++Unity企业内训(第2讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82861180
++++Unity企业内训(第3讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82927699
++++Unity企业内训(第4讲):https://blog.csdn.net/VRunSoftYanlz/article/details/83479776
++++Unity企业内训(第5讲):https://blog.csdn.net/VRunSoftYanlz/article/details/83963811
++++Unity企业内训(第6讲):https://blog.csdn.net/VRunSoftYanlz/article/details/84207696
++++钻哥带您了解产品原型:https://blog.csdn.net/VRunSoftYanlz/article/details/87303828
++++插件
++++计算机组成原理(教材篇):https://blog.csdn.net/VRunSoftYanlz/article/details/82719129
++++5G接入:云计算和雾计算:https://blog.csdn.net/VRunSoftYanlz/article/details/88372718
++++云计算通俗讲义:https://blog.csdn.net/VRunSoftYanlz/article/details/88652803
++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz
--_--VRunSoft:lovezuanzuan--_--
--_--VRunSoft:lovezuanzuan--_--