Beispiel #1
0
        public static PmxMaterial Parse(BinaryReader br, PmxDocument doc)
        {
            var rt = new PmxMaterial
            {
                Name                 = doc.Header.Encoding.GetString(br.ReadSizedBuffer()),
                EnglishName          = doc.Header.Encoding.GetString(br.ReadSizedBuffer()),
                Diffuse              = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
                Specular             = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
                Power                = br.ReadSingle(),
                Ambient              = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
                Options              = (PmxMaterialOptions)br.ReadByte(),
                EdgeColor            = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
                EdgeSize             = br.ReadSingle(),
                MainTexture          = doc.ReadIndex(br, PmxIndexKind.Texture),
                SubTexture           = doc.ReadIndex(br, PmxIndexKind.Texture),
                SubTextureMode       = (PmxTextureMode)br.ReadByte(),
                UseSharedToonTexture = br.ReadBoolean(),
            };

            rt.ToonTexture = rt.UseSharedToonTexture ? br.ReadByte() : doc.ReadIndex(br, PmxIndexKind.Texture);
            rt.Comment     = doc.Header.Encoding.GetString(br.ReadSizedBuffer());
            rt.IndexCount  = br.ReadInt32();

            return(rt);
        }
Beispiel #2
0
        public void Write(BinaryWriter bw, PmxDocument doc)
        {
            bw.WriteSizedBuffer(doc.Header.Encoding.GetBytes(this.Name));
            bw.WriteSizedBuffer(doc.Header.Encoding.GetBytes(this.EnglishName));
            this.Diffuse.ForEach(bw.Write);
            this.Specular.ForEach(bw.Write);
            bw.Write(this.Power);
            this.Ambient.ForEach(bw.Write);
            bw.Write((byte)this.Options);
            this.EdgeColor.ForEach(bw.Write);
            bw.Write(this.EdgeSize);
            doc.WriteIndex(bw, PmxIndexKind.Texture, this.MainTexture);
            doc.WriteIndex(bw, PmxIndexKind.Texture, this.SubTexture);
            bw.Write((byte)this.SubTextureMode);
            bw.Write(this.UseSharedToonTexture);

            if (this.UseSharedToonTexture)
            {
                bw.Write((byte)this.ToonTexture);
            }
            else
            {
                doc.WriteIndex(bw, PmxIndexKind.Texture, this.ToonTexture);
            }

            bw.WriteSizedBuffer(doc.Header.Encoding.GetBytes(this.Comment));
            bw.Write(this.IndexCount);
        }
Beispiel #3
0
        public static PmxConstraint Parse(BinaryReader br, PmxDocument doc)
        {
            var rt = new PmxSpringSixDegreesOfFreedomConstraint
            {
                Name        = doc.ReadString(br),
                EnglishName = doc.ReadString(br),
            };
            var kind = (PmxConstraintKind)br.ReadByte();

            rt.Read(br, doc);

            switch (kind)
            {
            case PmxConstraintKind.SpringSixDegreesOfFreedom:
                return(rt);

            case PmxConstraintKind.SixDegreesOfFreedom:
                return((PmxSixDegreesOfFreedomConstraint)rt);

            case PmxConstraintKind.PointToPoint:
                return((PmxPointToPointConstraint)rt);

            case PmxConstraintKind.ConeTwist:
                return((PmxConeTwistConstraint)rt);

            case PmxConstraintKind.Slider:
                return((PmxSliderConstraint)rt);

            case PmxConstraintKind.Hinge:
                return((PmxHingeConstraint)rt);

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #4
0
 public override void Write(BinaryWriter bw, PmxDocument doc)
 {
     doc.WriteIndex(bw, PmxIndexKind.Rigid, this.Rigid);
     bw.Write(this.IsLocal);
     this.CentralImpulse.ForEach(bw.Write);
     this.TorqueImpulse.ForEach(bw.Write);
 }
 public void Write(BinaryWriter bw, PmxDocument doc)
 {
     doc.WriteString(bw, this.ModelName);
     doc.WriteString(bw, this.EnglishModelName);
     doc.WriteString(bw, this.Description);
     doc.WriteString(bw, this.EnglishDescription);
 }
Beispiel #6
0
 public override void Read(BinaryReader br, PmxDocument doc)
 {
     this.Rigid          = doc.ReadIndex(br, PmxIndexKind.Rigid);
     this.IsLocal        = br.ReadBoolean();
     this.CentralImpulse = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.TorqueImpulse  = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
 }
 public void Write(BinaryWriter bw, PmxDocument doc)
 {
     doc.WriteString(bw, this.ModelName);
     doc.WriteString(bw, this.EnglishModelName);
     doc.WriteString(bw, this.Description);
     doc.WriteString(bw, this.EnglishDescription);
 }
Beispiel #8
0
 public static PmxTexture Parse(BinaryReader br, PmxDocument doc)
 {
     return new PmxTexture
     {
         FileName = doc.ReadString(br),
     };
 }
Beispiel #9
0
 public void Write(BinaryWriter bw, PmxDocument doc)
 {
     doc.WriteIndex(bw, PmxIndexKind.Bone, this.TargetBone);
     bw.Write(this.LoopCount);
     bw.Write(this.AngleLimitUnit);
     bw.Write(this.BindedBones.Count);
     this.BindedBones.ForEach(_ => _.Write(bw, doc));
 }
Beispiel #10
0
 public override void Write(BinaryWriter bw, PmxDocument doc)
 {
     this.Bones.ForEach(_ => doc.WriteIndex(bw, PmxIndexKind.Bone, _));
     bw.Write(this.Weight);
     this.Center.ForEach(bw.Write);
     this.RangeZero.ForEach(bw.Write);
     this.RangeOne.ForEach(bw.Write);
 }
Beispiel #11
0
 public override void Read(BinaryReader br, PmxDocument doc)
 {
     this.Bones     = new[] { doc.ReadIndex(br, PmxIndexKind.Bone), doc.ReadIndex(br, PmxIndexKind.Bone) };
     this.Weight    = br.ReadSingle();
     this.Center    = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.RangeZero = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.RangeOne  = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
 }
Beispiel #12
0
 public void Write(BinaryWriter bw, PmxDocument doc, PmxIndexCache cache)
 {
     cache.Write(this.TargetBone);
     bw.Write(this.LoopCount);
     bw.Write(this.AngleLimitUnit);
     bw.Write(this.BindedBones.Count);
     this.BindedBones.ForEach(_ => _.Write(bw, doc, cache));
 }
Beispiel #13
0
 public void Write(BinaryWriter bw, PmxDocument doc, PmxIndexCache cache)
 {
     doc.WriteString(bw, this.Name);
     doc.WriteString(bw, this.EnglishName);
     bw.Write(this.IsSpecial);
     bw.Write(this.Items.Count);
     this.Items.ForEach(_ => _.Write(bw, doc, cache));
 }
Beispiel #14
0
 public void Parse(BinaryReader br, PmxDocument doc)
 {
     this.Name = doc.ReadString(br);
     this.EnglishName = doc.ReadString(br);
     this.Category = (PmxMorphCategory)br.ReadByte();
     this.Kind = (PmxMorphKind)br.ReadByte();
     this.Offsets = Enumerable.Range(0, br.ReadInt32()).Select(_ => PmxMorphOffset.Parse(br, doc, this.Kind)).ToList();
 }
Beispiel #15
0
 public void Write(BinaryWriter bw, PmxDocument doc)
 {
     doc.WriteIndex(bw, PmxIndexKind.Bone, this.TargetBone);
     bw.Write(this.LoopCount);
     bw.Write(this.AngleLimitUnit);
     bw.Write(this.BindedBones.Count);
     this.BindedBones.ForEach(_ => _.Write(bw, doc));
 }
Beispiel #16
0
 public void Write(BinaryWriter bw, PmxDocument doc)
 {
     doc.WriteString(bw, this.Name);
     doc.WriteString(bw, this.EnglishName);
     bw.Write(this.IsSpecial);
     bw.Write(this.Items.Count);
     this.Items.ForEach(_ => _.Write(bw, doc));
 }
Beispiel #17
0
 public static PmxDisplayList Parse(BinaryReader br, PmxDocument doc)
 {
     return(new PmxDisplayList
     {
         Name = doc.ReadString(br),
         EnglishName = doc.ReadString(br),
         IsSpecial = br.ReadBoolean(),
         Items = Enumerable.Range(0, br.ReadInt32()).Select(_ => PmxDisplayItem.Parse(br, doc)).ToList(),
     });
 }
Beispiel #18
0
 public static PmxModelInformation Parse(BinaryReader br, PmxDocument doc)
 {
     return(new PmxModelInformation
     {
         ModelName = doc.ReadString(br),
         EnglishModelName = doc.ReadString(br),
         Description = doc.ReadString(br),
         EnglishDescription = doc.ReadString(br),
     });
 }
Beispiel #19
0
 public static PmxModelInformation Parse(BinaryReader br, PmxDocument doc)
 {
     return new PmxModelInformation
     {
         ModelName = doc.ReadString(br),
         EnglishModelName = doc.ReadString(br),
         Description = doc.ReadString(br),
         EnglishDescription = doc.ReadString(br),
     };
 }
Beispiel #20
0
 public static PmxIK Parse(BinaryReader br, PmxDocument doc)
 {
     return new PmxIK
     {
         TargetBone = doc.ReadBone(br),
         LoopCount = br.ReadInt32(),
         AngleLimitUnit = br.ReadSingle(),
         BindedBones = Enumerable.Range(0, br.ReadInt32()).Select(_ => PmxIKBinding.Parse(br, doc)).ToList(),
     };
 }
Beispiel #21
0
 public static PmxDisplayList Parse(BinaryReader br, PmxDocument doc)
 {
     return new PmxDisplayList
     {
         Name = doc.ReadString(br),
         EnglishName = doc.ReadString(br),
         IsSpecial = br.ReadBoolean(),
         Items = Enumerable.Range(0, br.ReadInt32()).Select(_ => PmxDisplayItem.Parse(br, doc)).ToList(),
     };
 }
Beispiel #22
0
 public static PmxIK Parse(BinaryReader br, PmxDocument doc)
 {
     return(new PmxIK
     {
         TargetBone = doc.ReadIndex(br, PmxIndexKind.Bone),
         LoopCount = br.ReadInt32(),
         AngleLimitUnit = br.ReadSingle(),
         BindedBones = Enumerable.Range(0, br.ReadInt32()).Select(_ => PmxIKBinding.Parse(br, doc)).ToList(),
     });
 }
Beispiel #23
0
        public void Write(BinaryWriter bw, PmxDocument doc)
        {
            doc.WriteIndex(bw, PmxIndexKind.Bone, this.Bone);
            bw.Write(this.IsAngleLimitEnabled);

            if (this.IsAngleLimitEnabled)
            {
                this.LowerAngleLimit.ForEach(bw.Write);
                this.HigherAngleLimit.ForEach(bw.Write);
            }
        }
Beispiel #24
0
        public static PmxDisplayItem Parse(BinaryReader br, PmxDocument doc)
        {
            var rt = new PmxDisplayItem
            {
                Kind = (PmxDisplayItemKind)br.ReadByte(),
            };

            rt.Index = rt.Kind == PmxDisplayItemKind.Bone ? doc.ReadIndex(br, PmxIndexKind.Bone) : doc.ReadIndex(br, PmxIndexKind.Morph);

            return rt;
        }
Beispiel #25
0
 public PmxIndexCache(PmxDocument doc, BinaryWriter bw)
 {
     this.doc = doc;
     this.bw = bw;
     this.Vertices = doc.Vertices.Select((i, j) => Tuple.Create(i, j)).ToDictionary(_ => _.Item1, _ => _.Item2);
     this.Textures = doc.Textures.Select((i, j) => Tuple.Create(i, j)).ToDictionary(_ => _.Item1, _ => _.Item2);
     this.Materials = doc.Materials.Select((i, j) => Tuple.Create(i, j)).ToDictionary(_ => _.Item1, _ => _.Item2);
     this.Bones = doc.Bones.Select((i, j) => Tuple.Create(i, j)).ToDictionary(_ => _.Item1, _ => _.Item2);
     this.Morphs = doc.Morphs.Select((i, j) => Tuple.Create(i, j)).ToDictionary(_ => _.Item1, _ => _.Item2);
     this.Rigids = doc.Rigids.Select((i, j) => Tuple.Create(i, j)).ToDictionary(_ => _.Item1, _ => _.Item2);
 }
Beispiel #26
0
        public void Write(BinaryWriter bw, PmxDocument doc)
        {
            doc.WriteIndex(bw, PmxIndexKind.Bone, this.Bone);
            bw.Write(this.IsAngleLimitEnabled);

            if (this.IsAngleLimitEnabled)
            {
                this.LowerAngleLimit.ForEach(bw.Write);
                this.HigherAngleLimit.ForEach(bw.Write);
            }
        }
Beispiel #27
0
        public static PmxDisplayItem Parse(BinaryReader br, PmxDocument doc)
        {
            var rt = new PmxDisplayItem
            {
                Kind = (PmxDisplayItemKind)br.ReadByte(),
            };

            rt.Index = rt.Kind == PmxDisplayItemKind.Bone ? doc.ReadIndex(br, PmxIndexKind.Bone) : doc.ReadIndex(br, PmxIndexKind.Morph);

            return(rt);
        }
Beispiel #28
0
        public void Write(BinaryWriter bw, PmxDocument doc, PmxIndexCache cache)
        {
            cache.Write(this.Bone);
            bw.Write(this.IsAngleLimitEnabled);

            if (this.IsAngleLimitEnabled)
            {
                this.LowerAngleLimit.ForEach(bw.Write);
                this.HigherAngleLimit.ForEach(bw.Write);
            }
        }
Beispiel #29
0
        public static PmxBone Parse(BinaryReader br, PmxDocument doc)
        {
            var rt = new PmxBone
            {
                Name         = doc.ReadString(br),
                EnglishName  = doc.ReadString(br),
                Position     = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
                ParentBone   = doc.ReadIndex(br, PmxIndexKind.Bone),
                Priority     = br.ReadInt32(),
                Capabilities = (PmxBoneCapabilities)br.ReadUInt16(),
            };

            if (rt.Capabilities.HasFlag(PmxBoneCapabilities.ConnectToBone))
            {
                rt.ConnectToBone = doc.ReadIndex(br, PmxIndexKind.Bone);
            }
            else
            {
                rt.ConnectToOffset = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() }
            };

            if (rt.Capabilities.HasFlag(PmxBoneCapabilities.RotationAffected) ||
                rt.Capabilities.HasFlag(PmxBoneCapabilities.MovementAffected))
            {
                rt.AffectedBone  = doc.ReadIndex(br, PmxIndexKind.Bone);
                rt.AffectionRate = br.ReadSingle();
            }

            if (rt.Capabilities.HasFlag(PmxBoneCapabilities.FixedAxis))
            {
                rt.FixedAxis = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() }
            }
            ;

            if (rt.Capabilities.HasFlag(PmxBoneCapabilities.LocalAxis))
            {
                rt.LocalVectorX = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
                rt.LocalVectorZ = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
            }

            if (rt.Capabilities.HasFlag(PmxBoneCapabilities.TransformByExternalParent))
            {
                rt.ExternalParentKey = br.ReadInt32();
            }

            if (rt.Capabilities.HasFlag(PmxBoneCapabilities.IK))
            {
                rt.IK = PmxIK.Parse(br, doc);
            }

            return(rt);
        }
