| 236 | } |
| 237 | |
| 238 | void Scene::LoadSceneGraph(const Json::Value& nodeList, const std::shared_ptr<SceneGraphNode>& parent) |
| 239 | { |
| 240 | for (const auto& src : nodeList) |
| 241 | { |
| 242 | if (!src.isObject()) |
| 243 | { |
| 244 | log::warning("Non-object node in the scene graph definition."); |
| 245 | continue; |
| 246 | } |
| 247 | |
| 248 | std::string nodeName; |
| 249 | const auto& name = src["name"]; |
| 250 | if (name.isString()) |
| 251 | { |
| 252 | nodeName = name.asString(); |
| 253 | } |
| 254 | |
| 255 | std::shared_ptr<SceneGraphNode> customParent = parent; |
| 256 | const auto& parentNode = src["parent"]; |
| 257 | if (parentNode.isString()) |
| 258 | { |
| 259 | customParent = m_SceneGraph->FindNode(parentNode.asString()); |
| 260 | if (!customParent) |
| 261 | { |
| 262 | log::warning("Custom parent '%s' specified for node '%s' not found, skipping the node.", |
| 263 | parentNode.asCString(), nodeName.c_str()); |
| 264 | continue; |
| 265 | } |
| 266 | } |
| 267 | else if (!parentNode.isNull()) |
| 268 | { |
| 269 | log::warning("Custom parent specification for node '%s' is not a string, ignoring.", |
| 270 | nodeName.c_str()); |
| 271 | } |
| 272 | |
| 273 | std::shared_ptr<SceneGraphNode> dst; |
| 274 | |
| 275 | const auto& modelNode = src["model"]; |
| 276 | if (!modelNode.isNull()) |
| 277 | { |
| 278 | if (!modelNode.isIntegral()) |
| 279 | { |
| 280 | log::warning("Model references in the scene graph must be indices into the model array."); |
| 281 | continue; |
| 282 | } |
| 283 | |
| 284 | int modelIndex = modelNode.asInt(); |
| 285 | if (modelIndex < 0 || modelIndex >= int(m_Models.size())) |
| 286 | { |
| 287 | log::warning("Referenced model %d is not defined in the model array.", modelIndex); |
| 288 | continue; |
| 289 | } |
| 290 | |
| 291 | const auto& loadedModel = m_Models[modelIndex]; |
| 292 | if (!loadedModel.rootNode) |
| 293 | { |
| 294 | continue; |
| 295 | } |
nothing calls this directly
no test coverage detected