Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
OpenWalnut Core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
44
Issues
44
List
Boards
Labels
Service Desk
Milestones
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
7e6965f1
Commit
7e6965f1
authored
Mar 06, 2015
by
Sebastian Eichelbaum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FIX] OBJ reader now supports colors as attributes too.
parent
8f3f658e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
1 deletion
+16
-1
src/modules/readMesh/WMeshReaderOBJ.cpp
src/modules/readMesh/WMeshReaderOBJ.cpp
+16
-1
No files found.
src/modules/readMesh/WMeshReaderOBJ.cpp
View file @
7e6965f1
...
...
@@ -68,6 +68,7 @@ WTriangleMesh::SPtr WMeshReaderOBJ::operator()( WProgressCombiner::SPtr parentPr
static
const
boost
::
regex
faceVNRegex
(
"^ *[f,F] *([0-9]+)//([0-9]+) +([0-9]+)//([0-9]+) +([0-9]+)//([0-9]+).*$"
);
static
const
boost
::
regex
vertexRegex
(
"^ *[v,V][^n] *(-?[0-9]*
\\
.?[0-9]*) +(-?[0-9]*
\\
.?[0-9]*) +(-?[0-9]*
\\
.?[0-9]*).*$"
);
static
const
boost
::
regex
vertexColorRegex
(
"^ *[v,V][^n] *(-?[0-9]*
\\
.?[0-9]*) +(-?[0-9]*
\\
.?[0-9]*) +(-?[0-9]*
\\
.?[0-9]*) (-?[0-9]*
\\
.?[0-9]*) +(-?[0-9]*
\\
.?[0-9]*) +(-?[0-9]*
\\
.?[0-9]*).*$"
);
// NOLINT
static
const
boost
::
regex
normalRegex
(
"^ *[v,V][n,N] *(-?[0-9]*
\\
.?[0-9]*) +(-?[0-9]*
\\
.?[0-9]*) +(-?[0-9]*
\\
.?[0-9]*).*$"
);
static
const
boost
::
regex
commentRegex
(
"^ *#.*$"
);
// please note that there are several more possible definitions ... Please see http://en.wikipedia.org/wiki/Wavefront_.obj_file
...
...
@@ -77,6 +78,7 @@ WTriangleMesh::SPtr WMeshReaderOBJ::operator()( WProgressCombiner::SPtr parentPr
std
::
string
line
=
""
;
std
::
vector
<
float
>
vertices
;
std
::
vector
<
float
>
colors
;
std
::
vector
<
size_t
>
faces
;
std
::
vector
<
size_t
>
normals
;
...
...
@@ -100,7 +102,16 @@ WTriangleMesh::SPtr WMeshReaderOBJ::operator()( WProgressCombiner::SPtr parentPr
boost
::
smatch
matches
;
// the list of matches
// check whether this is a vertex definition
if
(
boost
::
regex_match
(
line
,
matches
,
vertexRegex
)
)
if
(
boost
::
regex_match
(
line
,
matches
,
vertexColorRegex
)
)
{
vertices
.
push_back
(
string_utils
::
fromString
<
float
>
(
matches
[
1
]
)
);
vertices
.
push_back
(
string_utils
::
fromString
<
float
>
(
matches
[
2
]
)
);
vertices
.
push_back
(
string_utils
::
fromString
<
float
>
(
matches
[
3
]
)
);
colors
.
push_back
(
string_utils
::
fromString
<
float
>
(
matches
[
4
]
)
);
colors
.
push_back
(
string_utils
::
fromString
<
float
>
(
matches
[
5
]
)
);
colors
.
push_back
(
string_utils
::
fromString
<
float
>
(
matches
[
6
]
)
);
}
else
if
(
boost
::
regex_match
(
line
,
matches
,
vertexRegex
)
)
{
vertices
.
push_back
(
string_utils
::
fromString
<
float
>
(
matches
[
1
]
)
);
vertices
.
push_back
(
string_utils
::
fromString
<
float
>
(
matches
[
2
]
)
);
...
...
@@ -180,6 +191,10 @@ WTriangleMesh::SPtr WMeshReaderOBJ::operator()( WProgressCombiner::SPtr parentPr
{
triMesh
->
setVertexNormal
(
i
/
3
,
normals
[
i
+
0
],
normals
[
i
+
1
],
normals
[
i
+
2
]
);
}
for
(
size_t
i
=
0
;
i
<
colors
.
size
();
i
+=
3
)
{
triMesh
->
setVertexColor
(
i
/
3
,
osg
::
Vec4
(
colors
[
i
+
0
],
colors
[
i
+
1
],
colors
[
i
+
2
],
1.0
)
);
}
// done.
progress
->
finish
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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