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
Philip Trettner
polymesh
Commits
ed5b7f68
Commit
ed5b7f68
authored
Jul 25, 2018
by
Christian Mattes
Browse files
Added automatic registration of some common attribute types
parent
f5edacbc
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/polymesh/formats/pm.cc
View file @
ed5b7f68
#include
"pm.hh"
#include
<fstream>
#include
<glm/glm.hpp>
#include
<iostream>
#include
<mutex>
#include
<typeindex>
...
...
@@ -195,4 +196,42 @@ bool read_pm(const std::string &filename, Mesh &mesh, attribute_collection &attr
std
::
ifstream
in
(
filename
,
std
::
ios
::
binary
);
return
read_pm
(
in
,
mesh
,
attributes
);
}
#define REGISTER_TYPE(type) register_type<type>(#type)
static
bool
registered_default_types
=
[]()
{
REGISTER_TYPE
(
float
);
REGISTER_TYPE
(
double
);
REGISTER_TYPE
(
int8_t
);
REGISTER_TYPE
(
int16_t
);
REGISTER_TYPE
(
int32_t
);
REGISTER_TYPE
(
int64_t
);
REGISTER_TYPE
(
uint8_t
);
REGISTER_TYPE
(
uint16_t
);
REGISTER_TYPE
(
uint32_t
);
REGISTER_TYPE
(
uint64_t
);
REGISTER_TYPE
(
glm
::
vec2
);
REGISTER_TYPE
(
glm
::
vec3
);
REGISTER_TYPE
(
glm
::
vec4
);
REGISTER_TYPE
(
glm
::
dvec2
);
REGISTER_TYPE
(
glm
::
dvec3
);
REGISTER_TYPE
(
glm
::
dvec4
);
REGISTER_TYPE
(
glm
::
ivec2
);
REGISTER_TYPE
(
glm
::
ivec3
);
REGISTER_TYPE
(
glm
::
ivec4
);
REGISTER_TYPE
(
glm
::
uvec2
);
REGISTER_TYPE
(
glm
::
uvec3
);
REGISTER_TYPE
(
glm
::
uvec4
);
REGISTER_TYPE
(
glm
::
mat2x2
);
REGISTER_TYPE
(
glm
::
mat2x3
);
REGISTER_TYPE
(
glm
::
mat2x4
);
REGISTER_TYPE
(
glm
::
mat3x2
);
REGISTER_TYPE
(
glm
::
mat3x3
);
REGISTER_TYPE
(
glm
::
mat3x4
);
REGISTER_TYPE
(
glm
::
mat4x2
);
REGISTER_TYPE
(
glm
::
mat4x3
);
REGISTER_TYPE
(
glm
::
mat4x4
);
register_type
<
std
::
string
>
(
"std::string"
,
detail
::
string_serdes
{});
return
true
;
}();
}
src/polymesh/formats/pm.hh
View file @
ed5b7f68
...
...
@@ -22,7 +22,10 @@ namespace detail
template
<
typename
T
>
struct
bytewise_serdes
{
void
serialize
(
std
::
ostream
&
out
,
T
const
*
data
,
size_t
num_items
)
const
{
out
.
write
(
reinterpret_cast
<
char
const
*>
(
data
),
num_items
*
sizeof
(
T
));
}
void
serialize
(
std
::
ostream
&
out
,
T
const
*
data
,
size_t
num_items
)
const
{
out
.
write
(
reinterpret_cast
<
char
const
*>
(
data
),
num_items
*
sizeof
(
T
));
}
void
deserialize
(
std
::
istream
&
in
,
T
*
data
,
size_t
num_items
)
const
{
in
.
read
(
reinterpret_cast
<
char
*>
(
data
),
num_items
*
sizeof
(
T
));
}
};
...
...
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