Esempio n. 1
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;
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
 public override void Read(BinaryReader br, PmxDocument doc)
 {
     this.Vertex = doc.ReadVertex(br);
     this.Offset = new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() };
 }
Esempio n. 5
0
 public void Write(PmxVertex vertex)
 {
     doc.WriteIndex(bw, PmxIndexKind.Vertex, vertex == null ? -1 : this.Vertices[vertex]);
 }