本文整理汇总了C#中UnityEngine.Mesh.SetIndices方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.SetIndices方法的具体用法?C# Mesh.SetIndices怎么用?C# Mesh.SetIndices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Mesh
的用法示例。
在下文中一共展示了Mesh.SetIndices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateOverlayMesh
/**
* Creates a new mesh using only the @src positions, normals, and a new color array.
*/
public static Mesh CreateOverlayMesh(Mesh src)
{
Mesh m = new Mesh();
m.name = "Overlay Mesh: " + src.name;
m.vertices = src.vertices;
m.normals = src.normals;
m.colors = z_Util.Fill<Color>(new Color(0f, 0f, 0f, 0f), m.vertexCount);
m.subMeshCount = src.subMeshCount;
for(int i = 0; i < src.subMeshCount; i++)
{
if(src.GetTopology(i) == MeshTopology.Triangles)
{
int[] tris = src.GetIndices(i);
int[] lines = new int[tris.Length * 2];
int index = 0;
for(int n = 0; n < tris.Length; n+=3)
{
lines[index++] = tris[n+0];
lines[index++] = tris[n+1];
lines[index++] = tris[n+1];
lines[index++] = tris[n+2];
lines[index++] = tris[n+2];
lines[index++] = tris[n+0];
}
m.SetIndices(lines, MeshTopology.Lines, i);
}
else
{
m.SetIndices(src.GetIndices(i), src.GetTopology(i), i);
}
}
return m;
}
示例2: InitializeSharedMesh
static void InitializeSharedMesh()
{
sharedMesh = new Mesh ();
sharedMesh.subMeshCount = 2;
var vertices = new Vector3 [4 * 6];
vertices [0] = new Vector3 (-1, +1, -1);
vertices [1] = new Vector3 (+1, +1, -1);
vertices [2] = new Vector3 (+1, -1, -1);
vertices [3] = new Vector3 (-1, -1, -1);
vertices [4] = new Vector3 (+1, +1, -1);
vertices [5] = new Vector3 (+1, +1, +1);
vertices [6] = new Vector3 (+1, -1, +1);
vertices [7] = new Vector3 (+1, -1, -1);
vertices [8] = new Vector3 (+1, +1, +1);
vertices [9] = new Vector3 (-1, +1, +1);
vertices [10] = new Vector3 (-1, -1, +1);
vertices [11] = new Vector3 (+1, -1, +1);
vertices [12] = new Vector3 (-1, +1, +1);
vertices [13] = new Vector3 (-1, +1, -1);
vertices [14] = new Vector3 (-1, -1, -1);
vertices [15] = new Vector3 (-1, -1, +1);
vertices [16] = new Vector3 (-1, +1, +1);
vertices [17] = new Vector3 (+1, +1, +1);
vertices [18] = new Vector3 (+1, +1, -1);
vertices [19] = new Vector3 (-1, +1, -1);
vertices [20] = new Vector3 (-1, -1, -1);
vertices [21] = new Vector3 (+1, -1, -1);
vertices [22] = new Vector3 (+1, -1, +1);
vertices [23] = new Vector3 (-1, -1, +1);
sharedMesh.vertices = vertices;
var indices = new int[vertices.Length];
for (var i = 0; i < indices.Length; i++) {
indices [i] = i;
}
sharedMesh.SetIndices (indices, MeshTopology.Quads, 0);
sharedMesh.Optimize ();
sharedMesh.RecalculateNormals ();
indices = new int[4 * 3 * 2];
var offs = 0;
for (var i1 = 0; i1 < 16; i1 += 4) {
for (var i2 = i1; i2 < i1 + 3; i2++) {
indices [offs++] = i2;
indices [offs++] = i2 + 1;
}
}
sharedMesh.SetIndices (indices, MeshTopology.Lines, 1);
}
示例3: Start
// Use this for initialization
void Start ()
{
CreateLineMaterial();
mesh = new Mesh();
Vertex2[] vertices = new Vertex2[NumberOfVertices];
Vector3[] meshVerts = new Vector3[NumberOfVertices];
int[] indices = new int[NumberOfVertices];
Random.seed = 0;
for (var i = 0; i < NumberOfVertices; i++)
{
vertices[i] = new Vertex2(size * Random.Range(-1.0f, 1.0f), size * Random.Range(-1.0f, 1.0f));
meshVerts[i] = vertices[i].ToVector3();
indices[i] = i;
}
mesh.vertices = meshVerts;
mesh.SetIndices(indices, MeshTopology.Points, 0);
//mesh.bounds = new Bounds(Vector3.zero, new Vector3((float)size,(float)size,(float)size));
float now = Time.realtimeSinceStartup;
voronoiMesh = VoronoiMesh.Create<Vertex2, Cell2>(vertices);
float interval = Time.realtimeSinceStartup - now;
Debug.Log("time = " + interval * 1000.0f);
}
示例4: Start
// Use this for initialization
void Start ()
{
CreateLineMaterial();
mesh = new Mesh();
Vertex2[] vertices = new Vertex2[NumberOfVertices];
Vector3[] meshVerts = new Vector3[NumberOfVertices];
int[] indices = new int[NumberOfVertices];
Random.seed = 0;
for (var i = 0; i < NumberOfVertices; i++)
{
vertices[i] = new Vertex2(size * Random.Range(-1.0f, 1.0f), size * Random.Range(-1.0f, 1.0f));
meshVerts[i] = vertices[i].ToVector3();
indices[i] = i;
}
mesh.vertices = meshVerts;
mesh.SetIndices(indices, MeshTopology.Points, 0);
//mesh.bounds = new Bounds(Vector3.zero, new Vector3((float)size,(float)size,(float)size));
float now = Time.realtimeSinceStartup;
ConvexHull<Vertex2, Face2> convexHull = ConvexHull.Create<Vertex2, Face2>(vertices);
float interval = Time.realtimeSinceStartup - now;
convexHullVertices = new List<Vertex2>(convexHull.Points);
convexHullFaces = new List<Face2>(convexHull.Faces);
Debug.Log("Out of the " + NumberOfVertices + " vertices, there are " + convexHullVertices.Count + " verts on the convex hull.");
Debug.Log("time = " + interval * 1000.0f + " ms");
}
示例5: UpdateLineMesh
public static void UpdateLineMesh(OpticalFlowWorker.AsyncResult r, Mesh mesh, CvPoint2D32f[] velocities, float limitVelocity)
{
var vertices = new Vector3[r.nCorners * 2];
var colors = new Color[vertices.Length];
var indices = new int[vertices.Length];
var limitSqrVelocity = limitVelocity * limitVelocity;
var c0s = r.corners0;
var rTexelSize = new Vector2(1f / r.imageWidth, 1f / r.imageHeight);
for (var i = 0; i < r.nCorners; i++) {
var vertexIndex = 2 * i;
var c0 = c0s[i];
var v0 = new Vector3(c0.X * rTexelSize.x - 0.5f, -(c0.Y * rTexelSize.y - 0.5f), 0f);
var cv = velocities[i];
var v = new Vector3(cv.X * rTexelSize.x, cv.Y * rTexelSize.y, 0f);
var rad = Mathf.Atan2(v.y, v.x);
if (rad < 0)
rad += 2 * Mathf.PI;
var color = HSBColor.ToColor(new HSBColor(rad * R_TWO_PI, 1f, 1f));
if (limitSqrVelocity < v.sqrMagnitude)
v = Vector3.zero;
vertices[vertexIndex] = v0;
vertices[vertexIndex + 1] = v0 + v;
colors[vertexIndex] = color;
colors[vertexIndex + 1] = color;
indices[vertexIndex] = vertexIndex;
indices[vertexIndex + 1] = vertexIndex + 1;
}
mesh.vertices = vertices;
mesh.colors = colors;
mesh.SetIndices(indices, MeshTopology.Lines, 0);
mesh.RecalculateBounds();
}
示例6: Generate
private Mesh Generate()
{
Debug.Assert(starCount < 65536, "Number of stars must less than 65536");
var random = new System.Random(seed);
var mesh = new Mesh();
var vertices = new Vector3[starCount];
var indices = new int[starCount];
var colors = new Color[starCount];
for (var i = 0; i < starCount; ++i)
{
vertices[i] = random.OnUnitSphere();
indices[i] = i;
colors[i] = starColors[random.Next(starColors.Length)];
colors[i].a = (0.2f + 0.8f * MathUtils.NextFloat(random)) * (1 - (Mathf.Abs(vertices[i].y)));
}
mesh.vertices = vertices;
mesh.colors = colors;
mesh.SetIndices(indices, MeshTopology.Points, 0);
return mesh;
}
示例7: CreateLineCircle
public static void CreateLineCircle()
{
Mesh mesh = new Mesh();
Vector3[] vertices = new Vector3[33];
Vector2[] uv = new Vector2[33];
int[] indices = new int[33];
for(int i = 0; i < 33; i++){
float fi = (float)i;
vertices[i] = new Vector3(Mathf.Sin(fi/32f * 2f * Mathf.PI), Mathf.Cos(fi/32f * 2f * Mathf.PI), 0) * 0.5f;
uv[i] = new Vector2(fi/32f, 0);
indices[i] = i;
}
mesh.vertices = vertices;
mesh.normals = vertices;
mesh.uv = uv;
mesh.SetIndices(indices, MeshTopology.LineStrip, 0);
string path = GetCurrentPath() + "LineCircle.asset";
AssetDatabase.CreateAsset(mesh, path);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
Selection.activeObject = AssetDatabase.LoadAssetAtPath(path, typeof(Mesh));
}
示例8: Awake
void Awake()
{
var vertices = new Vector3[(width + 1) * 2 + (height + 1) * 2];
var offs = 0;
for (var h = 0; h <= height; h++) {
vertices [offs++] = new Vector3 (0, h, 0);
vertices [offs++] = new Vector3 (width, h, 0);
}
for (var w = 0; w <= width; w++) {
vertices [offs++] = new Vector3 (w, 0, 0);
vertices [offs++] = new Vector3 (w, height, 0);
}
var indices = new int[(width + 1) * 2 + (height + 1) * 2];
for (var i = 0; i < offs; i++) {
indices [i] = i;
}
var mesh = new Mesh ();
mesh.vertices = vertices;
mesh.SetIndices (indices, MeshTopology.Lines, 0);
GetComponent<MeshFilter> ().mesh = mesh;
}
示例9: make_wireframecircle
void make_wireframecircle()
{
GameObject go = new GameObject ();
go.name = "wireframeCircle";
go.transform.localPosition = new Vector3 (10, 0, 20);
MeshFilter mf = go.AddComponent<MeshFilter> ();
go.AddComponent<MeshRenderer> ();
int[] line_indices = new int[stepCount * 2];
Vector3[] vertices = new Vector3[stepCount];
Vector3 mid = new Vector3(0, 0, 0);
for (int i = 0; i < stepCount; i++)
{
vertices[i] = new Vector3(go.transform.localPosition.x + radius * Mathf.Cos((360.0f / stepCount) * i * 3.14f / 180.0f), go.transform.localPosition.y + radius * Mathf.Sin((360.0f / stepCount) * i * 3.14f / 180.0f), 0);
line_indices[i * 2] = i;
if (i == stepCount - 1)
line_indices[i * 2 + 1] = 0;
else
line_indices[i * 2 + 1] = i + 1;
}
Mesh mesh = new Mesh ();
mesh.vertices = vertices;
mesh.SetIndices (line_indices, MeshTopology.Lines, 0);
mf.mesh = mesh;
}
示例10: BuildMesh
void BuildMesh(ref Mesh mesh, Vector3[] verts, Vector2[] uvs, int[] tris, Color[] colors, Vector3[] normals, int meshCount, bool readRGB, bool readIntensity, bool readNormals, int vertexCount)
{
mesh.subMeshCount = 1;
Vector3[] v = new Vector3[vertexCount];
Vector2[] uv = new Vector2[vertexCount];
Array.Copy(verts, v, vertexCount);
Array.Copy(uvs, uv, vertexCount);
mesh.vertices = v;
mesh.uv = uv;
if (readRGB || readIntensity)
{
Color[] clr = new Color[vertexCount];
Array.Copy(colors, clr, vertexCount);
mesh.colors = clr;
}
if (readNormals)
{
Vector3[] n = new Vector3[vertexCount];
Array.Copy(normals, n, vertexCount);
mesh.normals = n;
}
int[] indices = new int[vertexCount];
Array.Copy(tris, indices, vertexCount);
//mesh.SetTriangles(triangles, 0);
mesh.SetIndices(indices, MeshTopology.Quads, 0);
}
示例11: AddFace
private void AddFace(WaterFace face)
{
// TODO
if ((face.Flags & WaterFlags.Visible) != WaterFlags.Visible) return;
var obj = Instantiate(WaterPrefab);
obj.transform.SetParent(transform);
var mid = obj.transform.position = face.Vertices.Aggregate(Vector3.zero,
(s, x) => s + x.Position) / face.Vertices.Length;
obj.name = string.Format("WaterFace ({0})", mid);
var mesh = new Mesh();
mesh.vertices = face.Vertices.Select(x => x.Position - mid).ToArray();
mesh.normals = face.Vertices.Select(x => Vector3.up).ToArray();
var indices = new int[(face.Vertices.Length - 2) * 3];
for (var i = 0; i < face.Vertices.Length - 2; ++i) {
var flip = i & 1;
indices[i * 3 + 0] = i + 1 - flip;
indices[i * 3 + 1] = i + 0 + flip;
indices[i * 3 + 2] = i + 2;
}
mesh.SetIndices(indices, MeshTopology.Triangles, 0);
obj.GetComponent<MeshFilter>().sharedMesh = mesh;
}
示例12: Start
// Use this for initialization
void Start()
{
var meshMarkers = transform.FindChild("MeshMarkers");
Transform firstChild = null;
var meshFilter = gameObject.AddComponent<MeshFilter>();
Mesh m = new Mesh();
var vertices = new List<Vector3>();
var normals = new List<Vector3>();
foreach (Transform child in meshMarkers) {
if (!firstChild) { firstChild = child;}
vertices.Add(child.position);
normals.Add(new Vector3(0,0,-1));
}
m.SetVertices(vertices);
var indices = new List<int>();
for (int i = 0; i < vertices.Count -2; i++) {
indices.Add(i);
indices.Add(i+1);
indices.Add(i+2);
}
m.SetIndices(indices.ToArray(), MeshTopology.Triangles, 0);
m.SetNormals(normals);
meshFilter.mesh = m;
var pathmarkers = transform.FindChild("PathMarkers");
var tp = from Transform path in pathmarkers select path.position;
var tr = from Transform path in pathmarkers select path.GetComponent<Renderer>();
foreach (var renderer1 in tr) {
renderer1.sortingLayerName = "Middle";
renderer1.material.color = Color.blue;
}
//tracePosList = Curver.MakeSmoothCurve(tp.ToArray(), 6);
tracePosList = tp.ToArray();
GetComponent<MeshRenderer>().sortingLayerName = "Background";
line = new GameObject().AddComponent<LineRenderer>();
line.transform.parent = transform;
line.SetWidth(0.5f,0.5f);
line.material = mat;
line.SetColors(Color.black, Color.black);
trace = new GameObject().AddComponent<LineRenderer>();
trace.transform.parent = transform;
trace.SetWidth(0.5f, 0.5f);
trace.material = mat;
trace.SetColors(Color.red, Color.red);
marble.transform.position = tracePosList[0];
marble.GetComponent<Renderer>().sortingLayerName = "Marble";
marble.GetComponent<MeshRenderer>().material.color = Color.yellow;
}
示例13: Generate
public Mesh Generate(Chunk chunk)
{
var mesh = new Mesh();
var normalsCache = PrecalculateNormals(chunk);
var verts = new Vector3[chunk.BlocksCount * chunk.BlocksCount * 4];
var normals = new Vector3[chunk.BlocksCount * chunk.BlocksCount * 4];
for (int z = 0; z < chunk.BlocksCount; z++)
for (int x = 0; x < chunk.BlocksCount; x++)
{
//Get neighbor chunks to form a tile
var vertIndex = (x + z*chunk.BlocksCount) * 4;
verts[vertIndex] = new Vector3(x * chunk.BlockSize, chunk.HeightMap[x, z], z * chunk.BlockSize);
verts[vertIndex + 1] = new Vector3(x * chunk.BlockSize, chunk.HeightMap[x, z + 1], (z + 1) * chunk.BlockSize);
verts[vertIndex + 2] = new Vector3((x + 1) * chunk.BlockSize, chunk.HeightMap[x + 1, z], z * chunk.BlockSize);
verts[vertIndex + 3] = new Vector3((x + 1) * chunk.BlockSize, chunk.HeightMap[x + 1, z + 1], (z + 1) * chunk.BlockSize);
normals[vertIndex] = normalsCache[x, z];
normals[vertIndex + 1] = normalsCache[x, z + 1];
normals[vertIndex + 2] = normalsCache[x + 1, z];
normals[vertIndex + 3] = normalsCache[x + 1, z + 1];
}
mesh.vertices = verts;
var indx = new int[chunk.BlocksCount * chunk.BlocksCount *4];
for (int z = 0; z < chunk.BlocksCount; z++)
for (int x = 0; x < chunk.BlocksCount; x++)
{
var index = (x + z*chunk.BlocksCount)*4;
indx[index + 0] = index;
indx[index + 1] = index + 1;
indx[index + 2] = index + 3;
indx[index + 3] = index + 2;
}
mesh.SetIndices(indx, MeshTopology.Quads, 0);
var colors = new Color[mesh.vertexCount];
for (int z = 0; z < chunk.BlocksCount; z++)
for (int x = 0; x < chunk.BlocksCount; x++)
{
var block = chunk.BlockType[x, z];
var color = _blocksColors[(int) block];
var index = (x + z * chunk.BlocksCount) * 4;
colors[index + 0] = color;
colors[index + 1] = color;
colors[index + 2] = color;
colors[index + 3] = color;
}
mesh.colors = colors;
mesh.normals = normals;
return mesh;
}
示例14: CreateMeshes
void CreateMeshes()
{
int width = m_depthImage.m_width;
int height = m_depthImage.m_height;
int numPoints = width * height;
int numPointsPerMesh = 20000;
int numMeshes = (numPoints + numPointsPerMesh - 1) / numPointsPerMesh;
Vector3[][] points = new Vector3[numMeshes][];
Vector2[][] uvs = new Vector2[numMeshes][];
int[] indices = Enumerable.Range(0, numPointsPerMesh).ToArray();
for (int i = 0; i < numMeshes; ++i)
{
points[i] = new Vector3[numPointsPerMesh];
uvs[i] = new Vector2[numPointsPerMesh];
}
for (int i = 0; i < numPoints; ++i)
{
int iMesh = i / numPointsPerMesh;
int iIndex = i % numPointsPerMesh;
int xi = i % width;
int yi = i / width;
float x = ((float)xi / width) - 0.5f;
float y = ((float)yi / height) - 0.5f;
float u = (float)xi / width;
float v = (float)yi / height;
points[iMesh][iIndex] = new Vector3(x, y, 0);
uvs[iMesh][iIndex] = new Vector2(u, v);
}
for (int i = 0; i < numMeshes; ++i)
{
GameObject meshObj = GameObject.Instantiate(m_prefPointMesh, transform.position, transform.rotation) as GameObject;
Mesh mesh = new Mesh();
mesh.vertices = points[i];
mesh.uv = uvs[i];
mesh.SetIndices(indices, MeshTopology.Points, 0);
mesh.bounds = new Bounds(Vector3.zero, Vector3.one);
meshObj.transform.parent = this.transform;
meshObj.transform.localScale = Vector3.one;
meshObj.hideFlags |= HideFlags.NotEditable;
meshObj.GetComponent<MeshFilter>().mesh = mesh;
meshObj.GetComponent<Renderer>().material = m_shaderMaterial;
}
}
示例15: Start
void Start()
{
var mesh = new Mesh();
var vertices = MakeVertices();
var indices = MakeIndices();
mesh.vertices = vertices;
mesh.SetIndices( indices, MeshTopology.Quads, 0 );
mesh.name = "TestMesh";
m_meshFilter.mesh = mesh;
}