diff --git a/examples/osgtext3D/osgtext3D.cpp b/examples/osgtext3D/osgtext3D.cpp index 8fd8cd676..1df06669e 100644 --- a/examples/osgtext3D/osgtext3D.cpp +++ b/examples/osgtext3D/osgtext3D.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +34,72 @@ extern int main_orig(int, char**); extern int main_test(int, char**); +class BevelProfile +{ + public: + + typedef std::vector Vertices; + + BevelProfile() + { + flatBevel(); + } + + void flatBevel(float width=0.25f) + { + _vertices.clear(); + + if (width>0.5f) width = 0.5f; + + _vertices.push_back(osg::Vec2(0.0f,0.0f)); + + _vertices.push_back(osg::Vec2(width,1.0f)); + + if (width<0.5f) _vertices.push_back(osg::Vec2(1-width,1.0f)); + + _vertices.push_back(osg::Vec2(1.0f,0.0f)); + } + + void roundedBevel(float width=0.5f, unsigned int numSteps=10) + { + _vertices.clear(); + + if (width>0.5f) width = 0.5f; + + unsigned int i = 0; + for(; i<=numSteps; ++i) + { + float angle = float(osg::PI)*0.5f*(float(i)/float(numSteps)); + _vertices.push_back( osg::Vec2((1.0f-cosf(angle))*width, sinf(angle)) ); + } + + // start the second half one into the curve if the width is half way across + i = width<0.5f ? 0 : 1; + for(; i<=numSteps; ++i) + { + float angle = float(osg::PI)*0.5f*(float(numSteps-i)/float(numSteps)); + _vertices.push_back( osg::Vec2(1.0-(1.0f-cosf(angle))*width, sin(angle)) ); + } + } + + void print(std::ostream& fout) + { + OSG_NOTICE<<"print bevel"< group = new osg::Group; osg::Vec3 position; + + for(unsigned int i=0; i glyph = font->getGlyph(word[i]); @@ -433,48 +640,36 @@ int main(int argc, char** argv) osg::ref_ptr face_and_bevel = computeThickness(geometry, thickness); - osg::Geometry* bevel = getGeometryComponent(face_and_bevel, true); - if (bevel) + osg::ref_ptr face = getGeometryComponent(face_and_bevel, false); + + if (face.valid()) { - geode->addDrawable(bevel); - osgUtil::SmoothingVisitor smoother; - smoother.setCreaseAngle(osg::DegreesToRadians(creaseAngle)); - geode->accept(smoother); + osgUtil::Tessellator ts; + ts.setWindingType(osgUtil::Tessellator::TESS_WINDING_POSITIVE); + ts.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); + ts.retessellatePolygons(*face); + + osg::ref_ptr faces = computeFrontAndBackGeometry(face.get(), width); + if (faces.valid()) geode->addDrawable(faces.get()); } - osg::Geometry* face = getGeometryComponent(face_and_bevel, false); - if (face) geode->addDrawable(face); + osg::ref_ptr bevel_strip = getGeometryComponent(face_and_bevel, true); + osg::ref_ptr bevel = computeBevelGeometry(bevel_strip, profile, width); - - if (useTessellator) + if (bevel.valid()) { - if (geometry) - { - osgUtil::Tessellator ts; - ts.setWindingType(osgUtil::Tessellator::TESS_WINDING_POSITIVE); - ts.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); - ts.retessellatePolygons(*geometry); - } - - if (face) - { - osgUtil::Tessellator ts; - ts.setWindingType(osgUtil::Tessellator::TESS_WINDING_POSITIVE); - ts.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); - ts.retessellatePolygons(*face); - } - + geode->addDrawable(bevel.get()); } - geode->addDrawable(geometry.get()); + osgUtil::SmoothingVisitor smoother; + smoother.setCreaseAngle(osg::DegreesToRadians(creaseAngle)); + geode->accept(smoother); transform->addChild(geode.get()); group->addChild(transform.get()); } - - std::string filename; if (arguments.read("-o", filename)) osgDB::writeNodeFile(*group, filename);