------------------------------------------------------------------------------------------------ Parse an object section in an AC file
| 193 | // ------------------------------------------------------------------------------------------------ |
| 194 | // Parse an object section in an AC file |
| 195 | bool AC3DImporter::LoadObjectSection(std::vector<Object> &objects) { |
| 196 | if (!TokenMatch(mBuffer.data, "OBJECT", 6)) { |
| 197 | return false; |
| 198 | } |
| 199 | |
| 200 | SkipSpaces(&mBuffer.data, mBuffer.end); |
| 201 | |
| 202 | ++mNumMeshes; |
| 203 | |
| 204 | objects.emplace_back(); |
| 205 | Object &obj = objects.back(); |
| 206 | |
| 207 | aiLight *light = nullptr; |
| 208 | if (!ASSIMP_strincmp(mBuffer.data, "light", 5)) { |
| 209 | // This is a light source. Add it to the list |
| 210 | mLights->push_back(light = new aiLight()); |
| 211 | |
| 212 | // Return a point light with no attenuation |
| 213 | light->mType = aiLightSource_POINT; |
| 214 | light->mColorDiffuse = light->mColorSpecular = aiColor3D(1.f, 1.f, 1.f); |
| 215 | light->mAttenuationConstant = 1.f; |
| 216 | |
| 217 | // Generate a default name for both the light source and the node |
| 218 | light->mName.length = ::ai_snprintf(light->mName.data, AI_MAXLEN, "ACLight_%i", static_cast<unsigned int>(mLights->size()) - 1); |
| 219 | obj.name = std::string(light->mName.data); |
| 220 | |
| 221 | ASSIMP_LOG_VERBOSE_DEBUG("AC3D: Light source encountered"); |
| 222 | obj.type = Object::Light; |
| 223 | } else if (!ASSIMP_strincmp(mBuffer.data, "group", 5)) { |
| 224 | obj.type = Object::Group; |
| 225 | } else if (!ASSIMP_strincmp(mBuffer.data, "world", 5)) { |
| 226 | obj.type = Object::World; |
| 227 | } else { |
| 228 | obj.type = Object::Poly; |
| 229 | } |
| 230 | |
| 231 | while (GetNextLine()) { |
| 232 | if (TokenMatch(mBuffer.data, "kids", 4)) { |
| 233 | SkipSpaces(&mBuffer.data, mBuffer.end); |
| 234 | unsigned int num = strtoul10(mBuffer.data, &mBuffer.data); |
| 235 | GetNextLine(); |
| 236 | if (num) { |
| 237 | // load the children of this object recursively |
| 238 | obj.children.reserve(num); |
| 239 | for (unsigned int i = 0; i < num; ++i) { |
| 240 | if (!LoadObjectSection(obj.children)) { |
| 241 | ASSIMP_LOG_WARN("AC3D: wrong number of kids"); |
| 242 | break; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | return true; |
| 247 | } else if (TokenMatch(mBuffer.data, "name", 4)) { |
| 248 | SkipSpaces(&mBuffer.data, mBuffer.data); |
| 249 | mBuffer.data = AcGetString(mBuffer.data, mBuffer.end, obj.name); |
| 250 | |
| 251 | // If this is a light source, we'll also need to store |
| 252 | // the name of the node in it. |
nothing calls this directly
no test coverage detected