Mercurial > hg > forks > gldragon
annotate dmmodel.cpp @ 21:1404dfcee7b8
More work on scenefile and model loading support.
Can now load PLY models and simple scene definition files.
Converted dragon mesh to binary PLY format.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 22 Nov 2019 03:03:52 +0200 |
parents | a329f0216491 |
children | 03b86b9c2f29 |
rev | line source |
---|---|
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 // |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 // |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 // |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 #include "dmmodel.h" |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
5 #include <SDL_endian.h> |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 static bool dmError(DMTextFileInfo &info, const std::string &msg) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 printf("ERROR: %s on line #%d: %s\n", |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 msg.c_str(), info.nline, info.line.c_str()); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 static bool dmSyntaxError(DMTextFileInfo &info, const std::string &msg) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 printf("ERROR: Syntax error on line #%d: %s\n", |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 info.nline, msg.c_str()); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 static bool dmReadLine(DMTextFileInfo &info) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 if (!std::getline(info.file, info.line)) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 info.nline++; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 info.line = dmStrTrim(info.line); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 return true; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 static DMPLYPropType dmPLYParsePropType(const std::string &name) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 if (name == "list") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 return PLY_TYPE_LIST; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 if (name == "float" || name == "float32") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 return PLY_TYPE_FLOAT; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 if (name == "double" || name == "float64") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 return PLY_TYPE_DOUBLE; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 if (name == "uchar" || name == "uint8") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 return PLY_TYPE_UINT8; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 if (name == "int16") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 return PLY_TYPE_INT16; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 if (name == "uint16") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 return PLY_TYPE_UINT16; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 if (name == "int" || name == "int32") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 return PLY_TYPE_INT32; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 if (name == "uint" || name == "uint32") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 return PLY_TYPE_UINT32; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 return PLY_TYPE_NONE; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 static bool dmPLYParsePropertyValueASCII(DMPLYFileInfo &info, const DMPLYPropType ptype, DMPLYPropValue &pval, size_t &pos) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 size_t len = 0; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 std::string val = info.line.substr(pos); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 switch (ptype) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 case PLY_TYPE_INT8: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 case PLY_TYPE_INT16: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 case PLY_TYPE_INT32: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 pval.v_int = std::stoi(val, &len); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 break; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 case PLY_TYPE_UINT8: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 case PLY_TYPE_UINT16: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 case PLY_TYPE_UINT32: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 pval.v_uint = std::stoi(val, &len); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 break; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 case PLY_TYPE_FLOAT: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 pval.v_float = std::stof(val, &len); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 break; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 case PLY_TYPE_DOUBLE: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 pval.v_double = std::stod(val, &len); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 break; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 default: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 return dmError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 "Internal error, unimplemented PLY property type"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 pos += len; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 return true; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 static bool dmPLYParsePropertyASCII(DMPLYFileInfo &info, DMPLYFileProperty &prop, size_t &pos) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 switch (prop.type) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 case PLY_TYPE_LIST: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 prop.list_values.clear(); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 if (!dmPLYParsePropertyValueASCII(info, prop.list_num_type, prop.list_num_value, pos)) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 for (unsigned int n = 0; n < prop.list_num_value.v_uint; n++) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 DMPLYPropValue pval; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 if (!dmPLYParsePropertyValueASCII(info, prop.list_values_type, pval, pos)) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 prop.list_values.push_back(pval); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 if (prop.list_values.size() != prop.list_num_value.v_uint) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 "Number of property list '"+ prop.name +" values not equal to number specified"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 return true; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 default: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 return dmPLYParsePropertyValueASCII(info, prop.type, prop.value, pos); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 static bool dmPLYParseElementASCII(DMPLYFileInfo &info, DMPLYFileElement &element) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 size_t nprop = 0, pos = 0; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 // Read one line |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 if (!dmReadLine(info)) |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
143 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
144 return dmError(info, |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
145 "Unexpected end of file"); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
146 } |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 // Skip empty lines |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 if (info.line.empty()) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 return true; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 // Parse the properties |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 for (auto const prop : element.properties) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 if (!dmPLYParsePropertyASCII(info, *prop, pos)) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 nprop++; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 if (nprop != element.properties.size()) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 "Expected N properties, got different number"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 return true; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 bool dmPLYReadPropertyValueBIN(DMPLYFileInfo &info, const DMPLYPropType ptype, DMPLYPropValue &pval) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 { |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
173 uint8_t tmpU8; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
174 int8_t tmpS8; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 uint16_t tmpU16; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 int16_t tmpS16; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 uint32_t tmpU32; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 int32_t tmpS32; |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
179 float tmpFloat; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 switch (ptype) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 case PLY_TYPE_INT8: |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
184 info.file.read(reinterpret_cast<char *>(&tmpS8), 1); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
185 pval.v_int = tmpS8; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 break; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 case PLY_TYPE_UINT8: |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
189 info.file.read(reinterpret_cast<char *>(&tmpU8), 1); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
190 pval.v_uint = tmpU8; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 break; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 case PLY_TYPE_INT16: |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
194 info.file.read(reinterpret_cast<char *>(&tmpS16), 2); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
195 tmpS16 = (info.format == PLY_FMT_BIN_LE) ? SDL_SwapLE16(tmpS16) : SDL_SwapBE16(tmpS16); |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 pval.v_int = tmpS16; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 break; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 case PLY_TYPE_UINT16: |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
200 info.file.read(reinterpret_cast<char *>(&tmpU16), 2); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
201 tmpU16 = (info.format == PLY_FMT_BIN_LE) ? SDL_SwapLE16(tmpU16) : SDL_SwapBE16(tmpU16); |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 pval.v_uint = tmpU16; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 break; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 case PLY_TYPE_INT32: |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
206 info.file.read(reinterpret_cast<char *>(&tmpS32), 4); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
207 tmpS32 = (info.format == PLY_FMT_BIN_LE) ? SDL_SwapLE32(tmpS32) : SDL_SwapBE32(tmpS32); |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 pval.v_int = tmpS32; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 break; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 case PLY_TYPE_UINT32: |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
212 info.file.read(reinterpret_cast<char *>(&tmpU32), 4); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
213 tmpU32 = (info.format == PLY_FMT_BIN_LE) ? SDL_SwapLE32(tmpU32) : SDL_SwapBE32(tmpU32); |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 pval.v_uint = tmpU32; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 break; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
216 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 case PLY_TYPE_FLOAT: |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
218 info.file.read(reinterpret_cast<char *>(&tmpFloat), 4); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
219 pval.v_float = (info.format == PLY_FMT_BIN_LE) ? SDL_SwapFloatLE(tmpFloat) : SDL_SwapFloatBE(tmpFloat); |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 break; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 default: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 return dmError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 "Internal error, unimplemented PLY property type"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
226 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 return true; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
231 bool dmPLYReadPropertyBIN(DMPLYFileInfo &info, DMPLYFileProperty &prop) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 switch (prop.type) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 case PLY_TYPE_LIST: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
236 prop.list_values.clear(); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 if (!dmPLYReadPropertyValueBIN(info, prop.list_num_type, prop.list_num_value)) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
241 for (unsigned int n = 0; n < prop.list_num_value.v_uint; n++) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
242 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
243 DMPLYPropValue pval; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
244 if (!dmPLYReadPropertyValueBIN(info, prop.list_values_type, pval)) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
246 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
247 prop.list_values.push_back(pval); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
249 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
250 if (prop.list_values.size() != prop.list_num_value.v_uint) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
251 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
252 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
253 "Number of property list '"+ prop.name +" values not equal to number specified"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
255 return true; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
256 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
257 default: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
258 return dmPLYReadPropertyValueBIN(info, prop.type, prop.value); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
259 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
262 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
263 bool dmPLYReadElementBIN(DMPLYFileInfo &info, DMPLYFileElement &element) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
264 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
265 size_t nprop = 0; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
266 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
267 for (auto const prop : element.properties) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
268 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
269 if (!dmPLYReadPropertyBIN(info, *prop)) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
270 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
271 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
272 nprop++; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
273 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
274 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
275 if (nprop != element.properties.size()) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
276 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
277 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
278 "Expected N properties, got different number"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
279 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
280 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
281 return true; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
282 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
283 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
284 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
285 bool DMModel::loadFromPLY(const std::string &filename) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
286 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
287 DMPLYFileInfo info; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
288 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
289 return loadFromPLY(filename, info); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
290 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
291 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
292 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
293 bool DMModel::loadFromPLY(const std::string &filename, DMPLYFileInfo &info) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
294 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
295 info.filename = filename; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
296 info.nline = info.state = 0; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
297 info.file.open(info.filename.c_str(), std::fstream::in | std::fstream::binary); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
298 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
299 printf("INFO: Trying to read mesh from '%s'.\n", |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
300 info.filename.c_str()); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
301 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
302 if (!info.file.is_open()) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
303 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
304 printf("ERROR: Unable to open file '%s'.\n", |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
305 info.filename.c_str()); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
306 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
307 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
308 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
309 // Parse the PLY header |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
310 while (info.state >= 0) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
311 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
312 // Read one line |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
313 if (!dmReadLine(info)) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
314 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
315 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
316 // Skip empty lines |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
317 if (info.line.empty()) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
318 continue; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
319 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
320 // Split key and value |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
321 std::vector<std::string> tokens = dmStrSplit(info.line); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
322 std::string &key = tokens[0]; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
323 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
324 if (info.state == 0 && key == "ply") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
325 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
326 info.state = 1; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
327 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
328 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
329 if (info.state > 0 && key == "end_header") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
330 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
331 info.state = -1; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
332 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
333 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
334 if (info.state == 1 && key == "format") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
335 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
336 if (tokens.size() < 3) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
337 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
338 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
339 "Expected value for format"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
340 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
341 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
342 info.format = PLY_FMT_UNKNOWN; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
343 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
344 if (tokens[1] == "ascii") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
345 info.format = PLY_FMT_ASCII; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
346 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
347 if (tokens[1] == "binary_little_endian") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
348 info.format = PLY_FMT_BIN_LE; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
349 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
350 if (tokens[1] == "binary_big_endian") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
351 info.format = PLY_FMT_BIN_BE; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
352 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
353 if (info.format == PLY_FMT_UNKNOWN || |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
354 tokens[2] != "1.0") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
355 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
356 printf("ERROR: Unknown or unsupported PLY file format '%s'.\n", |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
357 (tokens[1] +" "+ tokens[2]).c_str()); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
358 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
359 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
360 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
361 info.state = 2; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
362 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
363 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
364 if ((info.state == 2 || info.state == 3) && key == "element") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
365 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
366 if (tokens.size() < 3) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
367 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
368 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
369 "Expected a value for element key"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
370 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
371 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
372 std::string &el_name = tokens[1], &el_value = tokens[2]; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
373 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
374 if (info.elem_map.count(el_name)) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
375 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
376 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
377 "Element '"+ el_name +"' has already been defined"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
378 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
379 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
380 DMPLYFileElement &elem = info.elem_map[el_name]; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
381 info.element = &elem; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
382 info.elements.push_back(&elem); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
383 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
384 elem.name = el_name; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
385 elem.value = std::stoi(el_value); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
386 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
387 info.state = 3; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
388 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
389 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
390 if (info.state == 3 && key == "property") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
391 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
392 if (tokens.size() < 3) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
393 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
394 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
395 "Expected value for property"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
396 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
397 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
398 const std::string |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
399 &pr_name = tokens.back(), |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
400 &pr_typename = tokens.at(1); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
401 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
402 if (!info.element) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
403 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
404 // Should not happen |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
405 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
406 "No element defined for property '"+ pr_name +"'?"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
407 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
408 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
409 // Check if this property has been already defined |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
410 if (info.element->prop_map.count(pr_name)) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
411 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
412 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
413 "Element '"+ info.element->name + |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
414 "' already has property '"+ pr_name +"' defined?"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
415 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
416 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
417 // Parse property information |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
418 DMPLYPropType pr_type = dmPLYParsePropType(pr_typename); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
419 if (pr_type == PLY_TYPE_NONE) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
420 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
421 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
422 "Invalid or unsupported property type '"+ pr_typename +"'"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
423 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
424 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
425 DMPLYFileProperty &prop = info.element->prop_map[pr_name]; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
426 info.element->properties.push_back(&prop); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
427 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
428 prop.name = pr_name; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
429 prop.type = pr_type; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
430 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
431 if (pr_type == PLY_TYPE_LIST) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
432 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
433 // List is a special case |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
434 if (tokens.size() < 5) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
435 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
436 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
437 "Expected more values for a list property (num_type, val_type, name)"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
438 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
439 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
440 prop.list_num_type = dmPLYParsePropType(tokens.at(2)); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
441 prop.list_values_type = dmPLYParsePropType(tokens.at(3)); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
442 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
443 if (prop.list_num_type == PLY_TYPE_NONE || |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
444 prop.list_values_type == PLY_TYPE_NONE) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
445 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
446 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
447 "Invalid or unsupported property type(s)"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
448 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
449 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
450 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
451 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
452 if (info.state > 0 // && (key == "comment" || key == "obj_info") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
453 ) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
454 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
455 // Ignore comments |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
456 // .. and unknown keys |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
457 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
458 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
459 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
460 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
461 "Unexpected key '"+ key +"'"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
462 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
463 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
464 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
465 // Check header data |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
466 DMPLYFileElement *elem; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
467 DMPLYFileProperty *prop; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
468 if (info.state != -1 || |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
469 (elem = info.checkElem(PLY_ELEM_FACE)) == 0 || |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
470 (prop = elem->checkProp(PLY_PROP_VERTEX_INDICES)) == 0 || |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
471 prop->type != PLY_TYPE_LIST || |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
472 (elem = info.checkElem(PLY_ELEM_VERTEX)) == 0 || |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
473 (prop = elem->checkProp("x")) == 0 || prop->type != PLY_TYPE_FLOAT || |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
474 (prop = elem->checkProp("y")) == 0 || prop->type != PLY_TYPE_FLOAT || |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
475 (prop = elem->checkProp("z")) == 0 || prop->type != PLY_TYPE_FLOAT |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
476 ) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
477 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
478 printf("ERROR: PLY file did not contain expected information.\n"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
479 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
480 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
481 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
482 nvertices = info.elem_map[PLY_ELEM_VERTEX].value; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
483 nfaces = info.elem_map[PLY_ELEM_FACE].value; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
484 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
485 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
486 if (nvertices < 3 || nfaces < 1) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
487 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
488 printf("ERROR: Invalid nvertices (%d) and/or nfaces (%d).\n", |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
489 nvertices, nfaces); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
490 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
491 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
492 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
493 printf("INFO: Should have %d vertices, %d faces\n", |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
494 nvertices, nfaces); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
495 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
496 // Pre-allocate space |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
497 vertices.reserve(nvertices); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
498 normals.reserve(nvertices); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
499 faces.reserve(nfaces * 3); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
500 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
501 // Read the actual data (in order of the elements) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
502 for (auto *element : info.elements) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
503 for (int n = 0; n < element->value; n++) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
504 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
505 switch (info.format) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
506 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
507 case PLY_FMT_ASCII: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
508 if (!dmPLYParseElementASCII(info, *element)) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
509 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
510 break; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
511 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
512 default: |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
513 if (!dmPLYReadElementBIN(info, *element)) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
514 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
515 break; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
516 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
517 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
518 // Check for specific elements |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
519 if (element->name == PLY_ELEM_FACE) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
520 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
521 DMPLYFileProperty &prop = element->prop_map[PLY_PROP_VERTEX_INDICES]; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
522 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
523 if (prop.list_num_value.v_uint != 3) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
524 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
525 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
526 "Expected 3 vertices per face"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
527 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
528 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
529 for (unsigned int n = 0; n < prop.list_num_value.v_uint; n++) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
530 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
531 faces.push_back(prop.list_values[n].v_uint); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
532 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
533 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
534 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
535 if (element->name == PLY_ELEM_VERTEX) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
536 { |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
537 DMVector3 vert; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
538 vert.x = element->prop_map["x"].value.v_float; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
539 vert.y = element->prop_map["y"].value.v_float; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
540 vert.z = element->prop_map["z"].value.v_float; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
541 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
542 vertices.push_back(vert); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
543 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
544 if (element->checkProp("nx") && |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
545 element->checkProp("ny") && |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
546 element->checkProp("nz")) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
547 { |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
548 DMVector3 normal; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
549 normal.x = element->prop_map["nx"].value.v_float; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
550 normal.y = element->prop_map["ny"].value.v_float; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
551 normal.z = element->prop_map["nz"].value.v_float; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
552 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
553 normals.push_back(normal); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
554 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
555 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
556 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
557 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
558 printf("INFO: Found %ld vertices, %ld normals, %ld faces\n", |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
559 vertices.size(), |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
560 normals.size(), |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
561 faces.size() / 3); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
562 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
563 return true; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
564 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
565 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
566 |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
567 bool dmParseVector(DMTextFileInfo &info, const std::vector<std::string> tokens, const size_t offs, DMVector3 &vec) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
568 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
569 if (tokens.size() == offs + 1) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
570 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
571 vec.x = vec.y = vec.z = std::stof(tokens[offs]); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
572 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
573 else |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
574 if (tokens.size() == offs + 3) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
575 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
576 vec.x = std::stof(tokens[offs]); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
577 vec.y = std::stof(tokens[offs + 1]); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
578 vec.z = std::stof(tokens[offs + 2]); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
579 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
580 else |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
581 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
582 return dmSyntaxError(info, |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
583 "Expected 1/3 value vector for '"+ *info.key +"'"); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
584 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
585 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
586 return true; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
587 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
588 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
589 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
590 bool dmParseVector(DMTextFileInfo &info, const std::vector<std::string> tokens, const size_t offs, DMVector4 &vec) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
591 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
592 vec.w = 1.0f; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
593 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
594 if (tokens.size() == offs + 1) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
595 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
596 vec.x = vec.y = vec.z = std::stof(tokens[offs]); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
597 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
598 else |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
599 if (tokens.size() == offs + 3 || tokens.size() == offs + 4) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
600 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
601 vec.x = std::stof(tokens[offs]); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
602 vec.y = std::stof(tokens[offs + 1]); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
603 vec.z = std::stof(tokens[offs + 2]); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
604 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
605 if (tokens.size() == offs + 4) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
606 vec.w = std::stof(tokens[offs + 3]); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
607 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
608 else |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
609 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
610 return dmSyntaxError(info, |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
611 "Expected 1/3/4 value vector for '"+ *info.key +"'"); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
612 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
613 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
614 return true; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
615 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
616 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
617 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
618 bool dmParseColor(DMTextFileInfo &info, const std::vector<std::string> tokens, const size_t offs, DMColor &color) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
619 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
620 color.alpha = 0xff; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
621 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
622 if (tokens.size() == offs + 1) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
623 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
624 color.r = color.g = color.b = std::stoi(tokens[offs], 0, 0); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
625 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
626 else |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
627 if (tokens.size() == offs + 3 || tokens.size() == offs + 4) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
628 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
629 color.r = std::stoi(tokens[offs], 0, 0); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
630 color.g = std::stoi(tokens[offs + 1], 0, 0); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
631 color.b = std::stoi(tokens[offs + 2], 0, 0); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
632 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
633 if (tokens.size() == offs + 4) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
634 color.alpha = std::stoi(tokens[offs + 3], 0, 0); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
635 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
636 else |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
637 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
638 return dmSyntaxError(info, |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
639 "Expected color values <value> or <red> <green> <blue> [<alpha>] for '"+ *info.key +"'"); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
640 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
641 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
642 return true; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
643 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
644 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
645 |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
646 bool DMSimpleScene::loadInfo(const std::string &filename) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
647 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
648 DMTextFileInfo info; |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
649 DMModel *model = 0; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
650 DMLight *light = 0; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
651 DMVector3 *ppos = 0, *ppointAt = 0; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
652 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
653 info.filename = filename; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
654 info.nline = info.state = 0; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
655 info.file.open(info.filename.c_str(), std::fstream::in | std::fstream::binary); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
656 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
657 printf("INFO: Trying to read scene data from '%s'.\n", |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
658 info.filename.c_str()); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
659 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
660 if (!info.file.is_open()) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
661 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
662 printf("ERROR: Unable to open file '%s'.\n", |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
663 info.filename.c_str()); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
664 return false; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
665 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
666 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
667 while (info.state >= 0) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
668 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
669 // Read one line |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
670 if (!dmReadLine(info)) |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
671 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
672 info.state = -1; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
673 break; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
674 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
675 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
676 // Skip empty lines and comments |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
677 if (info.line.empty() || |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
678 info.line[0] == '#' || |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
679 info.line[0] == ';') |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
680 continue; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
681 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
682 // Split key and values |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
683 std::vector<std::string> tokens = dmStrSplit(info.line); |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
684 std::string key = tokens[0]; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
685 info.key = &key; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
686 |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
687 if (key == "model") |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
688 { |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
689 DMModel newmodel; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
690 if (tokens.size() != 2) |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
691 { |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
692 return dmError(info, |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
693 "Keyword model expects a filename argument"); |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
694 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
695 |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
696 models.push_back(newmodel); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
697 model = &models.back(); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
698 model->modelFile = tokens[1]; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
699 info.state = 1; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
700 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
701 else |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
702 if (info.state == 1 && key == "color") |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
703 { |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
704 if (!dmParseColor(info, tokens, 1, model->color)) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
705 return false; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
706 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
707 else |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
708 if (info.state == 1 && (key == "translate" || key == "rotate" || key == "scale")) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
709 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
710 DMVector3 vec; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
711 |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
712 if (!dmParseVector(info, tokens, 1, vec)) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
713 return false; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
714 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
715 if (!model) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
716 return false; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
717 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
718 if (key == "translate") |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
719 model->translate = vec; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
720 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
721 if (key == "rotate") |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
722 model->rotate = vec; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
723 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
724 if (key == "scale") |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
725 model->scale = vec; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
726 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
727 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
728 if (key == "light") |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
729 { |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
730 DMLight newlight; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
731 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
732 if (lights.size() >= 4) |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
733 { |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
734 printf("ERROR: Too many lights defined.\n"); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
735 return false; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
736 } |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
737 lights.push_back(newlight); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
738 light = &lights.back(); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
739 ppos = &light->pos; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
740 ppointAt = &light->pointAt; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
741 info.state = 2; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
742 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
743 else |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
744 if (info.state == 2 && (key == "ambient" || key == "diffuse" || key == "specular")) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
745 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
746 DMVector4 val; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
747 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
748 if (!dmParseVector(info, tokens, 1, val)) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
749 return false; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
750 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
751 if (key == "ambient") |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
752 light->ambient = val; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
753 else |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
754 if (key == "diffuse") |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
755 light->diffuse = val; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
756 else |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
757 if (key == "specular") |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
758 light->specular = val; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
759 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
760 else |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
761 if (key == "camera") |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
762 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
763 info.state = 3; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
764 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
765 ppos = &camera.pos; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
766 ppointAt = &camera.pointAt; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
767 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
768 else |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
769 if ((info.state == 3 || info.state == 2) && (key == "pos" || key == "point_at")) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
770 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
771 DMVector3 vec; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
772 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
773 if (!dmParseVector(info, tokens, 1, vec)) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
774 return false; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
775 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
776 if (key == "pos") |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
777 *ppos = vec; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
778 else |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
779 if (key == "point_at") |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
780 *ppointAt = vec; |
19
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
781 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
782 else |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
783 { |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
784 return dmSyntaxError(info, |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
785 "Unexpected key '"+ key +"'"); |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
786 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
787 } |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
788 |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
789 return true; |
a329f0216491
Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
790 } |