| 1924 | } |
| 1925 | |
| 1926 | void LoadMtl(std::map<std::string, int> *material_map, |
| 1927 | std::vector<material_t> *materials, std::istream *inStream, |
| 1928 | std::string *warning, std::string *err) { |
| 1929 | (void)err; |
| 1930 | |
| 1931 | // Create a default material anyway. |
| 1932 | material_t material; |
| 1933 | InitMaterial(&material); |
| 1934 | |
| 1935 | // Issue 43. `d` wins against `Tr` since `Tr` is not in the MTL specification. |
| 1936 | bool has_d = false; |
| 1937 | bool has_tr = false; |
| 1938 | |
| 1939 | // has_kd is used to set a default diffuse value when map_Kd is present |
| 1940 | // and Kd is not. |
| 1941 | bool has_kd = false; |
| 1942 | |
| 1943 | std::stringstream warn_ss; |
| 1944 | |
| 1945 | size_t line_no = 0; |
| 1946 | std::string linebuf; |
| 1947 | while (inStream->peek() != -1) { |
| 1948 | safeGetline(*inStream, linebuf); |
| 1949 | line_no++; |
| 1950 | |
| 1951 | // Trim trailing whitespace. |
| 1952 | if (linebuf.size() > 0) { |
| 1953 | linebuf = linebuf.substr(0, linebuf.find_last_not_of(" \t") + 1); |
| 1954 | } |
| 1955 | |
| 1956 | // Trim newline '\r\n' or '\n' |
| 1957 | if (linebuf.size() > 0) { |
| 1958 | if (linebuf[linebuf.size() - 1] == '\n') |
| 1959 | linebuf.erase(linebuf.size() - 1); |
| 1960 | } |
| 1961 | if (linebuf.size() > 0) { |
| 1962 | if (linebuf[linebuf.size() - 1] == '\r') |
| 1963 | linebuf.erase(linebuf.size() - 1); |
| 1964 | } |
| 1965 | |
| 1966 | // Skip if empty line. |
| 1967 | if (linebuf.empty()) { |
| 1968 | continue; |
| 1969 | } |
| 1970 | |
| 1971 | // Skip leading space. |
| 1972 | const char *token = linebuf.c_str(); |
| 1973 | token += strspn(token, " \t"); |
| 1974 | |
| 1975 | assert(token); |
| 1976 | if (token[0] == '\0') continue; // empty line |
| 1977 | |
| 1978 | if (token[0] == '#') continue; // comment line |
| 1979 | |
| 1980 | // new mtl |
| 1981 | if ((0 == strncmp(token, "newmtl", 6)) && IS_SPACE((token[6]))) { |
| 1982 | // flush previous material. |
| 1983 | if (!material.name.empty()) { |
no test coverage detected