| 45 | { |
| 46 | |
| 47 | struct CollectTriangles |
| 48 | { |
| 49 | CollectTriangles() |
| 50 | { |
| 51 | verts = new osg::Vec3Array(); |
| 52 | } |
| 53 | #ifdef OSG_VERSION_GREATER_THAN |
| 54 | #if OSG_VERSION_GREATER_THAN(3,4,0) |
| 55 | inline void operator () (const osg::Vec3& v1, const osg::Vec3& v2, const osg::Vec3& v3) |
| 56 | #elif OSG_VERSION_GREATER_THAN(3, 2, 0) |
| 57 | inline void operator () (const osg::Vec3& v1, const osg::Vec3& v2, const osg::Vec3& v3, bool treatVertexDataAsTemporary) |
| 58 | #else |
| 59 | inline void operator () (const osg::Vec3& v1, const osg::Vec3& v2, const osg::Vec3& v3) |
| 60 | #endif |
| 61 | #else |
| 62 | inline void operator () (const osg::Vec3& v1, const osg::Vec3& v2, const osg::Vec3& v3) |
| 63 | #endif |
| 64 | { |
| 65 | verts->push_back(v1); |
| 66 | verts->push_back(v2); |
| 67 | verts->push_back(v3); |
| 68 | } |
| 69 | |
| 70 | osg::ref_ptr< osg::Vec3Array > verts; |
| 71 | }; |
| 72 | |
| 73 | struct CollectTrianglesVisitor : public osg::NodeVisitor |
| 74 | { |
| 75 | CollectTrianglesVisitor() : |
| 76 | osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | void apply(osg::Transform& transform) |
| 81 | { |
| 82 | osg::Matrix matrix; |
| 83 | if (!_matrixStack.empty()) matrix = _matrixStack.back(); |
| 84 | |
| 85 | transform.computeLocalToWorldMatrix(matrix, this); |
| 86 | |
| 87 | pushMatrix(matrix); |
| 88 | |
| 89 | traverse(transform); |
| 90 | |
| 91 | popMatrix(); |
| 92 | } |
| 93 | |
| 94 | void apply(osg::Geode& geode) |
| 95 | { |
| 96 | for (unsigned int i = 0; i<geode.getNumDrawables(); ++i) |
| 97 | { |
| 98 | osg::TriangleFunctor<CollectTriangles> triangleCollector; |
| 99 | geode.getDrawable(i)->accept(triangleCollector); |
| 100 | for (unsigned int j = 0; j < triangleCollector.verts->size(); j++) |
| 101 | { |
| 102 | osg::Matrix matrix; |
| 103 | if (!_matrixStack.empty()) |
| 104 | { |
nothing calls this directly
no test coverage detected