Beispiel #30
0
 public override void Read(BinaryReader br, PmxDocument doc)
 {
     this.RigidA                 = doc.ReadIndex(br, PmxIndexKind.Rigid);
     this.RigidB                 = doc.ReadIndex(br, PmxIndexKind.Rigid);
     this.Position               = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.Rotation               = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.LinearLowerLimit       = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.LinearUpperLimit       = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.AngularLowerLimit      = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.AngularUpperLimit      = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.LinearSpringStiffness  = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.AngularSpringStiffness = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
 }
Beispiel #31
0
 public override void Write(BinaryWriter bw, PmxDocument doc)
 {
     base.Write(bw, doc);
     doc.WriteIndex(bw, PmxIndexKind.Rigid, this.RigidA);
     doc.WriteIndex(bw, PmxIndexKind.Rigid, this.RigidB);
     this.Position.ForEach(bw.Write);
     this.Rotation.ForEach(bw.Write);
     this.LinearLowerLimit.ForEach(bw.Write);
     this.LinearUpperLimit.ForEach(bw.Write);
     this.AngularLowerLimit.ForEach(bw.Write);
     this.AngularUpperLimit.ForEach(bw.Write);
     this.LinearSpringStiffness.ForEach(bw.Write);
     this.AngularSpringStiffness.ForEach(bw.Write);
 }
Beispiel #32
0
 public override void Write(BinaryWriter bw, PmxDocument doc)
 {
     doc.WriteIndex(bw, PmxIndexKind.Material, this.Material);
     bw.Write((byte)this.Kind);
     this.Diffuse.ForEach(bw.Write);
     this.Specular.ForEach(bw.Write);
     bw.Write(this.Power);
     this.Ambient.ForEach(bw.Write);
     this.EdgeColor.ForEach(bw.Write);
     bw.Write(this.EdgeSize);
     this.Texture.ForEach(bw.Write);
     this.SubTexture.ForEach(bw.Write);
     this.ToonTexture.ForEach(bw.Write);
 }
Beispiel #33
0
        public static PmxMorph Parse(BinaryReader br, PmxDocument doc)
        {
            var rt = new PmxMorph
            {
                Name        = doc.ReadString(br),
                EnglishName = doc.ReadString(br),
                Category    = (PmxMorphCategory)br.ReadByte(),
                Kind        = (PmxMorphKind)br.ReadByte(),
            };

            rt.Offsets = Enumerable.Range(0, br.ReadInt32()).Select(_ => PmxMorphOffset.Parse(br, doc, rt.Kind)).ToList();

            return(rt);
        }
Beispiel #34
0
 public override void Read(BinaryReader br, PmxDocument doc)
 {
     this.Material    = doc.ReadIndex(br, PmxIndexKind.Material);
     this.Kind        = (PmxMaterialMorphKind)br.ReadByte();
     this.Diffuse     = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.Specular    = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.Power       = br.ReadSingle();
     this.Ambient     = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.EdgeColor   = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.EdgeSize    = br.ReadSingle();
     this.Texture     = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.SubTexture  = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.ToonTexture = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
 }
