Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenMesh
OpenMesh
Commits
782adb7b
Commit
782adb7b
authored
Oct 01, 2016
by
Max Limper
Browse files
fixed handling of negative indices in OBJ loader
parent
8b7be54e
Pipeline
#2975
passed with stage
in 32 minutes and 9 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/OpenMesh/Core/IO/reader/OBJReader.cc
View file @
782adb7b
...
...
@@ -443,6 +443,10 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
_in
.
clear
();
_in
.
seekg
(
0
,
std
::
ios
::
beg
);
int
nCurrentPositions
=
0
,
nCurrentTexcoords
=
0
,
nCurrentNormals
=
0
;
// pass 2: read vertices
while
(
_in
&&
!
_in
.
eof
()
)
{
...
...
@@ -512,6 +516,21 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
matname
=
""
;
}
}
// track current number of parsed vertex attributes,
// to allow for OBJs negative indices
else
if
(
keyWrd
==
"v"
)
{
++
nCurrentPositions
;
}
else
if
(
keyWrd
==
"vt"
)
{
++
nCurrentTexcoords
;
}
else
if
(
keyWrd
==
"vn"
)
{
++
nCurrentNormals
;
}
// faces
else
if
(
keyWrd
==
"f"
)
...
...
@@ -592,7 +611,7 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
// Calculation of index :
// -1 is the last vertex in the list
// As obj counts from 1 and not zero add +1
value
=
int
(
_bi
.
n_vertices
()
+
value
+
1
)
;
value
=
nCurrentPositions
+
value
+
1
;
}
// Obj counts from 1 and not zero .. array counts from zero therefore -1
vhandles
.
push_back
(
VertexHandle
(
value
-
1
));
...
...
@@ -606,7 +625,7 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
// Calculation of index :
// -1 is the last vertex in the list
// As obj counts from 1 and not zero add +1
value
=
int
(
texcoords
.
size
())
+
value
+
1
;
value
=
nCurrentTexcoords
+
value
+
1
;
}
assert
(
!
vhandles
.
empty
());
...
...
@@ -643,7 +662,7 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
// Calculation of index :
// -1 is the last vertex in the list
// As obj counts from 1 and not zero add +1
value
=
int
(
normals
.
size
())
+
value
+
1
;
value
=
nCurrentNormals
+
value
+
1
;
}
// Obj counts from 1 and not zero .. array counts from zero therefore -1
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment