public void testClone() { IndexData indexData; IndexData clone; // with basic quad data indexData = new IndexData(); indexData.AddTriangle(1, 2, 3); indexData.AddTriangle(4, 5, 6); clone = indexData.Clone(); Assert.AreEqual(2, clone.NumTriangles); Assert.AreEqual(1, clone.GetIndex(0)); Assert.AreEqual(3, clone.GetIndex(2)); Assert.AreEqual(5, clone.GetIndex(4)); // with arbitrary data indexData = new IndexData(); indexData.AddTriangle(0, 1, 2); indexData.AddTriangle(1, 3, 2); clone = indexData.Clone(); Assert.AreEqual(2, clone.NumTriangles); Assert.AreEqual(1, clone.GetIndex(1)); Assert.AreEqual(2, clone.GetIndex(2)); Assert.AreEqual(3, clone.GetIndex(4)); }
public GeometryBucket(MaterialBucket parent, string formatString, VertexData vData, IndexData iData) { // Clone the structure from the example this.parent = parent; this.formatString = formatString; vertexData = vData.Clone(false); indexData = iData.Clone(false); vertexData.vertexCount = 0; vertexData.vertexStart = 0; indexData.indexCount = 0; indexData.indexStart = 0; indexType = indexData.indexBuffer.Type; queuedGeometry = new List <QueuedGeometry>(); // Derive the max vertices if (indexType == IndexType.Size32) { maxVertexIndex = int.MaxValue; } else { maxVertexIndex = ushort.MaxValue; } // Check to see if we have blend indices / blend weights // remove them if so, they can try to blend non-existent bones! VertexElement blendIndices = vertexData.vertexDeclaration.FindElementBySemantic(VertexElementSemantic.BlendIndices); VertexElement blendWeights = vertexData.vertexDeclaration.FindElementBySemantic(VertexElementSemantic.BlendWeights); if (blendIndices != null && blendWeights != null) { Debug.Assert(blendIndices.Source == blendWeights.Source, "Blend indices and weights should be in the same buffer"); // Get the source ushort source = blendIndices.Source; Debug.Assert(blendIndices.Size + blendWeights.Size == vertexData.vertexBufferBinding.GetBuffer(source).VertexSize, "Blend indices and blend buffers should have buffer to themselves!"); // Unset the buffer vertexData.vertexBufferBinding.UnsetBinding(source); // Remove the elements vertexData.vertexDeclaration.RemoveElement(VertexElementSemantic.BlendIndices); vertexData.vertexDeclaration.RemoveElement(VertexElementSemantic.BlendWeights); } }