Exemplo 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 = ReadUshorts(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);
                    }
                    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]);
                }
            }
        }
Exemplo n.º 2
0
        private void CreateFromPMD(PMD pmd)
        {
            VertNormUv = new float[pmd.Vertex.Length / 3 * 8];
            for (int i = 0; i < pmd.Vertex.Length / 3; i++)
            {
                VertNormUv[i * 8 + 0] = pmd.Vertex[i * 3 + 0];
                VertNormUv[i * 8 + 1] = pmd.Vertex[i * 3 + 1];
                VertNormUv[i * 8 + 2] = pmd.Vertex[i * 3 + 2];
                VertNormUv[i * 8 + 3] = pmd.Normal[i * 3 + 0];
                VertNormUv[i * 8 + 4] = pmd.Normal[i * 3 + 1];
                VertNormUv[i * 8 + 5] = pmd.Normal[i * 3 + 2];
                VertNormUv[i * 8 + 6] = pmd.Uv[i * 2 + 0];
                VertNormUv[i * 8 + 7] = pmd.Uv[i * 2 + 1];
            }

            Index = new ushort[pmd.Index.Length];
            for (int i = 0; i < pmd.Index.Length; i++)
            {
                Index[i] = (ushort)pmd.Index[i];
            }

            Materials = new FMaterial[pmd.RenderLists.Count()];
            for (int i = 0; i < pmd.RenderLists.Count(); i++)
            {
                Materials[i] = new FMaterial();
                Materials[i].diffuse_color = pmd.RenderLists[i].material.diffuse_color;
                Materials[i].power = pmd.RenderLists[i].material.power;
                Materials[i].specular_color = pmd.RenderLists[i].material.specular_color;
                Materials[i].emmisive_color = pmd.RenderLists[i].material.emmisive_color;
                Materials[i].toon_index = pmd.RenderLists[i].material.toon_index;
                Materials[i].edge_flag = pmd.RenderLists[i].material.edge_flag;
                Materials[i].face_vert_count = pmd.RenderLists[i].face_vert_count;
                Materials[i].texture = pmd.RenderLists[i].material.texture;
                Materials[i].sphere = "";   // ad-hock
                Materials[i].face_vert_offset = pmd.RenderLists[i].face_vert_offset;
                Materials[i].bone_num = pmd.RenderLists[i].bone_num;
                Materials[i].weight = pmd.RenderLists[i].weight;
                Materials[i].bone_inv_map = pmd.RenderLists[i].bone_inv_map;
            }

            Bones = new Bone[pmd.RenderBones.Count()];
            for (int i = 0; i < pmd.RenderBones.Count(); i++)
            {
                Bones[i] = pmd.RenderBones[i].bone;
            }

            IKs = pmd.IK;
            ToonNames = pmd.toon_name;

            is_pmf = true;
        }