Determine unique id and add the name and id to the maps @param type object type @param index object index @param name in/out. Caller to set the original name if known. @param idStr in/out. Caller to set the preferred id if known.
| 1737 | // @param name in/out. Caller to set the original name if known. |
| 1738 | // @param idStr in/out. Caller to set the preferred id if known. |
| 1739 | ColladaExporter::NameIdPair ColladaExporter::AddObjectIndexToMaps(AiObjectType type, size_t index) { |
| 1740 | |
| 1741 | std::string name; |
| 1742 | std::string idStr; |
| 1743 | std::string idPostfix; |
| 1744 | |
| 1745 | // Get the name and id postfix |
| 1746 | switch (type) { |
| 1747 | case AiObjectType::Mesh: |
| 1748 | name = mScene->mMeshes[index]->mName.C_Str(); |
| 1749 | break; |
| 1750 | case AiObjectType::Material: |
| 1751 | name = mScene->mMaterials[index]->GetName().C_Str(); |
| 1752 | break; |
| 1753 | case AiObjectType::Animation: |
| 1754 | name = mScene->mAnimations[index]->mName.C_Str(); |
| 1755 | break; |
| 1756 | case AiObjectType::Light: |
| 1757 | name = mScene->mLights[index]->mName.C_Str(); |
| 1758 | idPostfix = "-light"; |
| 1759 | break; |
| 1760 | case AiObjectType::Camera: |
| 1761 | name = mScene->mCameras[index]->mName.C_Str(); |
| 1762 | idPostfix = "-camera"; |
| 1763 | break; |
| 1764 | case AiObjectType::Count: |
| 1765 | throw std::logic_error("ColladaExporter::AiObjectType::Count is not an object type"); |
| 1766 | } |
| 1767 | |
| 1768 | if (name.empty()) { |
| 1769 | // Default ids if empty name |
| 1770 | switch (type) { |
| 1771 | case AiObjectType::Mesh: idStr = std::string("mesh_"); break; |
| 1772 | case AiObjectType::Material: idStr = std::string("material_"); break; // This one should never happen |
| 1773 | case AiObjectType::Animation: idStr = std::string("animation_"); break; |
| 1774 | case AiObjectType::Light: idStr = std::string("light_"); break; |
| 1775 | case AiObjectType::Camera: idStr = std::string("camera_"); break; |
| 1776 | case AiObjectType::Count: throw std::logic_error("ColladaExporter::AiObjectType::Count is not an object type"); |
| 1777 | } |
| 1778 | idStr.append(ai_to_string(index)); |
| 1779 | } else { |
| 1780 | idStr = XMLIDEncode(name); |
| 1781 | } |
| 1782 | |
| 1783 | if (!name.empty()) { |
| 1784 | name = XMLEscape(name); |
| 1785 | } |
| 1786 | |
| 1787 | idStr = MakeUniqueId(mUniqueIds, idStr, idPostfix); |
| 1788 | |
| 1789 | // Add to maps |
| 1790 | mUniqueIds.insert(idStr); |
| 1791 | GetObjectIdMap(type).insert(std::make_pair(index, idStr)); |
| 1792 | GetObjectNameMap(type).insert(std::make_pair(index, name)); |
| 1793 | |
| 1794 | return std::make_pair(name, idStr); |
| 1795 | } |
| 1796 |
nothing calls this directly
no test coverage detected