public static MemoryAccessInfo[] GetVertexAttributes(this IVertexBuilder firstVertex, int vertexCount, Schema2.EncodingType jointEncoding) { var tvg = firstVertex.GetGeometry().GetType(); var tvm = firstVertex.GetMaterial().GetType(); var tvs = firstVertex.GetSkinning().GetType(); var attributes = new List <MemoryAccessInfo>(); foreach (var finfo in tvg.GetFields()) { var attribute = _GetMemoryAccessInfo(finfo); if (attribute.HasValue) { attributes.Add(attribute.Value); } } foreach (var finfo in tvm.GetFields()) { var attribute = _GetMemoryAccessInfo(finfo); if (attribute.HasValue) { attributes.Add(attribute.Value); } } foreach (var finfo in tvs.GetFields()) { var attribute = _GetMemoryAccessInfo(finfo); if (attribute.HasValue) { var a = attribute.Value; if (a.Name.StartsWith("JOINTS_", StringComparison.OrdinalIgnoreCase)) { a.Encoding = jointEncoding; } attributes.Add(a); } } var array = attributes.ToArray(); MemoryAccessInfo.SetInterleavedInfo(array, 0, vertexCount); return(array); }
public static MemoryAccessor CreateIndexMemoryAccessor(this IReadOnlyList <Int32> indices, Schema2.EncodingType encoding) { if (indices == null || indices.Count == 0) { return(null); } var attribute = new MemoryAccessInfo("INDEX", 0, indices.Count, 0, Schema2.DimensionType.SCALAR, encoding); // create buffer var ibytes = new Byte[encoding.ByteLength() * indices.Count]; var ibuffer = new ArraySegment <byte>(ibytes); // fill the buffer with indices. var accessor = new MemoryAccessor(ibuffer, attribute.Slice(0, indices.Count)); accessor.AsIntegerArray().Fill(indices); return(accessor); }
public static MemoryAccessor[] CreateVertexMemoryAccessors <TVertex>(this IReadOnlyList <TVertex> vertices, 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); // create a buffer int byteStride = attributes[0].ByteStride; var vbuffer = new ArraySegment <byte>(new Byte[byteStride * vertices.Count]); // fill the buffer with the vertex attributes. var accessors = MemoryAccessInfo .Slice(attributes, 0, vertices.Count) .Select(item => new MemoryAccessor(vbuffer, item)) .ToArray(); foreach (var accessor in accessors) { accessor.FillAccessor(vertices); } return(accessors); }
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); }
public VertexAttributeAttribute(string attributeName, Schema2.EncodingType encoding, Boolean normalized) { this.Name = attributeName; this.Encoding = encoding; this.Normalized = normalized; }
private static FloatingAccessor _CreateFloatingAccessor(byte[] data, Schema2.EncodingType encoding, bool normalized) { return(new FloatingAccessor(new ArraySegment <byte>(data), 0, int.MaxValue, 0, 1, encoding, normalized)); }