Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing lines in Wavefront OBJ import #197

Open
pa-hobe opened this issue Jun 23, 2022 · 0 comments
Open

Missing lines in Wavefront OBJ import #197

pa-hobe opened this issue Jun 23, 2022 · 0 comments

Comments

@pa-hobe
Copy link

pa-hobe commented Jun 23, 2022

When importing a .obj file, only the first line element of a polyline is imported, the other line elements are ignored.
The line header l denotes a polyline, see https://en.wikipedia.org/wiki/Wavefront_.obj_file#Line_elements.
For example,

l 1 2 3 4

is equivalent to

l 1 2
l 2 3
l 3 4

The lines (2, 3) and (3, 4) of l 1 2 3 4 are ignored.

The parsing code is in wrap/io_trimesh/import_obj.h:

[...]
else if ( header.compare("l")==0 )
{
  loadingStr = "Edge Loading";
  
  if (numTokens < 3)
  {
    result = E_LESS_THAN_3_VERT_IN_FACE; // TODO add proper/handling error code
    continue;
  }
  
  ObjEdge e = { (atoi(tokens[1].c_str()) - 1),
                (atoi(tokens[2].c_str()) - 1) };
  ev.push_back(e);
  
  numEdges++;
}
[...]

I suggest adding a loop to get the other line elements:

[...]
else if ( header.compare("l")==0 )
{
  loadingStr = "Edge Loading";
  
  if (numTokens < 3)
  {
    result = E_LESS_THAN_3_VERT_IN_FACE; // TODO add proper/handling error code
    continue;
  }

  for (int i = 2; i < numTokens; i++)
  {      
    ObjEdge e = { (atoi(tokens[i -1].c_str()) - 1),
                  (atoi(tokens[i].c_str()) - 1) };
    ev.push_back(e);
  
    numEdges++;
  }
}
[...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant