public static ChannelInfo Convert(IExportContainer container, ChannelInfo origin)
        {
            ChannelInfo instance = origin;

            if (origin.IsSet)
            {
                if (VertexFormatExtensions.VertexFormat2019Relevant(container.Version))
                {
                }
                else if (ShaderChannelExtensions.ShaderChannel5Relevant(container.Version))
                {
                    if (VertexFormatExtensions.VertexFormat2019Relevant(container.ExportVersion))
                    {
                        instance.Format = origin.GetVertexFormat(container.Version).ToFormat(container.ExportVersion);
                    }
                }
                else
                {
                    if (container.ExportVersion.IsGreaterEqual(5))
                    {
                        VertexChannelFormat formatv4 = (VertexChannelFormat)origin.Format;
                        instance.Format = formatv4.ToVertexFormat().ToFormat(container.ExportVersion);
                        if (formatv4 == VertexChannelFormat.Color)
                        {
                            // replace Color4b[1] to Color1b[4]
                            instance.RawDimension = (byte)(instance.Dimension * 4);
                        }
                    }
                }
            }
            return(instance);
        }
Beispiel #2
0
 private static uint GetCurrentChannels(IExportContainer container, ref VertexData origin)
 {
     if (ShaderChannelExtensions.ShaderChannel5Relevant(container.Version))
     {
         return(origin.CurrentChannels);
     }
     else
     {
         BitArray curBits = new BitArray(BitConverter.GetBytes(origin.CurrentChannels));
         curBits.Set((int)ShaderChannel5.Tangent, curBits.Get((int)ShaderChannel4.Tangent));
         curBits.Set((int)ShaderChannel4.Tangent, false);
         return(curBits.ToUInt32());
     }
 }
Beispiel #3
0
        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, };