| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/android/vr_shell/gltf_parser.h" | 5 #include "chrome/browser/android/vr_shell/gltf_parser.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { | 199 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { |
| 200 const base::DictionaryValue* mesh_dict; | 200 const base::DictionaryValue* mesh_dict; |
| 201 if (!it.value().GetAsDictionary(&mesh_dict)) | 201 if (!it.value().GetAsDictionary(&mesh_dict)) |
| 202 return false; | 202 return false; |
| 203 | 203 |
| 204 auto mesh = base::MakeUnique<gltf::Mesh>(); | 204 auto mesh = base::MakeUnique<gltf::Mesh>(); |
| 205 const base::ListValue* list; | 205 const base::ListValue* list; |
| 206 if (mesh_dict->GetList("primitives", &list)) { | 206 if (mesh_dict->GetList("primitives", &list)) { |
| 207 for (const auto& primitive_value : *list) { | 207 for (const auto& primitive_value : *list) { |
| 208 const base::DictionaryValue* primitive_dict; | 208 const base::DictionaryValue* primitive_dict; |
| 209 if (!primitive_value.GetAsDictionary(&primitive_dict)) | 209 if (!primitive_value->GetAsDictionary(&primitive_dict)) |
| 210 return false; | 210 return false; |
| 211 | 211 |
| 212 auto primitive = ProcessPrimitive(*primitive_dict); | 212 auto primitive = ProcessPrimitive(*primitive_dict); |
| 213 if (!primitive) | 213 if (!primitive) |
| 214 return false; | 214 return false; |
| 215 mesh->primitives.push_back(std::move(primitive)); | 215 mesh->primitives.push_back(std::move(primitive)); |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 | 218 |
| 219 mesh_ids_[it.key()] = asset_->AddMesh(std::move(mesh)); | 219 mesh_ids_[it.key()] = asset_->AddMesh(std::move(mesh)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { | 254 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { |
| 255 const base::DictionaryValue* node_dict; | 255 const base::DictionaryValue* node_dict; |
| 256 if (!it.value().GetAsDictionary(&node_dict)) | 256 if (!it.value().GetAsDictionary(&node_dict)) |
| 257 return false; | 257 return false; |
| 258 | 258 |
| 259 auto node = base::MakeUnique<gltf::Node>(); | 259 auto node = base::MakeUnique<gltf::Node>(); |
| 260 const base::ListValue* list; | 260 const base::ListValue* list; |
| 261 if (node_dict->GetList("meshes", &list)) { | 261 if (node_dict->GetList("meshes", &list)) { |
| 262 std::string mesh_key; | 262 std::string mesh_key; |
| 263 for (const auto& mesh_value : *list) { | 263 for (const auto& mesh_value : *list) { |
| 264 if (!mesh_value.GetAsString(&mesh_key)) | 264 if (!mesh_value->GetAsString(&mesh_key)) |
| 265 return false; | 265 return false; |
| 266 auto mesh_it = mesh_ids_.find(mesh_key); | 266 auto mesh_it = mesh_ids_.find(mesh_key); |
| 267 if (mesh_it == mesh_ids_.end()) | 267 if (mesh_it == mesh_ids_.end()) |
| 268 return false; | 268 return false; |
| 269 node->meshes.push_back(asset_->GetMesh(mesh_it->second)); | 269 node->meshes.push_back(asset_->GetMesh(mesh_it->second)); |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 | 272 |
| 273 nodes[it.key()] = node.get(); | 273 nodes[it.key()] = node.get(); |
| 274 node_ids_[it.key()] = asset_->AddNode(std::move(node)); | 274 node_ids_[it.key()] = asset_->AddNode(std::move(node)); |
| 275 } | 275 } |
| 276 | 276 |
| 277 // Processing children after all nodes have been added to the asset. | 277 // Processing children after all nodes have been added to the asset. |
| 278 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { | 278 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { |
| 279 const base::DictionaryValue* node_dict; | 279 const base::DictionaryValue* node_dict; |
| 280 it.value().GetAsDictionary(&node_dict); | 280 it.value().GetAsDictionary(&node_dict); |
| 281 | 281 |
| 282 gltf::Node* node = nodes[it.key()]; | 282 gltf::Node* node = nodes[it.key()]; |
| 283 const base::ListValue* list; | 283 const base::ListValue* list; |
| 284 if (node_dict->GetList("children", &list)) { | 284 if (node_dict->GetList("children", &list)) { |
| 285 std::string node_key; | 285 std::string node_key; |
| 286 for (const auto& mesh_value : *list) { | 286 for (const auto& mesh_value : *list) { |
| 287 if (!mesh_value.GetAsString(&node_key)) | 287 if (!mesh_value->GetAsString(&node_key)) |
| 288 return false; | 288 return false; |
| 289 auto node_it = nodes.find(node_key); | 289 auto node_it = nodes.find(node_key); |
| 290 if (node_it == nodes.end()) | 290 if (node_it == nodes.end()) |
| 291 return false; | 291 return false; |
| 292 node->children.push_back(node_it->second); | 292 node->children.push_back(node_it->second); |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 | 296 |
| 297 return true; | 297 return true; |
| 298 } | 298 } |
| 299 | 299 |
| 300 bool GltfParser::SetScenes(const base::DictionaryValue& dict) { | 300 bool GltfParser::SetScenes(const base::DictionaryValue& dict) { |
| 301 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { | 301 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { |
| 302 const base::DictionaryValue* scene_dict; | 302 const base::DictionaryValue* scene_dict; |
| 303 if (!it.value().GetAsDictionary(&scene_dict)) | 303 if (!it.value().GetAsDictionary(&scene_dict)) |
| 304 return false; | 304 return false; |
| 305 | 305 |
| 306 auto scene = base::MakeUnique<gltf::Scene>(); | 306 auto scene = base::MakeUnique<gltf::Scene>(); |
| 307 const base::ListValue* list; | 307 const base::ListValue* list; |
| 308 if (scene_dict->GetList("nodes", &list)) { | 308 if (scene_dict->GetList("nodes", &list)) { |
| 309 std::string node_key; | 309 std::string node_key; |
| 310 for (const auto& node_value : *list) { | 310 for (const auto& node_value : *list) { |
| 311 if (!node_value.GetAsString(&node_key)) | 311 if (!node_value->GetAsString(&node_key)) |
| 312 return false; | 312 return false; |
| 313 auto node_it = node_ids_.find(node_key); | 313 auto node_it = node_ids_.find(node_key); |
| 314 if (node_it == node_ids_.end()) | 314 if (node_it == node_ids_.end()) |
| 315 return false; | 315 return false; |
| 316 scene->nodes.push_back(asset_->GetNode(node_it->second)); | 316 scene->nodes.push_back(asset_->GetNode(node_it->second)); |
| 317 } | 317 } |
| 318 } | 318 } |
| 319 | 319 |
| 320 scene_ids_[it.key()] = asset_->AddScene(std::move(scene)); | 320 scene_ids_[it.key()] = asset_->AddScene(std::move(scene)); |
| 321 } | 321 } |
| 322 return true; | 322 return true; |
| 323 } | 323 } |
| 324 | 324 |
| 325 void GltfParser::Clear() { | 325 void GltfParser::Clear() { |
| 326 asset_.reset(); | 326 asset_.reset(); |
| 327 path_.clear(); | 327 path_.clear(); |
| 328 buffer_ids_.clear(); | 328 buffer_ids_.clear(); |
| 329 buffer_view_ids_.clear(); | 329 buffer_view_ids_.clear(); |
| 330 accessor_ids_.clear(); | 330 accessor_ids_.clear(); |
| 331 node_ids_.clear(); | 331 node_ids_.clear(); |
| 332 mesh_ids_.clear(); | 332 mesh_ids_.clear(); |
| 333 scene_ids_.clear(); | 333 scene_ids_.clear(); |
| 334 } | 334 } |
| 335 | 335 |
| 336 } // namespace vr_shell | 336 } // namespace vr_shell |
| OLD | NEW |