示例#1
0
文件: LM.cs 项目: nnn1590/Smash-Forge
            public void Write(FileOutput o)
            {
                Console.WriteLine($"Properties {{ // offset=0x{o.size():X2}");
                Console.WriteLine($"\tunk0: 0x{unk0:X8}");
                Console.WriteLine($"\tunk1: 0x{unk1:X8}");
                Console.WriteLine($"\tunk2: 0x{unk2:X8}");
                Console.WriteLine($"\tmaxCharacterId: 0x{maxCharacterId:X8}");
                Console.WriteLine($"\tunk4: 0x{unk4:X8}");
                Console.WriteLine($"\tmaxCharacterId2: 0x{maxCharacterId2:X2}");
                Console.WriteLine($"\tmaxDepth: 0x{maxDepth:X4}");
                Console.WriteLine($"\tunk7: 0x{unk7:X4}");
                Console.WriteLine($"\tframerate: {framerate}");
                Console.WriteLine($"\tdimensions: {width}x{height}");
                Console.WriteLine($"\tunk8: 0x{unk8:X8}");
                Console.WriteLine($"\tunk9: 0x{unk9:X8}");
                Console.WriteLine("}\n");

                o.writeInt((int)TagType.Properties);
                o.writeInt(12);

                o.writeInt((int)unk0);
                o.writeInt((int)unk1);
                o.writeInt((int)unk2);
                o.writeInt((int)maxCharacterId);
                o.writeInt(unk4);
                o.writeInt((int)maxCharacterId2);
                o.writeShort((short)maxDepth);
                o.writeShort((short)unk7);
                o.writeFloat(framerate);
                o.writeFloat(width);
                o.writeFloat(height);
                o.writeInt((int)unk8);
                o.writeInt((int)unk9);
            }
示例#2
0
文件: LM.cs 项目: nnn1590/Smash-Forge
 public void Write(FileOutput o)
 {
     o.writeInt((int)TagType.RemoveObject);
     o.writeInt(2);
     o.writeInt(Unk1);
     o.writeShort(Depth);
     o.writeShort(Unk2);
 }
示例#3
0
        public override byte[] Rebuild()
        {
            FileOutput buf = new FileOutput();

            buf.Endian = Endianness.Little;

            var flagsOffset   = 0x10;
            var entriesOffset = flagsOffset + (atlases.Count * 4);
            var stringsOffset = entriesOffset + (textures.Count * 0x20);

            buf.writeInt(0x544C5354); // TLST
            buf.writeShort(0);        // idk
            buf.writeShort((short)atlases.Count);
            buf.writeShort((short)textures.Count);
            buf.writeShort((short)flagsOffset);
            buf.writeShort((short)entriesOffset);
            buf.writeShort((short)stringsOffset);

            // flags
            foreach (var flag in atlases)
            {
                buf.writeInt((int)flag);
            }

            // entries
            int namePtr = 0;

            foreach (var texture in textures)
            {
                buf.writeInt(namePtr);
                buf.writeInt(namePtr);
                namePtr += texture.name.Length + 1;

                buf.writeFloat(texture.topLeft.X);
                buf.writeFloat(texture.topLeft.Y);
                buf.writeFloat(texture.botRight.X);
                buf.writeFloat(texture.botRight.Y);

                buf.writeShort(texture.width);
                buf.writeShort(texture.height);
                buf.writeShort(texture.atlasId);
                buf.writeShort(0); // pad
            }

            //strings
            foreach (var texture in textures)
            {
                buf.writeString(texture.name);
                buf.writeByte(0);
            }

            buf.writeByte(0);

            return(buf.getBytes());
        }
示例#4
0
        public void Write(FileOutput file)
        {
            file.writeShort(unk1);
            file.writeShort(events.Count);
            file.writeShort(unk2);
            file.writeShort(unk3);

            for (int i = 0; i < events.Count; ++i)
            {
                events[i].Write(file);
            }
        }
示例#5
0
        public override byte[] Rebuild()
        {
            FileOutput o = new FileOutput();

            o.Endian = Endianness.Little;

            o.writeString(" BWS");
            o.writeShort(0x05);
            o.writeShort(0x01);
            o.writeInt(bones.Count);

            foreach (SBEntry s in bones)
            {
                o.writeInt((int)s.hash);
                o.writeFloat(s.param1_1);
                o.writeInt(s.param1_2);
                o.writeInt(s.param1_3);
                o.writeFloat(s.param2_1);
                o.writeFloat(s.param2_2);
                o.writeInt(s.param2_3);
                o.writeFloat(s.rx1);
                o.writeFloat(s.rx2);
                o.writeFloat(s.ry1);
                o.writeFloat(s.ry2);
                o.writeFloat(s.rz1);
                o.writeFloat(s.rz2);

                for (int j = 0; j < 8; j++)
                {
                    o.writeInt((int)s.boneHashes[j]);
                }

                for (int j = 0; j < 4; j++)
                {
                    o.writeFloat(s.unks1[j]);
                }

                for (int j = 0; j < 6; j++)
                {
                    o.writeFloat(s.unks2[j]);
                }

                o.writeFloat(s.factor);

                for (int j = 0; j < 3; j++)
                {
                    o.writeInt(s.ints[j]);
                }
            }

            return(o.getBytes());
        }
示例#6
0
        public override byte[] Rebuild()
        {
            FileOutput file = new FileOutput();
            if (file != null)
            {
                
                if (Endian == Endianness.Little) {
                    file.Endian = Endianness.Little;
                    file.writeString(" NBV");
                }
                if (Endian == Endianness.Big) {
                    file.Endian = Endianness.Big;
                    file.writeString("VBN ");
                }

                file.writeShort(0x01);
                file.writeShort(0x02);
                file.writeInt(bones.Count);
                if (boneCountPerType[0] == 0)
                    boneCountPerType[0] = (uint)bones.Count;
                for (int i = 0; i < 4; i++)
                    file.writeInt((int)boneCountPerType[i]);

                for (int i = 0; i < bones.Count; i++)
                {
                    file.writeString(new string(bones[i].boneName));
                    for (int j = 0; j < 64 - bones[i].boneName.Length; j++)
                        file.writeByte(0);
                    file.writeInt((int)bones[i].boneType);
                    if(bones[i].parentIndex == -1)
                        file.writeInt(0x0FFFFFFF);
                    else
                        file.writeInt(bones[i].parentIndex);
                    file.writeInt((int)bones[i].boneId);
                }

                for (int i = 0; i < bones.Count; i++)
                {
                    file.writeFloat(bones[i].position[0]);
                    file.writeFloat(bones[i].position[1]);
                    file.writeFloat(bones[i].position[2]);
                    file.writeFloat(bones[i].rotation[0]);
                    file.writeFloat(bones[i].rotation[1]);
                    file.writeFloat(bones[i].rotation[2]);
                    file.writeFloat(bones[i].scale[0]);
                    file.writeFloat(bones[i].scale[1]);
                    file.writeFloat(bones[i].scale[2]);
                }
            }
            return file.getBytes();
        }
示例#7
0
文件: LM.cs 项目: nnn1590/Smash-Forge
                public void Write(FileOutput o)
                {
                    o.writeInt((int)TagType.PlaceObject);
                    o.writeInt(12);

                    o.writeInt(CharacterId);
                    o.writeInt(PlacementId);
                    o.writeInt(Unk1);
                    o.writeInt(NameId);
                    o.writeShort((short)Flags);
                    o.writeShort((short)BlendMode);
                    o.writeShort(Depth);
                    o.writeShort(Unk4);
                    o.writeShort(Unk5);
                    o.writeShort(Unk6);
                    o.writeShort((short)PositionFlags);
                    o.writeShort(PositionId);
                    o.writeInt(ColorMultId);
                    o.writeInt(ColorAddId);

                    o.writeInt((ColorMatrix != null) ? 1 : 0);
                    o.writeInt((UnkF014 != null) ? 1 : 0);

                    if (ColorMatrix != null)
                    {
                        ColorMatrix.Write(o);
                    }

                    if (UnkF014 != null)
                    {
                        UnkF014.Write(o);
                    }
                }
示例#8
0
        public static byte[] FromIDSP(byte[] idsp)
        {
            File.WriteAllBytes("temp.idsp", idsp);
            IntPtr vgm = VGMStreamNative.InitVGMStream("temp.idsp");

            if (vgm == IntPtr.Zero)
            {
                throw new Exception("Error loading idsp");
            }

            int channelCount = VGMStreamNative.GetVGMStreamChannelCount(vgm);
            int bitsPerFrame = VGMStreamNative.GetVGMStreamFrameSize(vgm);
            int size         = VGMStreamNative.GetVGMStreamTotalSamples(vgm);
            int samplerate   = VGMStreamNative.GetVGMStreamSampleRate(vgm);

            int total = (int)((samplerate * bitsPerFrame * channelCount * (size / 24576000f)) / 8 * 1024);

            short[] buffer = new short[total];
            VGMStreamNative.RenderVGMStream(buffer, buffer.Length / 2, vgm);

            FileOutput o = new FileOutput();

            o.Endian = Endianness.Little;

            o.writeString("RIFF");
            o.writeInt(0);
            o.writeString("WAVEfmt ");

            o.writeInt(0x10);
            o.writeShort(1);
            o.writeShort(channelCount);
            o.writeInt(samplerate);
            o.writeInt(size);
            o.writeShort(2);
            o.writeShort(0x10);

            o.writeString("data");
            o.writeInt(buffer.Length);

            for (int i = 0; i < buffer.Length / 2; i++)
            {
                o.writeShort(buffer[i]);
            }

            o.writeIntAt(o.size() - 8, 4);

            VGMStreamNative.CloseVGMStream(vgm);
            File.Delete("temp.idsp");
            return(o.getBytes());
        }
示例#9
0
        public void ExportTEX(string filename)
        {
            FileOutput o = new FileOutput();

            o.Endian = Endianness.Little;

            o.writeInt(pictureBox1.Image.Width);
            o.writeInt(pictureBox1.Image.Height);
            o.writeByte(formatSelector.SelectedIndex);
            o.writeByte(1);
            o.writeShort(0);
            o.writeString(nameBox.Text);
            for (int i = 0; i < 0x74 - nameBox.Text.Length; i++)
            {
                o.writeByte(0);
            }

            pictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipY);

            o.writeBytes(_3DS.EncodeImage(new Bitmap(pictureBox1.Image), (_3DS.Tex_Formats)formatSelector.SelectedIndex));

            pictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipY);

            o.save(filename);
        }
示例#10
0
文件: LM.cs 项目: nnn1590/Smash-Forge
        void writeColors(FileOutput o)
        {
            Console.WriteLine($"Colors = [ // offset=0x{o.size():X2}");

            o.writeInt((int)TagType.Colors);
            o.writeInt(Colors.Count * 2 + 1);
            o.writeInt(Colors.Count);

            for (int i = 0; i < Colors.Count; i++)
            {
                var color = Colors[i];
                Console.WriteLine($"\t0x{i:X3}: #{(byte)(color.X * 255):X2}{(byte)(color.Z * 255):X2}{(byte)(color.Y * 255):X2}, {(byte)(color.W * 255):X2} // offset=0x{o.size():X2}");
                o.writeShort((short)(color.X * 256));
                o.writeShort((short)(color.Y * 256));
                o.writeShort((short)(color.Z * 256));
                o.writeShort((short)(color.W * 256));
            }
            Console.WriteLine("]\n");
        }
示例#11
0
        public byte[] Rebuild(int pos)
        {
            FileOutput f = new FileOutput();

            f.Endian = Endianness.Big;

            f.writeInt(pos + f.pos() + 0x20);
            f.writeInt(Convert.ToInt32(unk1));
            int offset = pos + f.pos() + 0x18;

            offset += name.Length + 1;
            while (offset % 16 != 0)
            {
                offset++;
            }
            offset += 0x10;
            f.writeInt(offset);
            f.writeBytes(new byte[0x14]);
            f.writeString(name);
            f.writeByte(0);
            while ((pos + f.pos()) % 16 != 0)
            {
                f.writeByte(0);
            }
            f.writeBytes(new byte[0x10]);
            f.writeInt(frameCount);
            f.writeShort(Convert.ToInt32(unk2));
            f.writeShort(frames.Count);
            f.writeInt(pos + f.pos() + 0x18);
            f.writeBytes(new byte[0x14]);
            foreach (frame keyframe in frames)
            {
                f.writeShort(keyframe.frameNum);
                f.writeByte(keyframe.state);
                f.writeByte(keyframe.unknown);
            }

            return(f.getBytes());
        }
