Ply file format and parsing

Source: Internet
Author: User
Tags format definition

The ply file format is a set of 3D mesh model data formats developed by Stanford University. many well-known model data in the graphic field, for example, Stanford's 3D scanning database [1] (including the happy Buddha, dragon, and bunny rabbits that are seen in many articles), geogia tech's large Geometric Model Library [3], north Carolina (UNC) power plant model [4] and so on, the initial model is based on this format.

The development goal of ply polygon file format is to create a polygon-oriented model with simple structure but can meet the needs of most graphics applications, it also allows file storage in ASCII format or binary format. Ply developers hope that such a set of simple and flexible file formats can help developers avoid repeated development of file formats. However, due to various reasons, new file formats are still emerging in the industrial field, but in the field of graphics research, ply is still a common and important file format.

As a polygon model data format, ply is different from common scene graph file formats and script files in 3D engines. Each ply file is only used to describe a polygon model object ), this model object can be described through data such as vertex and surface. Each type of data is called an element ). Compared with the various complex formats used in modern 3D engines, ply is a simple file format, but if you study it carefully, you will find that, as the designer said, this is enough for most graphics applications.

The ply file structure is also simple: the file header and the element data list. The file header describes the file type, format and version, element type, and element attributes in the unit of action, and then describes the sequence and attributes of the element types listed in the file header, records the attribute data of each element in sequence.

The following example is a typical ASCII ply file, which describes a cube.

Ply

Format ASCII 1.0... {file type: ASCII or binary, version number}

Comment made by anonymous... {comment row}

Comment this file is a cube... {comment row}

Element vertex 8... {defines the "vertex" element. The number of elements is 8}

Property float32 X... {x attribute of vertex, data type: float32}

Property float32 y... {x attribute of vertex, data type: float32}

Property float32 Z... {x attribute of vertex, data type: float32}

Element face 6... {defines the "surface" element. The number is 6}

Property list uint8 int32 vertex_index... {top vertex index attribute, type: uint8 list}

End_header... {end mark of the file header}

0 0 0... {vertex element list}

0 0 1

0 1 1

0 1 0

1 0 0

1 0 1

1 1 1

1 1 0

4 0 1 2 3... {surface element list}

4 7 6 5 4

4 0 4 5 1

4 1 5 6 2

4 2 6 7 3

4 3 7 4 0

From the file header, we can see that the object defined in the file consists of eight vertex elements and six polygon surface elements. The vertex elements include three attributes: X, Y, and Z, the object contains 32-bit floating point, while the polygon element only includes the attributes of a vertex index list. As a list attribute, it consists of two parts, that is, the number of list elements (uint8 type) and each list element (int32 type). The data of each list attribute includes four list elements, the indexes of the four vertices on each polygon.

The ply format supports the following data types.

Name type number of bytes

---------------------------------------

Int8 character 1

Uint8 unsigned character 1

Int16 short integer 2

Uint16 unsigned short integer 2

Int32 integer 4

Uint32 unsigned integer 4

Float32 Single-precision float 4

Float64 double-precision float 8

However, due to the openness of ply format, some ply File Parsing programs do not support all data types, and some ply files use custom data types, these may cause File Parsing failure. (When I manually write a ply file for testing purposes when I load the ply file to the ogre application, loading always fails, after repeated searches, we can find that the format of the vertex written in the file is uint32, which is not supported by the loader .)

For the attribute definition method of an element, ply allows a single attribute definition:

Property <data-type> <property-name-1>

And the list attribute method:

Property list <numerical-type> <property-Name>

The first data type describes the number of list elements, and the second data type describes each list element.

Apart from two basic elements: vertex and polygon, the ply file format allows the use of custom elements and element attributes, known as other element and other property. As long as the format definition of elements and element attributes in the file format is followed, it can be parsed normally, which is also a flexible feature of ply format.

Ply file format specifications and parsed source code are open, you can find the relevant download from references. The most famous is the parsing code that Greg Turk released in 1994. Turk seems to be one of the developers of ply format, because he wrote the reference "the ply polygon File Format. I am now using the Turk code, which is very convenient and stable. I have the opportunity to analyze the structure.

References

1. the Stanford 3D scanning Repository

2. Mac + PC + UNIX ply reading/writing

3. Large geometry models archieve

4. Power Plant Model

5. The ply polygon File Format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.