Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lava-vr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lava
lava-vr
Commits
be910b5d
Commit
be910b5d
authored
6 years ago
by
Christian Mattes
Browse files
Options
Downloads
Patches
Plain Diff
Added VRMesh loading from obj-files
parent
942ef177
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/lava-vr/VRMesh.cc
+77
-0
77 additions, 0 deletions
src/lava-vr/VRMesh.cc
src/lava-vr/VRMesh.hh
+1
-0
1 addition, 0 deletions
src/lava-vr/VRMesh.hh
src/lava-vr/VRMeshRenderer.cc
+3
-1
3 additions, 1 deletion
src/lava-vr/VRMeshRenderer.cc
with
81 additions
and
1 deletion
src/lava-vr/VRMesh.cc
+
77
−
0
View file @
be910b5d
...
...
@@ -3,6 +3,14 @@
#include
<iostream>
#include
<zlib.h>
#include
<assimp/Importer.hpp>
#include
<assimp/mesh.h>
#include
<assimp/postprocess.h>
#include
<assimp/scene.h>
#include
<assimp/vector3.h>
#include
<lodepng/lodepng.h>
namespace
lava
{
namespace
vr
{
...
...
@@ -122,5 +130,74 @@ VRMesh VRMesh::readFromFile(const std::string &filename) {
return
result
;
}
VRMesh
VRMesh
::
readFromObj
(
const
std
::
string
&
objfile
,
const
std
::
string
&
texture
)
{
VRMesh
result
;
Assimp
::
Importer
importer
;
const
aiScene
*
importScene
=
importer
.
ReadFile
(
objfile
,
AI_SCENE_FLAGS_NON_VERBOSE_FORMAT
|
aiProcess_JoinIdenticalVertices
);
if
(
importScene
==
NULL
)
{
std
::
cout
<<
"VRMesh::readFromObj(...): no scene loaded."
<<
std
::
endl
<<
"Perhaps invalid filepath given? Filepath is:"
<<
std
::
endl
<<
objfile
<<
std
::
endl
;
assert
(
0
);
}
if
(
importScene
->
HasMeshes
())
{
aiMesh
*
theMesh
=
importScene
->
mMeshes
[
0
];
auto
uv
=
theMesh
->
mTextureCoords
[
0
];
for
(
unsigned
int
i
=
0
;
i
<
theMesh
->
mNumVertices
;
++
i
)
{
Vertex
v
;
v
.
position
.
x
=
theMesh
->
mVertices
[
i
].
x
;
v
.
position
.
y
=
theMesh
->
mVertices
[
i
].
y
;
v
.
position
.
z
=
theMesh
->
mVertices
[
i
].
z
;
if
(
uv
)
{
v
.
texCoord
.
x
=
uv
[
i
].
x
;
v
.
texCoord
.
y
=
1.0
-
uv
[
i
].
y
;
}
v
.
layer
=
0.0
f
;
result
.
vertices
.
push_back
(
v
);
}
for
(
unsigned
int
i_f
=
0
;
i_f
<
theMesh
->
mNumFaces
;
++
i_f
)
{
assert
(
theMesh
->
mFaces
[
i_f
].
mNumIndices
==
3
&&
"Only triangles for now please"
);
for
(
unsigned
int
i_i
=
0
;
i_i
<
3
;
++
i_i
)
{
uint32_t
currentVertexIndex
=
(
uint32_t
)
theMesh
->
mFaces
[
i_f
].
mIndices
[
i_i
];
result
.
indices
.
push_back
(
currentVertexIndex
);
}
}
if
(
!
texture
.
empty
())
{
result
.
colorTexture
.
meta
.
depth
=
1
;
result
.
colorTexture
.
meta
.
mipLayers
=
1
;
result
.
colorTexture
.
meta
.
bytes_per_pixel
=
4
;
lodepng
::
decode
(
result
.
colorTexture
.
data
,
result
.
colorTexture
.
meta
.
width
,
result
.
colorTexture
.
meta
.
height
,
texture
,
LCT_RGBA
);
}
else
{
result
.
colorTexture
.
meta
.
width
=
1
;
result
.
colorTexture
.
meta
.
height
=
1
;
result
.
colorTexture
.
meta
.
depth
=
1
;
result
.
colorTexture
.
meta
.
mipLayers
=
1
;
result
.
colorTexture
.
meta
.
bytes_per_pixel
=
4
;
result
.
colorTexture
.
data
=
{
0xff
,
0xff
,
0xff
,
0xff
};
}
}
else
{
std
::
cout
<<
"Loading VRMesh from .obj-file failed (no mesh could be loaded)."
<<
std
::
endl
;
assert
(
0
);
}
return
result
;
}
}
// namespace vr
}
// namespace lava
This diff is collapsed.
Click to expand it.
src/lava-vr/VRMesh.hh
+
1
−
0
View file @
be910b5d
...
...
@@ -50,6 +50,7 @@ struct VRMesh {
#endif
static
VRMesh
readFromFile
(
const
std
::
string
&
filename
);
static
VRMesh
readFromObj
(
const
std
::
string
&
objfile
,
const
std
::
string
&
texture
=
""
);
struct
OffsetHelper
{
size_t
width
,
height
,
depth
,
bytes_per_pixel
,
mip_layers
;
...
...
This diff is collapsed.
Click to expand it.
src/lava-vr/VRMeshRenderer.cc
+
3
−
1
View file @
be910b5d
...
...
@@ -98,7 +98,9 @@ void VRMeshRenderer::upload(const VRMesh &mesh) {
auto
meta
=
mesh
.
colorTexture
.
meta
;
mTexture
=
lava
::
texture2DArray
(
meta
.
width
,
meta
.
height
,
meta
.
depth
,
vk
::
Format
::
eBc7SrgbBlock
)
meta
.
bytes_per_pixel
==
1
?
vk
::
Format
::
eBc7SrgbBlock
:
vk
::
Format
::
eR8G8B8A8Srgb
)
.
setMipLevels
(
meta
.
mipLayers
)
.
create
(
device
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment