| 854 | } |
| 855 | |
| 856 | S32 TSShape::readName(Stream * s, bool addName) |
| 857 | { |
| 858 | static char buffer[256]; |
| 859 | U32 sz; |
| 860 | S32 nameIndex = -1; |
| 861 | s->read(&sz); |
| 862 | if (sz>0 && sz<255) |
| 863 | { |
| 864 | s->read(sz,buffer); |
| 865 | buffer[sz] = '\0'; |
| 866 | nameIndex = findName(buffer); |
| 867 | |
| 868 | // Many modeling apps don't support spaces in names, so if the lookup |
| 869 | // failed, try the name again with spaces replaced by underscores |
| 870 | if (nameIndex < 0) |
| 871 | { |
| 872 | while (char *p = dStrchr(buffer, ' ')) |
| 873 | *p = '_'; |
| 874 | nameIndex = findName(buffer); |
| 875 | } |
| 876 | |
| 877 | if (nameIndex<0 && addName) |
| 878 | { |
| 879 | nameIndex = names.size(); |
| 880 | names.increment(); |
| 881 | names.last() = buffer; |
| 882 | } |
| 883 | } |
| 884 | else |
| 885 | Con::errorf("invalid TSShape::readName length!"); |
| 886 | |
| 887 | return nameIndex; |
| 888 | } |