Beispiel #35
0
        public static PmxMorph Parse(BinaryReader br, PmxDocument doc)
        {
            var rt = new PmxMorph
            {
                Name = doc.ReadString(br),
                EnglishName = doc.ReadString(br),
                Category = (PmxMorphCategory)br.ReadByte(),
                Kind = (PmxMorphKind)br.ReadByte(),
            };

            rt.Offsets = Enumerable.Range(0, br.ReadInt32()).Select(_ => PmxMorphOffset.Parse(br, doc, rt.Kind)).ToList();

            return rt;
        }
Beispiel #36
0
        public void Write(BinaryWriter bw, PmxDocument doc)
        {
            if (doc.Version < 2.1f)
                if (this.Kind == PmxMorphKind.Flip)
                    this.Kind = PmxMorphKind.Group;
                else if (this.Kind == PmxMorphKind.Impulse)
                    return;

            doc.WriteString(bw, this.Name);
            doc.WriteString(bw, this.EnglishName);
            bw.Write((byte)this.Category);
            bw.Write((byte)this.Kind);
            bw.Write(this.Offsets.Count);
            this.Offsets.ForEach(_ => _.Write(bw, doc));
        }
Beispiel #37
0
        public void Write(BinaryWriter bw, PmxDocument doc)
        {
            if (doc.Version < 2.1f &&
                this.SkinningKind == PmxSkinningKind.DualQuaternionDeforming)
            {
                this.SkinningKind = PmxSkinningKind.LinearBlendDeforming4;
            }

            this.Position.ForEach(bw.Write);
            this.Normal.ForEach(bw.Write);
            this.UV.ForEach(bw.Write);
            this.AdditionalUV.ForEach(_ => _.ForEach(bw.Write));
            bw.Write((byte)this.SkinningKind);
            this.SkinningFunction.Write(bw, doc);
            bw.Write(this.EdgeSize);
        }
Beispiel #38
0
        public static PmxIKBinding Parse(BinaryReader br, PmxDocument doc)
        {
            var rt = new PmxIKBinding
            {
                Bone = doc.ReadIndex(br, PmxIndexKind.Bone),
                IsAngleLimitEnabled = br.ReadBoolean(),
            };

            if (rt.IsAngleLimitEnabled)
            {
                rt.LowerAngleLimit  = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
                rt.HigherAngleLimit = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
            }

            return(rt);
        }
Beispiel #39
0
        public static PmxIKBinding Parse(BinaryReader br, PmxDocument doc)
        {
            var rt = new PmxIKBinding
            {
                Bone = doc.ReadIndex(br, PmxIndexKind.Bone),
                IsAngleLimitEnabled = br.ReadBoolean(),
            };

            if (rt.IsAngleLimitEnabled)
            {
                rt.LowerAngleLimit = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
                rt.HigherAngleLimit = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
            }

            return rt;
        }
Beispiel #40
0
        public static PmxVertex Parse(BinaryReader br, PmxDocument doc)
        {
            var rt = new PmxVertex
            {
                Position = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
                Normal = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
                UV = new[] { br.ReadSingle(), br.ReadSingle() },
                AdditionalUV = Enumerable.Range(0, doc.Header.AdditionalUVCount).Select(_ => new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle() }).ToArray(),
                SkinningKind = (PmxSkinningKind)br.ReadByte(),
            };

            rt.SkinningFunction = PmxSkinningFunction.Parse(br, doc, rt.SkinningKind);
            rt.EdgeSize = br.ReadSingle();

            return rt;
        }
Beispiel #41
0
        public static PmxVertex Parse(BinaryReader br, PmxDocument doc)
        {
            var rt = new PmxVertex
            {
                Position     = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
                Normal       = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
                UV           = new[] { br.ReadSingle(), br.ReadSingle() },
                AdditionalUV = Enumerable.Range(0, doc.Header.AdditionalUVCount).Select(_ => new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle() }).ToArray(),
                SkinningKind = (PmxSkinningKind)br.ReadByte(),
            };

            rt.SkinningFunction = PmxSkinningFunction.Parse(br, doc, rt.SkinningKind);
            rt.EdgeSize         = br.ReadSingle();

            return(rt);
        }
