Add simple mesh viewer
This commit is contained in:
parent
fcd90b5db4
commit
8a41337e2d
19 changed files with 275 additions and 2 deletions
|
@ -121,10 +121,16 @@ void OpenGlMeshPainter::paint(SceneModel* model, DrawingContext* context)
|
|||
else
|
||||
{
|
||||
indices = dynamic_cast<TriMesh*>(model->getMesh())->getFaceNodeIds();
|
||||
|
||||
}
|
||||
|
||||
auto model_color = model->getColor().getAsVectorDouble();
|
||||
std::vector<float> color = {float(model_color[0]), float(model_color[1]), float(model_color[2]), float(model_color[3])};
|
||||
|
||||
paint(vertices, indices, color, line_mesh);
|
||||
|
||||
if (model->getShowOutline())
|
||||
{
|
||||
auto edge_indices = dynamic_cast<TriMesh*>(model->getMesh())->getEdgeNodeIds();
|
||||
paint(vertices, edge_indices, {0, 0, 0, 1}, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,11 @@ public:
|
|||
|
||||
void transform(const Transform& transform);
|
||||
|
||||
unsigned getNumNodes() const
|
||||
{
|
||||
return mNodes.size();
|
||||
}
|
||||
|
||||
protected:
|
||||
std::unordered_map<std::string, std::vector<double> > mVectorAttributes;
|
||||
VecNodes mNodes;
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "Edge.h"
|
||||
#include "AbstractFace.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
FaceMesh::~FaceMesh()
|
||||
{
|
||||
|
||||
|
@ -64,18 +66,21 @@ void FaceMesh::resetIds()
|
|||
for (auto& node : mNodes)
|
||||
{
|
||||
node->setIndex(count);
|
||||
count++;
|
||||
}
|
||||
|
||||
count = 0;
|
||||
for (auto& edge : mEdges)
|
||||
{
|
||||
edge->setIndex(count);
|
||||
count++;
|
||||
}
|
||||
|
||||
count = 0;
|
||||
for (auto& face : mFaces)
|
||||
{
|
||||
face->setIndex(count);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,6 +137,17 @@ void FaceMesh::replaceIfOverlapping(FaceMesh* mesh, Edge* target_edge) const
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<unsigned> FaceMesh::getEdgeNodeIds() const
|
||||
{
|
||||
std::vector<unsigned> ids(2*mEdges.size());
|
||||
for(std::size_t idx=0; idx<mEdges.size(); idx++)
|
||||
{
|
||||
ids[2*idx] = mEdges[idx]->getNode0Id();
|
||||
ids[2*idx + 1] = mEdges[idx]->getNode1Id();
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
void FaceMesh::merge(std::unique_ptr<FaceMesh> mesh)
|
||||
{
|
||||
if (mesh->getType() != getType())
|
||||
|
|
|
@ -27,6 +27,8 @@ public:
|
|||
|
||||
std::vector<unsigned> getFaceNodeIds() const;
|
||||
|
||||
std::vector<unsigned> getEdgeNodeIds() const;
|
||||
|
||||
void addConstantFaceVectorAttribute(const std::string& tag, const std::vector<double>& values);
|
||||
|
||||
std::vector<std::vector<double> > getFaceVectorAttributes(const std::string& tag);
|
||||
|
|
|
@ -2,6 +2,7 @@ list(APPEND visual_elements_LIB_INCLUDES
|
|||
GeometryNode.cpp
|
||||
RectangleNode.cpp
|
||||
MaterialNode.cpp
|
||||
MeshNode.cpp
|
||||
TextNode.cpp
|
||||
Scene.cpp
|
||||
SceneModel.cpp
|
||||
|
|
90
src/visual_elements/MeshNode.cpp
Normal file
90
src/visual_elements/MeshNode.cpp
Normal 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;
|
||||
}
|
||||
}
|
||||
|
28
src/visual_elements/MeshNode.h
Normal file
28
src/visual_elements/MeshNode.h
Normal 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;
|
||||
};
|
|
@ -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;
|
||||
|
|
|
@ -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};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue