| 144 | } |
| 145 | |
| 146 | void ObjLoader::parseMaterial( std::shared_ptr<IStreamCinder> material ) |
| 147 | { |
| 148 | Material m; |
| 149 | m.Ka[0] = m.Ka[1] = m.Ka[2] = 1.0f; |
| 150 | m.Kd[0] = m.Kd[1] = m.Kd[2] = 1.0f; |
| 151 | |
| 152 | while( ! material->isEof() ) { |
| 153 | string line = material->readLine(); |
| 154 | if( line.empty() || line[0] == '#' ) |
| 155 | continue; |
| 156 | |
| 157 | while( line.back() == '\\' && ! material->isEof() ) { |
| 158 | auto next = material->readLine(); |
| 159 | line = line.substr( 0, line.size() - 1 ) + next; |
| 160 | } |
| 161 | |
| 162 | string tag; |
| 163 | stringstream ss( line ); |
| 164 | ss >> tag; |
| 165 | if( tag == "newmtl" ) { |
| 166 | if( m.mName.length() > 0 ) |
| 167 | mMaterials[m.mName] = m; |
| 168 | |
| 169 | ss >> m.mName; |
| 170 | m.Ka[0] = m.Ka[1] = m.Ka[2] = 1.0f; |
| 171 | m.Kd[0] = m.Kd[1] = m.Kd[2] = 1.0f; |
| 172 | } |
| 173 | else if( tag == "Ka" ) { |
| 174 | ss >> m.Ka[0] >> m.Ka[1] >> m.Ka[2]; |
| 175 | } |
| 176 | else if( tag == "Kd" ) { |
| 177 | ss >> m.Kd[0] >> m.Kd[1] >> m.Kd[2]; |
| 178 | } |
| 179 | } |
| 180 | if( m.mName.length() > 0 ) |
| 181 | mMaterials[m.mName] = m; |
| 182 | } |
| 183 | |
| 184 | void ObjLoader::parse( bool includeNormals, bool includeTexCoords ) |
| 185 | { |