Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
hw3d
Commits
dac6fa8a
Commit
dac6fa8a
authored
Jul 06, 2019
by
chili
Browse files
give each node its id (fixing imgui tree id problems)
parent
f67da57b
Changes
3
Show whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
dac6fa8a
...
...
@@ -87,7 +87,7 @@ void App::DoFrame()
{
if
(
!
wnd
.
CursorEnabled
()
)
{
cam
.
Rotate
(
delta
->
x
,
delta
->
y
);
cam
.
Rotate
(
(
float
)
delta
->
x
,
(
float
)
delta
->
y
);
}
}
...
...
hw3d/Mesh.cpp
View file @
dac6fa8a
...
...
@@ -66,8 +66,9 @@ DirectX::XMMATRIX Mesh::GetTransformXM() const noexcept
// Node
Node
::
Node
(
const
std
::
string
&
name
,
std
::
vector
<
Mesh
*>
meshPtrs
,
const
DirectX
::
XMMATRIX
&
transform_in
)
noxnd
Node
::
Node
(
int
id
,
const
std
::
string
&
name
,
std
::
vector
<
Mesh
*>
meshPtrs
,
const
DirectX
::
XMMATRIX
&
transform_in
)
noxnd
:
id
(
id
),
meshPtrs
(
std
::
move
(
meshPtrs
)
),
name
(
name
)
{
...
...
@@ -97,23 +98,20 @@ void Node::AddChild( std::unique_ptr<Node> pChild ) noxnd
childPtrs
.
push_back
(
std
::
move
(
pChild
)
);
}
void
Node
::
ShowTree
(
int
&
nodeIndexTracked
,
std
::
optional
<
int
>&
selectedIndex
,
Node
*&
pSelectedNode
)
const
noexcept
void
Node
::
ShowTree
(
std
::
optional
<
int
>&
selectedIndex
,
Node
*&
pSelectedNode
)
const
noexcept
{
// nodeIndex serves as the uid for gui tree nodes, incremented throughout recursion
const
int
currentNodeIndex
=
nodeIndexTracked
;
nodeIndexTracked
++
;
// build up flags for current node
const
auto
node_flags
=
ImGuiTreeNodeFlags_OpenOnArrow
|
((
currentNodeIndex
==
selectedIndex
.
value_or
(
-
1
))
?
ImGuiTreeNodeFlags_Selected
:
0
)
|
((
GetId
()
==
selectedIndex
.
value_or
(
-
1
))
?
ImGuiTreeNodeFlags_Selected
:
0
)
|
((
childPtrs
.
size
()
==
0
)
?
ImGuiTreeNodeFlags_Leaf
:
0
);
// render this node
const
auto
expanded
=
ImGui
::
TreeNodeEx
(
(
void
*
)(
intptr_t
)
currentNodeIndex
,
node_flags
,
name
.
c_str
()
(
void
*
)(
intptr_t
)
GetId
()
,
node_flags
,
name
.
c_str
()
);
// processing for selecting node
if
(
ImGui
::
IsItemClicked
()
)
{
selectedIndex
=
currentNodeIndex
;
selectedIndex
=
GetId
()
;
pSelectedNode
=
const_cast
<
Node
*>
(
this
);
}
// recursive rendering of open node's children
...
...
@@ -121,7 +119,7 @@ void Node::ShowTree( int& nodeIndexTracked,std::optional<int>& selectedIndex,Nod
{
for
(
const
auto
&
pChild
:
childPtrs
)
{
pChild
->
ShowTree
(
nodeIndexTracked
,
selectedIndex
,
pSelectedNode
);
pChild
->
ShowTree
(
selectedIndex
,
pSelectedNode
);
}
ImGui
::
TreePop
();
}
...
...
@@ -132,6 +130,11 @@ void Node::SetAppliedTransform( DirectX::FXMMATRIX transform ) noexcept
dx
::
XMStoreFloat4x4
(
&
appliedTransform
,
transform
);
}
int
Node
::
GetId
()
const
noexcept
{
return
id
;
}
// Model
class
ModelWindow
// pImpl idiom, only defined in this .cpp
...
...
@@ -146,7 +149,7 @@ public:
if
(
ImGui
::
Begin
(
windowName
)
)
{
ImGui
::
Columns
(
2
,
nullptr
,
true
);
root
.
ShowTree
(
nodeIndexTracker
,
selectedIndex
,
pSelectedNode
);
root
.
ShowTree
(
selectedIndex
,
pSelectedNode
);
ImGui
::
NextColumn
();
if
(
pSelectedNode
!=
nullptr
)
...
...
@@ -212,7 +215,8 @@ Model::Model( Graphics& gfx,const std::string fileName )
meshPtrs
.
push_back
(
ParseMesh
(
gfx
,
*
pScene
->
mMeshes
[
i
]
)
);
}
pRoot
=
ParseNode
(
*
pScene
->
mRootNode
);
int
nextId
=
0
;
pRoot
=
ParseNode
(
nextId
,
*
pScene
->
mRootNode
);
}
void
Model
::
Draw
(
Graphics
&
gfx
)
const
noxnd
...
...
@@ -287,7 +291,7 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh )
return
std
::
make_unique
<
Mesh
>
(
gfx
,
std
::
move
(
bindablePtrs
)
);
}
std
::
unique_ptr
<
Node
>
Model
::
ParseNode
(
const
aiNode
&
node
)
noexcept
std
::
unique_ptr
<
Node
>
Model
::
ParseNode
(
int
&
nextId
,
const
aiNode
&
node
)
noexcept
{
namespace
dx
=
DirectX
;
const
auto
transform
=
dx
::
XMMatrixTranspose
(
dx
::
XMLoadFloat4x4
(
...
...
@@ -302,10 +306,10 @@ std::unique_ptr<Node> Model::ParseNode( const aiNode& node ) noexcept
curMeshPtrs
.
push_back
(
meshPtrs
.
at
(
meshIdx
).
get
()
);
}
auto
pNode
=
std
::
make_unique
<
Node
>
(
node
.
mName
.
C_Str
(),
std
::
move
(
curMeshPtrs
),
transform
);
auto
pNode
=
std
::
make_unique
<
Node
>
(
nextId
++
,
node
.
mName
.
C_Str
(),
std
::
move
(
curMeshPtrs
),
transform
);
for
(
size_t
i
=
0
;
i
<
node
.
mNumChildren
;
i
++
)
{
pNode
->
AddChild
(
ParseNode
(
*
node
.
mChildren
[
i
]
)
);
pNode
->
AddChild
(
ParseNode
(
nextId
,
*
node
.
mChildren
[
i
]
)
);
}
return
pNode
;
...
...
hw3d/Mesh.h
View file @
dac6fa8a
...
...
@@ -35,14 +35,16 @@ class Node
friend
class
Model
;
friend
class
ModelWindow
;
public:
Node
(
const
std
::
string
&
name
,
std
::
vector
<
Mesh
*>
meshPtrs
,
const
DirectX
::
XMMATRIX
&
transform
)
noxnd
;
Node
(
int
id
,
const
std
::
string
&
name
,
std
::
vector
<
Mesh
*>
meshPtrs
,
const
DirectX
::
XMMATRIX
&
transform
)
noxnd
;
void
Draw
(
Graphics
&
gfx
,
DirectX
::
FXMMATRIX
accumulatedTransform
)
const
noxnd
;
void
SetAppliedTransform
(
DirectX
::
FXMMATRIX
transform
)
noexcept
;
int
GetId
()
const
noexcept
;
private:
void
AddChild
(
std
::
unique_ptr
<
Node
>
pChild
)
noxnd
;
void
ShowTree
(
int
&
nodeIndex
,
std
::
optional
<
int
>&
selectedIndex
,
Node
*&
pSelectedNode
)
const
noexcept
;
void
ShowTree
(
std
::
optional
<
int
>&
selectedIndex
,
Node
*&
pSelectedNode
)
const
noexcept
;
private:
std
::
string
name
;
int
id
;
std
::
vector
<
std
::
unique_ptr
<
Node
>>
childPtrs
;
std
::
vector
<
Mesh
*>
meshPtrs
;
DirectX
::
XMFLOAT4X4
transform
;
...
...
@@ -58,7 +60,7 @@ public:
~
Model
()
noexcept
;
private:
static
std
::
unique_ptr
<
Mesh
>
ParseMesh
(
Graphics
&
gfx
,
const
aiMesh
&
mesh
);
std
::
unique_ptr
<
Node
>
ParseNode
(
const
aiNode
&
node
)
noexcept
;
std
::
unique_ptr
<
Node
>
ParseNode
(
int
&
nextId
,
const
aiNode
&
node
)
noexcept
;
private:
std
::
unique_ptr
<
Node
>
pRoot
;
std
::
vector
<
std
::
unique_ptr
<
Mesh
>>
meshPtrs
;
...
...
Write
Preview
Markdown
is supported
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