]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/NodeAndDrawableVisitor.cxx
Work around apparent OSG 3.2.0 normal binding bug.
[simgear.git] / simgear / scene / util / NodeAndDrawableVisitor.cxx
1 /* -*-c++-*-
2  *
3  * Copyright (C) 2008 Tim Moore
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  * MA 02110-1301, USA.
19  *
20  */
21
22 #include <osg/Drawable>
23 #include <osg/Geode>
24
25 #include "NodeAndDrawableVisitor.hxx"
26
27 namespace simgear
28 {
29 using namespace osg;
30
31 NodeAndDrawableVisitor::NodeAndDrawableVisitor(NodeVisitor::TraversalMode tm) :
32     NodeVisitor(tm)
33 {
34 }
35
36 NodeAndDrawableVisitor::NodeAndDrawableVisitor(NodeVisitor::VisitorType type,
37                                                NodeVisitor::TraversalMode tm) :
38     NodeVisitor(type, tm)
39 {
40 }
41
42 NodeAndDrawableVisitor::~NodeAndDrawableVisitor()
43 {
44 }
45
46 void NodeAndDrawableVisitor::apply(Node& node)
47 {
48     traverse(node);
49 }
50
51 void NodeAndDrawableVisitor::apply(Drawable& Drawable)
52 {
53 }
54
55 void NodeAndDrawableVisitor::traverse(Node& node)
56 {
57     TraversalMode tm = getTraversalMode();
58     if (tm == TRAVERSE_NONE) {
59         return;
60     } else if (tm == TRAVERSE_PARENTS) {
61         NodeVisitor::traverse(node);
62         return;
63     }
64     Geode* geode = dynamic_cast<Geode*>(&node);
65     if (geode) {
66         unsigned numDrawables = geode->getNumDrawables();
67         for (unsigned i = 0; i < numDrawables; ++i)
68             apply(*geode->getDrawable(i));
69     } else {
70         NodeVisitor::traverse(node);
71     }
72 }
73 }