Example #1
0
        public static byte[] GetBytes(uint imageBase, bool DX, Dictionary <string, uint> labels, List <uint> njOffsets, List <XJMesh> xjMeshes, out uint address)
        {
            List <byte> result          = new List <byte>();
            List <int>  matOffsetList   = new List <int>();
            List <int>  stripOffsetList = new List <int>();

            address = (uint)result.Count;
            for (int i = 0; i < xjMeshes.Count; i++)
            {
                matOffsetList.Add(result.Count);
                stripOffsetList.Add(result.Count + 0x8);
                njOffsets.Add((uint)(result.Count + imageBase));
                njOffsets.Add((uint)(result.Count + imageBase + 0x8));
                result.AddRange(ByteConverter.GetBytes(0));
                result.AddRange(ByteConverter.GetBytes(3));
                result.AddRange(ByteConverter.GetBytes(0));
                result.AddRange(ByteConverter.GetBytes(xjMeshes[i].stripIndices.Length / 2));
                result.AddRange(ByteConverter.GetBytes(0));
            }
            result.Align(0x10);

            for (int i = 0; i < xjMeshes.Count; i++)
            {
                var mesh = xjMeshes[i];
                //Material
                result.SetByteListInt(matOffsetList[i], (int)(result.Count + imageBase));

                //Blend types
                result.AddRange(ByteConverter.GetBytes(2));
                result.AddRange(ByteConverter.GetBytes((uint)mesh.mat.SourceAlpha));
                result.AddRange(ByteConverter.GetBytes((uint)mesh.mat.DestinationAlpha));
                result.AddRange(ByteConverter.GetBytes(0));
                //Texture ID
                result.AddRange(ByteConverter.GetBytes(3));
                result.AddRange(ByteConverter.GetBytes((uint)mesh.mat.TextureID));
                result.AddRange(ByteConverter.GetBytes(0));
                result.AddRange(ByteConverter.GetBytes(0));
                //Diffuse color
                result.AddRange(ByteConverter.GetBytes(5));
                result.AddRange(VColor.GetBytes(mesh.mat.DiffuseColor, ColorType.RGBA8888_32));
                result.AddRange(ByteConverter.GetBytes(0));
                result.AddRange(ByteConverter.GetBytes(0));
                result.Align(0x10);

                //Strips
                result.SetByteListInt(stripOffsetList[i], (int)(result.Count + imageBase));
                result.AddRange(mesh.stripIndices);
                result.Align(0x10);
            }

            return(result.ToArray());
        }
Example #2
0
        public byte[] GetBytes(uint imageBase, bool DX, Dictionary <string, uint> labels, List <uint> njOffsets, out uint address)
        {
            bool hasUV     = (VertexType & 0x1) > 0;
            bool hasNormal = (VertexType & 0x2) > 0;
            bool hasColor  = (VertexType & 0x4) > 0;
            bool hasUnk0   = (VertexType & 0x8) > 0;
            bool hasUnk1   = (VertexType & 0x10) > 0;
            bool hasUnk2   = (VertexType & 0x20) > 0;
            bool hasUnk3   = (VertexType & 0x40) > 0;
            bool hasUnk4   = (VertexType & 0x80) > 0;

            List <byte> result = new List <byte>();

            for (int i = 0; i < Positions.Count; i++)
            {
                result.AddRange(Positions[i].GetBytes());
                if (hasNormal)
                {
                    result.AddRange(Normals[i].GetBytes());
                }
                if (hasColor)
                {
                    result.AddRange(VColor.GetBytes(Colors[i], ColorType.RGBA8888_32));
                }
                if (hasUV)
                {
                    result.AddRange(UVs[i].GetBytesXJ());
                }
            }
            result.Align(0x10);

            address = (uint)(result.Count);
            njOffsets.Add((uint)result.Count + imageBase + 4);
            result.AddRange(ByteConverter.GetBytes(VertexType));
            result.AddRange(ByteConverter.GetBytes(Ushort_02));
            result.AddRange(ByteConverter.GetBytes(imageBase));
            result.AddRange(ByteConverter.GetBytes(VertexSize));
            result.AddRange(ByteConverter.GetBytes(Positions.Count));

            result.Align(0x10);

            return(result.ToArray());
        }