Beispiel #42
0
        public void Write(BinaryWriter bw, PmxDocument doc)
        {
            doc.WriteString(bw, this.Name);
            doc.WriteString(bw, this.EnglishName);
            this.Position.ForEach(bw.Write);
            doc.WriteIndex(bw, PmxIndexKind.Bone, this.ParentBone);
            bw.Write(this.Priority);
            bw.Write((ushort)this.Capabilities);

            if (this.Capabilities.HasFlag(PmxBoneCapabilities.ConnectToBone))
            {
                doc.WriteIndex(bw, PmxIndexKind.Bone, this.ConnectToBone);
            }
            else
            {
                this.ConnectToOffset.ForEach(bw.Write);
            }

            if (this.Capabilities.HasFlag(PmxBoneCapabilities.RotationAffected) ||
                this.Capabilities.HasFlag(PmxBoneCapabilities.MovementAffected))
            {
                doc.WriteIndex(bw, PmxIndexKind.Bone, this.AffectedBone);
                bw.Write(this.AffectionRate);
            }

            if (this.Capabilities.HasFlag(PmxBoneCapabilities.FixedAxis))
            {
                this.FixedAxis.ForEach(bw.Write);
            }

            if (this.Capabilities.HasFlag(PmxBoneCapabilities.LocalAxis))
            {
                this.LocalVectorX.ForEach(bw.Write);
                this.LocalVectorZ.ForEach(bw.Write);
            }

            if (this.Capabilities.HasFlag(PmxBoneCapabilities.TransformByExternalParent))
            {
                bw.Write(this.ExternalParentKey);
            }

            if (this.Capabilities.HasFlag(PmxBoneCapabilities.IK))
            {
                this.IK.Write(bw, doc);
            }
        }
Beispiel #43
0
 public static PmxDisplayItem Parse(BinaryReader br, PmxDocument doc)
 {
     switch ((PmxDisplayItemKind)br.ReadByte())
     {
         case PmxDisplayItemKind.Bone:
             return new PmxBoneDisplayItem
             {
                 Bone = doc.ReadBone(br),
             };
         case PmxDisplayItemKind.Morph:
             return new PmxMorphDisplayItem
             {
                 Morph = doc.ReadMorph(br),
             };
         default:
             throw new InvalidOperationException();
     }
 }
Beispiel #44
0
 public void Write(BinaryWriter bw, PmxDocument doc)
 {
     doc.WriteString(bw, this.Name);
     doc.WriteString(bw, this.EnglishName);
     doc.WriteIndex(bw, PmxIndexKind.Bone, this.RelatedBone);
     bw.Write(this.Group);
     bw.Write((ushort)this.CollidableGroups);
     bw.Write((byte)this.Shape);
     this.Size.ForEach(bw.Write);
     this.Position.ForEach(bw.Write);
     this.Rotation.ForEach(bw.Write);
     bw.Write(this.Mass);
     bw.Write(this.LinearDamping);
     bw.Write(this.AngularDamping);
     bw.Write(this.Restitution);
     bw.Write(this.Friction);
     bw.Write((byte)this.Kind);
 }
Beispiel #45
0
 public static PmxRigidBody Parse(BinaryReader br, PmxDocument doc)
 {
     return(new PmxRigidBody
     {
         Name = doc.ReadString(br),
         EnglishName = doc.ReadString(br),
         RelatedBone = doc.ReadIndex(br, PmxIndexKind.Bone),
         Group = br.ReadByte(),
         CollidableGroups = (PmdRigidGroups)br.ReadUInt16(),
         Shape = (PmdRigidShape)br.ReadByte(),
         Size = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
         Position = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
         Rotation = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
         Mass = br.ReadSingle(),
         LinearDamping = br.ReadSingle(),
         AngularDamping = br.ReadSingle(),
         Restitution = br.ReadSingle(),
         Friction = br.ReadSingle(),
         Kind = (PmxRigidKind)br.ReadByte(),
     });
 }
Beispiel #46
0
        public void Write(BinaryWriter bw, PmxDocument doc)
        {
            if (doc.Version < 2.1f)
            {
                if (this.Kind == PmxMorphKind.Flip)
                {
                    this.Kind = PmxMorphKind.Group;
                }
                else if (this.Kind == PmxMorphKind.Impulse)
                {
                    return;
                }
            }

            doc.WriteString(bw, this.Name);
            doc.WriteString(bw, this.EnglishName);
            bw.Write((byte)this.Category);
            bw.Write((byte)this.Kind);
            bw.Write(this.Offsets.Count);
            this.Offsets.ForEach(_ => _.Write(bw, doc));
        }
