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

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

Issue 2757213003: Implementing glTF 1.0 parser (Closed)
Patch Set: Moving glTF structs to their own file 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_ASSET_H_
6 #define CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_ASSET_H_
7
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <vector>
12
13 #include "ui/gl/gl_bindings.h"
14
15 namespace vr_shell {
16
17 namespace gltf {
18
19 enum Type {
20 SCALAR = 0,
21 VEC2,
22 VEC3,
23 VEC4,
24 MAT2,
25 MAT3,
26 MAT4,
27 };
28
29 Type GetType(const std::string& type);
30
31 // A Buffer is data stored as binary blob in little-endian format.
32 using Buffer = std::string;
33
34 // The following structures match the objects defined in glTF 1.0 standard.
35 // https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#properties -reference
36
37 // A BufferView is subset of data in a buffer.
38 struct BufferView {
39 const Buffer* buffer;
40 int byte_length = 0;
41 int byte_offset;
42 int target = GL_ARRAY_BUFFER;
43 };
44
45 // An Accessor is a typed view into a BufferView.
46 struct Accessor {
47 const BufferView* buffer_view;
48 int byte_offset;
49 // TODO(acondor): byte_stride is on BufferView in glTF 2.0.
50 int byte_stride = 0;
51 int component_type;
52 int count;
53 Type type;
54 };
55
56 // A Mesh is a set of primitives to be rendered.
57 struct Mesh {
58 // A Primitive describes a geometry to be rendered.
59 struct Primitive {
60 std::map<std::string, const Accessor*> attributes;
61 const Accessor* indices;
62 int mode;
63 Primitive();
64 ~Primitive();
65 };
66
67 std::vector<std::unique_ptr<Primitive>> primitives;
68 Mesh();
69 ~Mesh();
70 };
71
72 // A Node in the node hierarchy.
73 struct Node {
74 std::vector<const Node*> children;
75 // TODO(acondor): There is only one mesh per node in glTF 2.0.
76 std::vector<const Mesh*> meshes;
77 Node();
78 ~Node();
79 };
80
81 // The root nodes of a scene.
82 struct Scene {
83 std::vector<const Node*> nodes;
84 Scene();
85 ~Scene();
86 };
87
88 class Asset {
89 public:
90 Asset();
91 virtual ~Asset();
92
93 std::size_t AddBuffer(std::unique_ptr<Buffer> buffer) {
bajones 2017/03/21 15:44:23 I know this are all pretty simple functions, but I
acondor_ 2017/03/22 16:25:28 Done.
94 auto id = buffers_.size();
95 buffers_.push_back(std::move(buffer));
96 return id;
97 }
98
99 std::size_t AddBufferView(std::unique_ptr<BufferView> buffer_view) {
100 auto id = buffer_views_.size();
101 buffer_views_.push_back(std::move(buffer_view));
102 return id;
103 }
104
105 std::size_t AddAccessor(std::unique_ptr<Accessor> accessor) {
106 auto id = accessors_.size();
107 accessors_.push_back(std::move(accessor));
108 return id;
109 }
110
111 std::size_t AddMesh(std::unique_ptr<Mesh> mesh) {
112 auto id = meshes_.size();
113 meshes_.push_back(std::move(mesh));
114 return id;
115 }
116
117 std::size_t AddNode(std::unique_ptr<Node> node) {
118 auto id = nodes_.size();
119 nodes_.push_back(std::move(node));
120 return id;
121 }
122
123 std::size_t AddScene(std::unique_ptr<Scene> scene) {
124 auto id = scenes_.size();
125 scenes_.push_back(std::move(scene));
126 return id;
127 }
128
129 const Buffer* GetBuffer(std::size_t id) const {
130 return id < buffers_.size() ? buffers_[id].get() : nullptr;
131 }
132
133 const BufferView* GetBufferView(std::size_t id) const {
134 return id < buffer_views_.size() ? buffer_views_[id].get() : nullptr;
135 }
136
137 const Accessor* GetAccessor(std::size_t id) const {
138 return id < accessors_.size() ? accessors_[id].get() : nullptr;
139 }
140
141 const Mesh* GetMesh(std::size_t id) const {
142 return id < meshes_.size() ? meshes_[id].get() : nullptr;
143 }
144
145 const Node* GetNode(std::size_t id) const {
146 return id < nodes_.size() ? nodes_[id].get() : nullptr;
147 }
148
149 const Scene* GetScene(std::size_t id) const {
150 return id < scenes_.size() ? scenes_[id].get() : nullptr;
151 }
152
153 const Scene* GetScene() const { return scene_; }
154
155 void SetScene(const Scene* scene) { scene_ = scene; }
156
157 private:
158 std::vector<std::unique_ptr<Buffer>> buffers_;
159 std::vector<std::unique_ptr<BufferView>> buffer_views_;
160 std::vector<std::unique_ptr<Accessor>> accessors_;
161 std::vector<std::unique_ptr<Mesh>> meshes_;
162 std::vector<std::unique_ptr<Node>> nodes_;
163 std::vector<std::unique_ptr<Scene>> scenes_;
164 const Scene* scene_;
165 };
166
167 } // namespace gltf
168
169 } // namespace vr_shell
170
171 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_ASSET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698