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
97013ac9
Commit
97013ac9
authored
Jun 21, 2019
by
chili
Browse files
basic model node tree
parent
551cc463
Changes
4
Show whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
97013ac9
...
...
@@ -26,37 +26,26 @@ void App::DoFrame()
wnd
.
Gfx
().
SetCamera
(
cam
.
GetMatrix
()
);
light
.
Bind
(
wnd
.
Gfx
(),
cam
.
GetMatrix
()
);
const
auto
transform
=
dx
::
XMMatrixRotationRollPitchYaw
(
pos
.
roll
,
pos
.
pitch
,
pos
.
yaw
)
*
dx
::
XMMatrixTranslation
(
pos
.
x
,
pos
.
y
,
pos
.
z
);
nano
.
Draw
(
wnd
.
Gfx
(),
transform
);
nano
.
Draw
(
wnd
.
Gfx
()
);
light
.
Draw
(
wnd
.
Gfx
()
);
// imgui windows
cam
.
SpawnControlWindow
();
light
.
SpawnControlWindow
();
ShowModelWindow
();
ShowImguiDemoWindow
();
nano
.
ShowWindow
();
// present
wnd
.
Gfx
().
EndFrame
();
}
void
App
::
Show
Model
Window
()
void
App
::
Show
ImguiDemo
Window
()
{
if
(
ImGui
::
Begin
(
"Model"
)
)
static
bool
show_demo_window
=
true
;
if
(
show_demo_window
)
{
using
namespace
std
::
string_literals
;
ImGui
::
Text
(
"Orientation"
);
ImGui
::
SliderAngle
(
"Roll"
,
&
pos
.
roll
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Pitch"
,
&
pos
.
pitch
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Yaw"
,
&
pos
.
yaw
,
-
180.0
f
,
180.0
f
);
ImGui
::
Text
(
"Position"
);
ImGui
::
SliderFloat
(
"X"
,
&
pos
.
x
,
-
20.0
f
,
20.0
f
);
ImGui
::
SliderFloat
(
"Y"
,
&
pos
.
y
,
-
20.0
f
,
20.0
f
);
ImGui
::
SliderFloat
(
"Z"
,
&
pos
.
z
,
-
20.0
f
,
20.0
f
);
ImGui
::
ShowDemoWindow
(
&
show_demo_window
);
}
ImGui
::
End
();
}
App
::~
App
()
...
...
hw3d/App.h
View file @
97013ac9
...
...
@@ -16,7 +16,7 @@ public:
~
App
();
private:
void
DoFrame
();
void
Show
Model
Window
();
void
Show
ImguiDemo
Window
();
private:
ImguiManager
imgui
;
Window
wnd
;
...
...
@@ -25,13 +25,4 @@ private:
Camera
cam
;
PointLight
light
;
Model
nano
{
wnd
.
Gfx
(),
"Models
\\
nanosuit.obj"
};
struct
{
float
roll
=
0.0
f
;
float
pitch
=
0.0
f
;
float
yaw
=
0.0
f
;
float
x
=
0.0
f
;
float
y
=
0.0
f
;
float
z
=
0.0
f
;
}
pos
;
};
\ No newline at end of file
hw3d/Mesh.cpp
View file @
97013ac9
#include "Mesh.h"
#include "imgui/imgui.h"
// Mesh
Mesh
::
Mesh
(
Graphics
&
gfx
,
std
::
vector
<
std
::
unique_ptr
<
Bind
::
Bindable
>>
bindPtrs
)
...
...
@@ -23,7 +24,7 @@ Mesh::Mesh( Graphics& gfx,std::vector<std::unique_ptr<Bind::Bindable>> bindPtrs
AddBind
(
std
::
make_unique
<
Bind
::
TransformCbuf
>
(
gfx
,
*
this
)
);
}
void
Mesh
::
Draw
(
Graphics
&
gfx
,
DirectX
::
FXMMATRIX
accumulatedTransform
)
const
no
except
(
!
IS_DEBUG
)
void
Mesh
::
Draw
(
Graphics
&
gfx
,
DirectX
::
FXMMATRIX
accumulatedTransform
)
const
no
xnd
{
DirectX
::
XMStoreFloat4x4
(
&
transform
,
accumulatedTransform
);
Drawable
::
Draw
(
gfx
);
...
...
@@ -35,12 +36,14 @@ DirectX::XMMATRIX Mesh::GetTransformXM() const noexcept
// Node
Node
::
Node
(
std
::
vector
<
Mesh
*>
meshPtrs
,
const
DirectX
::
XMMATRIX
&
transform
)
noxnd
Node
::
Node
(
const
std
::
string
&
name
,
std
::
vector
<
Mesh
*>
meshPtrs
,
const
DirectX
::
XMMATRIX
&
transform
)
noxnd
:
meshPtrs
(
std
::
move
(
meshPtrs
)
)
meshPtrs
(
std
::
move
(
meshPtrs
)
),
name
(
name
)
{
DirectX
::
XMStoreFloat4x4
(
&
this
->
transform
,
transform
);
}
void
Node
::
Draw
(
Graphics
&
gfx
,
DirectX
::
FXMMATRIX
accumulatedTransform
)
const
noxnd
{
const
auto
built
=
DirectX
::
XMLoadFloat4x4
(
&
transform
)
*
accumulatedTransform
;
...
...
@@ -53,12 +56,26 @@ void Node::Draw( Graphics& gfx,DirectX::FXMMATRIX accumulatedTransform ) const n
pc
->
Draw
(
gfx
,
built
);
}
}
void
Node
::
AddChild
(
std
::
unique_ptr
<
Node
>
pChild
)
noxnd
{
assert
(
pChild
);
childPtrs
.
push_back
(
std
::
move
(
pChild
)
);
}
void
Node
::
RenderTree
()
const
noexcept
{
// if tree node expanded, recursively render all children
if
(
ImGui
::
TreeNode
(
name
.
c_str
()
)
)
{
for
(
const
auto
&
pChild
:
childPtrs
)
{
pChild
->
RenderTree
();
}
ImGui
::
TreePop
();
}
}
// Model
Model
::
Model
(
Graphics
&
gfx
,
const
std
::
string
fileName
)
...
...
@@ -76,10 +93,35 @@ Model::Model( Graphics& gfx,const std::string fileName )
pRoot
=
ParseNode
(
*
pScene
->
mRootNode
);
}
void
Model
::
Draw
(
Graphics
&
gfx
,
DirectX
::
FXMMATRIX
transform
)
const
void
Model
::
Draw
(
Graphics
&
gfx
)
const
noxnd
{
const
auto
transform
=
DirectX
::
XMMatrixRotationRollPitchYaw
(
pos
.
roll
,
pos
.
pitch
,
pos
.
yaw
)
*
DirectX
::
XMMatrixTranslation
(
pos
.
x
,
pos
.
y
,
pos
.
z
);
pRoot
->
Draw
(
gfx
,
transform
);
}
void
Model
::
ShowWindow
(
const
char
*
windowName
)
noexcept
{
windowName
=
windowName
?
windowName
:
"Model"
;
if
(
ImGui
::
Begin
(
windowName
)
)
{
ImGui
::
Columns
(
2
,
nullptr
,
true
);
pRoot
->
RenderTree
();
ImGui
::
NextColumn
();
ImGui
::
Text
(
"Orientation"
);
ImGui
::
SliderAngle
(
"Roll"
,
&
pos
.
roll
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Pitch"
,
&
pos
.
pitch
,
-
180.0
f
,
180.0
f
);
ImGui
::
SliderAngle
(
"Yaw"
,
&
pos
.
yaw
,
-
180.0
f
,
180.0
f
);
ImGui
::
Text
(
"Position"
);
ImGui
::
SliderFloat
(
"X"
,
&
pos
.
x
,
-
20.0
f
,
20.0
f
);
ImGui
::
SliderFloat
(
"Y"
,
&
pos
.
y
,
-
20.0
f
,
20.0
f
);
ImGui
::
SliderFloat
(
"Z"
,
&
pos
.
z
,
-
20.0
f
,
20.0
f
);
}
ImGui
::
End
();
}
std
::
unique_ptr
<
Mesh
>
Model
::
ParseMesh
(
Graphics
&
gfx
,
const
aiMesh
&
mesh
)
{
namespace
dx
=
DirectX
;
...
...
@@ -135,7 +177,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
)
std
::
unique_ptr
<
Node
>
Model
::
ParseNode
(
const
aiNode
&
node
)
noexcept
{
namespace
dx
=
DirectX
;
const
auto
transform
=
dx
::
XMMatrixTranspose
(
dx
::
XMLoadFloat4x4
(
...
...
@@ -150,7 +192,7 @@ std::unique_ptr<Node> Model::ParseNode( const aiNode& node )
curMeshPtrs
.
push_back
(
meshPtrs
.
at
(
meshIdx
).
get
()
);
}
auto
pNode
=
std
::
make_unique
<
Node
>
(
std
::
move
(
curMeshPtrs
),
transform
);
auto
pNode
=
std
::
make_unique
<
Node
>
(
node
.
mName
.
C_Str
(),
std
::
move
(
curMeshPtrs
),
transform
);
for
(
size_t
i
=
0
;
i
<
node
.
mNumChildren
;
i
++
)
{
pNode
->
AddChild
(
ParseNode
(
*
node
.
mChildren
[
i
]
)
);
...
...
hw3d/Mesh.h
View file @
97013ac9
...
...
@@ -21,11 +21,13 @@ class Node
{
friend
class
Model
;
public:
Node
(
std
::
vector
<
Mesh
*>
meshPtrs
,
const
DirectX
::
XMMATRIX
&
transform
)
noxnd
;
Node
(
const
std
::
string
&
name
,
std
::
vector
<
Mesh
*>
meshPtrs
,
const
DirectX
::
XMMATRIX
&
transform
)
noxnd
;
void
Draw
(
Graphics
&
gfx
,
DirectX
::
FXMMATRIX
accumulatedTransform
)
const
noxnd
;
void
RenderTree
()
const
noexcept
;
private:
void
AddChild
(
std
::
unique_ptr
<
Node
>
pChild
)
noxnd
;
private:
std
::
string
name
;
std
::
vector
<
std
::
unique_ptr
<
Node
>>
childPtrs
;
std
::
vector
<
Mesh
*>
meshPtrs
;
DirectX
::
XMFLOAT4X4
transform
;
...
...
@@ -35,11 +37,21 @@ class Model
{
public:
Model
(
Graphics
&
gfx
,
const
std
::
string
fileName
);
void
Draw
(
Graphics
&
gfx
,
DirectX
::
FXMMATRIX
transform
)
const
;
void
Draw
(
Graphics
&
gfx
)
const
noxnd
;
void
ShowWindow
(
const
char
*
windowName
=
nullptr
)
noexcept
;
private:
static
std
::
unique_ptr
<
Mesh
>
ParseMesh
(
Graphics
&
gfx
,
const
aiMesh
&
mesh
);
std
::
unique_ptr
<
Node
>
ParseNode
(
const
aiNode
&
node
);
std
::
unique_ptr
<
Node
>
ParseNode
(
const
aiNode
&
node
)
noexcept
;
private:
std
::
unique_ptr
<
Node
>
pRoot
;
std
::
vector
<
std
::
unique_ptr
<
Mesh
>>
meshPtrs
;
struct
{
float
roll
=
0.0
f
;
float
pitch
=
0.0
f
;
float
yaw
=
0.0
f
;
float
x
=
0.0
f
;
float
y
=
0.0
f
;
float
z
=
0.0
f
;
}
pos
;
};
\ No newline at end of file
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