本文整理汇总了C#中GraphicFactory.CreateDynamicIndexBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicFactory.CreateDynamicIndexBuffer方法的具体用法?C# GraphicFactory.CreateDynamicIndexBuffer怎么用?C# GraphicFactory.CreateDynamicIndexBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphicFactory
的用法示例。
在下文中一共展示了GraphicFactory.CreateDynamicIndexBuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QuadTerrain
//.........这里部分代码省略.........
// {
// while (NodeDepth < maxNodeDepth - 5)
// {
// NodeLevel = (int)Math.Pow(2, (NodeDepth));
// NodeScale = ((heightMap.Height - 1) / NodeLevel) + 1;
// qNode = new QuadNode(HeightMap, SquareSize, NodeDepth, xPosition, yPosition);
// allQuadNodes.Add(qNode);
// qNode = new QuadNode(HeightMap, SquareSize, NodeDepth, xPosition + NodeScale - 1, yPosition);
// allQuadNodes.Add(qNode);
// qNode = new QuadNode(HeightMap, SquareSize, NodeDepth, xPosition, yPosition + NodeScale - 1);
// allQuadNodes.Add(qNode);
// qNode = new QuadNode(HeightMap, SquareSize, NodeDepth, xPosition + NodeScale - 1, yPosition + NodeScale - 1);
// allQuadNodes.Add(qNode);
// parentNode[0] = qNode;
// NodeDepth++;
// }
// NodeDepth--;
// NodeLevel = (int)Math.Pow(2, (NodeDepth-1));
// NodeScale = ((heightMap.Height - 1) / NodeLevel) + 1;
// //NodeDepth--;
// yPosition += NodeScale - 1;
// }
// xPosition += NodeScale - 1;
// yPosition = 0;
//}
//NodeDepth++;
//int numQuadNodes = allQuadNodes.Count;
//int[] indexBufferArray = new int[numQuadNodes * ((squareSize - 1) * (squareSize - 1) * 6)];
#endregion
//Define Quadnode List
allQuadNodes = new List<QuadNode>();
//Create RootNode
RootNode = new QuadNode(HeightMap, normStore, SquareSize, VBsize, Scale, 0, 0, 0, null, allVertices);
allQuadNodes.Add(RootNode);
////////////////////////////////////////////////
//Creates all quadnodes in the entire quadtree
//
//This is a recursive function. It breaks the rootnode into 4 new quadnodes, then applies itself to each of
//these children nodes, in turn breaking them. See it's definition for a more complete explanation.
RecursiveCreateQuad(RootNode);
////////////////////////////////////////////////
//Set Adjacent Nodes for each Quadnode, for stitching purposes.
for (int i = 0; i < allQuadNodes.Count; i++)
{
if (allQuadNodes[i].NodeDepth > 0)
{
foreach (QuadNode qNode in allQuadNodes)
{
if (qNode.XPosition == allQuadNodes[i].XPosition + allQuadNodes[i].NodeScale - 1 && qNode.NodeDepth == allQuadNodes[i].NodeDepth && qNode.YPosition == allQuadNodes[i].YPosition)
{
allQuadNodes[i].adjacentNorthQuad = qNode;
}
if (qNode.YPosition == allQuadNodes[i].YPosition + allQuadNodes[i].NodeScale - 1 && qNode.NodeDepth == allQuadNodes[i].NodeDepth && qNode.XPosition == allQuadNodes[i].XPosition)
{
allQuadNodes[i].adjacentEastQuad = qNode;
}
if (qNode.XPosition == allQuadNodes[i].XPosition - allQuadNodes[i].NodeScale + 1 && qNode.NodeDepth == allQuadNodes[i].NodeDepth && qNode.YPosition == allQuadNodes[i].YPosition)
{
allQuadNodes[i].adjacentSouthQuad = qNode;
}
if (qNode.YPosition == allQuadNodes[i].YPosition - allQuadNodes[i].NodeScale + 1 && qNode.NodeDepth == allQuadNodes[i].NodeDepth && qNode.XPosition == allQuadNodes[i].XPosition)
{
allQuadNodes[i].adjacentWestQuad = qNode;
}
}
}
}
///////////////////////////////////////////////
//Run an update on the terrain for it's initial state. See the update method.
//I'm not entirely sure why this is necessary, but I'm sure there's a good reason.
Matrix viewMatrix = Matrix.CreateLookAt(Vector3.Zero, Vector3.Forward, Vector3.Up);
Matrix projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 10f, 1, 100);
BoundingFrustum startFrustrum = new BoundingFrustum(viewMatrix * projectionMatrix);
#if DEBUG
debugTimer = new Stopwatch();
#endif
UpdateTerrain(new Vector3(), startFrustrum, 3.5f);
allIBs = new DynamicIndexBuffer[allIndices.Length];
for (int l = 0; l < allIndices.Length; l++)
{
allIBs[l] = factory.CreateDynamicIndexBuffer(IndexElementSize.ThirtyTwoBits, (allVertices[l].Length), BufferUsage.WriteOnly);
}
}
示例2: ClothModel
/// <summary>
/// Initializes a new instance of the <see cref="SimpleModel"/> class.
/// </summary>
/// <param name="factory">The graphic factory.</param>
/// <param name="PhysxPhysicWorld">The physx physic world.</param>
/// <param name="clothMeshDesc">The cloth mesh desc.</param>
/// <param name="Points">The points.</param>
/// <param name="TextCoords">The text coords.</param>
/// <param name="Indices">The indices.</param>
/// <param name="diffuseTextureName">Name of the diffuse texture.</param>
public ClothModel(GraphicFactory factory, PhysxPhysicWorld PhysxPhysicWorld, ClothMeshDescription clothMeshDesc,
Vector3[] Points ,
Vector2[] TextCoords ,
int[] Indices ,
String diffuseTextureName = null)
: base(factory, "Cloth", false)
{
this._diffuseName = diffuseTextureName;
VerticesNum = Points.Length;
IndicesNum = Indices.Length;
clothMeshDesc.AllocateVertices<Vector3>(VerticesNum);
clothMeshDesc.AllocateTriangles<int>(IndicesNum / 3);
clothMeshDesc.VertexCount = VerticesNum;
clothMeshDesc.TriangleCount = IndicesNum / 3;
BatchInformation = new PloobsEngine.Modelo.BatchInformation(0, VerticesNum, IndicesNum / 3, 0, 0,
VertexPositionNormalTexture.VertexDeclaration, VertexPositionNormalTexture.VertexDeclaration.VertexStride, PrimitiveType.TriangleList);
BatchInformation.ModelLocalTransformation = XNA.Matrix.Identity;
vertexPositionNormalTexture = new VertexPositionNormalTexture[VerticesNum];
BatchInformation.VertexBuffer = factory.CreateDynamicVertexBuffer(VertexPositionNormalTexture.VertexDeclaration, VerticesNum + (int)(1.2 * VerticesNum), BufferUsage.WriteOnly);
BatchInformation.IndexBuffer = factory.CreateDynamicIndexBuffer(IndexElementSize.ThirtyTwoBits, IndicesNum + (int)(1.2 * IndicesNum), BufferUsage.WriteOnly);
BatchInformation.IndexBuffer.SetData<int>(Indices);
clothMeshDesc.VerticesStream.SetData(Points);
clothMeshDesc.TriangleStream.SetData(Indices);
XNA.Vector3[] pts = new XNA.Vector3[BatchInformation.NumVertices];
for (int i = 0; i < BatchInformation.NumVertices; i++)
{
vertexPositionNormalTexture[i].TextureCoordinate = TextCoords[i].AsXNA();
vertexPositionNormalTexture[i].Position = Points[i].AsXNA();
pts[i] = vertexPositionNormalTexture[i].Position;
}
modelRadius = Microsoft.Xna.Framework.BoundingSphere.CreateFromPoints(pts).Radius;
pts = null;
// We are using 32 bit integers for our indices, so make sure the 16 bit flag is removed.
// 32 bits are the default, so this isn't technically needed, but it's good to show in a sample
clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;
//clothMeshDesc.Flags |= (MeshFlag)((int)clothMeshDesc.Flags | (int)ClothMeshFlag.Tearable);
// Write the cooked data to memory
using (var memoryStream = new MemoryStream())
{
Cooking.InitializeCooking();
Cooking.CookClothMesh(clothMeshDesc, memoryStream);
Cooking.CloseCooking();
// Need to reset the position of the stream to the beginning
memoryStream.Position = 0;
ClothMesh = PhysxPhysicWorld.Core.CreateClothMesh(memoryStream);
}
LoadModel(factory, out BatchInformations, out TextureInformations);
}
示例3: 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)
{
int vertCount = bilboards.Count() * 4;
int indexCount = bilboards.Count() * 6;
int noVertices = vertCount;
int noTriangles = indexCount / 3;
VertexBuffer vertexBufferS = factory.CreateDynamicVertexBuffer(VertexPositionTexture.VertexDeclaration, vertCount, BufferUsage.WriteOnly);
IndexBuffer IndexBufferS = factory.CreateDynamicIndexBuffer(IndexElementSize.SixteenBits, indexCount, BufferUsage.WriteOnly);
BatchInformations = new BatchInformation[1][];
BatchInformation[] b = new BatchInformation[1];
b[0] = new BatchInformation(0, vertCount, noTriangles, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride, BatchType.INDEXED);
b[0].ModelLocalTransformation = Matrix.Identity;
b[0].VertexBuffer = vertexBufferS;
b[0].IndexBuffer = IndexBufferS;
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();
}