Mercurial > hg > forks > gldragon
diff dmply.h @ 70:03aa729a9e90
Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 16 Dec 2019 07:51:05 +0200 |
parents | |
children | 9ee0edff3940 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmply.h Mon Dec 16 07:51:05 2019 +0200 @@ -0,0 +1,120 @@ +// +// GLDragon - OpenGL PLY model viewer / simple benchmark +// -- PLY file parsing +// Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org> +// (C) Copyright 2019 Tecnic Software productions (TNSP) +// +// See file "COPYING" for license information. +// +#ifndef DMPLY_H +#define DMPLY_H 1 + +#include "dmscene.h" +#include <unordered_map> + + +/* Constants + */ +#define PLY_PROP_VERTEX_INDICES "vertex_indices" +#define PLY_ELEM_FACE "face" +#define PLY_ELEM_VERTEX "vertex" + + +enum DMPLYFormat +{ + PLY_FMT_UNKNOWN, + PLY_FMT_ASCII, + PLY_FMT_BIN_LE, + PLY_FMT_BIN_BE +}; + + +enum DMPLYPropType +{ + PLY_TYPE_NONE, + PLY_TYPE_LIST, + + PLY_TYPE_UINT8, + PLY_TYPE_INT8, + PLY_TYPE_INT16, + PLY_TYPE_UINT16, + PLY_TYPE_INT32, + PLY_TYPE_UINT32, + PLY_TYPE_FLOAT, + PLY_TYPE_DOUBLE +}; + + +/* Structures + */ +union DMPLYPropValue +{ + double v_double; + float v_float; + unsigned int v_uint; + int v_int; +}; + + +struct DMPLYFileProperty +{ + std::string name; + DMPLYPropType + type, + list_num_type, + list_values_type; + + DMPLYPropValue value, list_num_value; + std::vector<DMPLYPropValue> list_values; +}; + + +struct DMPLYFileElement +{ + int value; + std::string name; + + std::unordered_map<std::string, DMPLYFileProperty> prop_map; + std::vector<DMPLYFileProperty *> properties; + + DMPLYFileProperty *checkProp(const std::string &prop) + { + if (prop_map.count(prop)) + return &prop_map[prop]; + else + return 0; + } +}; + + +struct DMPLYFileInfo : DMTextFileInfo +{ + DMPLYFormat format; + + std::unordered_map<std::string, DMPLYFileElement> elem_map; + std::vector<DMPLYFileElement *> elements; + DMPLYFileElement *element; + + DMPLYFileInfo() + { + element = 0; + format = PLY_FMT_UNKNOWN; + } + + DMPLYFileElement *checkElem(const std::string &elem) + { + if (elem_map.count(elem)) + return &elem_map[elem]; + else + return 0; + } +}; + + +/* Functions + */ +bool dmLoadFromPLY(DMModel &model, const std::string &filename); +bool dmLoadFromPLY(DMModel &model, const std::string &filename, DMPLYFileInfo &info); + + +#endif