Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
|
mthiesse
2017/03/20 22:32:44
nit: Copyright 2017
acondor_
2017/03/21 15:26:21
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_PARSER_H_ | |
| 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_PARSER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 #include <unordered_map> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/values.h" | |
| 14 | |
| 15 namespace vr_shell { | |
| 16 | |
| 17 namespace gltf { | |
|
mthiesse
2017/03/20 22:32:44
Move all of the code inside of this namespace to a
acondor_
2017/03/21 15:26:21
Done.
| |
| 18 | |
| 19 enum Type { | |
| 20 SCALAR = 0, | |
| 21 VEC2, | |
| 22 VEC3, | |
| 23 VEC4, | |
| 24 MAT2, | |
| 25 MAT3, | |
| 26 MAT4, | |
| 27 }; | |
| 28 | |
| 29 using Buffer = std::string; | |
| 30 | |
| 31 struct BufferView { | |
|
mthiesse
2017/03/20 22:32:44
Can you add a comment above these structs saying t
acondor_
2017/03/21 15:26:22
Done.
| |
| 32 const Buffer* buffer; | |
| 33 int byte_length; | |
| 34 int byte_offset; | |
| 35 int target; | |
| 36 }; | |
| 37 | |
| 38 struct Accessor { | |
| 39 const BufferView* buffer_view; | |
| 40 int byte_offset; | |
| 41 // TODO(acondor): byte_stride is on BufferView in glTF 2.0. | |
| 42 int byte_stride; | |
| 43 int component_type; | |
| 44 int count; | |
| 45 Type type; | |
| 46 }; | |
| 47 | |
| 48 struct Primitive { | |
| 49 std::map<std::string, const Accessor*> attributes; | |
| 50 const Accessor* indices; | |
| 51 int mode; | |
| 52 Primitive(); | |
| 53 ~Primitive(); | |
| 54 }; | |
| 55 | |
| 56 struct Mesh { | |
| 57 std::vector<std::unique_ptr<Primitive>> primitives; | |
| 58 Mesh(); | |
| 59 ~Mesh(); | |
| 60 }; | |
| 61 | |
| 62 struct Node { | |
| 63 std::vector<const Node*> children; | |
| 64 // TODO(acondor): There is only one mesh per node in glTF 2.0. | |
| 65 std::vector<const Mesh*> meshes; | |
| 66 Node(); | |
| 67 ~Node(); | |
| 68 }; | |
| 69 | |
| 70 struct Scene { | |
| 71 std::vector<const Node*> nodes; | |
| 72 Scene(); | |
| 73 ~Scene(); | |
| 74 }; | |
| 75 | |
| 76 class Asset { | |
| 77 public: | |
| 78 Asset(); | |
| 79 virtual ~Asset(); | |
| 80 | |
| 81 std::size_t AddBuffer(std::unique_ptr<Buffer> buffer) { | |
| 82 auto id = buffers_.size(); | |
|
mthiesse
2017/03/21 16:06:55
nit: s/id/index throughout? id makes this look lik
| |
| 83 buffers_.push_back(std::move(buffer)); | |
| 84 return id; | |
| 85 } | |
| 86 | |
| 87 std::size_t AddBufferView(std::unique_ptr<BufferView> buffer_view) { | |
| 88 auto id = buffer_views_.size(); | |
| 89 buffer_views_.push_back(std::move(buffer_view)); | |
| 90 return id; | |
| 91 } | |
| 92 | |
| 93 std::size_t AddAccessor(std::unique_ptr<Accessor> accessor) { | |
| 94 auto id = accessors_.size(); | |
| 95 accessors_.push_back(std::move(accessor)); | |
| 96 return id; | |
| 97 } | |
| 98 | |
| 99 std::size_t AddMesh(std::unique_ptr<Mesh> mesh) { | |
| 100 auto id = meshes_.size(); | |
| 101 meshes_.push_back(std::move(mesh)); | |
| 102 return id; | |
| 103 } | |
| 104 | |
| 105 std::size_t AddNode(std::unique_ptr<Node> node) { | |
| 106 auto id = nodes_.size(); | |
| 107 nodes_.push_back(std::move(node)); | |
| 108 return id; | |
| 109 } | |
| 110 | |
| 111 std::size_t AddScene(std::unique_ptr<Scene> scene) { | |
| 112 auto id = scenes_.size(); | |
| 113 scenes_.push_back(std::move(scene)); | |
| 114 return id; | |
| 115 } | |
| 116 | |
| 117 const Buffer* GetBuffer(std::size_t id) const { | |
| 118 return id < buffers_.size() ? buffers_[id].get() : nullptr; | |
| 119 } | |
| 120 | |
| 121 const BufferView* GetBufferView(std::size_t id) const { | |
| 122 return id < buffer_views_.size() ? buffer_views_[id].get() : nullptr; | |
| 123 } | |
| 124 | |
| 125 const Accessor* GetAccessor(std::size_t id) const { | |
| 126 return id < accessors_.size() ? accessors_[id].get() : nullptr; | |
| 127 } | |
| 128 | |
| 129 const Mesh* GetMesh(std::size_t id) const { | |
| 130 return id < meshes_.size() ? meshes_[id].get() : nullptr; | |
| 131 } | |
| 132 | |
| 133 const Node* GetNode(std::size_t id) const { | |
| 134 return id < nodes_.size() ? nodes_[id].get() : nullptr; | |
| 135 } | |
| 136 | |
| 137 const Scene* GetScene(std::size_t id) const { | |
| 138 return id < scenes_.size() ? scenes_[id].get() : nullptr; | |
| 139 } | |
| 140 | |
| 141 const Scene* GetScene() const { return scene_; } | |
|
mthiesse
2017/03/21 16:06:54
Can we change this to GetCurrentScene, and SetCurr
acondor_
2017/03/21 19:31:30
Doing Main instead of Current.
| |
| 142 | |
| 143 void SetScene(const Scene* scene) { scene_ = scene; } | |
|
mthiesse
2017/03/21 16:06:55
Is there ever a reason to call SetScene multiple t
acondor_
2017/03/21 19:31:30
Because the parser needs to set this at the end, w
| |
| 144 | |
| 145 private: | |
| 146 std::vector<std::unique_ptr<Buffer>> buffers_; | |
| 147 std::vector<std::unique_ptr<BufferView>> buffer_views_; | |
| 148 std::vector<std::unique_ptr<Accessor>> accessors_; | |
| 149 std::vector<std::unique_ptr<Mesh>> meshes_; | |
| 150 std::vector<std::unique_ptr<Node>> nodes_; | |
| 151 std::vector<std::unique_ptr<Scene>> scenes_; | |
| 152 const Scene* scene_; | |
| 153 }; | |
| 154 | |
| 155 } // namespace gltf | |
| 156 | |
| 157 // Parser for glTF 1.0 specification | |
| 158 // https://github.com/KhronosGroup/glTF/tree/master/specification/1.0 | |
| 159 // TODO(acondor): Implement glTF 2.0 parser. gltf::Asset is mostly version | |
| 160 // agnostic. | |
| 161 class GltfParser { | |
| 162 public: | |
| 163 GltfParser(); | |
| 164 ~GltfParser(); | |
| 165 std::unique_ptr<gltf::Asset> Parse(const base::DictionaryValue& dict); | |
| 166 | |
| 167 private: | |
| 168 void SetBuffers(const base::DictionaryValue& dict); | |
| 169 void SetBufferViews(const base::DictionaryValue& dict); | |
| 170 void SetAccessors(const base::DictionaryValue& dict); | |
| 171 void SetMeshes(const base::DictionaryValue& dict); | |
| 172 void SetNodes(const base::DictionaryValue& dict); | |
| 173 void SetScenes(const base::DictionaryValue& dict); | |
| 174 | |
| 175 std::unique_ptr<gltf::Asset> asset_; | |
| 176 std::unordered_map<std::string, std::size_t> buffer_ids_; | |
| 177 std::unordered_map<std::string, std::size_t> buffer_view_ids_; | |
| 178 std::unordered_map<std::string, std::size_t> accessor_ids_; | |
| 179 std::unordered_map<std::string, std::size_t> node_ids_; | |
| 180 std::unordered_map<std::string, std::size_t> mesh_ids_; | |
| 181 std::unordered_map<std::string, std::size_t> scene_ids_; | |
| 182 | |
| 183 DISALLOW_COPY_AND_ASSIGN(GltfParser); | |
| 184 }; | |
| 185 | |
| 186 } // namespace vr_shell | |
| 187 | |
| 188 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_PARSER_H_ | |
| OLD | NEW |