Unity Ply網格讀取
阿新 • • 發佈:2020-11-24
Unity Ply網格讀取
Ply格式說明
The version 1.0 PLY format, 詳細參見:https://ww2.mathworks.cn/help/vision/ug/the-ply-format.html
File Header
檔案頭示例’{}‘為說明:
ply {檔案頭} format binary_big_endian 1.0 {資料格式以及版本} element vertex 9200 {定義vertex元素} property float x {定義屬性} property float y property float z element face 18000 {定義面元素} property list uchar int vertex_indices end_header {這行後面就是資料了}
其中,format <data format> <PLY version>
中的<data format>
支援(little/big endian refers to the byte ordering of multi-byte data):
- ascii
- binary_little_endian
- binary_big_endian
元素定義方式如下:
element <element name> <number in file> property <data type> <property name 1> property <data type> <property name 2> property <data type> <property name 3> ...
其中對應的<data type>
有:
Name | Type |
---|---|
char | (8-bit) character |
uchar | (8-bit) unsigned character |
short | (16-bit) short integer |
ushort | (16-bit) unsigned short integer |
int | (32-bit) integer |
uint | (32-bit) unsigned integer |
float | (32-bit) single-precision float |
double | (64-bit) double-precision float |
對於list的屬性為:
property list <count data type> <data type> <property name>
在檔案頭裡面還可以添加註釋,具體格式如下:
comment <comment text>
Data
header之後存資料。按照之前約定的元素順序和屬性型別,依次儲存。
Common Elements and Properties
常見元素和屬性為:
Required Core Property | Element | Property | Data Type | Property Description |
---|---|---|---|---|
✓ | vertex | x | float |
x,y,z coordinates |
✓ | y | float |
||
✓ | z | float |
||
nx | float |
x,y,z of normal | ||
ny | float |
|||
nz | float |
|||
red | uchar |
vertex color | ||
green | uchar |
|||
blue | uchar |
|||
alpha | uchar |
amount of transparency | ||
material_index | int |
index to list of materials | ||
face | vertex_indices | list of int | indices to vertices | |
back_red | uchar |
backside color | ||
back_green | uchar |
|||
back_blue | uchar |
|||
edge | vertex1 | int |
index to vertex | |
vertex2 | int |
index to other vertex | ||
crease_tag | uchar |
crease in subdivision surface | ||
material | red | uchar |
material color | |
green | uchar |
|||
blue | uchar |
|||
alpha | uchar |
amount of transparency | ||
reflect_coeff | float |
amount of light reflected | ||
refract_coeff | float |
amount of light refracted | ||
refract_index | float |
index of refraction | ||
extinct_coeff | float |
extinction coefficent |
Unity Ply Reader
附上專案路徑:https://github.com/grassofsky/PlyImporter
PlyImporter
原始專案的說明見:https://github.com/3DBear/PlyImporter
在原來基礎上的改動主要有
- 增加了PlyElement基類,專門用來處理不同的element,方便後期進行擴充套件,目前支援PlyFaceElement,PlyVertexElement;
- 增加了PlyProperty基類,處理不同的屬性,按照屬性的功能又分為PlyMultiProperty,用來支援單個property定義;PlyListProperty支援property list定義。
TODO
- 支援PlyEdgeElement;
- 考慮到Unity中的shader基本沒有用到頂點的顏色,增加PlyMaterialElement用來設定材質顏色;
- 通常對於載入的檔案,需要知道該檔案對應的網格名稱,擴充套件comment支援更多的選項;
- Support for Binary Big Endian
- PLY exporting