本文整理汇总了C#中UnityEngine.Mesh.SetTriangles方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.SetTriangles方法的具体用法?C# Mesh.SetTriangles怎么用?C# Mesh.SetTriangles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Mesh
的用法示例。
在下文中一共展示了Mesh.SetTriangles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetDrops
public void SetDrops(int drops, int maxDrops)
{
Mesh mesh = new Mesh();
{
mesh.vertices = new []
{
new Vector3(0, 0, 0),
new Vector3(0, 10, 0),
new Vector3(drops * 10, 10, 0),
new Vector3(drops * 10, 0, 0),
new Vector3(drops * 10, 0, 0),
new Vector3(drops * 10, 10, 0),
new Vector3(maxDrops * 10, 10, 0),
new Vector3(maxDrops * 10, 0, 0)
};
mesh.uv = new []
{
new Vector2 { x = 0, y = 0 },
new Vector2 { x = 0, y = 1 },
new Vector2 { x = drops, y = 1 },
new Vector2 { x = drops, y = 0 },
new Vector2 { x = 0, y = 0.0f },
new Vector2 { x = 0, y = 1.0f },
new Vector2 { x = maxDrops - drops, y = 1 },
new Vector2 { x = maxDrops - drops, y = 0 },
};
mesh.subMeshCount = 2;
mesh.SetTriangles(new [] { 0, 1, 2, 2, 3, 0 }, 0);
mesh.SetTriangles(new [] { 4, 5, 6, 6, 7, 4 }, 1);
}
meshFilter.mesh = mesh;
}
示例2: CloneMesh
static Mesh CloneMesh(Mesh mesh)
{
Mesh clonemesh = new Mesh();
clonemesh.vertices = mesh.vertices;
clonemesh.uv1 = mesh.uv1;
clonemesh.uv2 = mesh.uv2;
clonemesh.uv = mesh.uv;
clonemesh.normals = mesh.normals;
clonemesh.tangents = mesh.tangents;
clonemesh.colors = mesh.colors;
clonemesh.subMeshCount = mesh.subMeshCount;
for ( int s = 0; s < mesh.subMeshCount; s++ )
{
clonemesh.SetTriangles(mesh.GetTriangles(s), s);
}
//clonemesh.triangles = mesh.triangles;
clonemesh.boneWeights = mesh.boneWeights;
clonemesh.bindposes = mesh.bindposes;
clonemesh.name = mesh.name + "_copy";
clonemesh.RecalculateBounds();
return clonemesh;
}
示例3: compileMesh
public Mesh compileMesh()
{
Mesh myMesh = new Mesh();
myMesh.name = "ProcedralMesh";
myMesh.subMeshCount = tris.Length;
if(verts.Count == 0)
{
Debug.LogError("sorry verts are empty"+ this);
}
myMesh.vertices = verts.ToArray();
for(int i=0; i < tris.Length; i++)
{
//Debug.Log(i);
myMesh.SetTriangles(tris[i].ToArray (),i);
}
uvMap();
if (uv.Count > 0)
{
myMesh.uv = uv.ToArray ();
}
myMesh.RecalculateNormals();
myMesh.RecalculateBounds();
return myMesh;
}
示例4: RotateMesh
//"rotate" the mesh data
private void RotateMesh(Mesh mesh)
{
int index = 0;
//switch all vertex z values with y values
Vector3[] vertices = mesh.vertices;
for (index = 0; index < vertices.Length; index++)
{
vertices[index] = new Vector3(vertices[index].x, vertices[index].z, vertices[index].y);
}
mesh.vertices = vertices;
//for each submesh, we invert the order of vertices for all triangles
//for some reason changing the vertex positions flips all the normals???
for (int submesh = 0; submesh < mesh.subMeshCount; submesh++)
{
int[] triangles = mesh.GetTriangles(submesh);
for (index = 0; index < triangles.Length; index += 3)
{
int intermediate = triangles[index];
triangles[index] = triangles[index + 2];
triangles[index + 2] = intermediate;
}
mesh.SetTriangles(triangles, submesh);
}
//recalculate other relevant mesh data
mesh.RecalculateNormals();
mesh.RecalculateBounds();
}
示例5: CreateConnectedMesh
public static void CreateConnectedMesh (Mesh mesh, List<Slice2D> slices)
{
var sliceCount = slices.Count;
if (sliceCount < 2)
return;
// Eg.: | | | | | => 5 slices = 8 tris (5 - 1 => 4quads * 2tris/quad = 8), times 3 idx / tri
var triIdx = new int[(sliceCount - 1) * 6];
// Eg.: 1 3 3 5
// 0 2 2 4 ... => 0,1,3, 0,3,2, 2,3,4, 2,5,4
int i = 0;
// J is the Triangle Index
// Will repeat the number of quads (slices-1) * 6 (2 tris)
for (int j = 0; j < ((sliceCount - 1) * 6); j = j + 6) {
triIdx[j] = i;
triIdx[j + 1] = i + 1;
triIdx[j + 2] = i + 3;
triIdx[j + 3] = i;
triIdx[j + 4] = i + 3;
triIdx[j + 5] = i + 2;
//Debug.Log(" j:" + j+" "+(j+1)+" "+(j+2)+" "+(j+3)+" "+(j+4)+" "+(j+5));
i += 2;
}
mesh.SetTriangles (triIdx, 0);
mesh.RecalculateNormals ();
}
示例6: CloneMesh
//todo this really needs to be threaded, some meshes are quite large
public static Mesh CloneMesh(Mesh mesh)
{
Mesh newmesh = new Mesh();
newmesh.name = mesh.name;
var newverts = new Vector3[mesh.vertices.Length];
for (int i = 0; i < mesh.vertices.Length; i++)
{
var vertex = mesh.vertices[i];
Vector3 v = qRotateX * vertex;
newverts[i] = qRotateZ * v;
}
newmesh.vertices = newverts;
newmesh.subMeshCount = mesh.subMeshCount;
for (int i = 0; i < mesh.subMeshCount; i++)
{
int[] triangles = mesh.GetTriangles(i);
newmesh.SetTriangles(triangles, i);
}
newmesh.uv = mesh.uv;
newmesh.uv2 = mesh.uv2;
newmesh.uv2 = mesh.uv2;
newmesh.normals = mesh.normals;
newmesh.colors = mesh.colors;
newmesh.tangents = mesh.tangents;
return newmesh;
}
示例7: MergeVertices
/**
* Merge indices to a single vertex. Operates on a Mesh, not pb_Object.
*/
public static void MergeVertices(List<List<int>> InIndices, ref Mesh InMesh)
{
Dictionary<int, int> swapTable = new Dictionary<int, int>();
foreach(List<int> group in InIndices)
{
for(int i = 1; i < group.Count; i++)
{
swapTable.Add(group[i], group[0]);
}
}
// Iterate triangles and point collapse-able verts to the first index
for(int submeshIndex = 0; submeshIndex < InMesh.subMeshCount; submeshIndex++)
{
int[] tris = InMesh.GetTriangles(submeshIndex);
for(int i = 0; i < tris.Length; i++)
{
if( swapTable.ContainsKey(tris[i]) )
tris[i] = swapTable[tris[i]];
}
InMesh.SetTriangles(tris, submeshIndex);
}
// populate list of unused vertices post-collapse
List<int> unused = InIndices.SelectMany( x => x.GetRange(1, x.Count - 1) ).ToList();
RemoveVertices(unused, ref InMesh);
}
示例8: CreateSplitMesh
public static void CreateSplitMesh (Mesh mesh, List<Slice2D> slices)
{
var sliceCount = slices.Count;
if (sliceCount < 2)
return;
// Eg.: | | | | | => 5 slices = 8 tris (5 - 1 => 4quads * 2tris/quad = 8), times 3 idx / tri
var triIdx = new int[(sliceCount - 1) * 6];
// Eg.: 1 3 5 7
// 0 2 4 6 ... => 0,1,3, 0,3,2, 4,5,7, 4,7,6
int i = 0;
// "j" is the Triangle Index
// Will repeat the number of quads (slices/2) * 6 (# of "j"s per quad)
for (int j = 0; j < (sliceCount * 3); j = j + 6) {
triIdx[j] = i;
triIdx[j + 1] = i + 1;
triIdx[j + 2] = i + 3;
triIdx[j + 3] = i;
triIdx[j + 4] = i + 3;
triIdx[j + 5] = i + 2;
//Debug.Log(" j:" + j+" "+(j+1)+" "+(j+2)+" "+(j+3)+" "+(j+4)+" "+(j+5));
//Debug.Log(" i:" + i + " " + (i + 1) + " " + (i + 3) + " " + (i) + " " + (i + 3) + " " + (i + 2));
i += 4;
}
mesh.SetTriangles (triIdx, 0);
mesh.RecalculateNormals ();
}
示例9: Instance
public void Instance(){
MeshFilter m = GetComponent<MeshFilter>();
Mesh oldMesh = m.mesh;
Mesh newMesh = new Mesh();
newMesh.name = oldMesh.name;
newMesh.vertices = oldMesh.vertices;
newMesh.normals = oldMesh.normals;
newMesh.uv = oldMesh.uv;
newMesh.SetTriangles(oldMesh.GetTriangles(0), 0);
m.mesh = newMesh;
}
示例10: DeepCopy
static void DeepCopy()
{
GameObject subject = Selection.activeGameObject;
GameObject clone = (GameObject)GameObject.Instantiate(subject);
MeshFilter[] mfs = subject.GetComponentsInChildren<MeshFilter>();
MeshFilter[] clonemfs = clone.GetComponentsInChildren<MeshFilter>();
MeshCollider[] mcs = clone.GetComponentsInChildren<MeshCollider>();
MeshCollider[] clonemcs = clone.GetComponentsInChildren<MeshCollider>();
int l = mfs.Length;
for ( int i = 0; i < l; i++ )
{
MeshFilter mf = mfs[i];
MeshFilter clonemf = clonemfs[i];
Mesh mesh = mf.sharedMesh;
Mesh clonemesh = new Mesh();
clonemesh.vertices = mesh.vertices;
clonemesh.uv1 = mesh.uv1;
clonemesh.uv2 = mesh.uv2;
clonemesh.uv = mesh.uv;
clonemesh.normals = mesh.normals;
clonemesh.tangents = mesh.tangents;
clonemesh.colors = mesh.colors;
clonemesh.subMeshCount = mesh.subMeshCount;
for ( int s = 0; s < mesh.subMeshCount; s++ )
{
clonemesh.SetTriangles(mesh.GetTriangles(s), s);
}
//clonemesh.triangles = mesh.triangles;
clonemesh.boneWeights = mesh.boneWeights;
clonemesh.bindposes = mesh.bindposes;
clonemesh.name = mesh.name + "_copy";
clonemesh.RecalculateBounds();
clonemf.sharedMesh = clonemesh;
for ( int j = 0; j < mcs.Length; j++ )
{
MeshCollider mc = mcs[j];
if ( mc.sharedMesh = mesh )
clonemcs[j].sharedMesh = clonemesh;
}
}
}
示例11: Sail
public Sail(Material _mat,Vector2 _size)
{
//m_mat=_mat;
m_sail_unit=new Vector2(_size.x/m_cell_num,_size.y/m_cell_num);
m_go=new GameObject("Sail");
m_mesh=m_go.AddComponent<MeshFilter>().mesh;
List<Vector3> _list=new List<Vector3>();
List<int> _ii=new List<int>();
for(int i=0;i<m_cell_num;++i)
{
for(int j=0;j<m_cell_num;++j)
{
_list.Add(new Vector3(j*m_sail_unit.x,i*m_sail_unit.y,0));
m_vec_list.Add(new Vector3(j*m_sail_unit.x,i*m_sail_unit.y,0));
m_base_vec_list.Add(new Vector3(j*m_sail_unit.x,i*m_sail_unit.y,0));
}
}
for(int i=0;i<m_cell_num-1;++i)
{
for(int j=0;j<m_cell_num-1;++j)
{
_ii.Add(i*m_cell_num+j);
_ii.Add(i*m_cell_num+j+1);
_ii.Add(i*m_cell_num+j+1+m_cell_num);
_ii.Add(i*m_cell_num+j);
_ii.Add(i*m_cell_num+j+1+m_cell_num);
_ii.Add(i*m_cell_num+j+m_cell_num);
}
}
List<Vector2> _uv_list=new List<Vector2>();
for(int i=0;i<m_cell_num;++i)
{
for(int j=0;j<m_cell_num;++j)
{
_uv_list.Add(new Vector2(j/(float)m_cell_num,i/(float)m_cell_num));
}
}
m_mesh.vertices=_list.ToArray();
m_mesh.SetTriangles(_ii.ToArray(),0);
m_mesh.uv=_uv_list.ToArray();
m_mesh.RecalculateNormals();
MeshRenderer _mr= m_go.AddComponent<MeshRenderer>();
for(int i=0;i<m_cell_num*(m_cell_num-1);++i)
{
m_node_list.Add(i);
}
_mr.material=_mat;
}
示例12: GenerateMesh
public override Mesh GenerateMesh(VoxelContainer data, IntVector3 start, IntVector3 end)
{
var verts = GenerateVertsFor(data, start, end);
if (!verts.Any())
return null;
var result = new Mesh()
{
vertices = verts.Select(v => v.Position).ToArray(),
uv = verts.Select(v => v.Uv).ToArray()
};
result.SetTriangles(GenerateIndicesFor(verts).ToArray(), 0);
return result;
}
示例13: FillMesh
public static void FillMesh(Mesh mesh, Vector3[] vs, Vector3[] ns, Vector2[] uv1s, Vector2[] uv2s, Vector2[] uv3s, Vector2[] uv4s, Color32[] colors32, int[] ts, BoneWeight[] bws, Matrix4x4[] bindposes, int[] subMeshOffsets, bool recalcNormals)
{
mesh.vertices = vs;
if(ns != null && ns.Length > 0) mesh.normals = ns;
if(uv1s != null && uv1s.Length > 0) mesh.uv = uv1s;
if(uv2s != null && uv2s.Length > 0) mesh.uv2 = uv2s;
#if UNITY_4_3
#elif UNITY_4_4
#elif UNITY_4_5
#elif UNITY_4_6
#else
if(uv3s != null && uv2s.Length > 0) mesh.uv3 = uv3s;
if(uv4s != null && uv2s.Length > 0) mesh.uv4 = uv4s;
#endif
if(colors32 != null && colors32.Length > 0) mesh.colors32 = colors32;
if(bws != null && bws.Length > 0) mesh.boneWeights = bws;
if(bindposes != null && bindposes.Length > 0) mesh.bindposes = bindposes;
if(subMeshOffsets.Length == 1) {
mesh.triangles = ts;
} else {
mesh.subMeshCount = subMeshOffsets.Length;
for(int s=0;s<subMeshOffsets.Length;s++) {
subMeshOffsets[s] = Mathf.Max(0,subMeshOffsets[s]);
int end = s+1 < subMeshOffsets.Length ? subMeshOffsets[s+1] : ts.Length;
if(end - subMeshOffsets[s] > 0) {
int[] subTs = new int[end - subMeshOffsets[s]];
Array.Copy(ts, subMeshOffsets[s], subTs, 0, end - subMeshOffsets[s]);
mesh.SetTriangles(subTs, s);
} else {
mesh.SetTriangles((int[])null, s);
}
}
}
if(recalcNormals || mesh.normals == null || mesh.normals.Length <= 0) mesh.RecalculateNormals();
mesh.RecalculateTangents();
}
示例14: Awake
// Use this for initialization
void Awake()
{
vfx = GetComponentInChildren<ParticleSystem>();
firedRay = GetComponentInChildren<MeshRenderer>();
firedRay.sortingLayerName = Tags.SortingLayers.overlay;
MeshFilter filter = GetComponent<MeshFilter>();
mesh = filter.mesh;
Vector3[] vertices = new Vector3[] { new Vector3(0, -width / 2, 0), new Vector3(0, width / 2, 0), new Vector3(60, -width / 2, 0), new Vector3(60, width / 2, 0)};
Vector2[] uvs = new Vector2[] {Vector2.zero, Vector2.up, Vector2.right, Vector2.one};
int[] tris = new int[]{3, 2, 1, 0, 1, 2};
//apply to mesh
mesh.vertices = vertices;
mesh.uv = uvs;
mesh.SetTriangles(tris, 0);
}
示例15: CreateNewSplit
void CreateNewSplit(Vector3[] verts, int[] tris, int[] innerTris, Vector2[] uvs, Vector3[] normals, Vector3 force)
{
var split = new GameObject();
split.transform.position = transform.position;
split.transform.rotation = transform.rotation;
split.transform.localScale = transform.localScale;
split.transform.parent = transform.parent;
Mesh mesh = new Mesh();
mesh.vertices = verts;
mesh.triangles = tris;
mesh.subMeshCount += 1;
mesh.SetTriangles(innerTris, 1);
mesh.uv = uvs;
//mesh.RecalculateNormals();
mesh.normals = normals;
mesh.colors = this.mesh.colors;
mesh.Optimize();
split.AddComponent<MeshFilter>().mesh = mesh;
var rend = split.AddComponent<MeshRenderer>();
Material[] materials = new Material[2]{
GetComponent<MeshRenderer>().material,
innerMaterial
};
rend.materials = materials;
//rend.material = GetComponent<MeshRenderer>().material;
var splittable = split.AddComponent<Splitable>();
splittable.innerMaterial = innerMaterial;
splittable.FireSplitEvent = false;
var convex = new SimpleConvex(mesh);
var simpleMesh1 = convex.BuildSimplifiedConvexMesh();
var collider = split.AddComponent<MeshCollider>();
collider.sharedMesh = simpleMesh1;
collider.convex = true;
var rigidBody = split.AddComponent<Rigidbody>();
rigidBody.AddForce(force);
/*split.GetComponent<Rigidbody>().velocity = GetComponent<Rigidbody>().velocity;*/
}