Some simple svg output.
This commit is contained in:
parent
1fc730d413
commit
b101a5f87c
11 changed files with 87 additions and 6 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "AbstractMesh.h"
|
||||
#include "TriMesh.h"
|
||||
#include "AbstractFace.h"
|
||||
|
||||
#include "SvgShapeElements.h"
|
||||
|
||||
|
@ -16,22 +17,44 @@ std::unique_ptr<SvgDocument> SvgConverter::convert(Scene* scene)
|
|||
auto doc = std::make_unique<SvgDocument>();
|
||||
|
||||
scene->update();
|
||||
|
||||
for(auto item : scene->getItems())
|
||||
{
|
||||
if (item->getType() == SceneItem::Type::MODEL)
|
||||
{
|
||||
auto mesh = dynamic_cast<SceneModel*>(item)->getMesh();
|
||||
auto transform = item->getTransform();
|
||||
|
||||
if (mesh->getType() == AbstractMesh::MeshType::TRI)
|
||||
{
|
||||
for(const auto& face : dynamic_cast<TriMesh*>(mesh)->getFaces())
|
||||
{
|
||||
auto svg_tri = std::make_unique<SvgPolygon>();
|
||||
// Get node locs for face
|
||||
|
||||
// Convert to pixel
|
||||
std::vector<DiscretePoint> points(3);
|
||||
unsigned count = 0;
|
||||
|
||||
// add polygon to doc
|
||||
auto face_locs = face->getNodeLocations();
|
||||
for(auto& loc : face_locs)
|
||||
{
|
||||
const auto x = loc.getX() * transform.getScaleX() + transform.getLocation().getX();
|
||||
const auto y = loc.getY() * transform.getScaleY() + transform.getLocation().getY();
|
||||
points[count] = {static_cast<unsigned>(x), static_cast<unsigned>(y)};
|
||||
count++;
|
||||
}
|
||||
svg_tri->setPoints(points);
|
||||
svg_tri->setFill(item->getColor());
|
||||
doc->getRoot()->addChild(std::move(svg_tri));
|
||||
|
||||
if (scene->shouldShowMeshOutline())
|
||||
{
|
||||
auto mesh_outline = std::make_unique<SvgPolyline>();
|
||||
points.push_back(points[0]);
|
||||
mesh_outline->setPoints(points);
|
||||
mesh_outline->setStrokeColor({0, 0, 0});
|
||||
mesh_outline->setStrokeWidth(0.1);
|
||||
doc->getRoot()->addChild(std::move(mesh_outline));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue