Skip to content

Commit 8f03cd9

Browse files
committed
line segments - export functionality done
1 parent ce7ca19 commit 8f03cd9

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

src/cherish/Settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ const int STROKE_SEGMENTS_NUMBER = 11;
223223
const float STROKE_FOG_MIN = 4.f;
224224
const float STROKE_FOG_MAX = 30.f;
225225
const float STROKE_MESH_RADIUS = 0.1f;
226+
const float SEGMENT_MESH_RADIUS = 0.2f;
227+
const unsigned int EXTRUSION_MESH_SHAPE = 8;
226228

227229
// polygon settings
228230
const float POLYGON_LINE_WIDTH = 4.f;

src/libSGEntities/LineSegment.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <osg/StateSet>
88

99
#include "MainWindow.h"
10+
#include "ParallelTransportFrame/libPTFTube/PTFTube.h"
1011

1112
const GLenum LINESEMENT_PHANTOM_TYPE = GL_LINES;
1213

@@ -56,6 +57,28 @@ void entity::LineSegment::editLastPoint(float u, float v)
5657
this->dirtyBound();
5758
}
5859

60+
osg::Node *entity::LineSegment::getMeshRepresentation() const
61+
{
62+
const osg::Vec3Array* vertices = static_cast<const osg::Vec3Array*>(this->getVertexArray());
63+
if (!vertices){
64+
qWarning("Could not extract the vertices.");
65+
return nullptr;
66+
}
67+
std::vector<osg::Vec3f> path;
68+
Q_ASSERT(vertices->size() >= 2);
69+
float delta = 0.01;
70+
osg::Vec3f dir = vertices->at(0)-vertices->at(1);
71+
path.push_back(vertices->at(0) + dir * delta);
72+
path.push_back(vertices->at(0));
73+
path.push_back(vertices->at(1));
74+
path.push_back(vertices->at(1) - dir * delta);
75+
76+
PTFTube extrusion(path, cher::SEGMENT_MESH_RADIUS, cher::EXTRUSION_MESH_SHAPE);
77+
extrusion.build();
78+
79+
return extrusion.generateTriMesh();
80+
}
81+
5982
bool entity::LineSegment::redefineToShader(osg::MatrixTransform *t)
6083
{
6184
if (!m_program) return false;

src/libSGEntities/LineSegment.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class LineSegment : public entity::ShaderedEntity2D
3131

3232
void editLastPoint(float u, float v);
3333

34+
osg::Node* getMeshRepresentation() const;
35+
3436
protected:
3537
virtual bool redefineToShader(osg::MatrixTransform *t);
3638

src/libSGEntities/RootScene.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,20 @@ bool RootScene::exportSceneToFile(const std::string &name)
195195
continue;
196196
}
197197
}
198+
for (unsigned int j=0; j<canvas->getNumLineSegments(); ++j){
199+
entity::LineSegment* segment = canvas->getLineSegment(j);
200+
if (!segment) continue;
201+
osg::ref_ptr<osg::Node> mesh = segment->getMeshRepresentation();
202+
if (!mesh.get()){
203+
qWarning("Could not obtain mesh represenation from the line segment.");
204+
continue;
205+
}
206+
bool added = meshes.back()->addChild(mesh.get());
207+
if (!added){
208+
qWarning("Could not attach mesh to the mesh group.");
209+
continue;
210+
}
211+
}
198212

199213
}
200214

src/libSGEntities/Stroke.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ osg::Node *entity::Stroke::getMeshRepresentation() const
157157
path.push_back(vertices->at(i));
158158
}
159159

160-
PTFTube extrusion(path, cher::STROKE_MESH_RADIUS, 8);
160+
PTFTube extrusion(path, cher::STROKE_MESH_RADIUS, cher::EXTRUSION_MESH_SHAPE);
161161
extrusion.build();
162162

163163
return extrusion.generateTriMesh();

0 commit comments

Comments
 (0)