MCPcopy Create free account
hub / github.com/axmolengine/axmol / LoadMtl

Function LoadMtl

core/3d/ObjLoader.cpp:460–681  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

458}
459
460std::string LoadMtl(hlookup::string_map<int>& material_map,
461 std::vector<material_t>& materials,
462 std::istream& inStream)
463{
464 std::stringstream err;
465
466 // Create a default material anyway.
467 material_t material;
468 InitMaterial(material);
469
470 int maxchars = 8192; // Alloc enough size.
471 std::vector<char> buf(maxchars); // Alloc enough size.
472 while (inStream.peek() != -1)
473 {
474 inStream.getline(&buf[0], maxchars);
475
476 std::string linebuf(&buf[0]);
477
478 // Trim newline '\r\n' or '\n'
479 if (!linebuf.empty())
480 {
481 if (linebuf[linebuf.size() - 1] == '\n')
482 linebuf.erase(linebuf.size() - 1);
483 }
484 if (!linebuf.empty())
485 {
486 if (linebuf[linebuf.size() - 1] == '\r')
487 linebuf.erase(linebuf.size() - 1);
488 }
489
490 // Skip if empty line.
491 if (linebuf.empty())
492 {
493 continue;
494 }
495
496 // Skip leading space.
497 const char* token = linebuf.c_str();
498 token += strspn(token, " \t");
499
500 assert(token);
501 if (token[0] == '\0')
502 continue; // empty line
503
504 if (token[0] == '#')
505 continue; // comment line
506
507 // new mtl
508 if ((0 == strncmp(token, "newmtl", 6)) && isSpace((token[6])))
509 {
510 // flush previous material.
511 if (!material.name.empty())
512 {
513 material_map.emplace(material.name, static_cast<int>(materials.size()));
514 materials.emplace_back(material);
515 }
516
517 // initial temporary material

Callers 1

operator()Method · 0.85

Calls 15

InitMaterialFunction · 0.85
isSpaceFunction · 0.85
nextWordFunction · 0.85
parseFloat3Function · 0.85
parseFloatFunction · 0.85
parseIntFunction · 0.85
peekMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
eraseMethod · 0.45
c_strMethod · 0.45
emplaceMethod · 0.45

Tested by

no test coverage detected