Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Philip Trettner
polymesh
Commits
3499cd38
Commit
3499cd38
authored
Jul 04, 2018
by
Philip Trettner
Browse files
off import/export
parent
c8c4f882
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/polymesh/formats/off.cc
0 → 100644
View file @
3499cd38
#include "off.hh"
#include <fstream>
#include <sstream>
namespace
polymesh
{
void
write_off
(
const
std
::
string
&
filename
,
const
Mesh
&
mesh
,
const
vertex_attribute
<
glm
::
vec3
>
&
position
)
{
std
::
ofstream
file
(
filename
);
write_off
(
file
,
mesh
,
position
);
}
void
write_off
(
std
::
ostream
&
out
,
const
Mesh
&
mesh
,
const
vertex_attribute
<
glm
::
vec3
>
&
position
)
{
out
<<
"OFF
\n
"
;
out
<<
mesh
.
vertices
().
size
()
<<
" "
<<
mesh
.
faces
().
size
()
<<
" "
<<
mesh
.
edges
().
size
()
<<
"
\n
"
;
for
(
auto
v
:
mesh
.
all_vertices
())
{
auto
pos
=
v
[
position
];
out
<<
pos
.
x
<<
" "
<<
pos
.
y
<<
" "
<<
pos
.
z
<<
"
\n
"
;
}
for
(
auto
f
:
mesh
.
faces
())
{
out
<<
f
.
vertices
().
size
();
for
(
auto
v
:
f
.
vertices
())
out
<<
" "
<<
v
.
idx
.
value
;
out
<<
"
\n
"
;
}
}
bool
read_off
(
const
std
::
string
&
filename
,
Mesh
&
mesh
,
vertex_attribute
<
glm
::
vec3
>
&
position
)
{
std
::
ifstream
file
(
filename
);
if
(
!
file
.
good
())
return
false
;
return
read_off
(
file
,
mesh
,
position
);
}
bool
read_off
(
std
::
istream
&
input
,
Mesh
&
mesh
,
vertex_attribute
<
glm
::
vec3
>
&
position
)
{
std
::
string
str
;
input
>>
str
;
if
(
str
!=
"OFF"
)
return
false
;
// read counts
int
v_cnt
,
f_cnt
,
e_cnt
;
input
>>
v_cnt
>>
f_cnt
>>
e_cnt
;
(
void
)
e_cnt
;
// unused
// read vertices
for
(
auto
i
=
0
;
i
<
v_cnt
;
++
i
)
{
auto
v
=
mesh
.
vertices
().
add
();
auto
&
pos
=
v
[
position
];
input
>>
pos
.
x
>>
pos
.
y
>>
pos
.
z
;
}
// read faces
std
::
vector
<
vertex_handle
>
vs
;
for
(
auto
i
=
0
;
i
<
f_cnt
;
++
i
)
{
int
valence
;
input
>>
valence
;
vs
.
resize
(
valence
);
for
(
auto
vi
=
0
;
vi
<
valence
;
++
vi
)
{
int
v
;
input
>>
v
;
vs
[
vi
]
=
mesh
[
vertex_index
(
v
)];
}
mesh
.
faces
().
add
(
vs
);
}
return
true
;
}
}
src/polymesh/formats/off.hh
0 → 100644
View file @
3499cd38
#pragma once
#include <glm/glm.hpp>
#include <iostream>
#include <string>
#include "../Mesh.hh"
namespace
polymesh
{
void
write_off
(
std
::
string
const
&
filename
,
Mesh
const
&
mesh
,
vertex_attribute
<
glm
::
vec3
>
const
&
position
);
void
write_off
(
std
::
ostream
&
out
,
Mesh
const
&
mesh
,
vertex_attribute
<
glm
::
vec3
>
const
&
position
);
bool
read_off
(
std
::
string
const
&
filename
,
Mesh
&
mesh
,
vertex_attribute
<
glm
::
vec3
>&
position
);
bool
read_off
(
std
::
istream
&
input
,
Mesh
&
mesh
,
vertex_attribute
<
glm
::
vec3
>&
position
);
}
Write
Preview
Supports
Markdown
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