32 _filename = Filename::text_filename(filename);
38 <<
"Unable to open input file " << _filename <<
"\n";
46 while (std::getline(input, line)) {
51 size_t comment = line.find(
'#');
52 while (comment != string::npos) {
53 if (comment == 0 || isspace(line[comment - 1])) {
54 line = line.substr(0, comment);
55 comment = string::npos;
58 comment = line.find(
'#', comment + 1);
64 if (!line.empty() && line[line.size() - 1] ==
'\\') {
66 complete_line += line.substr(0, line.size() - 1);
70 line =
trim(complete_line + line);
71 complete_line = string();
77 size_t colon = line.find(
": ");
78 if (colon == string::npos) {
80 << _filename <<
": line " << line_number
81 <<
" has no colon followed by whitespace.\n";
86 << _filename <<
": line " << line_number
87 <<
" has no nodes.\n";
93 vector_string names, params;
97 vector_string::const_iterator ni;
98 for (ni = names.begin(); ni != names.end(); ++ni) {
99 entry.add_node_name(*ni);
103 vector_string::iterator ci, cnext;
105 while (ci != params.end()) {
111 if (param[0] ==
'!' && param.size() > 1) {
113 param = param.substr(1);
115 if (tolower(param[0]) ==
'a' && param.size() > 1) {
116 switch (tolower(param[1])) {
118 entry._auto_place = !invert;
122 entry._auto_distribute = !invert;
128 << _filename <<
": line " << line_number
129 <<
" - invalid field " << param <<
"\n";
136 << _filename <<
": invalid parameters at line " 137 << line_number <<
".\n";
146 if (!params.empty()) {
148 if (cmp_nocase(params[0],
"omit")==0) {
151 }
else if (cmp_nocase(params[0],
"matchuu")==0) {
152 entry.set_match_uu();
153 if (params.size() > 1 && cmp_nocase(params[1],
"matchvv")==0) {
154 entry.set_match_vv();
157 }
else if (cmp_nocase(params[0],
"matchvv")==0) {
158 entry.set_match_vv();
159 if (params.size() > 1 && cmp_nocase(params[1],
"matchuu")==0) {
160 entry.set_match_uu();
163 }
else if (cmp_nocase(params[0],
"matchuv")==0) {
164 entry.set_match_uv();
165 if (params.size() > 1 && cmp_nocase(params[1],
"matchvu")==0) {
166 entry.set_match_vu();
169 }
else if (cmp_nocase(params[0],
"matchvu")==0) {
170 entry.set_match_vu();
171 if (params.size() > 1 && cmp_nocase(params[1],
"matchuv")==0) {
172 entry.set_match_uv();
175 }
else if (cmp_nocase(params[0],
"minu")==0) {
177 if (params.size() < 2) {
182 entry.set_min_u(value);
185 }
else if (cmp_nocase(params[0],
"minv")==0) {
187 if (params.size() < 2) {
192 entry.set_min_v(value);
195 }
else if (tolower(params[0][0]) ==
'i') {
199 entry.set_per_isoparam(value);
201 }
else if (params[0][params[0].length() - 1] ==
'%') {
203 okflag =
string_to_double(params[0].substr(0, params[0].length() - 1), value);
204 entry.set_importance(value / 100.0);
206 }
else if (params.size() == 1) {
210 entry.set_num_tris(value);
212 }
else if (params.size() >= 2) {
217 entry.set_uv(u, v, ¶ms[2], params.size() - 2);
225 << _filename <<
": invalid parameters at line " 226 << line_number <<
".\n";
230 _entries.push_back(entry);
235 if (qtess_cat.is_info()) {
237 <<
"read qtess parameter file " << _filename <<
".\n";
238 if (qtess_cat.is_debug()) {
239 write(qtess_cat.debug(
false));
255 if (_entries.empty()) {
259 return _entries.back();
274 QtessInputEntry::Type type;
276 if (_entries.empty()) {
281 Entries::iterator ei;
282 for (ei = _entries.begin(); ei != _entries.end(); ++ei) {
283 type = (*ei).match(surface);
284 if (type != QtessInputEntry::T_undefined) {
288 return QtessInputEntry::T_undefined;
300 Entries::iterator ei;
301 for (ei = _entries.begin(); ei != _entries.end(); ++ei) {
302 total_tris += (*ei).count_tris();
310 void QtessInputFile::
311 write(std::ostream &out,
int indent_level)
const {
312 Entries::const_iterator ei;
313 for (ei = _entries.begin(); ei != _entries.end(); ++ei) {
314 (*ei).write(out, indent_level);
322 void QtessInputFile::
323 add_default_entry() {
326 _entries.push_back(entry);
int string_to_int(const string &str, string &tail)
A string-interface wrapper around the C library strtol().
A reference to an EggNurbsSurface in the egg file, and its parameters as set by the user input file a...
double string_to_double(const string &str, string &tail)
A string-interface wrapper around the C library strtol().
bool open_read(std::ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int extract_words(const string &str, vector_string &words)
Divides the string into a number of words according to whitespace.
The name of a file, such as a texture file or an Egg file.
Stores one entry in the qtess input file.
string trim(const string &str)
Returns a new string representing the contents of the given string with both leading and trailing whi...
string trim_right(const string &str)
Returns a new string representing the contents of the given string with the trailing whitespace remov...