mmp / pbrt-v3

Source code for pbrt, the renderer described in the third edition of "Physically Based Rendering: From Theory To Implementation", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.
http://pbrt.org
BSD 2-Clause "Simplified" License
4.89k stars 1.19k forks source link

obj2pbrt creates output with backslashes #279

Open trevordblack opened 4 years ago

trevordblack commented 4 years ago

On my Ubuntu Linux 18.04, when I run ob2pbrt on the sponza from Morgan McGuire's Computer Graphics Archive, the pbrt file that is created is filled with backslashes, e.g.

 Texture "leaf-kd-img" "color" "imagemap" "string filename" ["textures\sponza_thorn_diff.png"]

pbrt promptly complains:

sponza.pbrt:36:93: Error: unexpected escaped character "s"

It only shows up for Textures definitions in the created pbrt file.

I believe the error comes from obj2pbrt.cpp:874-928, e.g.

    // ambient texture     
    if ((0 == strncmp(token, "map_Ka", 6)) && IS_SPACE(token[6])) {
      token += 7;
      material.ambient_texname = token;
      continue;
    }

this is just copying the file locations directly out of the .mtl file:

newmtl leaf
    Ns 10.0000
    Ni 1.5000
    d 1.0000
    Tr 0.0000
    Tf 1.0000 1.0000 1.0000 
    illum 2
    Ka 1 1 1
    Kd 1 1 1
    Ks 0.0000 0.0000 0.0000
    Ke 0.0000 0.0000 0.0000
    map_Ka textures\sponza_thorn_diff.png
    map_Kd textures\sponza_thorn_diff.png
    map_d textures\sponza_thorn_mask.png
    map_bump textures\sponza_thorn_bump.png

You might want to sanitize for backslashes in file locations