Example #1
0
        public static MemoryAccessor CreateVertexMemoryAccessor <TVertex>(this IReadOnlyList <TVertex> vertices, string attributeName, Schema2.EncodingType jointEncoding)
            where TVertex : IVertexBuilder
        {
            if (vertices == null || vertices.Count == 0)
            {
                return(null);
            }

            // determine the vertex attributes from the first vertex.
            var attributes = GetVertexAttributes(vertices[0], vertices.Count, jointEncoding);

            var attribute = attributes.FirstOrDefault(item => item.Name == attributeName);

            if (attribute.Name == null)
            {
                return(null);
            }
            attribute.ByteOffset = 0;
            attribute.ByteStride = 0;

            // create a buffer
            var vbuffer = new ArraySegment <byte>(new Byte[attribute.PaddedByteLength * vertices.Count]);

            // fill the buffer with the vertex attributes.
            var accessor = new MemoryAccessor(vbuffer, attribute);

            accessor.FillAccessor(vertices);

            return(accessor);
        }
Example #2
0
        public static MemoryAccessor CreateVertexMemoryAccessors <TVertex>(this IReadOnlyList <TVertex> vertices, string attributeName)
            where TVertex : IVertexBuilder
        {
            if (vertices == null || vertices.Count == 0)
            {
                return(null);
            }

            // determine the vertex attributes from the first vertex.
            var attributes = GetVertexAttributes(vertices[0], vertices.Count);

            var isMorphTangent = attributeName == "MORPHTANGENT";

            if (isMorphTangent)
            {
                attributeName = "TANGENT";
            }

            var attribute = attributes.FirstOrDefault(item => item.Name == attributeName);

            if (attribute.Name == null)
            {
                return(null);
            }
            attribute.ByteOffset = 0;
            attribute.ByteStride = 0;
            if (isMorphTangent)
            {
                attribute.Dimensions = Schema2.DimensionType.VEC3;
            }

            // create a buffer
            var vbuffer = new ArraySegment <byte>(new Byte[attribute.PaddedByteLength * vertices.Count]);

            // fill the buffer with the vertex attributes.
            var accessor = new MemoryAccessor(vbuffer, attribute);

            if (isMorphTangent)
            {
                var columnFunc = _GetVertexBuilderAttributeFunc("MORPHTANGENT");
                accessor.AsVector3Array().Fill(vertices._GetColumn <TVertex, Vector3>(columnFunc));
            }
            else
            {
                accessor.FillAccessor(vertices);
            }

            return(accessor);
        }