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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/vr_shell/gltf_asset.h
diff --git a/chrome/browser/android/vr_shell/gltf_asset.h b/chrome/browser/android/vr_shell/gltf_asset.h
new file mode 100644
index 0000000000000000000000000000000000000000..c269d2a7c4bdd385aa1ac7f4eca5ae6d1aba4743
--- /dev/null
+++ b/chrome/browser/android/vr_shell/gltf_asset.h
@@ -0,0 +1,171 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// 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_ASSET_H_
+#define CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_ASSET_H_
+
+#include <map>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "ui/gl/gl_bindings.h"
+
+namespace vr_shell {
+
+namespace gltf {
+
+enum Type {
+ SCALAR = 0,
+ VEC2,
+ VEC3,
+ VEC4,
+ MAT2,
+ MAT3,
+ MAT4,
+};
+
+Type GetType(const std::string& type);
+
+// A Buffer is data stored as binary blob in little-endian format.
+using Buffer = std::string;
+
+// The following structures match the objects defined in glTF 1.0 standard.
+// https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#properties-reference
+
+// A BufferView is subset of data in a buffer.
+struct BufferView {
+ const Buffer* buffer;
+ int byte_length = 0;
+ int byte_offset;
+ int target = GL_ARRAY_BUFFER;
+};
+
+// An Accessor is a typed view into a BufferView.
+struct Accessor {
+ const BufferView* buffer_view;
+ int byte_offset;
+ // TODO(acondor): byte_stride is on BufferView in glTF 2.0.
+ int byte_stride = 0;
+ int component_type;
+ int count;
+ Type type;
+};
+
+// A Mesh is a set of primitives to be rendered.
+struct Mesh {
+ // A Primitive describes a geometry to be rendered.
+ struct Primitive {
+ std::map<std::string, const Accessor*> attributes;
+ const Accessor* indices;
+ int mode;
+ Primitive();
+ ~Primitive();
+ };
+
+ std::vector<std::unique_ptr<Primitive>> primitives;
+ Mesh();
+ ~Mesh();
+};
+
+// A Node in the node hierarchy.
+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();
+};
+
+// The root nodes of a scene.
+struct Scene {
+ std::vector<const Node*> nodes;
+ Scene();
+ ~Scene();
+};
+
+class Asset {
+ public:
+ Asset();
+ virtual ~Asset();
+
+ 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.
+ auto id = buffers_.size();
+ 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_; }
+
+ void SetScene(const Scene* scene) { scene_ = scene; }
+
+ 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
+
+} // namespace vr_shell
+
+#endif // CHROME_BROWSER_ANDROID_VR_SHELL_GLTF_ASSET_H_

Powered by Google App Engine
This is Rietveld 408576698