----------------------------------------------------------------------------- Find a source with matching ID. Cannot use the DOM .getElement method since some lame Collada exporters generate s with non-unique IDs.
| 59 | // Find a source with matching ID. Cannot use the DOM .getElement method since |
| 60 | // some lame Collada exporters generate <source>s with non-unique IDs. |
| 61 | daeElement* findInputSource(const daeElement* input) |
| 62 | { |
| 63 | // Try using the DOM .getElement method => the resolved element's parent |
| 64 | // should be the input's grandparent |
| 65 | daeElement* parent = ((daeElement*)input)->getParentElement(); |
| 66 | daeElement* grandparent = parent ? parent->getParentElement() : 0; |
| 67 | if (!grandparent) |
| 68 | return NULL; |
| 69 | |
| 70 | const domURIFragmentType* uri = 0; |
| 71 | if (input->getElementType() == COLLADA_TYPE::INPUTLOCAL) |
| 72 | uri = &daeSafeCast<domInputLocal>((daeElement*)input)->getSource(); |
| 73 | else if (input->getElementType() == COLLADA_TYPE::INPUTLOCALOFFSET) |
| 74 | uri = &daeSafeCast<domInputLocalOffset>((daeElement*)input)->getSource(); |
| 75 | if (!uri) |
| 76 | return NULL; |
| 77 | |
| 78 | daeElement* element = uri->getElement(); |
| 79 | if (element && element->getParentElement() == grandparent) |
| 80 | return element; |
| 81 | else |
| 82 | { |
| 83 | // Probably a non-unique ID => search for the matching element manually |
| 84 | |
| 85 | // Skip the leading '#' on source IDs |
| 86 | const char* id = uri->originalStr().c_str(); |
| 87 | if (id && (id[0] == '#')) |
| 88 | id++; |
| 89 | |
| 90 | for (S32 iChild = 0; iChild < grandparent->getChildren().getCount(); iChild++) |
| 91 | { |
| 92 | element = grandparent->getChildren()[iChild]; |
| 93 | if ((element->getElementType() != COLLADA_TYPE::SOURCE) && |
| 94 | (element->getElementType() != COLLADA_TYPE::VERTICES)) |
| 95 | continue; |
| 96 | |
| 97 | if (dStrEqual(id, element->getAttribute("id").c_str())) |
| 98 | return element; |
| 99 | } |
| 100 | } |
| 101 | return NULL; |
| 102 | } |
| 103 | |
| 104 | //----------------------------------------------------------------------------- |
| 105 | // Collada scatters the data required for geometry all over the place; this class |
no test coverage detected