------------------------------------------------------------------------------------------------
| 74 | |
| 75 | // ------------------------------------------------------------------------------------------------ |
| 76 | const Object* LazyObject::Get(bool dieOnError) { |
| 77 | if(IsBeingConstructed() || FailedToConstruct()) { |
| 78 | return nullptr; |
| 79 | } |
| 80 | |
| 81 | if (object.get()) { |
| 82 | return object.get(); |
| 83 | } |
| 84 | |
| 85 | const Token& key = element.KeyToken(); |
| 86 | const TokenList& tokens = element.Tokens(); |
| 87 | |
| 88 | if(tokens.size() < 3) { |
| 89 | DOMError("expected at least 3 tokens: id, name and class tag",&element); |
| 90 | } |
| 91 | |
| 92 | const char* err; |
| 93 | std::string name = ParseTokenAsString(*tokens[1],err); |
| 94 | if (err) { |
| 95 | DOMError(err,&element); |
| 96 | } |
| 97 | |
| 98 | // small fix for binary reading: binary fbx files don't use |
| 99 | // prefixes such as Model:: in front of their names. The |
| 100 | // loading code expects this at many places, though! |
| 101 | // so convert the binary representation (a 0x0001) to the |
| 102 | // double colon notation. |
| 103 | if(tokens[1]->IsBinary()) { |
| 104 | for (size_t i = 0; i < name.length(); ++i) { |
| 105 | if (name[i] == 0x0 && name[i+1] == 0x1) { |
| 106 | name = name.substr(i+2) + "::" + name.substr(0,i); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | const std::string classtag = ParseTokenAsString(*tokens[2],err); |
| 112 | if (err) { |
| 113 | DOMError(err,&element); |
| 114 | } |
| 115 | |
| 116 | // prevent recursive calls |
| 117 | flags |= BEING_CONSTRUCTED; |
| 118 | |
| 119 | try { |
| 120 | // this needs to be relatively fast since it happens a lot, |
| 121 | // so avoid constructing strings all the time. |
| 122 | const char* obtype = key.begin(); |
| 123 | const size_t length = static_cast<size_t>(key.end()-key.begin()); |
| 124 | |
| 125 | // For debugging |
| 126 | //dumpObjectClassInfo( objtype, classtag ); |
| 127 | |
| 128 | if (!strncmp(obtype,"Geometry",length)) { |
| 129 | if (!strcmp(classtag.c_str(),"Mesh")) { |
| 130 | object.reset(new MeshGeometry(id,element,name,doc)); |
| 131 | } |
| 132 | if (!strcmp(classtag.c_str(), "Shape")) { |
| 133 | object.reset(new ShapeGeometry(id, element, name, doc)); |
no test coverage detected