5 using System.Runtime.InteropServices;
6 using SiliconStudio.Paradox.Effects.Data;
7 using SiliconStudio.Core;
9 namespace SiliconStudio.
Paradox.Extensions
18 public static T[] GetVertexBufferData<T>(
this MeshDrawData meshData, params
string[] vertexElementToExtract) where T :
struct
20 var declaration = meshData.VertexBuffers[0].Declaration;
22 var offsets = declaration.EnumerateWithOffsets().Where(vertexElementOffset => vertexElementToExtract.Contains(vertexElementOffset.VertexElement.SemanticAsText)).ToList();
24 int expectedSize = offsets.Sum(vertexElementWithOffset => vertexElementWithOffset.Size);
26 var
count = meshData.VertexBuffers[0].Count;
31 if (checkSize != outputSize)
32 throw new ArgumentException(
string.Format(
"Size of T is not a multiple of totalSize {0}", outputSize));
34 var output =
new T[outputSize / Utilities.SizeOf<T>()];
36 var handleOutput = GCHandle.Alloc(output, GCHandleType.Pinned);
37 var ptrOutput = handleOutput.AddrOfPinnedObject();
39 var handleInput = GCHandle.Alloc(meshData.VertexBuffers[0].Buffer.Value.Content, GCHandleType.Pinned);
40 var ptrInput = handleInput.AddrOfPinnedObject();
42 for(
int i = 0; i <
count; i++)
44 foreach (var vertexElementWithOffset
in offsets)
46 Utilities.CopyMemory(ptrOutput, ptrInput + vertexElementWithOffset.Offset, vertexElementWithOffset.Size);
47 ptrOutput = ptrOutput + vertexElementWithOffset.Size;
49 ptrInput += declaration.VertexStride;
Data type for SiliconStudio.Paradox.Effects.MeshDraw.