예제 #1
0
        public void Write(BinaryWriter writer, PmxHeaderData header)
        {
            writer.WritePmxId(header.BoneIndexSize, Index);

            writer.Write(Position);
            writer.Write(Rotation);
        }
예제 #2
0
        public void Write(BinaryWriter writer, PmxHeaderData header)
        {
            writer.WriteText(header.Encoding, MaterialName);
            writer.WriteText(header.Encoding, MaterialNameE);

            writer.WriteV(Diffuse);
            writer.WriteV(Specular);
            writer.Write(Shininess);
            writer.WriteV(Ambient);

            writer.Write((byte)Flag);

            writer.WriteV(Edge);
            writer.Write(EdgeThick);

            writer.WritePmxId(header.TextureIndexSize, TextureId);
            writer.WritePmxId(header.TextureIndexSize, SphereId);
            writer.Write((byte)Mode);
            writer.Write((byte)SharedToon);

            if (SharedToon == 0)
            {
                writer.WritePmxId(header.TextureIndexSize, ToonId);
            }
            else
            {
                writer.Write((byte)ToonId);
            }

            writer.WriteText(header.Encoding, Script);

            writer.Write(FaceCount);
        }
예제 #3
0
        public void Read(BinaryReader reader, PmxHeaderData header)
        {
            Index = reader.ReadPmxId(header.BoneIndexSize);

            Position = reader.ReadVector3();
            Rotation = reader.ReadQuaternion();
        }
예제 #4
0
        public void Read(BinaryReader reader, PmxHeaderData header)
        {
            MaterialName  = reader.ReadText(header.Encoding);
            MaterialNameE = reader.ReadText(header.Encoding);

            Diffuse   = reader.ReadVector4();
            Specular  = reader.ReadVector3();
            Shininess = reader.ReadSingle();
            Ambient   = reader.ReadVector3();

            Flag = (RenderFlags)reader.ReadByte();

            Edge      = reader.ReadVector4();
            EdgeThick = reader.ReadSingle();

            TextureId  = reader.ReadPmxId(header.TextureIndexSize);
            SphereId   = reader.ReadPmxId(header.TextureIndexSize);
            Mode       = (SphereMode)reader.ReadByte();
            SharedToon = (ToonMode)reader.ReadByte();

            if (SharedToon == 0)
            {
                ToonId = reader.ReadPmxId(header.TextureIndexSize);
            }
            else
            {
                ToonId = reader.ReadByte();
            }

            Script = reader.ReadText(header.Encoding);

            FaceCount = reader.ReadInt32();
        }
예제 #5
0
        public void ReadPmd(BinaryReader reader, PmxHeaderData header)
        {
            reader.ReadBytes(PMD_MAGIC_BYTES.Length);

            ModelName   = reader.ReadText(Encoding, PMD_MODELNAME_LEN);
            Description = reader.ReadText(Encoding, PMD_MODELDESC_LEN);
        }
예제 #6
0
 public void Read(BinaryReader reader, PmxHeaderData header)
 {
     Index    = reader.ReadPmxId(header.RigidIndexSize);
     IsLocal  = reader.ReadBoolean();
     Velocity = reader.ReadVector3();
     Torque   = reader.ReadVector3();
 }
예제 #7
0
 public void Write(BinaryWriter writer, PmxHeaderData header)
 {
     writer.WritePmxId(header.RigidIndexSize, Index);
     writer.Write(IsLocal);
     writer.Write(Velocity);
     writer.Write(Torque);
 }
