Example #1
0
 public void Write(BinaryWriter bw, PmdIndexCache cache)
 {
     bw.Write((short)(this.IKBone == null ? -1 : cache.Bones[this.IKBone]));
     bw.Write((short)(this.TargetBone == null ? -1 : cache.Bones[this.TargetBone]));
     bw.Write((byte)this.BindedBones.Count);
     bw.Write(this.LoopCount);
     bw.Write(this.AngleLimitUnit);
     this.BindedBones.Select(_ => (short)(_ == null ? -1 : cache.Bones[_])).ForEach(bw.Write);
 }
Example #2
0
 public void Write(BinaryWriter bw, PmdIndexCache cache)
 {
     this.Position.ForEach(_ => bw.Write(_));
     this.Normal.ForEach(_ => bw.Write(_));
     this.UV.ForEach(_ => bw.Write(_));
     this.RelatedBones.Select(_ => _ == null ? -1 : cache.Bones[_]).ForEach(_ => bw.Write((short)_));
     bw.Write((byte)(this.BoneWeight * 100));
     bw.Write(this.NoEdge);
 }
Example #3
0
        public void Write(BinaryWriter bw, PmdIndexCache cache, Dictionary<PmdVertex, int> morphBaseIndices)
        {
            PmdDocument.WritePmdString(bw, this.Name, 20);
            bw.Write((uint)this.Offsets.Count);
            bw.Write((byte)this.Kind);
            this.Indices.Zip(this.Offsets, Tuple.Create).ForEach(_ =>
            {
                if (this.Kind == PmdMorphKind.None)
                    bw.Write((uint)cache.Vertices[_.Item1]);
                else
                    bw.Write((uint)morphBaseIndices[_.Item1]);

                _.Item2.ForEach(bw.Write);
            });
        }
Example #4
0
 public void Write(BinaryWriter bw, PmdIndexCache cache)
 {
     PmdDocument.WritePmdString(bw, this.Name, 20);
     bw.Write((short)(this.ParentBone == null ? -1 : cache.Bones[this.ParentBone]));
     bw.Write((short)(this.ConnectedToOrAssociatedBone == null ? -1 : cache.Bones[this.ConnectedToOrAssociatedBone]));
     bw.Write((byte)this.Kind);
     bw.Write((short)(this.Kind == PmdBoneKind.RotationAssociated ? this.AssosiationRate * 100 : this.IKParentOrAffectedBone == null ? -1 : cache.Bones[this.IKParentOrAffectedBone]));
     this.Position.ForEach(bw.Write);
 }
Example #5
0
        public void Write(Stream stream)
        {
            // leave open
            var bw = new BinaryWriter(stream);
            var cache = new PmdIndexCache(this);

            bw.Write(Encoding.GetBytes("Pmd"));
            bw.Write(this.Version);
            WritePmdString(bw, this.ModelName, 20);
            WritePmdString(bw, this.Description, 256);

            bw.Write((uint)this.Vertices.Count);
            this.Vertices.ForEach(_ => _.Write(bw, cache));

            bw.Write((uint)this.Indices.Count);
            this.Indices.Select(_ => (ushort)cache.Vertices[_]).ForEach(bw.Write);

            bw.Write((uint)this.Materials.Count);
            this.Materials.ForEach(_ => _.Write(bw));

            bw.Write((ushort)this.Bones.Count);
            this.Bones.ForEach(_ => _.Write(bw, cache));

            bw.Write((ushort)this.IK.Count);
            this.IK.ForEach(_ => _.Write(bw, cache));

            bw.Write((ushort)(this.Morphs.Count + 1));

            var morphBase = PmdMorph.CreateMorphBase(this.Morphs);
            var morphBaseIndices = morphBase.Indices.Select((_, idx) => Tuple.Create(_, idx)).ToDictionary(_ => _.Item1, _ => _.Item2);

            morphBase.Write(bw, cache, morphBaseIndices);
            this.Morphs.ForEach(_ => _.Write(bw, cache, morphBaseIndices));

            bw.Write((byte)this.MorphDisplayList.Count);
            this.MorphDisplayList.Select(_ => this.Morphs.IndexOf(_) + 1).ForEach(_ => bw.Write((short)_));

            bw.Write((byte)this.BoneDisplayList.Count);
            this.BoneDisplayList.ForEach(_ => _.Write(bw));

            bw.Write((uint)this.BoneDisplayList.Sum(_ => _.Bones.Count));
            this.BoneDisplayList.SelectMany((_, idx) => _.Bones.Select(b => Tuple.Create(b, idx + 1))).ForEach(_ =>
            {
                bw.Write((short)this.Bones.IndexOf(_.Item1));
                bw.Write((byte)_.Item2);
            });

            bw.Write(this.EnglishCompatible);

            if (this.EnglishCompatible)
            {
                WritePmdString(bw, this.EnglishModelName, 20);
                WritePmdString(bw, this.EnglishDescription, 256);
                this.Bones.Select(_ => _.EnglishName).ForEach(_ => WritePmdString(bw, _, 20));
                this.Morphs.Select(_ => _.EnglishName).ForEach(_ => WritePmdString(bw, _, 20));
                this.BoneDisplayList.Select(_ => _.EnglishName).ForEach(_ => WritePmdString(bw, _, 50));
            }

            Enumerable.Range(0, 10).Select(_ => _ < this.ToonFileNames.Count ? this.ToonFileNames[_] : null).ForEach(_ => WritePmdString(bw, _, 100));

            bw.Write((uint)this.Rigids.Count);
            this.Rigids.ForEach(_ => _.Write(bw));

            bw.Write((uint)this.Constraints.Count);
            this.Constraints.ForEach(_ => _.Write(bw));
        }