Mercurial > hg > forks > gldragon
comparison dmscene.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 | 701bef61dcf1 |
children | 1ed7f9d85342 |
comparison
equal
deleted
inserted
replaced
69:267b3fd2c98c | 70:03aa729a9e90 |
---|---|
9 #ifndef DMSCENE_H | 9 #ifndef DMSCENE_H |
10 #define DMSCENE_H 1 | 10 #define DMSCENE_H 1 |
11 | 11 |
12 #include "dmutil.h" | 12 #include "dmutil.h" |
13 #include <cstdint> | 13 #include <cstdint> |
14 #include <fstream> | |
15 #include <unordered_map> | |
16 | 14 |
17 | 15 |
18 #define PLY_PROP_VERTEX_INDICES "vertex_indices" | 16 /* Structures and classes |
19 #define PLY_ELEM_FACE "face" | |
20 #define PLY_ELEM_VERTEX "vertex" | |
21 | |
22 | |
23 enum DMPLYFormat | |
24 { | |
25 PLY_FMT_UNKNOWN, | |
26 PLY_FMT_ASCII, | |
27 PLY_FMT_BIN_LE, | |
28 PLY_FMT_BIN_BE | |
29 }; | |
30 | |
31 | |
32 enum DMPLYPropType | |
33 { | |
34 PLY_TYPE_NONE, | |
35 PLY_TYPE_LIST, | |
36 | |
37 PLY_TYPE_UINT8, | |
38 PLY_TYPE_INT8, | |
39 PLY_TYPE_INT16, | |
40 PLY_TYPE_UINT16, | |
41 PLY_TYPE_INT32, | |
42 PLY_TYPE_UINT32, | |
43 PLY_TYPE_FLOAT, | |
44 PLY_TYPE_DOUBLE | |
45 }; | |
46 | |
47 | |
48 /* Structures | |
49 */ | 17 */ |
50 union DMPLYPropValue | |
51 { | |
52 double v_double; | |
53 float v_float; | |
54 unsigned int v_uint; | |
55 int v_int; | |
56 }; | |
57 | |
58 | |
59 struct DMPLYFileProperty | |
60 { | |
61 std::string name; | |
62 DMPLYPropType | |
63 type, | |
64 list_num_type, | |
65 list_values_type; | |
66 | |
67 DMPLYPropValue value, list_num_value; | |
68 std::vector<DMPLYPropValue> list_values; | |
69 }; | |
70 | |
71 | |
72 struct DMPLYFileElement | |
73 { | |
74 int value; | |
75 std::string name; | |
76 | |
77 std::unordered_map<std::string, DMPLYFileProperty> prop_map; | |
78 std::vector<DMPLYFileProperty *> properties; | |
79 | |
80 DMPLYFileProperty *checkProp(const std::string &prop) | |
81 { | |
82 if (prop_map.count(prop)) | |
83 return &prop_map[prop]; | |
84 else | |
85 return 0; | |
86 } | |
87 }; | |
88 | |
89 | |
90 struct DMTextFileInfo | |
91 { | |
92 int nline, state; | |
93 std::string filename; | |
94 std::string line; | |
95 std::ifstream file; | |
96 std::string *key; | |
97 }; | |
98 | |
99 | |
100 struct DMPLYFileInfo : DMTextFileInfo | |
101 { | |
102 DMPLYFormat format; | |
103 | |
104 std::unordered_map<std::string, DMPLYFileElement> elem_map; | |
105 std::vector<DMPLYFileElement *> elements; | |
106 DMPLYFileElement *element; | |
107 | |
108 DMPLYFileInfo() | |
109 { | |
110 element = 0; | |
111 format = PLY_FMT_UNKNOWN; | |
112 } | |
113 | |
114 DMPLYFileElement *checkElem(const std::string &elem) | |
115 { | |
116 if (elem_map.count(elem)) | |
117 return &elem_map[elem]; | |
118 else | |
119 return 0; | |
120 } | |
121 }; | |
122 | |
123 | |
124 struct DMVector3 | 18 struct DMVector3 |
125 { | 19 { |
126 float x, y, z; | 20 float x, y, z; |
127 }; | 21 }; |
128 | 22 |
156 | 50 |
157 std::string | 51 std::string |
158 modelFile, | 52 modelFile, |
159 fragShaderFile, vertShaderFile, | 53 fragShaderFile, vertShaderFile, |
160 fragShaderStr, vertShaderStr; | 54 fragShaderStr, vertShaderStr; |
161 | |
162 bool loadFromPLY(const std::string &filename); | |
163 bool loadFromPLY(const std::string &filename, DMPLYFileInfo &info); | |
164 | 55 |
165 DMModel() | 56 DMModel() |
166 { | 57 { |
167 nfaces = nvertices = 0; | 58 nfaces = nvertices = 0; |
168 | 59 |