| 2078 | } |
| 2079 | |
| 2080 | void LoadMtl(std::map<std::string, int> *material_map, |
| 2081 | std::vector<material_t> *materials, std::istream *inStream, |
| 2082 | std::string *warning, std::string *err) { |
| 2083 | (void)err; |
| 2084 | |
| 2085 | // Create a default material anyway. |
| 2086 | material_t material; |
| 2087 | InitMaterial(&material); |
| 2088 | |
| 2089 | // Issue 43. `d` wins against `Tr` since `Tr` is not in the MTL specification. |
| 2090 | bool has_d = false; |
| 2091 | bool has_tr = false; |
| 2092 | |
| 2093 | // has_kd is used to set a default diffuse value when map_Kd is present |
| 2094 | // and Kd is not. |
| 2095 | bool has_kd = false; |
| 2096 | |
| 2097 | std::stringstream warn_ss; |
| 2098 | |
| 2099 | size_t line_no = 0; |
| 2100 | std::string linebuf; |
| 2101 | while (inStream->peek() != -1) { |
| 2102 | safeGetline(*inStream, linebuf); |
| 2103 | line_no++; |
| 2104 | |
| 2105 | // Trim trailing whitespace. |
| 2106 | if (linebuf.size() > 0) { |
| 2107 | linebuf = linebuf.substr(0, linebuf.find_last_not_of(" \t") + 1); |
| 2108 | } |
| 2109 | |
| 2110 | // Trim newline '\r\n' or '\n' |
| 2111 | if (linebuf.size() > 0) { |
| 2112 | if (linebuf[linebuf.size() - 1] == '\n') |
| 2113 | linebuf.erase(linebuf.size() - 1); |
| 2114 | } |
| 2115 | if (linebuf.size() > 0) { |
| 2116 | if (linebuf[linebuf.size() - 1] == '\r') |
| 2117 | linebuf.erase(linebuf.size() - 1); |
| 2118 | } |
| 2119 | |
| 2120 | // Skip if empty line. |
| 2121 | if (linebuf.empty()) { |
| 2122 | continue; |
| 2123 | } |
| 2124 | if (line_no == 1) { |
| 2125 | linebuf = removeUtf8Bom(linebuf); |
| 2126 | } |
| 2127 | |
| 2128 | // Skip leading space. |
| 2129 | const char *token = linebuf.c_str(); |
| 2130 | token += strspn(token, " \t"); |
| 2131 | |
| 2132 | assert(token); |
| 2133 | if (token[0] == '\0') continue; // empty line |
| 2134 | |
| 2135 | if (token[0] == '#') continue; // comment line |
| 2136 | |
| 2137 | // new mtl |
no test coverage detected