示例#12
0
        public byte[] Rebuild(int pos)
        {
            FileOutput f = new FileOutput();

            f.Endian = Endianness.Big;

            f.writeInt(pos + f.pos() + 0x20);
            f.writeInt(unknown);
            f.writeInt(valueCount);
            f.writeInt(frames.Count);
            f.writeShort(unknown2);
            f.writeShort(unknown3);
            int position = pos + f.pos() + 0xC + name.Length + 1;

            while (position % 0x10 != 0)
            {
                position++;
            }

            f.writeInt(position);
            f.writeBytes(new byte[8]);
            f.writeString(name);
            f.writeByte(0);
            while ((pos + f.pos()) % 0x10 != 0)
            {
                f.writeByte(0);
            }

            foreach (frame fr in frames)
            {
                for (int i = 0; i < valueCount; i++)
                {
                    f.writeFloat(fr.values[i]);
                }
            }
            f.writeBytes(new byte[0x10]);

            return(f.getBytes());
        }
示例#13
0
        public override byte[] Rebuild()
        {
            FileOutput file = new FileOutput();

            file.Endian = Endianness.Little;

            file.writeHex("53514200"); //SQB

            file.writeShort(unk1);
            file.writeShort(unk2);

            file.writeInt(sequences.Count);
            file.writeInt(sequences.Count * 0x4);

            int currentOffset = 0;

            for (int i = 0; i < sequences.Count; ++i)
            {
                if (sequences[i].empty)
                {
                    file.writeInt(-1);
                    continue;
                }
                file.writeInt(currentOffset);
                currentOffset += 0x8 + (0x10 * sequences[i].events.Count);
            }

            for (int i = 0; i < sequences.Count; ++i)
            {
                if (sequences[i].empty)
                {
                    continue;
                }
                sequences[i].Write(file);
            }

            return(file.getBytes());
        }
示例#14
0
文件: LM.cs 项目: nnn1590/Smash-Forge
            public void Write(FileOutput o)
            {
                o.writeInt((int)TagType.DynamicText);
                o.writeInt(16);

                o.writeInt(CharacterId);
                o.writeInt(unk1);
                o.writeInt(placeholderTextId);
                o.writeInt(unk2);
                o.writeInt(strokeColorId);
                o.writeInt(unk3);
                o.writeInt(unk4);
                o.writeInt(unk5);
                o.writeShort((short)alignment);
                o.writeShort(unk6);
                o.writeInt(unk7);
                o.writeInt(unk8);
                o.writeFloat(size);
                o.writeInt(unk9);
                o.writeInt(unk10);
                o.writeInt(unk11);
                o.writeInt(unk12);
            }
示例#15
0
            public int Rebuild(FileOutput o)
            {
                o.writeString("PROP");
                int sizeoff = o.size();

                o.writeInt(0);
                int size = o.size();

                o.writeInt(0);
                o.writeInt(unk1);
                o.writeShort(0);
                o.writeShort(unk2);

                o.writeByte(project.Length + 1);
                o.writeString(project);
                o.writeByte(0);
                o.writeByte(0);
                o.writeByte(0);
                o.writeByte(0);
                o.align(4);
                o.writeShort(unk3);
                o.align(4);


                o.writeByte(timestamp.Length + 1);
                o.writeString(timestamp);
                o.writeByte(0);
                o.writeByte(0);
                o.writeByte(0);
                o.writeByte(0);
                o.align(4);

                size = o.size() - size;
                o.writeIntAt(size, sizeoff);
                return(size);
            }
示例#16
0
 public void Write(FileOutput file)
 {
     file.writeInt((int)hash);
     file.writeShort(type);
     file.writeShort(frame);
     file.writeShort(unk1);
     file.writeShort(unk2);
     file.writeShort(unk3);
     file.writeShort(unk4);
 }
示例#17
0
                public void Play()
                {
                    // this cannot be very fast .-.
                    // if anyone know how to pass the file via a byte array then that would be great...
                    File.WriteAllBytes("temp.idsp", idsp);
                    Console.WriteLine("here");
                    IntPtr vgm = VGMStreamNative.InitVGMStream("temp.idsp");

                    if (vgm == IntPtr.Zero)
                    {
                        throw new Exception("Error loading idsp");
                    }

                    Console.WriteLine("here");
                    int channelCount = VGMStreamNative.GetVGMStreamChannelCount(vgm);
                    int bitsPerFrame = VGMStreamNative.GetVGMStreamFrameSize(vgm);
                    int size         = VGMStreamNative.GetVGMStreamTotalSamples(vgm);
                    int samplerate   = VGMStreamNative.GetVGMStreamSampleRate(vgm);

                    Console.WriteLine("here");

                    int total = (int)((samplerate * bitsPerFrame * channelCount * (size / 24576000f)) / 8 * 1024);

                    //Console.WriteLine(channelCount + " " + bitsPerFrame + " " + size + " " + samplerate + " " + total.ToString("x"));

                    short[] buffer = new short[total];

                    VGMStreamNative.RenderVGMStream(buffer, buffer.Length / 2, vgm);
                    Console.WriteLine("here");

                    FileOutput o = new FileOutput();

                    o.Endian = Endianness.Little;
                    for (int i = 0; i < buffer.Length / 2; i++)
                    {
                        o.writeShort(buffer[i]);
                    }
                    o.save("test.wav");
                    Console.WriteLine("here");
                    WAVE.Play(o.getBytes(), VGMStreamNative.GetVGMStreamChannelCount(vgm), VGMStreamNative.GetVGMStreamSamplesPerFrame(vgm), VGMStreamNative.GetVGMStreamSampleRate(vgm));

                    VGMStreamNative.CloseVGMStream(vgm);
                    File.Delete("temp.idsp");
                }
示例#18
0
        private static void writeType(FileOutput d, float value, int format, float scale)
        {
            switch (format)
            {
            case 0:
                d.writeFloat(value / scale);
                break;

            case 1:
                d.writeByte((byte)(value / scale));
                break;

            case 2:
                d.writeByte((byte)(value / scale));
                break;

            case 3:
                d.writeShort((short)(value / scale));
                break;
            }
        }
示例#19
0
            private void WriteType(FileOutput d, float data)
            {
                switch (format)
                {
                case 0:
                    d.writeFloat(data / scale);
                    break;

                case 1:
                    d.writeByte((byte)(data / scale));
                    break;

                case 2:
                    d.writeByte((sbyte)(data / scale));
                    break;

                case 3:
                    d.writeShort((int)(data / scale));
                    break;
                }
            }
示例#20
0
        public void ExportTEX(string filename)
        {
            FileOutput o = new FileOutput();

            o.Endian = Endianness.Little;

            o.writeInt(pictureBox1.Image.Width);
            o.writeInt(pictureBox1.Image.Height);
            o.writeByte(formatSelector.SelectedIndex);
            o.writeByte(1);
            o.writeShort(0);
            o.writeString(nameBox.Text);
            for (int i = 0; i < 0x74 - nameBox.Text.Length; i++)
            {
                o.writeByte(0);
            }

            pictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipY);

            if (formatSelector.SelectedIndex == 0x0C)
            {
                o.writeBytes(Pixel.encodeETC(new Bitmap(pictureBox1.Image)));
            }
            if (formatSelector.SelectedIndex == 0x0D)
            {
                o.writeBytes(Pixel.encodeETCa4(new Bitmap(pictureBox1.Image)));
            }
            else
            {
                throw new Exception("Unsuppored format");
            }

            pictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipY);

            o.save(filename);
        }
示例#21
0
        public override byte[] Rebuild()
        {
            FileOutput o    = new FileOutput();
            FileOutput data = new FileOutput();

            o.writeUInt(0x4E545033); // "NTP3"
            o.writeUShort(Version);
            o.writeUShort((ushort)Nodes.Count);
            o.writeInt(0);
            o.writeInt(0);

            //calculate total header size
            uint headerLength = 0;

            foreach (NutTexture texture in Nodes)
            {
                byte surfaceCount = (byte)texture.surfaces.Count;
                bool isCubemap    = surfaceCount == 6;
                if (surfaceCount < 1 || surfaceCount > 6)
                {
                    throw new NotImplementedException($"Unsupported surface amount {surfaceCount} for texture with hash 0x{texture.HashId:X}. 1 to 6 faces are required.");
                }
                else if (surfaceCount > 1 && surfaceCount < 6)
                {
                    throw new NotImplementedException($"Unsupported cubemap face amount for texture with hash 0x{texture.HashId:X}. Six faces are required.");
                }
                byte mipmapCount = (byte)texture.surfaces[0].mipmaps.Count;

                ushort headerSize = 0x50;
                if (isCubemap)
                {
                    headerSize += 0x10;
                }
                if (mipmapCount > 1)
                {
                    headerSize += (ushort)(mipmapCount * 4);
                    while (headerSize % 0x10 != 0)
                    {
                        headerSize += 1;
                    }
                }

                headerLength += headerSize;
            }

            // write headers+data
            foreach (NutTexture texture in Nodes)
            {
                byte surfaceCount = (byte)texture.surfaces.Count;
                bool isCubemap    = surfaceCount == 6;
                byte mipmapCount  = (byte)texture.surfaces[0].mipmaps.Count;

                uint dataSize = 0;

                foreach (var mip in texture.GetAllMipmaps())
                {
                    dataSize += (uint)mip.Length;
                    while (dataSize % 0x10 != 0)
                    {
                        dataSize += 1;
                    }
                }

                ushort headerSize = 0x50;
                if (isCubemap)
                {
                    headerSize += 0x10;
                }
                if (mipmapCount > 1)
                {
                    headerSize += (ushort)(mipmapCount * 4);
                    while (headerSize % 0x10 != 0)
                    {
                        headerSize += 1;
                    }
                }

                o.writeUInt(dataSize + headerSize);
                o.writeUInt(0);
                o.writeUInt(dataSize);
                o.writeUShort(headerSize);
                o.writeUShort(0);

                o.writeByte(0);
                o.writeByte(mipmapCount);
                o.writeByte(0);
                o.writeByte(texture.getNutFormat());
                o.writeShort(texture.Width);
                o.writeShort(texture.Height);
                o.writeInt(0);
                o.writeUInt(texture.DdsCaps2);

                o.writeUInt((uint)(headerLength + data.size()));
                headerLength -= headerSize;
                o.writeInt(0);
                o.writeInt(0);
                o.writeInt(0);

                if (isCubemap)
                {
                    o.writeInt(texture.surfaces[0].mipmaps[0].Length);
                    o.writeInt(texture.surfaces[0].mipmaps[0].Length);
                    o.writeInt(0);
                    o.writeInt(0);
                }

                if (texture.getNutFormat() == 14 || texture.getNutFormat() == 17)
                {
                    texture.SwapChannelOrderDown();
                }

                for (byte surfaceLevel = 0; surfaceLevel < surfaceCount; ++surfaceLevel)
                {
                    for (byte mipLevel = 0; mipLevel < mipmapCount; ++mipLevel)
                    {
                        int ds = data.size();
                        data.writeBytes(texture.surfaces[surfaceLevel].mipmaps[mipLevel]);
                        data.align(0x10);
                        if (mipmapCount > 1 && surfaceLevel == 0)
                        {
                            o.writeInt(data.size() - ds);
                        }
                    }
                }
                o.align(0x10);

                if (texture.getNutFormat() == 14 || texture.getNutFormat() == 17)
                {
                    texture.SwapChannelOrderUp();
                }

                o.writeUInt(0x65587400); // "eXt\0"
                o.writeInt(0x20);
                o.writeInt(0x10);
                o.writeInt(0x00);

                o.writeUInt(0x47494458); // "GIDX"
                o.writeInt(0x10);
                o.writeInt(texture.HashId);
                o.writeInt(0);
            }
            o.writeOutput(data);

            return(o.getBytes());
        }
