* @private
(mtlPath)
| 482 | * @private |
| 483 | */ |
| 484 | async function parseMtl(mtlPath) { |
| 485 | let currentMaterial = null; |
| 486 | let materials = {}; |
| 487 | |
| 488 | const { data } = await request(mtlPath, 'text'); |
| 489 | const lines = data.split('\n'); |
| 490 | |
| 491 | for (let line = 0; line < lines.length; ++line) { |
| 492 | const tokens = lines[line].trim().split(/\s+/); |
| 493 | if (tokens[0] === 'newmtl') { |
| 494 | const materialName = tokens[1]; |
| 495 | currentMaterial = materialName; |
| 496 | materials[currentMaterial] = {}; |
| 497 | } else if (tokens[0] === 'Kd') { |
| 498 | //Diffuse color |
| 499 | materials[currentMaterial].diffuseColor = [ |
| 500 | parseFloat(tokens[1]), |
| 501 | parseFloat(tokens[2]), |
| 502 | parseFloat(tokens[3]) |
| 503 | ]; |
| 504 | } else if (tokens[0] === 'Ka') { |
| 505 | //Ambient Color |
| 506 | materials[currentMaterial].ambientColor = [ |
| 507 | parseFloat(tokens[1]), |
| 508 | parseFloat(tokens[2]), |
| 509 | parseFloat(tokens[3]) |
| 510 | ]; |
| 511 | } else if (tokens[0] === 'Ks') { |
| 512 | //Specular color |
| 513 | materials[currentMaterial].specularColor = [ |
| 514 | parseFloat(tokens[1]), |
| 515 | parseFloat(tokens[2]), |
| 516 | parseFloat(tokens[3]) |
| 517 | ]; |
| 518 | |
| 519 | } else if (tokens[0] === 'map_Kd') { |
| 520 | //Texture path |
| 521 | materials[currentMaterial].texturePath = tokens[1]; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | return materials; |
| 526 | } |
| 527 | |
| 528 | /** |
| 529 | * @private |
no test coverage detected