예제 #1
0
        public override void LoadFromStream(BinaryReader br, MMDImportSettings importSettings)
        {
            this.Position = PMXVector3.LoadFromStreamStatic(br);
            this.Normals  = PMXVector3.LoadFromStreamStatic(br);
            this.UV       = PMXVector2.LoadFromStreamStatic(br);


            if (importSettings.Format == MMDImportSettings.ModelFormat.PMX)
            { //PMX format
                for (int i = 0; i < importSettings.ExtendedUV; i++)
                {
                    this.AddedUVs.Add(PMXQuaternion.LoadFromStreamStatic(br));
                }

                byte deformType = br.ReadByte();

                switch (deformType)
                {
                case PMXBaseDeform.DEFORM_IDENTIFY_BDEF1:
                    this.Deform = new PMXVertexDeformBDEF1(this.Model, this);
                    break;

                case PMXBaseDeform.DEFORM_IDENTIFY_BDEF2:
                    this.Deform = new PMXVertexDeformBDEF2(this.Model, this);
                    break;

                case PMXBaseDeform.DEFORM_IDENTIFY_BDEF4:
                    this.Deform = new PMXVertexDeformBDEF4(this.Model, this);
                    break;

                case PMXBaseDeform.DEFORM_IDENTIFY_SDEF:
                    this.Deform = new PMXVertexDeformSDEF(this.Model, this);
                    break;

                case PMXBaseDeform.DEFORM_IDENTIFY_QDEF:
                default:
                    this.Deform = new PMXVertexDeformQDEF(this.Model, this);
                    break;
                }
                this.Deform.LoadFromStream(br, importSettings);

                this.OutlineMagnification = br.ReadSingle();
            }
            else
            { //PMD format
                this.Deform = PMXVertexDeformBDEF2.DeformFromPMDFile(this.Model, this, br);

                this.OutlineMagnification = ((br.ReadByte() == 0) ? 1.0f : 0.0f);
            }
        }
예제 #2
0
        public static PMXBaseDeform DeformFromPMDFile(PMXModel model, PMXVertex vertex, BinaryReader br)
        {
            ushort boneId1 = br.ReadUInt16();
            ushort boneId2 = br.ReadUInt16();
            byte   weight  = br.ReadByte();

            if (weight >= 100)
            { //BDEF1
                return(PMXVertexDeformBDEF1.DeformFromPMDFile(model, vertex, boneId1));
            }
            else if (weight <= 0)
            { //BDEF 1 as well
                return(PMXVertexDeformBDEF1.DeformFromPMDFile(model, vertex, boneId2));
            }
            else
            { //BDEF2
                PMXVertexDeformBDEF2 res = new PMXVertexDeformBDEF2(model, vertex);
                res.bone1Index  = (int)boneId1;
                res.bone2Index  = (int)boneId2;
                res.Bone1Weight = (float)weight / 100.0f;
                return(res);
            }
        }