| 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/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 | 10 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { | 148 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { |
| 149 const base::DictionaryValue* mesh_dict; | 149 const base::DictionaryValue* mesh_dict; |
| 150 if (!it.value().GetAsDictionary(&mesh_dict)) | 150 if (!it.value().GetAsDictionary(&mesh_dict)) |
| 151 return false; | 151 return false; |
| 152 | 152 |
| 153 auto mesh = base::MakeUnique<gltf::Mesh>(); | 153 auto mesh = base::MakeUnique<gltf::Mesh>(); |
| 154 const base::ListValue* list; | 154 const base::ListValue* list; |
| 155 if (mesh_dict->GetList("primitives", &list)) { | 155 if (mesh_dict->GetList("primitives", &list)) { |
| 156 for (const auto& primitive_value : *list) { | 156 for (const auto& primitive_value : *list) { |
| 157 const base::DictionaryValue* primitive_dict; | 157 const base::DictionaryValue* primitive_dict; |
| 158 if (!primitive_value->GetAsDictionary(&primitive_dict)) | 158 if (!primitive_value.GetAsDictionary(&primitive_dict)) |
| 159 return false; | 159 return false; |
| 160 | 160 |
| 161 auto primitive = ProcessPrimitive(*primitive_dict); | 161 auto primitive = ProcessPrimitive(*primitive_dict); |
| 162 if (!primitive) | 162 if (!primitive) |
| 163 return false; | 163 return false; |
| 164 mesh->primitives.push_back(std::move(primitive)); | 164 mesh->primitives.push_back(std::move(primitive)); |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 | 167 |
| 168 mesh_ids_[it.key()] = asset_->AddMesh(std::move(mesh)); | 168 mesh_ids_[it.key()] = asset_->AddMesh(std::move(mesh)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { | 203 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { |
| 204 const base::DictionaryValue* node_dict; | 204 const base::DictionaryValue* node_dict; |
| 205 if (!it.value().GetAsDictionary(&node_dict)) | 205 if (!it.value().GetAsDictionary(&node_dict)) |
| 206 return false; | 206 return false; |
| 207 | 207 |
| 208 auto node = base::MakeUnique<gltf::Node>(); | 208 auto node = base::MakeUnique<gltf::Node>(); |
| 209 const base::ListValue* list; | 209 const base::ListValue* list; |
| 210 if (node_dict->GetList("meshes", &list)) { | 210 if (node_dict->GetList("meshes", &list)) { |
| 211 std::string mesh_key; | 211 std::string mesh_key; |
| 212 for (const auto& mesh_value : *list) { | 212 for (const auto& mesh_value : *list) { |
| 213 if (!mesh_value->GetAsString(&mesh_key)) | 213 if (!mesh_value.GetAsString(&mesh_key)) |
| 214 return false; | 214 return false; |
| 215 auto mesh_it = mesh_ids_.find(mesh_key); | 215 auto mesh_it = mesh_ids_.find(mesh_key); |
| 216 if (mesh_it == mesh_ids_.end()) | 216 if (mesh_it == mesh_ids_.end()) |
| 217 return false; | 217 return false; |
| 218 node->meshes.push_back(asset_->GetMesh(mesh_it->second)); | 218 node->meshes.push_back(asset_->GetMesh(mesh_it->second)); |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 nodes[it.key()] = node.get(); | 222 nodes[it.key()] = node.get(); |
| 223 node_ids_[it.key()] = asset_->AddNode(std::move(node)); | 223 node_ids_[it.key()] = asset_->AddNode(std::move(node)); |
| 224 } | 224 } |
| 225 | 225 |
| 226 // Processing children after all nodes have been added to the asset. | 226 // Processing children after all nodes have been added to the asset. |
| 227 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { | 227 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { |
| 228 const base::DictionaryValue* node_dict; | 228 const base::DictionaryValue* node_dict; |
| 229 it.value().GetAsDictionary(&node_dict); | 229 it.value().GetAsDictionary(&node_dict); |
| 230 | 230 |
| 231 gltf::Node* node = nodes[it.key()]; | 231 gltf::Node* node = nodes[it.key()]; |
| 232 const base::ListValue* list; | 232 const base::ListValue* list; |
| 233 if (node_dict->GetList("children", &list)) { | 233 if (node_dict->GetList("children", &list)) { |
| 234 std::string node_key; | 234 std::string node_key; |
| 235 for (const auto& mesh_value : *list) { | 235 for (const auto& mesh_value : *list) { |
| 236 if (!mesh_value->GetAsString(&node_key)) | 236 if (!mesh_value.GetAsString(&node_key)) |
| 237 return false; | 237 return false; |
| 238 auto node_it = nodes.find(node_key); | 238 auto node_it = nodes.find(node_key); |
| 239 if (node_it == nodes.end()) | 239 if (node_it == nodes.end()) |
| 240 return false; | 240 return false; |
| 241 node->children.push_back(node_it->second); | 241 node->children.push_back(node_it->second); |
| 242 } | 242 } |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 | 245 |
| 246 return true; | 246 return true; |
| 247 } | 247 } |
| 248 | 248 |
| 249 bool GltfParser::SetScenes(const base::DictionaryValue& dict) { | 249 bool GltfParser::SetScenes(const base::DictionaryValue& dict) { |
| 250 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { | 250 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { |
| 251 const base::DictionaryValue* scene_dict; | 251 const base::DictionaryValue* scene_dict; |
| 252 if (!it.value().GetAsDictionary(&scene_dict)) | 252 if (!it.value().GetAsDictionary(&scene_dict)) |
| 253 return false; | 253 return false; |
| 254 | 254 |
| 255 auto scene = base::MakeUnique<gltf::Scene>(); | 255 auto scene = base::MakeUnique<gltf::Scene>(); |
| 256 const base::ListValue* list; | 256 const base::ListValue* list; |
| 257 if (scene_dict->GetList("nodes", &list)) { | 257 if (scene_dict->GetList("nodes", &list)) { |
| 258 std::string node_key; | 258 std::string node_key; |
| 259 for (const auto& node_value : *list) { | 259 for (const auto& node_value : *list) { |
| 260 if (!node_value->GetAsString(&node_key)) | 260 if (!node_value.GetAsString(&node_key)) |
| 261 return false; | 261 return false; |
| 262 auto node_it = node_ids_.find(node_key); | 262 auto node_it = node_ids_.find(node_key); |
| 263 if (node_it == node_ids_.end()) | 263 if (node_it == node_ids_.end()) |
| 264 return false; | 264 return false; |
| 265 scene->nodes.push_back(asset_->GetNode(node_it->second)); | 265 scene->nodes.push_back(asset_->GetNode(node_it->second)); |
| 266 } | 266 } |
| 267 } | 267 } |
| 268 | 268 |
| 269 scene_ids_[it.key()] = asset_->AddScene(std::move(scene)); | 269 scene_ids_[it.key()] = asset_->AddScene(std::move(scene)); |
| 270 } | 270 } |
| 271 return true; | 271 return true; |
| 272 } | 272 } |
| 273 | 273 |
| 274 } // namespace vr_shell | 274 } // namespace vr_shell |
| OLD | NEW |