Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: chrome/browser/android/vr_shell/gltf_parser.h

Issue 2774653002: Support for parsing external file references in a glTF resource. (Closed)
Patch Set: Scoped holders and tests for parsing failures. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_PARSER_H_ 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_PARSER_H_
6 #define CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_PARSER_H_ 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_PARSER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <unordered_map> 10 #include <unordered_map>
11 11
12 #include "base/files/file_path.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chrome/browser/android/vr_shell/gltf_asset.h" 14 #include "chrome/browser/android/vr_shell/gltf_asset.h"
14 15
15 namespace vr_shell { 16 namespace vr_shell {
16 17
17 // Parser for glTF 1.0 specification 18 // Parser for glTF 1.0 specification
18 // https://github.com/KhronosGroup/glTF/tree/master/specification/1.0 19 // https://github.com/KhronosGroup/glTF/tree/master/specification/1.0
19 // Supported objects are limited to: buffers, bufferViews, accessors, 20 // Supported objects are limited to: buffers, bufferViews, accessors,
20 // meshes (limited), nodes (limited), scenes (limited). 21 // meshes (limited), nodes (limited), scenes (limited).
21 // Non-supported objects include: materials, techniques, skins, shaders, 22 // Non-supported objects include: materials, techniques, skins, shaders,
22 // programs, animations, cameras, images, textures, extensions. 23 // programs, animations, cameras, images, textures, extensions.
23 // This parser is not intended to be used on user or third-party data, 24 // This parser is not intended to be used on user or third-party data,
24 // but only on thoroughly tested Chromium resource files. 25 // but only on thoroughly tested Chromium resource files.
25 // TODO(acondor): Implement glTF 2.0 parser. gltf::Asset is mostly version 26 // TODO(acondor): Implement glTF 2.0 parser. gltf::Asset is mostly version
26 // agnostic. 27 // agnostic.
27 class GltfParser { 28 class GltfParser {
28 public: 29 public:
29 GltfParser(); 30 GltfParser();
30 ~GltfParser(); 31 ~GltfParser();
31 std::unique_ptr<gltf::Asset> Parse(const base::DictionaryValue& dict); 32 // Note: If your glTF references external files, this function will perform
33 // IO, and a base path must be specified.
34 std::unique_ptr<gltf::Asset> Parse(
35 const base::DictionaryValue& dict,
36 const base::FilePath& path = base::FilePath());
37 // Note: This function will perform IO.
38 std::unique_ptr<gltf::Asset> Parse(const base::FilePath& gltf_path);
32 39
33 private: 40 private:
34 bool ParseInternal(const base::DictionaryValue& dict); 41 struct Helper {
42 std::unique_ptr<gltf::Asset> asset;
43 base::FilePath path;
44 std::unordered_map<std::string, std::size_t> buffer_ids;
45 std::unordered_map<std::string, std::size_t> buffer_view_ids;
46 std::unordered_map<std::string, std::size_t> accessor_ids;
47 std::unordered_map<std::string, std::size_t> node_ids;
48 std::unordered_map<std::string, std::size_t> mesh_ids;
49 std::unordered_map<std::string, std::size_t> scene_ids;
50 explicit Helper(const base::FilePath& path);
51 ~Helper();
52 };
53
35 bool SetBuffers(const base::DictionaryValue& dict); 54 bool SetBuffers(const base::DictionaryValue& dict);
36 bool SetBufferViews(const base::DictionaryValue& dict); 55 bool SetBufferViews(const base::DictionaryValue& dict);
37 bool SetAccessors(const base::DictionaryValue& dict); 56 bool SetAccessors(const base::DictionaryValue& dict);
38 bool SetMeshes(const base::DictionaryValue& dict); 57 bool SetMeshes(const base::DictionaryValue& dict);
39 bool SetNodes(const base::DictionaryValue& dict); 58 bool SetNodes(const base::DictionaryValue& dict);
40 bool SetScenes(const base::DictionaryValue& dict); 59 bool SetScenes(const base::DictionaryValue& dict);
41 std::unique_ptr<gltf::Mesh::Primitive> ProcessPrimitive( 60 std::unique_ptr<gltf::Mesh::Primitive> ProcessPrimitive(
42 const base::DictionaryValue& dict); 61 const base::DictionaryValue& dict);
62 std::unique_ptr<gltf::Buffer> ProcessUri(const std::string& uri_str);
43 63
44 std::unique_ptr<gltf::Asset> asset_; 64 Helper* helper_;
45 std::unordered_map<std::string, std::size_t> buffer_ids_;
46 std::unordered_map<std::string, std::size_t> buffer_view_ids_;
47 std::unordered_map<std::string, std::size_t> accessor_ids_;
48 std::unordered_map<std::string, std::size_t> node_ids_;
49 std::unordered_map<std::string, std::size_t> mesh_ids_;
50 std::unordered_map<std::string, std::size_t> scene_ids_;
51 65
52 DISALLOW_COPY_AND_ASSIGN(GltfParser); 66 DISALLOW_COPY_AND_ASSIGN(GltfParser);
53 }; 67 };
54 68
55 } // namespace vr_shell 69 } // namespace vr_shell
56 70
57 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_PARSER_H_ 71 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698