예제 #8
0
        public void Read(BinaryReader reader, PmxHeaderData header)
        {
            BoneName  = reader.ReadText(header.Encoding);
            BoneNameE = reader.ReadText(header.Encoding);

            Pos      = reader.ReadVector3();
            ParentId = reader.ReadPmxId(header.BoneIndexSize);

            Depth = reader.ReadInt32();
            Flag  = (BoneFlags)reader.ReadInt16();

            if (Flag.HasFlag(BoneFlags.OFFSET))
            {
                ArrowId = reader.ReadPmxId(header.BoneIndexSize);
            }
            else
            {
                PosOffset = reader.ReadVector3();
            }

            if (Flag.HasFlag(BoneFlags.ROTATE_LINK) || Flag.HasFlag(BoneFlags.MOVE_LINK))
            {
                LinkParentId = reader.ReadPmxId(header.BoneIndexSize);
                LinkWeight   = reader.ReadSingle();
            }

            if (Flag.HasFlag(BoneFlags.AXIS_ROTATE))
            {
                AxisVec = reader.ReadVector3();
            }

            if (Flag.HasFlag(BoneFlags.LOCAL_AXIS))
            {
                LocalAxisVecX = reader.ReadVector3();
                LocalAxisVecZ = reader.ReadVector3();
            }

            if (Flag.HasFlag(BoneFlags.EXTRA))
            {
                ExtraParentId = reader.ReadInt32();
            }

            if (Flag.HasFlag(BoneFlags.IK))
            {
                IkTargetId = reader.ReadPmxId(header.BoneIndexSize);

                IkDepth    = reader.ReadInt32();
                AngleLimit = reader.ReadSingle();

                int boneNum = reader.ReadInt32();
                IkChilds = new PmxIkData[boneNum];

                for (int i = 0; i < boneNum; i++)
                {
                    IkChilds[i] = new PmxIkData();
                    IkChilds[i].Read(reader, header);
                }
            }
        }
예제 #9
0
        public void Write(BinaryWriter writer, PmxHeaderData header)
        {
            writer.WriteText(header.Encoding, BoneName);
            writer.WriteText(header.Encoding, BoneNameE);

            writer.Write(Pos);
            writer.WritePmxId(header.BoneIndexSize, ParentId);

            writer.Write(Depth);
            writer.Write((short)Flag);

            if (Flag.HasFlag(BoneFlags.OFFSET))
            {
                writer.WritePmxId(header.BoneIndexSize, ArrowId);
            }
            else
            {
                writer.Write(PosOffset);
            }

            if (Flag.HasFlag(BoneFlags.ROTATE_LINK) || Flag.HasFlag(BoneFlags.MOVE_LINK))
            {
                writer.WritePmxId(header.BoneIndexSize, LinkParentId);
                writer.Write(LinkWeight);
            }

            if (Flag.HasFlag(BoneFlags.AXIS_ROTATE))
            {
                writer.Write(AxisVec);
            }

            if (Flag.HasFlag(BoneFlags.LOCAL_AXIS))
            {
                writer.Write(LocalAxisVecX);
                writer.Write(LocalAxisVecZ);
            }

            if (Flag.HasFlag(BoneFlags.EXTRA))
            {
                writer.Write(ExtraParentId);
            }

            if (Flag.HasFlag(BoneFlags.IK))
            {
                writer.WritePmxId(header.BoneIndexSize, IkTargetId);

                writer.Write(IkDepth);
                writer.Write(AngleLimit);

                int boneNum = IkChilds.Length;

                writer.Write(boneNum);
                for (int i = 0; i < boneNum; i++)
                {
                    IkChilds[i].Write(writer, header);
                }
            }
        }
예제 #10
0
        public void Read(BinaryReader reader, PmxHeaderData header)
        {
            Pos    = reader.ReadVector3();
            Normal = reader.ReadVector3();
            Uv     = reader.ReadVector2();

            WeightType = (WeightType)reader.ReadByte();

            switch (WeightType)
            {
            case WEIGHT_TYPE_BDEF1:
                BoneId = new int[1];
                break;

            case WeightType.BDEF2:
            case WeightType.SDEF:
                BoneId = new int[2];
                break;

            case WeightType.BDEF4:
                BoneId = new int[4];
                break;
            }

            for (int i = 0; i < BoneId.Length; i++)
            {
                BoneId[i] = reader.ReadPmxId(header.BoneIndexSize);
            }

            switch (WeightType)
            {
            case WEIGHT_TYPE_BDEF1:
                Weight = new float[] { 1 };
                break;

            case WeightType.BDEF2:
            case WeightType.SDEF:
                float we = reader.ReadSingle();
                Weight = new float[] { we, 1 - we };
                break;

            case WeightType.BDEF4:
                Weight = new float[4];
                for (byte i = 0; i < 4; i++)
                {
                    Weight[i] = reader.ReadSingle();
                }
                break;
            }

            if (WeightType == WeightType.SDEF)
            {
                Sdef_c  = reader.ReadVector3();
                Sdef_r0 = reader.ReadVector3();
                Sdef_r1 = reader.ReadVector3();
            }
            Edge = reader.ReadSingle();
        }
