@@ -218,23 +218,32 @@ Node* Node::getRootNode() const
218218}
219219
220220Node* Node::findNode (const char * id, bool recursive, bool exactMatch) const
221+ {
222+ return findNode (id, recursive, exactMatch, false );
223+ }
224+
225+ Node* Node::findNode (const char * id, bool recursive, bool exactMatch, bool skipSkin) const
221226{
222227 GP_ASSERT (id);
223228
224- // If the drawable is a model with a mesh skin, search the skin's hierarchy as well.
225- Node* rootNode = NULL ;
226- Model* model = dynamic_cast <Model*>(_drawable);
227- if (model)
229+ // If not skipSkin hierarchy, try searching the skin hierarchy
230+ if (!skipSkin)
228231 {
229- if (model->getSkin () != NULL && (rootNode = model->getSkin ()->_rootNode ) != NULL )
232+ // If the drawable is a model with a mesh skin, search the skin's hierarchy as well.
233+ Node* rootNode = NULL ;
234+ Model* model = dynamic_cast <Model*>(_drawable);
235+ if (model)
230236 {
231- if ((exactMatch && rootNode->_id == id) || (!exactMatch && rootNode->_id .find (id) == 0 ))
232- return rootNode;
233-
234- Node* match = rootNode->findNode (id, true , exactMatch);
235- if (match)
237+ if (model->getSkin () != NULL && (rootNode = model->getSkin ()->_rootNode ) != NULL )
236238 {
237- return match;
239+ if ((exactMatch && rootNode->_id == id) || (!exactMatch && rootNode->_id .find (id) == 0 ))
240+ return rootNode;
241+
242+ Node* match = rootNode->findNode (id, true , exactMatch, true );
243+ if (match)
244+ {
245+ return match;
246+ }
238247 }
239248 }
240249 }
@@ -252,7 +261,7 @@ Node* Node::findNode(const char* id, bool recursive, bool exactMatch) const
252261 {
253262 for (Node* child = getFirstChild (); child != NULL ; child = child->getNextSibling ())
254263 {
255- Node* match = child->findNode (id, true , exactMatch);
264+ Node* match = child->findNode (id, true , exactMatch, skipSkin );
256265 if (match)
257266 {
258267 return match;
@@ -263,25 +272,35 @@ Node* Node::findNode(const char* id, bool recursive, bool exactMatch) const
263272}
264273
265274unsigned int Node::findNodes (const char * id, std::vector<Node*>& nodes, bool recursive, bool exactMatch) const
275+ {
276+ return findNodes (id, nodes, recursive, exactMatch, false );
277+ }
278+
279+ unsigned int Node::findNodes (const char * id, std::vector<Node*>& nodes, bool recursive, bool exactMatch, bool skipSkin) const
266280{
267281 GP_ASSERT (id);
268282
269283 // If the drawable is a model with a mesh skin, search the skin's hierarchy as well.
270284 unsigned int count = 0 ;
271- Node* rootNode = NULL ;
272- Model* model = dynamic_cast <Model*>(_drawable);
273- if (model)
285+
286+ if (!skipSkin)
274287 {
275- if (model->getSkin () != NULL && (rootNode = model->getSkin ()->_rootNode ) != NULL )
288+ Node* rootNode = NULL ;
289+ Model* model = dynamic_cast <Model*>(_drawable);
290+ if (model)
276291 {
277- if ((exactMatch && rootNode-> _id == id) || (!exactMatch && rootNode-> _id . find (id) == 0 ) )
292+ if (model-> getSkin () != NULL && ( rootNode = model-> getSkin ()-> _rootNode ) != NULL )
278293 {
279- nodes.push_back (rootNode);
280- ++count;
294+ if ((exactMatch && rootNode->_id == id) || (!exactMatch && rootNode->_id .find (id) == 0 ))
295+ {
296+ nodes.push_back (rootNode);
297+ ++count;
298+ }
299+ count += rootNode->findNodes (id, nodes, recursive, exactMatch, true );
281300 }
282- count += rootNode->findNodes (id, nodes, true , exactMatch);
283301 }
284302 }
303+
285304 // Search immediate children first.
286305 for (Node* child = getFirstChild (); child != NULL ; child = child->getNextSibling ())
287306 {
@@ -297,7 +316,7 @@ unsigned int Node::findNodes(const char* id, std::vector<Node*>& nodes, bool rec
297316 {
298317 for (Node* child = getFirstChild (); child != NULL ; child = child->getNextSibling ())
299318 {
300- count += child->findNodes (id, nodes, true , exactMatch);
319+ count += child->findNodes (id, nodes, recursive , exactMatch, skipSkin );
301320 }
302321 }
303322
0 commit comments