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

model window in own class (pImpl)

parent 97013ac9
#include "Mesh.h"
#include "imgui/imgui.h"
namespace dx = DirectX;
// Mesh
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
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( ImGui::TreeNode( name.c_str() ) )
{
for( const auto& pChild : childPtrs )
{
pChild->RenderTree();
pChild->ShowTree();
}
ImGui::TreePop();
}
......@@ -78,7 +80,50 @@ void Node::RenderTree() const noexcept
// 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 )
:
pWindow( std::make_unique<ModelWindow>() )
{
Assimp::Importer imp;
const auto pScene = imp.ReadFile( fileName.c_str(),
......@@ -96,32 +141,17 @@ Model::Model( Graphics& gfx,const std::string fileName )
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 );
pRoot->Draw( gfx,pWindow->GetTransform() );
}
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.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();
pWindow->Show( windowName,*pRoot );
}
Model::~Model() noexcept
{}
std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh )
{
namespace dx = DirectX;
......
......@@ -23,7 +23,7 @@ class Node
public:
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;
void ShowTree() const noexcept;
private:
void AddChild( std::unique_ptr<Node> pChild ) noxnd;
private:
......@@ -39,19 +39,12 @@ public:
Model( Graphics& gfx,const std::string fileName );
void Draw( Graphics& gfx ) const noxnd;
void ShowWindow( const char* windowName = nullptr ) noexcept;
~Model() noexcept;
private:
static std::unique_ptr<Mesh> ParseMesh( Graphics& gfx,const aiMesh& mesh );
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.0f;
float pitch = 0.0f;
float yaw = 0.0f;
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;
} pos;
std::unique_ptr<class ModelWindow> pWindow;
};
\ 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