예제 #11
0
        public void Read(BinaryReader reader, PmxHeaderData header)
        {
            MorphName  = reader.ReadText(header.Encoding);
            MorphNameE = reader.ReadText(header.Encoding);

            SlotType = (MorphSlotType)reader.ReadByte();

            MorphType = (MorphType)reader.ReadByte();

            int elementCount = reader.ReadInt32();

            MorphArray = new IPmxMorphTypeData[elementCount];

            Func <IPmxMorphTypeData> factory = () => null;

            switch (MorphType)
            {
            case MorphType.GROUP:
                factory = () => new PmxMorphGroupData();
                break;

            case MorphType.VERTEX:
                factory = () => new PmxMorphVertexData();
                break;

            case MorphType.BONE:
                factory = () => new PmxMorphBoneData();
                break;

            case MorphType.UV:
            case MorphType.EXUV1:
            case MorphType.EXUV2:
            case MorphType.EXUV3:
            case MorphType.EXUV4:
                factory = () => new PmxMorphUVData();
                break;

            case MorphType.MATERIAL:
                factory = () => new PmxMorphMaterialData();
                break;

            case MorphType.IMPULSE:
                factory = () => new PmxMorphImpulseData();
                break;

            default:
                return;
            }

            for (int i = 0; i < MorphArray.Length; i++)
            {
                MorphArray[i] = factory();
                MorphArray[i].Read(reader, header);
            }
        }
예제 #12
0
 private void ReadPmxData <T>(T data, BinaryReader reader, PmxHeaderData header, bool pmd = false) where T : IPmxData
 {
     if (pmd)
     {
         data.ReadPmd(reader, header);
     }
     else
     {
         data.Read(reader, header);
     }
 }
예제 #13
0
        public void Read(BinaryReader reader, PmxHeaderData header)
        {
            ChildId = reader.ReadPmxId(header.BoneIndexSize);

            int limit = reader.ReadByte();

            if (limit > 0)
            {
                AngleMin = reader.ReadVector3();
                AngleMax = reader.ReadVector3();
            }
        }
예제 #14
0
        public void ReadPmd(BinaryReader reader, PmxHeaderData header)
        {
            BoneName = reader.ReadText(header.Encoding, PMD_BONENAME_LEN);

            ParentId = reader.ReadUInt16();
            ArrowId  = reader.ReadUInt16();

            byte type = reader.ReadByte();

            int ikId = reader.ReadUInt16();

            Pos = reader.ReadVector3();
        }
예제 #15
0
 public PmxModelData()
 {
     Header        = new PmxHeaderData();
     VertexArray   = new PmxVertexData[] { };
     MaterialArray = new PmxMaterialData[] { };
     BoneArray     = new PmxBoneData[] { };
     MorphArray    = new PmxMorphData[] { };
     SlotArray     = new PmxSlotData[] { };
     RigidArray    = new PmxRigidData[] { };
     JointArray    = new PmxJointData[] { };
     VertexIndices = new int[] { };
     TextureFiles  = new string[] { };
 }
예제 #16
0
        private T[] ReadPmxData <T>(BinaryReader reader, PmxHeaderData header) where T : IPmxData, new()
        {
            int len = reader.ReadInt32();

            T[] array = new T[len];

            for (int i = 0; i < len; i++)
            {
                array[i] = new T();
                array[i].Read(reader, header);
            }
            return(array);
        }
예제 #17
0
        public void Write(BinaryWriter writer, PmxHeaderData header)
        {
            writer.WritePmxId(header.BoneIndexSize, ChildId);

            int limit = AngleMin == Vector3.Zero && AngleMax == Vector3.Zero ? 0 : 1;

            writer.Write((byte)limit);

            if (limit > 0)
            {
                writer.Write(AngleMin);
                writer.Write(AngleMax);
            }
        }
예제 #18
0
        public void ReadPmd(BinaryReader reader, PmxHeaderData header)
        {
            Pos    = reader.ReadVector3();
            Normal = reader.ReadVector3();
            Uv     = reader.ReadVector2();

            WeightType = WeightType.BDEF2;
            BoneId     = new int[] { reader.ReadUInt16(), reader.ReadUInt16() };
            float we = reader.ReadByte() / 100.0F;

            Weight = new float[] { we, 1 - we };

            Edge = reader.ReadBoolean() ? 0 : 1;
        }
