Add simple mesh viewer

This commit is contained in:
James Grogan 2022-11-18 17:05:33 +00:00
parent fcd90b5db4
commit 8a41337e2d
19 changed files with 275 additions and 2 deletions

View file

@ -2,6 +2,7 @@ list(APPEND visual_elements_LIB_INCLUDES
GeometryNode.cpp
RectangleNode.cpp
MaterialNode.cpp
MeshNode.cpp
TextNode.cpp
Scene.cpp
SceneModel.cpp

View file

@ -0,0 +1,90 @@
#include "MeshNode.h"
#include <iostream>
MeshNode::MeshNode(const DiscretePoint& location)
: MaterialNode(location)
{
}
void MeshNode::setWidth(unsigned width)
{
if (mWidth != width)
{
mTransformIsDirty = true;
mWidth = width;
}
}
void MeshNode::setHeight(unsigned height)
{
if (mHeight != height)
{
mTransformIsDirty = true;
mHeight = height;
}
}
void MeshNode::setMesh(AbstractMesh* mesh)
{
mWorkingMesh = mesh;
mMeshIsDirty = true;
}
SceneItem* MeshNode::getSceneItem(std::size_t idx) const
{
return mModel.get();
}
unsigned MeshNode::getNumSceneItems() const
{
if (mWorkingMesh)
{
return 1;
}
else
{
return 0;
}
}
void MeshNode::update(FontsManager* fontsManager)
{
if (!mModel || mMeshIsDirty)
{
if (!mModel)
{
mModel = std::make_unique<SceneModel>(nullptr);
mModel->setName(mName + "_MeshModel");
mModel->setShowOutline(true);
}
if (mWorkingMesh)
{
mModel->updateMesh(mWorkingMesh);
mMeshIsDirty = false;
}
}
if (mWorkingMesh && mMeshIsDirty)
{
std::cout << "Updating mesh with " << mWorkingMesh->getNumNodes() << std::endl;
mModel->updateMesh(mWorkingMesh);
mMeshIsDirty = false;
}
if (mTransformIsDirty)
{
auto size = mHeight > mWidth ? mWidth : mHeight;
mModel->updateTransform({mLocation, static_cast<double>(size), static_cast<double>(size)});
mTransformIsDirty = false;
}
if (mMaterialIsDirty)
{
mModel->updateUniformColor(mFillColor);
mMaterialIsDirty = false;
}
}

View file

@ -0,0 +1,28 @@
#pragma once
#include "MaterialNode.h"
class AbstractMesh;
class MeshNode : public MaterialNode
{
public:
MeshNode(const DiscretePoint& location);
void setMesh(AbstractMesh* mesh);
SceneItem* getSceneItem(std::size_t idx) const override;
unsigned getNumSceneItems() const override;
void setWidth(unsigned width);
void setHeight(unsigned height);
void update(FontsManager* fontsManager) override;
private:
bool mMeshIsDirty{true};
AbstractMesh* mWorkingMesh{nullptr};
unsigned mWidth{1};
unsigned mHeight{1};
std::unique_ptr<SceneModel> mModel;
};

View file

@ -11,7 +11,14 @@ SceneModel::SceneModel(std::unique_ptr<AbstractMesh> mesh)
AbstractMesh* SceneModel::getMesh() const
{
return mMesh.get();
if (mMesh)
{
return mMesh.get();
}
else
{
return mRawMesh;
}
}
void SceneModel::updateMesh(std::unique_ptr<AbstractMesh> mesh)
@ -20,6 +27,12 @@ void SceneModel::updateMesh(std::unique_ptr<AbstractMesh> mesh)
mMeshIsDirty = true;
}
void SceneModel::updateMesh(AbstractMesh* mesh)
{
mRawMesh = mesh;
mMeshIsDirty = true;
}
SceneItem::Type SceneModel::getType() const
{
return SceneItem::Type::MODEL;

View file

@ -19,13 +19,27 @@ public:
AbstractMesh* getMesh() const;
void updateMesh(std::unique_ptr<AbstractMesh> mesh);
void updateMesh(AbstractMesh* mesh);
void setShowOutline(bool showOutline)
{
mShowOutline = showOutline;
}
bool getShowOutline() const
{
return mShowOutline;
}
Type getType() const override;
private:
AbstractMesh* mRawMesh{nullptr};
std::unique_ptr<AbstractMesh> mMesh;
std::unique_ptr<Texture> mColorMap;
bool mMeshIsDirty{true};
bool mColorMapIsDirty{true};
bool mShowOutline{false};
};