本文整理汇总了C#中Mesh.SetIndices方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.SetIndices方法的具体用法?C# Mesh.SetIndices怎么用?C# Mesh.SetIndices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mesh
的用法示例。
在下文中一共展示了Mesh.SetIndices方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnUpdate
public void OnUpdate()
{
if (mesh)
{
mesh.Dispose();
}
Rect rect = rectTransform.rect;
positionVboData[0] = new Vector3f((float)rect.min.X, (float)rect.min.Y, 0);
positionVboData[1] = new Vector3f((float)rect.min.X, (float)rect.max.Y, 0);
positionVboData[2] = new Vector3f((float)rect.max.X, (float)rect.max.Y, 0);
positionVboData[3] = new Vector3f((float)rect.max.X, (float)rect.min.Y, 0);
mesh = new Mesh();
mesh.AddBuffer<VertexBufferObject3f>("vertex");
mesh.SetBuffer3f("vertex", positionVboData);
mesh.AddBuffer<VertexBufferObject3f>("normal");
mesh.SetBuffer3f("normal", normalVboData);
mesh.AddBuffer<VertexBufferObject2f>("uv0");
mesh.SetBuffer2f("uv0", uvVboData);
mesh.SetIndices(indicesVboData, 0, Graphics.PrimitiveType.Triangles);
MeshRenderer meshRenderer = sceneObject.GetModule<MeshRenderer>();
if (meshRenderer)
{
meshRenderer.mesh = mesh;
}
}
示例2: OnUpdate
public void OnUpdate()
{
//base.OnInitialize();
string text = "Test text! "+Engine.current.deltaTime;
Font font = new Font("Verdana", 12, FontStyle.Regular, GraphicsUnit.Point);
Bitmap measureBitmap = new Bitmap(2, 2);
Bitmap bitmap = null;
System.Drawing.Graphics measureGraphics = System.Drawing.Graphics.FromImage(measureBitmap);
measureGraphics.PageUnit = GraphicsUnit.Pixel;
measureGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
measureGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
SizeF size = measureGraphics.MeasureString(text, font);
measureGraphics.Dispose();
measureBitmap.Dispose();
bitmap = new Bitmap((int)size.Width, (int)size.Height);
System.Drawing.Graphics drawGraphics = System.Drawing.Graphics.FromImage(bitmap);
drawGraphics.PageUnit = GraphicsUnit.Pixel;
drawGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
drawGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
drawGraphics.Clear(System.Drawing.Color.FromArgb(255, 0, 0, 0));
drawGraphics.DrawString(text, font, new SolidBrush(System.Drawing.Color.White), 0, 0);
drawGraphics.Dispose();
if (texture)
{
texture.Dispose();
}
texture = new Texture2D(bitmap, false, Texture2D.MemoryResidence.GPU);
bitmap.Dispose();
if (mesh)
{
mesh.Dispose();
}
positionVboData[0] = new Vector3f(0, 0, 0);
positionVboData[1] = new Vector3f(0, texture.height, 0);
positionVboData[2] = new Vector3f(texture.width, texture.height, 0);
positionVboData[3] = new Vector3f(texture.width, 0, 0);
mesh = new Mesh();
mesh.AddBuffer<VertexBufferObject3f>("vertex");
mesh.SetBuffer3f("vertex", positionVboData);
mesh.AddBuffer<VertexBufferObject3f>("normal");
mesh.SetBuffer3f("normal", normalVboData);
mesh.AddBuffer<VertexBufferObject2f>("uv0");
mesh.SetBuffer2f("uv0", uvVboData);
mesh.SetIndices(indicesVboData, 0, Graphics.PrimitiveType.Triangles);
MeshRenderer meshRenderer = sceneObject.GetModule<MeshRenderer>();
if (meshRenderer)
{
MaterialProperties properties = new MaterialProperties();
MaterialPropertyTexture2D texProperty = properties.AddProperty<MaterialPropertyTexture2D>("colorTexture");
texProperty.value = texture;
meshRenderer.mesh = mesh;
meshRenderer.overrideProperties = properties;
}
}
示例3: ToMesh
public Mesh ToMesh(IEnumerable<int> faceList, List<int> triangleToFaceMap)
{
List<Vector3f> vertices = new List<Vector3f>();
List<Vector3f> normals = new List<Vector3f>();
List<Vector2f> uvs = new List<Vector2f>();
List<uint> triangles = new List<uint>();
List<uint> edges = new List<uint>();
if (faceList == null)
{
faceList = Enumerable.Range(0, geometry.Faces.Count).Select(i => i);
}
foreach (var faceIndex in faceList)
{
PlanktonFace face = geometry.Faces[faceIndex];
if (face.IsUnused)
{
continue;
}
int startVertexIndex = vertices.Count;
int[] halfedgeIndices = geometry.Faces.GetHalfedges(faceIndex);
for (int h = 0; h < halfedgeIndices.Length; h++)
{
int halfEdgeIndex = halfedgeIndices[h];
int vertexIndex = geometry.Halfedges[halfEdgeIndex].StartVertex;
PlanktonVertex vertex = geometry.Vertices[vertexIndex];
PlanktonVertex end = geometry.Vertices[vertexIndex];
//if (vertex.IsUnused)
//{
// continue;
//}
Vector3f normal = (Vector3f)GetHalfedgeNormal(halfEdgeIndex);
Vector3f position = vertex.ToXYZ().ToVector3f();
vertices.Add(position);
normals.Add(normal);
uvs.Add(new Vector2f(position.X, position.Y));
int pairIndex = geometry.Halfedges.GetPairHalfedge(halfEdgeIndex);
bool makeEdge = halfEdgeIndex%2 == 0 || geometry.Halfedges[halfEdgeIndex].AdjacentFace == -1 || geometry.Halfedges[pairIndex].AdjacentFace == -1;
if (makeEdge)
{
edges.Add((uint)(vertices.Count-1));
int nextIndex = vertices.Count;
if (h == halfedgeIndices.Length-1)
{
nextIndex = startVertexIndex;
}
edges.Add((uint)nextIndex);
}
}
for (int h = 0; h < halfedgeIndices.Length; h++)
{
if (h < 3)
{
if (triangleToFaceMap != null)
{
if (h == 2)
{
triangleToFaceMap.Add(faceIndex);
}
}
triangles.Add((uint)(startVertexIndex+h));
}
else
{
if (triangleToFaceMap != null)
{
triangleToFaceMap.Add(faceIndex);
}
triangles.Add((uint)startVertexIndex);
triangles.Add((uint)(startVertexIndex+(h-1)));
triangles.Add((uint)(startVertexIndex+h));
}
}
}
Mesh mesh = new Mesh();
mesh.AddBuffer<VertexBufferObject3f>("vertex");
mesh.SetBuffer3f("vertex", vertices.ToArray());
mesh.AddBuffer<VertexBufferObject3f>("normal");
mesh.SetBuffer3f("normal", normals.ToArray());
mesh.AddBuffer<VertexBufferObject2f>("uv0");
mesh.SetBuffer2f("uv0", uvs.ToArray());
mesh.SetIndices(triangles.ToArray(), 0, Graphics.PrimitiveType.Triangles);
mesh.SetIndices(edges.ToArray(), 1, Graphics.PrimitiveType.Lines);
//.........这里部分代码省略.........