private static void ReadConstraints(BinaryReader reader, RawMMDModel model)
        {
            var constraintNum = reader.ReadUInt32();

            model.Joints = new Model.Joint[constraintNum];
            for (var i = 0; i < constraintNum; ++i)
            {
                var constraint = new Model.Joint();
                constraint.Name = MMDReaderUtil.ReadStringFixedLength(reader, 20, Tools.JapaneseEncoding);
                constraint.AssociatedRigidBodyIndex[0] = reader.ReadInt32();
                constraint.AssociatedRigidBodyIndex[1] = reader.ReadInt32();
                constraint.Position         = MMDReaderUtil.ReadVector3(reader);
                constraint.Rotation         = MMDReaderUtil.ReadAmpVector3(reader, Mathf.Rad2Deg);
                constraint.PositionLowLimit = MMDReaderUtil.ReadVector3(reader);
                constraint.PositionHiLimit  = MMDReaderUtil.ReadVector3(reader);
                constraint.RotationLowLimit = MMDReaderUtil.ReadVector3(reader);
                constraint.RotationHiLimit  = MMDReaderUtil.ReadVector3(reader);
                constraint.SpringTranslate  = MMDReaderUtil.ReadVector3(reader);
                constraint.SpringRotate     = MMDReaderUtil.ReadVector3(reader);
                model.Joints[i]             = constraint;
            }
        }
Beispiel #2
0
        private static void ReadJoints(BinaryReader reader, RawMMDModel model, PmxConfig pmxConfig)
        {
            var constraintNum = reader.ReadInt32();

            model.Joints = new Model.Joint[constraintNum];
            for (var i = 0; i < constraintNum; ++i)
            {
                var joint = new Model.Joint
                {
                    Name   = MMDReaderUtil.ReadSizedString(reader, pmxConfig.Encoding),
                    NameEn = MMDReaderUtil.ReadSizedString(reader, pmxConfig.Encoding)
                };
                var dofType = reader.ReadByte();
                if (dofType == 0)
                {
                    joint.AssociatedRigidBodyIndex[0] =
                        MMDReaderUtil.ReadIndex(reader, pmxConfig.RigidBodyIndexSize);
                    joint.AssociatedRigidBodyIndex[1] =
                        MMDReaderUtil.ReadIndex(reader, pmxConfig.RigidBodyIndexSize);
                    joint.Position         = MMDReaderUtil.ReadVector3(reader);
                    joint.Rotation         = MMDReaderUtil.ReadAmpVector3(reader, Mathf.Rad2Deg);
                    joint.PositionLowLimit = MMDReaderUtil.ReadVector3(reader);
                    joint.PositionHiLimit  = MMDReaderUtil.ReadVector3(reader);
                    joint.RotationLowLimit = MMDReaderUtil.ReadVector3(reader);
                    joint.RotationHiLimit  = MMDReaderUtil.ReadVector3(reader);
                    joint.SpringTranslate  = MMDReaderUtil.ReadVector3(reader);
                    joint.SpringRotate     = MMDReaderUtil.ReadVector3(reader);
                }
                else
                {
                    throw new MMDFileParseException("Only 6DOF spring joints are supported.");
                }

                model.Joints[i] = joint;
            }
        }