Beispiel #47
0
        public static PmxDocument Parse(Stream stream)
        {
            // leave open
            var br     = new BinaryReader(stream);
            var header = Encoding.ASCII.GetString(br.ReadBytes(4));
            var rt     = new PmxDocument();

            if (header != "PMX ")
            {
                throw new InvalidOperationException("invalid format");
            }

            rt.Version = br.ReadSingle();

            if (rt.Version != 2 &&
                rt.Version != 2.1f)
            {
                throw new NotSupportedException("specified format version not supported");
            }

            rt.Header           = PmxHeader.Parse(br);
            rt.ModelInformation = PmxModelInformation.Parse(br, rt);
            rt.Vertices         = Enumerable.Range(0, br.ReadInt32()).Select(_ => PmxVertex.Parse(br, rt)).ToList();
            rt.Indices          = Enumerable.Range(0, br.ReadInt32()).Select(_ => rt.ReadIndex(br, PmxIndexKind.Vertex)).ToList();
            rt.Textures         = Enumerable.Range(0, br.ReadInt32()).Select(_ => rt.ReadString(br)).ToList();
            rt.Materials        = Enumerable.Range(0, br.ReadInt32()).Select(_ => PmxMaterial.Parse(br, rt)).ToList();
            rt.Bones            = Enumerable.Range(0, br.ReadInt32()).Select(_ => PmxBone.Parse(br, rt)).ToList();
            rt.Morphs           = Enumerable.Range(0, br.ReadInt32()).Select(_ => PmxMorph.Parse(br, rt)).ToList();
            rt.DisplayList      = Enumerable.Range(0, br.ReadInt32()).Select(_ => PmxDisplayList.Parse(br, rt)).ToList();
            rt.Rigids           = Enumerable.Range(0, br.ReadInt32()).Select(_ => PmxRigidBody.Parse(br, rt)).ToList();
            rt.Constraints      = Enumerable.Range(0, br.ReadInt32()).Select(_ => PmxConstraint.Parse(br, rt)).ToList();

            if (rt.Version > 2)
            {
                rt.SoftBodies = Enumerable.Range(0, br.ReadInt32()).Select(_ => PmxSoftBody.Parse(br, rt)).ToList();
            }

            return(rt);
        }
Beispiel #48
0
        public static PmxSkinningFunction Parse(BinaryReader br, PmxDocument doc, PmxSkinningKind kind)
        {
            PmxSkinningFunction rt;

            switch (kind)
            {
            case PmxSkinningKind.LinearBlendDeforming1:
                rt = new PmxLinearBlendDeforming1();

                break;

            case PmxSkinningKind.LinearBlendDeforming2:
                rt = new PmxLinearBlendDeforming2();

                break;

            case PmxSkinningKind.LinearBlendDeforming4:
                rt = new PmxLinearBlendDeforming4();

                break;

            case PmxSkinningKind.SphericalDeforming:
                rt = new PmxSphericalDeforming();

                break;

            case PmxSkinningKind.DualQuaternionDeforming:
                rt = new PmxDualQuaternionDeforming();

                break;

            default:
                throw new NotSupportedException();
            }

            rt.Read(br, doc);

            return(rt);
        }
Beispiel #49
0
 public void Write(BinaryWriter bw, PmxDocument doc)
 {
     bw.Write((byte)this.Kind);
     doc.WriteIndex(bw, this.Kind == PmxDisplayItemKind.Bone ? PmxIndexKind.Bone : PmxIndexKind.Morph, this.Index);
 }
Beispiel #50
0
        public void Write(BinaryWriter bw, PmxDocument doc)
        {
            bw.WriteSizedBuffer(doc.Header.Encoding.GetBytes(this.Name));
            bw.WriteSizedBuffer(doc.Header.Encoding.GetBytes(this.EnglishName));
            this.Diffuse.ForEach(bw.Write);
            this.Specular.ForEach(bw.Write);
            bw.Write(this.Power);
            this.Ambient.ForEach(bw.Write);
            bw.Write((byte)this.Options);
            this.EdgeColor.ForEach(bw.Write);
            bw.Write(this.EdgeSize);
            doc.WriteIndex(bw, PmxIndexKind.Texture, this.MainTexture);
            doc.WriteIndex(bw, PmxIndexKind.Texture, this.SubTexture);
            bw.Write((byte)this.SubTextureMode);
            bw.Write(this.UseSharedToonTexture);

            if (this.UseSharedToonTexture)
                bw.Write((byte)this.ToonTexture);
            else
                doc.WriteIndex(bw, PmxIndexKind.Texture, this.ToonTexture);

            bw.WriteSizedBuffer(doc.Header.Encoding.GetBytes(this.Comment));
            bw.Write(this.IndexCount);
        }
