|
10 | 10 |
|
11 | 11 | #include "CameraCallbacks.h" |
12 | 12 | #include "CurveFitting/libPathFitter/OsgPathFitter.h" |
| 13 | +#include "ParallelTransportFrame/libPTFTube/PTFTube.h" |
13 | 14 |
|
14 | 15 | const GLenum STROKE_PHANTOM_TYPE = GL_LINE_STRIP; |
15 | 16 |
|
@@ -133,6 +134,32 @@ bool entity::Stroke::redefineToShape(osg::MatrixTransform *t) |
133 | 134 | return true; |
134 | 135 | } |
135 | 136 |
|
| 137 | +osg::Node *entity::Stroke::getMeshRepresentation() const |
| 138 | +{ |
| 139 | + if (!m_isCurved){ |
| 140 | + qCritical("The stroke was never sampled and cannot be converted to the mesh."); |
| 141 | + return nullptr; |
| 142 | + } |
| 143 | + const osg::Vec3Array* vertices = static_cast<const osg::Vec3Array*>(this->getVertexArray()); |
| 144 | + if (!vertices){ |
| 145 | + qWarning("Could not extract the vertices."); |
| 146 | + return nullptr; |
| 147 | + } |
| 148 | + std::vector<osg::Vec3f> path; |
| 149 | + for (unsigned int i=0; i<vertices->size(); ++i){ |
| 150 | + if (i>0){ |
| 151 | + if (path.back() == vertices->at(i)) |
| 152 | + continue; |
| 153 | + } |
| 154 | + path.push_back(vertices->at(i)); |
| 155 | + } |
| 156 | + |
| 157 | + PTFTube extrusion(path, cher::STROKE_MESH_RADIUS, 8); |
| 158 | + extrusion.build(); |
| 159 | + |
| 160 | + return extrusion.generateTriMesh(); |
| 161 | +} |
| 162 | + |
136 | 163 | // read more on why: http://stackoverflow.com/questions/36655888/opengl-thick-and-smooth-non-broken-lines-in-3d |
137 | 164 | bool entity::Stroke::redefineToShader(osg::MatrixTransform *t) |
138 | 165 | { |
@@ -202,7 +229,7 @@ osg::Vec3Array *entity::Stroke::getCurvePoints(const osg::Vec3Array *bezierPts) |
202 | 229 | osg::ref_ptr<osg::Vec3Array> points = new osg::Vec3Array; |
203 | 230 |
|
204 | 231 | float delta = 1.f / cher::STROKE_SEGMENTS_NUMBER; |
205 | | - for (unsigned int j=0; j<bezierPts->size(); j=j+4){ |
| 232 | + for (unsigned int j=0; j<bezierPts->size(); j=j+4) { |
206 | 233 | auto b0 = bezierPts->at(j) |
207 | 234 | , b1 = bezierPts->at(j+1) |
208 | 235 | , b2 = bezierPts->at(j+2) |
|
0 commit comments