------------------------------------------------------------------------------------------------ Recursively constructs a scene node for the given parser node and returns it.
| 231 | // ------------------------------------------------------------------------------------------------ |
| 232 | // Recursively constructs a scene node for the given parser node and returns it. |
| 233 | aiNode *ColladaLoader::BuildHierarchy(const ColladaParser &pParser, const Collada::Node *pNode) { |
| 234 | // create a node for it |
| 235 | auto *node = new aiNode(); |
| 236 | |
| 237 | // find a name for the new node. It's more complicated than you might think |
| 238 | node->mName.Set(FindNameForNode(pNode)); |
| 239 | // if we're not using the unique IDs, hold onto them for reference and export |
| 240 | if (useColladaName) { |
| 241 | if (!pNode->mID.empty()) { |
| 242 | AddNodeMetaData(node, AI_METADATA_COLLADA_ID, aiString(pNode->mID)); |
| 243 | } |
| 244 | if (!pNode->mSID.empty()) { |
| 245 | AddNodeMetaData(node, AI_METADATA_COLLADA_SID, aiString(pNode->mSID)); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | // calculate the transformation matrix for it |
| 250 | node->mTransformation = pParser.CalculateResultTransform(pNode->mTransforms); |
| 251 | |
| 252 | // now resolve node instances |
| 253 | std::vector<const Node*> instances; |
| 254 | ResolveNodeInstances(pParser, pNode, instances); |
| 255 | |
| 256 | // add children. first the *real* ones |
| 257 | node->mNumChildren = static_cast<unsigned int>(pNode->mChildren.size() + instances.size()); |
| 258 | if (node->mNumChildren != 0) { |
| 259 | node->mChildren = new aiNode * [node->mNumChildren]; |
| 260 | } |
| 261 | |
| 262 | for (size_t a = 0; a < pNode->mChildren.size(); ++a) { |
| 263 | node->mChildren[a] = BuildHierarchy(pParser, pNode->mChildren[a]); |
| 264 | node->mChildren[a]->mParent = node; |
| 265 | } |
| 266 | |
| 267 | // ... and finally the resolved node instances |
| 268 | for (size_t a = 0; a < instances.size(); ++a) { |
| 269 | node->mChildren[pNode->mChildren.size() + a] = BuildHierarchy(pParser, instances[a]); |
| 270 | node->mChildren[pNode->mChildren.size() + a]->mParent = node; |
| 271 | } |
| 272 | |
| 273 | BuildMeshesForNode(pParser, pNode, node); |
| 274 | BuildCamerasForNode(pParser, pNode, node); |
| 275 | BuildLightsForNode(pParser, pNode, node); |
| 276 | |
| 277 | return node; |
| 278 | } |
| 279 | |
| 280 | // ------------------------------------------------------------------------------------------------ |
| 281 | // Resolve node instances |
nothing calls this directly
no test coverage detected