Ejemplo n.º 1
0
        public override MmdModel Read(BinaryReader reader, ModelReadConfig config)
        {
            var pmxHeader = ReadMeta(reader);

            if (!"PMX ".Equals(pmxHeader.Magic) || Math.Abs(pmxHeader.Version - 2.0f) > 0.0001f || pmxHeader.FileFlagSize != 8)
            {
                throw new MmdFileParseException("File is not a PMX 2.0 file");
            }

            var model     = new MmdModel();
            var pmxConfig = ReadPmxConfig(reader, model);

            ReadModelNameAndDescription(reader, model, pmxConfig);
            ReadVertices(reader, model, pmxConfig);
            ReadTriangles(reader, model, pmxConfig);
            var textureList = ReadTextureList(reader, pmxConfig);

            ReadParts(reader, config, model, pmxConfig, textureList);
            ReadBones(reader, model, pmxConfig);
            ReadMorphs(reader, model, pmxConfig);
            ReadEntries(reader, pmxConfig);
            ReadRigidBodies(reader, model, pmxConfig);
            ReadConstraints(reader, model, pmxConfig);
            model.Normalize();
            return(model);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 读取mmd
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public override MmdModel Read(BinaryReader reader, ModelReadConfig config)
        {
            //config虽然现在是空的,但是等下会被赋值,作者只是想顺便传出去一下
            var pmxHeader = ReadMeta(reader);                                                                                   //OYM:读取

            if (!"PMX ".Equals(pmxHeader.Magic) || Math.Abs(pmxHeader.Version - 2.0f) > 0.0001f || pmxHeader.FileFlagSize != 8) //OYM:验证文件
            {
                throw new MmdFileParseException("File is not a PMX 2.0 file");
            }

            var model     = new MmdModel();
            var pmxConfig = ReadPmxConfig(reader, model);             //OYM:底层读取,另外config在这里获取

            ReadModelNameAndDescription(reader, model, pmxConfig);    //OYM:读取文件信息
            ReadVertices(reader, model, pmxConfig);                   //OYM:读取顶点
            ReadTriangles(reader, model, pmxConfig);                  //OYM:读取三角形
            var textureList = ReadTextureList(reader, pmxConfig);     //OYM:获取所有材质的路径的一个类

            ReadParts(reader, config, model, pmxConfig, textureList); //OYM:获取材质shader的类
            ReadBones(reader, model, pmxConfig);                      //OYM:获取骨骼
            ReadMorphs(reader, model, pmxConfig);                     //OYM:表情包~
            ReadEntries(reader, pmxConfig);                           //OYM:没用,但是还是要把字节取出来丢掉
            ReadRigidBodies(reader, model, pmxConfig);                //OYM:获取碰撞
            ReadConstraints(reader, model, pmxConfig);                //OYM:获取约束
            model.Normalize();                                        //OYM:检查顶点
            return(model);
        }
Ejemplo n.º 3
0
        public override MmdModel Read(BinaryReader reader, ModelReadConfig config)
        {
            var model   = new MmdModel();
            var context = new PmdReadContext();
            var meta    = ReadMeta(reader);

            if (!"Pmd".Equals(meta.Magic) || Math.Abs(meta.Version - 1.0f) > 0.0001f)
            {
                throw new MmdFileParseException("File is not a PMD 1.0 file");
            }
            ReadDescription(reader, model);
            ReadVertices(reader, model);
            ReadTriangles(reader, model);
            var toonTextureIds = new List <int>();

            ReadParts(reader, model, toonTextureIds);
            ReadBonesAndIks(reader, model, context);
            ReadFaces(reader, model);
            ReadFacdDisplayListNames(reader);
            ReadBoneNameList(reader, context);
            ReadBoneDisp(reader);
            if (MmdReaderUtil.Eof(reader))
            {
                goto PMD_READER_READ_LEGACY_30;
            }
            ReadInfoEn(reader, model, context);
            if (MmdReaderUtil.Eof(reader))
            {
                goto PMD_READER_READ_LEGACY_30;
            }
            ReadCustomTextures(reader, config, model, toonTextureIds);
            if (MmdReaderUtil.Eof(reader))
            {
                goto PMD_READER_READ_LEGACY_50;
            }
            ReadRigidBodies(reader, model, context);
            ReadConstraints(reader, model);
            goto PMD_READER_READ_SUCCEED;

PMD_READER_READ_LEGACY_30:

            for (var i = 0; i < model.Parts.Length; ++i)
            {
                var material = model.Parts[i].Material;
                material.Toon = MmdTextureUtil.GetGlobalToon(toonTextureIds[i], config.GlobalToonPath);
            }
PMD_READER_READ_LEGACY_50:
PMD_READER_READ_SUCCEED:
            model.Normalize();
            return(model);
        }