本文整理汇总了C#中Mesh.SetIndexBufferData方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.SetIndexBufferData方法的具体用法?C# Mesh.SetIndexBufferData怎么用?C# Mesh.SetIndexBufferData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mesh
的用法示例。
在下文中一共展示了Mesh.SetIndexBufferData方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateGroundPlane
public void CreateGroundPlane(float minValue, float size, float uvScale)
{
VertexElement[] vElements = new VertexElement[]
{
new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
new VertexElement(0, 12, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
new VertexElement(0, 20, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
new VertexElement(0, 32, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Tangent, 0),
VertexElement.VertexDeclarationEnd
};
model = new Mesh(2, 4, MeshFlags.Managed | MeshFlags.Use32Bit, vElements, device);
Vertex[] vertexList = new Vertex[4];
// Initialize the values for the 4 vertexes.
vertexList[0].Position = new Vector3(-size, minValue, -size);
vertexList[0].Normal = new Vector3(0, 1.0f, 0);
vertexList[0].TexCoord = new Vector2(0, 0);
vertexList[1].Position = new Vector3(-size, minValue, size);
vertexList[1].Normal = new Vector3(0, 1.0f, 0);
vertexList[1].TexCoord = new Vector2(0, uvScale);
vertexList[2].Position = new Vector3(size, minValue, -size);
vertexList[2].Normal = new Vector3(0, 1.0f, 0);
vertexList[2].TexCoord = new Vector2(uvScale, 0);
vertexList[3].Position = new Vector3(size, minValue, size);
vertexList[3].Normal = new Vector3(0, 1.0f, 0);
vertexList[3].TexCoord = new Vector2(uvScale, uvScale);
int[] indexList = { 0, 3, 2, 1, 3, 0 };
model.SetIndexBufferData(indexList, LockFlags.None);
model.SetVertexBufferData(vertexList, LockFlags.None);
TangentBuilder.CalculateTangents(model);
}
示例2: RebuildAsync
private void RebuildAsync(Object deviceObj)
{
try
{
Device device = (Device)deviceObj;
// Rebuild
if (_bitmap == null)
{
_bitmap = new Bitmap(1, 1);
_valid = true;
}
else
{
try
{
_imageTexture = Texture.FromBitmap(device, _bitmap, Usage.Dynamic, Pool.Default);
// Set up the material
_imageMaterial = new Material();
_imageMaterial.Diffuse = _color;
// Set up the rectangular mesh
CustomVertex.PositionNormalTextured[] verts = new CustomVertex.PositionNormalTextured[4];
verts[0].Position = new Vector3(0, 0, -_height);
verts[0].Normal = new Vector3(0, 1, 0);
verts[0].Tu = 0; verts[0].Tv = 1;
verts[1].Position = new Vector3(_width, 0, -_height);
verts[1].Normal = new Vector3(0, 1, 0);
verts[1].Tu = 1; verts[1].Tv = 1;
verts[2].Position = new Vector3(_width, 0, 0);
verts[2].Normal = new Vector3(0, 1, 0);
verts[2].Tu = 1; verts[2].Tv = 0;
verts[3].Position = new Vector3(0, 0, 0);
verts[3].Normal = new Vector3(0, 1, 0);
verts[3].Tu = 0; verts[3].Tv = 0;
AttributeRange[] attributes = new AttributeRange[1];
attributes[0].AttributeId = 0;
attributes[0].FaceCount = 2;
attributes[0].FaceStart = 0;
attributes[0].VertexCount = 4;
attributes[0].VertexStart = 0;
short[] indices = new short[]
{
0, 1, 2,
0, 2, 3
};
_imageSprite = new Mesh(2, 4, 0, CustomVertex.PositionNormalTextured.Format, device);
_imageSprite.SetVertexBufferData(verts, LockFlags.Discard);
_imageSprite.SetIndexBufferData(indices, LockFlags.Discard);
_imageSprite.SetAttributeTable(attributes);
_valid = true;
}
catch (Exception)
{
_valid = false;
_imageTexture = null;
_imageSprite = null;
return;
}
}
}
catch (Exception)
{
_valid = false;
_imageTexture = null;
_imageSprite = null;
}
finally
{
_building = false;
}
}
示例3: buildMesh
/// <summary>
/// Copies over the vertex and index buffers and calls the function within
/// the model class to build a Mesh class.
/// </summary>
private void buildMesh()
{
VertexElement[] vElements = new VertexElement[]
{
new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
new VertexElement(0, 12, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
new VertexElement(0, 20, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
new VertexElement(0, 32, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Tangent, 0),
VertexElement.VertexDeclarationEnd
};
// Creates a new mesh
try
{
mesh = new Mesh(faceList.Count, vertexInfo.Count, MeshFlags.Managed | MeshFlags.Use32Bit, vElements, device);
mesh.SetVertexBufferData(vertexInfo.ToArray(), LockFlags.None);
mesh.SetIndexBufferData(faceList.ToArray(), LockFlags.None);
}
catch(DirectXException)
{
MessageBox.Show("A problem occured with the model", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
faceList.Clear();
vertexInfo.Clear();
vertexList.Clear();
mesh = new Mesh(1, 1, MeshFlags.Managed, vElements, device);
return;
}
// Try loop to generate normals (if needed), tangents and binormals.
try
{
// Generates a list of adjacent faces used for generating normals.
int[] adjacency = new int[mesh.NumberFaces * 3];
mesh.GenerateAdjacency(0, adjacency);
if(!hasNormals)
mesh.ComputeNormals(adjacency);
TangentBuilder.CalculateTangents(mesh);
}
catch (DirectXException dxe)
{
Console.WriteLine(dxe);
}
}
示例4: createMovementGizmo
//.........这里部分代码省略.........
indices[i * eachILength + 11] = (short)(i * eachVLength + 5);
indices[i * eachILength + 12] = (short)(i * eachVLength + 0);
indices[i * eachILength + 13] = (short)(i * eachVLength + 5);
indices[i * eachILength + 14] = (short)(i * eachVLength + 6);
indices[i * eachILength + 15] = (short)(i * eachVLength + 0);
indices[i * eachILength + 16] = (short)(i * eachVLength + 6);
indices[i * eachILength + 17] = (short)(i * eachVLength + 7);
indices[i * eachILength + 18] = (short)(i * eachVLength + 0);
indices[i * eachILength + 19] = (short)(i * eachVLength + 7);
indices[i * eachILength + 20] = (short)(i * eachVLength + 8);
indices[i * eachILength + 21] = (short)(i * eachVLength + 0);
indices[i * eachILength + 22] = (short)(i * eachVLength + 8);
indices[i * eachILength + 23] = (short)(i * eachVLength + 1);
}
for (int i = 3; i < 6; i++)
{
// Shaft
indices[i * eachILength + 0] = (short)((i - 3) * eachVLength + 9);
indices[i * eachILength + 1] = (short)((i - 3) * eachVLength + 13);
indices[i * eachILength + 2] = (short)((i - 3) * eachVLength + 10);
indices[i * eachILength + 3] = (short)((i - 3) * eachVLength + 10);
indices[i * eachILength + 4] = (short)((i - 3) * eachVLength + 13);
indices[i * eachILength + 5] = (short)((i - 3) * eachVLength + 14);
indices[i * eachILength + 6] = (short)((i - 3) * eachVLength + 10);
indices[i * eachILength + 7] = (short)((i - 3) * eachVLength + 14);
indices[i * eachILength + 8] = (short)((i - 3) * eachVLength + 11);
indices[i * eachILength + 9] = (short)((i - 3) * eachVLength + 11);
indices[i * eachILength + 10] = (short)((i - 3) * eachVLength + 14);
indices[i * eachILength + 11] = (short)((i - 3) * eachVLength + 15);
indices[i * eachILength + 12] = (short)((i - 3) * eachVLength + 11);
indices[i * eachILength + 13] = (short)((i - 3) * eachVLength + 15);
indices[i * eachILength + 14] = (short)((i - 3) * eachVLength + 12);
indices[i * eachILength + 15] = (short)((i - 3) * eachVLength + 12);
indices[i * eachILength + 16] = (short)((i - 3) * eachVLength + 15);
indices[i * eachILength + 17] = (short)((i - 3) * eachVLength + 16);
indices[i * eachILength + 18] = (short)((i - 3) * eachVLength + 12);
indices[i * eachILength + 19] = (short)((i - 3) * eachVLength + 16);
indices[i * eachILength + 20] = (short)((i - 3) * eachVLength + 13);
indices[i * eachILength + 21] = (short)((i - 3) * eachVLength + 12);
indices[i * eachILength + 22] = (short)((i - 3) * eachVLength + 13);
indices[i * eachILength + 23] = (short)((i - 3) * eachVLength + 9);
}
// Squares
indices[6 * eachILength + 0] = (short)(3 * eachVLength + 0);
indices[6 * eachILength + 1] = (short)(3 * eachVLength + 1);
indices[6 * eachILength + 2] = (short)(3 * eachVLength + 4);
indices[6 * eachILength + 3] = (short)(3 * eachVLength + 0);
indices[6 * eachILength + 4] = (short)(3 * eachVLength + 2);
indices[6 * eachILength + 5] = (short)(3 * eachVLength + 4);
indices[6 * eachILength + 6] = (short)(3 * eachVLength + 0);
indices[6 * eachILength + 7] = (short)(3 * eachVLength + 2);
indices[6 * eachILength + 8] = (short)(3 * eachVLength + 6);
indices[6 * eachILength + 9] = (short)(3 * eachVLength + 0);
indices[6 * eachILength + 10] = (short)(3 * eachVLength + 3);
indices[6 * eachILength + 11] = (short)(3 * eachVLength + 6);
indices[6 * eachILength + 12] = (short)(3 * eachVLength + 0);
indices[6 * eachILength + 13] = (short)(3 * eachVLength + 3);
indices[6 * eachILength + 14] = (short)(3 * eachVLength + 5);
indices[6 * eachILength + 15] = (short)(3 * eachVLength + 0);
indices[6 * eachILength + 16] = (short)(3 * eachVLength + 1);
indices[6 * eachILength + 17] = (short)(3 * eachVLength + 5);
m.SetIndexBufferData(indices, LockFlags.None);
#endregion
int[] attr = m.LockAttributeBufferArray(LockFlags.Discard);
int step = eachILength / 3; // 1 face = 3 indices
for (int i = 0; i < step; i++)
{
attr[step * 0 + i] = 0;
attr[step * 1 + i] = 1;
attr[step * 2 + i] = 2;
attr[step * 3 + i] = 3;
attr[step * 4 + i] = 4;
attr[step * 5 + i] = 5;
}
for (int i = step * 6; i < attr.Length; i++)
{
attr[i] = 6 + (i - step * 6) / 2;
}
m.UnlockAttributeBuffer(attr);
int[] adj = new int[m.NumberFaces * 3];
m.GenerateAdjacency(0.001f, adj);
m.OptimizeInPlace(MeshFlags.OptimizeVertexCache, adj);
this.gizmo = m;
}
示例5: RebuildAsync
private void RebuildAsync(Object deviceObj)
{
try
{
Device device = (Device)deviceObj;
// Rebuild
if (_line.Equals(""))
{
_lineSprite = null;
_valid = true;
}
else
{
try
{
int firstTick = Environment.TickCount;
System.Drawing.Font font = new System.Drawing.Font(_fontFace, _fontSize);
Bitmap b = new Bitmap(_lineWidth, _lineHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(b);
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
g.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, b.Width, b.Height));
g.DrawString(_displayString, font, new SolidBrush(Color.White), new PointF(0, 0));
//TextRenderer.DrawText(g, _displayString, font, new Point(0, 0), Color.White);
_lineTexture = Texture.FromBitmap(device, b, Usage.None, Pool.Managed);
//_lineTexture = new Texture(device, (int)_lineWidth * (int)Math.Pow(2.0, (double)mipLevels), (int)_lineHeight * (int)Math.Pow(2.0, (double)mipLevels), mipLevels + 1, Usage.RenderTarget, Format.Unknown, Pool.Default);
//Surface s = _lineTexture.GetSurfaceLevel(mipLevels);
//SurfaceLoader.FromSurface(s, Surface.FromBitmap(device, b, Pool.Default), Filter.Box, 0xFF0000);
g.Dispose();
//for (int i = 1; i <= mipLevels; i++)
//{
// int width = _lineWidth * (int)Math.Pow(2.0, (double)i);
// int height = _lineHeight * (int)Math.Pow(2, (double)i);
// b = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
// font = new System.Drawing.Font(_fontFace, _fontSize * (float)Math.Pow(2, (double)i));
// g = Graphics.FromImage(b);
// g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
// g.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, b.Width, b.Height));
// g.DrawString(displayString, font, new SolidBrush(Color.White), new PointF(0, 0));
// s = _lineTexture.GetSurfaceLevel(mipLevels - i);
// SurfaceLoader.FromSurface(s, Surface.FromBitmap(device, b, Pool.Default), Filter.Box, 0xFF0000);
// g.Dispose();
//}
// Set up the material
_lineMaterial = new Material();
_lineMaterial.Diffuse = _line.Color;
//_lineMaterial.Ambient = GetColor(_line.Type);
// Set up the rectangular mesh
CustomVertex.PositionNormalTextured[] verts = new CustomVertex.PositionNormalTextured[4];
verts[0].Position = new Vector3(0, 0, -_lineHeight);
verts[0].Normal = new Vector3(0, 1, 0);
verts[0].Tu = 0; verts[0].Tv = 1;
verts[1].Position = new Vector3(_lineWidth, 0, -_lineHeight);
verts[1].Normal = new Vector3(0, 1, 0);
verts[1].Tu = 1; verts[1].Tv = 1;
verts[2].Position = new Vector3(_lineWidth, 0, 0);
verts[2].Normal = new Vector3(0, 1, 0);
verts[2].Tu = 1; verts[2].Tv = 0;
verts[3].Position = new Vector3(0, 0, 0);
verts[3].Normal = new Vector3(0, 1, 0);
verts[3].Tu = 0; verts[3].Tv = 0;
AttributeRange[] attributes = new AttributeRange[1];
attributes[0].AttributeId = 0;
attributes[0].FaceCount = 2;
attributes[0].FaceStart = 0;
attributes[0].VertexCount = 4;
attributes[0].VertexStart = 0;
short[] indices = new short[]
{
0, 1, 2,
0, 2, 3
};
_lineSprite = new Mesh(2, 4, 0, CustomVertex.PositionNormalTextured.Format, device);
_lineSprite.SetVertexBufferData(verts, LockFlags.Discard);
_lineSprite.SetIndexBufferData(indices, LockFlags.Discard);
_lineSprite.SetAttributeTable(attributes);
//.........这里部分代码省略.........
示例6: Init
public static void Init(Device device, Bitmap unknownBitmap)
{
SquareMesh = new Mesh(2, 6, MeshFlags.Managed, CustomVertex.PositionTextured.Format, device);
List<short> ib = new List<short>();
for (int i = 0; i < SquareVerts.Length; i++)
ib.Add((short)(i));
SquareMesh.SetVertexBufferData(SquareVerts, LockFlags.None);
SquareMesh.SetIndexBufferData(ib.ToArray(), LockFlags.None);
QuestionMark = unknownBitmap != null ? new Texture(device, unknownBitmap, Usage.None, Pool.Managed) : new Texture(device, 16, 16, 0, Usage.None, Format.A16B16G16R16, Pool.Managed);
}