annotate dmmodel.cpp @ 47:9909014498f0

Add helper functions dmError() and dmMsg() and use them.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Dec 2019 23:52:45 +0200
parents d640f2a34031
children 0ae1ff609626
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 //
22
03b86b9c2f29 Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
2 // GLDragon - OpenGL PLY model viewer / simple benchmark
03b86b9c2f29 Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
3 // -- Scene and model handling + PLY file parsing
03b86b9c2f29 Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
4 // Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
03b86b9c2f29 Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
5 // (C) Copyright 2019 Tecnic Software productions (TNSP)
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 //
22
03b86b9c2f29 Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
7 // See file "COPYING" for license information.
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 //
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "dmmodel.h"
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
10 #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
11
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
13 static bool dmTextError(DMTextFileInfo &info, const std::string &msg)
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
15 dmError("%s on line #%d: %s\n",
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 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
17 return false;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 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
22 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
23 dmError("Syntax error on line #%d: %s\n",
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 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
25 return false;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
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 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
30 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 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
32 return false;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 info.nline++;
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 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
37
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 return true;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 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
43 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 if (name == "list")
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 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
46 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 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
48 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
49 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 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
51 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
52 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 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
54 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
55 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 if (name == "int16")
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 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
58 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 if (name == "uint16")
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 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
61 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 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
63 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
64 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 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
66 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
67 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 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
69 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70
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 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
73 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 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
75 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
76
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 switch (ptype)
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 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
80 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
81 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
82 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
83 break;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 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
86 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
87 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
88 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
89 break;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 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
92 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
93 break;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 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
96 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
97 break;
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 default:
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
100 return dmTextError(info,
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 "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
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 pos += len;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 return true;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 }
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
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 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
111 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 switch (prop.type)
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 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
115 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
116
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 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
118 return false;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 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
121 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 DMPLYPropValue pval;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 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
124 return false;
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 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
127 }
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 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
130 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 "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
133 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 return true;
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 default:
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 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
138 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 }
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
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 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
143 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 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
145
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 // Read one line
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 if (!dmReadLine(info))
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
148 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
149 return dmTextError(info,
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
150 "Unexpected end of file");
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
151 }
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 // Skip empty lines
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 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
155 return true;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 // Parse the properties
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 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
159 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 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
161 return false;
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 nprop++;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 }
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 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
167 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 "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
170 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 return true;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 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
177 {
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
178 uint8_t tmpU8;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
179 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
180 uint16_t tmpU16;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 int16_t tmpS16;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 uint32_t tmpU32;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 int32_t tmpS32;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
184 float tmpFloat;
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 switch (ptype)
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_INT8:
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 *>(&tmpS8), 1);
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
190 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
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_UINT8:
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 *>(&tmpU8), 1);
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
195 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
196 break;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 case PLY_TYPE_INT16:
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
199 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
200 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
201 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
202 break;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 case PLY_TYPE_UINT16:
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
205 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
206 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
207 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
208 break;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 case PLY_TYPE_INT32:
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
211 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
212 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
213 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
214 break;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 case PLY_TYPE_UINT32:
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
217 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
218 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
219 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
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 case PLY_TYPE_FLOAT:
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
223 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
224 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
225 break;
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 default:
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
228 return dmTextError(info,
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 "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
230 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 return true;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 }
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
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 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
237 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 switch (prop.type)
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 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
241 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
242
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 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
244 return false;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 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
247 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 DMPLYPropValue pval;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 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
250 return false;
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 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
253 }
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 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
256 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 "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
259 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 return true;
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 default:
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 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
264 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 }
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
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 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
269 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 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
271
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 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
273 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 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
275 return false;
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 nprop++;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 }
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 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
281 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 "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
284 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 return true;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 }
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
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 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
291 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 DMPLYFileInfo info;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 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
295 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 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
299 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 info.filename = filename;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 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
302 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
303
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
304 dmMsg("Trying to read mesh from '%s'.\n",
19
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
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 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
308 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
309 dmError("Unable to open file '%s'.\n",
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 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
311 return false;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 // 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
315 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
316 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 // Read one line
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 if (!dmReadLine(info))
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 return false;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 // Skip empty lines
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 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
323 continue;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 // 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
326 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
327 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
328
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 == "ply")
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 > 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
335 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 info.state = -1;
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 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 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
340 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 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
342 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 "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
345 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 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
348
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 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
350 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
351 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 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
353 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
354 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 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
356 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
357
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 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
359 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
360 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
361 dmError("Unknown or unsupported PLY file format '%s'.\n",
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 (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
363 return false;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 }
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 info.state = 2;
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 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 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
370 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371 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
372 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 "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
375 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 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
378
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 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
380 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 "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
383 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 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
386 info.element = &elem;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 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
388
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 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
390 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
391
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 info.state = 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 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 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
396 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 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
398 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 "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
401 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 const std::string
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 &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
405 &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
406
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 if (!info.element)
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 // Should not happen
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 "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
412 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 // 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
415 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
416 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 "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
419 "' 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
420 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 // Parse property information
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 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
424 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
425 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 "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
428 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 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
431 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
432
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 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
434 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
435
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 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
437 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 // 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
439 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
440 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 "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
443 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 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
446 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
447
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 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
449 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
450 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 "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
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 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 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
458 )
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 // Ignore comments
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461 // .. and unknown keys
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 else
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 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 "Unexpected key '"+ key +"'");
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470 // Check header data
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471 DMPLYFileElement *elem;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472 DMPLYFileProperty *prop;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473 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
474 (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
475 (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
476 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
477 (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
478 (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
479 (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
480 (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
481 )
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
483 dmError("PLY file did not contain expected information.\n");
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484 return false;
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
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 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
488 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
489
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491 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
492 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
493 dmError("Invalid nvertices (%d) and/or nfaces (%d).\n",
19
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 return false;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
498 dmMsg("Should have %d vertices, %d faces\n",
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 nvertices, nfaces);
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 // Pre-allocate space
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502 vertices.reserve(nvertices);
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503 normals.reserve(nvertices);
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 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
505
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 // 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
507 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
508 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
509 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 switch (info.format)
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 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
513 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
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 default:
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
518 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
519 return false;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
520 break;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521 }
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 // 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
524 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
525 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
526 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
527
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528 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
529 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 "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
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 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
535 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
536 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
537 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540 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
541 {
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
542 DMVector3 vert;
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543 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
544 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
545 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
546
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547 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
548
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549 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
550 element->checkProp("ny") &&
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551 element->checkProp("nz"))
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 {
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
553 DMVector3 normal;
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
554 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
555 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
556 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
557
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
558 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
559 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
560 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
561 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
563 dmMsg("Found %ld vertices, %ld normals, %ld faces\n",
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 vertices.size(),
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565 normals.size(),
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 faces.size() / 3);
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568 return true;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
572 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
573 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
574 if (tokens.size() == offs + 1)
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 = 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
577 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
578 else
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
579 if (tokens.size() == offs + 3)
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
580 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
581 vec.x = std::stof(tokens[offs]);
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
582 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
583 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
584 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
585 else
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
586 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
587 return dmSyntaxError(info,
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
588 "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
589 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
590
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
591 return true;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
592 }
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
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
595 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
596 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
597 if (tokens.size() == offs + 1)
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
598 {
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
599 vec.p.x = vec.p.y = vec.p.z = std::stof(tokens[offs]);
21
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 else
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
602 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
603 {
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
604 vec.p.x = std::stof(tokens[offs]);
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
605 vec.p.y = std::stof(tokens[offs + 1]);
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
606 vec.p.z = std::stof(tokens[offs + 2]);
21
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 if (tokens.size() == offs + 4)
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
609 vec.p.w = std::stof(tokens[offs + 3]);
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
610 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
611 else
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 return dmSyntaxError(info,
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
614 "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
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 return true;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
618 }
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
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621 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
622 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
623 DMTextFileInfo info;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
624 DMModel *model = 0;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
625 DMLight *light = 0;
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
626 DMVector4 *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
627
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
628 info.filename = filename;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
629 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
630 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
631
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
632 dmMsg("Trying to read scene data from '%s'.\n",
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
633 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
634
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
635 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
636 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
637 dmError("Unable to open file '%s'.\n",
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
638 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
639 return false;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
640 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
641
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
642 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
643 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
644 // Read one line
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
645 if (!dmReadLine(info))
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
646 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
647 info.state = -1;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
648 break;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
649 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
650
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
651 // 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
652 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
653 info.line[0] == '#' ||
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
654 info.line[0] == ';')
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
655 continue;
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 // 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
658 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
659 std::string key = tokens[0];
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
660 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
661
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
662 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
663 {
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
664 DMModel newmodel;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
665 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
666 {
33
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
667 return dmSyntaxError(info,
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
668 "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
669 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
670
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
671 models.push_back(newmodel);
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
672 model = &models.back();
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
673 model->modelFile = tokens[1];
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
674 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
675 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
676 else
33
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
677 if (info.state == 1 && (key == "shaderfile"))
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
678 {
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
679 if (tokens.size() != 3)
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
680 {
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
681 return dmSyntaxError(info,
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
682 "Keyword shaderfile expects shader type (fs, vs) and filename arguments");
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
683 }
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
684
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
685 std::string
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
686 &shtype = tokens[1],
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
687 &shfile = tokens[2];
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
688
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
689 if (shtype == "fs")
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
690 model->fragShaderFile = shfile;
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
691 else
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
692 if (shtype == "vs")
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
693 model->vertShaderFile = shfile;
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
694 else
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
695 {
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
696 return dmSyntaxError(info,
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
697 "Invalid shaderfile type '"+ shtype +"'");
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
698 }
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
699 }
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
700 else
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
701 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
702 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
703 DMVector3 vec;
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
704
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
705 if (!dmParseVector(info, tokens, 1, vec))
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
706 return false;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
707
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
708 if (!model)
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
709 return false;
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
710
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
711 if (key == "translate")
36
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
712 {
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
713 model->translate = vec;
36
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
714 model->translateSet = true;
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
715 }
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
716 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
717 if (key == "rotate")
36
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
718 {
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
719 model->rotate = vec;
36
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
720 model->rotateSet = true;
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
721 }
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
722 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
723 if (key == "scale")
36
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
724 {
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
725 model->scale = vec;
36
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
726 model->scaleSet = true;
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
727 }
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
728 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
729 else
32
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
730 if (info.state == 1 && key == "specular")
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
731 {
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
732 DMVector4 val;
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
733 val.p.w = 1.0f;
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
734
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
735 if (!dmParseVector(info, tokens, 1, val))
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
736 return false;
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
737
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
738 model->specular = val;
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
739 }
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
740 else
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
741 if (info.state == 1 && key == "shininess")
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
742 {
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
743 if (tokens.size() != 2)
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
744 {
33
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
745 return dmSyntaxError(info,
32
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
746 "Expected argument for shininess");
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
747 }
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
748
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
749 model->shininess = std::stoi(tokens[1], 0, 0);
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
750 }
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
751 else
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
752 if (key == "light")
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
753 {
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
754 DMLight newlight;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
755
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
756 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
757 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
758 return dmTextError(info,
32
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
759 "Too many lights defined (max 4)");
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
760 }
32
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
761
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
762 lights.push_back(newlight);
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
763 light = &lights.back();
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
764 ppos = &light->position;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
765 ppointAt = &light->pointAt;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
766 info.state = 2;
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 == 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
770 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
771 DMVector4 val;
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
772 val.p.w = 1.0f;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
773
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
774 if (!dmParseVector(info, tokens, 1, val))
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
775 return false;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
776
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
777 if (key == "ambient")
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
778 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
779 else
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
780 if (key == "diffuse")
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
781 light->diffuse = val;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
782 else
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
783 if (key == "specular")
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
784 light->specular = val;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
785 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
786 else
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
787 if (key == "camera")
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
788 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
789 info.state = 3;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
790
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
791 ppos = &camera.position;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
792 ppointAt = &camera.pointAt;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
793 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
794 else
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
795 if ((info.state == 3 || info.state == 2) &&
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
796 (key == "position" || key == "pos" || key == "point_at"))
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
797 {
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
798 DMVector4 vec;
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
799 vec.p.w = 0;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
800
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
801 if (!dmParseVector(info, tokens, 1, vec))
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
802 return false;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
803
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
804 if (key == "position" || key == "pos")
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
805 *ppos = vec;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
806 else
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
807 if (key == "point_at")
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
808 *ppointAt = vec;
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
809 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
810 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
811 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
812 return dmSyntaxError(info,
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
813 "Unexpected key '"+ key +"'");
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
814 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
815 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
816
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
817 return true;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
818 }