本文整理汇总了C#中UnityEngine.Mesh.SetColors方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.SetColors方法的具体用法?C# Mesh.SetColors怎么用?C# Mesh.SetColors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Mesh
的用法示例。
在下文中一共展示了Mesh.SetColors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModifyMesh
public override void ModifyMesh(Mesh mesh)
{
if (!IsActive()) { return; }
if (mesh == null || mesh.vertexCount <= 0) return;
int count = mesh.vertexCount;
float bottomY = mesh.vertices[0].y;
float topY = mesh.vertices[0].y;
for (int i = 1; i < count; i++)
{
float y = mesh.vertices[i].y;
if (y > topY)
{
topY = y;
}
else if (y < bottomY)
{
bottomY = y;
}
}
float uiElementHeight = topY - bottomY;
List<Color32> newClr = new List<Color32>();
for (int i = 0; i < count; i++)
{
newClr.Add(Color32.Lerp(_bottomColor, _topColor, (mesh.vertices[i].y - bottomY) / uiElementHeight));
}
mesh.SetColors(newClr);
}
示例2: ModifyMesh
public override void ModifyMesh(Mesh mesh)
{
if (!IsActive())
{
return;
}
Vector3[] vertexList = mesh.vertices;
int count = mesh.vertexCount;
if (count > 0)
{
float bottomY = vertexList[0].y;
float topY = vertexList[0].y;
for (int i = 1; i < count; i++)
{
float y = vertexList[i].y;
if (y > topY)
{
topY = y;
}
else if (y < bottomY)
{
bottomY = y;
}
}
List<Color32> colors = new List<Color32>();
float uiElementHeight = topY - bottomY;
for (int i = 0; i < count; i++)
{
colors.Add(Color32.Lerp(bottomColor, topColor, (vertexList[i].y - bottomY) / uiElementHeight));
}
mesh.SetColors(colors);
}
}
示例3: 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;
}
示例4: 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> uvs = new List<Vector2>();
List<Vector2> list4 = new List<Vector2>();
List<Vector3> inNormals = new List<Vector3>();
List<Vector4> inTangents = new List<Vector4>();
List<int> list7 = new List<int>();
for (int i = 0; i < size; i += 4)
{
for (int j = 0; j < 4; j++)
{
inVertices.Add(vertices[i + j].position);
inColors.Add(vertices[i + j].color);
uvs.Add(vertices[i + j].uv0);
list4.Add(vertices[i + j].uv1);
inNormals.Add(vertices[i + j].normal);
inTangents.Add(vertices[i + j].tangent);
}
list7.Add(i);
list7.Add(i + 1);
list7.Add(i + 2);
list7.Add(i + 2);
list7.Add(i + 3);
list7.Add(i);
}
mesh.SetVertices(inVertices);
mesh.SetColors(inColors);
mesh.SetNormals(inNormals);
mesh.SetTangents(inTangents);
mesh.SetUVs(0, uvs);
mesh.SetUVs(1, list4);
mesh.SetIndices(list7.ToArray(), MeshTopology.Triangles, 0);
this.SetMesh(mesh);
UnityEngine.Object.DestroyImmediate(mesh);
}
示例5: 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);
}
示例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: 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);
}
示例8: 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;
}
}
示例9: 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;
}
示例10: GenerateSides
//.........这里部分代码省略.........
faces.Add(i * 4 + 1);
faces.Add(i * 4 + 5);
faces.Add(i * 4 + 3);
faces.Add(i * 4 + 3);
faces.Add(i * 4 + 5);
faces.Add(i * 4 + 7);
}
// Generate a bit of floor
mesh = new Mesh();
mesh.Clear();
mesh.SetVertices(vertices);
mesh.SetTriangles(faces, 0);
mesh.RecalculateNormals();
mf = (MeshFilter)this._side.gameObject.GetComponent(typeof(MeshFilter));
mr = (MeshRenderer)this._side.gameObject.GetComponent(typeof(MeshRenderer));
mf.mesh.Clear();
mf.mesh = mesh;
this._side.transform.parent = parent;
this._other.Add(this._side);
//dirtObject = ObjectPool.ObjectPool.GetInstance().GetObject(ObjectPool.GameObjectType.Dirt);
//dirtObject = GameObject.Instantiate(dirtObject);
vertices = new List<Vector3>();
faces = new List<int>();
List<Color> colors = new List<Color>();
int sideSize = 50;
if (this._last != null)
{
vertices.AddRange(this._last._lastTopData);
amountToDo = 6;
}
for (int i = 0; i < 5; i++)
{
vertices.Add(new Vector3(this.GetPivit(i, true) - 5, 1, this._zPos + i * 2));
vertices.Add(new Vector3(this.GetPivit(i, false) + 5, 1, this._zPos + i * 2));
vertices.Add(new Vector3(low - 1 - sideSize, 5, this._zPos + i * 2));
vertices.Add(new Vector3(high + 1 + sideSize, 5, this._zPos + i * 2));
}
// Add vertices at the end, so the next stroke can connect to it
vertices.Add(new Vector3(this.GetPivit(4, true) - 5, 1, this._zPos + 4 * 2 + 1));
vertices.Add(new Vector3(this.GetPivit(4, false) + 5, 1, this._zPos + 4 * 2 + 1));
vertices.Add(new Vector3(low - 1 - sideSize, 5, this._zPos + 4 * 2 + 1));
vertices.Add(new Vector3(high + 1 + sideSize, 5, this._zPos + 4 * 2 + 1));
this._lastTopData = vertices.GetRange(vertices.Count - 4, 4);
for (int i = 0; i < amountToDo; i++)
{
faces.Add(i * 4);
faces.Add(i * 4 + 2);
faces.Add(i * 4 + 6);
faces.Add(i * 4);
faces.Add(i * 4 + 6);
faces.Add(i * 4 + 4);
faces.Add(i * 4 + 1);
faces.Add(i * 4 + 5);
faces.Add(i * 4 + 3);
faces.Add(i * 4 + 3);
faces.Add(i * 4 + 5);
faces.Add(i * 4 + 7);
}
// Generate a bit of floor
mesh = new Mesh();
mesh.Clear();
mesh.SetVertices(vertices);
mesh.SetColors(colors);
mesh.SetTriangles(faces, 0);
mesh.RecalculateNormals();
mf = (MeshFilter)this._top.gameObject.GetComponent(typeof(MeshFilter));
mr = (MeshRenderer)this._top.gameObject.GetComponent(typeof(MeshRenderer));
mf.mesh.Clear();
mf.mesh = mesh;
this._top.transform.parent = parent;
this._other.Add(this._top);
}
示例11: 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();
}
示例12: 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 ();
}
}
}
示例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: FillMesh
/// <summary>
/// <para>Fill the given mesh with the stream data.</para>
/// </summary>
/// <param name="mesh"></param>
public void FillMesh(Mesh mesh)
{
mesh.Clear();
if (this.m_Positions.Count >= 0xfde8)
{
throw new ArgumentException("Mesh can not have more than 65000 vertices");
}
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_Indices, 0);
mesh.RecalculateBounds();
}
示例15: CreateNavmeshOutlineVisualization
//.........这里部分代码省略.........
// Loop throgh neighbours to figure
// out which edges are shared
if (other != null && other.GraphIndex == node.GraphIndex) {
for (int v = 0; v < 3; v++) {
for (int v2 = 0; v2 < 3; v2++) {
if (node.GetVertexIndex(v) == other.GetVertexIndex((v2+1)%3) && node.GetVertexIndex((v+1)%3) == other.GetVertexIndex(v2)) {
// Found a shared edge with the other node
sharedEdges[v] = true;
v = 3;
break;
}
}
}
}
}
for (int v = 0; v < 3; v++) {
if (!sharedEdges[v]) {
edgeList.Add(node.GetVertex(v));
edgeList.Add(node.GetVertex((v+1)%3));
var color = (Color32)AstarColor.GetAreaColor(node.Area);
colorList.Add(color);
colorList.Add(color);
}
}
}
// Use pooled lists to avoid excessive allocations
var vertices = ListPool<Vector3>.Claim(edgeList.Count*2);
var colors = ListPool<Color32>.Claim(edgeList.Count*2);
var normals = ListPool<Vector3>.Claim(edgeList.Count*2);
var tris = ListPool<int>.Claim(edgeList.Count*3);
// Loop through each endpoint of the lines
// and add 2 vertices for each
for (int j = 0; j < edgeList.Count; j++) {
var vertex = (Vector3)edgeList[j];
vertices.Add(vertex);
vertices.Add(vertex);
// Encode the side of the line
// in the alpha component
var color = colorList[j];
colors.Add(new Color32(color.r, color.g, color.b, 0));
colors.Add(new Color32(color.r, color.g, color.b, 255));
}
// Loop through each line and add
// one normal for each vertex
for (int j = 0; j < edgeList.Count; j += 2) {
var lineDir = (Vector3)(edgeList[j+1] - edgeList[j]);
lineDir.Normalize();
// Store the line direction in the normals
// A line consists of 4 vertices
// The line direction will be used to
// offset the vertices to create a
// line with a fixed pixel thickness
normals.Add(lineDir);
normals.Add(lineDir);
normals.Add(lineDir);
normals.Add(lineDir);
}
// Setup triangle indices
// A triangle consists of 3 indices
// A line (4 vertices) consists of 2 triangles, so 6 triangle indices
for (int j = 0, v = 0; j < edgeList.Count*3; j += 6, v += 4) {
// First triangle
tris.Add(v+0);
tris.Add(v+1);
tris.Add(v+2);
// Second triangle
tris.Add(v+1);
tris.Add(v+3);
tris.Add(v+2);
}
// Set all data on the mesh
mesh.SetVertices(vertices);
mesh.SetTriangles(tris, 0);
mesh.SetColors(colors);
mesh.SetNormals(normals);
// Upload all data and mark the mesh as unreadable
mesh.UploadMeshData(true);
// Release the lists back to the pool
ListPool<Color32>.Release(colorList);
ListPool<Int3>.Release(edgeList);
ListPool<Vector3>.Release(vertices);
ListPool<Color32>.Release(colors);
ListPool<Vector3>.Release(normals);
ListPool<int>.Release(tris);
return mesh;
}