Esempio n. 1
0
        public void Load(string filename)
        {
            using (var fs = File.OpenRead(filename))
                using (var bs = new BinaryReader(fs))
                {
                    // header
                    string s = bs.ReadString();
                    Log.Debug("RMC", "MAGIC: " + s);

                    // VertNormUv
                    Log.Debug("RMC", "VertNormUv");
                    VertNormUv = ReadFloats(bs);

                    // Index
                    Log.Debug("RMC", "Index");
                    Index = ReadShorts(bs);

                    // Bone
                    Log.Debug("RMC", "Bone");
                    Bones = new Bone[bs.ReadUInt32()];
                    Log.Debug("RMC", "count : " + Bones.Length.ToString());
                    for (int i = 0; i < Bones.Length; i++)
                    {
                        Bones[i]          = new Bone();
                        Bones[i].name     = bs.ReadString();
                        Bones[i].parent   = bs.ReadInt16();
                        Bones[i].tail     = bs.ReadInt16();
                        Bones[i].type     = bs.ReadByte();
                        Bones[i].ik       = bs.ReadInt16();
                        Bones[i].head_pos = ReadFloats(bs, 3);
                        Bones[i].is_leg   = bs.ReadBoolean();
                    }

                    // IKs
                    Log.Debug("RMC", "IK");
                    IKs = new IK[bs.ReadUInt32()];
                    Log.Debug("RMC", "count : " + IKs.Length.ToString());
                    for (int i = 0; i < IKs.Length; i++)
                    {
                        IKs[i] = new IK();
                        IKs[i].ik_bone_index        = bs.ReadInt32();
                        IKs[i].ik_target_bone_index = bs.ReadInt32();
                        IKs[i].ik_chain_length      = bs.ReadByte();
                        IKs[i].iterations           = bs.ReadInt32();
                        IKs[i].control_weight       = bs.ReadSingle();
                        IKs[i].ik_child_bone_index  = new short[bs.ReadUInt32()];
                        for (int j = 0; j < IKs[i].ik_child_bone_index.Length; j++)
                        {
                            IKs[i].ik_child_bone_index[j] = bs.ReadInt16();
                        }
                    }

                    // Materials
                    Log.Debug("RMC", "Material");
                    Materials = new FMaterial[bs.ReadUInt32()];
                    Log.Debug("RMC", "count : " + Materials.Length.ToString());
                    for (int i = 0; i < Materials.Length; i++)
                    {
                        Materials[i] = new FMaterial();


                        Materials[i].diffuse_color   = ReadFloats(bs, 4);
                        Materials[i].power           = bs.ReadSingle();
                        Materials[i].specular_color  = ReadFloats(bs, 3);
                        Materials[i].emmisive_color  = ReadFloats(bs, 3);
                        Materials[i].toon_index      = bs.ReadByte();
                        Materials[i].edge_flag       = bs.ReadByte();
                        Materials[i].face_vert_count = bs.ReadInt32();
                        if (bs.ReadBoolean())
                        {
                            Materials[i].texture = bs.ReadString();
                            Log.Debug("RMC", "load texture in material ... " + Materials[i].texture);
                            var sf = bs.ReadByte();
                            if (sf == 1)
                            {
                                Materials[i].sph = bs.ReadString();
                                Materials[i].spa = null;
                                Log.Debug("RMC", "load sphere(sph) in material ... " + Materials[i].sph);
                            }
                            else if (sf == 2)
                            {
                                Materials[i].sph = null;
                                Materials[i].spa = bs.ReadString();
                                Log.Debug("RMC", "load sphere(spa) in material ... " + Materials[i].spa);
                            }
                        }
                        Materials[i].face_vert_offset = bs.ReadInt32();
                        Materials[i].bone_num         = bs.ReadInt32();
                        Log.Debug("RMC", "Bone num: " + Materials[i].bone_num.ToString());
                        Materials[i].weight       = bs.ReadBytes(VertNormUv.Length / 8 * 3);
                        Materials[i].bone_inv_map = new int[48]; // ad-hock
                        for (int j = 0; j < Materials[i].bone_inv_map.Length; j++)
                        {
                            Materials[i].bone_inv_map[j] = bs.ReadInt32();
                        }
                    }

                    // ToonNames
                    Log.Debug("RMC", "ToonNames");
                    ToonNames = new string[11];
                    for (int i = 0; i < 11; i++)
                    {
                        ToonNames[i] = bs.ReadString();
                        Log.Debug("RMC", ToonNames[i]);
                    }
                }
        }
