private static VertexData GenerateVertexData(IExportContainer container, Mesh origin) { Vector3f[] normals = origin.Normals; Vector4f[] tangents = origin.Tangents; if (Mesh.HasTangentSpace(container.Version)) { normals = TangentConverter.GenerateNormals(origin.TangentSpace); tangents = TangentConverter.GenerateTangents(origin.TangentSpace); } VertexData instance = new VertexData(); bool hasVertices = origin.Vertices.Length > 0; bool hasNormals = normals.Length > 0; bool hasColors = origin.Colors.Length > 0; bool hasUV0 = origin.UV.Length > 0; bool hasUV1 = Mesh.HasUV1(container.Version) && origin.UV1.Length > 0; bool hasTangents = tangents.Length > 0; bool hasChannels = VertexData.HasChannels(container.ExportVersion); if (hasChannels) { int channelCount = ShaderChannelExtensions.GetChannelCount(container.ExportVersion); instance.Channels = new ChannelInfo[channelCount]; } byte stride = 0; BitArray curChannels = new BitArray(32); if (hasVertices) { int index = ShaderChannel.Vertex.ToChannel(container.ExportVersion); curChannels.Set(index, true); if (hasChannels) { byte format = ShaderChannel.Vertex.GetVertexFormat(container.ExportVersion).ToFormat(container.ExportVersion); byte dimention = ShaderChannel.Vertex.GetDimention(container.ExportVersion); instance.Channels[index] = new ChannelInfo(0, stride, format, dimention); } stride += ShaderChannel.Vertex.GetStride(container.ExportVersion); } if (hasNormals) { int index = ShaderChannel.Normal.ToChannel(container.ExportVersion); curChannels.Set(index, true); if (hasChannels) { byte format = ShaderChannel.Normal.GetVertexFormat(container.ExportVersion).ToFormat(container.ExportVersion); byte dimention = ShaderChannel.Normal.GetDimention(container.ExportVersion); instance.Channels[index] = new ChannelInfo(0, stride, format, dimention); } stride += ShaderChannel.Normal.GetStride(container.ExportVersion); } if (hasColors) { int index = ShaderChannel.Color.ToChannel(container.ExportVersion); curChannels.Set(index, true); if (hasChannels) { byte format = ShaderChannel.Color.GetVertexFormat(container.ExportVersion).ToFormat(container.ExportVersion); byte dimention = ShaderChannel.Color.GetDimention(container.ExportVersion); instance.Channels[index] = new ChannelInfo(0, stride, format, dimention); } stride += ShaderChannel.Color.GetStride(container.ExportVersion); } if (hasUV0) { int index = ShaderChannel.UV0.ToChannel(container.ExportVersion); curChannels.Set(index, true); if (hasChannels) { byte format = ShaderChannel.UV0.GetVertexFormat(container.ExportVersion).ToFormat(container.ExportVersion); byte dimention = ShaderChannel.UV0.GetDimention(container.ExportVersion); instance.Channels[index] = new ChannelInfo(0, stride, format, dimention); } stride += ShaderChannel.UV0.GetStride(container.ExportVersion); } if (hasUV1) { int index = ShaderChannel.UV1.ToChannel(container.ExportVersion); curChannels.Set(index, true); if (hasChannels) { byte format = ShaderChannel.UV1.GetVertexFormat(container.ExportVersion).ToFormat(container.ExportVersion); byte dimention = ShaderChannel.UV1.GetDimention(container.ExportVersion); instance.Channels[index] = new ChannelInfo(0, stride, format, dimention); } stride += ShaderChannel.UV1.GetStride(container.ExportVersion); } if (hasTangents) { int index = ShaderChannel.Tangent.ToChannel(container.ExportVersion); curChannels.Set(index, true); if (hasChannels) { byte format = ShaderChannel.Tangent.GetVertexFormat(container.ExportVersion).ToFormat(container.ExportVersion); byte dimention = ShaderChannel.Tangent.GetDimention(container.ExportVersion); instance.Channels[index] = new ChannelInfo(0, stride, format, dimention); } stride += ShaderChannel.Tangent.GetStride(container.ExportVersion); } if (VertexData.HasCurrentChannels(container.ExportVersion)) { instance.CurrentChannels = curChannels.ToUInt32(); } instance.VertexCount = origin.Vertices.Length; if (VertexData.HasStreams(container.ExportVersion)) { StreamInfo info = new StreamInfo(instance.CurrentChannels, 0, stride); if (VertexData.IsStreamStatic(container.ExportVersion)) { instance.Streams = new StreamInfo[] { info, default, default, default, };
private static Vector4f[] GetTangents(IExportContainer container, Mesh origin) { return(Mesh.HasTangentSpace(container.Version) ? TangentConverter.GenerateTangents(origin.TangentSpace) : origin.Tangents.ToArray()); }