Beispiel #51
0
        public static PmxMaterial Parse(BinaryReader br, PmxDocument doc)
        {
            var rt = new PmxMaterial
            {
                Name = doc.Header.Encoding.GetString(br.ReadSizedBuffer()),
                EnglishName = doc.Header.Encoding.GetString(br.ReadSizedBuffer()),
                Diffuse = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
                Specular = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
                Power = br.ReadSingle(),
                Ambient = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
                Options = (PmxMaterialOptions)br.ReadByte(),
                EdgeColor = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle() },
                EdgeSize = br.ReadSingle(),
                MainTexture = doc.ReadIndex(br, PmxIndexKind.Texture),
                SubTexture = doc.ReadIndex(br, PmxIndexKind.Texture),
                SubTextureMode = (PmxTextureMode)br.ReadByte(),
                UseSharedToonTexture = br.ReadBoolean(),
            };

            rt.ToonTexture = rt.UseSharedToonTexture ? br.ReadByte() : doc.ReadIndex(br, PmxIndexKind.Texture);
            rt.Comment = doc.Header.Encoding.GetString(br.ReadSizedBuffer());
            rt.IndexCount = br.ReadInt32();

            return rt;
        }
Beispiel #52
0
 public override void Read(BinaryReader br, PmxDocument doc)
 {
     this.Bone = doc.ReadBone(br);
     this.MovementOffset = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
     this.RotationOffset = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
 }
Beispiel #53
0
 public abstract void Read(BinaryReader br, PmxDocument doc);
Beispiel #54
0
 public override void Write(BinaryWriter bw, PmxDocument doc, PmxIndexCache cache)
 {
     cache.Write(this.Material);
     bw.Write((byte)this.Kind);
     this.Diffuse.ForEach(bw.Write);
     this.Specular.ForEach(bw.Write);
     bw.Write(this.Power);
     this.Ambient.ForEach(bw.Write);
     this.EdgeColor.ForEach(bw.Write);
     bw.Write(this.EdgeSize);
     this.Texture.ForEach(bw.Write);
     this.SubTexture.ForEach(bw.Write);
     this.ToonTexture.ForEach(bw.Write);
 }
Beispiel #55
0
 public override void Read(BinaryReader br, PmxDocument doc)
 {
     this.Morph = doc.ReadMorph(br);
     this.Weight = br.ReadSingle();
 }
Beispiel #56
0
 public override void Write(BinaryWriter bw, PmxDocument doc, PmxIndexCache cache)
 {
     cache.Write(this.Bone);
     this.MovementOffset.ForEach(bw.Write);
     this.RotationOffset.ForEach(bw.Write);
 }
Beispiel #57
0
 public override void Write(BinaryWriter bw, PmxDocument doc, PmxIndexCache cache)
 {
     cache.Write(this.Vertex);
     this.Offset.ForEach(bw.Write);
 }
Beispiel #58
0
 public override void Read(BinaryReader br, PmxDocument doc)
 {
     this.Vertex = doc.ReadVertex(br);
     this.Offset = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
 }
Beispiel #59
0
        public static PmxMorphOffset Parse(BinaryReader br, PmxDocument doc, PmxMorphKind kind)
        {
            PmxMorphOffset rt;

            switch (kind)
            {
                case PmxMorphKind.Group:
                    rt = new PmxGroupMorphOffset();

                    break;
                case PmxMorphKind.Vertex:
                    rt = new PmxVertexMorphOffset();

                    break;
                case PmxMorphKind.Bone:
                    rt = new PmxBoneMorphOffset();

                    break;
                case PmxMorphKind.UV:
                    rt = new PmxUVMorphOffset();

                    break;
                case PmxMorphKind.AdditionalUV1:
                    rt = new PmxUVMorphOffset();

                    break;
                case PmxMorphKind.AdditionalUV2:
                    rt = new PmxUVMorphOffset();

                    break;
                case PmxMorphKind.AdditionalUV3:
                    rt = new PmxUVMorphOffset();

                    break;
                case PmxMorphKind.AdditionalUV4:
                    rt = new PmxUVMorphOffset();

                    break;
                case PmxMorphKind.Material:
                    rt = new PmxMaterialMorphOffset();

                    break;
                case PmxMorphKind.Flip:
                    rt = new PmxFlipMorphOffset();

                    break;
                case PmxMorphKind.Impulse:
                    rt = new PmxImpulseMorphOffset();

                    break;
                default:
                    throw new ArgumentException();
            }

            rt.Read(br, doc);

            return rt;
        }
Beispiel #60
0
 public abstract void Write(BinaryWriter bw, PmxDocument doc, PmxIndexCache cache);