Esempio n. 2
0
        public void Load(string filename)
        {
            using(var fs = File.OpenRead(filename))
            using(var bs = new BinaryReader(fs))
            {
                // header
                string s = bs.ReadString();
                Log.Debug("RMC", "MAGIC: " + s);

                // VertNormUv
                Log.Debug("RMC", "VertNormUv");
                VertNormUv = ReadFloats(bs);

                // Index
                Log.Debug("RMC", "Index");
                Index = ReadShorts(bs);

                // Bone
                Log.Debug("RMC", "Bone");
                Bones = new Bone[bs.ReadUInt32()];
                Log.Debug("RMC", "count : " + Bones.Length.ToString());
                for (int i = 0; i < Bones.Length; i++)
                {
                    Bones[i] = new Bone();
                    Bones[i].name = bs.ReadString();
                    Bones[i].parent = bs.ReadInt16();
                    Bones[i].tail = bs.ReadInt16();
                    Bones[i].type = bs.ReadByte();
                    Bones[i].ik = bs.ReadInt16();
                    Bones[i].head_pos = ReadFloats(bs, 3);
                    Bones[i].is_leg = bs.ReadBoolean();
                }

                // IKs
                Log.Debug("RMC", "IK");
                IKs = new IK[bs.ReadUInt32()];
                Log.Debug("RMC", "count : " + IKs.Length.ToString());
                for (int i = 0; i < IKs.Length; i++)
                {
                    IKs[i] = new IK();
                    IKs[i].ik_bone_index = bs.ReadInt32();
                    IKs[i].ik_target_bone_index = bs.ReadInt32();
                    IKs[i].ik_chain_length = bs.ReadByte();
                    IKs[i].iterations = bs.ReadInt32();
                    IKs[i].control_weight = bs.ReadSingle();
                    IKs[i].ik_child_bone_index = new short[bs.ReadUInt32()];
                    for (int j = 0; j < IKs[i].ik_child_bone_index.Length; j++)
                    {
                        IKs[i].ik_child_bone_index[j] = bs.ReadInt16();
                    }
                }

                // Materials
                Log.Debug("RMC", "Material");
                Materials = new FMaterial[bs.ReadUInt32()];
                Log.Debug("RMC", "count : " + Materials.Length.ToString());
                for (int i = 0; i < Materials.Length; i++)
                {
                    Materials[i] = new FMaterial();

                    Materials[i].diffuse_color = ReadFloats(bs, 4);
                    Materials[i].power = bs.ReadSingle();
                    Materials[i].specular_color = ReadFloats(bs, 3);
                    Materials[i].emmisive_color = ReadFloats(bs, 3);
                    Materials[i].toon_index = bs.ReadByte();
                    Materials[i].edge_flag = bs.ReadByte();
                    Materials[i].face_vert_count = bs.ReadInt32();
                    if (bs.ReadBoolean())
                    {
                        Materials[i].texture = bs.ReadString();
                        Log.Debug("RMC", "load texture in material ... " + Materials[i].texture);
                        var sf = bs.ReadByte();
                        if (sf == 1)
                        {
                            Materials[i].sph = bs.ReadString();
                            Materials[i].spa = null;
                            Log.Debug("RMC", "load sphere(sph) in material ... " + Materials[i].sph);
                        } else if (sf == 2)
                        {
                            Materials[i].sph = null;
                            Materials[i].spa = bs.ReadString();
                            Log.Debug("RMC", "load sphere(spa) in material ... " + Materials[i].spa);
                        }
                    }
                    Materials[i].face_vert_offset = bs.ReadInt32();
                    Materials[i].bone_num = bs.ReadInt32();
                    Log.Debug("RMC", "Bone num: " + Materials[i].bone_num.ToString());
                    Materials[i].weight = bs.ReadBytes(VertNormUv.Length / 8 * 3);
                    Materials[i].bone_inv_map = new int[48];    // ad-hock
                    for (int j = 0; j < Materials[i].bone_inv_map.Length; j++)
                    {
                        Materials[i].bone_inv_map[j] = bs.ReadInt32();
                    }
                }

                // ToonNames
                Log.Debug("RMC", "ToonNames");
                ToonNames = new string[11];
                for (int i = 0; i < 11; i++)
                {
                    ToonNames[i] = bs.ReadString();
                    Log.Debug("RMC", ToonNames[i]);
                }
            }
        }