예제 #19
0
        public void Write(BinaryWriter writer, PmxHeaderData header)
        {
            //writer.Write(Pos);
            //writer.Write(Normal);
            //writer.Write(Uv);
            writer.WriteV(Pos);
            writer.WriteV(Normal);
            writer.WriteV(Uv);

            for (int i = 0; i < header.NumberOfExtraUv; i++)
            {
                Vector4 exUV = GetExtraUv(i);
                //writer.Write( exUV );
                writer.WriteV(exUV);
            }

            writer.Write((byte)WeightType);

            for (byte i = 0; i < BoneId.Length; i++)
            {
                writer.WritePmxId(header.BoneIndexSize, BoneId[i]);
            }

            switch (WeightType)
            {
            case WeightType.BDEF1:
                break;

            case WeightType.BDEF2:
            case WeightType.SDEF:
                writer.Write(Weight[0]);
                break;

            case WeightType.BDEF4:
                for (byte i = 0; i < 4; i++)
                {
                    writer.Write(Weight[i]);
                }
                break;
            }

            if (WeightType == WeightType.SDEF)
            {
                writer.WriteV(Sdef_c);
                writer.WriteV(Sdef_r0);
                writer.WriteV(Sdef_r1);
            }
            writer.Write(Edge);
        }
예제 #20
0
        public void Read(BinaryReader reader, PmxHeaderData header)
        {
            Index = reader.ReadPmxId(header.MaterialIndexSize);

            CalcType      = reader.ReadByte();
            Diffuse       = reader.ReadVector4();
            Specular      = reader.ReadVector3();
            Shininess     = reader.ReadSingle();
            Ambient       = reader.ReadVector3();
            Edge          = reader.ReadVector4();
            EdgeThick     = reader.ReadSingle();
            Texture       = reader.ReadVector4();
            SphereTexture = reader.ReadVector4();
            ToonTexture   = reader.ReadVector4();
        }
예제 #21
0
        public void Write(BinaryWriter writer, PmxHeaderData header)
        {
            writer.WritePmxId(header.MaterialIndexSize, Index);

            writer.Write(CalcType);
            writer.Write(Diffuse);
            writer.Write(Specular);
            writer.Write(Shininess);
            writer.Write(Ambient);
            writer.Write(Edge);
            writer.Write(EdgeThick);
            writer.Write(Texture);
            writer.Write(SphereTexture);
            writer.Write(ToonTexture);
        }
예제 #22
0
        public void Write(BinaryWriter writer, PmxHeaderData header)
        {
            writer.WriteText(header.Encoding, MorphName);
            writer.WriteText(header.Encoding, MorphNameE);

            writer.Write((byte)SlotType);

            writer.Write((byte)MorphType);

            writer.Write(MorphArray.Length);

            for (int i = 0; i < MorphArray.Length; i++)
            {
                MorphArray[i].Write(writer, header);
            }
        }
예제 #23
0
        public void Read(BinaryReader reader, PmxHeaderData header)
        {
            RigidName  = reader.ReadText(header.Encoding);
            RigidNameE = reader.ReadText(header.Encoding);
            JointType  = reader.ReadByte( );

            BodyA = reader.ReadPmxId(header.RigidIndexSize);
            BodyB = reader.ReadPmxId(header.RigidIndexSize);

            Position   = reader.ReadVector3( );
            Rot        = reader.ReadVector3( );
            MoveLower  = reader.ReadVector3( );
            MoveUpper  = reader.ReadVector3( );
            RotLower   = reader.ReadVector3( );
            RotUpper   = reader.ReadVector3( );
            SpringMove = reader.ReadVector3( );
            SpringRot  = reader.ReadVector3( );
        }
예제 #24
0
        public void Write(BinaryWriter writer, PmxHeaderData header)
        {
            writer.WriteText(header.Encoding, RigidName);
            writer.WriteText(header.Encoding, RigidNameE);
            writer.Write(JointType);

            writer.WritePmxId(header.RigidIndexSize, BodyA);
            writer.WritePmxId(header.RigidIndexSize, BodyB);

            writer.WriteV(Position);
            writer.WriteV(Rot);
            writer.WriteV(MoveLower);
            writer.WriteV(MoveUpper);
            writer.WriteV(RotLower);
            writer.WriteV(RotUpper);
            writer.WriteV(SpringMove);
            writer.WriteV(SpringRot);
        }