示例#22
0
        public override byte[] Rebuild()
        {
            FileOutput f = new FileOutput();

            f.Endian = Endianness.Little;
            FileOutput fv = new FileOutput();

            fv.Endian = Endianness.Little;

            f.writeShort(format);
            f.writeShort(unknown);
            f.writeInt(flags);
            f.writeInt(mode);
            bool hasNameTable = (flags & 2) > 0;

            f.writeInt(mesh.Count);

            int vertSize = 0;

            // Vertex Bank
            for (int i = 0; i < 1; i++)
            {
                if (mode == 0 || i == 0)
                {
                    Descriptor des = descript[i];

                    if (format != 4)
                    {
                        foreach (Vertex v in vertices)
                        {
                            for (int k = 0; k < des.type.Length; k++)
                            {
                                fv.align(2, 0x00);
                                switch (des.type[k])
                                {
                                case 0:     //Position
                                    writeType(fv, v.pos.X, des.format[k], des.scale[k]);
                                    writeType(fv, v.pos.Y, des.format[k], des.scale[k]);
                                    writeType(fv, v.pos.Z, des.format[k], des.scale[k]);
                                    break;

                                case 1:     //Normal
                                    writeType(fv, v.nrm.X, des.format[k], des.scale[k]);
                                    writeType(fv, v.nrm.Y, des.format[k], des.scale[k]);
                                    writeType(fv, v.nrm.Z, des.format[k], des.scale[k]);
                                    break;

                                case 2:     //Color
                                    writeType(fv, v.col.X, des.format[k], des.scale[k]);
                                    writeType(fv, v.col.Y, des.format[k], des.scale[k]);
                                    writeType(fv, v.col.Z, des.format[k], des.scale[k]);
                                    writeType(fv, v.col.W, des.format[k], des.scale[k]);
                                    break;

                                case 3:     //Tex0
                                    writeType(fv, v.tx[0].X, des.format[k], des.scale[k]);
                                    writeType(fv, v.tx[0].Y, des.format[k], des.scale[k]);
                                    break;

                                case 4:     //Tex1
                                    writeType(fv, v.tx[1].X, des.format[k], des.scale[k]);
                                    writeType(fv, v.tx[1].Y, des.format[k], des.scale[k]);
                                    break;

                                case 5:     //Bone Index
                                    fv.writeByte(v.node[0]);
                                    fv.writeByte(v.node[1]);
                                    break;

                                case 6:     //Bone Weight
                                    writeType(fv, v.weight[0], des.format[k], des.scale[k]);
                                    writeType(fv, v.weight[1], des.format[k], des.scale[k]);
                                    break;
                                    //default:
                                    //    Console.WriteLine("WTF is this");
                                }
                            }
                        }
                        vertSize = fv.size();
                        fv.align(32, 0xFF);
                    }
                }


                for (int j = 0; j < mesh.Count; j++)
                {
                    foreach (List <int> l in mesh[j].faces)
                    {
                        foreach (int index in l)
                        {
                            fv.writeShort(index);
                        }
                        fv.align(32, 0xFF);
                    }
                }
            }


            for (int i = 0; i < mesh.Count; i++)
            {
                if (i == 0 && mode == 1)
                {
                    descript[0].WriteDescription(f);
                    f.writeInt(vertSize);
                }

                f.writeInt(mesh[i].nodeList.Count);
                //Console.WriteLine(mesh[i].faces.Count + " " + mesh[i].nodeList.Count);
                for (int j = 0; j < mesh[i].nodeList.Count; j++)
                {
                    f.writeInt(mesh[i].nodeList[j].Count);

                    for (int k = 0; k < mesh[i].nodeList[j].Count; k++)
                    {
                        f.writeInt(mesh[i].nodeList[j][k]);
                    }

                    f.writeInt(mesh[i].faces[j].Count);

                    // TODO: This stuff
                    if (hasNameTable)
                    {
                        //int nameId = d.readInt();
                    }

                    /*if (mode == 0)
                     * {
                     *  if (format == 4)
                     *  {
                     *      int[] buffer = new int[primitiveCount];
                     *      for (int k = 0; k < primitiveCount; k++)
                     *      {
                     *          buffer[k] = d.readShort();
                     *      }
                     *      d.align(4);
                     *      List<int> buf = new List<int>();
                     *      buf.AddRange(buffer);
                     *      m.faces.Add(buf);
                     *  }
                     *  else
                     *  {
                     *      Descriptor des = new Descriptor();
                     *      des.ReadDescription(d);
                     *      descript.Add(des);
                     *  }
                     *
                     * }*/
                }
            }

            // TODO: STRING TABLE

            /*if (hasNameTable)
             * {
             *  for (int i = 0; i < mesh.Count; i++)
             *  {
             *      int index = d.readByte();
             *      nameTable.Add(d.readString());
             *  }
             * }*/


            if (format != 4)
            {
                f.align(32, 0xFF);
            }

            f.writeOutput(fv);

            return(f.getBytes());
        }
示例#23
0
        public override byte[] Rebuild()
        {
            FileOutput file = new FileOutput();

            if (file != null)
            {
                if (Endian == Endianness.Little)
                {
                    file.Endian = Endianness.Little;
                    file.writeString(" NBV");
                    file.writeShort(0x02);
                    file.writeShort(0x01);
                }
                else if (Endian == Endianness.Big)
                {
                    file.Endian = Endianness.Big;
                    file.writeString("VBN ");
                    file.writeShort(0x01);
                    file.writeShort(0x02);
                }


                file.writeInt(bones.Count);
                if (boneCountPerType[0] == 0)
                {
                    boneCountPerType[0] = (uint)bones.Count;
                }

                List <Bone> Normal = new List <Bone>();
                List <Bone> Unk    = new List <Bone>();
                List <Bone> Helper = new List <Bone>();
                List <Bone> Swing  = new List <Bone>();

                string[] SpecialBones = new string[] { "TransN",
                                                       "RotN",
                                                       "HipN",
                                                       "LLegJ",
                                                       "LKneeJ",
                                                       "LFootJ",
                                                       "LToeN",
                                                       "RLegJ",
                                                       "RKneeJ",
                                                       "RFootJ",
                                                       "RToeN",
                                                       "WaistN",
                                                       "BustN",
                                                       "LShoulderN",
                                                       "LShoulderJ",
                                                       "LArmJ",
                                                       "LHandN",
                                                       "RShoulderN",
                                                       "RShoulderJ",
                                                       "RArmJ",
                                                       "RHandN",
                                                       "NeckN",
                                                       "HeadN",
                                                       "RHaveN",
                                                       "LHaveN",
                                                       "ThrowN" };
                Bone[] Special      = new Bone[SpecialBones.Length];
                int    specialCount = 0;
                // OrderPass
                foreach (Bone b in bones)
                {
                    for (int i = 0; i < SpecialBones.Length; i++)
                    {
                        if (b.Text.Equals(SpecialBones[i]) || (SpecialBones[i].Equals("RotN") && b.Text.Equals("XRotN")))
                        {
                            specialCount++;
                            Special[i] = b;
                            break;
                        }
                    }
                }
                Console.WriteLine(SpecialBones.Length + " " + specialCount);
                if (specialCount == SpecialBones.Length)
                {
                    Normal.AddRange(Special);
                }

                //Gather Each Bone Type
                foreach (Bone b in bones)
                {
                    switch (b.boneType)
                    {
                    case 0: if (!Normal.Contains(b))
                        {
                            Normal.Add(b);
                        }
                        break;

                    case 2: Helper.Add(b); break;

                    case 3: Swing.Add(b); break;

                    default: Unk.Add(b); break;
                    }
                }

                file.writeInt(Normal.Count);
                file.writeInt(Unk.Count);
                file.writeInt(Helper.Count);
                file.writeInt(Swing.Count);

                List <Bone> NewBoneOrder = new List <Bone>();
                NewBoneOrder.AddRange(Normal);
                NewBoneOrder.AddRange(Unk);
                NewBoneOrder.AddRange(Helper);
                NewBoneOrder.AddRange(Swing);
                bones.Clear();
                bones = NewBoneOrder;

                for (int i = 0; i < bones.Count; i++)
                {
                    file.writeString(bones[i].Text);
                    for (int j = 0; j < 64 - bones[i].Text.Length; j++)
                    {
                        file.writeByte(0);
                    }
                    file.writeInt((int)bones[i].boneType);
                    if (bones[i].parentIndex == -1)
                    {
                        file.writeInt(0x0FFFFFFF);
                    }
                    else
                    {
                        file.writeInt(bones[i].parentIndex);
                    }
                    file.writeInt((int)bones[i].boneId);
                }

                for (int i = 0; i < bones.Count; i++)
                {
                    file.writeFloat(bones[i].position[0]);
                    file.writeFloat(bones[i].position[1]);
                    file.writeFloat(bones[i].position[2]);
                    file.writeFloat(bones[i].rotation[0]);
                    file.writeFloat(bones[i].rotation[1]);
                    file.writeFloat(bones[i].rotation[2]);
                    file.writeFloat(bones[i].scale[0]);
                    file.writeFloat(bones[i].scale[1]);
                    file.writeFloat(bones[i].scale[2]);
                }
            }
            return(file.getBytes());
        }
