Commit 143981dc authored by chili's avatar chili
Browse files

model window in own class (pImpl)

parent 97013ac9
#include "Mesh.h" #include "Mesh.h"
#include "imgui/imgui.h" #include "imgui/imgui.h"
namespace dx = DirectX;
// Mesh // Mesh
Mesh::Mesh( Graphics& gfx,std::vector<std::unique_ptr<Bind::Bindable>> bindPtrs ) Mesh::Mesh( Graphics& gfx,std::vector<std::unique_ptr<Bind::Bindable>> bindPtrs )
{ {
...@@ -63,14 +65,14 @@ void Node::AddChild( std::unique_ptr<Node> pChild ) noxnd ...@@ -63,14 +65,14 @@ void Node::AddChild( std::unique_ptr<Node> pChild ) noxnd
childPtrs.push_back( std::move( pChild ) ); childPtrs.push_back( std::move( pChild ) );
} }
void Node::RenderTree() const noexcept void Node::ShowTree() const noexcept
{ {
// if tree node expanded, recursively render all children // if tree node expanded, recursively render all children
if( ImGui::TreeNode( name.c_str() ) ) if( ImGui::TreeNode( name.c_str() ) )
{ {
for( const auto& pChild : childPtrs ) for( const auto& pChild : childPtrs )
{ {
pChild->RenderTree(); pChild->ShowTree();
} }
ImGui::TreePop(); ImGui::TreePop();
} }
...@@ -78,7 +80,50 @@ void Node::RenderTree() const noexcept ...@@ -78,7 +80,50 @@ void Node::RenderTree() const noexcept
// Model // Model
class ModelWindow // pImpl idiom, only defined in this .cpp
{
public:
void Show( const char* windowName,const Node& root ) noexcept
{
// window name defaults to "Model"
windowName = windowName ? windowName : "Model";
if( ImGui::Begin( windowName ) )
{
ImGui::Columns( 2,nullptr,true );
root.ShowTree();
ImGui::NextColumn();
ImGui::Text( "Orientation" );
ImGui::SliderAngle( "Roll",&pos.roll,-180.0f,180.0f );
ImGui::SliderAngle( "Pitch",&pos.pitch,-180.0f,180.0f );
ImGui::SliderAngle( "Yaw",&pos.yaw,-180.0f,180.0f );
ImGui::Text( "Position" );
ImGui::SliderFloat( "X",&pos.x,-20.0f,20.0f );
ImGui::SliderFloat( "Y",&pos.y,-20.0f,20.0f );
ImGui::SliderFloat( "Z",&pos.z,-20.0f,20.0f );
}
ImGui::End();
}
dx::XMMATRIX GetTransform() const noexcept
{
return dx::XMMatrixRotationRollPitchYaw( pos.roll,pos.pitch,pos.yaw ) *
dx::XMMatrixTranslation( pos.x,pos.y,pos.z );
}
private:
struct
{
float roll = 0.0f;
float pitch = 0.0f;
float yaw = 0.0f;
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;
} pos;
};
Model::Model( Graphics& gfx,const std::string fileName ) Model::Model( Graphics& gfx,const std::string fileName )
:
pWindow( std::make_unique<ModelWindow>() )
{ {
Assimp::Importer imp; Assimp::Importer imp;
const auto pScene = imp.ReadFile( fileName.c_str(), const auto pScene = imp.ReadFile( fileName.c_str(),
...@@ -96,32 +141,17 @@ Model::Model( Graphics& gfx,const std::string fileName ) ...@@ -96,32 +141,17 @@ Model::Model( Graphics& gfx,const std::string fileName )
void Model::Draw( Graphics& gfx ) const noxnd void Model::Draw( Graphics& gfx ) const noxnd
{ {
const auto transform = DirectX::XMMatrixRotationRollPitchYaw( pos.roll,pos.pitch,pos.yaw ) * pRoot->Draw( gfx,pWindow->GetTransform() );
DirectX::XMMatrixTranslation( pos.x,pos.y,pos.z );
pRoot->Draw( gfx,transform );
} }
void Model::ShowWindow( const char* windowName ) noexcept void Model::ShowWindow( const char* windowName ) noexcept
{ {
windowName = windowName ? windowName : "Model"; pWindow->Show( windowName,*pRoot );
if( ImGui::Begin( windowName ) )
{
ImGui::Columns( 2,nullptr,true );
pRoot->RenderTree();
ImGui::NextColumn();
ImGui::Text( "Orientation" );
ImGui::SliderAngle( "Roll",&pos.roll,-180.0f,180.0f );
ImGui::SliderAngle( "Pitch",&pos.pitch,-180.0f,180.0f );
ImGui::SliderAngle( "Yaw",&pos.yaw,-180.0f,180.0f );
ImGui::Text( "Position" );
ImGui::SliderFloat( "X",&pos.x,-20.0f,20.0f );
ImGui::SliderFloat( "Y",&pos.y,-20.0f,20.0f );
ImGui::SliderFloat( "Z",&pos.z,-20.0f,20.0f );
}
ImGui::End();
} }
Model::~Model() noexcept
{}
std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh ) std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh )
{ {
namespace dx = DirectX; namespace dx = DirectX;
......
...@@ -23,7 +23,7 @@ class Node ...@@ -23,7 +23,7 @@ class Node
public: public:
Node( const std::string& name,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 Draw( Graphics& gfx,DirectX::FXMMATRIX accumulatedTransform ) const noxnd;
void RenderTree() const noexcept; void ShowTree() const noexcept;
private: private:
void AddChild( std::unique_ptr<Node> pChild ) noxnd; void AddChild( std::unique_ptr<Node> pChild ) noxnd;
private: private:
...@@ -39,19 +39,12 @@ public: ...@@ -39,19 +39,12 @@ public:
Model( Graphics& gfx,const std::string fileName ); Model( Graphics& gfx,const std::string fileName );
void Draw( Graphics& gfx ) const noxnd; void Draw( Graphics& gfx ) const noxnd;
void ShowWindow( const char* windowName = nullptr ) noexcept; void ShowWindow( const char* windowName = nullptr ) noexcept;
~Model() noexcept;
private: private:
static std::unique_ptr<Mesh> ParseMesh( Graphics& gfx,const aiMesh& mesh ); 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( const aiNode& node ) noexcept;
private: private:
std::unique_ptr<Node> pRoot; std::unique_ptr<Node> pRoot;
std::vector<std::unique_ptr<Mesh>> meshPtrs; std::vector<std::unique_ptr<Mesh>> meshPtrs;
struct std::unique_ptr<class ModelWindow> pWindow;
{
float roll = 0.0f;
float pitch = 0.0f;
float yaw = 0.0f;
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;
} pos;
}; };
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment