stuff-from-scratch/apps/notes_tk/mesh_viewer/MeshViewerView.cpp
2023-12-21 09:18:44 +00:00

66 lines
1.3 KiB
C++

#include "MeshViewerView.h"
#include "MeshNode.h"
#include "TransformNode.h"
#include "AbstractMesh.h"
#include "MeshPrimitives.h"
#include "ThemeManager.h"
#include "PaintEvent.h"
#include <iostream>
Ptr<MeshViewerView> MeshViewerView::Create()
{
return std::make_unique<MeshViewerView>();
}
MeshViewerView::~MeshViewerView()
{
}
MeshViewerView::MeshViewerView()
{
mName = "MeshViewerView";
}
void MeshViewerView::doPaint(const PaintEvent* event)
{
if (!mVisible)
{
return;
}
if (!mMeshNode)
{
mMeshNode = std::make_unique<MeshNode>(Transform(Point3(mLocation)));
mMeshNode->setName(mName + "_MeshNode");
mMeshNode->setWidth(mSize.mWidth);
mMeshNode->setHeight(mSize.mHeight);
mMeshNode->setFillColor(event->getThemesManager()->getColor(mBackground));
mRootNode->addChild(mMeshNode.get());
}
if (mTransformDirty)
{
mMeshNode->setWidth(mSize.mWidth);
mMeshNode->setHeight(mSize.mHeight);
}
if (mMaterialDirty)
{
mMeshNode->setFillColor(event->getThemesManager()->getColor(mBackground));
}
if (!mMesh)
{
auto mesh = MeshPrimitives::buildRectangleAsTriMesh();
mMesh = std::move(mesh);
mMeshNode->setMesh(mMesh.get());
}
}