本文整理汇总了C#中UnityEngine.Mesh.SetVertices方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.SetVertices方法的具体用法?C# Mesh.SetVertices怎么用?C# Mesh.SetVertices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Mesh
的用法示例。
在下文中一共展示了Mesh.SetVertices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: MakeStripped
public static Mesh MakeStripped(List<Vector3> vertices, List<Vector3> normals = null, List<Vector2> uvs = null, List<Color32> colors = null, bool isBacksided = false)
{
Mesh mesh = new Mesh();
mesh.SetVertices(vertices);
if (normals != null)
{
mesh.SetNormals(normals);
}
if (uvs != null)
{
mesh.SetUVs(0, uvs);
}
if (colors != null)
{
mesh.SetColors(colors);
}
List<int> _tris = new List<int>();
for (int i = 1; i < vertices.Count - 1; i += 2)
{
_tris.Add(i);
_tris.Add(i - 1);
_tris.Add(i + 1);
if (isBacksided)
{
_tris.Add(i + 1);
_tris.Add(i - 1);
_tris.Add(i);
}
if (i + 2 < vertices.Count)
{
_tris.Add(i);
_tris.Add(i + 1);
_tris.Add(i + 2);
if (isBacksided)
{
_tris.Add(i + 2);
_tris.Add(i + 1);
_tris.Add(i);
}
}
}
mesh.SetTriangles(_tris, 0);
return mesh;
}
示例3: generateMeshes
private void generateMeshes() {
_cubeMesh = new Mesh();
_cubeMesh.name = "RuntimeGizmoCube";
_cubeMesh.hideFlags = HideFlags.HideAndDontSave;
List<Vector3> verts = new List<Vector3>();
List<int> indexes = new List<int>();
Vector3[] faces = new Vector3[] { Vector3.forward, Vector3.right, Vector3.up };
for (int i = 0; i < 3; i++) {
addQuad(verts, indexes, faces[(i + 0) % 3], -faces[(i + 1) % 3], faces[(i + 2) % 3]);
addQuad(verts, indexes, -faces[(i + 0) % 3], faces[(i + 1) % 3], faces[(i + 2) % 3]);
}
_cubeMesh.SetVertices(verts);
_cubeMesh.SetIndices(indexes.ToArray(), MeshTopology.Quads, 0);
_cubeMesh.RecalculateNormals();
_cubeMesh.RecalculateBounds();
_cubeMesh.UploadMeshData(true);
_wireCubeMesh = new Mesh();
_wireCubeMesh.name = "RuntimeWireCubeMesh";
_wireCubeMesh.hideFlags = HideFlags.HideAndDontSave;
verts.Clear();
indexes.Clear();
for (int dx = 1; dx >= -1; dx -= 2) {
for (int dy = 1; dy >= -1; dy -= 2) {
for (int dz = 1; dz >= -1; dz -= 2) {
verts.Add(0.5f * new Vector3(dx, dy, dz));
}
}
}
addCorner(indexes, 0, 1, 2, 4);
addCorner(indexes, 3, 1, 2, 7);
addCorner(indexes, 5, 1, 4, 7);
addCorner(indexes, 6, 2, 4, 7);
_wireCubeMesh.SetVertices(verts);
_wireCubeMesh.SetIndices(indexes.ToArray(), MeshTopology.Lines, 0);
_wireCubeMesh.RecalculateBounds();
_wireCubeMesh.UploadMeshData(true);
_wireSphereMesh = new Mesh();
_wireSphereMesh.name = "RuntimeWireSphereMesh";
_wireSphereMesh.hideFlags = HideFlags.HideAndDontSave;
verts.Clear();
indexes.Clear();
int totalVerts = CIRCLE_RESOLUTION * 3;
for (int i = 0; i < CIRCLE_RESOLUTION; i++) {
float angle = Mathf.PI * 2 * i / CIRCLE_RESOLUTION;
float dx = 0.5f * Mathf.Cos(angle);
float dy = 0.5f * Mathf.Sin(angle);
for (int j = 0; j < 3; j++) {
indexes.Add((i * 3 + j + 0) % totalVerts);
indexes.Add((i * 3 + j + 3) % totalVerts);
}
verts.Add(new Vector3(dx, dy, 0));
verts.Add(new Vector3(0, dx, dy));
verts.Add(new Vector3(dx, 0, dy));
}
_wireSphereMesh.SetVertices(verts);
_wireSphereMesh.SetIndices(indexes.ToArray(), MeshTopology.Lines, 0);
_wireSphereMesh.RecalculateBounds();
_wireSphereMesh.UploadMeshData(true);
}
示例4: ProcessChunk
public void ProcessChunk(ByteData data, Mesh mesh)
{
if (lookup == null || lookup.GetLength(0) < data.Length*2 + 3)
{
lookup = new IntInt[data.Length*2 + 3, data.Length*2 + 3, data.Length*2 + 3];
}
lookupVersion++;
vertices.Clear();
normals.Clear();
triangles.Clear();
colors.Clear();
counters.Clear();
for (int x = -1; x < data.Length; x++)
{
for (int y = -1; y < data.Length; y++)
{
for (int z = -1; z < data.Length; z++)
{
int configuration = 0;
byte target = 1;
//for (int i = 0; i < 8; i++)
//{
// byte val = data[x + vertexOffset[i, 0], y + vertexOffset[i, 1], z + vertexOffset[i, 2]];
// if (val > target)
// {
// target = val;
// }
//}
int blend = 1;
var color = new Color32();
for (int i = 0; i < 8; i++)
{
byte val = data[x + vertexOffset[i, 0], y + vertexOffset[i, 1], z + vertexOffset[i, 2]];
if (val <= target)
{
configuration |= 1 << i;
}
if (val > target)
{
color = Color32.Lerp(color, colorMap[val], 1f/blend);
blend++;
}
}
if (configuration > 0 && configuration < 255)
{
ProcessCube((byte) configuration, new Vector3(x, y, z), color, x < 0 || y < 0 || z < 0);
}
}
}
}
mesh.Clear();
mesh.SetVertices(vertices);
if (SMOOTH)
{
for (int i = 0; i < vertices.Count; i++)
{
normals.Add(compositeNormals[i].Normal);
}
}
mesh.SetNormals(normals);
mesh.SetColors(colors);
mesh.SetTriangles(triangles, 0);
}
示例5: Update
//.........这里部分代码省略.........
// Ensure ordering
if (Vector3.Dot(Vector3.Cross(verts[i1] - verts[i0], verts[i2] - verts[i0]), vert0) < 0f)
{
int tmp = i1;
i1 = i3;
i3 = tmp;
}
edgeTris.AddRange(new int[] { i0, i1, i2, i0, i2, i3 });
// Normal
Vector3 normal = 0.5f * (vert0 + vert1);
normal.Normalize();
normals.AddRange(new Vector3[] { normal, normal, normal, normal });
// The UVs encode the sampling plane normals.
Vector2 uv0 = encodeNormalToUV(midPoint0.normalized);
Vector2 uv1 = encodeNormalToUV(midPoint1.normalized);
uvNormal0.AddRange(new Vector2[] { uv0, uv0, uv0, uv0 });
uvNormal1.AddRange(new Vector2[] { uv1, uv1, uv1, uv1 });
uvNormal2.AddRange(new Vector2[] { Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero });
// Blend weights are stored in the color channel
Color c0 = new Color(1f, 0f, 0f);
Color c1 = new Color(0f, 1f, 0f);
colors.AddRange(new Color[] { c0, c1, c1, c0 });
}
// Compute the bevelled vertices.
// Those have three blend weights.
List<int> vertTris = new List<int>(20 * 3);
for (int i=0; i<20; i++)
{
Vector3 normal = rawVerts[i].normalized;
// The UVs encode the sampling plane normals.
Vector2 uv0 = encodeNormalToUV(faceMidPoints[vertFaceIndices[i, 0]].normalized);
Vector2 uv1 = encodeNormalToUV(faceMidPoints[vertFaceIndices[i, 1]].normalized);
Vector2 uv2 = encodeNormalToUV(faceMidPoints[vertFaceIndices[i, 2]].normalized);
for (int j=0; j<3; j++)
{
int faceIdx = vertFaceIndices[i, j];
Vector3 faceMidPoint = faceMidPoints[faceIdx];
Vector3 beveledVertexPosition = faceMidPoint + (1f - bevel) * (rawVerts[i] - faceMidPoint);
verts.Add(beveledVertexPosition);
normals.Add(normal);
uvNormal0.Add(uv0);
uvNormal1.Add(uv1);
uvNormal2.Add(uv2);
}
// Blend weights are stored in the color channel.
colors.Add(new Color(1f, 0f, 0f));
colors.Add(new Color(0f, 1f, 0f));
colors.Add(new Color(0f, 0f, 1f));
// Indices
int i0 = verts.Count - 3;
int i1 = verts.Count - 2;
int i2 = verts.Count - 1;
// Ensure ordering
if (Vector3.Dot (Vector3.Cross(verts[i1] - verts[i0], verts[i2] - verts[i0]), rawVerts[i]) < 0)
{
int tmp = i1;
i1 = i2;
i2 = tmp;
}
vertTris.AddRange(new int[] { i0, i1, i2 });
}
// Finish setting up the mesh.
mesh.SetVertices(verts);
mesh.SetNormals(normals);
mesh.SetColors(colors);
mesh.SetUVs(0, uvNormal0);
mesh.SetUVs(1, uvNormal1);
mesh.SetUVs(2, uvNormal2);
// There are three sub-meshes: Face faces, edge faces, and vertex faces.
mesh.subMeshCount = 3;
mesh.SetTriangles(faceTris, 0);
mesh.SetTriangles(edgeTris, 1);
mesh.SetTriangles(vertTris, 2);
// If there is a mesh filter component, apply the mesh.
var meshFilter = GetComponent<MeshFilter>();
if (meshFilter)
meshFilter.sharedMesh = mesh;
}
}
示例6: FillMesh
public void FillMesh(Mesh mesh)
{
mesh.Clear();
mesh.SetVertices(this.m_Positions);
mesh.SetColors(this.m_Colors);
mesh.SetUVs(0, this.m_Uv0S);
mesh.SetUVs(1, this.m_Uv1S);
mesh.SetNormals(this.m_Normals);
mesh.SetTangents(this.m_Tangents);
mesh.SetTriangles(this.m_Indicies, 0);
mesh.RecalculateBounds();
}
示例7: ToMesh
/// <summary>
/// Creates new mesh from information in draft
/// </summary>
public Mesh ToMesh()
{
var mesh = new Mesh {name = name};
mesh.SetVertices(vertices);
mesh.SetTriangles(triangles, 0);
mesh.SetNormals(normals);
mesh.SetUVs(0, uv);
mesh.SetColors(colors);
return mesh;
}
示例8: BakeMesh
private Mesh BakeMesh(InstanceData[] instances)
{
if (meshFilter == null)
{
meshFilter = GetComponent<MeshFilter>();
}
Mesh mesh = new Mesh();
var meshVertices = meshFilter.sharedMesh.vertices;
var meshUVs = meshFilter.sharedMesh.uv;
var indices = meshFilter.sharedMesh.GetIndices(0);
var normals = meshFilter.sharedMesh.normals;
var vertexData = new List<Vector3>();
var normalData = new List<Vector3>();
var uv0Data = new List<Vector2>();
for (int instanceIdx = 0; instanceIdx < instances.Length; instanceIdx++)
{
var scale = Vector3.Lerp(minScale, maxScale, UnityEngine.Random.value);
var cur = instances[instanceIdx];
var instancePos = new Vector3(Mathf.Cos(cur.startAngle), cur.verticalOffset, Mathf.Sin(cur.startAngle)) * cur.ringRadius;
var instanceRotation = Quaternion.AngleAxis(UnityEngine.Random.value * 360, UnityEngine.Random.insideUnitSphere);
vertexData.AddRange(meshVertices.Select(v => instancePos + instanceRotation * (new Vector3(v.x * scale.x, v.y * scale.y, v.z * scale.z) * meshScale)));
normalData.AddRange(normals.Select(v => Vector3.Normalize(instanceRotation * new Vector3(v.x * scale.x, v.y * scale.y, v.z * scale.z) * meshScale)));
uv0Data.AddRange(meshUVs);
}
mesh.SetVertices(vertexData);
mesh.SetIndices(Enumerable.Range(0, instances.Length).SelectMany(i => indices.Select(vi => i * meshVertices.Length + vi)).ToArray(), MeshTopology.Triangles, 0);
mesh.SetUVs(0, uv0Data);
mesh.SetNormals(normalData);
mesh.RecalculateNormals();
mesh.RecalculateBounds();
mesh.Optimize();
return mesh;
}
示例9: generateMengerMesh
private Mesh generateMengerMesh(int lod)
{
Mesh mesh = new Mesh();
mesh.name = "MengerMesh";
int size = Mathf.RoundToInt(Mathf.Pow(3, _subMeshLod));
bool[,,] _isFilled = new bool[size, size, size];
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
for (int z = 0; z < size; z++) {
if (isSpaceFilled(x, y, z, size / 3)) {
_isFilled[x, y, z] = true;
}
}
}
}
List<Vector3> verts = new List<Vector3>();
List<int> tris = new List<int>();
float quadRadius = 0.5f / size;
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
for (int z = 0; z < size; z++) {
if (_isFilled[x, y, z]) {
Vector3 position = new Vector3(x, y, z) / size + Vector3.one * quadRadius - Vector3.one * 0.5f;
if (x == 0 || !_isFilled[x - 1, y, z]) {
addQuad(verts, tris, position + Vector3.left * quadRadius, Vector3.forward, Vector3.up, quadRadius);
}
if (x == size - 1 || !_isFilled[x + 1, y, z]) {
addQuad(verts, tris, position + Vector3.right * quadRadius, Vector3.up, Vector3.forward, quadRadius);
}
if (y == 0 || !_isFilled[x, y - 1, z]) {
addQuad(verts, tris, position + Vector3.down * quadRadius, Vector3.right, Vector3.forward, quadRadius);
}
if (y == size - 1 || !_isFilled[x, y + 1, z]) {
addQuad(verts, tris, position + Vector3.up * quadRadius, Vector3.forward, Vector3.right, quadRadius);
}
if (z == 0 || !_isFilled[x, y, z - 1]) {
addQuad(verts, tris, position + Vector3.back * quadRadius, Vector3.up, Vector3.right, quadRadius);
}
if (z == size - 1 || !_isFilled[x, y, z + 1]) {
addQuad(verts, tris, position + Vector3.forward * quadRadius, Vector3.right, Vector3.up, quadRadius);
}
}
}
}
}
List<Vector2> uvs = new List<Vector2>();
for (int i = 0; i < verts.Count; i++) {
uvs.Add(verts[i]);
}
mesh.SetVertices(verts);
mesh.SetUVs(0, uvs);
mesh.SetIndices(tris.ToArray(), MeshTopology.Triangles, 0);
mesh.RecalculateNormals();
mesh.RecalculateBounds();
;
mesh.UploadMeshData(true);
return mesh;
}
示例10: FillMesh
protected void FillMesh(Mesh mesh)
{
mesh.Clear();
if (positions.Count > 65000)
throw new System.ArgumentException("Mesh cannot have more than 65000 vertices."); // Limitation based on UnityEngine.UI.VertexHelper
mesh.SetVertices(positions);
//mesh.SetColors(colors); // 5.3 mesh.SetColors(Color) is broken in UI.
mesh.SetColors(colors32);
mesh.SetUVs(0, uvs);
mesh.SetNormals(normals);
mesh.SetTriangles(indices, 0);
mesh.RecalculateBounds();
}
示例11: GetBuffers
/// <summary>
/// Put mesh buffer data to mesh.
/// </summary>
/// <param name="mesh">Mesh.</param>
/// <param name="recalculateBounds">Are mesh bounds should be recalculated.</param>
public static void GetBuffers(Mesh mesh, bool recalculateBounds = true)
{
if (mesh != null) {
mesh.Clear (true);
if (_cacheV.Count <= 65535) {
mesh.SetVertices (_cacheV);
mesh.SetUVs (0, _cacheUV);
mesh.SetColors (_cacheC);
mesh.SetTriangles (_cacheT, 0);
} else {
Debug.LogWarning ("Too many vertices", mesh);
}
if (recalculateBounds) {
mesh.RecalculateBounds ();
}
}
}
示例12: Start
//.........这里部分代码省略.........
List<int> trianglesIndices = new List<int>() {
0, 9, 5,//triangles around point 0
0, 5, 3,
0, 3, 4,
0, 4, 8,
0, 8, 9,
2, 10, 6,//triangles around point 2
2, 6, 1,
2, 1, 7,
2, 7, 11,
2, 11, 10,
3, 10, 11,//triangles between ends
3, 11, 4,
4, 11, 7,
4, 7, 8,
8, 7, 1,
8, 1, 9,
9, 1, 6,
9, 6, 5,
5, 6, 10,
5, 10, 3};
//Triangle smoothing loop, each loop quadruples the number of faces
for (int i = 0; i < smoothLevel; i++)
{
List<Vector3> newVertices = new List<Vector3>();//these lists will overwrite the previous vertices & triangles
List<int> newTriangleIndices = new List<int>();
for (int j = 0; j < trianglesIndices.Count; j += 3)//every set of three indices is a distinct triangle
{
int sm = j * 2;//start multiplier
Vector3 vertexZero = SetVectorDist (faceMesh.vertices[trianglesIndices[j ]], origin, radius);
Vector3 vertexOne = SetVectorDist (faceMesh.vertices[trianglesIndices[j + 1]], origin, radius);
Vector3 vertexTwo = SetVectorDist (faceMesh.vertices[trianglesIndices[j + 2]], origin, radius);
Vector3 vertexThree = SetVectorDist (GetMidpoint(vertexZero, vertexOne), origin, radius);//get the midpoints of the three sides
Vector3 vertexFour = SetVectorDist (GetMidpoint(vertexOne, vertexTwo), origin, radius);
Vector3 vertexFive = SetVectorDist (GetMidpoint(vertexTwo, vertexZero), origin, radius);
newVertices.AddRange(new[] {//adds the six new vertices to the list
vertexZero,
vertexOne,
vertexTwo,
vertexThree,
vertexFour,
vertexFive
});
newTriangleIndices.AddRange(new[] {//arranges the vertices to create four new triangles in place of the starting triangle
0+sm,3+sm,5+sm,
3+sm,1+sm,4+sm,
5+sm,4+sm,2+sm,
5+sm,3+sm,4+sm});
}
faceMesh.vertices = newVertices.ToArray();//replace the previous set of vertices with the smoothed one
trianglesIndices = newTriangleIndices;
faceMesh.triangles = trianglesIndices.ToArray();
}
//Mesh mutation, based on some basic facial proportions
List<Vector3> overwriteVertices = new List<Vector3>();
for (int i = 0; i < faceMesh.vertices.Length; i++) {
Vector3 overwriteVertex = faceMesh.vertices[i];
if (overwriteVertex.y >= 0){//shaping the upper half of the face
//overwriteVertex.y += gr*0.3f;
}
if (overwriteVertex.y < 0) {//shaping the lower half of the face
overwriteVertex.x += (overwriteVertex.y * -0.25f);
overwriteVertex.y *= 1.4f;
}
overwriteVertex.z *= 0.9f;
overwriteVertices.Add(overwriteVertex);
}
faceMesh.SetVertices(overwriteVertices);
//Add some eyes
AddeEyes(Face, faceMesh);
//Set Colour
Material material = new Material(Shader.Find("Standard"));
Color fleshtone = new Color(10, 205, 180);
material.SetColor("fleshtone", fleshtone);
Face.GetComponent<Renderer>().material = material;
/*Color32[] meshColor = new Color32[faceMesh.triangles.Length];
for (int i = 0; i < meshColor.Length; i++) {
meshColor[i] = fleshtone;
}*/
faceMesh.RecalculateBounds();
faceMesh.RecalculateNormals();
faceMesh.Optimize();
MeshCollider meshCollider = gameObject.AddComponent(typeof(MeshCollider)) as MeshCollider;
}
示例13: OnPopulateMesh
//.........这里部分代码省略.........
var fpsStep = -1;
var maxFrameTime = FloatingScale ? CalculateMaxFrameTime() : 1f/targetFps;
if (FloatingScale)
{
for (var i = 0; i < ScaleSteps.Length; i++)
{
var step = ScaleSteps[i];
if (maxFrameTime < step*1.1f)
{
maxValue = step;
fpsStep = i;
break;
}
}
// Fall back on the largest one
if (fpsStep < 0)
{
fpsStep = ScaleSteps.Length - 1;
maxValue = ScaleSteps[fpsStep];
}
}
else
{
// Search for the next scale step after the user-provided step
for (var i = 0; i < ScaleSteps.Length; i++)
{
var step = ScaleSteps[i];
if (maxFrameTime > step)
{
fpsStep = i;
}
}
}
var verticalScale = (graphHeight - (VerticalPadding*2))/maxValue;
// Number of data points that can fit into the graph space
var availableDataPoints = CalculateVisibleDataPointCount();
// Reallocate vertex array if insufficient length (or not yet created)
var sampleCount = GetFrameBufferCurrentSize();
for (var i = 0; i < sampleCount; i++)
{
// Break loop if all visible data points have been drawn
if (i >= availableDataPoints)
{
break;
}
// When using right-alignment, read from the end of the profiler buffer
var frame = GetFrame(sampleCount - i - 1);
// Left-hand x coord
var lx = graphWidth - DataPointWidth*i - DataPointWidth - graphWidth/2f;
DrawDataPoint(lx, verticalScale, frame);
}
if (DrawAxes)
{
if (!FloatingScale)
{
DrawAxis(maxValue, maxValue*verticalScale, GetAxisLabel(0));
}
var axisCount = 2;
var j = 0;
if (!FloatingScale)
{
j++;
}
for (var i = fpsStep; i >= 0; --i)
{
if (j >= axisCount)
{
break;
}
DrawAxis(ScaleSteps[i], ScaleSteps[i]*verticalScale, GetAxisLabel(j));
++j;
}
}
#if !LEGACY_UI
m.Clear();
m.SetVertices(_meshVertices);
m.SetColors(_meshVertexColors);
m.SetTriangles(_meshTriangles, 0);
#endif
}
示例14: SetVertices
public void SetVertices(UIVertex[] vertices, int size)
{
Mesh mesh = new Mesh();
List<Vector3> inVertices = new List<Vector3>();
List<Color32> inColors = new List<Color32>();
List<Vector2> uvs1 = new List<Vector2>();
List<Vector2> uvs2 = new List<Vector2>();
List<Vector3> inNormals = new List<Vector3>();
List<Vector4> inTangents = new List<Vector4>();
List<int> intList = new List<int>();
int num = 0;
while (num < size)
{
for (int index = 0; index < 4; ++index)
{
inVertices.Add(vertices[num + index].position);
inColors.Add(vertices[num + index].color);
uvs1.Add(vertices[num + index].uv0);
uvs2.Add(vertices[num + index].uv1);
inNormals.Add(vertices[num + index].normal);
inTangents.Add(vertices[num + index].tangent);
}
intList.Add(num);
intList.Add(num + 1);
intList.Add(num + 2);
intList.Add(num + 2);
intList.Add(num + 3);
intList.Add(num);
num += 4;
}
mesh.SetVertices(inVertices);
mesh.SetColors(inColors);
mesh.SetNormals(inNormals);
mesh.SetTangents(inTangents);
mesh.SetUVs(0, uvs1);
mesh.SetUVs(1, uvs2);
mesh.SetIndices(intList.ToArray(), MeshTopology.Triangles, 0);
this.SetMesh(mesh);
Object.DestroyImmediate((Object) mesh);
}
示例15: CutObject
//.........这里部分代码省略.........
tmpIntersectionUv);
// add intersection point into overall buffers
tmpLowerHull.AddRange(tmpIntersectionPt);
tmpUpperHull.AddRange(tmpIntersectionPt);
tmpLowerHullUV.AddRange(tmpIntersectionUv);
tmpUpperHullUV.AddRange(tmpIntersectionUv);
closingHull.AddRange(tmpIntersectionPt);
// triangulate the temporary buffers and get the indices
Triangulator.TriangulateNDSlice(tmpLowerHull, tmpLowerIndices, lowerHull.Count);
Triangulator.TriangulateNDSlice(tmpUpperHull, tmpUpperIndices, upperHull.Count);
// add to the final buffers
upperHull.AddRange(tmpUpperHull);
lowerHull.AddRange(tmpLowerHull);
upperIndices.AddRange(tmpUpperIndices);
lowerIndices.AddRange(tmpLowerIndices);
upperUV.AddRange(tmpUpperHullUV);
lowerUV.AddRange(tmpLowerHullUV);
}
List<Vector3> finalClosingHull = new List<Vector3>();
// generate the closing hull (if any)
if (closingHull.Count > 0) {
Triangulator.TriangulateHullPt(closingHull, finalClosingHull, closingHullIndices, closingHullUV, plane.Normal);
}
if (upperIndices.Count > 0) {
Mesh newMesh = new Mesh();
newMesh.subMeshCount = 2;
// close the hull
int count = upperHull.Count;
upperHull.AddRange(finalClosingHull);
upperUV.AddRange(closingHullUV);
newMesh.SetVertices(upperHull);
newMesh.SetTriangles(upperIndices, 0);
newMesh.SetUVs(0, upperUV);
// set the closing hull UV's
int triCount = closingHullIndices.Count;
if (triCount > 0) {
List<int> finalTriangles = new List<int>();
for (int i = 0; i < triCount; i += 3) {
finalTriangles.Add(closingHullIndices[i] + count);
finalTriangles.Add(closingHullIndices[i + 2] + count);
finalTriangles.Add(closingHullIndices[i + 1] + count);
}
newMesh.SetTriangles(finalTriangles, 1);
}
newMesh.RecalculateNormals();
newMeshes.Add(newMesh);
}
if (lowerIndices.Count > 0) {
Mesh newMesh = new Mesh();
newMesh.subMeshCount = 2;
// close the hull
int count = lowerHull.Count;
lowerHull.AddRange(finalClosingHull);
lowerUV.AddRange(closingHullUV);
newMesh.SetVertices(lowerHull);
newMesh.SetTriangles(lowerIndices, 0);
newMesh.SetUVs(0, lowerUV);
// set the closing hull UV's
int triCount = closingHullIndices.Count;
if (triCount > 0) {
List<int> finalTriangles = new List<int>();
for (int i = 0; i < triCount; i += 3) {
finalTriangles.Add(closingHullIndices[i] + count);
finalTriangles.Add(closingHullIndices[i + 1] + count);
finalTriangles.Add(closingHullIndices[i + 2] + count);
}
newMesh.SetTriangles(finalTriangles, 1);
}
newMesh.RecalculateNormals();
newMeshes.Add(newMesh);
}
return newMeshes;
}