Exemple #1
0
        private static PlyResult ParseBinaryLittleEndian(byte[] content, PlyHeader header)
        {
            PlyResult plyResult = new PlyResult();

            plyResult.meshName  = header.GlobalMeshInfoElement.GetName();
            plyResult.meshColor = header.GloablMaterialElement.GetColor();

            var headerAsText  = header.RawHeader.Aggregate((a, b) => $"{a}\n{b}") + "\n";
            var headerAsBytes = Encoding.ASCII.GetBytes(headerAsText);
            var withoutHeader = content.Skip(headerAsBytes.Length).ToArray();

            int bytesUsed;

            header.VertexElement.ParseElementBinaryLittleEndian(withoutHeader, out bytesUsed, out plyResult.vertices, out plyResult.normals, out plyResult.colors);

            int bytesOffset = bytesUsed;

            header.FaceElement.ParseElementBinaryLittleEndian(withoutHeader, bytesOffset, out bytesUsed, out plyResult.triangles);

            bytesOffset = bytesOffset + bytesUsed;
            header.LineElement.ParseElementBinaryLittleEndian(withoutHeader, bytesOffset, out bytesUsed, out plyResult.lines);

            bytesOffset = bytesOffset + bytesUsed;
            header.LineColorElement.ParseElementBinaryLittleEndian(withoutHeader, bytesOffset, out bytesUsed, out plyResult.lineColors);

            return(plyResult);
        }
Exemple #2
0
        public static PlyResult GetResult(byte[] content)
        {
            PlyResult plyResult    = null;
            var       header       = GetHeader(content);
            var       headerParsed = new PlyHeader(header);

            if (!headerParsed.VertexElement.IsValid ||
                (!headerParsed.FaceElement.IsValid && !headerParsed.LineElement.IsValid))
            {
                return(null);
            }

            if (headerParsed.Format == PlyFormat.Ascii)
            {
                plyResult = ParseAscii(GetLines(content), headerParsed);
            }
            else if (headerParsed.Format == PlyFormat.BinaryLittleEndian)
            {
                plyResult = ParseBinaryLittleEndian(content, headerParsed);
            }
            else // todo: support BinaryBigEndian
            {
                return(null);
            }

            return(plyResult); // new PlyResult(mesh, headerParsed.GloablMaterialElement.GetColor());
        }
Exemple #3
0
        private static PlyResult ParseAscii(List <string> plyFile, PlyHeader header)
        {
            PlyResult plyResult = new PlyResult();

            plyResult.meshName  = header.GlobalMeshInfoElement.GetName();
            plyResult.meshColor = header.GloablMaterialElement.GetColor();

            // TODO: order independent
            var headerEndIndex      = plyFile.IndexOf("end_header");
            var vertexStartIndex    = headerEndIndex + 1;
            var faceStartIndex      = vertexStartIndex + header.VertexElement.NElement;
            var lineStartIndex      = faceStartIndex + header.FaceElement.NElement;
            var lineColorStartIndex = lineStartIndex + header.LineElement.NElement;

            header.VertexElement.ParseElement(plyFile.GetRange(vertexStartIndex, header.VertexElement.NElement),
                                              out plyResult.vertices, out plyResult.normals, out plyResult.colors);
            header.FaceElement.ParseElement(plyFile.GetRange(faceStartIndex, header.FaceElement.NElement), out plyResult.triangles);
            header.LineElement.ParseElement(plyFile.GetRange(lineStartIndex, header.LineElement.NElement), out plyResult.lines);
            header.LineColorElement.ParseElement(plyFile.GetRange(lineColorStartIndex, header.LineColorElement.NElement), out plyResult.lineColors);

            return(plyResult);
        }