Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
GameDevWeek
Dependencies
Cpp
Mesh Converter
Commits
5b137086
Commit
5b137086
authored
Sep 20, 2015
by
Georg Schaefer
Browse files
fix some bugs
parent
c24d4f02
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/mesh_converter.hpp
View file @
5b137086
...
...
@@ -7,6 +7,8 @@
#include
<glm/glm.hpp>
namespace
gdw
{
#pragma pack(push)
#pragma pack(1)
struct
header
{
const
uint32_t
magic
=
0x4D574447
;
uint64_t
vertex_count
=
0
;
...
...
@@ -29,6 +31,7 @@ namespace gdw {
uint64_t
normal
=
0
;
uint64_t
material
=
0
;
};
#pragma pack(pop)
struct
mesh
{
std
::
vector
<
vertex
>
vertices
;
...
...
src/mesh_converter.cpp
View file @
5b137086
...
...
@@ -31,23 +31,28 @@ namespace gdw {
auto
&
indices
=
meshes
[
name
].
indices
;
submesh
s
;
s
.
offset
=
indices
.
size
();
auto
index_offset
=
vertices
.
size
();
for
(
auto
j
=
0
;
j
<
mesh
->
mNumFaces
;
++
j
)
{
auto
&
face
=
mesh
->
mFaces
[
j
];
for
(
auto
k
=
0
;
k
<
3
;
++
k
)
{
auto
position
=
mesh
->
mVertices
[
face
.
mIndices
[
k
]];
auto
texcoord
=
mesh
->
HasTextureCoords
(
0
)
?
mesh
->
mTextureCoords
[
0
][
face
.
mIndices
[
k
]]
:
aiVector3D
(
0.
f
);
auto
normal
=
mesh
->
mNormals
[
face
.
mIndices
[
k
]];
auto
tangent
=
mesh
->
HasTangentsAndBitangents
()
?
mesh
->
mTangents
[
face
.
mIndices
[
k
]]
:
aiVector3D
(
0.
f
);
auto
vertex
=
gdw
::
vertex
{
glm
::
vec3
(
position
.
x
,
position
.
y
,
position
.
z
),
glm
::
vec2
(
texcoord
.
x
,
texcoord
.
y
),
glm
::
vec3
(
normal
.
x
,
normal
.
y
,
normal
.
z
),
glm
::
vec3
(
tangent
.
x
,
tangent
.
y
,
tangent
.
z
)
};
vertices
.
emplace_back
(
vertex
);
indices
.
emplace_back
(
face
.
mIndices
[
k
]);
auto
real_index
=
index_offset
+
face
.
mIndices
[
k
];
auto
it
=
std
::
find
(
indices
.
begin
(),
indices
.
end
(),
real_index
);
if
(
it
==
indices
.
end
())
{
auto
position
=
mesh
->
mVertices
[
face
.
mIndices
[
k
]];
auto
texcoord
=
mesh
->
HasTextureCoords
(
0
)
?
mesh
->
mTextureCoords
[
0
][
face
.
mIndices
[
k
]]
:
aiVector3D
(
0.
f
);
auto
normal
=
mesh
->
mNormals
[
face
.
mIndices
[
k
]];
auto
tangent
=
mesh
->
HasTangentsAndBitangents
()
?
mesh
->
mTangents
[
face
.
mIndices
[
k
]]
:
aiVector3D
(
0.
f
);
auto
vertex
=
gdw
::
vertex
{
glm
::
vec3
(
position
.
x
,
position
.
z
,
-
position
.
y
),
glm
::
vec2
(
texcoord
.
x
,
texcoord
.
y
),
glm
::
vec3
(
normal
.
x
,
normal
.
z
,
-
normal
.
y
),
glm
::
vec3
(
tangent
.
x
,
tangent
.
z
,
-
tangent
.
y
)
};
vertices
.
emplace_back
(
vertex
);
}
indices
.
emplace_back
(
real_index
);
}
}
...
...
@@ -59,9 +64,11 @@ namespace gdw {
aiColor3D
color
(
0.
f
,
0.
f
,
0.
f
);
material
->
Get
(
AI_MATKEY_COLOR_DIFFUSE
,
color
);
s
.
color
=
glm
::
vec3
(
color
.
r
,
color
.
g
,
color
.
b
);
submeshes
.
emplace_back
(
s
);
}
for
(
auto
mesh
:
meshes
)
{
for
(
auto
&
mesh
:
meshes
)
{
header
h
;
h
.
vertex_count
=
mesh
.
second
.
vertices
.
size
();
h
.
index_count
=
mesh
.
second
.
indices
.
size
();
...
...
@@ -75,7 +82,7 @@ namespace gdw {
of
.
write
(
reinterpret_cast
<
char
*>
(
&
h
),
sizeof
(
header
));
of
.
write
(
reinterpret_cast
<
char
*>
(
mesh
.
second
.
vertices
.
data
()),
h
.
vertex_count
*
sizeof
(
vertex
));
of
.
write
(
reinterpret_cast
<
char
*>
(
mesh
.
second
.
indices
.
data
()),
h
.
index_count
*
sizeof
(
int
));
of
.
write
(
reinterpret_cast
<
char
*>
(
mesh
.
second
.
indices
.
data
()),
h
.
index_count
*
sizeof
(
u
int
32_t
));
of
.
write
(
reinterpret_cast
<
char
*>
(
mesh
.
second
.
submeshes
.
data
()),
h
.
submesh_count
*
sizeof
(
submesh
));
of
.
close
();
...
...
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