From 35fbe3ffb4e02ff98299576388ae568af8cf616e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 20 Jul 2010 10:46:27 +0000 Subject: [PATCH] Implemented boundary polygon creation based on the refined boundary segments --- examples/osgtext3D/osgtext3D.cpp | 145 +++++++++++++++++++++++++------ 1 file changed, 117 insertions(+), 28 deletions(-) diff --git a/examples/osgtext3D/osgtext3D.cpp b/examples/osgtext3D/osgtext3D.cpp index 7abbd5ba3..13745a228 100644 --- a/examples/osgtext3D/osgtext3D.cpp +++ b/examples/osgtext3D/osgtext3D.cpp @@ -37,7 +37,7 @@ osg::Vec3 computeRayIntersectionPoint(const osg::Vec3& a, const osg::Vec3& an, c float denominator = ( cn.x() * an.y() - cn.y() * an.x()); if (denominator==0.0) { - OSG_NOTICE<<"computeRayIntersectionPoint()<(orig_geometry->getVertexArray()); osg::Geometry::PrimitiveSetList& orig_primitives = orig_geometry->getPrimitiveSetList(); @@ -408,10 +464,17 @@ osg::Geometry* computeBevelEdge(osg::Geometry* orig_geometry) osg::Geometry* computeThickness(osg::Geometry* orig_geometry, float thickness) { - OSG_NOTICE<<"computeThickness("<(orig_geometry->getVertexArray()); osg::Geometry::PrimitiveSetList& orig_primitives = orig_geometry->getPrimitiveSetList(); + osg::Geometry* new_geometry = new osg::Geometry; + + osg::Vec4Array* new_colours = new osg::Vec4Array; + new_colours->push_back(osg::Vec4(1.0,1.0,0.0,1.0)); + new_geometry->setColorArray(new_colours); + new_geometry->setColorBinding(osg::Geometry::BIND_OVERALL); + for(osg::Geometry::PrimitiveSetList::iterator itr = orig_primitives.begin(); itr != orig_primitives.end(); ++itr) @@ -423,12 +486,12 @@ osg::Geometry* computeThickness(osg::Geometry* orig_geometry, float thickness) boundary.computeAllThickness(); boundary.removeAllSegmentsBelowThickness(thickness); + boundary.addBoundaryToGeometry(new_geometry, thickness); } } - return 0; + return new_geometry; } - int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); @@ -446,12 +509,24 @@ int main(int argc, char** argv) while(arguments.read("-f",fontFile)) {} std::string word("This is a simple test"); + + while(arguments.read("--ascii")) + { + word.clear(); + for(unsigned int c=' '; c<=127;++c) + { + word.push_back(c); + } + } + while(arguments.read("-w",word)) {} osg::ref_ptr font = osgText::readFont3DFile(fontFile); if (!font) return 1; OSG_NOTICE<<"Read font "<setColorArray(colours); geometry->setColorBinding(osg::Geometry::BIND_OVERALL); - // computeBoundaryAngles(geometry); + osg::Geometry* bevel = 0; + if (useOldBoundaryCalc) + { + bevel = computeBevelEdge(geometry); + } + else + { + bevel = computeThickness(geometry, thickness); + } - osg::Geometry* bevel = computeBevelEdge(geometry); - geode->addDrawable(bevel); - - computeThickness(geometry, thickness); + if (bevel) geode->addDrawable(bevel); if (useTessellator) { - osgUtil::Tessellator ts; - ts.setWindingType(osgUtil::Tessellator::TESS_WINDING_POSITIVE); - ts.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); - ts.retessellatePolygons(*geometry); + if (geometry) + { + osgUtil::Tessellator ts; + ts.setWindingType(osgUtil::Tessellator::TESS_WINDING_POSITIVE); + ts.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); + ts.retessellatePolygons(*geometry); + } - ts.retessellatePolygons(*bevel); + if (bevel) + { + osgUtil::Tessellator ts; + ts.setWindingType(osgUtil::Tessellator::TESS_WINDING_POSITIVE); + ts.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); + ts.retessellatePolygons(*bevel); + } }