MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / findInputSource

Function findInputSource

Engine/source/ts/collada/colladaAppMesh.cpp:61–102  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Find a source with matching ID. Cannot use the DOM .getElement method since some lame Collada exporters generate s with non-unique IDs.

Source from the content-addressed store, hash-verified

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.
61daeElement* 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

Callers 5

initSourceReaderMethod · 0.85
classifyInputsMethod · 0.85
animatesMatFrameMethod · 0.85
animatesFrameMethod · 0.85
getMorphVertexDataMethod · 0.85

Calls 8

dStrEqualFunction · 0.85
getAttributeMethod · 0.80
getElementTypeMethod · 0.45
getSourceMethod · 0.45
getElementMethod · 0.45
c_strMethod · 0.45
getCountMethod · 0.45
getChildrenMethod · 0.45

Tested by

no test coverage detected