public T[] VerticesExtractChannel <T>(VertexElementSemantic semantic) where T : unmanaged
        {
            var vertexStructure = VertexStructure.Value;

            if (vertexStructure != null)
            {
                vertexStructure.GetInfo(out var vertexSize, out _);

                var vertices = Vertices.Value;
                if (vertices != null)
                {
                    var vertexCount = vertices.Length / vertexSize;

                    if (vertexStructure.GetElementBySemantic(semantic, out var element))
                    {
                        unsafe
                        {
                            if (VertexElement.GetSizeInBytes(element.Type) == sizeof(T))
                            {
                                T[] result = new T[vertexCount];
                                fixed(byte *pVertices = vertices)
                                {
                                    byte *src = pVertices + element.Offset;

                                    for (int n = 0; n < vertexCount; n++)
                                    {
                                        result[n] = *(T *)src;
                                        src      += vertexSize;
                                    }
                                }

                                return(result);
                            }
                        }
                    }
                }
            }

            return(null);
        }
Exemple #2
0
        //!!!!IList<> ?

        public static bool GetElementBySemantic(this VertexElement[] elements, VertexElementSemantic semantic, out VertexElement element)
        {
            //!!!!slowly

            for (int n = 0; n < elements.Length; n++)
            {
                if (elements[n].Semantic == semantic)
                {
                    element = elements[n];
                    return(true);
                }
            }

            element = new VertexElement();
            return(false);
        }