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

Unified Diff: chrome/browser/android/vr_shell/gltf_parser.h

Issue 2757213003: Implementing glTF 1.0 parser (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/vr_shell/gltf_parser.h
diff --git a/chrome/browser/android/vr_shell/gltf_parser.h b/chrome/browser/android/vr_shell/gltf_parser.h
new file mode 100644
index 0000000000000000000000000000000000000000..ad5ad6234e914657f96e65d15ac406d63275c353
--- /dev/null
+++ b/chrome/browser/android/vr_shell/gltf_parser.h
@@ -0,0 +1,188 @@
+// 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.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_PARSER_H_
+#define CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_PARSER_H_
+
+#include <memory>
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "base/values.h"
+
+namespace vr_shell {
+
+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.
+
+enum Type {
+ SCALAR = 0,
+ VEC2,
+ VEC3,
+ VEC4,
+ MAT2,
+ MAT3,
+ MAT4,
+};
+
+using Buffer = std::string;
+
+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.
+ const Buffer* buffer;
+ int byte_length;
+ int byte_offset;
+ int target;
+};
+
+struct Accessor {
+ const BufferView* buffer_view;
+ int byte_offset;
+ // TODO(acondor): byte_stride is on BufferView in glTF 2.0.
+ int byte_stride;
+ int component_type;
+ int count;
+ Type type;
+};
+
+struct Primitive {
+ std::map<std::string, const Accessor*> attributes;
+ const Accessor* indices;
+ int mode;
+ Primitive();
+ ~Primitive();
+};
+
+struct Mesh {
+ std::vector<std::unique_ptr<Primitive>> primitives;
+ Mesh();
+ ~Mesh();
+};
+
+struct Node {
+ std::vector<const Node*> children;
+ // TODO(acondor): There is only one mesh per node in glTF 2.0.
+ std::vector<const Mesh*> meshes;
+ Node();
+ ~Node();
+};
+
+struct Scene {
+ std::vector<const Node*> nodes;
+ Scene();
+ ~Scene();
+};
+
+class Asset {
+ public:
+ Asset();
+ virtual ~Asset();
+
+ std::size_t AddBuffer(std::unique_ptr<Buffer> buffer) {
+ auto id = buffers_.size();
mthiesse 2017/03/21 16:06:55 nit: s/id/index throughout? id makes this look lik
+ buffers_.push_back(std::move(buffer));
+ return id;
+ }
+
+ std::size_t AddBufferView(std::unique_ptr<BufferView> buffer_view) {
+ auto id = buffer_views_.size();
+ buffer_views_.push_back(std::move(buffer_view));
+ return id;
+ }
+
+ std::size_t AddAccessor(std::unique_ptr<Accessor> accessor) {
+ auto id = accessors_.size();
+ accessors_.push_back(std::move(accessor));
+ return id;
+ }
+
+ std::size_t AddMesh(std::unique_ptr<Mesh> mesh) {
+ auto id = meshes_.size();
+ meshes_.push_back(std::move(mesh));
+ return id;
+ }
+
+ std::size_t AddNode(std::unique_ptr<Node> node) {
+ auto id = nodes_.size();
+ nodes_.push_back(std::move(node));
+ return id;
+ }
+
+ std::size_t AddScene(std::unique_ptr<Scene> scene) {
+ auto id = scenes_.size();
+ scenes_.push_back(std::move(scene));
+ return id;
+ }
+
+ const Buffer* GetBuffer(std::size_t id) const {
+ return id < buffers_.size() ? buffers_[id].get() : nullptr;
+ }
+
+ const BufferView* GetBufferView(std::size_t id) const {
+ return id < buffer_views_.size() ? buffer_views_[id].get() : nullptr;
+ }
+
+ const Accessor* GetAccessor(std::size_t id) const {
+ return id < accessors_.size() ? accessors_[id].get() : nullptr;
+ }
+
+ const Mesh* GetMesh(std::size_t id) const {
+ return id < meshes_.size() ? meshes_[id].get() : nullptr;
+ }
+
+ const Node* GetNode(std::size_t id) const {
+ return id < nodes_.size() ? nodes_[id].get() : nullptr;
+ }
+
+ const Scene* GetScene(std::size_t id) const {
+ return id < scenes_.size() ? scenes_[id].get() : nullptr;
+ }
+
+ 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.
+
+ 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
+
+ private:
+ std::vector<std::unique_ptr<Buffer>> buffers_;
+ std::vector<std::unique_ptr<BufferView>> buffer_views_;
+ std::vector<std::unique_ptr<Accessor>> accessors_;
+ std::vector<std::unique_ptr<Mesh>> meshes_;
+ std::vector<std::unique_ptr<Node>> nodes_;
+ std::vector<std::unique_ptr<Scene>> scenes_;
+ const Scene* scene_;
+};
+
+} // namespace gltf
+
+// Parser for glTF 1.0 specification
+// https://github.com/KhronosGroup/glTF/tree/master/specification/1.0
+// TODO(acondor): Implement glTF 2.0 parser. gltf::Asset is mostly version
+// agnostic.
+class GltfParser {
+ public:
+ GltfParser();
+ ~GltfParser();
+ std::unique_ptr<gltf::Asset> Parse(const base::DictionaryValue& dict);
+
+ private:
+ void SetBuffers(const base::DictionaryValue& dict);
+ void SetBufferViews(const base::DictionaryValue& dict);
+ void SetAccessors(const base::DictionaryValue& dict);
+ void SetMeshes(const base::DictionaryValue& dict);
+ void SetNodes(const base::DictionaryValue& dict);
+ void SetScenes(const base::DictionaryValue& dict);
+
+ std::unique_ptr<gltf::Asset> asset_;
+ std::unordered_map<std::string, std::size_t> buffer_ids_;
+ std::unordered_map<std::string, std::size_t> buffer_view_ids_;
+ std::unordered_map<std::string, std::size_t> accessor_ids_;
+ std::unordered_map<std::string, std::size_t> node_ids_;
+ std::unordered_map<std::string, std::size_t> mesh_ids_;
+ std::unordered_map<std::string, std::size_t> scene_ids_;
+
+ DISALLOW_COPY_AND_ASSIGN(GltfParser);
+};
+
+} // namespace vr_shell
+
+#endif // CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_PARSER_H_

Powered by Google App Engine
This is Rietveld 408576698