예제 #25
0
        public void Write(BinaryWriter writer, PmxHeaderData header)
        {
            writer.Write(Pos);
            writer.Write(Normal);
            writer.Write(Uv);

            // for (byte i = 0; i < header.; i++)
            // {
            // writer.dumpLeFloat(uvEX.x).dumpLeFloat(uvEX.y).dumpLeFloat(uvEX.z).dumpLeFloat(uvEX.w);
            // }

            writer.Write((byte)WeightType);

            for (byte i = 0; i < BoneId.Length; i++)
            {
                writer.WritePmxId(header.BoneIndexSize, BoneId[i]);
            }

            switch (WeightType)
            {
            case WeightType.BDEF1:
                break;

            case WeightType.BDEF2:
            case WeightType.SDEF:
                writer.Write(Weight[0]);
                break;

            case WeightType.BDEF4:
                for (byte i = 0; i < 4; i++)
                {
                    writer.Write(Weight[i]);
                }
                break;
            }

            if (WeightType == WeightType.SDEF)
            {
                writer.Write(Sdef_c);
                writer.Write(Sdef_r0);
                writer.Write(Sdef_r1);
            }
            writer.Write(Edge);
        }
예제 #26
0
        public void Read(BinaryReader reader, PmxHeaderData header)
        {
            SlotName  = reader.ReadText(header.Encoding);
            SlotNameE = reader.ReadText(header.Encoding);

            NormalSlot = reader.ReadByte() == 0;

            int elementCount = reader.ReadInt32();

            Indices = new int[elementCount];

            for (int i = 0; i < elementCount; i++)
            {
                byte type = reader.ReadByte();
                byte size = type == (byte)SlotType.BONE ? header.BoneIndexSize : header.MorphIndexSize;

                Indices[i] = reader.ReadPmxId(size);
            }
        }
예제 #27
0
        private T[] ReadPmxData <T>(BinaryReader reader, PmxHeaderData header, int len, bool pmd = false) where T : IPmxData, new()
        {
            T[] array = new T[len];

            for (int i = 0; i < len; i++)
            {
                array[i] = new T();

                if (pmd)
                {
                    array[i].ReadPmd(reader, header);
                }
                else
                {
                    array[i].Read(reader, header);
                }
            }
            return(array);
        }
예제 #28
0
        public void Read(BinaryReader reader, PmxHeaderData header)
        {
            JointName  = reader.ReadText(header.Encoding);
            JointNameE = reader.ReadText(header.Encoding);

            JointType = (JointType)reader.ReadByte();

            RigidBodyA = reader.ReadPmxId(header.RigidIndexSize);
            RigidBodyB = reader.ReadPmxId(header.RigidIndexSize);

            Pos               = reader.ReadVector3();
            Rot               = reader.ReadVector3();
            PosMin            = reader.ReadVector3();
            PosMax            = reader.ReadVector3();
            RotMin            = reader.ReadVector3();
            RotMax            = reader.ReadVector3();
            SpringConstantPos = reader.ReadVector3();
            SpringConstantRot = reader.ReadVector3();
        }
예제 #29
0
        public void Write(BinaryWriter writer, PmxHeaderData header)
        {
            writer.WriteText(header.Encoding, JointName);
            writer.WriteText(header.Encoding, JointNameE);

            writer.Write((byte)JointType);

            writer.WritePmxId(header.RigidIndexSize, RigidBodyA);
            writer.WritePmxId(header.RigidIndexSize, RigidBodyB);

            writer.Write(Pos);
            writer.Write(Rot);
            writer.Write(PosMin);
            writer.Write(PosMax);
            writer.Write(RotMin);
            writer.Write(RotMax);
            writer.Write(SpringConstantPos);
            writer.Write(SpringConstantRot);
        }
예제 #30
0
        public void Write(BinaryWriter writer, PmxHeaderData header)
        {
            writer.Write(MAGIC_BYTES);
            writer.Write(Version);

            writer.Write((byte)8);//length of byte array
            writer.Write((byte)(Encoding == Encoding.UTF8 ? 1 : 0));
            writer.Write(NumberOfExtraUv);
            writer.Write(VertexIndexSize);
            writer.Write(TextureIndexSize);
            writer.Write(MaterialIndexSize);
            writer.Write(BoneIndexSize);
            writer.Write(MorphIndexSize);
            writer.Write(RigidIndexSize);

            writer.WriteText(Encoding, ModelName);
            writer.WriteText(Encoding, ModelNameE);

            writer.WriteText(Encoding, Description.Replace(LF, CRLF));
            writer.WriteText(Encoding, DescriptionE.Replace(LF, CRLF));
        }