Exemplo n.º 1
0
        private static Vertex ReadVertex(BinaryReader reader, PmxConfig pmxConfig)
        {
            var pv     = ReadVertexBasic(reader);
            var vertex = new Vertex
            {
                Coordinate   = pv.Coordinate,
                Normal       = pv.Normal,
                UvCoordinate = pv.UvCoordinate
            };

            if (pmxConfig.ExtraUvNumber > 0)
            {
                var extraUv = new Vector4[pmxConfig.ExtraUvNumber];
                for (var ei = 0; ei < pmxConfig.ExtraUvNumber; ++ei)
                {
                    extraUv[ei] = MMDReaderUtil.ReadVector4(reader);
                }
                vertex.ExtraUvCoordinate = extraUv;
            }

            var op           = new SkinningOperator();
            var skinningType = (SkinningOperator.SkinningType)reader.ReadByte();

            op.Type = skinningType;

            switch (skinningType)
            {
            case SkinningOperator.SkinningType.SkinningBdef1:
                var bdef1 = new SkinningOperator.Bdef1();
                bdef1.BoneId = MMDReaderUtil.ReadIndex(reader, pmxConfig.BoneIndexSize);
                op.Param     = bdef1;
                break;

            case SkinningOperator.SkinningType.SkinningBdef2:
                var bdef2 = new SkinningOperator.Bdef2();
                bdef2.BoneId[0]  = MMDReaderUtil.ReadIndex(reader, pmxConfig.BoneIndexSize);
                bdef2.BoneId[1]  = MMDReaderUtil.ReadIndex(reader, pmxConfig.BoneIndexSize);
                bdef2.BoneWeight = reader.ReadSingle();
                op.Param         = bdef2;
                break;

            case SkinningOperator.SkinningType.SkinningBdef4:
                var bdef4 = new SkinningOperator.Bdef4();
                for (var j = 0; j < 4; ++j)
                {
                    bdef4.BoneId[j] = MMDReaderUtil.ReadIndex(reader, pmxConfig.BoneIndexSize);
                }
                for (var j = 0; j < 4; ++j)
                {
                    bdef4.BoneWeight[j] = reader.ReadSingle();
                }
                op.Param = bdef4;
                break;

            case SkinningOperator.SkinningType.SkinningSdef:
                var sdef = new SkinningOperator.Sdef();
                sdef.BoneId[0]  = MMDReaderUtil.ReadIndex(reader, pmxConfig.BoneIndexSize);
                sdef.BoneId[1]  = MMDReaderUtil.ReadIndex(reader, pmxConfig.BoneIndexSize);
                sdef.BoneWeight = reader.ReadSingle();
                sdef.C          = MMDReaderUtil.ReadVector3(reader);
                sdef.R0         = MMDReaderUtil.ReadVector3(reader);
                sdef.R1         = MMDReaderUtil.ReadVector3(reader);
                op.Param        = sdef;
                break;

            default:
                throw new MMDFileParseException("invalid skinning type: " + skinningType);
            }
            vertex.SkinningOperator = op;
            vertex.EdgeScale        = reader.ReadSingle();
            return(vertex);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 关键部分
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="pmxConfig"></param>
        /// <returns></returns>
        private static Vertex ReadVertex(BinaryReader reader, PmxConfig pmxConfig)
        {
            var pv = ReadVertexBasic(reader);
            //new一个顶点,赋值

            var vertex = new Vertex
            {
                Coordinate   = pv.Coordinate,
                Normal       = pv.Normal,
                UvCoordinate = pv.UvCoordinate
            };

            //OYM:如果有额外的uv(在底层设置那里)
            //OYM:也不知道到底有什么用...
            if (pmxConfig.ExtraUvNumber > 0)
            {
                var extraUv = new Vector4[pmxConfig.ExtraUvNumber];
                for (var ei = 0; ei < pmxConfig.ExtraUvNumber; ++ei)
                {
                    extraUv[ei] = MmdReaderUtil.ReadVector4(reader);
                }
                vertex.ExtraUvCoordinate = extraUv;
            }

            var op           = new SkinningOperator();
            var skinningType = (SkinningOperator.SkinningType)reader.ReadByte(); //OYM:蒙皮种类

            op.Type = skinningType;                                              //OYM:看不懂就完事了

            switch (skinningType)                                                //OYM:应该是权重没跑了
            {
            case SkinningOperator.SkinningType.SkinningBdef1:
                var bdef1 = new SkinningOperator.Bdef1();    //OYM:注意这里用了父类可以为任意形式子类的方法,很模糊但是还是要好好学
                bdef1.BoneId = MmdReaderUtil.ReadIndex(reader, pmxConfig.BoneIndexSize);
                op.Param     = bdef1;
                break;

            case SkinningOperator.SkinningType.SkinningBdef2:
                var bdef2 = new SkinningOperator.Bdef2();
                bdef2.BoneId[0]  = MmdReaderUtil.ReadIndex(reader, pmxConfig.BoneIndexSize);
                bdef2.BoneId[1]  = MmdReaderUtil.ReadIndex(reader, pmxConfig.BoneIndexSize);
                bdef2.BoneWeight = reader.ReadSingle();
                op.Param         = bdef2;
                break;

            case SkinningOperator.SkinningType.SkinningBdef4:
                var bdef4 = new SkinningOperator.Bdef4();
                for (var j = 0; j < 4; ++j)
                {
                    bdef4.BoneId[j] = MmdReaderUtil.ReadIndex(reader, pmxConfig.BoneIndexSize);
                }
                for (var j = 0; j < 4; ++j)
                {
                    bdef4.BoneWeight[j] = reader.ReadSingle();
                }
                op.Param = bdef4;
                break;

            case SkinningOperator.SkinningType.SkinningSdef:    //OYM:这个猜不准,到时候再看
                var sdef = new SkinningOperator.Sdef();
                sdef.BoneId[0]  = MmdReaderUtil.ReadIndex(reader, pmxConfig.BoneIndexSize);
                sdef.BoneId[1]  = MmdReaderUtil.ReadIndex(reader, pmxConfig.BoneIndexSize);
                sdef.BoneWeight = reader.ReadSingle();
                sdef.C          = MmdReaderUtil.ReadVector3(reader);
                sdef.R0         = MmdReaderUtil.ReadVector3(reader);
                sdef.R1         = MmdReaderUtil.ReadVector3(reader);
                op.Param        = sdef;
                break;

            default:
                throw new MmdFileParseException("invalid skinning type: " + skinningType);
            }
            vertex.SkinningOperator = op;                  //OYM:顶点的蒙皮操作
            vertex.EdgeScale        = reader.ReadSingle(); //OYM:这个实在猜不准,但是考虑到就一个单精度,猜一个倍率好了
            return(vertex);
        }