本文整理汇总了C#中GraphicFactory.CreateIndexBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicFactory.CreateIndexBuffer方法的具体用法?C# GraphicFactory.CreateIndexBuffer怎么用?C# GraphicFactory.CreateIndexBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphicFactory
的用法示例。
在下文中一共展示了GraphicFactory.CreateIndexBuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadModel
protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
{
List<VertexPositionNormalTexture> vertexList = new List<VertexPositionNormalTexture>();
#if WINDOWS_PHONE || REACH
////gambi shortcut
List<int> indexList2 = new List<int>();
GetVertexData(vertexList, indexList2, terrainObject);
List<short> indexList = new List<short>();
foreach (var item in indexList2)
{
indexList.Add( (short) item);
}
indexList2.Clear();
#else
List<int> indexList = new List<int>();
GetVertexData(vertexList, indexList, terrainObject);
#endif
modelRadius = (terrainObject.BoundingBox.Value.Max - terrainObject.BoundingBox.Value.Max).Length() / 2;
var newVertices = new VertexPositionNormalTexture[vertexList.Count];
vertexList.CopyTo(newVertices);
#if WINDOWS_PHONE|| REACH
var newIndices = new short[indexList.Count];
#else
var newIndices = new int[indexList.Count];
#endif
indexList.CopyTo(newIndices);
VertexBuffer vertexBufferS = factory.CreateVertexBuffer(VertexPositionNormalTexture.VertexDeclaration, newVertices.Count(), BufferUsage.WriteOnly);
vertexBufferS.SetData(newVertices);
#if WINDOWS_PHONE || REACH
IndexBuffer indexBufferS = factory.CreateIndexBuffer(IndexElementSize.SixteenBits,newIndices.Count(),BufferUsage.WriteOnly);
#else
IndexBuffer indexBufferS = factory.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, newIndices.Count(), BufferUsage.WriteOnly);
#endif
indexBufferS.SetData(newIndices);
BatchInformations = new BatchInformation[1][];
BatchInformation[] b = new BatchInformation[1];
b[0] = new BatchInformation(0, newVertices.Count(), newIndices.Count() / 3, 0, 0, VertexPositionNormalTexture.VertexDeclaration,VertexPositionNormalTexture.VertexDeclaration.VertexStride);
b[0].VertexBuffer = vertexBufferS;
b[0].IndexBuffer = indexBufferS;
b[0].ModelLocalTransformation = Matrix.Identity;
BatchInformations[0] = b;
TextureInformations = new TextureInformation[1][];
TextureInformations[0] = new TextureInformation[1];
TextureInformations[0][0] = new TextureInformation(isInternal, factory, null, null, null, null);
TextureInformations[0][0].LoadTexture();
}
示例2: LoadModel
/// <summary>
/// Loads the model.
/// </summary>
/// <param name="factory">The factory.</param>
/// <param name="BatchInformations">The batch informations.</param>
/// <param name="TextureInformations">The texture informations.</param>
protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
{
VertexPositionTexture[] billboardVertices = new VertexPositionTexture[4];
int i = 0;
billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 0));
billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 0));
billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 1));
billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 1));
VertexElement v0 = new VertexElement(0,VertexElementFormat.Vector3,VertexElementUsage.TextureCoordinate,1);
VertexElement v1 = new VertexElement(sizeof(float) * 3,VertexElementFormat.Vector2,VertexElementUsage.TextureCoordinate,2);
vd = new VertexDeclaration(v0, v1);
VertexBuffer InstancedvertexBufferS;
if (dynamicBufferSize != -1)
{
InstancedvertexBufferS = factory.CreateDynamicVertexBuffer(vd, dynamicBufferSize, BufferUsage.WriteOnly);
}
else
{
InstancedvertexBufferS = factory.CreateDynamicVertexBuffer(vd, instances.Count(), BufferUsage.WriteOnly);
}
InstancedvertexBufferS.SetData(instances);
VertexBuffer vertexBufferS = factory.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, billboardVertices.Count(), BufferUsage.WriteOnly);
vertexBufferS.SetData(billboardVertices);
short[] indices = new short[] { 0,2,1,1,2,3};
IndexBuffer indexBufferS = factory.CreateIndexBuffer(IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly);
indexBufferS.SetData<short>(indices);
BatchInformations = new BatchInformation[1][];
BatchInformation[] b = new BatchInformation[1];
b[0] = new BatchInformation(0, 4, 2, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride,instances.Count());
b[0].VertexBuffer = vertexBufferS;
b[0].IndexBuffer = indexBufferS;
b[0].InstancedVertexBuffer = InstancedvertexBufferS;
BatchInformations[0] = b;
TextureInformations = new TextureInformation[1][];
TextureInformations[0] = new TextureInformation[1];
TextureInformations[0][0] = new TextureInformation(isInternal, factory, diffuseTextureName, null, null, null);
TextureInformations[0][0].LoadTexture();
}
示例3: LoadModel
protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
{
Vector3 myPosition = new Vector3(basePosition.X - (myWidth / 2), basePosition.Y, basePosition.Z - (myHeight / 2));
Vector3[] pos = new Vector3[myWidth * myHeight];
// Vertices
VertexMultitextured[] myVertices = new VertexMultitextured[myWidth * myHeight];
for (int x = 0; x < myWidth; x++)
for (int y = 0; y < myHeight; y++)
{
myVertices[x + y * myWidth].Position = new Vector3(y, 0, x);
pos[x + y * myWidth] = new Vector3(y, 0, x);
myVertices[x + y * myWidth].Normal = new Vector3(0, -1, 0);
myVertices[x + y * myWidth].TextureCoordinate.X = (float)x / 30.0f;
myVertices[x + y * myWidth].TextureCoordinate.Y = (float)y / 30.0f;
}
modelRadius = BoundingSphere.CreateFromPoints(pos).Radius;
// Calc Tangent and Bi Normals.
for (int x = 0; x < myWidth; x++)
for (int y = 0; y < myHeight; y++)
{
// Tangent Data.
if (x != 0 && x < myWidth - 1)
myVertices[x + y * myWidth].Tangent = myVertices[x - 1 + y * myWidth].Position - myVertices[x + 1 + y * myWidth].Position;
else
if (x == 0)
myVertices[x + y * myWidth].Tangent = myVertices[x + y * myWidth].Position - myVertices[x + 1 + y * myWidth].Position;
else
myVertices[x + y * myWidth].Tangent = myVertices[x - 1 + y * myWidth].Position - myVertices[x + y * myWidth].Position;
// Bi Normal Data.
if (y != 0 && y < myHeight - 1)
myVertices[x + y * myWidth].BiNormal = myVertices[x + (y - 1) * myWidth].Position - myVertices[x + (y + 1) * myWidth].Position;
else
if (y == 0)
myVertices[x + y * myWidth].BiNormal = myVertices[x + y * myWidth].Position - myVertices[x + (y + 1) * myWidth].Position;
else
myVertices[x + y * myWidth].BiNormal = myVertices[x + (y - 1) * myWidth].Position - myVertices[x + y * myWidth].Position;
}
VertexDeclaration vd = new VertexDeclaration(VertexMultitextured.SizeInBytes,VertexMultitextured.VertexElements);
VertexBuffer vb = factory.CreateVertexBuffer(vd, myWidth * myHeight, BufferUsage.WriteOnly);
vb.SetData(myVertices);
short[] terrainIndices = new short[(myWidth - 1) * (myHeight - 1) * 6];
for (short x = 0; x < myWidth - 1; x++)
{
for (short y = 0; y < myHeight - 1; y++)
{
terrainIndices[(x + y * (myWidth - 1)) * 6] = (short)((x + 1) + (y + 1) * myWidth);
terrainIndices[(x + y * (myWidth - 1)) * 6 + 1] = (short)((x + 1) + y * myWidth);
terrainIndices[(x + y * (myWidth - 1)) * 6 + 2] = (short)(x + y * myWidth);
terrainIndices[(x + y * (myWidth - 1)) * 6 + 3] = (short)((x + 1) + (y + 1) * myWidth);
terrainIndices[(x + y * (myWidth - 1)) * 6 + 4] = (short)(x + y * myWidth);
terrainIndices[(x + y * (myWidth - 1)) * 6 + 5] = (short)(x + (y + 1) * myWidth);
}
}
IndexBuffer ib = factory.CreateIndexBuffer(IndexElementSize.SixteenBits, (myWidth - 1) * (myHeight - 1) * 6, BufferUsage.WriteOnly);
ib.SetData(terrainIndices);
BatchInformations = new BatchInformation[1][];
BatchInformation[] b = new BatchInformation[1];
b[0] = new BatchInformation(0,myVertices.Count(),terrainIndices.Count() /3,0,0,vd,VertexMultitextured.SizeInBytes);
b[0].VertexBuffer = vb;
b[0].IndexBuffer = ib;
BatchInformations[0] = b;
TextureInformations = new TextureInformation[1][];
TextureInformations[0] = new TextureInformation[1];
TextureInformations[0][0] = new TextureInformation(isInternal, factory, null, null, null, null);
TextureInformations[0][0].LoadTexture();
}