Skip to content

Commit

Permalink
line segments - export functionality done
Browse files Browse the repository at this point in the history
  • Loading branch information
vicrucann committed May 12, 2017
1 parent ce7ca19 commit 8f03cd9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/cherish/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ const int STROKE_SEGMENTS_NUMBER = 11;
const float STROKE_FOG_MIN = 4.f;
const float STROKE_FOG_MAX = 30.f;
const float STROKE_MESH_RADIUS = 0.1f;
const float SEGMENT_MESH_RADIUS = 0.2f;
const unsigned int EXTRUSION_MESH_SHAPE = 8;

// polygon settings
const float POLYGON_LINE_WIDTH = 4.f;
Expand Down
23 changes: 23 additions & 0 deletions src/libSGEntities/LineSegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <osg/StateSet>

#include "MainWindow.h"
#include "ParallelTransportFrame/libPTFTube/PTFTube.h"

const GLenum LINESEMENT_PHANTOM_TYPE = GL_LINES;

Expand Down Expand Up @@ -56,6 +57,28 @@ void entity::LineSegment::editLastPoint(float u, float v)
this->dirtyBound();
}

osg::Node *entity::LineSegment::getMeshRepresentation() const
{
const osg::Vec3Array* vertices = static_cast<const osg::Vec3Array*>(this->getVertexArray());
if (!vertices){
qWarning("Could not extract the vertices.");
return nullptr;
}
std::vector<osg::Vec3f> path;
Q_ASSERT(vertices->size() >= 2);
float delta = 0.01;
osg::Vec3f dir = vertices->at(0)-vertices->at(1);
path.push_back(vertices->at(0) + dir * delta);
path.push_back(vertices->at(0));
path.push_back(vertices->at(1));
path.push_back(vertices->at(1) - dir * delta);

PTFTube extrusion(path, cher::SEGMENT_MESH_RADIUS, cher::EXTRUSION_MESH_SHAPE);
extrusion.build();

return extrusion.generateTriMesh();
}

bool entity::LineSegment::redefineToShader(osg::MatrixTransform *t)
{
if (!m_program) return false;
Expand Down
2 changes: 2 additions & 0 deletions src/libSGEntities/LineSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class LineSegment : public entity::ShaderedEntity2D

void editLastPoint(float u, float v);

osg::Node* getMeshRepresentation() const;

protected:
virtual bool redefineToShader(osg::MatrixTransform *t);

Expand Down
14 changes: 14 additions & 0 deletions src/libSGEntities/RootScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,20 @@ bool RootScene::exportSceneToFile(const std::string &name)
continue;
}
}
for (unsigned int j=0; j<canvas->getNumLineSegments(); ++j){
entity::LineSegment* segment = canvas->getLineSegment(j);
if (!segment) continue;
osg::ref_ptr<osg::Node> mesh = segment->getMeshRepresentation();
if (!mesh.get()){
qWarning("Could not obtain mesh represenation from the line segment.");
continue;
}
bool added = meshes.back()->addChild(mesh.get());
if (!added){
qWarning("Could not attach mesh to the mesh group.");
continue;
}
}

}

Expand Down
2 changes: 1 addition & 1 deletion src/libSGEntities/Stroke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ osg::Node *entity::Stroke::getMeshRepresentation() const
path.push_back(vertices->at(i));
}

PTFTube extrusion(path, cher::STROKE_MESH_RADIUS, 8);
PTFTube extrusion(path, cher::STROKE_MESH_RADIUS, cher::EXTRUSION_MESH_SHAPE);
extrusion.build();

return extrusion.generateTriMesh();
Expand Down

0 comments on commit 8f03cd9

Please sign in to comment.