示例#24
0
        public static byte[] CreateOMOFromAnimation(Animation a, VBN vbn)
        {
            FileOutput o = new FileOutput();

            o.Endian = Endianness.Big;

            FileOutput t1 = new FileOutput();

            t1.Endian = Endianness.Big;

            FileOutput t2 = new FileOutput();

            t2.Endian = Endianness.Big;

            o.writeString("OMO ");
            o.writeShort(1);        //idk
            o.writeShort(3);        //idk

            o.writeInt(0x091E100C); //flags??


            o.writeShort(0);             //padding
            o.writeShort(a.Bones.Count); // numOfNodes

            o.writeShort(a.FrameCount);  // frame size
            o.writeShort(0);             // frame start ??

            o.writeInt(0);
            o.writeInt(0);
            o.writeInt(0);

            o.writeIntAt(o.size(), 0x14);

            // ASSESSMENT
            Vector3[] maxT     = new Vector3[a.Bones.Count], minT = new Vector3[a.Bones.Count];
            Vector4[] maxR     = new Vector4[a.Bones.Count], minR = new Vector4[a.Bones.Count];
            Vector3[] maxS     = new Vector3[a.Bones.Count], minS = new Vector3[a.Bones.Count];
            bool[]    hasScale = new bool[a.Bones.Count];
            bool[]    hasTrans = new bool[a.Bones.Count];
            bool[]    hasRot   = new bool[a.Bones.Count];

            bool[] conScale = new bool[a.Bones.Count];
            bool[] conTrans = new bool[a.Bones.Count];
            bool[] conRot   = new bool[a.Bones.Count];

            a.SetFrame(0);

            //for (int i = 0; i < a.FrameCount; i++)
            {
                //a.NextFrame(vbn);

                for (int j = 0; j < a.Bones.Count; j++)
                {
                    Animation.KeyNode keynode = ((Animation.KeyNode)a.Bones[j]);
                    if (keynode.XPOS.HasAnimation() || keynode.YPOS.HasAnimation() || keynode.ZPOS.HasAnimation())
                    {
                        hasTrans[j] = true;
                    }
                    if (keynode.XROT.HasAnimation())
                    {
                        hasRot[j] = true;
                    }
                    if (keynode.XSCA.HasAnimation() || keynode.YSCA.HasAnimation() || keynode.ZSCA.HasAnimation())
                    {
                        hasScale[j] = true;
                    }

                    maxT[j] = new Vector3(-999f, -999f, -999f);
                    minT[j] = new Vector3(999f, 999f, 999f);
                    maxS[j] = new Vector3(-999f, -999f, -999f);
                    minS[j] = new Vector3(999f, 999f, 999f);
                    maxR[j] = new Vector4(-999f, -999f, -999f, -999f);
                    minR[j] = new Vector4(999f, 999f, 999f, 999f);

                    foreach (Animation.KeyFrame key in keynode.XPOS.Keys)
                    {
                        maxT[j].X = Math.Max(maxT[j].X, key.Value);
                        minT[j].X = Math.Min(minT[j].X, key.Value);
                    }
                    foreach (Animation.KeyFrame key in keynode.YPOS.Keys)
                    {
                        maxT[j].Y = Math.Max(maxT[j].Y, key.Value);
                        minT[j].Y = Math.Min(minT[j].Y, key.Value);
                    }
                    foreach (Animation.KeyFrame key in keynode.ZPOS.Keys)
                    {
                        maxT[j].Z = Math.Max(maxT[j].Z, key.Value);
                        minT[j].Z = Math.Min(minT[j].Z, key.Value);
                    }
                    foreach (Animation.KeyFrame key in keynode.XSCA.Keys)
                    {
                        maxS[j].X = Math.Max(maxS[j].X, key.Value);
                        minS[j].X = Math.Min(minS[j].X, key.Value);
                    }
                    foreach (Animation.KeyFrame key in keynode.YSCA.Keys)
                    {
                        maxS[j].Y = Math.Max(maxS[j].Y, key.Value);
                        minS[j].Y = Math.Min(minS[j].Y, key.Value);
                    }
                    foreach (Animation.KeyFrame key in keynode.ZSCA.Keys)
                    {
                        maxS[j].Z = Math.Max(maxS[j].Z, key.Value);
                        minS[j].Z = Math.Min(minS[j].Z, key.Value);
                    }
                    //TODO: Euler Rotation Values
                    a.SetFrame(0);
                    Bone b = vbn.getBone(keynode.Text);
                    if (b == null)
                    {
                        continue;
                    }
                    for (int i = 0; i < a.FrameCount; i++)
                    {
                        maxR[j].X = Math.Max(maxR[j].X, b.rot.X);
                        minR[j].X = Math.Min(minR[j].X, b.rot.X);
                        maxR[j].Y = Math.Max(maxR[j].Y, b.rot.Y);
                        minR[j].Y = Math.Min(minR[j].Y, b.rot.Y);
                        maxR[j].Z = Math.Max(maxR[j].Z, b.rot.Z);
                        minR[j].Z = Math.Min(minR[j].Z, b.rot.Z);
                        a.NextFrame(vbn);
                    }

                    if (b != null)
                    {
                        if (maxT[j].X == -999)
                        {
                            maxT[j].X = b.position[0];
                        }
                        if (maxT[j].Y == -999)
                        {
                            maxT[j].Y = b.position[1];
                        }
                        if (maxT[j].Z == -999)
                        {
                            maxT[j].Z = b.position[2];
                        }
                        if (minT[j].X == -999)
                        {
                            minT[j].X = b.position[0];
                        }
                        if (minT[j].Y == -999)
                        {
                            minT[j].Y = b.position[1];
                        }
                        if (minT[j].Z == -999)
                        {
                            minT[j].Z = b.position[2];
                        }

                        if (maxS[j].X == -999)
                        {
                            maxS[j].X = b.scale[0];
                        }
                        if (maxS[j].Y == -999)
                        {
                            maxS[j].Y = b.scale[1];
                        }
                        if (maxS[j].Z == -999)
                        {
                            maxS[j].Z = b.scale[2];
                        }
                        if (minS[j].X == -999)
                        {
                            minS[j].X = b.scale[0];
                        }
                        if (minS[j].Y == -999)
                        {
                            minS[j].Y = b.scale[1];
                        }
                        if (minS[j].Z == -999)
                        {
                            minS[j].Z = b.scale[2];
                        }
                    }
                }
            }

            // NODE INFO

            int t2Size = 0;

            for (int i = 0; i < a.Bones.Count; i++)
            {
                int flag = 0;

                conRot[i]   = false;
                conScale[i] = false;
                conTrans[i] = false;

                // check for constant
                if (maxT[i].Equals(minT[i]))
                {
                    conTrans[i] = true;
                }
                if (maxR[i].Equals(minR[i]))
                {
                    conRot[i] = true;
                }
                if (maxS[i].Equals(minS[i]))
                {
                    conScale[i] = true;
                }

                if (hasTrans[i])
                {
                    flag |= 0x01000000;
                }
                if (hasRot[i])
                {
                    flag |= 0x02000000;
                }
                if (hasScale[i])
                {
                    flag |= 0x04000000;
                }

                if (conTrans[i] && hasTrans[i])
                {
                    flag |= 0x00200000;
                }
                else
                {
                    flag |= 0x00080000;
                }

                if (conRot[i] && hasRot[i])
                {
                    flag |= 0x00007000;
                }
                else
                {
                    flag |= 0x00005000;
                }

                if (conScale[i] && hasScale[i])
                {
                    flag |= 0x00000200;
                }
                else
                {
                    flag |= 0x00000080;
                }

                flag |= 0x00000001;

                //uint id = 999;
                Bone b    = vbn.getBone(a.Bones[i].Text);
                int  hash = -1;
                if (b != null)
                {
                    hash = (int)b.boneId;
                }
                else
                {
                    continue;
                }
                //if(hash == -1)
                //hash = (int)FileData.crc32(getNodeId(nodeid.get(i)).name);
                o.writeInt(flag);      // flags...
                o.writeInt(hash);      //hash
                o.writeInt(t1.size()); // Offset in 1 table
                o.writeInt(t2Size);    // Offset in 2 table

                // calculate size needed
                if (hasTrans[i])
                {
                    t1.writeFloat(minT[i].X);
                    t1.writeFloat(minT[i].Y);
                    t1.writeFloat(minT[i].Z);

                    if (!conTrans[i])
                    {
                        maxT[i].X -= minT[i].X;
                        maxT[i].Y -= minT[i].Y;
                        maxT[i].Z -= minT[i].Z;

                        t1.writeFloat(maxT[i].X);
                        t1.writeFloat(maxT[i].Y);
                        t1.writeFloat(maxT[i].Z);

                        t2Size += 6;
                    }
                }

                if (hasRot[i])
                {
                    t1.writeFloat(minR[i].X);
                    t1.writeFloat(minR[i].Y);
                    t1.writeFloat(minR[i].Z);

                    if (!conRot[i])
                    {
                        maxR[i].X -= minR[i].X;
                        maxR[i].Y -= minR[i].Y;
                        maxR[i].Z -= minR[i].Z;

                        t1.writeFloat(maxR[i].X);
                        t1.writeFloat(maxR[i].Y);
                        t1.writeFloat(maxR[i].Z);

                        t2Size += 6;
                    }
                }

                if (hasScale[i])
                {
                    t1.writeFloat(minS[i].X);
                    t1.writeFloat(minS[i].Y);
                    t1.writeFloat(minS[i].Z);

                    if (!conScale[i])
                    {
                        maxS[i].X -= minS[i].X;
                        maxS[i].Y -= minS[i].Y;
                        maxS[i].Z -= minS[i].Z;

                        t1.writeFloat(maxS[i].X);
                        t1.writeFloat(maxS[i].Y);
                        t1.writeFloat(maxS[i].Z);

                        t2Size += 6;
                    }
                }
            }

            o.writeIntAt(o.size(), 0x18);

            o.writeOutput(t1);

            o.writeIntAt(o.size(), 0x1C);

            // INTERPOLATION

            a.SetFrame(0);

            for (int i = 0; i < a.FrameCount; i++)
            {
                //Console.WriteLine("Workin on" + i);
                a.NextFrame(vbn);
                for (int j = 0; j < a.Bones.Count; j++)
                {
                    Bone node = vbn.getBone(a.Bones[j].Text);
                    if (node == null)
                    {
                        continue;
                    }

                    if (hasTrans[j] && !conTrans[j])
                    {
                        t2.writeShort((int)(((node.pos.X - minT[j].X) / maxT[j].X) * 0xFFFF));
                        t2.writeShort((int)(((node.pos.Y - minT[j].Y) / maxT[j].Y) * 0xFFFF));
                        t2.writeShort((int)(((node.pos.Z - minT[j].Z) / maxT[j].Z) * 0xFFFF));
                    }

                    if (hasRot[j] && !conRot[j])
                    {
                        Quaternion r = node.rot;

                        t2.writeShort((int)(((r.X - minR[j].X) / maxR[j].X) * 0xFFFF));
                        t2.writeShort((int)(((r.Y - minR[j].Y) / maxR[j].Y) * 0xFFFF));
                        t2.writeShort((int)(((r.Z - minR[j].Z) / maxR[j].Z) * 0xFFFF));
                    }

                    if (hasScale[j] && !conScale[j])
                    {
                        t2.writeShort((int)(((node.sca.X - minS[j].X) / maxS[j].X) * 0xFFFF));
                        t2.writeShort((int)(((node.sca.Y - minS[j].Y) / maxS[j].Y) * 0xFFFF));
                        t2.writeShort((int)(((node.sca.Z - minS[j].Z) / maxS[j].Z) * 0xFFFF));
                    }
                }

                if (i == 0)
                {
                    o.writeShortAt(t2.size(), 0x12);
                }
            }

            //Console.WriteLine("Saving");
            o.writeOutput(t2);
            return(o.getBytes());
        }
示例#25
0
        public static byte[] CreateOMOFromAnimation(Animation a, VBN vbn)
        {
            if (vbn == null || a == null)
            {
                return new byte[] { }
            }
            ;

            // Test Actual Bones
            //-------------------------

            List <Animation.KeyNode> toRem = new List <Animation.KeyNode>();

            for (int j = 0; j < a.Bones.Count; j++)
            {
                Animation.KeyNode keynode = ((Animation.KeyNode)a.Bones[j]);
                Bone b = vbn.getBone(keynode.Text);

                if (b == null)
                {
                    toRem.Add(keynode);
                }
            }
            foreach (Animation.KeyNode r in toRem)
            {
                Console.WriteLine("Removing " + r.Text);
                a.Bones.Remove(r);
            }

            //-------------------------

            FileOutput o = new FileOutput();

            o.Endian = Endianness.Big;

            FileOutput t1 = new FileOutput();

            t1.Endian = Endianness.Big;

            FileOutput t2 = new FileOutput();

            t2.Endian = Endianness.Big;

            o.writeString("OMO ");
            o.writeShort(1);        //idk
            o.writeShort(3);        //idk

            o.writeInt(0x091E100C); //flags??


            o.writeShort(0);             //padding
            o.writeShort(a.Bones.Count); // numOfNodes

            o.writeShort(a.FrameCount);  // frame size
            o.writeShort(0);             // frame start ??

            o.writeInt(0);
            o.writeInt(0);
            o.writeInt(0);

            o.writeIntAt(o.size(), 0x14);

            // ASSESSMENT
            Vector3[] maxT     = new Vector3[a.Bones.Count], minT = new Vector3[a.Bones.Count];
            Vector4[] maxR     = new Vector4[a.Bones.Count], minR = new Vector4[a.Bones.Count];
            Vector3[] maxS     = new Vector3[a.Bones.Count], minS = new Vector3[a.Bones.Count];
            bool[]    hasScale = new bool[a.Bones.Count];
            bool[]    hasTrans = new bool[a.Bones.Count];
            bool[]    hasRot   = new bool[a.Bones.Count];

            bool[] conScale = new bool[a.Bones.Count];
            bool[] conTrans = new bool[a.Bones.Count];
            bool[] conRot   = new bool[a.Bones.Count];

            a.SetFrame(0);

            List <List <Bone> > Frames = new List <List <Bone> >();

            {
                for (int j = 0; j < a.Bones.Count; j++)
                {
                    Animation.KeyNode keynode = ((Animation.KeyNode)a.Bones[j]);
                    if (keynode.XPOS.HasAnimation() || keynode.YPOS.HasAnimation() || keynode.ZPOS.HasAnimation())
                    {
                        hasTrans[j] = true;
                    }
                    if (keynode.XROT.HasAnimation())
                    {
                        hasRot[j] = true;
                    }
                    if (keynode.XSCA.HasAnimation() || keynode.YSCA.HasAnimation() || keynode.ZSCA.HasAnimation())
                    {
                        hasScale[j] = true;
                    }

                    maxT[j] = new Vector3(-999f, -999f, -999f);
                    minT[j] = new Vector3(999f, 999f, 999f);
                    maxS[j] = new Vector3(-999f, -999f, -999f);
                    minS[j] = new Vector3(999f, 999f, 999f);
                    maxR[j] = new Vector4(-999f, -999f, -999f, -999f);
                    minR[j] = new Vector4(999f, 999f, 999f, 999f);

                    foreach (Animation.KeyFrame key in keynode.XPOS.Keys)
                    {
                        maxT[j].X = Math.Max(maxT[j].X, key.Value);
                        minT[j].X = Math.Min(minT[j].X, key.Value);
                    }
                    foreach (Animation.KeyFrame key in keynode.YPOS.Keys)
                    {
                        maxT[j].Y = Math.Max(maxT[j].Y, key.Value);
                        minT[j].Y = Math.Min(minT[j].Y, key.Value);
                    }
                    foreach (Animation.KeyFrame key in keynode.ZPOS.Keys)
                    {
                        maxT[j].Z = Math.Max(maxT[j].Z, key.Value);
                        minT[j].Z = Math.Min(minT[j].Z, key.Value);
                    }
                    foreach (Animation.KeyFrame key in keynode.XSCA.Keys)
                    {
                        maxS[j].X = Math.Max(maxS[j].X, key.Value);
                        minS[j].X = Math.Min(minS[j].X, key.Value);
                    }
                    foreach (Animation.KeyFrame key in keynode.YSCA.Keys)
                    {
                        maxS[j].Y = Math.Max(maxS[j].Y, key.Value);
                        minS[j].Y = Math.Min(minS[j].Y, key.Value);
                    }
                    foreach (Animation.KeyFrame key in keynode.ZSCA.Keys)
                    {
                        maxS[j].Z = Math.Max(maxS[j].Z, key.Value);
                        minS[j].Z = Math.Min(minS[j].Z, key.Value);
                    }

                    Bone b = vbn.getBone(keynode.Text);
                    for (int i = 0; i < a.FrameCount; i++)
                    {
                        Quaternion r = new Quaternion();
                        if (keynode.RotType == Animation.RotationType.QUATERNION)
                        {
                            Animation.KeyFrame[] x  = keynode.XROT.GetFrame(i);
                            Animation.KeyFrame[] y  = keynode.YROT.GetFrame(i);
                            Animation.KeyFrame[] z  = keynode.ZROT.GetFrame(i);
                            Animation.KeyFrame[] w  = keynode.WROT.GetFrame(i);
                            Quaternion           q1 = new Quaternion(x[0].Value, y[0].Value, z[0].Value, w[0].Value);
                            Quaternion           q2 = new Quaternion(x[1].Value, y[1].Value, z[1].Value, w[1].Value);
                            if (x[0].Frame == i)
                            {
                                r = q1;
                            }
                            else
                            if (x[1].Frame == i)
                            {
                                r = q2;
                            }
                            else
                            {
                                r = Quaternion.Slerp(q1, q2, (i - x[0].Frame) / (x[1].Frame - x[0].Frame));
                            }
                        }
                        else
                        if (keynode.RotType == Animation.RotationType.EULER)
                        {
                            float x = keynode.XROT.HasAnimation() ? keynode.XROT.GetValue(i) : b.rotation[0];
                            float y = keynode.YROT.HasAnimation() ? keynode.YROT.GetValue(i) : b.rotation[1];
                            float z = keynode.ZROT.HasAnimation() ? keynode.ZROT.GetValue(i) : b.rotation[2];
                            r = Animation.EulerToQuat(z, y, x);
                        }
                        r.Normalize();

                        maxR[j].X = Math.Max(maxR[j].X, r.X);
                        minR[j].X = Math.Min(minR[j].X, r.X);
                        maxR[j].Y = Math.Max(maxR[j].Y, r.Y);
                        minR[j].Y = Math.Min(minR[j].Y, r.Y);
                        maxR[j].Z = Math.Max(maxR[j].Z, r.Z);
                        minR[j].Z = Math.Min(minR[j].Z, r.Z);
                    }

                    //if (b == null)continue;
                    if (b != null)
                    {
                        if (maxT[j].X == -999)
                        {
                            maxT[j].X = b.position[0];
                        }
                        if (maxT[j].Y == -999)
                        {
                            maxT[j].Y = b.position[1];
                        }
                        if (maxT[j].Z == -999)
                        {
                            maxT[j].Z = b.position[2];
                        }
                        if (minT[j].X == -999)
                        {
                            minT[j].X = b.position[0];
                        }
                        if (minT[j].Y == -999)
                        {
                            minT[j].Y = b.position[1];
                        }
                        if (minT[j].Z == -999)
                        {
                            minT[j].Z = b.position[2];
                        }

                        if (maxS[j].X == -999)
                        {
                            maxS[j].X = b.scale[0];
                        }
                        if (maxS[j].Y == -999)
                        {
                            maxS[j].Y = b.scale[1];
                        }
                        if (maxS[j].Z == -999)
                        {
                            maxS[j].Z = b.scale[2];
                        }
                        if (minS[j].X == -999)
                        {
                            minS[j].X = b.scale[0];
                        }
                        if (minS[j].Y == -999)
                        {
                            minS[j].Y = b.scale[1];
                        }
                        if (minS[j].Z == -999)
                        {
                            minS[j].Z = b.scale[2];
                        }
                    }
                }
            }

            //TODO: Euler Rotation Values

            /*VBN tempvbn = new VBN();
             * a.SetFrame(0);
             * for (int i = 0; i < a.FrameCount; i++)
             * {
             *  //Frames.Add(new List<Bone>());
             *  for (int j = 0; j < a.Bones.Count; j++)
             *  {
             *      Animation.KeyNode keynode = a.Bones[j];
             *      Bone b = vbn.getBone(keynode.Text);
             *      //if(b == null) continue;
             *      maxR[j].X = Math.Max(maxR[j].X, b.rot.X);
             *      minR[j].X = Math.Min(minR[j].X, b.rot.X);
             *      maxR[j].Y = Math.Max(maxR[j].Y, b.rot.Y);
             *      minR[j].Y = Math.Min(minR[j].Y, b.rot.Y);
             *      maxR[j].Z = Math.Max(maxR[j].Z, b.rot.Z);
             *      minR[j].Z = Math.Min(minR[j].Z, b.rot.Z);
             *
             *      Bone f1 = new Bone(tempvbn);
             *      f1.pos = b.pos;
             *      f1.rot = b.rot;
             *      f1.sca = b.sca;
             *      //Frames[i].Add(f1);
             *  }
             *  a.NextFrame(vbn);
             * }*/

            // NODE INFO

            int t2Size = 0;

            for (int i = 0; i < a.Bones.Count; i++)
            {
                int flag = 0;

                conRot[i]   = false;
                conScale[i] = false;
                conTrans[i] = false;

                // check for constant
                if (maxT[i].Equals(minT[i]))
                {
                    conTrans[i] = true;
                }
                if (maxR[i].Equals(minR[i]))
                {
                    conRot[i] = true;
                }
                if (maxS[i].Equals(minS[i]))
                {
                    conScale[i] = true;
                }

                if (hasTrans[i])
                {
                    flag |= 0x01000000;
                }
                if (hasRot[i])
                {
                    flag |= 0x02000000;
                }
                if (hasScale[i])
                {
                    flag |= 0x04000000;
                }

                if (conTrans[i] && hasTrans[i])
                {
                    flag |= 0x00200000;
                }
                else
                {
                    flag |= 0x00080000;
                }

                if (conRot[i] && hasRot[i])
                {
                    flag |= 0x00007000;
                }
                else
                {
                    flag |= 0x00005000;
                }

                if (conScale[i] && hasScale[i])
                {
                    flag |= 0x00000200;
                }
                else
                {
                    flag |= 0x00000080;
                }

                flag |= 0x00000001;

                //uint id = 999;

                Bone b    = vbn.getBone(a.Bones[i].Text);
                int  hash = -1;
                if (MainForm.Hashes.names.ContainsKey(a.Bones[i].Text))
                {
                    hash = (int)MainForm.Hashes.names[a.Bones[i].Text];
                }
                else
                {
                    if (b != null)
                    {
                        hash = (int)b.boneId;
                    }
                    else
                    {
                        continue;
                    }
                }
                //if(hash == -1)
                //hash = (int)FileData.crc32(getNodeId(nodeid.get(i)).name);
                o.writeInt(flag);      // flags...
                o.writeInt(hash);      //hash
                o.writeInt(t1.size()); // Offset in 1 table
                o.writeInt(t2Size);    // Offset in 2 table

                // calculate size needed
                if (hasTrans[i])
                {
                    t1.writeFloat(minT[i].X);
                    t1.writeFloat(minT[i].Y);
                    t1.writeFloat(minT[i].Z);

                    if (!conTrans[i])
                    {
                        maxT[i].X -= minT[i].X;
                        maxT[i].Y -= minT[i].Y;
                        maxT[i].Z -= minT[i].Z;

                        t1.writeFloat(maxT[i].X);
                        t1.writeFloat(maxT[i].Y);
                        t1.writeFloat(maxT[i].Z);

                        t2Size += 6;
                    }
                }

                if (hasRot[i])
                {
                    t1.writeFloat(minR[i].X);
                    t1.writeFloat(minR[i].Y);
                    t1.writeFloat(minR[i].Z);

                    if (!conRot[i])
                    {
                        maxR[i].X -= minR[i].X;
                        maxR[i].Y -= minR[i].Y;
                        maxR[i].Z -= minR[i].Z;

                        t1.writeFloat(maxR[i].X);
                        t1.writeFloat(maxR[i].Y);
                        t1.writeFloat(maxR[i].Z);

                        t2Size += 6;
                    }
                }

                if (hasScale[i])
                {
                    t1.writeFloat(minS[i].X);
                    t1.writeFloat(minS[i].Y);
                    t1.writeFloat(minS[i].Z);

                    if (!conScale[i])
                    {
                        maxS[i].X -= minS[i].X;
                        maxS[i].Y -= minS[i].Y;
                        maxS[i].Z -= minS[i].Z;

                        t1.writeFloat(maxS[i].X);
                        t1.writeFloat(maxS[i].Y);
                        t1.writeFloat(maxS[i].Z);

                        t2Size += 6;
                    }
                }
            }

            o.writeIntAt(o.size(), 0x18);

            o.writeOutput(t1);

            o.writeIntAt(o.size(), 0x1C);

            // INTERPOLATION

            a.SetFrame(0);

            bool go = true;

            for (int i = 0; i < a.FrameCount; i++)
            {
                //a.NextFrame(vbn);
                for (int j = 0; j < a.Bones.Count; j++)
                {
                    Bone node = vbn.getBone(a.Bones[j].Text);

                    Animation.KeyNode anode = a.Bones[j];
                    //if (node == null) continue;

                    if (hasTrans[j] && !conTrans[j])
                    {
                        t2.writeShort((int)(((anode.XPOS.GetValue(i) - minT[j].X) / maxT[j].X) * 0xFFFF));
                        t2.writeShort((int)(((anode.YPOS.GetValue(i) - minT[j].Y) / maxT[j].Y) * 0xFFFF));
                        t2.writeShort((int)(((anode.ZPOS.GetValue(i) - minT[j].Z) / maxT[j].Z) * 0xFFFF));
                    }

                    if (hasRot[j] && !conRot[j])
                    {
                        Quaternion r = new Quaternion();
                        if (anode.RotType == Animation.RotationType.QUATERNION)
                        {
                            Animation.KeyFrame[] x  = anode.XROT.GetFrame(i);
                            Animation.KeyFrame[] y  = anode.YROT.GetFrame(i);
                            Animation.KeyFrame[] z  = anode.ZROT.GetFrame(i);
                            Animation.KeyFrame[] w  = anode.WROT.GetFrame(i);
                            Quaternion           q1 = new Quaternion(x[0].Value, y[0].Value, z[0].Value, w[0].Value);
                            Quaternion           q2 = new Quaternion(x[1].Value, y[1].Value, z[1].Value, w[1].Value);
                            if (x[0].Frame == i)
                            {
                                r = q1;
                            }
                            else
                            if (x[1].Frame == i)
                            {
                                r = q2;
                            }
                            else
                            {
                                r = Quaternion.Slerp(q1, q2, (i - x[0].Frame) / (x[1].Frame - x[0].Frame));
                            }
                        }
                        else
                        if (anode.RotType == Animation.RotationType.EULER)
                        {
                            float x = anode.XROT.HasAnimation() ? anode.XROT.GetValue(i) : node.rotation[0];
                            float y = anode.YROT.HasAnimation() ? anode.YROT.GetValue(i) : node.rotation[1];
                            float z = anode.ZROT.HasAnimation() ? anode.ZROT.GetValue(i) : node.rotation[2];
                            r = Animation.EulerToQuat(z, y, x);
                        }
                        r.Normalize();
                        t2.writeShort((int)(((r.X - minR[j].X) / maxR[j].X) * 0xFFFF));
                        t2.writeShort((int)(((r.Y - minR[j].Y) / maxR[j].Y) * 0xFFFF));
                        t2.writeShort((int)(((r.Z - minR[j].Z) / maxR[j].Z) * 0xFFFF));
                    }

                    if (hasScale[j] && !conScale[j])
                    {
                        t2.writeShort((int)(((anode.XSCA.GetValue(i) - minS[j].X) / maxS[j].X) * 0xFFFF));
                        t2.writeShort((int)(((anode.YSCA.GetValue(i) - minS[j].Y) / maxS[j].Y) * 0xFFFF));
                        t2.writeShort((int)(((anode.ZSCA.GetValue(i) - minS[j].Z) / maxS[j].Z) * 0xFFFF));
                    }
                }

                if (go)
                {
                    o.writeShortAt(t2.size(), 0x12);
                    go = false;
                }
            }

            o.writeOutput(t2);
            return(o.getBytes());
        }
    }
示例#26
0
        public void SaveAsMBN(string fname)
        {
            int        format = 6;
            FileOutput o      = new FileOutput();

            o.Endian = Endianness.Little;

            o.writeShort(format);
            o.writeShort(0xFFFF);
            o.writeInt(0); //flags
            o.writeInt(1); //mode
            o.writeInt(Nodes.Count);

            // Write Vertex Attributes
            {
                o.writeInt(Attributes.Count);
                foreach (VertexAttribute va in Attributes)
                {
                    o.writeInt(va.type);
                    o.writeInt(va.format);
                    o.writeFloat(va.scale);
                }
            }


            //Vertex Buffer
            FileOutput vertexBuffer = new FileOutput();

            vertexBuffer.Endian = Endianness.Little;

            for (int i = 0; i < Vertices.Length; i++)
            {
                foreach (VertexAttribute va in Attributes)
                {
                    //Write Data
                    va.WriteVertex(vertexBuffer, ref Vertices[i]);
                }
            }

            o.writeInt(vertexBuffer.size()); // Vertex Buffer Size

            //Mesh Information
            FileOutput indexBuffer = new FileOutput();

            indexBuffer.Endian = Endianness.Little;
            foreach (BCH_Mesh mesh in Nodes)
            {
                o.writeInt(mesh.Nodes.Count);
                foreach (BCH_PolyGroup pg in mesh.Nodes)
                {
                    // Node List
                    o.writeInt(pg.BoneList.Length);
                    foreach (int b in pg.BoneList)
                    {
                        o.writeInt(b);
                    }

                    // Triangle Count
                    o.writeInt(pg.Faces.Length);
                    // o.writeInt(0); something if format == 4

                    // Index Buffer
                    foreach (int i in pg.Faces)
                    {
                        indexBuffer.writeShort(i);
                    }
                    indexBuffer.align(0x20, 0xFF);
                }
            }

            if (format != 4)
            {
                o.align(0x20, 0xFF);
            }

            o.writeOutput(vertexBuffer);
            o.align(0x20, 0xFF);
            o.writeOutput(indexBuffer);
            o.save(fname);
        }
示例#27
0
        public static byte[] createOMO(SkelAnimation a, VBN vbn)
        {
            List <int> nodeid = a.getNodes(true, vbn);

            int startNode = 0;
            int sizeNode  = nodeid.Count;

            FileOutput o = new FileOutput();

            o.Endian = Endianness.Big;

            FileOutput t1 = new FileOutput();

            t1.Endian = Endianness.Big;

            FileOutput t2 = new FileOutput();

            t2.Endian = Endianness.Big;

            o.writeString("OMO ");
            o.writeShort(1);        //idk
            o.writeShort(3);        //idk

            o.writeInt(0x091E100C); //flags??


            o.writeShort(0);              //padding
            o.writeShort(sizeNode);       // numOfNodes

            o.writeShort(a.frames.Count); // frame size
            o.writeShort(0);              // frame start ??

            o.writeInt(0);
            o.writeInt(0);
            o.writeInt(0);

            o.writeIntAt(o.size(), 0x14);


            // ASSESSMENT
            KeyNode[] minmax   = new KeyNode[sizeNode];
            bool[]    hasScale = new bool[sizeNode];
            bool[]    hasTrans = new bool[sizeNode];
            bool[]    hasRot   = new bool[sizeNode];

            bool[] conScale = new bool[sizeNode];
            bool[] conTrans = new bool[sizeNode];
            bool[] conRot   = new bool[sizeNode];

            a.setFrame(0);

            for (int i = 0; i < a.size(); i++)
            {
                a.nextFrame(vbn);

                for (int j = 0; j < nodeid.Count; j++)
                {
                    Bone node = getNodeId(vbn, nodeid[j]);

                    if (minmax[j] == null)
                    {
                        hasRot[j]   = false;
                        hasScale[j] = false;
                        hasTrans[j] = false;

                        KeyNode n = a.getFirstNode(nodeid[j]);
                        if (n != null)
                        {
                            if (n.r_type != -1)
                            {
                                hasRot[j] = true;
                            }
                            if (n.t_type != -1)
                            {
                                hasTrans[j] = true;
                            }
                            if (n.s_type != -1)
                            {
                                hasScale[j] = true;
                            }
                        }

                        minmax[j]    = new KeyNode();
                        minmax[j].t  = new Vector3(999f, 999f, 999f);
                        minmax[j].r  = new Quaternion(999f, 999f, 999f, 999f);
                        minmax[j].s  = new Vector3(999f, 999f, 999f);
                        minmax[j].t2 = new Vector3(-999f, -999f, -999f);
                        minmax[j].r2 = new Quaternion(-999f, -999f, -999f, -999f);
                        minmax[j].s2 = new Vector3(-999f, -999f, -999f);
                    }

                    if (node.pos.X < minmax[j].t.X)
                    {
                        minmax[j].t.X = node.pos.X;
                    }
                    if (node.pos.X > minmax[j].t2.X)
                    {
                        minmax[j].t2.X = node.pos.X;
                    }

                    if (node.pos.Y < minmax[j].t.Y)
                    {
                        minmax[j].t.Y = node.pos.Y;
                    }
                    if (node.pos.Y > minmax[j].t2.Y)
                    {
                        minmax[j].t2.Y = node.pos.Y;
                    }

                    if (node.pos.Z < minmax[j].t.Z)
                    {
                        minmax[j].t.Z = node.pos.Z;
                    }
                    if (node.pos.Z > minmax[j].t2.Z)
                    {
                        minmax[j].t2.Z = node.pos.Z;
                    }

                    //				float[] fix = Node.fix360(node.nrx, node.nry, node.nrz);
                    //float[] f = Bone.CalculateRotation(node.nrx, node.nry, node.nrz);
                    Quaternion r = node.rot;

                    if (r.X < minmax[j].r.X)
                    {
                        minmax[j].r.X = r.X;
                    }
                    if (r.X > minmax[j].r2.X)
                    {
                        minmax[j].r2.X = r.X;
                    }

                    if (r.Y < minmax[j].r.Y)
                    {
                        minmax[j].r.Y = r.Y;
                    }
                    if (r.Y > minmax[j].r2.Y)
                    {
                        minmax[j].r2.Y = r.Y;
                    }

                    if (r.Z < minmax[j].r.Z)
                    {
                        minmax[j].r.Z = r.Z;
                    }
                    if (r.Z > minmax[j].r2.Z)
                    {
                        minmax[j].r2.Z = r.Z;
                    }


                    if (node.sca.X < minmax[j].s.X)
                    {
                        minmax[j].s.X = node.sca.X;
                    }
                    if (node.sca.X > minmax[j].s2.X)
                    {
                        minmax[j].s2.X = node.sca.X;
                    }

                    if (node.sca.Y < minmax[j].s.Y)
                    {
                        minmax[j].s.Y = node.sca.Y;
                    }
                    if (node.sca.Y > minmax[j].s2.Y)
                    {
                        minmax[j].s2.Y = node.sca.Y;
                    }

                    if (node.sca.Z < minmax[j].s.Z)
                    {
                        minmax[j].s.Z = node.sca.Z;
                    }
                    if (node.sca.Z > minmax[j].s2.Z)
                    {
                        minmax[j].s2.Z = node.sca.Z;
                    }
                }
            }

            // NODE INFO

            int t2Size = 0;

            for (int i = 0; i < sizeNode; i++)
            {
                int flag = 0;

                conRot[i]   = false;
                conScale[i] = false;
                conTrans[i] = false;

                // check for constant
                if (minmax[i].t.Equals(minmax[i].t2))
                {
                    conTrans[i] = true;
                }
                if (minmax[i].r.Equals(minmax[i].r2))
                {
                    conRot[i] = true;
                }
                if (minmax[i].s.Equals(minmax[i].s2))
                {
                    conScale[i] = true;
                }

                if (hasTrans[i])
                {
                    flag |= 0x01000000;
                }
                if (hasRot[i])
                {
                    flag |= 0x02000000;
                }
                if (hasScale[i])
                {
                    flag |= 0x04000000;
                }

                if (conTrans[i] && hasTrans[i])
                {
                    flag |= 0x00200000;
                }
                else
                {
                    flag |= 0x00080000;
                }

                if (conRot[i] && hasRot[i])
                {
                    flag |= 0x00007000;
                }
                else
                {
                    flag |= 0x00005000;
                }

                if (conScale[i] && hasScale[i])
                {
                    flag |= 0x00000200;
                }
                else
                {
                    flag |= 0x00000080;
                }

                flag |= 0x00000001;

                int hash = (int)getNodeId(vbn, nodeid[i]).boneId;
                //if(hash == -1)
                //hash = (int)FileData.crc32(getNodeId(nodeid.get(i)).name);
                o.writeInt(flag);      // flags...
                o.writeInt(hash);      //hash
                o.writeInt(t1.size()); // Offset in 1 table
                o.writeInt(t2Size);    // Offset in 2 table

                // calculate size needed
                if (hasTrans[i])
                {
                    t1.writeFloat(minmax[i].t.X);
                    t1.writeFloat(minmax[i].t.Y);
                    t1.writeFloat(minmax[i].t.Z);

                    if (!conTrans[i])
                    {
                        minmax[i].t2.X -= minmax[i].t.X;
                        minmax[i].t2.Y -= minmax[i].t.Y;
                        minmax[i].t2.Z -= minmax[i].t.Z;

                        t1.writeFloat(minmax[i].t2.X);
                        t1.writeFloat(minmax[i].t2.Y);
                        t1.writeFloat(minmax[i].t2.Z);

                        t2Size += 6;
                    }
                }

                if (hasRot[i])
                {
                    t1.writeFloat(minmax[i].r.X);
                    t1.writeFloat(minmax[i].r.Y);
                    t1.writeFloat(minmax[i].r.Z);

                    if (!conRot[i])
                    {
                        minmax[i].r2.X -= minmax[i].r.X;
                        minmax[i].r2.Y -= minmax[i].r.Y;
                        minmax[i].r2.Z -= minmax[i].r.Z;

                        t1.writeFloat(minmax[i].r2.X);
                        t1.writeFloat(minmax[i].r2.Y);
                        t1.writeFloat(minmax[i].r2.Z);

                        t2Size += 6;
                    }
                }

                if (hasScale[i])
                {
                    t1.writeFloat(minmax[i].s.X);
                    t1.writeFloat(minmax[i].s.Y);
                    t1.writeFloat(minmax[i].s.Z);

                    if (!conScale[i])
                    {
                        minmax[i].s2.X -= minmax[i].s.X;
                        minmax[i].s2.Y -= minmax[i].s.Y;
                        minmax[i].s2.Z -= minmax[i].s.Z;

                        t1.writeFloat(minmax[i].s2.X);
                        t1.writeFloat(minmax[i].s2.Y);
                        t1.writeFloat(minmax[i].s2.Z);

                        t2Size += 6;
                    }
                }
            }

            o.writeIntAt(o.size(), 0x18);

            o.writeOutput(t1);

            o.writeIntAt(o.size(), 0x1C);

            // INTERPOLATION

            a.setFrame(0);

            for (int i = 0; i < a.size(); i++)
            {
                a.nextFrame(vbn);
                for (int j = 0; j < nodeid.Count; j++)
                {
                    Bone node = getNodeId(vbn, nodeid[j]);

                    if (hasTrans[j] && !conTrans[j])
                    {
                        t2.writeShort((int)(((node.pos.X - minmax[j].t.X) / minmax[j].t2.X) * 0xFFFF));
                        t2.writeShort((int)(((node.pos.Y - minmax[j].t.Y) / minmax[j].t2.Y) * 0xFFFF));
                        t2.writeShort((int)(((node.pos.Z - minmax[j].t.Z) / minmax[j].t2.Z) * 0xFFFF));
                    }

                    if (hasRot[j] && !conRot[j])
                    {
                        //					float[] fix = Node.fix360(node.nrx, node.nry, node.nrz);
                        //float[] f = CalculateRotation(node.nrx, node.nry, node.nrz);
                        Quaternion r = node.rot;

                        t2.writeShort((int)(((r.X - minmax[j].r.X) / minmax[j].r2.X) * 0xFFFF));
                        t2.writeShort((int)(((r.Y - minmax[j].r.Y) / minmax[j].r2.Y) * 0xFFFF));
                        t2.writeShort((int)(((r.Z - minmax[j].r.Z) / minmax[j].r2.Z) * 0xFFFF));
                    }

                    if (hasScale[j] && !conScale[j])
                    {
                        t2.writeShort((int)(((node.sca.X - minmax[j].s.X) / minmax[j].s2.X) * 0xFFFF));
                        t2.writeShort((int)(((node.sca.Y - minmax[j].s.Y) / minmax[j].s2.Y) * 0xFFFF));
                        t2.writeShort((int)(((node.sca.Z - minmax[j].s.Z) / minmax[j].s2.Z) * 0xFFFF));
                    }
                }

                if (i == 0)
                {
                    o.writeShortAt(t2.size(), 0x12);
                }
            }

            o.writeOutput(t2);
            return(o.getBytes());
        }
示例#28
0
        public static void Rebuild(string fname, List <Animation> animations)
        {
            // poopity doo da
            // headery deadery
            FileOutput o = new FileOutput();

            o.writeString("BCH");
            o.align(4);
            o.writeByte(0x21);    // version stuffs
            o.writeByte(0x21);    // version stuffs
            o.Endian = System.IO.Endianness.Little;
            o.writeShort(0xA755); // version

            FileOutput d_Main = new FileOutput();

            d_Main.Endian = System.IO.Endianness.Little;
            FileOutput d_Main2 = new FileOutput();

            d_Main2.Endian = System.IO.Endianness.Little;
            FileOutput d_Main3 = new FileOutput();

            d_Main3.Endian = System.IO.Endianness.Little;
            FileOutput d_String = new FileOutput();

            d_String.Endian = System.IO.Endianness.Little;
            FileOutput d_GPU = new FileOutput();

            d_GPU.Endian = System.IO.Endianness.Little;
            FileOutput d_Data = new FileOutput();

            d_Data.Endian = System.IO.Endianness.Little;

            FileOutput Reloc = new FileOutput();

            Reloc.Endian = System.IO.Endianness.Little;

            //Offsets
            o.writeInt(0); //main
            o.writeInt(0); //string
            o.writeInt(0); //gpu
            o.writeInt(0); //data
            o.writeInt(0); //dataext
            o.writeInt(0); //relocationtable

            //Length
            o.writeInt(0);   //main
            o.writeInt(0);   //string
            o.writeInt(0);   //gpu
            o.writeInt(0);   //data
            o.writeInt(0);   //dataext
            o.writeInt(0);   //relocationtable

            o.writeInt(0);   //datasection
            o.writeInt(0);   //

            o.writeShort(1); //flag
            o.writeShort(0); //addcount

            //Contents in the main header......

            d_Main.writeInt(0);                                // Model
            d_Main.writeInt(0);                                //
            d_Main.WriteOffset(0xB4 + d_Main2.size(), d_Main); //

            d_Main2.writeInt(0);
            d_Main2.writeInt(0);
            d_Main2.writeInt(0);

            d_Main.writeInt(0);                                // Material
            d_Main.writeInt(0);                                //
            d_Main.WriteOffset(0xB4 + d_Main2.size(), d_Main); //

            d_Main2.writeInt(0);
            d_Main2.writeInt(0);
            d_Main2.writeInt(0);

            d_Main.writeInt(0);                                // Shader
            d_Main.writeInt(0);                                //
            d_Main.WriteOffset(0xB4 + d_Main2.size(), d_Main); //

            d_Main2.writeInt(0);
            d_Main2.writeInt(0);
            d_Main2.writeInt(0);

            d_Main.writeInt(0);                                // Texture
            d_Main.writeInt(0);                                //
            d_Main.WriteOffset(0xB4 + d_Main2.size(), d_Main); //

            d_Main2.writeInt(0);
            d_Main2.writeInt(0);
            d_Main2.writeInt(0);

            d_Main.writeInt(0);                                // MaterialLUT
            d_Main.writeInt(0);                                //
            d_Main.WriteOffset(0xB4 + d_Main2.size(), d_Main); //

            d_Main2.writeInt(0);
            d_Main2.writeInt(0);
            d_Main2.writeInt(0);

            d_Main.writeInt(0);                                // Lights
            d_Main.writeInt(0);                                //
            d_Main.WriteOffset(0xB4 + d_Main2.size(), d_Main); //

            d_Main2.writeInt(0);
            d_Main2.writeInt(0);
            d_Main2.writeInt(0);

            d_Main.writeInt(0);                                // Camera
            d_Main.writeInt(0);                                //
            d_Main.WriteOffset(0xB4 + d_Main2.size(), d_Main); //

            d_Main2.writeInt(0);
            d_Main2.writeInt(0);
            d_Main2.writeInt(0);

            d_Main.writeInt(0);                                // Fog
            d_Main.writeInt(0);                                //
            d_Main.WriteOffset(0xB4 + d_Main2.size(), d_Main); //

            d_Main2.writeInt(0);
            d_Main2.writeInt(0);
            d_Main2.writeInt(0);

            // SkeAnim
            {
                // Names need to be in patricia tree.......
                Dictionary <string, int> NameBank = new Dictionary <string, int>();

                NameBank.Add("BustN", d_String.size());
                d_String.writeString("BustN");
                d_String.writeByte(0);

                List <PatriciaTree.PatriciaTreeNode> Nodes = new List <PatriciaTree.PatriciaTreeNode>();
                int maxlength = 0;
                foreach (Animation a in animations)
                {
                    maxlength = Math.Max(maxlength, a.Text.Length);
                }

                Nodes.Add(new PatriciaTree.PatriciaTreeNode()
                {
                    ReferenceBit = uint.MaxValue
                });
                foreach (Animation a in animations)
                {
                    PatriciaTree.Insert(Nodes, new PatriciaTree.PatriciaTreeNode()
                    {
                        Name = a.Text
                    }, maxlength);
                }

                int nameOff = 0xb4 + d_Main2.size();
                foreach (PatriciaTree.PatriciaTreeNode node in Nodes)
                {
                    d_Main2.writeInt((int)node.ReferenceBit);
                    d_Main2.writeShort(node.LeftNodeIndex);
                    d_Main2.writeShort(node.RightNodeIndex);
                    if (node.Name.Equals(""))
                    {
                        d_Main2.writeInt(0);
                    }
                    else
                    {
                        NameBank.Add(node.Name, d_String.size());
                        d_Main2.WriteOffset(d_String.size(), d_String);
                        d_String.writeString(node.Name);
                        d_String.writeByte(0);
                    }
                }
                // bones


                // Okay, first create the animation data then create the table pointng to it side by side

                int dataOff = 0xb4 + d_Main2.size();
                foreach (Animation a in animations)
                {
                    d_Main2.WriteOffset(d_Main3.size(), d_Main2);

                    // now create the actual animation data I guess
                    d_Main3.WriteOffset(NameBank[a.Text], d_String);   // name offset
                    d_Main3.writeInt(0x2);                             // Flags TODO: What are these
                    d_Main3.writeFloat(a.FrameCount + 1);
                    d_Main3.WriteOffset(d_Main3.size() + 12, d_Main3); // bone offset
                    d_Main3.writeInt(a.Bones.Count);                   // bonecount
                    d_Main3.writeInt(0);                               // metadata nonsense

                    FileOutput boneHeader = new FileOutput();
                    boneHeader.Endian = System.IO.Endianness.Little;
                    FileOutput keyData = new FileOutput();
                    keyData.Endian = System.IO.Endianness.Little;
                    int start = d_Main3.size() + (a.Bones.Count * 4);
                    int track = 0;
                    foreach (Animation.KeyNode node in a.Bones)
                    {
                        d_Main3.WriteOffset(start + boneHeader.size(), d_Main3); // bone offset
                        // name type and flags
                        if (!NameBank.ContainsKey(node.Text))
                        {
                            NameBank.Add(node.Text, d_String.size());
                            d_String.writeString(node.Text);
                            d_String.writeByte(0);
                        }
                        boneHeader.WriteOffset(NameBank[node.Text], d_String); // name offset
                        boneHeader.writeInt(0x040000);                         // animation type flags, default is just simply transform
                        // Actual Flags
                        int flags = 0;
                        flags |= (((node.XSCA.Keys.Count > 0) ? 0 : 1) << (16 + 0));
                        flags |= (((node.YSCA.Keys.Count > 0) ? 0 : 1) << (16 + 1));
                        flags |= (((node.ZSCA.Keys.Count > 0) ? 0 : 1) << (16 + 2));
                        flags |= (((node.XROT.Keys.Count > 0) ? 0 : 1) << (16 + 3));
                        flags |= (((node.YROT.Keys.Count > 0) ? 0 : 1) << (16 + 4));
                        flags |= (((node.ZROT.Keys.Count > 0) ? 0 : 1) << (16 + 5));
                        flags |= (((node.XPOS.Keys.Count > 0) ? 0 : 1) << (16 + 6));
                        flags |= (((node.YPOS.Keys.Count > 0) ? 0 : 1) << (16 + 7));
                        flags |= (((node.ZPOS.Keys.Count > 0) ? 0 : 1) << (16 + 8));

                        flags |= (((node.XSCA.Keys.Count == 1) ? 1 : 0) << (6 + 0));
                        flags |= (((node.YSCA.Keys.Count == 1) ? 1 : 0) << (6 + 1));
                        flags |= (((node.ZSCA.Keys.Count == 1) ? 1 : 0) << (6 + 2));
                        flags |= (((node.XROT.Keys.Count == 1) ? 1 : 0) << (6 + 3));
                        flags |= (((node.YROT.Keys.Count == 1) ? 1 : 0) << (6 + 4));
                        flags |= (((node.ZROT.Keys.Count == 1) ? 1 : 0) << (6 + 5));
                        flags |= (((node.XPOS.Keys.Count == 1) ? 1 : 0) << (6 + 7));
                        flags |= (((node.YPOS.Keys.Count == 1) ? 1 : 0) << (6 + 8));
                        flags |= (((node.ZPOS.Keys.Count == 1) ? 1 : 0) << (6 + 9));
                        boneHeader.writeInt(flags);

                        // Create KeyFrame Data
                        int sta = start + (a.Bones.Count * 12 * 4);
                        WriteKeyData(node.XSCA, boneHeader, keyData, d_Main3, sta, ref track);
                        WriteKeyData(node.YSCA, boneHeader, keyData, d_Main3, sta, ref track);
                        WriteKeyData(node.ZSCA, boneHeader, keyData, d_Main3, sta, ref track);
                        WriteKeyData(node.XROT, boneHeader, keyData, d_Main3, sta, ref track);
                        WriteKeyData(node.YROT, boneHeader, keyData, d_Main3, sta, ref track);
                        WriteKeyData(node.ZROT, boneHeader, keyData, d_Main3, sta, ref track);
                        WriteKeyData(node.XPOS, boneHeader, keyData, d_Main3, sta, ref track);
                        WriteKeyData(node.YPOS, boneHeader, keyData, d_Main3, sta, ref track);
                        WriteKeyData(node.ZPOS, boneHeader, keyData, d_Main3, sta, ref track);
                    }
                    d_Main3.writeOutput(boneHeader);
                    d_Main3.writeOutput(keyData);
                }

                d_Main.WriteOffset(dataOff, d_Main);
                d_Main.writeInt(animations.Count);   //
                d_Main.WriteOffset(nameOff, d_Main); //
            }


            d_Main.writeInt(0);                                // MaterialAnim
            d_Main.writeInt(0);                                //
            d_Main.WriteOffset(0xB4 + d_Main2.size(), d_Main); //

            d_Main2.writeInt(0);
            d_Main2.writeInt(0);
            d_Main2.writeInt(0);

            d_Main.writeInt(0);                                // VisAnim
            d_Main.writeInt(0);                                //
            d_Main.WriteOffset(0xB4 + d_Main2.size(), d_Main); //

            d_Main2.writeInt(0);
            d_Main2.writeInt(0);
            d_Main2.writeInt(0);

            d_Main.writeInt(0);                                // LightAnim
            d_Main.writeInt(0);                                //
            d_Main.WriteOffset(0xB4 + d_Main2.size(), d_Main); //

            d_Main2.writeInt(0);
            d_Main2.writeInt(0);
            d_Main2.writeInt(0);

            d_Main.writeInt(0);                                // CameraAnim
            d_Main.writeInt(0);                                //
            d_Main.WriteOffset(0xB4 + d_Main2.size(), d_Main); //

            d_Main2.writeInt(0);
            d_Main2.writeInt(0);
            d_Main2.writeInt(0);

            d_Main.writeInt(0);                                // FogAnim
            d_Main.writeInt(0);                                //
            d_Main.WriteOffset(0xB4 + d_Main2.size(), d_Main); //

            d_Main2.writeInt(0);
            d_Main2.writeInt(0);
            d_Main2.writeInt(0);

            d_Main.writeInt(0);                                // Scene
            d_Main.writeInt(0);                                //
            d_Main.WriteOffset(0xB4 + d_Main2.size(), d_Main); //

            d_Main2.writeInt(0);
            d_Main2.writeInt(0);
            d_Main2.writeInt(0);

            d_Main.writeOutput(d_Main2);
            d_Main.writeOutput(d_Main3);

            int headSize = o.size();

            o.writeIntAt(headSize, 0x08);
            o.writeIntAt(d_Main.size(), 0x20);
            o.writeOutput(d_Main);
            o.align(4);

            int stringSize = o.size();

            o.writeIntAt(stringSize, 0x0C);
            o.writeIntAt(d_String.size(), 0x24);
            o.writeOutput(d_String);
            o.align(4);

            int gpuSize = o.size();

            o.writeIntAt(d_GPU.size() > 0 ? gpuSize : 0, 0x10);
            o.writeIntAt(d_GPU.size(), 0x28);
            o.writeOutput(d_GPU);
            o.align(0x100);

            int dataSize = o.size();

            o.writeIntAt(dataSize, 0x14);
            o.writeIntAt(dataSize, 0x18);
            o.writeIntAt(d_Data.size(), 0x2C);
            o.writeIntAt(d_Data.size(), 0x30);
            o.writeOutput(d_Data);

            //Create Relocation Table
            // Flag is 7 bits
            // 0 - main 1 - string 2 - gpu 3 - data
            foreach (FileOutput.RelocOffset off in o.Offsets)
            {
                int size = 0;
                int code = 0;
                int div  = 4;
                if (off.output == d_Main || off.output == d_Main2 || off.output == d_Main3)
                {
                    size = headSize;
                    code = 0;
                    if (off.output == d_Main3)
                    {
                        off.Value += headSize;
                    }
                    if (off.output == d_Main2)
                    {
                        off.Value += d_Main2.size() + headSize;
                    }
                }
                if (off.output == d_String)
                {
                    size = stringSize;
                    code = 1;
                    div  = 1;
                }
                if (off.output == d_GPU)
                {
                    size = gpuSize;
                    code = 2;
                }
                if (off.output == d_Data)
                {
                    size = dataSize;
                    code = 3;
                }

                o.writeIntAt(off.Value - size, off.Position);
                int reloc = (code << 25) | (((off.Position - headSize) / div) & 0x1FFFFFF);
                Reloc.writeInt(reloc);
            }

            int relocSize = o.size();

            o.writeIntAt(relocSize, 0x1C);
            o.writeIntAt(Reloc.size(), 0x34);
            o.writeOutput(Reloc);

            o.save(fname);
        }
示例#29
0
文件: NUT.cs 项目: ReRezd/Smash-Forge
        public override byte[] Rebuild()
        {
            FileOutput o = new FileOutput();

            o.writeInt(0x4E545033); // "NTP3"
            o.writeShort(0x0200);
            o.writeShort(textures.Count);
            o.writeInt(0);
            o.writeInt(0);

            int offset = textures.Count * 0x60;

            foreach (var texture in textures)
            {
                int size       = 0;
                int headerSize = 0x60;

                foreach (var mip in texture.mipmaps)
                {
                    size += mip.Length;
                }

                // // headerSize 0x50 seems to crash with models
                //if (texture.mipmaps.Count == 1)
                //{
                //    headerSize = 0x50;
                //}

                o.writeInt(size + headerSize);
                o.writeInt(0x00);
                o.writeInt(size);
                o.writeShort(headerSize);
                o.writeShort(0);
                o.writeShort(texture.mipmaps.Count);
                o.writeShort(texture.getNutFormat());
                o.writeShort(texture.width);
                o.writeShort(texture.height);
                o.writeInt(0);
                o.writeInt(0);
                o.writeInt(offset);
                o.writeInt(0);
                o.writeInt(0);
                o.writeInt(0);

                if (headerSize > 0x50)
                {
                    foreach (var mip in texture.mipmaps)
                    {
                        o.writeInt(mip.Length);
                    }

                    // Sizes for missing mips.
                    for (int j = 0; j < 4 - texture.mipmaps.Count; j++)
                    {
                        o.writeInt(0);
                    }
                }

                o.writeInt(0x65587400); // "eXt\0"
                o.writeInt(0x20);
                o.writeInt(0x10);
                o.writeInt(0x00);
                o.writeInt(0x47494458); // "GIDX"
                o.writeInt(0x10);

                o.writeInt(texture.id);
                o.writeInt(0);

                offset += (size - headerSize);
            }

            foreach (var texture in textures)
            {
                int m = 0;

                foreach (var mip in texture.mipmaps)
                {
                    int off = 0;
                    if (texture.getNutFormat() == 14)
                    {
                        for (int h = 0; h < (texture.height / (Math.Pow(2, m))) * (texture.width / (Math.Pow(2, m))); h++)
                        {
                            for (int p = 0; p < 4; p++)
                            {
                                if (p == 0)
                                {
                                    o.writeByte(mip[off + 3]);
                                }
                                else
                                {
                                    o.writeByte(mip[off + (p - 1)]);
                                }
                            }
                            off += 4;
                        }
                    }
                    else
                    {
                        o.writeBytes(mip);
                    }
                    m++;
                }
            }

            return(o.getBytes());
        }
示例#30
0
        public override byte[] Rebuild()
        {
            FileOutput o    = new FileOutput();
            FileOutput data = new FileOutput();

            o.writeInt(0x4E545033); // "NTP3"
            o.writeShort(0x0200);
            o.writeShort(textures.Count);
            o.writeInt(0);
            o.writeInt(0);

            //calculate total header size
            int headerLength = 0;

            foreach (var texture in textures)
            {
                int headerSize = 0x50;

                if (texture.mipmaps.Count > 1)
                {
                    headerSize += texture.mipmaps.Count * 4;
                    while (headerSize % 16 != 0)
                    {
                        headerSize += 4;
                    }
                }
                headerLength += headerSize;
            }

            // write headers+data
            foreach (var texture in textures)
            {
                int size = 0;

                foreach (var mip in texture.mipmaps)
                {
                    size += mip.Length;
                    while (size % 16 != 0)
                    {
                        size += 1;
                    }
                }

                int headerSize = 0x50;

                // calculate header size
                if (texture.mipmaps.Count > 1)
                {
                    headerSize += texture.mipmaps.Count * 4;
                    //align to 16
                    while (headerSize % 16 != 0)
                    {
                        headerSize += 1;
                    }
                }

                o.writeInt(size + headerSize);
                o.writeInt(0x00);         //padding
                o.writeInt(size);
                o.writeShort(headerSize); //+ (texture.mipmaps.Count - 4 > 0 ? texture.mipmaps.Count - 4 : 0) * 4
                o.writeShort(0);
                o.writeShort(texture.mipmaps.Count);
                o.writeShort(texture.getNutFormat());
                o.writeShort(texture.width);
                o.writeShort(texture.height);
                o.writeInt(0);
                o.writeInt(0);
                o.writeInt(headerLength + data.size());
                headerLength -= headerSize;
                o.writeInt(0);
                o.writeInt(0);
                o.writeInt(0);

                if (texture.getNutFormat() == 14 || texture.getNutFormat() == 17)
                {
                    foreach (byte[] mip in texture.mipmaps)
                    {
                        for (int t = 0; t < mip.Length; t += 4)
                        {
                            byte t1 = mip[t + 3];
                            mip[t + 3] = mip[t + 2];
                            mip[t + 2] = mip[t + 1];
                            mip[t + 1] = mip[t];
                            mip[t]     = t1;
                        }
                    }
                }

                foreach (var mip in texture.mipmaps)
                {
                    int ds = data.size();
                    data.writeBytes(mip);
                    data.align(0x10);
                    if (texture.mipmaps.Count > 1)
                    {
                        o.writeInt(data.size() - ds);
                    }
                }
                o.align(16);

                if (texture.getNutFormat() == 14 || texture.getNutFormat() == 17)
                {
                    foreach (byte[] mip in texture.mipmaps)
                    {
                        for (int t = 0; t < mip.Length; t += 4)
                        {
                            byte t1 = mip[t];
                            mip[t]     = mip[t + 1];
                            mip[t + 1] = mip[t + 2];
                            mip[t + 2] = mip[t + 3];
                            mip[t + 3] = t1;
                        }
                    }
                }

                o.writeInt(0x65587400); // "eXt\0"
                o.writeInt(0x20);
                o.writeInt(0x10);
                o.writeInt(0x00);
                o.writeInt(0x47494458); // "GIDX"
                o.writeInt(0x10);

                o.writeInt(texture.id);
                o.writeInt(0);
            }
            o.writeOutput(data);

            return(o.getBytes());
        }