【问题标题】:Reading obj files! (Indices)读取 obj 文件! (指数)
【发布时间】:2020-10-07 15:51:47
【问题描述】:

我想要做的是读取面孔(f),但他们有我不知道如何删除的“/”?基本上我想要的是获取存储在临时变量中的面孔编号。我不知道如何在 c++ fstream 中做到这一点。

std::string text;
    std::istringstream iss(line);

    iss >> text;

    // Easy part!
    if (text == "v")
    {
        glm::vec3 currectPos;

        iss >> currectPos.x;
        iss >> currectPos.y;
        iss >> currectPos.z;

        filePos.push_back(currectPos);
    }
    if (text == "vt")
    {
        glm::vec2 currectUV;

        iss >> currectUV.x;
        iss >> currectUV.y;

        fileUV.push_back(currectUV);
    }
    if (text == "vn")
    {
        glm::vec3 currectNorm;

        iss >> currectNorm.x;
        iss >> currectNorm.y;
        iss >> currectNorm.z;

        fileNorm.push_back(currectNorm);
    }


    // Last part, hard part!
    if (text == "f")
    {
        // Face!!! :O
        // This one here I am having trouble with
        // How do I read it?
    }

v -1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
vt 0.625000 0.000000
vt 0.375000 0.250000
vt 0.375000 0.000000
vt 0.625000 0.250000
vt 0.375000 0.500000
vt 0.625000 0.500000
vt 0.375000 0.750000
vt 0.625000 0.750000
vt 0.375000 1.000000
vt 0.125000 0.750000
vt 0.125000 0.500000
vt 0.875000 0.500000
vt 0.625000 1.000000
vt 0.875000 0.750000
vn -1.0000 0.0000 0.0000
vn 0.0000 0.0000 -1.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 1.0000
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
f 2/1/1 3/2/1 1/3/1
f 4/4/2 7/5/2 3/2/2
f 8/6/3 5/7/3 7/5/3
f 6/8/4 1/9/4 5/7/4
f 7/5/5 1/10/5 3/11/5
f 4/12/6 6/8/6 8/6/6
f 2/1/1 4/4/1 3/2/1
f 4/4/2 8/6/2 7/5/2
f 8/6/3 6/8/3 5/7/3
f 6/8/4 2/13/4 1/9/4
f 7/5/5 5/7/5 1/10/5
f 4/12/6 2/14/6 6/8/6

【问题讨论】:

  • 能否详细说明您的问题?
  • 问题是怎么读“f 4/4/2”?
  • 哎呀……对不起! 2s
  • 是的!对不起!我不知何故忘记了我的推理。
  • 您使用哪个编译器生成“.obj”文件?

标签: c++ iostream stringstream glm-math wavefront


【解决方案1】:
int i, j, k;
char c;
iss >> i;
iss >> c; // remove the /
iss >> j;
iss >> c; // remove the next /
iss >> k;

将 i,j,k 存储在某处等等,然后根据需要重复多次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-18
    • 2013-10-14
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    • 2018-09-05
    • 1970-01-01
    • 2013-05-14
    相关资源
    最近更新 更多