Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vairdraw-src
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pirvi-public
vairdraw
vairdraw-src
Commits
3bd63464
Commit
3bd63464
authored
3 months ago
by
sdegrande
Browse files
Options
Downloads
Patches
Plain Diff
Fix computation of matrix transformations of hierarchical 3D models.
parent
b99354a1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Misc/Model3DImport.cpp
+2
-3
2 additions, 3 deletions
src/Misc/Model3DImport.cpp
src/SceneGraph/Misc/Model3D.cpp
+14
-6
14 additions, 6 deletions
src/SceneGraph/Misc/Model3D.cpp
src/SceneGraph/Misc/Model3D.hpp
+1
-1
1 addition, 1 deletion
src/SceneGraph/Misc/Model3D.hpp
with
17 additions
and
10 deletions
src/Misc/Model3DImport.cpp
+
2
−
3
View file @
3bd63464
...
...
@@ -47,9 +47,8 @@ const aiScene* Model3DImport::import(const std::string& modelName, const std::st
/* Remove lines and points - TODO: handle those primitives */
importer
.
SetPropertyInteger
(
AI_CONFIG_PP_SBP_REMOVE
,
aiPrimitiveType_LINE
|
aiPrimitiveType_POINT
);
readFlags
=
(
importProperties
.
pretransformVertices
)
?
aiProcess_PreTransformVertices
:
(
aiProcess_OptimizeGraph
|
aiProcess_OptimizeMeshes
);
// Nota: do not use aiProcess_OptimizeGraph, it produces a somehow buggy graph !
readFlags
=
(
importProperties
.
pretransformVertices
)
?
aiProcess_PreTransformVertices
:
aiProcess_OptimizeMeshes
;
readFlags
|=
aiProcess_Triangulate
|
aiProcess_SortByPType
|
aiProcess_RemoveComponent
;
if
(
importProperties
.
meshesSize
>
0
)
readFlags
|=
aiProcess_SplitLargeMeshes
;
...
...
This diff is collapsed.
Click to expand it.
src/SceneGraph/Misc/Model3D.cpp
+
14
−
6
View file @
3bd63464
...
...
@@ -15,6 +15,7 @@
#include
"Model3D.hpp"
#include
<glm/glm.hpp>
#include
<glm/ext.hpp>
#include
<glm/gtx/transform.hpp>
#include
<assimp/scene.h>
#include
<assimp/postprocess.h>
...
...
@@ -45,7 +46,7 @@ static inline glm::mat4 aiToGlmMatrix(const aiMatrix4x4& mat)
// Hierarchy functions
//=====================================================================
void
HierarchyContainer
::
loadNodeHierarchy
(
aiNode
*
importedNode
,
std
::
string
tab
)
void
HierarchyContainer
::
loadNodeHierarchy
(
aiNode
*
importedNode
)
{
setId
(
importedNode
->
mName
.
C_Str
());
setMatrix
(
aiToGlmMatrix
(
importedNode
->
mTransformation
));
...
...
@@ -57,7 +58,8 @@ void HierarchyContainer::loadNodeHierarchy(aiNode* importedNode, std::string tab
if
(
importedNode
->
mNumChildren
!=
0
)
{
for
(
size_t
i
=
0
;
i
<
importedNode
->
mNumChildren
;
++
i
)
{
HierarchyContainer
*
child
=
new
HierarchyContainer
;
child
->
loadNodeHierarchy
(
importedNode
->
mChildren
[
i
],
tab
.
append
(
" "
));
child
->
loadNodeHierarchy
(
importedNode
->
mChildren
[
i
]);
addNode
(
child
);
}
}
}
...
...
@@ -72,13 +74,18 @@ glm::mat4 HierarchyContainer::getCumulativeMeshTransform(uint32_t searchedMeshId
HierarchyContainer
*
node
)
->
std
::
pair
<
bool
,
glm
::
mat4
>
{
for
(
const
auto
&
meshIdx
:
node
->
meshIndices
)
{
if
(
meshIdx
==
searchedMeshIdx
)
{
return
{
true
,
node
->
getMatrix
(
)
};
return
{
true
,
glm
::
mat4
(
1.0f
)
};
}
}
for
(
const
auto
&
child
:
node
->
nodes
)
{
auto
[
found
,
mat
]
=
descend
(
descend
,
dynamic_cast
<
HierarchyContainer
*>
(
child
));
if
(
found
)
{
return
{
true
,
node
->
getMatrix
()
*
child
->
getMatrix
()
};
if
(
node
->
getParent
()
==
nullptr
)
{
// do not accumulate with the root transform, it is applied to the Content
return
{
true
,
mat
};
}
else
{
return
{
true
,
node
->
getMatrix
()
*
mat
};
}
}
}
return
{
false
,
{
1.0f
}
};
...
...
@@ -176,7 +183,7 @@ void Model3DNode::render(Renderer* renderer, const glm::mat4& local)
{
if
(
!
canRender
(
renderer
))
return
;
glm
::
mat4
localMat
=
local
*
getMatrix
();
glm
::
mat4
localMat
=
local
*
getMatrix
()
*
content
.
getMatrix
()
;
for
(
int
i
=
0
;
i
<
content
.
nbChildren
();
++
i
)
{
static_cast
<
Model3DMeshNode
*>
(
content
[
i
])
->
render
(
renderer
,
localMat
);
}
...
...
@@ -233,7 +240,7 @@ bool Model3DNode::importModel(const std::string& modelName, const std::string& m
// Will be used to computed the meshes transform matrices, if nedded.
HierarchyContainer
*
rootNode
=
new
HierarchyContainer
();
rootNode
->
loadNodeHierarchy
(
scene
->
mRootNode
,
std
::
string
{
""
}
);
rootNode
->
loadNodeHierarchy
(
scene
->
mRootNode
);
// Create and add a mesh for each object's imported mesh.
// It could be a Mesh<MVertex> or a Mesh<SMVertex> if the mesh has bones.
...
...
@@ -363,6 +370,7 @@ bool Model3DNode::importModel(const std::string& modelName, const std::string& m
content
.
addNode
(
meshNode
);
}
content
.
setMatrix
(
aiToGlmMatrix
(
scene
->
mRootNode
->
mTransformation
));
setTransparency
(
modelTransparency
);
modelLoaded
=
true
;
...
...
This diff is collapsed.
Click to expand it.
src/SceneGraph/Misc/Model3D.hpp
+
1
−
1
View file @
3bd63464
...
...
@@ -65,7 +65,7 @@ public:
return
-
1
;
}
void
loadNodeHierarchy
(
aiNode
*
importedNode
,
std
::
string
tab
);
void
loadNodeHierarchy
(
aiNode
*
importedNode
);
glm
::
mat4
getCumulativeMeshTransform
(
uint32_t
meshIdx
);
private
:
...
...
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